blob: 926113f79d363a3e69bcb3ca46fb8fb3c2178e91 [file] [log] [blame]
Yangbo Lu982f4252019-06-21 11:42:27 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2007, 2010-2011 Freescale Semiconductor, Inc
Yangbo Lu023d4192021-06-03 10:51:18 +08004 * Copyright 2019, 2021 NXP
Yangbo Lu982f4252019-06-21 11:42:27 +08005 * Andy Fleming
6 * Yangbo Lu <yangbo.lu@nxp.com>
7 *
8 * Based vaguely on the pxa mmc code:
9 * (C) Copyright 2003
10 * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net
11 */
12
13#include <config.h>
Yangbo Lu982f4252019-06-21 11:42:27 +080014#include <command.h>
15#include <clk.h>
Simon Glass63334482019-11-14 12:57:39 -070016#include <cpu_func.h>
Yangbo Lu982f4252019-06-21 11:42:27 +080017#include <errno.h>
18#include <hwconfig.h>
Simon Glass0f2af882020-05-10 11:40:05 -060019#include <log.h>
Yangbo Lu982f4252019-06-21 11:42:27 +080020#include <mmc.h>
21#include <part.h>
Simon Glass274e0b02020-05-10 11:39:56 -060022#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060023#include <asm/global_data.h>
Simon Glass9bc15642020-02-03 07:36:16 -070024#include <dm/device_compat.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060025#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060026#include <linux/delay.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070027#include <linux/err.h>
Simon Glassbdd5f812023-09-14 18:21:46 -060028#include <linux/printk.h>
Yangbo Lu982f4252019-06-21 11:42:27 +080029#include <power/regulator.h>
30#include <malloc.h>
31#include <fsl_esdhc_imx.h>
32#include <fdt_support.h>
33#include <asm/io.h>
34#include <dm.h>
35#include <asm-generic/gpio.h>
36#include <dm/pinctrl.h>
Walter Lozano8aff6732020-07-29 12:31:17 -030037#include <dt-structs.h>
38#include <mapmem.h>
39#include <dm/ofnode.h>
Haibo Chene6a999b2020-09-01 15:34:06 +080040#include <linux/iopoll.h>
Sean Anderson120fc012021-11-23 15:03:43 -050041#include <linux/dma-mapping.h>
Yangbo Lu982f4252019-06-21 11:42:27 +080042
Yangbo Lu982f4252019-06-21 11:42:27 +080043DECLARE_GLOBAL_DATA_PTR;
44
45#define SDHCI_IRQ_EN_BITS (IRQSTATEN_CC | IRQSTATEN_TC | \
46 IRQSTATEN_CINT | \
47 IRQSTATEN_CTOE | IRQSTATEN_CCE | IRQSTATEN_CEBE | \
48 IRQSTATEN_CIE | IRQSTATEN_DTOE | IRQSTATEN_DCE | \
49 IRQSTATEN_DEBE | IRQSTATEN_BRR | IRQSTATEN_BWR | \
50 IRQSTATEN_DINT)
51#define MAX_TUNING_LOOP 40
Yangbo Lu982f4252019-06-21 11:42:27 +080052
53struct fsl_esdhc {
54 uint dsaddr; /* SDMA system address register */
55 uint blkattr; /* Block attributes register */
56 uint cmdarg; /* Command argument register */
57 uint xfertyp; /* Transfer type register */
58 uint cmdrsp0; /* Command response 0 register */
59 uint cmdrsp1; /* Command response 1 register */
60 uint cmdrsp2; /* Command response 2 register */
61 uint cmdrsp3; /* Command response 3 register */
62 uint datport; /* Buffer data port register */
63 uint prsstat; /* Present state register */
64 uint proctl; /* Protocol control register */
65 uint sysctl; /* System Control Register */
66 uint irqstat; /* Interrupt status register */
67 uint irqstaten; /* Interrupt status enable register */
68 uint irqsigen; /* Interrupt signal enable register */
69 uint autoc12err; /* Auto CMD error status register */
70 uint hostcapblt; /* Host controller capabilities register */
71 uint wml; /* Watermark level register */
72 uint mixctrl; /* For USDHC */
73 char reserved1[4]; /* reserved */
74 uint fevt; /* Force event register */
75 uint admaes; /* ADMA error status register */
76 uint adsaddr; /* ADMA system address register */
77 char reserved2[4];
78 uint dllctrl;
79 uint dllstat;
80 uint clktunectrlstatus;
81 char reserved3[4];
82 uint strobe_dllctrl;
83 uint strobe_dllstat;
84 char reserved4[72];
85 uint vendorspec;
86 uint mmcboot;
87 uint vendorspec2;
Giulio Benetti65b5ec12020-01-10 15:51:46 +010088 uint tuning_ctrl; /* on i.MX6/7/8/RT */
Yangbo Lu982f4252019-06-21 11:42:27 +080089 char reserved5[44];
90 uint hostver; /* Host controller version register */
91 char reserved6[4]; /* reserved */
92 uint dmaerraddr; /* DMA error address register */
93 char reserved7[4]; /* reserved */
94 uint dmaerrattr; /* DMA error attribute register */
95 char reserved8[4]; /* reserved */
96 uint hostcapblt2; /* Host controller capabilities register 2 */
97 char reserved9[8]; /* reserved */
98 uint tcr; /* Tuning control register */
99 char reserved10[28]; /* reserved */
100 uint sddirctl; /* SD direction control register */
101 char reserved11[712];/* reserved */
102 uint scr; /* eSDHC control register */
103};
104
105struct fsl_esdhc_plat {
Walter Lozano8aff6732020-07-29 12:31:17 -0300106#if CONFIG_IS_ENABLED(OF_PLATDATA)
107 /* Put this first since driver model will copy the data here */
108 struct dtd_fsl_esdhc dtplat;
109#endif
110
Yangbo Lu982f4252019-06-21 11:42:27 +0800111 struct mmc_config cfg;
112 struct mmc mmc;
113};
114
115struct esdhc_soc_data {
116 u32 flags;
Yangbo Lu982f4252019-06-21 11:42:27 +0800117};
118
119/**
120 * struct fsl_esdhc_priv
121 *
122 * @esdhc_regs: registers of the sdhc controller
123 * @sdhc_clk: Current clk of the sdhc controller
Yangbo Lu982f4252019-06-21 11:42:27 +0800124 * @cfg: mmc config
125 * @mmc: mmc
126 * Following is used when Driver Model is enabled for MMC
127 * @dev: pointer for the device
Fabio Estevam7e3d8a92020-01-06 20:11:27 -0300128 * @broken_cd: 0: use GPIO for card detect; 1: Do not use GPIO for card detect
Yangbo Lu982f4252019-06-21 11:42:27 +0800129 * @wp_enable: 1: enable checking wp; 0: no check
130 * @vs18_enable: 1: use 1.8V voltage; 0: use 3.3V
131 * @flags: ESDHC_FLAG_xx in include/fsl_esdhc_imx.h
132 * @caps: controller capabilities
133 * @tuning_step: tuning step setting in tuning_ctrl register
134 * @start_tuning_tap: the start point for tuning in tuning_ctrl register
135 * @strobe_dll_delay_target: settings in strobe_dllctrl
136 * @signal_voltage: indicating the current voltage
Haibo Chen26154952021-03-22 18:55:38 +0800137 * @signal_voltage_switch_extra_delay_ms: extra delay for IO voltage switch
Yangbo Lu982f4252019-06-21 11:42:27 +0800138 * @cd_gpio: gpio for card detection
139 * @wp_gpio: gpio for write protection
140 */
141struct fsl_esdhc_priv {
142 struct fsl_esdhc *esdhc_regs;
143 unsigned int sdhc_clk;
144 struct clk per_clk;
Peng Fane5b6e5c2024-10-01 21:07:53 +0800145 struct clk_bulk clk_bulk;
Yangbo Lu982f4252019-06-21 11:42:27 +0800146 unsigned int clock;
147 unsigned int mode;
Sean Anderson80b81612022-01-12 08:18:52 +0900148#if !CONFIG_IS_ENABLED(DM_MMC)
Yangbo Lu982f4252019-06-21 11:42:27 +0800149 struct mmc *mmc;
150#endif
151 struct udevice *dev;
Fabio Estevam7e3d8a92020-01-06 20:11:27 -0300152 int broken_cd;
Yangbo Lu982f4252019-06-21 11:42:27 +0800153 int wp_enable;
154 int vs18_enable;
155 u32 flags;
156 u32 caps;
157 u32 tuning_step;
158 u32 tuning_start_tap;
159 u32 strobe_dll_delay_target;
160 u32 signal_voltage;
Haibo Chen26154952021-03-22 18:55:38 +0800161 u32 signal_voltage_switch_extra_delay_ms;
Yangbo Lu982f4252019-06-21 11:42:27 +0800162 struct udevice *vqmmc_dev;
163 struct udevice *vmmc_dev;
Simon Glassfa4689a2019-12-06 21:41:35 -0700164#if CONFIG_IS_ENABLED(DM_GPIO)
Yangbo Lu982f4252019-06-21 11:42:27 +0800165 struct gpio_desc cd_gpio;
166 struct gpio_desc wp_gpio;
167#endif
Sean Anderson120fc012021-11-23 15:03:43 -0500168 dma_addr_t dma_addr;
Yangbo Lu982f4252019-06-21 11:42:27 +0800169};
170
171/* Return the XFERTYP flags for a given command and data packet */
172static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data)
173{
174 uint xfertyp = 0;
175
176 if (data) {
177 xfertyp |= XFERTYP_DPSEL;
Sean Anderson218dfa12021-11-23 15:03:45 -0500178 if (!IS_ENABLED(CONFIG_SYS_FSL_ESDHC_USE_PIO) &&
179 cmd->cmdidx != MMC_CMD_SEND_TUNING_BLOCK &&
180 cmd->cmdidx != MMC_CMD_SEND_TUNING_BLOCK_HS200)
181 xfertyp |= XFERTYP_DMAEN;
Yangbo Lu982f4252019-06-21 11:42:27 +0800182 if (data->blocks > 1) {
183 xfertyp |= XFERTYP_MSBSEL;
184 xfertyp |= XFERTYP_BCEN;
Sean Anderson218dfa12021-11-23 15:03:45 -0500185 if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_ESDHC111))
186 xfertyp |= XFERTYP_AC12EN;
Yangbo Lu982f4252019-06-21 11:42:27 +0800187 }
188
189 if (data->flags & MMC_DATA_READ)
190 xfertyp |= XFERTYP_DTDSEL;
191 }
192
193 if (cmd->resp_type & MMC_RSP_CRC)
194 xfertyp |= XFERTYP_CCCEN;
195 if (cmd->resp_type & MMC_RSP_OPCODE)
196 xfertyp |= XFERTYP_CICEN;
197 if (cmd->resp_type & MMC_RSP_136)
198 xfertyp |= XFERTYP_RSPTYP_136;
199 else if (cmd->resp_type & MMC_RSP_BUSY)
200 xfertyp |= XFERTYP_RSPTYP_48_BUSY;
201 else if (cmd->resp_type & MMC_RSP_PRESENT)
202 xfertyp |= XFERTYP_RSPTYP_48;
203
204 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
205 xfertyp |= XFERTYP_CMDTYP_ABORT;
206
207 return XFERTYP_CMD(cmd->cmdidx) | xfertyp;
208}
209
Yangbo Lu982f4252019-06-21 11:42:27 +0800210/*
211 * PIO Read/Write Mode reduce the performace as DMA is not used in this mode.
212 */
213static void esdhc_pio_read_write(struct fsl_esdhc_priv *priv,
214 struct mmc_data *data)
215{
216 struct fsl_esdhc *regs = priv->esdhc_regs;
217 uint blocks;
218 char *buffer;
219 uint databuf;
220 uint size;
221 uint irqstat;
222 ulong start;
223
224 if (data->flags & MMC_DATA_READ) {
225 blocks = data->blocks;
226 buffer = data->dest;
227 while (blocks) {
228 start = get_timer(0);
229 size = data->blocksize;
230 irqstat = esdhc_read32(&regs->irqstat);
231 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BREN)) {
232 if (get_timer(start) > PIO_TIMEOUT) {
233 printf("\nData Read Failed in PIO Mode.");
234 return;
235 }
236 }
237 while (size && (!(irqstat & IRQSTAT_TC))) {
238 udelay(100); /* Wait before last byte transfer complete */
239 irqstat = esdhc_read32(&regs->irqstat);
240 databuf = in_le32(&regs->datport);
241 *((uint *)buffer) = databuf;
242 buffer += 4;
243 size -= 4;
244 }
245 blocks--;
246 }
247 } else {
248 blocks = data->blocks;
249 buffer = (char *)data->src;
250 while (blocks) {
251 start = get_timer(0);
252 size = data->blocksize;
253 irqstat = esdhc_read32(&regs->irqstat);
254 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BWEN)) {
255 if (get_timer(start) > PIO_TIMEOUT) {
256 printf("\nData Write Failed in PIO Mode.");
257 return;
258 }
259 }
260 while (size && (!(irqstat & IRQSTAT_TC))) {
261 udelay(100); /* Wait before last byte transfer complete */
262 databuf = *((uint *)buffer);
263 buffer += 4;
264 size -= 4;
265 irqstat = esdhc_read32(&regs->irqstat);
266 out_le32(&regs->datport, databuf);
267 }
268 blocks--;
269 }
270 }
271}
Yangbo Lu982f4252019-06-21 11:42:27 +0800272
Sean Andersonaa6d91d2021-11-23 15:03:44 -0500273static void esdhc_setup_watermark_level(struct fsl_esdhc_priv *priv,
274 struct mmc_data *data)
Yangbo Lu982f4252019-06-21 11:42:27 +0800275{
Yangbo Lu982f4252019-06-21 11:42:27 +0800276 struct fsl_esdhc *regs = priv->esdhc_regs;
Sean Andersonaa6d91d2021-11-23 15:03:44 -0500277 uint wml_value = data->blocksize / 4;
Yangbo Lu982f4252019-06-21 11:42:27 +0800278
279 if (data->flags & MMC_DATA_READ) {
280 if (wml_value > WML_RD_WML_MAX)
281 wml_value = WML_RD_WML_MAX_VAL;
282
283 esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
Yangbo Lu982f4252019-06-21 11:42:27 +0800284 } else {
Yangbo Lu982f4252019-06-21 11:42:27 +0800285 if (wml_value > WML_WR_WML_MAX)
286 wml_value = WML_WR_WML_MAX_VAL;
Sean Andersonaa6d91d2021-11-23 15:03:44 -0500287
288 esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK,
289 wml_value << 16);
290 }
291}
Sean Andersonaa6d91d2021-11-23 15:03:44 -0500292
293static void esdhc_setup_dma(struct fsl_esdhc_priv *priv, struct mmc_data *data)
294{
295 uint trans_bytes = data->blocksize * data->blocks;
296 struct fsl_esdhc *regs = priv->esdhc_regs;
297 void *buf;
298
299 if (data->flags & MMC_DATA_WRITE)
300 buf = (void *)data->src;
301 else
302 buf = data->dest;
303
304 priv->dma_addr = dma_map_single(buf, trans_bytes,
305 mmc_get_dma_dir(data));
306 if (upper_32_bits(priv->dma_addr))
307 printf("Cannot use 64 bit addresses with SDMA\n");
308 esdhc_write32(&regs->dsaddr, lower_32_bits(priv->dma_addr));
309 esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
310}
311
312static int esdhc_setup_data(struct fsl_esdhc_priv *priv, struct mmc *mmc,
313 struct mmc_data *data)
314{
315 int timeout;
316 bool is_write = data->flags & MMC_DATA_WRITE;
317 struct fsl_esdhc *regs = priv->esdhc_regs;
318
319 if (is_write) {
320 if (priv->wp_enable && !(esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL)) {
321 printf("Cannot write to locked SD card.\n");
322 return -EINVAL;
Yangbo Lu982f4252019-06-21 11:42:27 +0800323 } else {
Simon Glassfa4689a2019-12-06 21:41:35 -0700324#if CONFIG_IS_ENABLED(DM_GPIO)
325 if (dm_gpio_is_valid(&priv->wp_gpio) &&
326 dm_gpio_get_value(&priv->wp_gpio)) {
Sean Andersonaa6d91d2021-11-23 15:03:44 -0500327 printf("Cannot write to locked SD card.\n");
328 return -EINVAL;
Yangbo Lu982f4252019-06-21 11:42:27 +0800329 }
330#endif
331 }
Yangbo Lu982f4252019-06-21 11:42:27 +0800332 }
333
Marcel Ziswiler86376fd2022-01-31 23:08:31 +0100334 esdhc_setup_watermark_level(priv, data);
335 if (!IS_ENABLED(CONFIG_SYS_FSL_ESDHC_USE_PIO))
Sean Anderson218dfa12021-11-23 15:03:45 -0500336 esdhc_setup_dma(priv, data);
Yangbo Lu982f4252019-06-21 11:42:27 +0800337
338 /* Calculate the timeout period for data transactions */
339 /*
340 * 1)Timeout period = (2^(timeout+13)) SD Clock cycles
341 * 2)Timeout period should be minimum 0.250sec as per SD Card spec
342 * So, Number of SD Clock cycles for 0.25sec should be minimum
343 * (SD Clock/sec * 0.25 sec) SD Clock cycles
344 * = (mmc->clock * 1/4) SD Clock cycles
345 * As 1) >= 2)
346 * => (2^(timeout+13)) >= mmc->clock * 1/4
347 * Taking log2 both the sides
348 * => timeout + 13 >= log2(mmc->clock/4)
349 * Rounding up to next power of 2
350 * => timeout + 13 = log2(mmc->clock/4) + 1
351 * => timeout + 13 = fls(mmc->clock/4)
352 *
353 * However, the MMC spec "It is strongly recommended for hosts to
354 * implement more than 500ms timeout value even if the card
355 * indicates the 250ms maximum busy length." Even the previous
356 * value of 300ms is known to be insufficient for some cards.
357 * So, we use
358 * => timeout + 13 = fls(mmc->clock/2)
359 */
360 timeout = fls(mmc->clock/2);
361 timeout -= 13;
362
363 if (timeout > 14)
364 timeout = 14;
365
366 if (timeout < 0)
367 timeout = 0;
368
Sean Anderson218dfa12021-11-23 15:03:45 -0500369 if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_ESDHC_A001) &&
370 (timeout == 4 || timeout == 8 || timeout == 12))
Yangbo Lu982f4252019-06-21 11:42:27 +0800371 timeout++;
Yangbo Lu982f4252019-06-21 11:42:27 +0800372
Tom Rini133facb2025-02-27 09:29:42 -0600373 if (IS_ENABLED(CONFIG_ESDHCI_QUIRK_BROKEN_TIMEOUT_VALUE))
Sean Anderson218dfa12021-11-23 15:03:45 -0500374 timeout = 0xE;
375
Yangbo Lu982f4252019-06-21 11:42:27 +0800376 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16);
377
378 return 0;
379}
380
Sean Anderson3e330792021-11-23 15:03:46 -0500381#if IS_ENABLED(CONFIG_MCF5441x)
Yangbo Lu982f4252019-06-21 11:42:27 +0800382/*
383 * Swaps 32-bit words to little-endian byte order.
384 */
385static inline void sd_swap_dma_buff(struct mmc_data *data)
386{
387 int i, size = data->blocksize >> 2;
388 u32 *buffer = (u32 *)data->dest;
389 u32 sw;
390
391 while (data->blocks--) {
392 for (i = 0; i < size; i++) {
393 sw = __sw32(*buffer);
394 *buffer++ = sw;
395 }
396 }
397}
Sean Anderson218dfa12021-11-23 15:03:45 -0500398#else
399static inline void sd_swap_dma_buff(struct mmc_data *data)
400{
401 return;
402}
Yangbo Lu982f4252019-06-21 11:42:27 +0800403#endif
404
405/*
406 * Sends a command out on the bus. Takes the mmc pointer,
407 * a command pointer, and an optional data pointer.
408 */
409static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
410 struct mmc_cmd *cmd, struct mmc_data *data)
411{
412 int err = 0;
413 uint xfertyp;
414 uint irqstat;
415 u32 flags = IRQSTAT_CC | IRQSTAT_CTOE;
416 struct fsl_esdhc *regs = priv->esdhc_regs;
417 unsigned long start;
418
Sean Anderson218dfa12021-11-23 15:03:45 -0500419 if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_ESDHC111) &&
420 cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
Yangbo Lu982f4252019-06-21 11:42:27 +0800421 return 0;
Yangbo Lu982f4252019-06-21 11:42:27 +0800422
423 esdhc_write32(&regs->irqstat, -1);
424
425 sync();
426
427 /* Wait for the bus to be idle */
428 while ((esdhc_read32(&regs->prsstat) & PRSSTAT_CICHB) ||
429 (esdhc_read32(&regs->prsstat) & PRSSTAT_CIDHB))
430 ;
431
432 while (esdhc_read32(&regs->prsstat) & PRSSTAT_DLA)
433 ;
434
Yangbo Lu982f4252019-06-21 11:42:27 +0800435 /* Set up for a data transfer if we have one */
436 if (data) {
437 err = esdhc_setup_data(priv, mmc, data);
438 if(err)
439 return err;
Yangbo Lu982f4252019-06-21 11:42:27 +0800440 }
441
442 /* Figure out the transfer arguments */
443 xfertyp = esdhc_xfertyp(cmd, data);
444
445 /* Mask all irqs */
446 esdhc_write32(&regs->irqsigen, 0);
447
448 /* Send the command */
449 esdhc_write32(&regs->cmdarg, cmd->cmdarg);
Simon Glass87f79c52022-01-22 05:07:24 -0700450 if (IS_ENABLED(CONFIG_FSL_USDHC)) {
Sean Anderson3e330792021-11-23 15:03:46 -0500451 u32 mixctrl = esdhc_read32(&regs->mixctrl);
452
453 esdhc_write32(&regs->mixctrl,
454 (mixctrl & 0xFFFFFF80) | (xfertyp & 0x7F)
455 | (mmc->ddr_mode ? XFERTYP_DDREN : 0));
456 esdhc_write32(&regs->xfertyp, xfertyp & 0xFFFF0000);
457 } else {
458 esdhc_write32(&regs->xfertyp, xfertyp);
459 }
Yangbo Lu982f4252019-06-21 11:42:27 +0800460
461 if ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK) ||
462 (cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200))
463 flags = IRQSTAT_BRR;
464
465 /* Wait for the command to complete */
466 start = get_timer(0);
467 while (!(esdhc_read32(&regs->irqstat) & flags)) {
468 if (get_timer(start) > 1000) {
469 err = -ETIMEDOUT;
470 goto out;
471 }
472 }
473
474 irqstat = esdhc_read32(&regs->irqstat);
475
476 if (irqstat & CMD_ERR) {
477 err = -ECOMM;
478 goto out;
479 }
480
481 if (irqstat & IRQSTAT_CTOE) {
482 err = -ETIMEDOUT;
483 goto out;
484 }
485
Yangbo Lu982f4252019-06-21 11:42:27 +0800486 /* Workaround for ESDHC errata ENGcm03648 */
487 if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
Peng Fan3dbea592019-07-10 09:35:30 +0000488 int timeout = 50000;
Yangbo Lu982f4252019-06-21 11:42:27 +0800489
Peng Fan3dbea592019-07-10 09:35:30 +0000490 /* Poll on DATA0 line for cmd with busy signal for 5000 ms */
Yangbo Lu982f4252019-06-21 11:42:27 +0800491 while (timeout > 0 && !(esdhc_read32(&regs->prsstat) &
492 PRSSTAT_DAT0)) {
493 udelay(100);
494 timeout--;
495 }
496
497 if (timeout <= 0) {
498 printf("Timeout waiting for DAT0 to go high!\n");
499 err = -ETIMEDOUT;
500 goto out;
501 }
502 }
503
504 /* Copy the response to the response buffer */
505 if (cmd->resp_type & MMC_RSP_136) {
506 u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0;
507
508 cmdrsp3 = esdhc_read32(&regs->cmdrsp3);
509 cmdrsp2 = esdhc_read32(&regs->cmdrsp2);
510 cmdrsp1 = esdhc_read32(&regs->cmdrsp1);
511 cmdrsp0 = esdhc_read32(&regs->cmdrsp0);
512 cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
513 cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
514 cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
515 cmd->response[3] = (cmdrsp0 << 8);
516 } else
517 cmd->response[0] = esdhc_read32(&regs->cmdrsp0);
518
519 /* Wait until all of the blocks are transferred */
520 if (data) {
Sean Anderson218dfa12021-11-23 15:03:45 -0500521 if (IS_ENABLED(CONFIG_SYS_FSL_ESDHC_USE_PIO)) {
522 esdhc_pio_read_write(priv, data);
523 } else {
524 flags = DATA_COMPLETE;
525 if (cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK ||
526 cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200)
527 flags = IRQSTAT_BRR;
Yangbo Lu982f4252019-06-21 11:42:27 +0800528
Sean Anderson218dfa12021-11-23 15:03:45 -0500529 do {
530 irqstat = esdhc_read32(&regs->irqstat);
Yangbo Lu982f4252019-06-21 11:42:27 +0800531
Sean Anderson218dfa12021-11-23 15:03:45 -0500532 if (irqstat & IRQSTAT_DTOE) {
533 err = -ETIMEDOUT;
534 goto out;
535 }
Yangbo Lu982f4252019-06-21 11:42:27 +0800536
Sean Anderson218dfa12021-11-23 15:03:45 -0500537 if (irqstat & DATA_ERR) {
538 err = -ECOMM;
539 goto out;
540 }
541 } while ((irqstat & flags) != flags);
Yangbo Lu982f4252019-06-21 11:42:27 +0800542
Sean Anderson218dfa12021-11-23 15:03:45 -0500543 /*
544 * Need invalidate the dcache here again to avoid any
545 * cache-fill during the DMA operations such as the
546 * speculative pre-fetching etc.
547 */
548 dma_unmap_single(priv->dma_addr,
549 data->blocks * data->blocksize,
550 mmc_get_dma_dir(data));
551 if (IS_ENABLED(CONFIG_MCF5441x) &&
552 (data->flags & MMC_DATA_READ))
553 sd_swap_dma_buff(data);
554 }
Yangbo Lu982f4252019-06-21 11:42:27 +0800555 }
556
557out:
558 /* Reset CMD and DATA portions on error */
559 if (err) {
560 esdhc_write32(&regs->sysctl, esdhc_read32(&regs->sysctl) |
561 SYSCTL_RSTC);
562 while (esdhc_read32(&regs->sysctl) & SYSCTL_RSTC)
563 ;
564
565 if (data) {
566 esdhc_write32(&regs->sysctl,
567 esdhc_read32(&regs->sysctl) |
568 SYSCTL_RSTD);
569 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTD))
570 ;
571 }
572
573 /* If this was CMD11, then notify that power cycle is needed */
574 if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V)
575 printf("CMD11 to switch to 1.8V mode failed, card requires power cycle.\n");
576 }
577
578 esdhc_write32(&regs->irqstat, -1);
579
580 return err;
581}
582
583static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
584{
585 struct fsl_esdhc *regs = priv->esdhc_regs;
586 int div = 1;
Haibo Chene6a999b2020-09-01 15:34:06 +0800587 u32 tmp;
Sean Anderson218dfa12021-11-23 15:03:45 -0500588 int ret, pre_div;
Yangbo Lu982f4252019-06-21 11:42:27 +0800589 int ddr_pre_div = mmc->ddr_mode ? 2 : 1;
590 int sdhc_clk = priv->sdhc_clk;
591 uint clk;
592
Sean Anderson3e330792021-11-23 15:03:46 -0500593#if IS_ENABLED(CONFIG_MX53)
Haibo Chen84516a72022-02-11 19:16:56 +0800594 /* For i.MX53 eSDHCv3, SYSCTL.SDCLKFS may not be set to 0. */
595 pre_div = (regs == (struct fsl_esdhc *)MMC_SDHC3_BASE_ADDR) ? 2 : 1;
Sean Anderson218dfa12021-11-23 15:03:45 -0500596#else
Haibo Chen84516a72022-02-11 19:16:56 +0800597 pre_div = 1;
Sean Anderson218dfa12021-11-23 15:03:45 -0500598#endif
Sean Anderson218dfa12021-11-23 15:03:45 -0500599
Yangbo Lu982f4252019-06-21 11:42:27 +0800600 while (sdhc_clk / (16 * pre_div * ddr_pre_div) > clock && pre_div < 256)
601 pre_div *= 2;
602
603 while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16)
604 div++;
605
Haibo Chen8be0ba32022-02-11 19:16:57 +0800606 mmc->clock = sdhc_clk / pre_div / div / ddr_pre_div;
607
Yangbo Lu982f4252019-06-21 11:42:27 +0800608 pre_div >>= 1;
609 div -= 1;
610
611 clk = (pre_div << 8) | (div << 4);
612
Sean Anderson218dfa12021-11-23 15:03:45 -0500613 if (IS_ENABLED(CONFIG_FSL_USDHC))
614 esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_CKEN);
615 else
616 esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
Yangbo Lu982f4252019-06-21 11:42:27 +0800617
618 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
619
Haibo Chene6a999b2020-09-01 15:34:06 +0800620 ret = readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp, tmp & PRSSTAT_SDSTB, 100);
621 if (ret)
622 pr_warn("fsl_esdhc_imx: Internal clock never stabilised.\n");
Yangbo Lu982f4252019-06-21 11:42:27 +0800623
Sean Anderson218dfa12021-11-23 15:03:45 -0500624 if (IS_ENABLED(CONFIG_FSL_USDHC))
625 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN | VENDORSPEC_CKEN);
626 else
627 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
Yangbo Lu982f4252019-06-21 11:42:27 +0800628
629 priv->clock = clock;
630}
631
Tom Rinidec7ea02024-05-20 13:35:03 -0600632#if CONFIG_IS_ENABLED(MMC_SUPPORTS_TUNING)
Yangbo Lu982f4252019-06-21 11:42:27 +0800633static int esdhc_change_pinstate(struct udevice *dev)
634{
635 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
636 int ret;
637
638 switch (priv->mode) {
639 case UHS_SDR50:
640 case UHS_DDR50:
641 ret = pinctrl_select_state(dev, "state_100mhz");
642 break;
643 case UHS_SDR104:
644 case MMC_HS_200:
645 case MMC_HS_400:
Peng Fan69b9d3a2019-07-10 09:35:26 +0000646 case MMC_HS_400_ES:
Yangbo Lu982f4252019-06-21 11:42:27 +0800647 ret = pinctrl_select_state(dev, "state_200mhz");
648 break;
649 default:
650 ret = pinctrl_select_state(dev, "default");
651 break;
652 }
653
654 if (ret)
655 printf("%s %d error\n", __func__, priv->mode);
656
657 return ret;
658}
659
660static void esdhc_reset_tuning(struct mmc *mmc)
661{
662 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
663 struct fsl_esdhc *regs = priv->esdhc_regs;
664
665 if (priv->flags & ESDHC_FLAG_USDHC) {
666 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
667 esdhc_clrbits32(&regs->autoc12err,
668 MIX_CTRL_SMPCLK_SEL |
669 MIX_CTRL_EXE_TUNE);
670 }
671 }
672}
673
674static void esdhc_set_strobe_dll(struct mmc *mmc)
675{
676 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
677 struct fsl_esdhc *regs = priv->esdhc_regs;
678 u32 val;
679
680 if (priv->clock > ESDHC_STROBE_DLL_CLK_FREQ) {
Haibo Chen920f5d02020-09-30 15:52:23 +0800681 esdhc_write32(&regs->strobe_dllctrl, ESDHC_STROBE_DLL_CTRL_RESET);
Oleksandr Suvorovd4245c22021-09-08 21:56:43 +0300682 /* clear the reset bit on strobe dll before any setting */
683 esdhc_write32(&regs->strobe_dllctrl, 0);
Yangbo Lu982f4252019-06-21 11:42:27 +0800684
685 /*
686 * enable strobe dll ctrl and adjust the delay target
687 * for the uSDHC loopback read clock
688 */
689 val = ESDHC_STROBE_DLL_CTRL_ENABLE |
Oleksandr Suvorovd4245c22021-09-08 21:56:43 +0300690 ESDHC_STROBE_DLL_CTRL_SLV_UPDATE_INT_DEFAULT |
Yangbo Lu982f4252019-06-21 11:42:27 +0800691 (priv->strobe_dll_delay_target <<
692 ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT);
Haibo Chen920f5d02020-09-30 15:52:23 +0800693 esdhc_write32(&regs->strobe_dllctrl, val);
Oleksandr Suvorovd4245c22021-09-08 21:56:43 +0300694 /* wait 5us to make sure strobe dll status register stable */
695 mdelay(5);
Haibo Chen920f5d02020-09-30 15:52:23 +0800696 val = esdhc_read32(&regs->strobe_dllstat);
Yangbo Lu982f4252019-06-21 11:42:27 +0800697 if (!(val & ESDHC_STROBE_DLL_STS_REF_LOCK))
698 pr_warn("HS400 strobe DLL status REF not lock!\n");
699 if (!(val & ESDHC_STROBE_DLL_STS_SLV_LOCK))
700 pr_warn("HS400 strobe DLL status SLV not lock!\n");
701 }
702}
703
704static int esdhc_set_timing(struct mmc *mmc)
705{
706 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
707 struct fsl_esdhc *regs = priv->esdhc_regs;
708 u32 mixctrl;
709
Haibo Chen920f5d02020-09-30 15:52:23 +0800710 mixctrl = esdhc_read32(&regs->mixctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +0800711 mixctrl &= ~(MIX_CTRL_DDREN | MIX_CTRL_HS400_EN);
712
713 switch (mmc->selected_mode) {
714 case MMC_LEGACY:
Yangbo Lu982f4252019-06-21 11:42:27 +0800715 esdhc_reset_tuning(mmc);
Haibo Chen920f5d02020-09-30 15:52:23 +0800716 esdhc_write32(&regs->mixctrl, mixctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +0800717 break;
718 case MMC_HS_400:
Peng Fan69b9d3a2019-07-10 09:35:26 +0000719 case MMC_HS_400_ES:
Yangbo Lu982f4252019-06-21 11:42:27 +0800720 mixctrl |= MIX_CTRL_DDREN | MIX_CTRL_HS400_EN;
Haibo Chen920f5d02020-09-30 15:52:23 +0800721 esdhc_write32(&regs->mixctrl, mixctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +0800722 break;
723 case MMC_HS:
724 case MMC_HS_52:
725 case MMC_HS_200:
726 case SD_HS:
727 case UHS_SDR12:
728 case UHS_SDR25:
729 case UHS_SDR50:
730 case UHS_SDR104:
Haibo Chen920f5d02020-09-30 15:52:23 +0800731 esdhc_write32(&regs->mixctrl, mixctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +0800732 break;
733 case UHS_DDR50:
734 case MMC_DDR_52:
735 mixctrl |= MIX_CTRL_DDREN;
Haibo Chen920f5d02020-09-30 15:52:23 +0800736 esdhc_write32(&regs->mixctrl, mixctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +0800737 break;
738 default:
739 printf("Not supported %d\n", mmc->selected_mode);
740 return -EINVAL;
741 }
742
743 priv->mode = mmc->selected_mode;
744
745 return esdhc_change_pinstate(mmc->dev);
746}
747
748static int esdhc_set_voltage(struct mmc *mmc)
749{
750 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
751 struct fsl_esdhc *regs = priv->esdhc_regs;
752 int ret;
753
754 priv->signal_voltage = mmc->signal_voltage;
755 switch (mmc->signal_voltage) {
756 case MMC_SIGNAL_VOLTAGE_330:
757 if (priv->vs18_enable)
Marek Vasutba79fed2020-05-22 18:28:33 +0200758 return -ENOTSUPP;
Sean Anderson3e330792021-11-23 15:03:46 -0500759 if (CONFIG_IS_ENABLED(DM_REGULATOR) &&
760 !IS_ERR_OR_NULL(priv->vqmmc_dev)) {
761 ret = regulator_set_value(priv->vqmmc_dev,
762 3300000);
Yangbo Lu982f4252019-06-21 11:42:27 +0800763 if (ret) {
Alexander Stein4b5cebb2024-07-05 15:27:24 +0200764 printf("Setting to 3.3V error: %d\n", ret);
Yangbo Lu982f4252019-06-21 11:42:27 +0800765 return -EIO;
766 }
Yangbo Lu982f4252019-06-21 11:42:27 +0800767 mdelay(5);
768 }
Yangbo Lu982f4252019-06-21 11:42:27 +0800769
770 esdhc_clrbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
771 if (!(esdhc_read32(&regs->vendorspec) &
772 ESDHC_VENDORSPEC_VSELECT))
773 return 0;
774
775 return -EAGAIN;
776 case MMC_SIGNAL_VOLTAGE_180:
Sean Anderson3e330792021-11-23 15:03:46 -0500777 if (CONFIG_IS_ENABLED(DM_REGULATOR) &&
778 !IS_ERR_OR_NULL(priv->vqmmc_dev)) {
779 ret = regulator_set_value(priv->vqmmc_dev,
780 1800000);
Yangbo Lu982f4252019-06-21 11:42:27 +0800781 if (ret) {
Alexander Stein4b5cebb2024-07-05 15:27:24 +0200782 printf("Setting to 1.8V error: %d\n", ret);
Yangbo Lu982f4252019-06-21 11:42:27 +0800783 return -EIO;
784 }
785 }
Yangbo Lu982f4252019-06-21 11:42:27 +0800786 esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
Haibo Chen26154952021-03-22 18:55:38 +0800787 /*
788 * some board like imx8mm-evk need about 18ms to switch
789 * the IO voltage from 3.3v to 1.8v, common code only
790 * delay 10ms, so need to delay extra time to make sure
791 * the IO voltage change to 1.8v.
792 */
793 if (priv->signal_voltage_switch_extra_delay_ms)
794 mdelay(priv->signal_voltage_switch_extra_delay_ms);
Yangbo Lu982f4252019-06-21 11:42:27 +0800795 if (esdhc_read32(&regs->vendorspec) & ESDHC_VENDORSPEC_VSELECT)
796 return 0;
797
798 return -EAGAIN;
799 case MMC_SIGNAL_VOLTAGE_120:
800 return -ENOTSUPP;
801 default:
802 return 0;
803 }
804}
805
806static void esdhc_stop_tuning(struct mmc *mmc)
807{
808 struct mmc_cmd cmd;
809
810 cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
811 cmd.cmdarg = 0;
812 cmd.resp_type = MMC_RSP_R1b;
813
Jaehoon Chung099814b2021-05-31 08:31:49 +0900814 mmc_send_cmd(mmc, &cmd, NULL);
Yangbo Lu982f4252019-06-21 11:42:27 +0800815}
816
817static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode)
818{
Simon Glassfa20e932020-12-03 16:55:20 -0700819 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Yangbo Lu982f4252019-06-21 11:42:27 +0800820 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
821 struct fsl_esdhc *regs = priv->esdhc_regs;
822 struct mmc *mmc = &plat->mmc;
Haibo Chen920f5d02020-09-30 15:52:23 +0800823 u32 irqstaten = esdhc_read32(&regs->irqstaten);
824 u32 irqsigen = esdhc_read32(&regs->irqsigen);
Haibo Chen3a385c82022-02-22 11:28:18 +0800825 int i, err, ret = -ETIMEDOUT;
826 u32 val, mixctrl, tmp;
Yangbo Lu982f4252019-06-21 11:42:27 +0800827
828 /* clock tuning is not needed for upto 52MHz */
829 if (mmc->clock <= 52000000)
830 return 0;
831
Haibo Chen3a385c82022-02-22 11:28:18 +0800832 /* make sure the card clock keep on */
833 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
834
Yangbo Lu982f4252019-06-21 11:42:27 +0800835 /* This is readw/writew SDHCI_HOST_CONTROL2 when tuning */
836 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
Haibo Chen920f5d02020-09-30 15:52:23 +0800837 val = esdhc_read32(&regs->autoc12err);
838 mixctrl = esdhc_read32(&regs->mixctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +0800839 val &= ~MIX_CTRL_SMPCLK_SEL;
840 mixctrl &= ~(MIX_CTRL_FBCLK_SEL | MIX_CTRL_AUTO_TUNE_EN);
841
842 val |= MIX_CTRL_EXE_TUNE;
843 mixctrl |= MIX_CTRL_FBCLK_SEL | MIX_CTRL_AUTO_TUNE_EN;
844
Haibo Chen920f5d02020-09-30 15:52:23 +0800845 esdhc_write32(&regs->autoc12err, val);
846 esdhc_write32(&regs->mixctrl, mixctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +0800847 }
848
849 /* sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); */
Haibo Chen920f5d02020-09-30 15:52:23 +0800850 mixctrl = esdhc_read32(&regs->mixctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +0800851 mixctrl = MIX_CTRL_DTDSEL_READ | (mixctrl & ~MIX_CTRL_SDHCI_MASK);
Haibo Chen920f5d02020-09-30 15:52:23 +0800852 esdhc_write32(&regs->mixctrl, mixctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +0800853
Haibo Chen920f5d02020-09-30 15:52:23 +0800854 esdhc_write32(&regs->irqstaten, IRQSTATEN_BRR);
855 esdhc_write32(&regs->irqsigen, IRQSTATEN_BRR);
Yangbo Lu982f4252019-06-21 11:42:27 +0800856
857 /*
858 * Issue opcode repeatedly till Execute Tuning is set to 0 or the number
859 * of loops reaches 40 times.
860 */
861 for (i = 0; i < MAX_TUNING_LOOP; i++) {
862 u32 ctrl;
863
864 if (opcode == MMC_CMD_SEND_TUNING_BLOCK_HS200) {
865 if (mmc->bus_width == 8)
Haibo Chen920f5d02020-09-30 15:52:23 +0800866 esdhc_write32(&regs->blkattr, 0x7080);
Yangbo Lu982f4252019-06-21 11:42:27 +0800867 else if (mmc->bus_width == 4)
Haibo Chen920f5d02020-09-30 15:52:23 +0800868 esdhc_write32(&regs->blkattr, 0x7040);
Yangbo Lu982f4252019-06-21 11:42:27 +0800869 } else {
Haibo Chen920f5d02020-09-30 15:52:23 +0800870 esdhc_write32(&regs->blkattr, 0x7040);
Yangbo Lu982f4252019-06-21 11:42:27 +0800871 }
872
873 /* sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE) */
Haibo Chen920f5d02020-09-30 15:52:23 +0800874 val = esdhc_read32(&regs->mixctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +0800875 val = MIX_CTRL_DTDSEL_READ | (val & ~MIX_CTRL_SDHCI_MASK);
Haibo Chen920f5d02020-09-30 15:52:23 +0800876 esdhc_write32(&regs->mixctrl, val);
Yangbo Lu982f4252019-06-21 11:42:27 +0800877
878 /* We are using STD tuning, no need to check return value */
Marek Vasutdad81fb2024-02-20 09:36:23 +0100879 mmc_send_tuning(mmc, opcode);
Yangbo Lu982f4252019-06-21 11:42:27 +0800880
Haibo Chen920f5d02020-09-30 15:52:23 +0800881 ctrl = esdhc_read32(&regs->autoc12err);
Yangbo Lu982f4252019-06-21 11:42:27 +0800882 if ((!(ctrl & MIX_CTRL_EXE_TUNE)) &&
883 (ctrl & MIX_CTRL_SMPCLK_SEL)) {
Yangbo Lu982f4252019-06-21 11:42:27 +0800884 ret = 0;
885 break;
886 }
Yangbo Lu982f4252019-06-21 11:42:27 +0800887 }
888
Haibo Chen920f5d02020-09-30 15:52:23 +0800889 esdhc_write32(&regs->irqstaten, irqstaten);
890 esdhc_write32(&regs->irqsigen, irqsigen);
Yangbo Lu982f4252019-06-21 11:42:27 +0800891
892 esdhc_stop_tuning(mmc);
893
Haibo Chen3a385c82022-02-22 11:28:18 +0800894 /* change to default setting, let host control the card clock */
895 esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
896 err = readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp, tmp & PRSSTAT_SDOFF, 100);
897 if (err)
898 dev_warn(dev, "card clock not gate off as expect.\n");
899
Yangbo Lu982f4252019-06-21 11:42:27 +0800900 return ret;
901}
902#endif
903
904static int esdhc_set_ios_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
905{
906 struct fsl_esdhc *regs = priv->esdhc_regs;
907 int ret __maybe_unused;
Peng Fan2cdf52b2019-11-04 17:14:15 +0800908 u32 clock;
Yangbo Lu982f4252019-06-21 11:42:27 +0800909
Tom Rinidec7ea02024-05-20 13:35:03 -0600910#if CONFIG_IS_ENABLED(MMC_SUPPORTS_TUNING)
Haibo Cheneaa2f102020-11-03 17:18:35 +0800911 /*
912 * call esdhc_set_timing() before update the clock rate,
913 * This is because current we support DDR and SDR mode,
914 * Once the DDR_EN bit is set, the card clock will be
915 * divide by 2 automatically. So need to do this before
916 * setting clock rate.
917 */
918 if (priv->mode != mmc->selected_mode) {
919 ret = esdhc_set_timing(mmc);
920 if (ret) {
921 printf("esdhc_set_timing error %d\n", ret);
922 return ret;
923 }
924 }
925#endif
926
Yangbo Lu982f4252019-06-21 11:42:27 +0800927 /* Set the clock speed */
Peng Fan2cdf52b2019-11-04 17:14:15 +0800928 clock = mmc->clock;
929 if (clock < mmc->cfg->f_min)
930 clock = mmc->cfg->f_min;
931
932 if (priv->clock != clock)
933 set_sysctl(priv, mmc, clock);
Yangbo Lu982f4252019-06-21 11:42:27 +0800934
Yangbo Lu982f4252019-06-21 11:42:27 +0800935 if (mmc->clk_disable) {
Sean Anderson3e330792021-11-23 15:03:46 -0500936 if (IS_ENABLED(CONFIG_FSL_USDHC))
937 esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_CKEN);
938 else
939 esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
Yangbo Lu982f4252019-06-21 11:42:27 +0800940 } else {
Sean Anderson3e330792021-11-23 15:03:46 -0500941 if (IS_ENABLED(CONFIG_FSL_USDHC))
942 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN |
943 VENDORSPEC_CKEN);
944 else
945 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
Yangbo Lu982f4252019-06-21 11:42:27 +0800946 }
947
Tom Rinidec7ea02024-05-20 13:35:03 -0600948#if CONFIG_IS_ENABLED(MMC_SUPPORTS_TUNING)
Haibo Cheneaa2f102020-11-03 17:18:35 +0800949 /*
950 * For HS400/HS400ES mode, make sure set the strobe dll in the
951 * target clock rate. So call esdhc_set_strobe_dll() after the
952 * clock updated.
953 */
954 if (mmc->selected_mode == MMC_HS_400 || mmc->selected_mode == MMC_HS_400_ES)
955 esdhc_set_strobe_dll(mmc);
Yangbo Lu982f4252019-06-21 11:42:27 +0800956
957 if (priv->signal_voltage != mmc->signal_voltage) {
958 ret = esdhc_set_voltage(mmc);
959 if (ret) {
Marek Vasutba79fed2020-05-22 18:28:33 +0200960 if (ret != -ENOTSUPP)
961 printf("esdhc_set_voltage error %d\n", ret);
Yangbo Lu982f4252019-06-21 11:42:27 +0800962 return ret;
963 }
964 }
965#endif
966
967 /* Set the bus width */
968 esdhc_clrbits32(&regs->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
969
970 if (mmc->bus_width == 4)
971 esdhc_setbits32(&regs->proctl, PROCTL_DTW_4);
972 else if (mmc->bus_width == 8)
973 esdhc_setbits32(&regs->proctl, PROCTL_DTW_8);
974
975 return 0;
976}
977
978static int esdhc_init_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
979{
980 struct fsl_esdhc *regs = priv->esdhc_regs;
981 ulong start;
982
983 /* Reset the entire host controller */
Peng Fan97a645c2024-10-01 21:07:57 +0800984 esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA | SYSCTL_RSTT);
Yangbo Lu982f4252019-06-21 11:42:27 +0800985
986 /* Wait until the controller is available */
987 start = get_timer(0);
Peng Fan97a645c2024-10-01 21:07:57 +0800988 while ((esdhc_read32(&regs->sysctl) & (SYSCTL_RSTA | SYSCTL_RSTT))) {
Yangbo Lu982f4252019-06-21 11:42:27 +0800989 if (get_timer(start) > 1000)
990 return -ETIMEDOUT;
991 }
992
Sean Anderson3e330792021-11-23 15:03:46 -0500993 if (IS_ENABLED(CONFIG_FSL_USDHC)) {
994 /* RSTA doesn't reset MMC_BOOT register, so manually reset it */
995 esdhc_write32(&regs->mmcboot, 0x0);
996 /* Reset MIX_CTRL and CLK_TUNE_CTRL_STATUS regs to 0 */
997 esdhc_write32(&regs->mixctrl, 0x0);
998 esdhc_write32(&regs->clktunectrlstatus, 0x0);
Yangbo Lu982f4252019-06-21 11:42:27 +0800999
Sean Anderson3e330792021-11-23 15:03:46 -05001000 /* Put VEND_SPEC to default value */
1001 if (priv->vs18_enable)
1002 esdhc_write32(&regs->vendorspec, VENDORSPEC_INIT |
1003 ESDHC_VENDORSPEC_VSELECT);
1004 else
1005 esdhc_write32(&regs->vendorspec, VENDORSPEC_INIT);
Yangbo Lu982f4252019-06-21 11:42:27 +08001006
Sean Anderson3e330792021-11-23 15:03:46 -05001007 /* Disable DLL_CTRL delay line */
1008 esdhc_write32(&regs->dllctrl, 0x0);
1009 }
Yangbo Lu982f4252019-06-21 11:42:27 +08001010
Sean Anderson3e330792021-11-23 15:03:46 -05001011 if (IS_ENABLED(CONFIG_FSL_USDHC))
1012 esdhc_setbits32(&regs->vendorspec,
1013 VENDORSPEC_HCKEN | VENDORSPEC_IPGEN);
1014 else
1015 esdhc_setbits32(&regs->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
Yangbo Lu982f4252019-06-21 11:42:27 +08001016
1017 /* Set the initial clock speed */
Sean Andersonab3d1542021-11-23 15:03:47 -05001018 set_sysctl(priv, mmc, 400000);
Yangbo Lu982f4252019-06-21 11:42:27 +08001019
1020 /* Disable the BRR and BWR bits in IRQSTAT */
1021 esdhc_clrbits32(&regs->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR);
1022
Yangbo Lu982f4252019-06-21 11:42:27 +08001023 /* Put the PROCTL reg back to the default */
Sean Anderson3e330792021-11-23 15:03:46 -05001024 if (IS_ENABLED(CONFIG_MCF5441x))
1025 esdhc_write32(&regs->proctl, PROCTL_INIT | PROCTL_D3CD);
1026 else
1027 esdhc_write32(&regs->proctl, PROCTL_INIT);
Yangbo Lu982f4252019-06-21 11:42:27 +08001028
1029 /* Set timout to the maximum value */
1030 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
1031
Ye Li56cb13e2024-10-01 21:07:54 +08001032 /* max 1ms delay with clock on for initialization */
1033 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
1034 udelay(1000);
1035 esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
1036
Yangbo Lu982f4252019-06-21 11:42:27 +08001037 return 0;
1038}
1039
1040static int esdhc_getcd_common(struct fsl_esdhc_priv *priv)
1041{
1042 struct fsl_esdhc *regs = priv->esdhc_regs;
1043 int timeout = 1000;
1044
Sean Anderson3e330792021-11-23 15:03:46 -05001045 if (IS_ENABLED(CONFIG_ESDHC_DETECT_QUIRK))
Yangbo Lu982f4252019-06-21 11:42:27 +08001046 return 1;
Yangbo Lu982f4252019-06-21 11:42:27 +08001047
Sean Anderson3e330792021-11-23 15:03:46 -05001048 if (CONFIG_IS_ENABLED(DM_MMC)) {
1049 if (priv->broken_cd)
1050 return 1;
Simon Glassfa4689a2019-12-06 21:41:35 -07001051#if CONFIG_IS_ENABLED(DM_GPIO)
Sean Anderson3e330792021-11-23 15:03:46 -05001052 if (dm_gpio_is_valid(&priv->cd_gpio))
1053 return dm_gpio_get_value(&priv->cd_gpio);
Yangbo Lu982f4252019-06-21 11:42:27 +08001054#endif
Sean Anderson3e330792021-11-23 15:03:46 -05001055 }
Yangbo Lu982f4252019-06-21 11:42:27 +08001056
1057 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
1058 udelay(1000);
1059
1060 return timeout > 0;
1061}
1062
Loic Poulain233c3732022-05-26 16:37:22 +02001063static int esdhc_wait_dat0_common(struct fsl_esdhc_priv *priv, int state,
1064 int timeout_us)
1065{
1066 struct fsl_esdhc *regs = priv->esdhc_regs;
1067 int ret, err;
1068 u32 tmp;
1069
1070 /* make sure the card clock keep on */
1071 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
1072
1073 ret = readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp,
1074 !!(tmp & PRSSTAT_DAT0) == !!state,
1075 timeout_us);
1076
1077 /* change to default setting, let host control the card clock */
1078 esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_FRC_SDCLK_ON);
1079
1080 err = readx_poll_timeout(esdhc_read32, &regs->prsstat, tmp, tmp & PRSSTAT_SDOFF, 100);
1081 if (err)
1082 pr_warn("card clock not gate off as expect.\n");
1083
1084 return ret;
1085}
1086
Yangbo Lu982f4252019-06-21 11:42:27 +08001087static int esdhc_reset(struct fsl_esdhc *regs)
1088{
1089 ulong start;
1090
1091 /* reset the controller */
Peng Fan97a645c2024-10-01 21:07:57 +08001092 esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA | SYSCTL_RSTT);
Yangbo Lu982f4252019-06-21 11:42:27 +08001093
1094 /* hardware clears the bit when it is done */
1095 start = get_timer(0);
Peng Fan97a645c2024-10-01 21:07:57 +08001096 while ((esdhc_read32(&regs->sysctl) & (SYSCTL_RSTA | SYSCTL_RSTT))) {
Yangbo Lu982f4252019-06-21 11:42:27 +08001097 if (get_timer(start) > 100) {
1098 printf("MMC/SD: Reset never completed.\n");
1099 return -ETIMEDOUT;
1100 }
1101 }
1102
1103 return 0;
1104}
1105
1106#if !CONFIG_IS_ENABLED(DM_MMC)
1107static int esdhc_getcd(struct mmc *mmc)
1108{
1109 struct fsl_esdhc_priv *priv = mmc->priv;
1110
1111 return esdhc_getcd_common(priv);
1112}
1113
1114static int esdhc_init(struct mmc *mmc)
1115{
1116 struct fsl_esdhc_priv *priv = mmc->priv;
1117
1118 return esdhc_init_common(priv, mmc);
1119}
1120
1121static int esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
1122 struct mmc_data *data)
1123{
1124 struct fsl_esdhc_priv *priv = mmc->priv;
1125
1126 return esdhc_send_cmd_common(priv, mmc, cmd, data);
1127}
1128
1129static int esdhc_set_ios(struct mmc *mmc)
1130{
1131 struct fsl_esdhc_priv *priv = mmc->priv;
1132
1133 return esdhc_set_ios_common(priv, mmc);
1134}
1135
Loic Poulain233c3732022-05-26 16:37:22 +02001136static int esdhc_wait_dat0(struct mmc *mmc, int state, int timeout_us)
1137{
1138 struct fsl_esdhc_priv *priv = mmc->priv;
1139
1140 return esdhc_wait_dat0_common(priv, state, timeout_us);
1141}
1142
Yangbo Lu982f4252019-06-21 11:42:27 +08001143static const struct mmc_ops esdhc_ops = {
1144 .getcd = esdhc_getcd,
1145 .init = esdhc_init,
1146 .send_cmd = esdhc_send_cmd,
1147 .set_ios = esdhc_set_ios,
Loic Poulain233c3732022-05-26 16:37:22 +02001148 .wait_dat0 = esdhc_wait_dat0,
Yangbo Lu982f4252019-06-21 11:42:27 +08001149};
1150#endif
1151
1152static int fsl_esdhc_init(struct fsl_esdhc_priv *priv,
1153 struct fsl_esdhc_plat *plat)
1154{
1155 struct mmc_config *cfg;
1156 struct fsl_esdhc *regs;
Sean Anderson6dff7b72021-11-23 15:03:38 -05001157 u32 caps;
Yangbo Lu982f4252019-06-21 11:42:27 +08001158 int ret;
1159
1160 if (!priv)
1161 return -EINVAL;
1162
1163 regs = priv->esdhc_regs;
1164
1165 /* First reset the eSDHC controller */
1166 ret = esdhc_reset(regs);
1167 if (ret)
1168 return ret;
1169
Yangbo Lu982f4252019-06-21 11:42:27 +08001170 /* ColdFire, using SDHC_DATA[3] for card detection */
Sean Anderson218dfa12021-11-23 15:03:45 -05001171 if (IS_ENABLED(CONFIG_MCF5441x))
1172 esdhc_write32(&regs->proctl, PROCTL_INIT | PROCTL_D3CD);
Yangbo Lu982f4252019-06-21 11:42:27 +08001173
Sean Anderson218dfa12021-11-23 15:03:45 -05001174 if (IS_ENABLED(CONFIG_FSL_USDHC)) {
1175 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN |
1176 VENDORSPEC_HCKEN | VENDORSPEC_IPGEN | VENDORSPEC_CKEN);
1177 } else {
1178 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN
1179 | SYSCTL_IPGEN | SYSCTL_CKEN);
1180 /* Clearing tuning bits in case ROM has set it already */
1181 esdhc_write32(&regs->mixctrl, 0);
1182 esdhc_write32(&regs->autoc12err, 0);
1183 esdhc_write32(&regs->clktunectrlstatus, 0);
1184 }
Yangbo Lu982f4252019-06-21 11:42:27 +08001185
1186 if (priv->vs18_enable)
1187 esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
1188
Haibo Chen920f5d02020-09-30 15:52:23 +08001189 esdhc_write32(&regs->irqstaten, SDHCI_IRQ_EN_BITS);
Yangbo Lu982f4252019-06-21 11:42:27 +08001190 cfg = &plat->cfg;
Yangbo Lu982f4252019-06-21 11:42:27 +08001191
Yangbo Lu982f4252019-06-21 11:42:27 +08001192 caps = esdhc_read32(&regs->hostcapblt);
Sean Anderson218dfa12021-11-23 15:03:45 -05001193
Yangbo Lu982f4252019-06-21 11:42:27 +08001194 /*
1195 * MCF5441x RM declares in more points that sdhc clock speed must
1196 * never exceed 25 Mhz. From this, the HS bit needs to be disabled
1197 * from host capabilities.
1198 */
Sean Anderson218dfa12021-11-23 15:03:45 -05001199 if (IS_ENABLED(CONFIG_MCF5441x))
1200 caps &= ~HOSTCAPBLT_HSS;
Yangbo Lu982f4252019-06-21 11:42:27 +08001201
Sean Anderson218dfa12021-11-23 15:03:45 -05001202 if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_ESDHC135))
1203 caps &= ~(HOSTCAPBLT_SRS | HOSTCAPBLT_VS18 | HOSTCAPBLT_VS30);
Sean Anderson6dff7b72021-11-23 15:03:38 -05001204
Sean Anderson218dfa12021-11-23 15:03:45 -05001205 if (IS_ENABLED(CONFIG_SYS_FSL_MMC_HAS_CAPBLT_VS33))
1206 caps |= HOSTCAPBLT_VS33;
Yangbo Lu982f4252019-06-21 11:42:27 +08001207
Sean Anderson6dff7b72021-11-23 15:03:38 -05001208 if (caps & HOSTCAPBLT_VS18)
1209 cfg->voltages |= MMC_VDD_165_195;
1210 if (caps & HOSTCAPBLT_VS30)
1211 cfg->voltages |= MMC_VDD_29_30 | MMC_VDD_30_31;
1212 if (caps & HOSTCAPBLT_VS33)
1213 cfg->voltages |= MMC_VDD_32_33 | MMC_VDD_33_34;
Yangbo Lu982f4252019-06-21 11:42:27 +08001214
1215 cfg->name = "FSL_SDHC";
Sean Anderson218dfa12021-11-23 15:03:45 -05001216
Yangbo Lu982f4252019-06-21 11:42:27 +08001217#if !CONFIG_IS_ENABLED(DM_MMC)
1218 cfg->ops = &esdhc_ops;
1219#endif
Yangbo Lu982f4252019-06-21 11:42:27 +08001220
Sean Anderson218dfa12021-11-23 15:03:45 -05001221 if (IS_ENABLED(CONFIG_SYS_FSL_ESDHC_HAS_DDR_MODE))
1222 cfg->host_caps |= MMC_MODE_DDR_52MHz;
1223
Sean Anderson6dff7b72021-11-23 15:03:38 -05001224 if (caps & HOSTCAPBLT_HSS)
Yangbo Lu982f4252019-06-21 11:42:27 +08001225 cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
1226
Yangbo Lu982f4252019-06-21 11:42:27 +08001227 cfg->host_caps |= priv->caps;
1228
1229 cfg->f_min = 400000;
1230 cfg->f_max = min(priv->sdhc_clk, (u32)200000000);
1231
1232 cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
1233
Haibo Chen920f5d02020-09-30 15:52:23 +08001234 esdhc_write32(&regs->dllctrl, 0);
Yangbo Lu982f4252019-06-21 11:42:27 +08001235 if (priv->flags & ESDHC_FLAG_USDHC) {
1236 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
Haibo Chen920f5d02020-09-30 15:52:23 +08001237 u32 val = esdhc_read32(&regs->tuning_ctrl);
Yangbo Lu982f4252019-06-21 11:42:27 +08001238
1239 val |= ESDHC_STD_TUNING_EN;
1240 val &= ~ESDHC_TUNING_START_TAP_MASK;
1241 val |= priv->tuning_start_tap;
1242 val &= ~ESDHC_TUNING_STEP_MASK;
1243 val |= (priv->tuning_step) << ESDHC_TUNING_STEP_SHIFT;
Haibo Chen43162c32020-06-22 19:38:04 +08001244
1245 /* Disable the CMD CRC check for tuning, if not, need to
1246 * add some delay after every tuning command, because
1247 * hardware standard tuning logic will directly go to next
1248 * step once it detect the CMD CRC error, will not wait for
1249 * the card side to finally send out the tuning data, trigger
1250 * the buffer read ready interrupt immediately. If usdhc send
1251 * the next tuning command some eMMC card will stuck, can't
1252 * response, block the tuning procedure or the first command
1253 * after the whole tuning procedure always can't get any response.
1254 */
1255 val |= ESDHC_TUNING_CMD_CRC_CHECK_DISABLE;
Haibo Chen920f5d02020-09-30 15:52:23 +08001256 esdhc_write32(&regs->tuning_ctrl, val);
Yangbo Lu982f4252019-06-21 11:42:27 +08001257 }
Adam Ford97497fd2022-01-12 07:53:56 -06001258
1259 /*
1260 * UHS doesn't have explicit ESDHC flags, so if it's
1261 * not supported, disable it in config.
1262 */
1263 if (CONFIG_IS_ENABLED(MMC_UHS_SUPPORT))
1264 cfg->host_caps |= UHS_CAPS;
Yangbo Lu982f4252019-06-21 11:42:27 +08001265
Adam Ford97497fd2022-01-12 07:53:56 -06001266 if (CONFIG_IS_ENABLED(MMC_HS200_SUPPORT)) {
1267 if (priv->flags & ESDHC_FLAG_HS200)
1268 cfg->host_caps |= MMC_CAP(MMC_HS_200);
1269 }
1270
1271 if (CONFIG_IS_ENABLED(MMC_HS400_SUPPORT)) {
1272 if (priv->flags & ESDHC_FLAG_HS400)
1273 cfg->host_caps |= MMC_CAP(MMC_HS_400);
1274 }
1275
1276 if (CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)) {
1277 if (priv->flags & ESDHC_FLAG_HS400_ES)
1278 cfg->host_caps |= MMC_CAP(MMC_HS_400_ES);
1279 }
1280 }
Yangbo Lu982f4252019-06-21 11:42:27 +08001281 return 0;
1282}
1283
1284#if !CONFIG_IS_ENABLED(DM_MMC)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001285int fsl_esdhc_initialize(struct bd_info *bis, struct fsl_esdhc_cfg *cfg)
Yangbo Lu982f4252019-06-21 11:42:27 +08001286{
1287 struct fsl_esdhc_plat *plat;
1288 struct fsl_esdhc_priv *priv;
Sean Anderson1f0d6c62021-11-23 15:03:39 -05001289 struct mmc_config *mmc_cfg;
Yangbo Lu982f4252019-06-21 11:42:27 +08001290 struct mmc *mmc;
1291 int ret;
1292
1293 if (!cfg)
1294 return -EINVAL;
1295
1296 priv = calloc(sizeof(struct fsl_esdhc_priv), 1);
1297 if (!priv)
1298 return -ENOMEM;
1299 plat = calloc(sizeof(struct fsl_esdhc_plat), 1);
1300 if (!plat) {
1301 free(priv);
1302 return -ENOMEM;
1303 }
1304
Sean Anderson1f0d6c62021-11-23 15:03:39 -05001305 priv->esdhc_regs = (struct fsl_esdhc *)(unsigned long)(cfg->esdhc_base);
1306 priv->sdhc_clk = cfg->sdhc_clk;
1307 priv->wp_enable = cfg->wp_enable;
1308
1309 mmc_cfg = &plat->cfg;
1310
1311 switch (cfg->max_bus_width) {
1312 case 0: /* Not set in config; assume everything is supported */
1313 case 8:
1314 mmc_cfg->host_caps |= MMC_MODE_8BIT;
1315 fallthrough;
1316 case 4:
1317 mmc_cfg->host_caps |= MMC_MODE_4BIT;
1318 fallthrough;
1319 case 1:
1320 mmc_cfg->host_caps |= MMC_MODE_1BIT;
1321 break;
1322 default:
1323 printf("invalid max bus width %u\n", cfg->max_bus_width);
Ye Lic6b90e22024-10-01 21:07:56 +08001324 free(plat);
1325 free(priv);
Sean Anderson1f0d6c62021-11-23 15:03:39 -05001326 return -EINVAL;
Yangbo Lu982f4252019-06-21 11:42:27 +08001327 }
1328
Sean Anderson218dfa12021-11-23 15:03:45 -05001329 if (IS_ENABLED(CONFIG_ESDHC_DETECT_8_BIT_QUIRK))
Sean Anderson1f0d6c62021-11-23 15:03:39 -05001330 mmc_cfg->host_caps &= ~MMC_MODE_8BIT;
Sean Anderson1f0d6c62021-11-23 15:03:39 -05001331
Yangbo Lu982f4252019-06-21 11:42:27 +08001332 ret = fsl_esdhc_init(priv, plat);
1333 if (ret) {
1334 debug("%s init failure\n", __func__);
1335 free(plat);
1336 free(priv);
1337 return ret;
1338 }
1339
1340 mmc = mmc_create(&plat->cfg, priv);
1341 if (!mmc)
1342 return -EIO;
1343
1344 priv->mmc = mmc;
1345
1346 return 0;
1347}
1348
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001349int fsl_esdhc_mmc_init(struct bd_info *bis)
Yangbo Lu982f4252019-06-21 11:42:27 +08001350{
1351 struct fsl_esdhc_cfg *cfg;
1352
1353 cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1);
Tom Rini376b88a2022-10-28 20:27:13 -04001354 cfg->esdhc_base = CFG_SYS_FSL_ESDHC_ADDR;
Yangbo Lu982f4252019-06-21 11:42:27 +08001355 cfg->sdhc_clk = gd->arch.sdhc_clk;
1356 return fsl_esdhc_initialize(bis, cfg);
1357}
1358#endif
1359
Sean Anderson3e330792021-11-23 15:03:46 -05001360#if CONFIG_IS_ENABLED(OF_LIBFDT)
Yangbo Lu982f4252019-06-21 11:42:27 +08001361__weak int esdhc_status_fixup(void *blob, const char *compat)
1362{
Tom Rinif8967f82022-12-02 16:42:22 -05001363 if (IS_ENABLED(CONFIG_FSL_ESDHC_PIN_MUX) && !hwconfig("esdhc")) {
Yangbo Lu982f4252019-06-21 11:42:27 +08001364 do_fixup_by_compat(blob, compat, "status", "disabled",
1365 sizeof("disabled"), 1);
1366 return 1;
1367 }
Yangbo Lu982f4252019-06-21 11:42:27 +08001368 return 0;
1369}
1370
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001371void fdt_fixup_esdhc(void *blob, struct bd_info *bd)
Yangbo Lu982f4252019-06-21 11:42:27 +08001372{
1373 const char *compat = "fsl,esdhc";
1374
1375 if (esdhc_status_fixup(blob, compat))
1376 return;
1377
Yangbo Lu982f4252019-06-21 11:42:27 +08001378 do_fixup_by_compat_u32(blob, compat, "clock-frequency",
1379 gd->arch.sdhc_clk, 1);
Yangbo Lu982f4252019-06-21 11:42:27 +08001380}
1381#endif
1382
1383#if CONFIG_IS_ENABLED(DM_MMC)
Yangbo Lu982f4252019-06-21 11:42:27 +08001384#include <asm/arch/clock.h>
Yangbo Lu982f4252019-06-21 11:42:27 +08001385__weak void init_clk_usdhc(u32 index)
1386{
1387}
1388
Simon Glassaad29ae2020-12-03 16:55:21 -07001389static int fsl_esdhc_of_to_plat(struct udevice *dev)
Yangbo Lu982f4252019-06-21 11:42:27 +08001390{
Yangbo Lu982f4252019-06-21 11:42:27 +08001391 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
Yangbo Lu982f4252019-06-21 11:42:27 +08001392 struct udevice *vqmmc_dev;
Walter Lozano8aff6732020-07-29 12:31:17 -03001393 int ret;
Sean Anderson3e330792021-11-23 15:03:46 -05001394
Tim Harveycc8f3ea2024-10-23 13:28:55 -07001395 ofnode node = dev_ofnode(dev);
Yangbo Lu982f4252019-06-21 11:42:27 +08001396 fdt_addr_t addr;
1397 unsigned int val;
Yangbo Lu982f4252019-06-21 11:42:27 +08001398
Simon Glass6d70ba02021-08-07 07:24:06 -06001399 if (!CONFIG_IS_ENABLED(OF_REAL))
1400 return 0;
1401
Yangbo Lu982f4252019-06-21 11:42:27 +08001402 addr = dev_read_addr(dev);
1403 if (addr == FDT_ADDR_T_NONE)
1404 return -EINVAL;
Yangbo Lu982f4252019-06-21 11:42:27 +08001405 priv->esdhc_regs = (struct fsl_esdhc *)addr;
Yangbo Lu982f4252019-06-21 11:42:27 +08001406 priv->dev = dev;
1407 priv->mode = -1;
Yangbo Lu982f4252019-06-21 11:42:27 +08001408
Tim Harveycc8f3ea2024-10-23 13:28:55 -07001409 val = ofnode_read_u32_default(node, "fsl,tuning-step", 1);
Yangbo Lu982f4252019-06-21 11:42:27 +08001410 priv->tuning_step = val;
Tim Harveycc8f3ea2024-10-23 13:28:55 -07001411 val = ofnode_read_u32_default(node, "fsl,tuning-start-tap",
1412 ESDHC_TUNING_START_TAP_DEFAULT);
Yangbo Lu982f4252019-06-21 11:42:27 +08001413 priv->tuning_start_tap = val;
Tim Harveycc8f3ea2024-10-23 13:28:55 -07001414 val = ofnode_read_u32_default(node, "fsl,strobe-dll-delay-target",
1415 ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_DEFAULT);
Yangbo Lu982f4252019-06-21 11:42:27 +08001416 priv->strobe_dll_delay_target = val;
Tim Harveycc8f3ea2024-10-23 13:28:55 -07001417 val = ofnode_read_u32_default(node, "fsl,signal-voltage-switch-extra-delay-ms", 0);
Haibo Chen26154952021-03-22 18:55:38 +08001418 priv->signal_voltage_switch_extra_delay_ms = val;
Yangbo Lu982f4252019-06-21 11:42:27 +08001419
Fabio Estevam7e3d8a92020-01-06 20:11:27 -03001420 if (dev_read_bool(dev, "broken-cd"))
1421 priv->broken_cd = 1;
1422
Yangbo Lu982f4252019-06-21 11:42:27 +08001423 if (dev_read_prop(dev, "fsl,wp-controller", NULL)) {
1424 priv->wp_enable = 1;
1425 } else {
1426 priv->wp_enable = 0;
Sean Anderson5b8040b2021-11-23 15:03:40 -05001427 }
1428
Simon Glassfa4689a2019-12-06 21:41:35 -07001429#if CONFIG_IS_ENABLED(DM_GPIO)
Sean Anderson5b8040b2021-11-23 15:03:40 -05001430 gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio,
1431 GPIOD_IS_IN);
1432 gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio,
1433 GPIOD_IS_IN);
Yangbo Lu982f4252019-06-21 11:42:27 +08001434#endif
Yangbo Lu982f4252019-06-21 11:42:27 +08001435
1436 priv->vs18_enable = 0;
1437
Sean Anderson3e330792021-11-23 15:03:46 -05001438 if (!CONFIG_IS_ENABLED(DM_REGULATOR))
1439 return 0;
1440
Yangbo Lu982f4252019-06-21 11:42:27 +08001441 /*
1442 * If emmc I/O has a fixed voltage at 1.8V, this must be provided,
1443 * otherwise, emmc will work abnormally.
1444 */
1445 ret = device_get_supply_regulator(dev, "vqmmc-supply", &vqmmc_dev);
1446 if (ret) {
1447 dev_dbg(dev, "no vqmmc-supply\n");
1448 } else {
Marek Vasut34e67f92020-05-22 18:19:08 +02001449 priv->vqmmc_dev = vqmmc_dev;
Yangbo Lu982f4252019-06-21 11:42:27 +08001450 ret = regulator_set_enable(vqmmc_dev, true);
1451 if (ret) {
1452 dev_err(dev, "fail to enable vqmmc-supply\n");
1453 return ret;
1454 }
1455
1456 if (regulator_get_value(vqmmc_dev) == 1800000)
1457 priv->vs18_enable = 1;
1458 }
Walter Lozano8aff6732020-07-29 12:31:17 -03001459 return 0;
1460}
1461
1462static int fsl_esdhc_probe(struct udevice *dev)
1463{
1464 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
Simon Glassfa20e932020-12-03 16:55:20 -07001465 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Walter Lozano8aff6732020-07-29 12:31:17 -03001466 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1467 struct esdhc_soc_data *data =
1468 (struct esdhc_soc_data *)dev_get_driver_data(dev);
1469 struct mmc *mmc;
Walter Lozano8aff6732020-07-29 12:31:17 -03001470 int ret;
1471
1472#if CONFIG_IS_ENABLED(OF_PLATDATA)
1473 struct dtd_fsl_esdhc *dtplat = &plat->dtplat;
Walter Lozano8aff6732020-07-29 12:31:17 -03001474
1475 priv->esdhc_regs = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
Walter Lozanocfc05fd2020-07-29 12:31:19 -03001476
1477 if (dtplat->non_removable)
Sean Anderson5b8040b2021-11-23 15:03:40 -05001478 plat->cfg.host_caps |= MMC_CAP_NONREMOVABLE;
Walter Lozanocfc05fd2020-07-29 12:31:19 -03001479 else
Sean Anderson5b8040b2021-11-23 15:03:40 -05001480 plat->cfg.host_caps &= ~MMC_CAP_NONREMOVABLE;
Walter Lozanocfc05fd2020-07-29 12:31:19 -03001481
Sean Anderson5b8040b2021-11-23 15:03:40 -05001482 if (CONFIG_IS_ENABLED(DM_GPIO) && !dtplat->non_removable) {
Walter Lozanocfc05fd2020-07-29 12:31:19 -03001483 struct udevice *gpiodev;
Walter Lozanocfc05fd2020-07-29 12:31:19 -03001484
Simon Glass0000e0d2021-03-15 17:25:28 +13001485 ret = device_get_by_ofplat_idx(dtplat->cd_gpios->idx, &gpiodev);
Walter Lozanocfc05fd2020-07-29 12:31:19 -03001486 if (ret)
1487 return ret;
1488
1489 ret = gpio_dev_request_index(gpiodev, gpiodev->name, "cd-gpios",
1490 dtplat->cd_gpios->arg[0], GPIOD_IS_IN,
1491 dtplat->cd_gpios->arg[1], &priv->cd_gpio);
1492
1493 if (ret)
1494 return ret;
1495 }
Walter Lozano8aff6732020-07-29 12:31:17 -03001496#endif
1497
1498 if (data)
1499 priv->flags = data->flags;
Yangbo Lu982f4252019-06-21 11:42:27 +08001500
Yangbo Lu982f4252019-06-21 11:42:27 +08001501 /*
1502 * TODO:
1503 * Because lack of clk driver, if SDHC clk is not enabled,
1504 * need to enable it first before this driver is invoked.
1505 *
1506 * we use MXC_ESDHC_CLK to get clk freq.
1507 * If one would like to make this function work,
1508 * the aliases should be provided in dts as this:
1509 *
1510 * aliases {
1511 * mmc0 = &usdhc1;
1512 * mmc1 = &usdhc2;
1513 * mmc2 = &usdhc3;
1514 * mmc3 = &usdhc4;
1515 * };
1516 * Then if your board only supports mmc2 and mmc3, but we can
1517 * correctly get the seq as 2 and 3, then let mxc_get_clock
1518 * work as expected.
1519 */
1520
Giulio Benettidbdbc632020-01-10 15:51:45 +01001521#if CONFIG_IS_ENABLED(CLK)
1522 /* Assigned clock already set clock */
Peng Fane5b6e5c2024-10-01 21:07:53 +08001523 ret = clk_get_bulk(dev, &priv->clk_bulk);
Giulio Benettidbdbc632020-01-10 15:51:45 +01001524 if (ret) {
Peng Fane5b6e5c2024-10-01 21:07:53 +08001525 dev_err(dev, "Failed to get clks: %d\n", ret);
Giulio Benettidbdbc632020-01-10 15:51:45 +01001526 return ret;
1527 }
Peng Fane5b6e5c2024-10-01 21:07:53 +08001528
1529 ret = clk_enable_bulk(&priv->clk_bulk);
Giulio Benettidbdbc632020-01-10 15:51:45 +01001530 if (ret) {
Peng Fane5b6e5c2024-10-01 21:07:53 +08001531 dev_err(dev, "Failed to enable clks: %d\n", ret);
1532 return ret;
1533 }
1534
1535 ret = clk_get_by_name(dev, "per", &priv->per_clk);
1536 if (ret) {
1537 printf("Failed to get per_clk\n");
Giulio Benettidbdbc632020-01-10 15:51:45 +01001538 return ret;
1539 }
Yangbo Lu982f4252019-06-21 11:42:27 +08001540
Giulio Benettidbdbc632020-01-10 15:51:45 +01001541 priv->sdhc_clk = clk_get_rate(&priv->per_clk);
1542#else
Ye Li2a4b3b92022-09-24 00:29:33 +02001543 init_clk_usdhc(dev_seq(dev));
1544
Simon Glass75e534b2020-12-16 21:20:07 -07001545 priv->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK + dev_seq(dev));
Giulio Benettidbdbc632020-01-10 15:51:45 +01001546 if (priv->sdhc_clk <= 0) {
1547 dev_err(dev, "Unable to get clk for %s\n", dev->name);
1548 return -EINVAL;
Yangbo Lu982f4252019-06-21 11:42:27 +08001549 }
Giulio Benettidbdbc632020-01-10 15:51:45 +01001550#endif
Yangbo Lu982f4252019-06-21 11:42:27 +08001551
1552 ret = fsl_esdhc_init(priv, plat);
1553 if (ret) {
1554 dev_err(dev, "fsl_esdhc_init failure\n");
1555 return ret;
1556 }
1557
Simon Glass6d70ba02021-08-07 07:24:06 -06001558 if (CONFIG_IS_ENABLED(OF_REAL)) {
1559 ret = mmc_of_parse(dev, &plat->cfg);
1560 if (ret)
1561 return ret;
1562 }
Peng Fan3766a482019-07-10 09:35:24 +00001563
Yangbo Lu982f4252019-06-21 11:42:27 +08001564 mmc = &plat->mmc;
1565 mmc->cfg = &plat->cfg;
1566 mmc->dev = dev;
Yangbo Lu982f4252019-06-21 11:42:27 +08001567
1568 upriv->mmc = mmc;
1569
Ye Li56cb13e2024-10-01 21:07:54 +08001570 return 0;
Yangbo Lu982f4252019-06-21 11:42:27 +08001571}
1572
Yangbo Lu982f4252019-06-21 11:42:27 +08001573static int fsl_esdhc_get_cd(struct udevice *dev)
1574{
Sean Anderson5b8040b2021-11-23 15:03:40 -05001575 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Yangbo Lu982f4252019-06-21 11:42:27 +08001576 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1577
Sean Anderson5b8040b2021-11-23 15:03:40 -05001578 if (plat->cfg.host_caps & MMC_CAP_NONREMOVABLE)
1579 return 1;
1580
Yangbo Lu982f4252019-06-21 11:42:27 +08001581 return esdhc_getcd_common(priv);
1582}
1583
1584static int fsl_esdhc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
1585 struct mmc_data *data)
1586{
Simon Glassfa20e932020-12-03 16:55:20 -07001587 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Yangbo Lu982f4252019-06-21 11:42:27 +08001588 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1589
1590 return esdhc_send_cmd_common(priv, &plat->mmc, cmd, data);
1591}
1592
1593static int fsl_esdhc_set_ios(struct udevice *dev)
1594{
Simon Glassfa20e932020-12-03 16:55:20 -07001595 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Yangbo Lu982f4252019-06-21 11:42:27 +08001596 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1597
1598 return esdhc_set_ios_common(priv, &plat->mmc);
1599}
1600
Sean Anderson3e330792021-11-23 15:03:46 -05001601static int __maybe_unused fsl_esdhc_set_enhanced_strobe(struct udevice *dev)
Peng Fan69b9d3a2019-07-10 09:35:26 +00001602{
1603 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1604 struct fsl_esdhc *regs = priv->esdhc_regs;
1605 u32 m;
1606
Haibo Chen920f5d02020-09-30 15:52:23 +08001607 m = esdhc_read32(&regs->mixctrl);
Peng Fan69b9d3a2019-07-10 09:35:26 +00001608 m |= MIX_CTRL_HS400_ES;
Haibo Chen920f5d02020-09-30 15:52:23 +08001609 esdhc_write32(&regs->mixctrl, m);
Peng Fan69b9d3a2019-07-10 09:35:26 +00001610
1611 return 0;
1612}
Peng Fan69b9d3a2019-07-10 09:35:26 +00001613
Haibo Chencb78f212020-11-05 14:57:13 +08001614static int fsl_esdhc_wait_dat0(struct udevice *dev, int state,
1615 int timeout_us)
1616{
Haibo Chencb78f212020-11-05 14:57:13 +08001617 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
Haibo Chen3a385c82022-02-22 11:28:18 +08001618
Loic Poulain233c3732022-05-26 16:37:22 +02001619 return esdhc_wait_dat0_common(priv, state, timeout_us);
Haibo Chencb78f212020-11-05 14:57:13 +08001620}
1621
Ye Li56cb13e2024-10-01 21:07:54 +08001622static int fsl_esdhc_reinit(struct udevice *dev)
1623{
1624 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
1625 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1626
1627 return esdhc_init_common(priv, &plat->mmc);
1628}
1629
Yangbo Lu982f4252019-06-21 11:42:27 +08001630static const struct dm_mmc_ops fsl_esdhc_ops = {
1631 .get_cd = fsl_esdhc_get_cd,
1632 .send_cmd = fsl_esdhc_send_cmd,
1633 .set_ios = fsl_esdhc_set_ios,
Tom Rinidec7ea02024-05-20 13:35:03 -06001634#if CONFIG_IS_ENABLED(MMC_SUPPORTS_TUNING)
Yangbo Lu982f4252019-06-21 11:42:27 +08001635 .execute_tuning = fsl_esdhc_execute_tuning,
1636#endif
Peng Fan69b9d3a2019-07-10 09:35:26 +00001637#if CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)
1638 .set_enhanced_strobe = fsl_esdhc_set_enhanced_strobe,
1639#endif
Haibo Chencb78f212020-11-05 14:57:13 +08001640 .wait_dat0 = fsl_esdhc_wait_dat0,
Ye Li56cb13e2024-10-01 21:07:54 +08001641 .reinit = fsl_esdhc_reinit,
Yangbo Lu982f4252019-06-21 11:42:27 +08001642};
Yangbo Lu982f4252019-06-21 11:42:27 +08001643
1644static struct esdhc_soc_data usdhc_imx7d_data = {
1645 .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
1646 | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
1647 | ESDHC_FLAG_HS400,
Yangbo Lu982f4252019-06-21 11:42:27 +08001648};
1649
Jorge Ramirez-Ortiz8239e822021-09-08 21:56:42 +03001650static struct esdhc_soc_data usdhc_imx7ulp_data = {
1651 .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
Oleksandr Suvorovd4245c22021-09-08 21:56:43 +03001652 | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
1653 | ESDHC_FLAG_HS400,
Jorge Ramirez-Ortiz8239e822021-09-08 21:56:42 +03001654};
1655
Peng Fan457fe962019-07-10 09:35:28 +00001656static struct esdhc_soc_data usdhc_imx8qm_data = {
1657 .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING |
1658 ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200 |
1659 ESDHC_FLAG_HS400 | ESDHC_FLAG_HS400_ES,
1660};
1661
Yangbo Lu982f4252019-06-21 11:42:27 +08001662static const struct udevice_id fsl_esdhc_ids[] = {
Fabio Estevameaf8ccc2021-02-15 08:58:15 -03001663 { .compatible = "fsl,imx51-esdhc", },
Yangbo Lu982f4252019-06-21 11:42:27 +08001664 { .compatible = "fsl,imx53-esdhc", },
1665 { .compatible = "fsl,imx6ul-usdhc", },
1666 { .compatible = "fsl,imx6sx-usdhc", },
1667 { .compatible = "fsl,imx6sl-usdhc", },
1668 { .compatible = "fsl,imx6q-usdhc", },
1669 { .compatible = "fsl,imx7d-usdhc", .data = (ulong)&usdhc_imx7d_data,},
Jorge Ramirez-Ortiz8239e822021-09-08 21:56:42 +03001670 { .compatible = "fsl,imx7ulp-usdhc", .data = (ulong)&usdhc_imx7ulp_data,},
Peng Fan457fe962019-07-10 09:35:28 +00001671 { .compatible = "fsl,imx8qm-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
Peng Fand7689fa2019-11-04 17:31:17 +08001672 { .compatible = "fsl,imx8mm-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
1673 { .compatible = "fsl,imx8mn-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
Marek Vasut104704b2022-03-10 21:27:04 +01001674 { .compatible = "fsl,imx8mp-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
Peng Fand7689fa2019-11-04 17:31:17 +08001675 { .compatible = "fsl,imx8mq-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
Giulio Benetti65b5ec12020-01-10 15:51:46 +01001676 { .compatible = "fsl,imxrt-usdhc", },
Yangbo Lu982f4252019-06-21 11:42:27 +08001677 { .compatible = "fsl,esdhc", },
1678 { /* sentinel */ }
1679};
1680
Yangbo Lu982f4252019-06-21 11:42:27 +08001681static int fsl_esdhc_bind(struct udevice *dev)
1682{
Simon Glassfa20e932020-12-03 16:55:20 -07001683 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Yangbo Lu982f4252019-06-21 11:42:27 +08001684
1685 return mmc_bind(dev, &plat->mmc, &plat->cfg);
1686}
Yangbo Lu982f4252019-06-21 11:42:27 +08001687
1688U_BOOT_DRIVER(fsl_esdhc) = {
Walter Lozano904b0be2020-07-29 12:31:16 -03001689 .name = "fsl_esdhc",
Yangbo Lu982f4252019-06-21 11:42:27 +08001690 .id = UCLASS_MMC,
1691 .of_match = fsl_esdhc_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -07001692 .of_to_plat = fsl_esdhc_of_to_plat,
Yangbo Lu982f4252019-06-21 11:42:27 +08001693 .ops = &fsl_esdhc_ops,
Yangbo Lu982f4252019-06-21 11:42:27 +08001694 .bind = fsl_esdhc_bind,
Yangbo Lu982f4252019-06-21 11:42:27 +08001695 .probe = fsl_esdhc_probe,
Simon Glass71fa5b42020-12-03 16:55:18 -07001696 .plat_auto = sizeof(struct fsl_esdhc_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -07001697 .priv_auto = sizeof(struct fsl_esdhc_priv),
Yangbo Lu982f4252019-06-21 11:42:27 +08001698};
Walter Lozano8aff6732020-07-29 12:31:17 -03001699
Simon Glassdf65db82020-12-28 20:34:57 -07001700DM_DRIVER_ALIAS(fsl_esdhc, fsl_imx6q_usdhc)
Yangbo Lu982f4252019-06-21 11:42:27 +08001701#endif