1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright 2007, 2010-2011 Freescale Semiconductor, Inc
4 * Copyright 2019 NXP Semiconductors
8 * Based vaguely on the pxa mmc code:
23 #include <asm/cache.h>
24 #include <dm/device_compat.h>
25 #include <linux/bitops.h>
26 #include <linux/delay.h>
27 #include <linux/err.h>
28 #include <power/regulator.h>
30 #include <fsl_esdhc_imx.h>
31 #include <fdt_support.h>
34 #include <asm-generic/gpio.h>
35 #include <dm/pinctrl.h>
37 #if !CONFIG_IS_ENABLED(BLK)
38 #include "mmc_private.h"
41 DECLARE_GLOBAL_DATA_PTR;
43 #define SDHCI_IRQ_EN_BITS (IRQSTATEN_CC | IRQSTATEN_TC | \
45 IRQSTATEN_CTOE | IRQSTATEN_CCE | IRQSTATEN_CEBE | \
46 IRQSTATEN_CIE | IRQSTATEN_DTOE | IRQSTATEN_DCE | \
47 IRQSTATEN_DEBE | IRQSTATEN_BRR | IRQSTATEN_BWR | \
49 #define MAX_TUNING_LOOP 40
50 #define ESDHC_DRIVER_STAGE_VALUE 0xffffffff
53 uint dsaddr; /* SDMA system address register */
54 uint blkattr; /* Block attributes register */
55 uint cmdarg; /* Command argument register */
56 uint xfertyp; /* Transfer type register */
57 uint cmdrsp0; /* Command response 0 register */
58 uint cmdrsp1; /* Command response 1 register */
59 uint cmdrsp2; /* Command response 2 register */
60 uint cmdrsp3; /* Command response 3 register */
61 uint datport; /* Buffer data port register */
62 uint prsstat; /* Present state register */
63 uint proctl; /* Protocol control register */
64 uint sysctl; /* System Control Register */
65 uint irqstat; /* Interrupt status register */
66 uint irqstaten; /* Interrupt status enable register */
67 uint irqsigen; /* Interrupt signal enable register */
68 uint autoc12err; /* Auto CMD error status register */
69 uint hostcapblt; /* Host controller capabilities register */
70 uint wml; /* Watermark level register */
71 uint mixctrl; /* For USDHC */
72 char reserved1[4]; /* reserved */
73 uint fevt; /* Force event register */
74 uint admaes; /* ADMA error status register */
75 uint adsaddr; /* ADMA system address register */
79 uint clktunectrlstatus;
87 uint tuning_ctrl; /* on i.MX6/7/8/RT */
89 uint hostver; /* Host controller version register */
90 char reserved6[4]; /* reserved */
91 uint dmaerraddr; /* DMA error address register */
92 char reserved7[4]; /* reserved */
93 uint dmaerrattr; /* DMA error attribute register */
94 char reserved8[4]; /* reserved */
95 uint hostcapblt2; /* Host controller capabilities register 2 */
96 char reserved9[8]; /* reserved */
97 uint tcr; /* Tuning control register */
98 char reserved10[28]; /* reserved */
99 uint sddirctl; /* SD direction control register */
100 char reserved11[712];/* reserved */
101 uint scr; /* eSDHC control register */
104 struct fsl_esdhc_plat {
105 struct mmc_config cfg;
109 struct esdhc_soc_data {
114 * struct fsl_esdhc_priv
116 * @esdhc_regs: registers of the sdhc controller
117 * @sdhc_clk: Current clk of the sdhc controller
118 * @bus_width: bus width, 1bit, 4bit or 8bit
121 * Following is used when Driver Model is enabled for MMC
122 * @dev: pointer for the device
123 * @non_removable: 0: removable; 1: non-removable
124 * @broken_cd: 0: use GPIO for card detect; 1: Do not use GPIO for card detect
125 * @wp_enable: 1: enable checking wp; 0: no check
126 * @vs18_enable: 1: use 1.8V voltage; 0: use 3.3V
127 * @flags: ESDHC_FLAG_xx in include/fsl_esdhc_imx.h
128 * @caps: controller capabilities
129 * @tuning_step: tuning step setting in tuning_ctrl register
130 * @start_tuning_tap: the start point for tuning in tuning_ctrl register
131 * @strobe_dll_delay_target: settings in strobe_dllctrl
132 * @signal_voltage: indicating the current voltage
133 * @cd_gpio: gpio for card detection
134 * @wp_gpio: gpio for write protection
136 struct fsl_esdhc_priv {
137 struct fsl_esdhc *esdhc_regs;
138 unsigned int sdhc_clk;
142 unsigned int bus_width;
143 #if !CONFIG_IS_ENABLED(BLK)
154 u32 tuning_start_tap;
155 u32 strobe_dll_delay_target;
157 #if CONFIG_IS_ENABLED(DM_REGULATOR)
158 struct udevice *vqmmc_dev;
159 struct udevice *vmmc_dev;
161 #if CONFIG_IS_ENABLED(DM_GPIO)
162 struct gpio_desc cd_gpio;
163 struct gpio_desc wp_gpio;
167 /* Return the XFERTYP flags for a given command and data packet */
168 static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data)
173 xfertyp |= XFERTYP_DPSEL;
174 #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
175 xfertyp |= XFERTYP_DMAEN;
177 if (data->blocks > 1) {
178 xfertyp |= XFERTYP_MSBSEL;
179 xfertyp |= XFERTYP_BCEN;
180 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
181 xfertyp |= XFERTYP_AC12EN;
185 if (data->flags & MMC_DATA_READ)
186 xfertyp |= XFERTYP_DTDSEL;
189 if (cmd->resp_type & MMC_RSP_CRC)
190 xfertyp |= XFERTYP_CCCEN;
191 if (cmd->resp_type & MMC_RSP_OPCODE)
192 xfertyp |= XFERTYP_CICEN;
193 if (cmd->resp_type & MMC_RSP_136)
194 xfertyp |= XFERTYP_RSPTYP_136;
195 else if (cmd->resp_type & MMC_RSP_BUSY)
196 xfertyp |= XFERTYP_RSPTYP_48_BUSY;
197 else if (cmd->resp_type & MMC_RSP_PRESENT)
198 xfertyp |= XFERTYP_RSPTYP_48;
200 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
201 xfertyp |= XFERTYP_CMDTYP_ABORT;
203 return XFERTYP_CMD(cmd->cmdidx) | xfertyp;
206 #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
208 * PIO Read/Write Mode reduce the performace as DMA is not used in this mode.
210 static void esdhc_pio_read_write(struct fsl_esdhc_priv *priv,
211 struct mmc_data *data)
213 struct fsl_esdhc *regs = priv->esdhc_regs;
221 if (data->flags & MMC_DATA_READ) {
222 blocks = data->blocks;
225 start = get_timer(0);
226 size = data->blocksize;
227 irqstat = esdhc_read32(®s->irqstat);
228 while (!(esdhc_read32(®s->prsstat) & PRSSTAT_BREN)) {
229 if (get_timer(start) > PIO_TIMEOUT) {
230 printf("\nData Read Failed in PIO Mode.");
234 while (size && (!(irqstat & IRQSTAT_TC))) {
235 udelay(100); /* Wait before last byte transfer complete */
236 irqstat = esdhc_read32(®s->irqstat);
237 databuf = in_le32(®s->datport);
238 *((uint *)buffer) = databuf;
245 blocks = data->blocks;
246 buffer = (char *)data->src;
248 start = get_timer(0);
249 size = data->blocksize;
250 irqstat = esdhc_read32(®s->irqstat);
251 while (!(esdhc_read32(®s->prsstat) & PRSSTAT_BWEN)) {
252 if (get_timer(start) > PIO_TIMEOUT) {
253 printf("\nData Write Failed in PIO Mode.");
257 while (size && (!(irqstat & IRQSTAT_TC))) {
258 udelay(100); /* Wait before last byte transfer complete */
259 databuf = *((uint *)buffer);
262 irqstat = esdhc_read32(®s->irqstat);
263 out_le32(®s->datport, databuf);
271 static int esdhc_setup_data(struct fsl_esdhc_priv *priv, struct mmc *mmc,
272 struct mmc_data *data)
275 struct fsl_esdhc *regs = priv->esdhc_regs;
276 #if defined(CONFIG_S32V234) || defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)
281 wml_value = data->blocksize/4;
283 if (data->flags & MMC_DATA_READ) {
284 if (wml_value > WML_RD_WML_MAX)
285 wml_value = WML_RD_WML_MAX_VAL;
287 esdhc_clrsetbits32(®s->wml, WML_RD_WML_MASK, wml_value);
288 #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
289 #if defined(CONFIG_S32V234) || defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)
290 addr = virt_to_phys((void *)(data->dest));
291 if (upper_32_bits(addr))
292 printf("Error found for upper 32 bits\n");
294 esdhc_write32(®s->dsaddr, lower_32_bits(addr));
296 esdhc_write32(®s->dsaddr, (u32)data->dest);
300 #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
301 flush_dcache_range((ulong)data->src,
302 (ulong)data->src+data->blocks
305 if (wml_value > WML_WR_WML_MAX)
306 wml_value = WML_WR_WML_MAX_VAL;
307 if (priv->wp_enable) {
308 if ((esdhc_read32(®s->prsstat) &
309 PRSSTAT_WPSPL) == 0) {
310 printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
314 #if CONFIG_IS_ENABLED(DM_GPIO)
315 if (dm_gpio_is_valid(&priv->wp_gpio) &&
316 dm_gpio_get_value(&priv->wp_gpio)) {
317 printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
323 esdhc_clrsetbits32(®s->wml, WML_WR_WML_MASK,
325 #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
326 #if defined(CONFIG_S32V234) || defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)
327 addr = virt_to_phys((void *)(data->src));
328 if (upper_32_bits(addr))
329 printf("Error found for upper 32 bits\n");
331 esdhc_write32(®s->dsaddr, lower_32_bits(addr));
333 esdhc_write32(®s->dsaddr, (u32)data->src);
338 esdhc_write32(®s->blkattr, data->blocks << 16 | data->blocksize);
340 /* Calculate the timeout period for data transactions */
342 * 1)Timeout period = (2^(timeout+13)) SD Clock cycles
343 * 2)Timeout period should be minimum 0.250sec as per SD Card spec
344 * So, Number of SD Clock cycles for 0.25sec should be minimum
345 * (SD Clock/sec * 0.25 sec) SD Clock cycles
346 * = (mmc->clock * 1/4) SD Clock cycles
348 * => (2^(timeout+13)) >= mmc->clock * 1/4
349 * Taking log2 both the sides
350 * => timeout + 13 >= log2(mmc->clock/4)
351 * Rounding up to next power of 2
352 * => timeout + 13 = log2(mmc->clock/4) + 1
353 * => timeout + 13 = fls(mmc->clock/4)
355 * However, the MMC spec "It is strongly recommended for hosts to
356 * implement more than 500ms timeout value even if the card
357 * indicates the 250ms maximum busy length." Even the previous
358 * value of 300ms is known to be insufficient for some cards.
360 * => timeout + 13 = fls(mmc->clock/2)
362 timeout = fls(mmc->clock/2);
371 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC_A001
372 if ((timeout == 4) || (timeout == 8) || (timeout == 12))
376 #ifdef ESDHCI_QUIRK_BROKEN_TIMEOUT_VALUE
379 esdhc_clrsetbits32(®s->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16);
384 static void check_and_invalidate_dcache_range
385 (struct mmc_cmd *cmd,
386 struct mmc_data *data) {
389 unsigned size = roundup(ARCH_DMA_MINALIGN,
390 data->blocks*data->blocksize);
391 #if defined(CONFIG_S32V234) || defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)
394 addr = virt_to_phys((void *)(data->dest));
395 if (upper_32_bits(addr))
396 printf("Error found for upper 32 bits\n");
398 start = lower_32_bits(addr);
400 start = (unsigned)data->dest;
403 invalidate_dcache_range(start, end);
406 #ifdef CONFIG_MCF5441x
408 * Swaps 32-bit words to little-endian byte order.
410 static inline void sd_swap_dma_buff(struct mmc_data *data)
412 int i, size = data->blocksize >> 2;
413 u32 *buffer = (u32 *)data->dest;
416 while (data->blocks--) {
417 for (i = 0; i < size; i++) {
418 sw = __sw32(*buffer);
426 * Sends a command out on the bus. Takes the mmc pointer,
427 * a command pointer, and an optional data pointer.
429 static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
430 struct mmc_cmd *cmd, struct mmc_data *data)
435 u32 flags = IRQSTAT_CC | IRQSTAT_CTOE;
436 struct fsl_esdhc *regs = priv->esdhc_regs;
439 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
440 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
444 esdhc_write32(®s->irqstat, -1);
448 /* Wait for the bus to be idle */
449 while ((esdhc_read32(®s->prsstat) & PRSSTAT_CICHB) ||
450 (esdhc_read32(®s->prsstat) & PRSSTAT_CIDHB))
453 while (esdhc_read32(®s->prsstat) & PRSSTAT_DLA)
456 /* Wait at least 8 SD clock cycles before the next command */
458 * Note: This is way more than 8 cycles, but 1ms seems to
459 * resolve timing issues with some cards
463 /* Set up for a data transfer if we have one */
465 err = esdhc_setup_data(priv, mmc, data);
469 if (data->flags & MMC_DATA_READ)
470 check_and_invalidate_dcache_range(cmd, data);
473 /* Figure out the transfer arguments */
474 xfertyp = esdhc_xfertyp(cmd, data);
477 esdhc_write32(®s->irqsigen, 0);
479 /* Send the command */
480 esdhc_write32(®s->cmdarg, cmd->cmdarg);
481 #if defined(CONFIG_FSL_USDHC)
482 esdhc_write32(®s->mixctrl,
483 (esdhc_read32(®s->mixctrl) & 0xFFFFFF80) | (xfertyp & 0x7F)
484 | (mmc->ddr_mode ? XFERTYP_DDREN : 0));
485 esdhc_write32(®s->xfertyp, xfertyp & 0xFFFF0000);
487 esdhc_write32(®s->xfertyp, xfertyp);
490 if ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK) ||
491 (cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200))
494 /* Wait for the command to complete */
495 start = get_timer(0);
496 while (!(esdhc_read32(®s->irqstat) & flags)) {
497 if (get_timer(start) > 1000) {
503 irqstat = esdhc_read32(®s->irqstat);
505 if (irqstat & CMD_ERR) {
510 if (irqstat & IRQSTAT_CTOE) {
515 /* Switch voltage to 1.8V if CMD11 succeeded */
516 if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V) {
517 esdhc_setbits32(®s->vendorspec, ESDHC_VENDORSPEC_VSELECT);
519 printf("Run CMD11 1.8V switch\n");
520 /* Sleep for 5 ms - max time for card to switch to 1.8V */
524 /* Workaround for ESDHC errata ENGcm03648 */
525 if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
528 /* Poll on DATA0 line for cmd with busy signal for 5000 ms */
529 while (timeout > 0 && !(esdhc_read32(®s->prsstat) &
536 printf("Timeout waiting for DAT0 to go high!\n");
542 /* Copy the response to the response buffer */
543 if (cmd->resp_type & MMC_RSP_136) {
544 u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0;
546 cmdrsp3 = esdhc_read32(®s->cmdrsp3);
547 cmdrsp2 = esdhc_read32(®s->cmdrsp2);
548 cmdrsp1 = esdhc_read32(®s->cmdrsp1);
549 cmdrsp0 = esdhc_read32(®s->cmdrsp0);
550 cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
551 cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
552 cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
553 cmd->response[3] = (cmdrsp0 << 8);
555 cmd->response[0] = esdhc_read32(®s->cmdrsp0);
557 /* Wait until all of the blocks are transferred */
559 #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
560 esdhc_pio_read_write(priv, data);
562 flags = DATA_COMPLETE;
563 if ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK) ||
564 (cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200)) {
569 irqstat = esdhc_read32(®s->irqstat);
571 if (irqstat & IRQSTAT_DTOE) {
576 if (irqstat & DATA_ERR) {
580 } while ((irqstat & flags) != flags);
583 * Need invalidate the dcache here again to avoid any
584 * cache-fill during the DMA operations such as the
585 * speculative pre-fetching etc.
587 if (data->flags & MMC_DATA_READ) {
588 check_and_invalidate_dcache_range(cmd, data);
589 #ifdef CONFIG_MCF5441x
590 sd_swap_dma_buff(data);
597 /* Reset CMD and DATA portions on error */
599 esdhc_write32(®s->sysctl, esdhc_read32(®s->sysctl) |
601 while (esdhc_read32(®s->sysctl) & SYSCTL_RSTC)
605 esdhc_write32(®s->sysctl,
606 esdhc_read32(®s->sysctl) |
608 while ((esdhc_read32(®s->sysctl) & SYSCTL_RSTD))
612 /* If this was CMD11, then notify that power cycle is needed */
613 if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V)
614 printf("CMD11 to switch to 1.8V mode failed, card requires power cycle.\n");
617 esdhc_write32(®s->irqstat, -1);
622 static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
624 struct fsl_esdhc *regs = priv->esdhc_regs;
628 /* For i.MX53 eSDHCv3, SYSCTL.SDCLKFS may not be set to 0. */
629 int pre_div = (regs == (struct fsl_esdhc *)MMC_SDHC3_BASE_ADDR) ? 2 : 1;
636 int ddr_pre_div = mmc->ddr_mode ? 2 : 1;
637 int sdhc_clk = priv->sdhc_clk;
640 while (sdhc_clk / (16 * pre_div * ddr_pre_div) > clock && pre_div < 256)
643 while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16)
649 clk = (pre_div << 8) | (div << 4);
651 #ifdef CONFIG_FSL_USDHC
652 esdhc_clrbits32(®s->vendorspec, VENDORSPEC_CKEN);
654 esdhc_clrbits32(®s->sysctl, SYSCTL_CKEN);
657 esdhc_clrsetbits32(®s->sysctl, SYSCTL_CLOCK_MASK, clk);
661 #ifdef CONFIG_FSL_USDHC
662 esdhc_setbits32(®s->vendorspec, VENDORSPEC_PEREN | VENDORSPEC_CKEN);
664 esdhc_setbits32(®s->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
670 #ifdef MMC_SUPPORTS_TUNING
671 static int esdhc_change_pinstate(struct udevice *dev)
673 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
676 switch (priv->mode) {
679 ret = pinctrl_select_state(dev, "state_100mhz");
685 ret = pinctrl_select_state(dev, "state_200mhz");
688 ret = pinctrl_select_state(dev, "default");
693 printf("%s %d error\n", __func__, priv->mode);
698 static void esdhc_reset_tuning(struct mmc *mmc)
700 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
701 struct fsl_esdhc *regs = priv->esdhc_regs;
703 if (priv->flags & ESDHC_FLAG_USDHC) {
704 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
705 esdhc_clrbits32(®s->autoc12err,
706 MIX_CTRL_SMPCLK_SEL |
712 static void esdhc_set_strobe_dll(struct mmc *mmc)
714 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
715 struct fsl_esdhc *regs = priv->esdhc_regs;
718 if (priv->clock > ESDHC_STROBE_DLL_CLK_FREQ) {
719 writel(ESDHC_STROBE_DLL_CTRL_RESET, ®s->strobe_dllctrl);
722 * enable strobe dll ctrl and adjust the delay target
723 * for the uSDHC loopback read clock
725 val = ESDHC_STROBE_DLL_CTRL_ENABLE |
726 (priv->strobe_dll_delay_target <<
727 ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT);
728 writel(val, ®s->strobe_dllctrl);
729 /* wait 1us to make sure strobe dll status register stable */
731 val = readl(®s->strobe_dllstat);
732 if (!(val & ESDHC_STROBE_DLL_STS_REF_LOCK))
733 pr_warn("HS400 strobe DLL status REF not lock!\n");
734 if (!(val & ESDHC_STROBE_DLL_STS_SLV_LOCK))
735 pr_warn("HS400 strobe DLL status SLV not lock!\n");
739 static int esdhc_set_timing(struct mmc *mmc)
741 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
742 struct fsl_esdhc *regs = priv->esdhc_regs;
745 mixctrl = readl(®s->mixctrl);
746 mixctrl &= ~(MIX_CTRL_DDREN | MIX_CTRL_HS400_EN);
748 switch (mmc->selected_mode) {
750 esdhc_reset_tuning(mmc);
751 writel(mixctrl, ®s->mixctrl);
755 mixctrl |= MIX_CTRL_DDREN | MIX_CTRL_HS400_EN;
756 writel(mixctrl, ®s->mixctrl);
757 esdhc_set_strobe_dll(mmc);
767 writel(mixctrl, ®s->mixctrl);
771 mixctrl |= MIX_CTRL_DDREN;
772 writel(mixctrl, ®s->mixctrl);
775 printf("Not supported %d\n", mmc->selected_mode);
779 priv->mode = mmc->selected_mode;
781 return esdhc_change_pinstate(mmc->dev);
784 static int esdhc_set_voltage(struct mmc *mmc)
786 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
787 struct fsl_esdhc *regs = priv->esdhc_regs;
790 priv->signal_voltage = mmc->signal_voltage;
791 switch (mmc->signal_voltage) {
792 case MMC_SIGNAL_VOLTAGE_330:
793 if (priv->vs18_enable)
795 #if CONFIG_IS_ENABLED(DM_REGULATOR)
796 if (!IS_ERR_OR_NULL(priv->vqmmc_dev)) {
797 ret = regulator_set_value(priv->vqmmc_dev, 3300000);
799 printf("Setting to 3.3V error");
807 esdhc_clrbits32(®s->vendorspec, ESDHC_VENDORSPEC_VSELECT);
808 if (!(esdhc_read32(®s->vendorspec) &
809 ESDHC_VENDORSPEC_VSELECT))
813 case MMC_SIGNAL_VOLTAGE_180:
814 #if CONFIG_IS_ENABLED(DM_REGULATOR)
815 if (!IS_ERR_OR_NULL(priv->vqmmc_dev)) {
816 ret = regulator_set_value(priv->vqmmc_dev, 1800000);
818 printf("Setting to 1.8V error");
823 esdhc_setbits32(®s->vendorspec, ESDHC_VENDORSPEC_VSELECT);
824 if (esdhc_read32(®s->vendorspec) & ESDHC_VENDORSPEC_VSELECT)
828 case MMC_SIGNAL_VOLTAGE_120:
835 static void esdhc_stop_tuning(struct mmc *mmc)
839 cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
841 cmd.resp_type = MMC_RSP_R1b;
843 dm_mmc_send_cmd(mmc->dev, &cmd, NULL);
846 static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode)
848 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
849 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
850 struct fsl_esdhc *regs = priv->esdhc_regs;
851 struct mmc *mmc = &plat->mmc;
852 u32 irqstaten = readl(®s->irqstaten);
853 u32 irqsigen = readl(®s->irqsigen);
854 int i, ret = -ETIMEDOUT;
857 /* clock tuning is not needed for upto 52MHz */
858 if (mmc->clock <= 52000000)
861 /* This is readw/writew SDHCI_HOST_CONTROL2 when tuning */
862 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
863 val = readl(®s->autoc12err);
864 mixctrl = readl(®s->mixctrl);
865 val &= ~MIX_CTRL_SMPCLK_SEL;
866 mixctrl &= ~(MIX_CTRL_FBCLK_SEL | MIX_CTRL_AUTO_TUNE_EN);
868 val |= MIX_CTRL_EXE_TUNE;
869 mixctrl |= MIX_CTRL_FBCLK_SEL | MIX_CTRL_AUTO_TUNE_EN;
871 writel(val, ®s->autoc12err);
872 writel(mixctrl, ®s->mixctrl);
875 /* sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); */
876 mixctrl = readl(®s->mixctrl);
877 mixctrl = MIX_CTRL_DTDSEL_READ | (mixctrl & ~MIX_CTRL_SDHCI_MASK);
878 writel(mixctrl, ®s->mixctrl);
880 writel(IRQSTATEN_BRR, ®s->irqstaten);
881 writel(IRQSTATEN_BRR, ®s->irqsigen);
884 * Issue opcode repeatedly till Execute Tuning is set to 0 or the number
885 * of loops reaches 40 times.
887 for (i = 0; i < MAX_TUNING_LOOP; i++) {
890 if (opcode == MMC_CMD_SEND_TUNING_BLOCK_HS200) {
891 if (mmc->bus_width == 8)
892 writel(0x7080, ®s->blkattr);
893 else if (mmc->bus_width == 4)
894 writel(0x7040, ®s->blkattr);
896 writel(0x7040, ®s->blkattr);
899 /* sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE) */
900 val = readl(®s->mixctrl);
901 val = MIX_CTRL_DTDSEL_READ | (val & ~MIX_CTRL_SDHCI_MASK);
902 writel(val, ®s->mixctrl);
904 /* We are using STD tuning, no need to check return value */
905 mmc_send_tuning(mmc, opcode, NULL);
907 ctrl = readl(®s->autoc12err);
908 if ((!(ctrl & MIX_CTRL_EXE_TUNE)) &&
909 (ctrl & MIX_CTRL_SMPCLK_SEL)) {
915 writel(irqstaten, ®s->irqstaten);
916 writel(irqsigen, ®s->irqsigen);
918 esdhc_stop_tuning(mmc);
924 static int esdhc_set_ios_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
926 struct fsl_esdhc *regs = priv->esdhc_regs;
927 int ret __maybe_unused;
930 /* Set the clock speed */
932 if (clock < mmc->cfg->f_min)
933 clock = mmc->cfg->f_min;
935 if (priv->clock != clock)
936 set_sysctl(priv, mmc, clock);
938 #ifdef MMC_SUPPORTS_TUNING
939 if (mmc->clk_disable) {
940 #ifdef CONFIG_FSL_USDHC
941 esdhc_clrbits32(®s->vendorspec, VENDORSPEC_CKEN);
943 esdhc_clrbits32(®s->sysctl, SYSCTL_CKEN);
946 #ifdef CONFIG_FSL_USDHC
947 esdhc_setbits32(®s->vendorspec, VENDORSPEC_PEREN |
950 esdhc_setbits32(®s->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
954 if (priv->mode != mmc->selected_mode) {
955 ret = esdhc_set_timing(mmc);
957 printf("esdhc_set_timing error %d\n", ret);
962 if (priv->signal_voltage != mmc->signal_voltage) {
963 ret = esdhc_set_voltage(mmc);
965 if (ret != -ENOTSUPP)
966 printf("esdhc_set_voltage error %d\n", ret);
972 /* Set the bus width */
973 esdhc_clrbits32(®s->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
975 if (mmc->bus_width == 4)
976 esdhc_setbits32(®s->proctl, PROCTL_DTW_4);
977 else if (mmc->bus_width == 8)
978 esdhc_setbits32(®s->proctl, PROCTL_DTW_8);
983 static int esdhc_init_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
985 struct fsl_esdhc *regs = priv->esdhc_regs;
988 /* Reset the entire host controller */
989 esdhc_setbits32(®s->sysctl, SYSCTL_RSTA);
991 /* Wait until the controller is available */
992 start = get_timer(0);
993 while ((esdhc_read32(®s->sysctl) & SYSCTL_RSTA)) {
994 if (get_timer(start) > 1000)
998 #if defined(CONFIG_FSL_USDHC)
999 /* RSTA doesn't reset MMC_BOOT register, so manually reset it */
1000 esdhc_write32(®s->mmcboot, 0x0);
1001 /* Reset MIX_CTRL and CLK_TUNE_CTRL_STATUS regs to 0 */
1002 esdhc_write32(®s->mixctrl, 0x0);
1003 esdhc_write32(®s->clktunectrlstatus, 0x0);
1005 /* Put VEND_SPEC to default value */
1006 if (priv->vs18_enable)
1007 esdhc_write32(®s->vendorspec, (VENDORSPEC_INIT |
1008 ESDHC_VENDORSPEC_VSELECT));
1010 esdhc_write32(®s->vendorspec, VENDORSPEC_INIT);
1012 /* Disable DLL_CTRL delay line */
1013 esdhc_write32(®s->dllctrl, 0x0);
1017 /* Enable cache snooping */
1018 esdhc_write32(®s->scr, 0x00000040);
1021 #ifndef CONFIG_FSL_USDHC
1022 esdhc_setbits32(®s->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
1024 esdhc_setbits32(®s->vendorspec, VENDORSPEC_HCKEN | VENDORSPEC_IPGEN);
1027 /* Set the initial clock speed */
1028 mmc_set_clock(mmc, 400000, MMC_CLK_ENABLE);
1030 /* Disable the BRR and BWR bits in IRQSTAT */
1031 esdhc_clrbits32(®s->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR);
1033 #ifdef CONFIG_MCF5441x
1034 esdhc_write32(®s->proctl, PROCTL_INIT | PROCTL_D3CD);
1036 /* Put the PROCTL reg back to the default */
1037 esdhc_write32(®s->proctl, PROCTL_INIT);
1040 /* Set timout to the maximum value */
1041 esdhc_clrsetbits32(®s->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
1046 static int esdhc_getcd_common(struct fsl_esdhc_priv *priv)
1048 struct fsl_esdhc *regs = priv->esdhc_regs;
1051 #ifdef CONFIG_ESDHC_DETECT_QUIRK
1052 if (CONFIG_ESDHC_DETECT_QUIRK)
1056 #if CONFIG_IS_ENABLED(DM_MMC)
1057 if (priv->non_removable)
1060 if (priv->broken_cd)
1062 #if CONFIG_IS_ENABLED(DM_GPIO)
1063 if (dm_gpio_is_valid(&priv->cd_gpio))
1064 return dm_gpio_get_value(&priv->cd_gpio);
1068 while (!(esdhc_read32(®s->prsstat) & PRSSTAT_CINS) && --timeout)
1074 static int esdhc_reset(struct fsl_esdhc *regs)
1078 /* reset the controller */
1079 esdhc_setbits32(®s->sysctl, SYSCTL_RSTA);
1081 /* hardware clears the bit when it is done */
1082 start = get_timer(0);
1083 while ((esdhc_read32(®s->sysctl) & SYSCTL_RSTA)) {
1084 if (get_timer(start) > 100) {
1085 printf("MMC/SD: Reset never completed.\n");
1093 #if !CONFIG_IS_ENABLED(DM_MMC)
1094 static int esdhc_getcd(struct mmc *mmc)
1096 struct fsl_esdhc_priv *priv = mmc->priv;
1098 return esdhc_getcd_common(priv);
1101 static int esdhc_init(struct mmc *mmc)
1103 struct fsl_esdhc_priv *priv = mmc->priv;
1105 return esdhc_init_common(priv, mmc);
1108 static int esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
1109 struct mmc_data *data)
1111 struct fsl_esdhc_priv *priv = mmc->priv;
1113 return esdhc_send_cmd_common(priv, mmc, cmd, data);
1116 static int esdhc_set_ios(struct mmc *mmc)
1118 struct fsl_esdhc_priv *priv = mmc->priv;
1120 return esdhc_set_ios_common(priv, mmc);
1123 static const struct mmc_ops esdhc_ops = {
1124 .getcd = esdhc_getcd,
1126 .send_cmd = esdhc_send_cmd,
1127 .set_ios = esdhc_set_ios,
1131 static int fsl_esdhc_init(struct fsl_esdhc_priv *priv,
1132 struct fsl_esdhc_plat *plat)
1134 struct mmc_config *cfg;
1135 struct fsl_esdhc *regs;
1136 u32 caps, voltage_caps;
1142 regs = priv->esdhc_regs;
1144 /* First reset the eSDHC controller */
1145 ret = esdhc_reset(regs);
1149 #ifdef CONFIG_MCF5441x
1150 /* ColdFire, using SDHC_DATA[3] for card detection */
1151 esdhc_write32(®s->proctl, PROCTL_INIT | PROCTL_D3CD);
1154 #ifndef CONFIG_FSL_USDHC
1155 esdhc_setbits32(®s->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN
1156 | SYSCTL_IPGEN | SYSCTL_CKEN);
1157 /* Clearing tuning bits in case ROM has set it already */
1158 esdhc_write32(®s->mixctrl, 0);
1159 esdhc_write32(®s->autoc12err, 0);
1160 esdhc_write32(®s->clktunectrlstatus, 0);
1162 esdhc_setbits32(®s->vendorspec, VENDORSPEC_PEREN |
1163 VENDORSPEC_HCKEN | VENDORSPEC_IPGEN | VENDORSPEC_CKEN);
1166 if (priv->vs18_enable)
1167 esdhc_setbits32(®s->vendorspec, ESDHC_VENDORSPEC_VSELECT);
1169 writel(SDHCI_IRQ_EN_BITS, ®s->irqstaten);
1171 #ifndef CONFIG_DM_MMC
1172 memset(cfg, '\0', sizeof(*cfg));
1176 caps = esdhc_read32(®s->hostcapblt);
1178 #ifdef CONFIG_MCF5441x
1180 * MCF5441x RM declares in more points that sdhc clock speed must
1181 * never exceed 25 Mhz. From this, the HS bit needs to be disabled
1182 * from host capabilities.
1184 caps &= ~ESDHC_HOSTCAPBLT_HSS;
1187 #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC135
1188 caps = caps & ~(ESDHC_HOSTCAPBLT_SRS |
1189 ESDHC_HOSTCAPBLT_VS18 | ESDHC_HOSTCAPBLT_VS30);
1192 /* T4240 host controller capabilities register should have VS33 bit */
1193 #ifdef CONFIG_SYS_FSL_MMC_HAS_CAPBLT_VS33
1194 caps = caps | ESDHC_HOSTCAPBLT_VS33;
1197 if (caps & ESDHC_HOSTCAPBLT_VS18)
1198 voltage_caps |= MMC_VDD_165_195;
1199 if (caps & ESDHC_HOSTCAPBLT_VS30)
1200 voltage_caps |= MMC_VDD_29_30 | MMC_VDD_30_31;
1201 if (caps & ESDHC_HOSTCAPBLT_VS33)
1202 voltage_caps |= MMC_VDD_32_33 | MMC_VDD_33_34;
1204 cfg->name = "FSL_SDHC";
1205 #if !CONFIG_IS_ENABLED(DM_MMC)
1206 cfg->ops = &esdhc_ops;
1208 #ifdef CONFIG_SYS_SD_VOLTAGE
1209 cfg->voltages = CONFIG_SYS_SD_VOLTAGE;
1211 cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
1213 if ((cfg->voltages & voltage_caps) == 0) {
1214 printf("voltage not supported by controller\n");
1218 if (priv->bus_width == 8)
1219 cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
1220 else if (priv->bus_width == 4)
1221 cfg->host_caps = MMC_MODE_4BIT;
1223 cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
1224 #ifdef CONFIG_SYS_FSL_ESDHC_HAS_DDR_MODE
1225 cfg->host_caps |= MMC_MODE_DDR_52MHz;
1228 if (priv->bus_width > 0) {
1229 if (priv->bus_width < 8)
1230 cfg->host_caps &= ~MMC_MODE_8BIT;
1231 if (priv->bus_width < 4)
1232 cfg->host_caps &= ~MMC_MODE_4BIT;
1235 if (caps & ESDHC_HOSTCAPBLT_HSS)
1236 cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
1238 #ifdef CONFIG_ESDHC_DETECT_8_BIT_QUIRK
1239 if (CONFIG_ESDHC_DETECT_8_BIT_QUIRK)
1240 cfg->host_caps &= ~MMC_MODE_8BIT;
1243 cfg->host_caps |= priv->caps;
1245 cfg->f_min = 400000;
1246 cfg->f_max = min(priv->sdhc_clk, (u32)200000000);
1248 cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
1250 writel(0, ®s->dllctrl);
1251 if (priv->flags & ESDHC_FLAG_USDHC) {
1252 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
1253 u32 val = readl(®s->tuning_ctrl);
1255 val |= ESDHC_STD_TUNING_EN;
1256 val &= ~ESDHC_TUNING_START_TAP_MASK;
1257 val |= priv->tuning_start_tap;
1258 val &= ~ESDHC_TUNING_STEP_MASK;
1259 val |= (priv->tuning_step) << ESDHC_TUNING_STEP_SHIFT;
1261 /* Disable the CMD CRC check for tuning, if not, need to
1262 * add some delay after every tuning command, because
1263 * hardware standard tuning logic will directly go to next
1264 * step once it detect the CMD CRC error, will not wait for
1265 * the card side to finally send out the tuning data, trigger
1266 * the buffer read ready interrupt immediately. If usdhc send
1267 * the next tuning command some eMMC card will stuck, can't
1268 * response, block the tuning procedure or the first command
1269 * after the whole tuning procedure always can't get any response.
1271 val |= ESDHC_TUNING_CMD_CRC_CHECK_DISABLE;
1272 writel(val, ®s->tuning_ctrl);
1279 #if !CONFIG_IS_ENABLED(DM_MMC)
1280 static int fsl_esdhc_cfg_to_priv(struct fsl_esdhc_cfg *cfg,
1281 struct fsl_esdhc_priv *priv)
1286 priv->esdhc_regs = (struct fsl_esdhc *)(unsigned long)(cfg->esdhc_base);
1287 priv->bus_width = cfg->max_bus_width;
1288 priv->sdhc_clk = cfg->sdhc_clk;
1289 priv->wp_enable = cfg->wp_enable;
1290 priv->vs18_enable = cfg->vs18_enable;
1295 int fsl_esdhc_initialize(struct bd_info *bis, struct fsl_esdhc_cfg *cfg)
1297 struct fsl_esdhc_plat *plat;
1298 struct fsl_esdhc_priv *priv;
1305 priv = calloc(sizeof(struct fsl_esdhc_priv), 1);
1308 plat = calloc(sizeof(struct fsl_esdhc_plat), 1);
1314 ret = fsl_esdhc_cfg_to_priv(cfg, priv);
1316 debug("%s xlate failure\n", __func__);
1322 ret = fsl_esdhc_init(priv, plat);
1324 debug("%s init failure\n", __func__);
1330 mmc = mmc_create(&plat->cfg, priv);
1339 int fsl_esdhc_mmc_init(struct bd_info *bis)
1341 struct fsl_esdhc_cfg *cfg;
1343 cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1);
1344 cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR;
1345 cfg->sdhc_clk = gd->arch.sdhc_clk;
1346 return fsl_esdhc_initialize(bis, cfg);
1350 #ifdef CONFIG_OF_LIBFDT
1351 __weak int esdhc_status_fixup(void *blob, const char *compat)
1353 #ifdef CONFIG_FSL_ESDHC_PIN_MUX
1354 if (!hwconfig("esdhc")) {
1355 do_fixup_by_compat(blob, compat, "status", "disabled",
1356 sizeof("disabled"), 1);
1363 void fdt_fixup_esdhc(void *blob, struct bd_info *bd)
1365 const char *compat = "fsl,esdhc";
1367 if (esdhc_status_fixup(blob, compat))
1370 do_fixup_by_compat_u32(blob, compat, "clock-frequency",
1371 gd->arch.sdhc_clk, 1);
1375 #if CONFIG_IS_ENABLED(DM_MMC)
1376 #include <asm/arch/clock.h>
1377 __weak void init_clk_usdhc(u32 index)
1381 static int fsl_esdhc_probe(struct udevice *dev)
1383 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
1384 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1385 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1386 const void *fdt = gd->fdt_blob;
1387 int node = dev_of_offset(dev);
1388 struct esdhc_soc_data *data =
1389 (struct esdhc_soc_data *)dev_get_driver_data(dev);
1390 #if CONFIG_IS_ENABLED(DM_REGULATOR)
1391 struct udevice *vqmmc_dev;
1396 #if !CONFIG_IS_ENABLED(BLK)
1397 struct blk_desc *bdesc;
1401 addr = dev_read_addr(dev);
1402 if (addr == FDT_ADDR_T_NONE)
1404 priv->esdhc_regs = (struct fsl_esdhc *)addr;
1408 priv->flags = data->flags;
1410 val = dev_read_u32_default(dev, "bus-width", -1);
1412 priv->bus_width = 8;
1414 priv->bus_width = 4;
1416 priv->bus_width = 1;
1418 val = fdtdec_get_int(fdt, node, "fsl,tuning-step", 1);
1419 priv->tuning_step = val;
1420 val = fdtdec_get_int(fdt, node, "fsl,tuning-start-tap",
1421 ESDHC_TUNING_START_TAP_DEFAULT);
1422 priv->tuning_start_tap = val;
1423 val = fdtdec_get_int(fdt, node, "fsl,strobe-dll-delay-target",
1424 ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_DEFAULT);
1425 priv->strobe_dll_delay_target = val;
1427 if (dev_read_bool(dev, "broken-cd"))
1428 priv->broken_cd = 1;
1430 if (dev_read_bool(dev, "non-removable")) {
1431 priv->non_removable = 1;
1433 priv->non_removable = 0;
1434 #if CONFIG_IS_ENABLED(DM_GPIO)
1435 gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio,
1440 if (dev_read_prop(dev, "fsl,wp-controller", NULL)) {
1441 priv->wp_enable = 1;
1443 priv->wp_enable = 0;
1444 #if CONFIG_IS_ENABLED(DM_GPIO)
1445 gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio,
1450 priv->vs18_enable = 0;
1452 #if CONFIG_IS_ENABLED(DM_REGULATOR)
1454 * If emmc I/O has a fixed voltage at 1.8V, this must be provided,
1455 * otherwise, emmc will work abnormally.
1457 ret = device_get_supply_regulator(dev, "vqmmc-supply", &vqmmc_dev);
1459 dev_dbg(dev, "no vqmmc-supply\n");
1461 priv->vqmmc_dev = vqmmc_dev;
1462 ret = regulator_set_enable(vqmmc_dev, true);
1464 dev_err(dev, "fail to enable vqmmc-supply\n");
1468 if (regulator_get_value(vqmmc_dev) == 1800000)
1469 priv->vs18_enable = 1;
1475 * Because lack of clk driver, if SDHC clk is not enabled,
1476 * need to enable it first before this driver is invoked.
1478 * we use MXC_ESDHC_CLK to get clk freq.
1479 * If one would like to make this function work,
1480 * the aliases should be provided in dts as this:
1488 * Then if your board only supports mmc2 and mmc3, but we can
1489 * correctly get the seq as 2 and 3, then let mxc_get_clock
1493 init_clk_usdhc(dev->seq);
1495 #if CONFIG_IS_ENABLED(CLK)
1496 /* Assigned clock already set clock */
1497 ret = clk_get_by_name(dev, "per", &priv->per_clk);
1499 printf("Failed to get per_clk\n");
1502 ret = clk_enable(&priv->per_clk);
1504 printf("Failed to enable per_clk\n");
1508 priv->sdhc_clk = clk_get_rate(&priv->per_clk);
1510 priv->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK + dev->seq);
1511 if (priv->sdhc_clk <= 0) {
1512 dev_err(dev, "Unable to get clk for %s\n", dev->name);
1517 ret = fsl_esdhc_init(priv, plat);
1519 dev_err(dev, "fsl_esdhc_init failure\n");
1523 ret = mmc_of_parse(dev, &plat->cfg);
1528 mmc->cfg = &plat->cfg;
1530 #if !CONFIG_IS_ENABLED(BLK)
1533 /* Setup dsr related values */
1535 mmc->dsr = ESDHC_DRIVER_STAGE_VALUE;
1536 /* Setup the universal parts of the block interface just once */
1537 bdesc = mmc_get_blk_desc(mmc);
1538 bdesc->if_type = IF_TYPE_MMC;
1539 bdesc->removable = 1;
1540 bdesc->devnum = mmc_get_next_devnum();
1541 bdesc->block_read = mmc_bread;
1542 bdesc->block_write = mmc_bwrite;
1543 bdesc->block_erase = mmc_berase;
1545 /* setup initial part type */
1546 bdesc->part_type = mmc->cfg->part_type;
1552 return esdhc_init_common(priv, mmc);
1555 #if CONFIG_IS_ENABLED(DM_MMC)
1556 static int fsl_esdhc_get_cd(struct udevice *dev)
1558 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1560 return esdhc_getcd_common(priv);
1563 static int fsl_esdhc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
1564 struct mmc_data *data)
1566 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1567 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1569 return esdhc_send_cmd_common(priv, &plat->mmc, cmd, data);
1572 static int fsl_esdhc_set_ios(struct udevice *dev)
1574 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1575 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1577 return esdhc_set_ios_common(priv, &plat->mmc);
1580 #if CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)
1581 static int fsl_esdhc_set_enhanced_strobe(struct udevice *dev)
1583 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1584 struct fsl_esdhc *regs = priv->esdhc_regs;
1587 m = readl(®s->mixctrl);
1588 m |= MIX_CTRL_HS400_ES;
1589 writel(m, ®s->mixctrl);
1595 static const struct dm_mmc_ops fsl_esdhc_ops = {
1596 .get_cd = fsl_esdhc_get_cd,
1597 .send_cmd = fsl_esdhc_send_cmd,
1598 .set_ios = fsl_esdhc_set_ios,
1599 #ifdef MMC_SUPPORTS_TUNING
1600 .execute_tuning = fsl_esdhc_execute_tuning,
1602 #if CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)
1603 .set_enhanced_strobe = fsl_esdhc_set_enhanced_strobe,
1608 static struct esdhc_soc_data usdhc_imx7d_data = {
1609 .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
1610 | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
1614 static struct esdhc_soc_data usdhc_imx8qm_data = {
1615 .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING |
1616 ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200 |
1617 ESDHC_FLAG_HS400 | ESDHC_FLAG_HS400_ES,
1620 static const struct udevice_id fsl_esdhc_ids[] = {
1621 { .compatible = "fsl,imx53-esdhc", },
1622 { .compatible = "fsl,imx6ul-usdhc", },
1623 { .compatible = "fsl,imx6sx-usdhc", },
1624 { .compatible = "fsl,imx6sl-usdhc", },
1625 { .compatible = "fsl,imx6q-usdhc", },
1626 { .compatible = "fsl,imx7d-usdhc", .data = (ulong)&usdhc_imx7d_data,},
1627 { .compatible = "fsl,imx7ulp-usdhc", },
1628 { .compatible = "fsl,imx8qm-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
1629 { .compatible = "fsl,imx8mm-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
1630 { .compatible = "fsl,imx8mn-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
1631 { .compatible = "fsl,imx8mq-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
1632 { .compatible = "fsl,imxrt-usdhc", },
1633 { .compatible = "fsl,esdhc", },
1637 #if CONFIG_IS_ENABLED(BLK)
1638 static int fsl_esdhc_bind(struct udevice *dev)
1640 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1642 return mmc_bind(dev, &plat->mmc, &plat->cfg);
1646 U_BOOT_DRIVER(fsl_esdhc) = {
1647 .name = "fsl-esdhc-mmc",
1649 .of_match = fsl_esdhc_ids,
1650 .ops = &fsl_esdhc_ops,
1651 #if CONFIG_IS_ENABLED(BLK)
1652 .bind = fsl_esdhc_bind,
1654 .probe = fsl_esdhc_probe,
1655 .platdata_auto_alloc_size = sizeof(struct fsl_esdhc_plat),
1656 .priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv),