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