blob: 788677984bf5349d93d34e32225a05db788f26a6 [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
4 * Copyright 2019 NXP Semiconductors
5 * 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>
14#include <common.h>
15#include <command.h>
16#include <clk.h>
Simon Glass63334482019-11-14 12:57:39 -070017#include <cpu_func.h>
Yangbo Lu982f4252019-06-21 11:42:27 +080018#include <errno.h>
19#include <hwconfig.h>
Simon Glass0f2af882020-05-10 11:40:05 -060020#include <log.h>
Yangbo Lu982f4252019-06-21 11:42:27 +080021#include <mmc.h>
22#include <part.h>
Simon Glass274e0b02020-05-10 11:39:56 -060023#include <asm/cache.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>
Yangbo Lu982f4252019-06-21 11:42:27 +080028#include <power/regulator.h>
29#include <malloc.h>
30#include <fsl_esdhc_imx.h>
31#include <fdt_support.h>
32#include <asm/io.h>
33#include <dm.h>
34#include <asm-generic/gpio.h>
35#include <dm/pinctrl.h>
Walter Lozano8aff6732020-07-29 12:31:17 -030036#include <dt-structs.h>
37#include <mapmem.h>
38#include <dm/ofnode.h>
Yangbo Lu982f4252019-06-21 11:42:27 +080039
40#if !CONFIG_IS_ENABLED(BLK)
41#include "mmc_private.h"
42#endif
43
44DECLARE_GLOBAL_DATA_PTR;
45
46#define SDHCI_IRQ_EN_BITS (IRQSTATEN_CC | IRQSTATEN_TC | \
47 IRQSTATEN_CINT | \
48 IRQSTATEN_CTOE | IRQSTATEN_CCE | IRQSTATEN_CEBE | \
49 IRQSTATEN_CIE | IRQSTATEN_DTOE | IRQSTATEN_DCE | \
50 IRQSTATEN_DEBE | IRQSTATEN_BRR | IRQSTATEN_BWR | \
51 IRQSTATEN_DINT)
52#define MAX_TUNING_LOOP 40
53#define ESDHC_DRIVER_STAGE_VALUE 0xffffffff
54
55struct fsl_esdhc {
56 uint dsaddr; /* SDMA system address register */
57 uint blkattr; /* Block attributes register */
58 uint cmdarg; /* Command argument register */
59 uint xfertyp; /* Transfer type register */
60 uint cmdrsp0; /* Command response 0 register */
61 uint cmdrsp1; /* Command response 1 register */
62 uint cmdrsp2; /* Command response 2 register */
63 uint cmdrsp3; /* Command response 3 register */
64 uint datport; /* Buffer data port register */
65 uint prsstat; /* Present state register */
66 uint proctl; /* Protocol control register */
67 uint sysctl; /* System Control Register */
68 uint irqstat; /* Interrupt status register */
69 uint irqstaten; /* Interrupt status enable register */
70 uint irqsigen; /* Interrupt signal enable register */
71 uint autoc12err; /* Auto CMD error status register */
72 uint hostcapblt; /* Host controller capabilities register */
73 uint wml; /* Watermark level register */
74 uint mixctrl; /* For USDHC */
75 char reserved1[4]; /* reserved */
76 uint fevt; /* Force event register */
77 uint admaes; /* ADMA error status register */
78 uint adsaddr; /* ADMA system address register */
79 char reserved2[4];
80 uint dllctrl;
81 uint dllstat;
82 uint clktunectrlstatus;
83 char reserved3[4];
84 uint strobe_dllctrl;
85 uint strobe_dllstat;
86 char reserved4[72];
87 uint vendorspec;
88 uint mmcboot;
89 uint vendorspec2;
Giulio Benetti65b5ec12020-01-10 15:51:46 +010090 uint tuning_ctrl; /* on i.MX6/7/8/RT */
Yangbo Lu982f4252019-06-21 11:42:27 +080091 char reserved5[44];
92 uint hostver; /* Host controller version register */
93 char reserved6[4]; /* reserved */
94 uint dmaerraddr; /* DMA error address register */
95 char reserved7[4]; /* reserved */
96 uint dmaerrattr; /* DMA error attribute register */
97 char reserved8[4]; /* reserved */
98 uint hostcapblt2; /* Host controller capabilities register 2 */
99 char reserved9[8]; /* reserved */
100 uint tcr; /* Tuning control register */
101 char reserved10[28]; /* reserved */
102 uint sddirctl; /* SD direction control register */
103 char reserved11[712];/* reserved */
104 uint scr; /* eSDHC control register */
105};
106
107struct fsl_esdhc_plat {
Walter Lozano8aff6732020-07-29 12:31:17 -0300108#if CONFIG_IS_ENABLED(OF_PLATDATA)
109 /* Put this first since driver model will copy the data here */
110 struct dtd_fsl_esdhc dtplat;
111#endif
112
Yangbo Lu982f4252019-06-21 11:42:27 +0800113 struct mmc_config cfg;
114 struct mmc mmc;
115};
116
117struct esdhc_soc_data {
118 u32 flags;
Yangbo Lu982f4252019-06-21 11:42:27 +0800119};
120
121/**
122 * struct fsl_esdhc_priv
123 *
124 * @esdhc_regs: registers of the sdhc controller
125 * @sdhc_clk: Current clk of the sdhc controller
126 * @bus_width: bus width, 1bit, 4bit or 8bit
127 * @cfg: mmc config
128 * @mmc: mmc
129 * Following is used when Driver Model is enabled for MMC
130 * @dev: pointer for the device
131 * @non_removable: 0: removable; 1: non-removable
Fabio Estevam7e3d8a92020-01-06 20:11:27 -0300132 * @broken_cd: 0: use GPIO for card detect; 1: Do not use GPIO for card detect
Yangbo Lu982f4252019-06-21 11:42:27 +0800133 * @wp_enable: 1: enable checking wp; 0: no check
134 * @vs18_enable: 1: use 1.8V voltage; 0: use 3.3V
135 * @flags: ESDHC_FLAG_xx in include/fsl_esdhc_imx.h
136 * @caps: controller capabilities
137 * @tuning_step: tuning step setting in tuning_ctrl register
138 * @start_tuning_tap: the start point for tuning in tuning_ctrl register
139 * @strobe_dll_delay_target: settings in strobe_dllctrl
140 * @signal_voltage: indicating the current voltage
141 * @cd_gpio: gpio for card detection
142 * @wp_gpio: gpio for write protection
143 */
144struct fsl_esdhc_priv {
145 struct fsl_esdhc *esdhc_regs;
146 unsigned int sdhc_clk;
147 struct clk per_clk;
148 unsigned int clock;
149 unsigned int mode;
150 unsigned int bus_width;
151#if !CONFIG_IS_ENABLED(BLK)
152 struct mmc *mmc;
153#endif
154 struct udevice *dev;
155 int non_removable;
Fabio Estevam7e3d8a92020-01-06 20:11:27 -0300156 int broken_cd;
Yangbo Lu982f4252019-06-21 11:42:27 +0800157 int wp_enable;
158 int vs18_enable;
159 u32 flags;
160 u32 caps;
161 u32 tuning_step;
162 u32 tuning_start_tap;
163 u32 strobe_dll_delay_target;
164 u32 signal_voltage;
Ye Li7aa20fd2019-07-11 03:29:02 +0000165#if CONFIG_IS_ENABLED(DM_REGULATOR)
Yangbo Lu982f4252019-06-21 11:42:27 +0800166 struct udevice *vqmmc_dev;
167 struct udevice *vmmc_dev;
168#endif
Simon Glassfa4689a2019-12-06 21:41:35 -0700169#if CONFIG_IS_ENABLED(DM_GPIO)
Yangbo Lu982f4252019-06-21 11:42:27 +0800170 struct gpio_desc cd_gpio;
171 struct gpio_desc wp_gpio;
172#endif
173};
174
175/* Return the XFERTYP flags for a given command and data packet */
176static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data)
177{
178 uint xfertyp = 0;
179
180 if (data) {
181 xfertyp |= XFERTYP_DPSEL;
182#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
183 xfertyp |= XFERTYP_DMAEN;
184#endif
185 if (data->blocks > 1) {
186 xfertyp |= XFERTYP_MSBSEL;
187 xfertyp |= XFERTYP_BCEN;
188#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
189 xfertyp |= XFERTYP_AC12EN;
190#endif
191 }
192
193 if (data->flags & MMC_DATA_READ)
194 xfertyp |= XFERTYP_DTDSEL;
195 }
196
197 if (cmd->resp_type & MMC_RSP_CRC)
198 xfertyp |= XFERTYP_CCCEN;
199 if (cmd->resp_type & MMC_RSP_OPCODE)
200 xfertyp |= XFERTYP_CICEN;
201 if (cmd->resp_type & MMC_RSP_136)
202 xfertyp |= XFERTYP_RSPTYP_136;
203 else if (cmd->resp_type & MMC_RSP_BUSY)
204 xfertyp |= XFERTYP_RSPTYP_48_BUSY;
205 else if (cmd->resp_type & MMC_RSP_PRESENT)
206 xfertyp |= XFERTYP_RSPTYP_48;
207
208 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
209 xfertyp |= XFERTYP_CMDTYP_ABORT;
210
211 return XFERTYP_CMD(cmd->cmdidx) | xfertyp;
212}
213
214#ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
215/*
216 * PIO Read/Write Mode reduce the performace as DMA is not used in this mode.
217 */
218static void esdhc_pio_read_write(struct fsl_esdhc_priv *priv,
219 struct mmc_data *data)
220{
221 struct fsl_esdhc *regs = priv->esdhc_regs;
222 uint blocks;
223 char *buffer;
224 uint databuf;
225 uint size;
226 uint irqstat;
227 ulong start;
228
229 if (data->flags & MMC_DATA_READ) {
230 blocks = data->blocks;
231 buffer = data->dest;
232 while (blocks) {
233 start = get_timer(0);
234 size = data->blocksize;
235 irqstat = esdhc_read32(&regs->irqstat);
236 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BREN)) {
237 if (get_timer(start) > PIO_TIMEOUT) {
238 printf("\nData Read Failed in PIO Mode.");
239 return;
240 }
241 }
242 while (size && (!(irqstat & IRQSTAT_TC))) {
243 udelay(100); /* Wait before last byte transfer complete */
244 irqstat = esdhc_read32(&regs->irqstat);
245 databuf = in_le32(&regs->datport);
246 *((uint *)buffer) = databuf;
247 buffer += 4;
248 size -= 4;
249 }
250 blocks--;
251 }
252 } else {
253 blocks = data->blocks;
254 buffer = (char *)data->src;
255 while (blocks) {
256 start = get_timer(0);
257 size = data->blocksize;
258 irqstat = esdhc_read32(&regs->irqstat);
259 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BWEN)) {
260 if (get_timer(start) > PIO_TIMEOUT) {
261 printf("\nData Write Failed in PIO Mode.");
262 return;
263 }
264 }
265 while (size && (!(irqstat & IRQSTAT_TC))) {
266 udelay(100); /* Wait before last byte transfer complete */
267 databuf = *((uint *)buffer);
268 buffer += 4;
269 size -= 4;
270 irqstat = esdhc_read32(&regs->irqstat);
271 out_le32(&regs->datport, databuf);
272 }
273 blocks--;
274 }
275 }
276}
277#endif
278
279static int esdhc_setup_data(struct fsl_esdhc_priv *priv, struct mmc *mmc,
280 struct mmc_data *data)
281{
282 int timeout;
283 struct fsl_esdhc *regs = priv->esdhc_regs;
Yangbo Lu16b38542019-06-21 11:42:30 +0800284#if defined(CONFIG_S32V234) || defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)
Yangbo Lu982f4252019-06-21 11:42:27 +0800285 dma_addr_t addr;
286#endif
287 uint wml_value;
288
289 wml_value = data->blocksize/4;
290
291 if (data->flags & MMC_DATA_READ) {
292 if (wml_value > WML_RD_WML_MAX)
293 wml_value = WML_RD_WML_MAX_VAL;
294
295 esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
296#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
Yangbo Lu16b38542019-06-21 11:42:30 +0800297#if defined(CONFIG_S32V234) || defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)
Yangbo Lu982f4252019-06-21 11:42:27 +0800298 addr = virt_to_phys((void *)(data->dest));
299 if (upper_32_bits(addr))
300 printf("Error found for upper 32 bits\n");
301 else
302 esdhc_write32(&regs->dsaddr, lower_32_bits(addr));
303#else
304 esdhc_write32(&regs->dsaddr, (u32)data->dest);
305#endif
306#endif
307 } else {
308#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
309 flush_dcache_range((ulong)data->src,
310 (ulong)data->src+data->blocks
311 *data->blocksize);
312#endif
313 if (wml_value > WML_WR_WML_MAX)
314 wml_value = WML_WR_WML_MAX_VAL;
315 if (priv->wp_enable) {
316 if ((esdhc_read32(&regs->prsstat) &
317 PRSSTAT_WPSPL) == 0) {
318 printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
319 return -ETIMEDOUT;
320 }
321 } else {
Simon Glassfa4689a2019-12-06 21:41:35 -0700322#if CONFIG_IS_ENABLED(DM_GPIO)
323 if (dm_gpio_is_valid(&priv->wp_gpio) &&
324 dm_gpio_get_value(&priv->wp_gpio)) {
Yangbo Lu982f4252019-06-21 11:42:27 +0800325 printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
326 return -ETIMEDOUT;
327 }
328#endif
329 }
330
331 esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK,
332 wml_value << 16);
333#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
Yangbo Lu16b38542019-06-21 11:42:30 +0800334#if defined(CONFIG_S32V234) || defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)
Yangbo Lu982f4252019-06-21 11:42:27 +0800335 addr = virt_to_phys((void *)(data->src));
336 if (upper_32_bits(addr))
337 printf("Error found for upper 32 bits\n");
338 else
339 esdhc_write32(&regs->dsaddr, lower_32_bits(addr));
340#else
341 esdhc_write32(&regs->dsaddr, (u32)data->src);
342#endif
343#endif
344 }
345
346 esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
347
348 /* Calculate the timeout period for data transactions */
349 /*
350 * 1)Timeout period = (2^(timeout+13)) SD Clock cycles
351 * 2)Timeout period should be minimum 0.250sec as per SD Card spec
352 * So, Number of SD Clock cycles for 0.25sec should be minimum
353 * (SD Clock/sec * 0.25 sec) SD Clock cycles
354 * = (mmc->clock * 1/4) SD Clock cycles
355 * As 1) >= 2)
356 * => (2^(timeout+13)) >= mmc->clock * 1/4
357 * Taking log2 both the sides
358 * => timeout + 13 >= log2(mmc->clock/4)
359 * Rounding up to next power of 2
360 * => timeout + 13 = log2(mmc->clock/4) + 1
361 * => timeout + 13 = fls(mmc->clock/4)
362 *
363 * However, the MMC spec "It is strongly recommended for hosts to
364 * implement more than 500ms timeout value even if the card
365 * indicates the 250ms maximum busy length." Even the previous
366 * value of 300ms is known to be insufficient for some cards.
367 * So, we use
368 * => timeout + 13 = fls(mmc->clock/2)
369 */
370 timeout = fls(mmc->clock/2);
371 timeout -= 13;
372
373 if (timeout > 14)
374 timeout = 14;
375
376 if (timeout < 0)
377 timeout = 0;
378
379#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC_A001
380 if ((timeout == 4) || (timeout == 8) || (timeout == 12))
381 timeout++;
382#endif
383
384#ifdef ESDHCI_QUIRK_BROKEN_TIMEOUT_VALUE
385 timeout = 0xE;
386#endif
387 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16);
388
389 return 0;
390}
391
392static void check_and_invalidate_dcache_range
393 (struct mmc_cmd *cmd,
394 struct mmc_data *data) {
395 unsigned start = 0;
396 unsigned end = 0;
397 unsigned size = roundup(ARCH_DMA_MINALIGN,
398 data->blocks*data->blocksize);
Yangbo Lu16b38542019-06-21 11:42:30 +0800399#if defined(CONFIG_S32V234) || defined(CONFIG_IMX8) || defined(CONFIG_IMX8M)
Yangbo Lu982f4252019-06-21 11:42:27 +0800400 dma_addr_t addr;
401
402 addr = virt_to_phys((void *)(data->dest));
403 if (upper_32_bits(addr))
404 printf("Error found for upper 32 bits\n");
405 else
406 start = lower_32_bits(addr);
407#else
408 start = (unsigned)data->dest;
409#endif
410 end = start + size;
411 invalidate_dcache_range(start, end);
412}
413
414#ifdef CONFIG_MCF5441x
415/*
416 * Swaps 32-bit words to little-endian byte order.
417 */
418static inline void sd_swap_dma_buff(struct mmc_data *data)
419{
420 int i, size = data->blocksize >> 2;
421 u32 *buffer = (u32 *)data->dest;
422 u32 sw;
423
424 while (data->blocks--) {
425 for (i = 0; i < size; i++) {
426 sw = __sw32(*buffer);
427 *buffer++ = sw;
428 }
429 }
430}
431#endif
432
433/*
434 * Sends a command out on the bus. Takes the mmc pointer,
435 * a command pointer, and an optional data pointer.
436 */
437static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
438 struct mmc_cmd *cmd, struct mmc_data *data)
439{
440 int err = 0;
441 uint xfertyp;
442 uint irqstat;
443 u32 flags = IRQSTAT_CC | IRQSTAT_CTOE;
444 struct fsl_esdhc *regs = priv->esdhc_regs;
445 unsigned long start;
446
447#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
448 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
449 return 0;
450#endif
451
452 esdhc_write32(&regs->irqstat, -1);
453
454 sync();
455
456 /* Wait for the bus to be idle */
457 while ((esdhc_read32(&regs->prsstat) & PRSSTAT_CICHB) ||
458 (esdhc_read32(&regs->prsstat) & PRSSTAT_CIDHB))
459 ;
460
461 while (esdhc_read32(&regs->prsstat) & PRSSTAT_DLA)
462 ;
463
464 /* Wait at least 8 SD clock cycles before the next command */
465 /*
466 * Note: This is way more than 8 cycles, but 1ms seems to
467 * resolve timing issues with some cards
468 */
469 udelay(1000);
470
471 /* Set up for a data transfer if we have one */
472 if (data) {
473 err = esdhc_setup_data(priv, mmc, data);
474 if(err)
475 return err;
476
477 if (data->flags & MMC_DATA_READ)
478 check_and_invalidate_dcache_range(cmd, data);
479 }
480
481 /* Figure out the transfer arguments */
482 xfertyp = esdhc_xfertyp(cmd, data);
483
484 /* Mask all irqs */
485 esdhc_write32(&regs->irqsigen, 0);
486
487 /* Send the command */
488 esdhc_write32(&regs->cmdarg, cmd->cmdarg);
489#if defined(CONFIG_FSL_USDHC)
490 esdhc_write32(&regs->mixctrl,
491 (esdhc_read32(&regs->mixctrl) & 0xFFFFFF80) | (xfertyp & 0x7F)
492 | (mmc->ddr_mode ? XFERTYP_DDREN : 0));
493 esdhc_write32(&regs->xfertyp, xfertyp & 0xFFFF0000);
494#else
495 esdhc_write32(&regs->xfertyp, xfertyp);
496#endif
497
498 if ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK) ||
499 (cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200))
500 flags = IRQSTAT_BRR;
501
502 /* Wait for the command to complete */
503 start = get_timer(0);
504 while (!(esdhc_read32(&regs->irqstat) & flags)) {
505 if (get_timer(start) > 1000) {
506 err = -ETIMEDOUT;
507 goto out;
508 }
509 }
510
511 irqstat = esdhc_read32(&regs->irqstat);
512
513 if (irqstat & CMD_ERR) {
514 err = -ECOMM;
515 goto out;
516 }
517
518 if (irqstat & IRQSTAT_CTOE) {
519 err = -ETIMEDOUT;
520 goto out;
521 }
522
523 /* Switch voltage to 1.8V if CMD11 succeeded */
524 if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V) {
525 esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
526
527 printf("Run CMD11 1.8V switch\n");
528 /* Sleep for 5 ms - max time for card to switch to 1.8V */
529 udelay(5000);
530 }
531
532 /* Workaround for ESDHC errata ENGcm03648 */
533 if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
Peng Fan3dbea592019-07-10 09:35:30 +0000534 int timeout = 50000;
Yangbo Lu982f4252019-06-21 11:42:27 +0800535
Peng Fan3dbea592019-07-10 09:35:30 +0000536 /* Poll on DATA0 line for cmd with busy signal for 5000 ms */
Yangbo Lu982f4252019-06-21 11:42:27 +0800537 while (timeout > 0 && !(esdhc_read32(&regs->prsstat) &
538 PRSSTAT_DAT0)) {
539 udelay(100);
540 timeout--;
541 }
542
543 if (timeout <= 0) {
544 printf("Timeout waiting for DAT0 to go high!\n");
545 err = -ETIMEDOUT;
546 goto out;
547 }
548 }
549
550 /* Copy the response to the response buffer */
551 if (cmd->resp_type & MMC_RSP_136) {
552 u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0;
553
554 cmdrsp3 = esdhc_read32(&regs->cmdrsp3);
555 cmdrsp2 = esdhc_read32(&regs->cmdrsp2);
556 cmdrsp1 = esdhc_read32(&regs->cmdrsp1);
557 cmdrsp0 = esdhc_read32(&regs->cmdrsp0);
558 cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
559 cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
560 cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
561 cmd->response[3] = (cmdrsp0 << 8);
562 } else
563 cmd->response[0] = esdhc_read32(&regs->cmdrsp0);
564
565 /* Wait until all of the blocks are transferred */
566 if (data) {
567#ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
568 esdhc_pio_read_write(priv, data);
569#else
570 flags = DATA_COMPLETE;
571 if ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK) ||
572 (cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200)) {
573 flags = IRQSTAT_BRR;
574 }
575
576 do {
577 irqstat = esdhc_read32(&regs->irqstat);
578
579 if (irqstat & IRQSTAT_DTOE) {
580 err = -ETIMEDOUT;
581 goto out;
582 }
583
584 if (irqstat & DATA_ERR) {
585 err = -ECOMM;
586 goto out;
587 }
588 } while ((irqstat & flags) != flags);
589
590 /*
591 * Need invalidate the dcache here again to avoid any
592 * cache-fill during the DMA operations such as the
593 * speculative pre-fetching etc.
594 */
595 if (data->flags & MMC_DATA_READ) {
596 check_and_invalidate_dcache_range(cmd, data);
597#ifdef CONFIG_MCF5441x
598 sd_swap_dma_buff(data);
599#endif
600 }
601#endif
602 }
603
604out:
605 /* Reset CMD and DATA portions on error */
606 if (err) {
607 esdhc_write32(&regs->sysctl, esdhc_read32(&regs->sysctl) |
608 SYSCTL_RSTC);
609 while (esdhc_read32(&regs->sysctl) & SYSCTL_RSTC)
610 ;
611
612 if (data) {
613 esdhc_write32(&regs->sysctl,
614 esdhc_read32(&regs->sysctl) |
615 SYSCTL_RSTD);
616 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTD))
617 ;
618 }
619
620 /* If this was CMD11, then notify that power cycle is needed */
621 if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V)
622 printf("CMD11 to switch to 1.8V mode failed, card requires power cycle.\n");
623 }
624
625 esdhc_write32(&regs->irqstat, -1);
626
627 return err;
628}
629
630static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
631{
632 struct fsl_esdhc *regs = priv->esdhc_regs;
633 int div = 1;
634#ifdef ARCH_MXC
635#ifdef CONFIG_MX53
636 /* For i.MX53 eSDHCv3, SYSCTL.SDCLKFS may not be set to 0. */
637 int pre_div = (regs == (struct fsl_esdhc *)MMC_SDHC3_BASE_ADDR) ? 2 : 1;
638#else
639 int pre_div = 1;
640#endif
641#else
642 int pre_div = 2;
643#endif
644 int ddr_pre_div = mmc->ddr_mode ? 2 : 1;
645 int sdhc_clk = priv->sdhc_clk;
646 uint clk;
647
Yangbo Lu982f4252019-06-21 11:42:27 +0800648 while (sdhc_clk / (16 * pre_div * ddr_pre_div) > clock && pre_div < 256)
649 pre_div *= 2;
650
651 while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16)
652 div++;
653
654 pre_div >>= 1;
655 div -= 1;
656
657 clk = (pre_div << 8) | (div << 4);
658
659#ifdef CONFIG_FSL_USDHC
660 esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_CKEN);
661#else
662 esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
663#endif
664
665 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
666
667 udelay(10000);
668
669#ifdef CONFIG_FSL_USDHC
670 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN | VENDORSPEC_CKEN);
671#else
672 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
673#endif
674
675 priv->clock = clock;
676}
677
Yangbo Lu982f4252019-06-21 11:42:27 +0800678#ifdef MMC_SUPPORTS_TUNING
679static int esdhc_change_pinstate(struct udevice *dev)
680{
681 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
682 int ret;
683
684 switch (priv->mode) {
685 case UHS_SDR50:
686 case UHS_DDR50:
687 ret = pinctrl_select_state(dev, "state_100mhz");
688 break;
689 case UHS_SDR104:
690 case MMC_HS_200:
691 case MMC_HS_400:
Peng Fan69b9d3a2019-07-10 09:35:26 +0000692 case MMC_HS_400_ES:
Yangbo Lu982f4252019-06-21 11:42:27 +0800693 ret = pinctrl_select_state(dev, "state_200mhz");
694 break;
695 default:
696 ret = pinctrl_select_state(dev, "default");
697 break;
698 }
699
700 if (ret)
701 printf("%s %d error\n", __func__, priv->mode);
702
703 return ret;
704}
705
706static void esdhc_reset_tuning(struct mmc *mmc)
707{
708 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
709 struct fsl_esdhc *regs = priv->esdhc_regs;
710
711 if (priv->flags & ESDHC_FLAG_USDHC) {
712 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
713 esdhc_clrbits32(&regs->autoc12err,
714 MIX_CTRL_SMPCLK_SEL |
715 MIX_CTRL_EXE_TUNE);
716 }
717 }
718}
719
720static void esdhc_set_strobe_dll(struct mmc *mmc)
721{
722 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
723 struct fsl_esdhc *regs = priv->esdhc_regs;
724 u32 val;
725
726 if (priv->clock > ESDHC_STROBE_DLL_CLK_FREQ) {
727 writel(ESDHC_STROBE_DLL_CTRL_RESET, &regs->strobe_dllctrl);
728
729 /*
730 * enable strobe dll ctrl and adjust the delay target
731 * for the uSDHC loopback read clock
732 */
733 val = ESDHC_STROBE_DLL_CTRL_ENABLE |
734 (priv->strobe_dll_delay_target <<
735 ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT);
736 writel(val, &regs->strobe_dllctrl);
737 /* wait 1us to make sure strobe dll status register stable */
738 mdelay(1);
739 val = readl(&regs->strobe_dllstat);
740 if (!(val & ESDHC_STROBE_DLL_STS_REF_LOCK))
741 pr_warn("HS400 strobe DLL status REF not lock!\n");
742 if (!(val & ESDHC_STROBE_DLL_STS_SLV_LOCK))
743 pr_warn("HS400 strobe DLL status SLV not lock!\n");
744 }
745}
746
747static int esdhc_set_timing(struct mmc *mmc)
748{
749 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
750 struct fsl_esdhc *regs = priv->esdhc_regs;
751 u32 mixctrl;
752
753 mixctrl = readl(&regs->mixctrl);
754 mixctrl &= ~(MIX_CTRL_DDREN | MIX_CTRL_HS400_EN);
755
756 switch (mmc->selected_mode) {
757 case MMC_LEGACY:
Yangbo Lu982f4252019-06-21 11:42:27 +0800758 esdhc_reset_tuning(mmc);
759 writel(mixctrl, &regs->mixctrl);
760 break;
761 case MMC_HS_400:
Peng Fan69b9d3a2019-07-10 09:35:26 +0000762 case MMC_HS_400_ES:
Yangbo Lu982f4252019-06-21 11:42:27 +0800763 mixctrl |= MIX_CTRL_DDREN | MIX_CTRL_HS400_EN;
764 writel(mixctrl, &regs->mixctrl);
765 esdhc_set_strobe_dll(mmc);
766 break;
767 case MMC_HS:
768 case MMC_HS_52:
769 case MMC_HS_200:
770 case SD_HS:
771 case UHS_SDR12:
772 case UHS_SDR25:
773 case UHS_SDR50:
774 case UHS_SDR104:
775 writel(mixctrl, &regs->mixctrl);
776 break;
777 case UHS_DDR50:
778 case MMC_DDR_52:
779 mixctrl |= MIX_CTRL_DDREN;
780 writel(mixctrl, &regs->mixctrl);
781 break;
782 default:
783 printf("Not supported %d\n", mmc->selected_mode);
784 return -EINVAL;
785 }
786
787 priv->mode = mmc->selected_mode;
788
789 return esdhc_change_pinstate(mmc->dev);
790}
791
792static int esdhc_set_voltage(struct mmc *mmc)
793{
794 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
795 struct fsl_esdhc *regs = priv->esdhc_regs;
796 int ret;
797
798 priv->signal_voltage = mmc->signal_voltage;
799 switch (mmc->signal_voltage) {
800 case MMC_SIGNAL_VOLTAGE_330:
801 if (priv->vs18_enable)
Marek Vasutba79fed2020-05-22 18:28:33 +0200802 return -ENOTSUPP;
Yangbo Lu982f4252019-06-21 11:42:27 +0800803#if CONFIG_IS_ENABLED(DM_REGULATOR)
804 if (!IS_ERR_OR_NULL(priv->vqmmc_dev)) {
805 ret = regulator_set_value(priv->vqmmc_dev, 3300000);
806 if (ret) {
807 printf("Setting to 3.3V error");
808 return -EIO;
809 }
810 /* Wait for 5ms */
811 mdelay(5);
812 }
813#endif
814
815 esdhc_clrbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
816 if (!(esdhc_read32(&regs->vendorspec) &
817 ESDHC_VENDORSPEC_VSELECT))
818 return 0;
819
820 return -EAGAIN;
821 case MMC_SIGNAL_VOLTAGE_180:
822#if CONFIG_IS_ENABLED(DM_REGULATOR)
823 if (!IS_ERR_OR_NULL(priv->vqmmc_dev)) {
824 ret = regulator_set_value(priv->vqmmc_dev, 1800000);
825 if (ret) {
826 printf("Setting to 1.8V error");
827 return -EIO;
828 }
829 }
830#endif
831 esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
832 if (esdhc_read32(&regs->vendorspec) & ESDHC_VENDORSPEC_VSELECT)
833 return 0;
834
835 return -EAGAIN;
836 case MMC_SIGNAL_VOLTAGE_120:
837 return -ENOTSUPP;
838 default:
839 return 0;
840 }
841}
842
843static void esdhc_stop_tuning(struct mmc *mmc)
844{
845 struct mmc_cmd cmd;
846
847 cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
848 cmd.cmdarg = 0;
849 cmd.resp_type = MMC_RSP_R1b;
850
851 dm_mmc_send_cmd(mmc->dev, &cmd, NULL);
852}
853
854static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode)
855{
856 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
857 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
858 struct fsl_esdhc *regs = priv->esdhc_regs;
859 struct mmc *mmc = &plat->mmc;
860 u32 irqstaten = readl(&regs->irqstaten);
861 u32 irqsigen = readl(&regs->irqsigen);
862 int i, ret = -ETIMEDOUT;
863 u32 val, mixctrl;
864
865 /* clock tuning is not needed for upto 52MHz */
866 if (mmc->clock <= 52000000)
867 return 0;
868
869 /* This is readw/writew SDHCI_HOST_CONTROL2 when tuning */
870 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
871 val = readl(&regs->autoc12err);
872 mixctrl = readl(&regs->mixctrl);
873 val &= ~MIX_CTRL_SMPCLK_SEL;
874 mixctrl &= ~(MIX_CTRL_FBCLK_SEL | MIX_CTRL_AUTO_TUNE_EN);
875
876 val |= MIX_CTRL_EXE_TUNE;
877 mixctrl |= MIX_CTRL_FBCLK_SEL | MIX_CTRL_AUTO_TUNE_EN;
878
879 writel(val, &regs->autoc12err);
880 writel(mixctrl, &regs->mixctrl);
881 }
882
883 /* sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); */
884 mixctrl = readl(&regs->mixctrl);
885 mixctrl = MIX_CTRL_DTDSEL_READ | (mixctrl & ~MIX_CTRL_SDHCI_MASK);
886 writel(mixctrl, &regs->mixctrl);
887
888 writel(IRQSTATEN_BRR, &regs->irqstaten);
889 writel(IRQSTATEN_BRR, &regs->irqsigen);
890
891 /*
892 * Issue opcode repeatedly till Execute Tuning is set to 0 or the number
893 * of loops reaches 40 times.
894 */
895 for (i = 0; i < MAX_TUNING_LOOP; i++) {
896 u32 ctrl;
897
898 if (opcode == MMC_CMD_SEND_TUNING_BLOCK_HS200) {
899 if (mmc->bus_width == 8)
900 writel(0x7080, &regs->blkattr);
901 else if (mmc->bus_width == 4)
902 writel(0x7040, &regs->blkattr);
903 } else {
904 writel(0x7040, &regs->blkattr);
905 }
906
907 /* sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE) */
908 val = readl(&regs->mixctrl);
909 val = MIX_CTRL_DTDSEL_READ | (val & ~MIX_CTRL_SDHCI_MASK);
910 writel(val, &regs->mixctrl);
911
912 /* We are using STD tuning, no need to check return value */
913 mmc_send_tuning(mmc, opcode, NULL);
914
915 ctrl = readl(&regs->autoc12err);
916 if ((!(ctrl & MIX_CTRL_EXE_TUNE)) &&
917 (ctrl & MIX_CTRL_SMPCLK_SEL)) {
Yangbo Lu982f4252019-06-21 11:42:27 +0800918 ret = 0;
919 break;
920 }
Yangbo Lu982f4252019-06-21 11:42:27 +0800921 }
922
923 writel(irqstaten, &regs->irqstaten);
924 writel(irqsigen, &regs->irqsigen);
925
926 esdhc_stop_tuning(mmc);
927
928 return ret;
929}
930#endif
931
932static int esdhc_set_ios_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
933{
934 struct fsl_esdhc *regs = priv->esdhc_regs;
935 int ret __maybe_unused;
Peng Fan2cdf52b2019-11-04 17:14:15 +0800936 u32 clock;
Yangbo Lu982f4252019-06-21 11:42:27 +0800937
Yangbo Lu982f4252019-06-21 11:42:27 +0800938 /* Set the clock speed */
Peng Fan2cdf52b2019-11-04 17:14:15 +0800939 clock = mmc->clock;
940 if (clock < mmc->cfg->f_min)
941 clock = mmc->cfg->f_min;
942
943 if (priv->clock != clock)
944 set_sysctl(priv, mmc, clock);
Yangbo Lu982f4252019-06-21 11:42:27 +0800945
946#ifdef MMC_SUPPORTS_TUNING
947 if (mmc->clk_disable) {
948#ifdef CONFIG_FSL_USDHC
949 esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_CKEN);
950#else
951 esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
952#endif
953 } else {
954#ifdef CONFIG_FSL_USDHC
955 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN |
956 VENDORSPEC_CKEN);
957#else
958 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
959#endif
960 }
961
962 if (priv->mode != mmc->selected_mode) {
963 ret = esdhc_set_timing(mmc);
964 if (ret) {
965 printf("esdhc_set_timing error %d\n", ret);
966 return ret;
967 }
968 }
969
970 if (priv->signal_voltage != mmc->signal_voltage) {
971 ret = esdhc_set_voltage(mmc);
972 if (ret) {
Marek Vasutba79fed2020-05-22 18:28:33 +0200973 if (ret != -ENOTSUPP)
974 printf("esdhc_set_voltage error %d\n", ret);
Yangbo Lu982f4252019-06-21 11:42:27 +0800975 return ret;
976 }
977 }
978#endif
979
980 /* Set the bus width */
981 esdhc_clrbits32(&regs->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
982
983 if (mmc->bus_width == 4)
984 esdhc_setbits32(&regs->proctl, PROCTL_DTW_4);
985 else if (mmc->bus_width == 8)
986 esdhc_setbits32(&regs->proctl, PROCTL_DTW_8);
987
988 return 0;
989}
990
991static int esdhc_init_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
992{
993 struct fsl_esdhc *regs = priv->esdhc_regs;
994 ulong start;
995
996 /* Reset the entire host controller */
997 esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
998
999 /* Wait until the controller is available */
1000 start = get_timer(0);
1001 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA)) {
1002 if (get_timer(start) > 1000)
1003 return -ETIMEDOUT;
1004 }
1005
1006#if defined(CONFIG_FSL_USDHC)
1007 /* RSTA doesn't reset MMC_BOOT register, so manually reset it */
1008 esdhc_write32(&regs->mmcboot, 0x0);
1009 /* Reset MIX_CTRL and CLK_TUNE_CTRL_STATUS regs to 0 */
1010 esdhc_write32(&regs->mixctrl, 0x0);
1011 esdhc_write32(&regs->clktunectrlstatus, 0x0);
1012
1013 /* Put VEND_SPEC to default value */
1014 if (priv->vs18_enable)
1015 esdhc_write32(&regs->vendorspec, (VENDORSPEC_INIT |
1016 ESDHC_VENDORSPEC_VSELECT));
1017 else
1018 esdhc_write32(&regs->vendorspec, VENDORSPEC_INIT);
1019
1020 /* Disable DLL_CTRL delay line */
1021 esdhc_write32(&regs->dllctrl, 0x0);
1022#endif
1023
1024#ifndef ARCH_MXC
1025 /* Enable cache snooping */
1026 esdhc_write32(&regs->scr, 0x00000040);
1027#endif
1028
1029#ifndef CONFIG_FSL_USDHC
1030 esdhc_setbits32(&regs->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
1031#else
1032 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_HCKEN | VENDORSPEC_IPGEN);
1033#endif
1034
1035 /* Set the initial clock speed */
1036 mmc_set_clock(mmc, 400000, MMC_CLK_ENABLE);
1037
1038 /* Disable the BRR and BWR bits in IRQSTAT */
1039 esdhc_clrbits32(&regs->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR);
1040
1041#ifdef CONFIG_MCF5441x
1042 esdhc_write32(&regs->proctl, PROCTL_INIT | PROCTL_D3CD);
1043#else
1044 /* Put the PROCTL reg back to the default */
1045 esdhc_write32(&regs->proctl, PROCTL_INIT);
1046#endif
1047
1048 /* Set timout to the maximum value */
1049 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
1050
1051 return 0;
1052}
1053
1054static int esdhc_getcd_common(struct fsl_esdhc_priv *priv)
1055{
1056 struct fsl_esdhc *regs = priv->esdhc_regs;
1057 int timeout = 1000;
1058
1059#ifdef CONFIG_ESDHC_DETECT_QUIRK
1060 if (CONFIG_ESDHC_DETECT_QUIRK)
1061 return 1;
1062#endif
1063
1064#if CONFIG_IS_ENABLED(DM_MMC)
1065 if (priv->non_removable)
1066 return 1;
Fabio Estevam7e3d8a92020-01-06 20:11:27 -03001067
1068 if (priv->broken_cd)
1069 return 1;
Simon Glassfa4689a2019-12-06 21:41:35 -07001070#if CONFIG_IS_ENABLED(DM_GPIO)
Yangbo Lu982f4252019-06-21 11:42:27 +08001071 if (dm_gpio_is_valid(&priv->cd_gpio))
1072 return dm_gpio_get_value(&priv->cd_gpio);
1073#endif
1074#endif
1075
1076 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
1077 udelay(1000);
1078
1079 return timeout > 0;
1080}
1081
1082static int esdhc_reset(struct fsl_esdhc *regs)
1083{
1084 ulong start;
1085
1086 /* reset the controller */
1087 esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
1088
1089 /* hardware clears the bit when it is done */
1090 start = get_timer(0);
1091 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA)) {
1092 if (get_timer(start) > 100) {
1093 printf("MMC/SD: Reset never completed.\n");
1094 return -ETIMEDOUT;
1095 }
1096 }
1097
1098 return 0;
1099}
1100
1101#if !CONFIG_IS_ENABLED(DM_MMC)
1102static int esdhc_getcd(struct mmc *mmc)
1103{
1104 struct fsl_esdhc_priv *priv = mmc->priv;
1105
1106 return esdhc_getcd_common(priv);
1107}
1108
1109static int esdhc_init(struct mmc *mmc)
1110{
1111 struct fsl_esdhc_priv *priv = mmc->priv;
1112
1113 return esdhc_init_common(priv, mmc);
1114}
1115
1116static int esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
1117 struct mmc_data *data)
1118{
1119 struct fsl_esdhc_priv *priv = mmc->priv;
1120
1121 return esdhc_send_cmd_common(priv, mmc, cmd, data);
1122}
1123
1124static int esdhc_set_ios(struct mmc *mmc)
1125{
1126 struct fsl_esdhc_priv *priv = mmc->priv;
1127
1128 return esdhc_set_ios_common(priv, mmc);
1129}
1130
1131static const struct mmc_ops esdhc_ops = {
1132 .getcd = esdhc_getcd,
1133 .init = esdhc_init,
1134 .send_cmd = esdhc_send_cmd,
1135 .set_ios = esdhc_set_ios,
1136};
1137#endif
1138
1139static int fsl_esdhc_init(struct fsl_esdhc_priv *priv,
1140 struct fsl_esdhc_plat *plat)
1141{
1142 struct mmc_config *cfg;
1143 struct fsl_esdhc *regs;
1144 u32 caps, voltage_caps;
1145 int ret;
1146
1147 if (!priv)
1148 return -EINVAL;
1149
1150 regs = priv->esdhc_regs;
1151
1152 /* First reset the eSDHC controller */
1153 ret = esdhc_reset(regs);
1154 if (ret)
1155 return ret;
1156
1157#ifdef CONFIG_MCF5441x
1158 /* ColdFire, using SDHC_DATA[3] for card detection */
1159 esdhc_write32(&regs->proctl, PROCTL_INIT | PROCTL_D3CD);
1160#endif
1161
1162#ifndef CONFIG_FSL_USDHC
1163 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN
1164 | SYSCTL_IPGEN | SYSCTL_CKEN);
1165 /* Clearing tuning bits in case ROM has set it already */
1166 esdhc_write32(&regs->mixctrl, 0);
1167 esdhc_write32(&regs->autoc12err, 0);
1168 esdhc_write32(&regs->clktunectrlstatus, 0);
1169#else
1170 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN |
1171 VENDORSPEC_HCKEN | VENDORSPEC_IPGEN | VENDORSPEC_CKEN);
1172#endif
1173
1174 if (priv->vs18_enable)
1175 esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
1176
1177 writel(SDHCI_IRQ_EN_BITS, &regs->irqstaten);
1178 cfg = &plat->cfg;
1179#ifndef CONFIG_DM_MMC
1180 memset(cfg, '\0', sizeof(*cfg));
1181#endif
1182
1183 voltage_caps = 0;
1184 caps = esdhc_read32(&regs->hostcapblt);
1185
1186#ifdef CONFIG_MCF5441x
1187 /*
1188 * MCF5441x RM declares in more points that sdhc clock speed must
1189 * never exceed 25 Mhz. From this, the HS bit needs to be disabled
1190 * from host capabilities.
1191 */
1192 caps &= ~ESDHC_HOSTCAPBLT_HSS;
1193#endif
1194
1195#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC135
1196 caps = caps & ~(ESDHC_HOSTCAPBLT_SRS |
1197 ESDHC_HOSTCAPBLT_VS18 | ESDHC_HOSTCAPBLT_VS30);
1198#endif
1199
1200/* T4240 host controller capabilities register should have VS33 bit */
1201#ifdef CONFIG_SYS_FSL_MMC_HAS_CAPBLT_VS33
1202 caps = caps | ESDHC_HOSTCAPBLT_VS33;
1203#endif
1204
1205 if (caps & ESDHC_HOSTCAPBLT_VS18)
1206 voltage_caps |= MMC_VDD_165_195;
1207 if (caps & ESDHC_HOSTCAPBLT_VS30)
1208 voltage_caps |= MMC_VDD_29_30 | MMC_VDD_30_31;
1209 if (caps & ESDHC_HOSTCAPBLT_VS33)
1210 voltage_caps |= MMC_VDD_32_33 | MMC_VDD_33_34;
1211
1212 cfg->name = "FSL_SDHC";
1213#if !CONFIG_IS_ENABLED(DM_MMC)
1214 cfg->ops = &esdhc_ops;
1215#endif
1216#ifdef CONFIG_SYS_SD_VOLTAGE
1217 cfg->voltages = CONFIG_SYS_SD_VOLTAGE;
1218#else
1219 cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
1220#endif
1221 if ((cfg->voltages & voltage_caps) == 0) {
1222 printf("voltage not supported by controller\n");
1223 return -1;
1224 }
1225
1226 if (priv->bus_width == 8)
1227 cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
1228 else if (priv->bus_width == 4)
1229 cfg->host_caps = MMC_MODE_4BIT;
1230
1231 cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
1232#ifdef CONFIG_SYS_FSL_ESDHC_HAS_DDR_MODE
1233 cfg->host_caps |= MMC_MODE_DDR_52MHz;
1234#endif
1235
1236 if (priv->bus_width > 0) {
1237 if (priv->bus_width < 8)
1238 cfg->host_caps &= ~MMC_MODE_8BIT;
1239 if (priv->bus_width < 4)
1240 cfg->host_caps &= ~MMC_MODE_4BIT;
1241 }
1242
1243 if (caps & ESDHC_HOSTCAPBLT_HSS)
1244 cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
1245
1246#ifdef CONFIG_ESDHC_DETECT_8_BIT_QUIRK
1247 if (CONFIG_ESDHC_DETECT_8_BIT_QUIRK)
1248 cfg->host_caps &= ~MMC_MODE_8BIT;
1249#endif
1250
1251 cfg->host_caps |= priv->caps;
1252
1253 cfg->f_min = 400000;
1254 cfg->f_max = min(priv->sdhc_clk, (u32)200000000);
1255
1256 cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
1257
1258 writel(0, &regs->dllctrl);
1259 if (priv->flags & ESDHC_FLAG_USDHC) {
1260 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
1261 u32 val = readl(&regs->tuning_ctrl);
1262
1263 val |= ESDHC_STD_TUNING_EN;
1264 val &= ~ESDHC_TUNING_START_TAP_MASK;
1265 val |= priv->tuning_start_tap;
1266 val &= ~ESDHC_TUNING_STEP_MASK;
1267 val |= (priv->tuning_step) << ESDHC_TUNING_STEP_SHIFT;
Haibo Chen43162c32020-06-22 19:38:04 +08001268
1269 /* Disable the CMD CRC check for tuning, if not, need to
1270 * add some delay after every tuning command, because
1271 * hardware standard tuning logic will directly go to next
1272 * step once it detect the CMD CRC error, will not wait for
1273 * the card side to finally send out the tuning data, trigger
1274 * the buffer read ready interrupt immediately. If usdhc send
1275 * the next tuning command some eMMC card will stuck, can't
1276 * response, block the tuning procedure or the first command
1277 * after the whole tuning procedure always can't get any response.
1278 */
1279 val |= ESDHC_TUNING_CMD_CRC_CHECK_DISABLE;
Yangbo Lu982f4252019-06-21 11:42:27 +08001280 writel(val, &regs->tuning_ctrl);
1281 }
1282 }
1283
1284 return 0;
1285}
1286
1287#if !CONFIG_IS_ENABLED(DM_MMC)
1288static int fsl_esdhc_cfg_to_priv(struct fsl_esdhc_cfg *cfg,
1289 struct fsl_esdhc_priv *priv)
1290{
1291 if (!cfg || !priv)
1292 return -EINVAL;
1293
1294 priv->esdhc_regs = (struct fsl_esdhc *)(unsigned long)(cfg->esdhc_base);
1295 priv->bus_width = cfg->max_bus_width;
1296 priv->sdhc_clk = cfg->sdhc_clk;
1297 priv->wp_enable = cfg->wp_enable;
1298 priv->vs18_enable = cfg->vs18_enable;
1299
1300 return 0;
1301};
1302
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001303int fsl_esdhc_initialize(struct bd_info *bis, struct fsl_esdhc_cfg *cfg)
Yangbo Lu982f4252019-06-21 11:42:27 +08001304{
1305 struct fsl_esdhc_plat *plat;
1306 struct fsl_esdhc_priv *priv;
1307 struct mmc *mmc;
1308 int ret;
1309
1310 if (!cfg)
1311 return -EINVAL;
1312
1313 priv = calloc(sizeof(struct fsl_esdhc_priv), 1);
1314 if (!priv)
1315 return -ENOMEM;
1316 plat = calloc(sizeof(struct fsl_esdhc_plat), 1);
1317 if (!plat) {
1318 free(priv);
1319 return -ENOMEM;
1320 }
1321
1322 ret = fsl_esdhc_cfg_to_priv(cfg, priv);
1323 if (ret) {
1324 debug("%s xlate failure\n", __func__);
1325 free(plat);
1326 free(priv);
1327 return ret;
1328 }
1329
1330 ret = fsl_esdhc_init(priv, plat);
1331 if (ret) {
1332 debug("%s init failure\n", __func__);
1333 free(plat);
1334 free(priv);
1335 return ret;
1336 }
1337
1338 mmc = mmc_create(&plat->cfg, priv);
1339 if (!mmc)
1340 return -EIO;
1341
1342 priv->mmc = mmc;
1343
1344 return 0;
1345}
1346
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +09001347int fsl_esdhc_mmc_init(struct bd_info *bis)
Yangbo Lu982f4252019-06-21 11:42:27 +08001348{
1349 struct fsl_esdhc_cfg *cfg;
1350
1351 cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1);
1352 cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR;
1353 cfg->sdhc_clk = gd->arch.sdhc_clk;
1354 return fsl_esdhc_initialize(bis, cfg);
1355}
1356#endif
1357
Yangbo Lu982f4252019-06-21 11:42:27 +08001358#ifdef CONFIG_OF_LIBFDT
1359__weak int esdhc_status_fixup(void *blob, const char *compat)
1360{
1361#ifdef CONFIG_FSL_ESDHC_PIN_MUX
1362 if (!hwconfig("esdhc")) {
1363 do_fixup_by_compat(blob, compat, "status", "disabled",
1364 sizeof("disabled"), 1);
1365 return 1;
1366 }
1367#endif
1368 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
Walter Lozano8aff6732020-07-29 12:31:17 -03001389static int fsl_esdhc_ofdata_to_platdata(struct udevice *dev)
Yangbo Lu982f4252019-06-21 11:42:27 +08001390{
Walter Lozano8aff6732020-07-29 12:31:17 -03001391#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Yangbo Lu982f4252019-06-21 11:42:27 +08001392 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
Yangbo Lu982f4252019-06-21 11:42:27 +08001393#if CONFIG_IS_ENABLED(DM_REGULATOR)
1394 struct udevice *vqmmc_dev;
Walter Lozano8aff6732020-07-29 12:31:17 -03001395 int ret;
Yangbo Lu982f4252019-06-21 11:42:27 +08001396#endif
Walter Lozano8aff6732020-07-29 12:31:17 -03001397 const void *fdt = gd->fdt_blob;
1398 int node = dev_of_offset(dev);
1399
Yangbo Lu982f4252019-06-21 11:42:27 +08001400 fdt_addr_t addr;
1401 unsigned int val;
Yangbo Lu982f4252019-06-21 11:42:27 +08001402
1403 addr = dev_read_addr(dev);
1404 if (addr == FDT_ADDR_T_NONE)
1405 return -EINVAL;
Yangbo Lu982f4252019-06-21 11:42:27 +08001406 priv->esdhc_regs = (struct fsl_esdhc *)addr;
Yangbo Lu982f4252019-06-21 11:42:27 +08001407 priv->dev = dev;
1408 priv->mode = -1;
Yangbo Lu982f4252019-06-21 11:42:27 +08001409
1410 val = dev_read_u32_default(dev, "bus-width", -1);
1411 if (val == 8)
1412 priv->bus_width = 8;
1413 else if (val == 4)
1414 priv->bus_width = 4;
1415 else
1416 priv->bus_width = 1;
1417
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;
1426
Fabio Estevam7e3d8a92020-01-06 20:11:27 -03001427 if (dev_read_bool(dev, "broken-cd"))
1428 priv->broken_cd = 1;
1429
Yangbo Lu982f4252019-06-21 11:42:27 +08001430 if (dev_read_bool(dev, "non-removable")) {
1431 priv->non_removable = 1;
1432 } else {
1433 priv->non_removable = 0;
Simon Glassfa4689a2019-12-06 21:41:35 -07001434#if CONFIG_IS_ENABLED(DM_GPIO)
Yangbo Lu982f4252019-06-21 11:42:27 +08001435 gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio,
1436 GPIOD_IS_IN);
1437#endif
1438 }
1439
1440 if (dev_read_prop(dev, "fsl,wp-controller", NULL)) {
1441 priv->wp_enable = 1;
1442 } else {
1443 priv->wp_enable = 0;
Simon Glassfa4689a2019-12-06 21:41:35 -07001444#if CONFIG_IS_ENABLED(DM_GPIO)
Yangbo Lu982f4252019-06-21 11:42:27 +08001445 gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio,
1446 GPIOD_IS_IN);
1447#endif
1448 }
1449
1450 priv->vs18_enable = 0;
1451
1452#if CONFIG_IS_ENABLED(DM_REGULATOR)
1453 /*
1454 * If emmc I/O has a fixed voltage at 1.8V, this must be provided,
1455 * otherwise, emmc will work abnormally.
1456 */
1457 ret = device_get_supply_regulator(dev, "vqmmc-supply", &vqmmc_dev);
1458 if (ret) {
1459 dev_dbg(dev, "no vqmmc-supply\n");
1460 } else {
Marek Vasut34e67f92020-05-22 18:19:08 +02001461 priv->vqmmc_dev = vqmmc_dev;
Yangbo Lu982f4252019-06-21 11:42:27 +08001462 ret = regulator_set_enable(vqmmc_dev, true);
1463 if (ret) {
1464 dev_err(dev, "fail to enable vqmmc-supply\n");
1465 return ret;
1466 }
1467
1468 if (regulator_get_value(vqmmc_dev) == 1800000)
1469 priv->vs18_enable = 1;
1470 }
1471#endif
Walter Lozano8aff6732020-07-29 12:31:17 -03001472#endif
1473 return 0;
1474}
1475
1476static int fsl_esdhc_probe(struct udevice *dev)
1477{
1478 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
1479 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1480 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1481 struct esdhc_soc_data *data =
1482 (struct esdhc_soc_data *)dev_get_driver_data(dev);
1483 struct mmc *mmc;
1484#if !CONFIG_IS_ENABLED(BLK)
1485 struct blk_desc *bdesc;
1486#endif
1487 int ret;
1488
1489#if CONFIG_IS_ENABLED(OF_PLATDATA)
1490 struct dtd_fsl_esdhc *dtplat = &plat->dtplat;
1491 unsigned int val;
1492
1493 priv->esdhc_regs = map_sysmem(dtplat->reg[0], dtplat->reg[1]);
1494 val = plat->dtplat.bus_width;
1495 if (val == 8)
1496 priv->bus_width = 8;
1497 else if (val == 4)
1498 priv->bus_width = 4;
1499 else
1500 priv->bus_width = 1;
Walter Lozanocfc05fd2020-07-29 12:31:19 -03001501
1502 if (dtplat->non_removable)
1503 priv->non_removable = 1;
1504 else
1505 priv->non_removable = 0;
1506
1507 if (CONFIG_IS_ENABLED(DM_GPIO) && !priv->non_removable) {
1508 struct udevice *gpiodev;
1509 struct driver_info *info;
1510
1511 info = (struct driver_info *)dtplat->cd_gpios->node;
1512
1513 ret = device_get_by_driver_info(info, &gpiodev);
1514
1515 if (ret)
1516 return ret;
1517
1518 ret = gpio_dev_request_index(gpiodev, gpiodev->name, "cd-gpios",
1519 dtplat->cd_gpios->arg[0], GPIOD_IS_IN,
1520 dtplat->cd_gpios->arg[1], &priv->cd_gpio);
1521
1522 if (ret)
1523 return ret;
1524 }
Walter Lozano8aff6732020-07-29 12:31:17 -03001525#endif
1526
1527 if (data)
1528 priv->flags = data->flags;
Yangbo Lu982f4252019-06-21 11:42:27 +08001529
Yangbo Lu982f4252019-06-21 11:42:27 +08001530 /*
1531 * TODO:
1532 * Because lack of clk driver, if SDHC clk is not enabled,
1533 * need to enable it first before this driver is invoked.
1534 *
1535 * we use MXC_ESDHC_CLK to get clk freq.
1536 * If one would like to make this function work,
1537 * the aliases should be provided in dts as this:
1538 *
1539 * aliases {
1540 * mmc0 = &usdhc1;
1541 * mmc1 = &usdhc2;
1542 * mmc2 = &usdhc3;
1543 * mmc3 = &usdhc4;
1544 * };
1545 * Then if your board only supports mmc2 and mmc3, but we can
1546 * correctly get the seq as 2 and 3, then let mxc_get_clock
1547 * work as expected.
1548 */
1549
1550 init_clk_usdhc(dev->seq);
1551
Giulio Benettidbdbc632020-01-10 15:51:45 +01001552#if CONFIG_IS_ENABLED(CLK)
1553 /* Assigned clock already set clock */
1554 ret = clk_get_by_name(dev, "per", &priv->per_clk);
1555 if (ret) {
1556 printf("Failed to get per_clk\n");
1557 return ret;
1558 }
1559 ret = clk_enable(&priv->per_clk);
1560 if (ret) {
1561 printf("Failed to enable per_clk\n");
1562 return ret;
1563 }
Yangbo Lu982f4252019-06-21 11:42:27 +08001564
Giulio Benettidbdbc632020-01-10 15:51:45 +01001565 priv->sdhc_clk = clk_get_rate(&priv->per_clk);
1566#else
1567 priv->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK + dev->seq);
1568 if (priv->sdhc_clk <= 0) {
1569 dev_err(dev, "Unable to get clk for %s\n", dev->name);
1570 return -EINVAL;
Yangbo Lu982f4252019-06-21 11:42:27 +08001571 }
Giulio Benettidbdbc632020-01-10 15:51:45 +01001572#endif
Yangbo Lu982f4252019-06-21 11:42:27 +08001573
1574 ret = fsl_esdhc_init(priv, plat);
1575 if (ret) {
1576 dev_err(dev, "fsl_esdhc_init failure\n");
1577 return ret;
1578 }
1579
Walter Lozano8aff6732020-07-29 12:31:17 -03001580#if !CONFIG_IS_ENABLED(OF_PLATDATA)
Peng Fan3766a482019-07-10 09:35:24 +00001581 ret = mmc_of_parse(dev, &plat->cfg);
1582 if (ret)
1583 return ret;
Walter Lozano8aff6732020-07-29 12:31:17 -03001584#endif
Peng Fan3766a482019-07-10 09:35:24 +00001585
Yangbo Lu982f4252019-06-21 11:42:27 +08001586 mmc = &plat->mmc;
1587 mmc->cfg = &plat->cfg;
1588 mmc->dev = dev;
1589#if !CONFIG_IS_ENABLED(BLK)
1590 mmc->priv = priv;
1591
1592 /* Setup dsr related values */
1593 mmc->dsr_imp = 0;
1594 mmc->dsr = ESDHC_DRIVER_STAGE_VALUE;
1595 /* Setup the universal parts of the block interface just once */
1596 bdesc = mmc_get_blk_desc(mmc);
1597 bdesc->if_type = IF_TYPE_MMC;
1598 bdesc->removable = 1;
1599 bdesc->devnum = mmc_get_next_devnum();
1600 bdesc->block_read = mmc_bread;
1601 bdesc->block_write = mmc_bwrite;
1602 bdesc->block_erase = mmc_berase;
1603
1604 /* setup initial part type */
1605 bdesc->part_type = mmc->cfg->part_type;
1606 mmc_list_add(mmc);
1607#endif
1608
1609 upriv->mmc = mmc;
1610
1611 return esdhc_init_common(priv, mmc);
1612}
1613
1614#if CONFIG_IS_ENABLED(DM_MMC)
1615static int fsl_esdhc_get_cd(struct udevice *dev)
1616{
1617 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1618
1619 return esdhc_getcd_common(priv);
1620}
1621
1622static int fsl_esdhc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
1623 struct mmc_data *data)
1624{
1625 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1626 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1627
1628 return esdhc_send_cmd_common(priv, &plat->mmc, cmd, data);
1629}
1630
1631static int fsl_esdhc_set_ios(struct udevice *dev)
1632{
1633 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1634 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1635
1636 return esdhc_set_ios_common(priv, &plat->mmc);
1637}
1638
Peng Fan69b9d3a2019-07-10 09:35:26 +00001639#if CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)
1640static int fsl_esdhc_set_enhanced_strobe(struct udevice *dev)
1641{
1642 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1643 struct fsl_esdhc *regs = priv->esdhc_regs;
1644 u32 m;
1645
1646 m = readl(&regs->mixctrl);
1647 m |= MIX_CTRL_HS400_ES;
1648 writel(m, &regs->mixctrl);
1649
1650 return 0;
1651}
1652#endif
1653
Yangbo Lu982f4252019-06-21 11:42:27 +08001654static const struct dm_mmc_ops fsl_esdhc_ops = {
1655 .get_cd = fsl_esdhc_get_cd,
1656 .send_cmd = fsl_esdhc_send_cmd,
1657 .set_ios = fsl_esdhc_set_ios,
1658#ifdef MMC_SUPPORTS_TUNING
1659 .execute_tuning = fsl_esdhc_execute_tuning,
1660#endif
Peng Fan69b9d3a2019-07-10 09:35:26 +00001661#if CONFIG_IS_ENABLED(MMC_HS400_ES_SUPPORT)
1662 .set_enhanced_strobe = fsl_esdhc_set_enhanced_strobe,
1663#endif
Yangbo Lu982f4252019-06-21 11:42:27 +08001664};
1665#endif
1666
1667static struct esdhc_soc_data usdhc_imx7d_data = {
1668 .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
1669 | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
1670 | ESDHC_FLAG_HS400,
Yangbo Lu982f4252019-06-21 11:42:27 +08001671};
1672
Peng Fan457fe962019-07-10 09:35:28 +00001673static struct esdhc_soc_data usdhc_imx8qm_data = {
1674 .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING |
1675 ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200 |
1676 ESDHC_FLAG_HS400 | ESDHC_FLAG_HS400_ES,
1677};
1678
Yangbo Lu982f4252019-06-21 11:42:27 +08001679static const struct udevice_id fsl_esdhc_ids[] = {
1680 { .compatible = "fsl,imx53-esdhc", },
1681 { .compatible = "fsl,imx6ul-usdhc", },
1682 { .compatible = "fsl,imx6sx-usdhc", },
1683 { .compatible = "fsl,imx6sl-usdhc", },
1684 { .compatible = "fsl,imx6q-usdhc", },
1685 { .compatible = "fsl,imx7d-usdhc", .data = (ulong)&usdhc_imx7d_data,},
1686 { .compatible = "fsl,imx7ulp-usdhc", },
Peng Fan457fe962019-07-10 09:35:28 +00001687 { .compatible = "fsl,imx8qm-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
Peng Fand7689fa2019-11-04 17:31:17 +08001688 { .compatible = "fsl,imx8mm-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
1689 { .compatible = "fsl,imx8mn-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
1690 { .compatible = "fsl,imx8mq-usdhc", .data = (ulong)&usdhc_imx8qm_data,},
Giulio Benetti65b5ec12020-01-10 15:51:46 +01001691 { .compatible = "fsl,imxrt-usdhc", },
Yangbo Lu982f4252019-06-21 11:42:27 +08001692 { .compatible = "fsl,esdhc", },
1693 { /* sentinel */ }
1694};
1695
1696#if CONFIG_IS_ENABLED(BLK)
1697static int fsl_esdhc_bind(struct udevice *dev)
1698{
1699 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1700
1701 return mmc_bind(dev, &plat->mmc, &plat->cfg);
1702}
1703#endif
1704
1705U_BOOT_DRIVER(fsl_esdhc) = {
Walter Lozano904b0be2020-07-29 12:31:16 -03001706 .name = "fsl_esdhc",
Yangbo Lu982f4252019-06-21 11:42:27 +08001707 .id = UCLASS_MMC,
1708 .of_match = fsl_esdhc_ids,
Walter Lozano8aff6732020-07-29 12:31:17 -03001709 .ofdata_to_platdata = fsl_esdhc_ofdata_to_platdata,
Yangbo Lu982f4252019-06-21 11:42:27 +08001710 .ops = &fsl_esdhc_ops,
1711#if CONFIG_IS_ENABLED(BLK)
1712 .bind = fsl_esdhc_bind,
1713#endif
1714 .probe = fsl_esdhc_probe,
1715 .platdata_auto_alloc_size = sizeof(struct fsl_esdhc_plat),
1716 .priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv),
1717};
Walter Lozano8aff6732020-07-29 12:31:17 -03001718
1719U_BOOT_DRIVER_ALIAS(fsl_esdhc, fsl_imx6q_usdhc)
Yangbo Lu982f4252019-06-21 11:42:27 +08001720#endif