1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2011, Marvell Semiconductor Inc.
4 * Lei Wen <leiwen@marvell.com>
6 * Back ported to the 8xx platform (from the 8260 platform) by
7 * Murray.Jensen@cmst.csiro.au, 27-Jan-01.
17 #if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
18 void *aligned_buffer = (void *)CONFIG_FIXED_SDHCI_ALIGNED_BUFFER;
23 static void sdhci_reset(struct sdhci_host *host, u8 mask)
25 unsigned long timeout;
29 sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET);
30 while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) {
32 printf("%s: Reset 0x%x never completed.\n",
41 static void sdhci_cmd_done(struct sdhci_host *host, struct mmc_cmd *cmd)
44 if (cmd->resp_type & MMC_RSP_136) {
45 /* CRC is stripped so we need to do some shifting. */
46 for (i = 0; i < 4; i++) {
47 cmd->response[i] = sdhci_readl(host,
48 SDHCI_RESPONSE + (3-i)*4) << 8;
50 cmd->response[i] |= sdhci_readb(host,
51 SDHCI_RESPONSE + (3-i)*4-1);
54 cmd->response[0] = sdhci_readl(host, SDHCI_RESPONSE);
58 static void sdhci_transfer_pio(struct sdhci_host *host, struct mmc_data *data)
62 for (i = 0; i < data->blocksize; i += 4) {
63 offs = data->dest + i;
64 if (data->flags == MMC_DATA_READ)
65 *(u32 *)offs = sdhci_readl(host, SDHCI_BUFFER);
67 sdhci_writel(host, *(u32 *)offs, SDHCI_BUFFER);
71 #if CONFIG_IS_ENABLED(MMC_SDHCI_ADMA)
72 static void sdhci_adma_desc(struct sdhci_host *host, char *buf, u16 len,
75 struct sdhci_adma_desc *desc;
78 desc = &host->adma_desc_table[host->desc_slot];
80 attr = ADMA_DESC_ATTR_VALID | ADMA_DESC_TRANSFER_DATA;
84 attr |= ADMA_DESC_ATTR_END;
89 desc->addr_lo = (dma_addr_t)buf;
90 #ifdef CONFIG_DMA_ADDR_T_64BIT
91 desc->addr_hi = (u64)buf >> 32;
95 static void sdhci_prepare_adma_table(struct sdhci_host *host,
96 struct mmc_data *data)
98 uint trans_bytes = data->blocksize * data->blocks;
99 uint desc_count = DIV_ROUND_UP(trans_bytes, ADMA_MAX_LEN);
105 if (data->flags & MMC_DATA_READ)
108 buf = (char *)data->src;
111 sdhci_adma_desc(host, buf, ADMA_MAX_LEN, false);
113 trans_bytes -= ADMA_MAX_LEN;
116 sdhci_adma_desc(host, buf, trans_bytes, true);
118 flush_cache((dma_addr_t)host->adma_desc_table,
119 ROUND(desc_count * sizeof(struct sdhci_adma_desc),
122 #elif defined(CONFIG_MMC_SDHCI_SDMA)
123 static void sdhci_prepare_adma_table(struct sdhci_host *host,
124 struct mmc_data *data)
127 #if (defined(CONFIG_MMC_SDHCI_SDMA) || CONFIG_IS_ENABLED(MMC_SDHCI_ADMA))
128 static void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data,
129 int *is_aligned, int trans_bytes)
133 if (data->flags == MMC_DATA_READ)
134 host->start_addr = (dma_addr_t)data->dest;
136 host->start_addr = (dma_addr_t)data->src;
138 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
139 ctrl &= ~SDHCI_CTRL_DMA_MASK;
140 if (host->flags & USE_ADMA64)
141 ctrl |= SDHCI_CTRL_ADMA64;
142 else if (host->flags & USE_ADMA)
143 ctrl |= SDHCI_CTRL_ADMA32;
144 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
146 if (host->flags & USE_SDMA) {
147 if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) &&
148 (host->start_addr & 0x7) != 0x0) {
150 host->start_addr = (unsigned long)aligned_buffer;
151 if (data->flags != MMC_DATA_READ)
152 memcpy(aligned_buffer, data->src, trans_bytes);
155 #if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
157 * Always use this bounce-buffer when
158 * CONFIG_FIXED_SDHCI_ALIGNED_BUFFER is defined
161 host->start_addr = (unsigned long)aligned_buffer;
162 if (data->flags != MMC_DATA_READ)
163 memcpy(aligned_buffer, data->src, trans_bytes);
165 sdhci_writel(host, host->start_addr, SDHCI_DMA_ADDRESS);
167 } else if (host->flags & (USE_ADMA | USE_ADMA64)) {
168 sdhci_prepare_adma_table(host, data);
170 sdhci_writel(host, (u32)host->adma_addr, SDHCI_ADMA_ADDRESS);
171 if (host->flags & USE_ADMA64)
172 sdhci_writel(host, (u64)host->adma_addr >> 32,
173 SDHCI_ADMA_ADDRESS_HI);
176 flush_cache(host->start_addr, ROUND(trans_bytes, ARCH_DMA_MINALIGN));
179 static void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data,
180 int *is_aligned, int trans_bytes)
183 static int sdhci_transfer_data(struct sdhci_host *host, struct mmc_data *data)
185 dma_addr_t start_addr = host->start_addr;
186 unsigned int stat, rdy, mask, timeout, block = 0;
187 bool transfer_done = false;
190 rdy = SDHCI_INT_SPACE_AVAIL | SDHCI_INT_DATA_AVAIL;
191 mask = SDHCI_DATA_AVAILABLE | SDHCI_SPACE_AVAILABLE;
193 stat = sdhci_readl(host, SDHCI_INT_STATUS);
194 if (stat & SDHCI_INT_ERROR) {
195 pr_debug("%s: Error detected in status(0x%X)!\n",
199 if (!transfer_done && (stat & rdy)) {
200 if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) & mask))
202 sdhci_writel(host, rdy, SDHCI_INT_STATUS);
203 sdhci_transfer_pio(host, data);
204 data->dest += data->blocksize;
205 if (++block >= data->blocks) {
206 /* Keep looping until the SDHCI_INT_DATA_END is
207 * cleared, even if we finished sending all the
210 transfer_done = true;
214 if ((host->flags & USE_DMA) && !transfer_done &&
215 (stat & SDHCI_INT_DMA_END)) {
216 sdhci_writel(host, SDHCI_INT_DMA_END, SDHCI_INT_STATUS);
217 if (host->flags & USE_SDMA) {
219 ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1);
220 start_addr += SDHCI_DEFAULT_BOUNDARY_SIZE;
221 sdhci_writel(host, start_addr,
228 printf("%s: Transfer data timeout\n", __func__);
231 } while (!(stat & SDHCI_INT_DATA_END));
236 * No command will be sent by driver if card is busy, so driver must wait
237 * for card ready state.
238 * Every time when card is busy after timeout then (last) timeout value will be
239 * increased twice but only if it doesn't exceed global defined maximum.
240 * Each function call will use last timeout value.
242 #define SDHCI_CMD_MAX_TIMEOUT 3200
243 #define SDHCI_CMD_DEFAULT_TIMEOUT 100
244 #define SDHCI_READ_STATUS_TIMEOUT 1000
247 static int sdhci_send_command(struct udevice *dev, struct mmc_cmd *cmd,
248 struct mmc_data *data)
250 struct mmc *mmc = mmc_get_mmc_dev(dev);
253 static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
254 struct mmc_data *data)
257 struct sdhci_host *host = mmc->priv;
258 unsigned int stat = 0;
260 int trans_bytes = 0, is_aligned = 1;
261 u32 mask, flags, mode;
262 unsigned int time = 0;
263 int mmc_dev = mmc_get_blk_desc(mmc)->devnum;
264 ulong start = get_timer(0);
266 host->start_addr = 0;
267 /* Timeout unit - ms */
268 static unsigned int cmd_timeout = SDHCI_CMD_DEFAULT_TIMEOUT;
270 mask = SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT;
272 /* We shouldn't wait for data inihibit for stop commands, even
273 though they might use busy signaling */
274 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION ||
275 ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK ||
276 cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200) && !data))
277 mask &= ~SDHCI_DATA_INHIBIT;
279 while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
280 if (time >= cmd_timeout) {
281 printf("%s: MMC: %d busy ", __func__, mmc_dev);
282 if (2 * cmd_timeout <= SDHCI_CMD_MAX_TIMEOUT) {
283 cmd_timeout += cmd_timeout;
284 printf("timeout increasing to: %u ms.\n",
295 sdhci_writel(host, SDHCI_INT_ALL_MASK, SDHCI_INT_STATUS);
297 mask = SDHCI_INT_RESPONSE;
298 if ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK ||
299 cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200) && !data)
300 mask = SDHCI_INT_DATA_AVAIL;
302 if (!(cmd->resp_type & MMC_RSP_PRESENT))
303 flags = SDHCI_CMD_RESP_NONE;
304 else if (cmd->resp_type & MMC_RSP_136)
305 flags = SDHCI_CMD_RESP_LONG;
306 else if (cmd->resp_type & MMC_RSP_BUSY) {
307 flags = SDHCI_CMD_RESP_SHORT_BUSY;
309 mask |= SDHCI_INT_DATA_END;
311 flags = SDHCI_CMD_RESP_SHORT;
313 if (cmd->resp_type & MMC_RSP_CRC)
314 flags |= SDHCI_CMD_CRC;
315 if (cmd->resp_type & MMC_RSP_OPCODE)
316 flags |= SDHCI_CMD_INDEX;
317 if (data || cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK ||
318 cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200)
319 flags |= SDHCI_CMD_DATA;
321 /* Set Transfer mode regarding to data flag */
323 sdhci_writeb(host, 0xe, SDHCI_TIMEOUT_CONTROL);
324 mode = SDHCI_TRNS_BLK_CNT_EN;
325 trans_bytes = data->blocks * data->blocksize;
326 if (data->blocks > 1)
327 mode |= SDHCI_TRNS_MULTI;
329 if (data->flags == MMC_DATA_READ)
330 mode |= SDHCI_TRNS_READ;
332 if (host->flags & USE_DMA) {
333 mode |= SDHCI_TRNS_DMA;
334 sdhci_prepare_dma(host, data, &is_aligned, trans_bytes);
337 sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG,
340 sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
341 sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
342 } else if (cmd->resp_type & MMC_RSP_BUSY) {
343 sdhci_writeb(host, 0xe, SDHCI_TIMEOUT_CONTROL);
346 sdhci_writel(host, cmd->cmdarg, SDHCI_ARGUMENT);
347 sdhci_writew(host, SDHCI_MAKE_CMD(cmd->cmdidx, flags), SDHCI_COMMAND);
348 start = get_timer(0);
350 stat = sdhci_readl(host, SDHCI_INT_STATUS);
351 if (stat & SDHCI_INT_ERROR)
354 if (get_timer(start) >= SDHCI_READ_STATUS_TIMEOUT) {
355 if (host->quirks & SDHCI_QUIRK_BROKEN_R1B) {
358 printf("%s: Timeout for status update!\n",
363 } while ((stat & mask) != mask);
365 if ((stat & (SDHCI_INT_ERROR | mask)) == mask) {
366 sdhci_cmd_done(host, cmd);
367 sdhci_writel(host, mask, SDHCI_INT_STATUS);
372 ret = sdhci_transfer_data(host, data);
374 if (host->quirks & SDHCI_QUIRK_WAIT_SEND_CMD)
377 stat = sdhci_readl(host, SDHCI_INT_STATUS);
378 sdhci_writel(host, SDHCI_INT_ALL_MASK, SDHCI_INT_STATUS);
380 if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) &&
381 !is_aligned && (data->flags == MMC_DATA_READ))
382 memcpy(data->dest, aligned_buffer, trans_bytes);
386 sdhci_reset(host, SDHCI_RESET_CMD);
387 sdhci_reset(host, SDHCI_RESET_DATA);
388 if (stat & SDHCI_INT_TIMEOUT)
394 #if defined(CONFIG_DM_MMC) && defined(MMC_SUPPORTS_TUNING)
395 static int sdhci_execute_tuning(struct udevice *dev, uint opcode)
398 struct mmc *mmc = mmc_get_mmc_dev(dev);
399 struct sdhci_host *host = mmc->priv;
401 debug("%s\n", __func__);
403 if (host->ops && host->ops->platform_execute_tuning) {
404 err = host->ops->platform_execute_tuning(mmc, opcode);
412 static int sdhci_set_clock(struct mmc *mmc, unsigned int clock)
414 struct sdhci_host *host = mmc->priv;
415 unsigned int div, clk = 0, timeout;
419 while (sdhci_readl(host, SDHCI_PRESENT_STATE) &
420 (SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT)) {
422 printf("%s: Timeout to wait cmd & data inhibit\n",
431 sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
436 if (host->ops && host->ops->set_delay)
437 host->ops->set_delay(host);
439 if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) {
441 * Check if the Host Controller supports Programmable Clock
445 for (div = 1; div <= 1024; div++) {
446 if ((host->max_clk / div) <= clock)
451 * Set Programmable Clock Mode in the Clock
454 clk = SDHCI_PROG_CLOCK_MODE;
457 /* Version 3.00 divisors must be a multiple of 2. */
458 if (host->max_clk <= clock) {
462 div < SDHCI_MAX_DIV_SPEC_300;
464 if ((host->max_clk / div) <= clock)
471 /* Version 2.00 divisors must be a power of 2. */
472 for (div = 1; div < SDHCI_MAX_DIV_SPEC_200; div *= 2) {
473 if ((host->max_clk / div) <= clock)
479 if (host->ops && host->ops->set_clock)
480 host->ops->set_clock(host, div);
482 clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
483 clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN)
484 << SDHCI_DIVIDER_HI_SHIFT;
485 clk |= SDHCI_CLOCK_INT_EN;
486 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
490 while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
491 & SDHCI_CLOCK_INT_STABLE)) {
493 printf("%s: Internal clock never stabilised.\n",
501 clk |= SDHCI_CLOCK_CARD_EN;
502 sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
506 static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
510 if (power != (unsigned short)-1) {
511 switch (1 << power) {
512 case MMC_VDD_165_195:
513 pwr = SDHCI_POWER_180;
517 pwr = SDHCI_POWER_300;
521 pwr = SDHCI_POWER_330;
527 sdhci_writeb(host, 0, SDHCI_POWER_CONTROL);
531 pwr |= SDHCI_POWER_ON;
533 sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
537 static int sdhci_set_ios(struct udevice *dev)
539 struct mmc *mmc = mmc_get_mmc_dev(dev);
541 static int sdhci_set_ios(struct mmc *mmc)
545 struct sdhci_host *host = mmc->priv;
547 if (host->ops && host->ops->set_control_reg)
548 host->ops->set_control_reg(host);
550 if (mmc->clock != host->clock)
551 sdhci_set_clock(mmc, mmc->clock);
553 if (mmc->clk_disable)
554 sdhci_set_clock(mmc, 0);
557 ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
558 if (mmc->bus_width == 8) {
559 ctrl &= ~SDHCI_CTRL_4BITBUS;
560 if ((SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) ||
561 (host->quirks & SDHCI_QUIRK_USE_WIDE8))
562 ctrl |= SDHCI_CTRL_8BITBUS;
564 if ((SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) ||
565 (host->quirks & SDHCI_QUIRK_USE_WIDE8))
566 ctrl &= ~SDHCI_CTRL_8BITBUS;
567 if (mmc->bus_width == 4)
568 ctrl |= SDHCI_CTRL_4BITBUS;
570 ctrl &= ~SDHCI_CTRL_4BITBUS;
573 if (mmc->clock > 26000000)
574 ctrl |= SDHCI_CTRL_HISPD;
576 ctrl &= ~SDHCI_CTRL_HISPD;
578 if ((host->quirks & SDHCI_QUIRK_NO_HISPD_BIT) ||
579 (host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE))
580 ctrl &= ~SDHCI_CTRL_HISPD;
582 sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
584 /* If available, call the driver specific "post" set_ios() function */
585 if (host->ops && host->ops->set_ios_post)
586 host->ops->set_ios_post(host);
591 static int sdhci_init(struct mmc *mmc)
593 struct sdhci_host *host = mmc->priv;
594 #if CONFIG_IS_ENABLED(DM_MMC) && CONFIG_IS_ENABLED(DM_GPIO)
595 struct udevice *dev = mmc->dev;
597 gpio_request_by_name(dev, "cd-gpio", 0,
598 &host->cd_gpio, GPIOD_IS_IN);
601 sdhci_reset(host, SDHCI_RESET_ALL);
603 if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) && !aligned_buffer) {
604 aligned_buffer = memalign(8, 512*1024);
605 if (!aligned_buffer) {
606 printf("%s: Aligned buffer alloc failed!!!\n",
612 sdhci_set_power(host, fls(mmc->cfg->voltages) - 1);
614 if (host->ops && host->ops->get_cd)
615 host->ops->get_cd(host);
617 /* Enable only interrupts served by the SD controller */
618 sdhci_writel(host, SDHCI_INT_DATA_MASK | SDHCI_INT_CMD_MASK,
620 /* Mask all sdhci interrupt sources */
621 sdhci_writel(host, 0x0, SDHCI_SIGNAL_ENABLE);
627 int sdhci_probe(struct udevice *dev)
629 struct mmc *mmc = mmc_get_mmc_dev(dev);
631 return sdhci_init(mmc);
634 int sdhci_get_cd(struct udevice *dev)
636 struct mmc *mmc = mmc_get_mmc_dev(dev);
637 struct sdhci_host *host = mmc->priv;
640 /* If nonremovable, assume that the card is always present. */
641 if (mmc->cfg->host_caps & MMC_CAP_NONREMOVABLE)
643 /* If polling, assume that the card is always present. */
644 if (mmc->cfg->host_caps & MMC_CAP_NEEDS_POLL)
647 #if CONFIG_IS_ENABLED(DM_GPIO)
648 value = dm_gpio_get_value(&host->cd_gpio);
650 if (mmc->cfg->host_caps & MMC_CAP_CD_ACTIVE_HIGH)
656 value = !!(sdhci_readl(host, SDHCI_PRESENT_STATE) &
658 if (mmc->cfg->host_caps & MMC_CAP_CD_ACTIVE_HIGH)
664 const struct dm_mmc_ops sdhci_ops = {
665 .send_cmd = sdhci_send_command,
666 .set_ios = sdhci_set_ios,
667 .get_cd = sdhci_get_cd,
668 #ifdef MMC_SUPPORTS_TUNING
669 .execute_tuning = sdhci_execute_tuning,
673 static const struct mmc_ops sdhci_ops = {
674 .send_cmd = sdhci_send_command,
675 .set_ios = sdhci_set_ios,
680 int sdhci_setup_cfg(struct mmc_config *cfg, struct sdhci_host *host,
681 u32 f_max, u32 f_min)
683 u32 caps, caps_1 = 0;
685 caps = sdhci_readl(host, SDHCI_CAPABILITIES);
687 #ifdef CONFIG_MMC_SDHCI_SDMA
688 if (!(caps & SDHCI_CAN_DO_SDMA)) {
689 printf("%s: Your controller doesn't support SDMA!!\n",
694 host->flags |= USE_SDMA;
696 #if CONFIG_IS_ENABLED(MMC_SDHCI_ADMA)
697 if (!(caps & SDHCI_CAN_DO_ADMA2)) {
698 printf("%s: Your controller doesn't support SDMA!!\n",
702 host->adma_desc_table = (struct sdhci_adma_desc *)
703 memalign(ARCH_DMA_MINALIGN, ADMA_TABLE_SZ);
705 host->adma_addr = (dma_addr_t)host->adma_desc_table;
706 #ifdef CONFIG_DMA_ADDR_T_64BIT
707 host->flags |= USE_ADMA64;
709 host->flags |= USE_ADMA;
712 if (host->quirks & SDHCI_QUIRK_REG32_RW)
714 sdhci_readl(host, SDHCI_HOST_VERSION - 2) >> 16;
716 host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
718 cfg->name = host->name;
719 #ifndef CONFIG_DM_MMC
720 cfg->ops = &sdhci_ops;
723 /* Check whether the clock multiplier is supported or not */
724 if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) {
725 caps_1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
726 host->clk_mul = (caps_1 & SDHCI_CLOCK_MUL_MASK) >>
727 SDHCI_CLOCK_MUL_SHIFT;
730 if (host->max_clk == 0) {
731 if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300)
732 host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK) >>
733 SDHCI_CLOCK_BASE_SHIFT;
735 host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK) >>
736 SDHCI_CLOCK_BASE_SHIFT;
737 host->max_clk *= 1000000;
739 host->max_clk *= host->clk_mul;
741 if (host->max_clk == 0) {
742 printf("%s: Hardware doesn't specify base clock frequency\n",
746 if (f_max && (f_max < host->max_clk))
749 cfg->f_max = host->max_clk;
753 if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300)
754 cfg->f_min = cfg->f_max / SDHCI_MAX_DIV_SPEC_300;
756 cfg->f_min = cfg->f_max / SDHCI_MAX_DIV_SPEC_200;
759 if (caps & SDHCI_CAN_VDD_330)
760 cfg->voltages |= MMC_VDD_32_33 | MMC_VDD_33_34;
761 if (caps & SDHCI_CAN_VDD_300)
762 cfg->voltages |= MMC_VDD_29_30 | MMC_VDD_30_31;
763 if (caps & SDHCI_CAN_VDD_180)
764 cfg->voltages |= MMC_VDD_165_195;
766 if (host->quirks & SDHCI_QUIRK_BROKEN_VOLTAGE)
767 cfg->voltages |= host->voltages;
769 cfg->host_caps |= MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_4BIT;
771 /* Since Host Controller Version3.0 */
772 if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) {
773 if (!(caps & SDHCI_CAN_DO_8BIT))
774 cfg->host_caps &= ~MMC_MODE_8BIT;
777 if (host->quirks & SDHCI_QUIRK_BROKEN_HISPD_MODE) {
778 cfg->host_caps &= ~MMC_MODE_HS;
779 cfg->host_caps &= ~MMC_MODE_HS_52MHz;
782 if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300)
783 caps_1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
785 if (!(cfg->voltages & MMC_VDD_165_195) ||
786 (host->quirks & SDHCI_QUIRK_NO_1_8_V))
787 caps_1 &= ~(SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 |
788 SDHCI_SUPPORT_DDR50);
790 if (caps_1 & (SDHCI_SUPPORT_SDR104 | SDHCI_SUPPORT_SDR50 |
791 SDHCI_SUPPORT_DDR50))
792 cfg->host_caps |= MMC_CAP(UHS_SDR12) | MMC_CAP(UHS_SDR25);
794 if (caps_1 & SDHCI_SUPPORT_SDR104) {
795 cfg->host_caps |= MMC_CAP(UHS_SDR104) | MMC_CAP(UHS_SDR50);
797 * SD3.0: SDR104 is supported so (for eMMC) the caps2
798 * field can be promoted to support HS200.
800 cfg->host_caps |= MMC_CAP(MMC_HS_200);
801 } else if (caps_1 & SDHCI_SUPPORT_SDR50) {
802 cfg->host_caps |= MMC_CAP(UHS_SDR50);
805 if (caps_1 & SDHCI_SUPPORT_DDR50)
806 cfg->host_caps |= MMC_CAP(UHS_DDR50);
809 cfg->host_caps |= host->host_caps;
811 cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
817 int sdhci_bind(struct udevice *dev, struct mmc *mmc, struct mmc_config *cfg)
819 return mmc_bind(dev, mmc, cfg);
822 int add_sdhci(struct sdhci_host *host, u32 f_max, u32 f_min)
826 ret = sdhci_setup_cfg(&host->cfg, host, f_max, f_min);
830 host->mmc = mmc_create(&host->cfg, host);
831 if (host->mmc == NULL) {
832 printf("%s: mmc create fail!\n", __func__);