blob: ebb307e95066b34cfec338bc1019c99c42e79c7e [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Fleminge52ffb82008-10-30 16:47:16 -05002/*
Jerry Huanged413672011-01-06 23:42:19 -06003 * Copyright 2007, 2010-2011 Freescale Semiconductor, Inc
Yangbo Lue087cd62021-06-03 10:51:17 +08004 * Copyright 2019-2021 NXP
Andy Fleminge52ffb82008-10-30 16:47:16 -05005 * Andy Fleming
6 *
7 * Based vaguely on the pxa mmc code:
8 * (C) Copyright 2003
9 * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net
Andy Fleminge52ffb82008-10-30 16:47:16 -050010 */
11
12#include <config.h>
13#include <common.h>
14#include <command.h>
Simon Glass63334482019-11-14 12:57:39 -070015#include <cpu_func.h>
Jaehoon Chung7825d202016-07-19 16:33:36 +090016#include <errno.h>
Anton Vorontsovf751a3c2009-06-10 00:25:29 +040017#include <hwconfig.h>
Andy Fleminge52ffb82008-10-30 16:47:16 -050018#include <mmc.h>
19#include <part.h>
20#include <malloc.h>
Andy Fleminge52ffb82008-10-30 16:47:16 -050021#include <fsl_esdhc.h>
Anton Vorontsovf751a3c2009-06-10 00:25:29 +040022#include <fdt_support.h>
Simon Glass274e0b02020-05-10 11:39:56 -060023#include <asm/cache.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060024#include <asm/global_data.h>
Andy Fleminge52ffb82008-10-30 16:47:16 -050025#include <asm/io.h>
Peng Fana4d36f72016-03-25 14:16:56 +080026#include <dm.h>
Simon Glass9bc15642020-02-03 07:36:16 -070027#include <dm/device_compat.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060028#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060029#include <linux/delay.h>
Michael Wallec9bba2e2020-09-23 12:42:48 +020030#include <linux/dma-mapping.h>
Michael Walle081d4012020-10-12 10:07:14 +020031#include <sdhci.h>
Andy Fleminge52ffb82008-10-30 16:47:16 -050032
Andy Fleminge52ffb82008-10-30 16:47:16 -050033DECLARE_GLOBAL_DATA_PTR;
34
35struct fsl_esdhc {
Haijun.Zhangd49eb9e2013-10-30 11:37:55 +080036 uint dsaddr; /* SDMA system address register */
37 uint blkattr; /* Block attributes register */
38 uint cmdarg; /* Command argument register */
39 uint xfertyp; /* Transfer type register */
40 uint cmdrsp0; /* Command response 0 register */
41 uint cmdrsp1; /* Command response 1 register */
42 uint cmdrsp2; /* Command response 2 register */
43 uint cmdrsp3; /* Command response 3 register */
44 uint datport; /* Buffer data port register */
45 uint prsstat; /* Present state register */
46 uint proctl; /* Protocol control register */
47 uint sysctl; /* System Control Register */
48 uint irqstat; /* Interrupt status register */
49 uint irqstaten; /* Interrupt status enable register */
50 uint irqsigen; /* Interrupt signal enable register */
51 uint autoc12err; /* Auto CMD error status register */
52 uint hostcapblt; /* Host controller capabilities register */
53 uint wml; /* Watermark level register */
Yangbo Lu62b56b32019-06-21 11:42:29 +080054 char reserved1[8]; /* reserved */
Haijun.Zhangd49eb9e2013-10-30 11:37:55 +080055 uint fevt; /* Force event register */
56 uint admaes; /* ADMA error status register */
Michael Walle081d4012020-10-12 10:07:14 +020057 uint adsaddrl; /* ADMA system address low register */
58 uint adsaddrh; /* ADMA system address high register */
59 char reserved2[156];
Haijun.Zhangd49eb9e2013-10-30 11:37:55 +080060 uint hostver; /* Host controller version register */
Yangbo Lu62b56b32019-06-21 11:42:29 +080061 char reserved3[4]; /* reserved */
Peng Fanb9b42362018-01-21 19:00:22 +080062 uint dmaerraddr; /* DMA error address register */
Yangbo Lu62b56b32019-06-21 11:42:29 +080063 char reserved4[4]; /* reserved */
Peng Fanb9b42362018-01-21 19:00:22 +080064 uint dmaerrattr; /* DMA error attribute register */
Yangbo Lu62b56b32019-06-21 11:42:29 +080065 char reserved5[4]; /* reserved */
Haijun.Zhangd49eb9e2013-10-30 11:37:55 +080066 uint hostcapblt2; /* Host controller capabilities register 2 */
Yangbo Lu73da9c82020-09-01 16:58:01 +080067 char reserved6[8]; /* reserved */
68 uint tbctl; /* Tuning block control register */
Yangbo Lu8f9ace12020-09-01 16:58:05 +080069 char reserved7[32]; /* reserved */
70 uint sdclkctl; /* SD clock control register */
71 uint sdtimingctl; /* SD timing control register */
72 char reserved8[20]; /* reserved */
73 uint dllcfg0; /* DLL config 0 register */
Michael Walle7259dc52021-03-17 15:01:37 +010074 uint dllcfg1; /* DLL config 1 register */
75 char reserved9[8]; /* reserved */
Yangbo Lu8fbe95b2020-10-20 11:04:52 +080076 uint dllstat0; /* DLL status 0 register */
77 char reserved10[664];/* reserved */
Yangbo Lu62b56b32019-06-21 11:42:29 +080078 uint esdhcctl; /* eSDHC control register */
Andy Fleminge52ffb82008-10-30 16:47:16 -050079};
80
Simon Glassfa02ca52017-07-29 11:35:21 -060081struct fsl_esdhc_plat {
82 struct mmc_config cfg;
83 struct mmc mmc;
84};
85
Peng Fana4d36f72016-03-25 14:16:56 +080086/**
87 * struct fsl_esdhc_priv
88 *
89 * @esdhc_regs: registers of the sdhc controller
90 * @sdhc_clk: Current clk of the sdhc controller
91 * @bus_width: bus width, 1bit, 4bit or 8bit
92 * @cfg: mmc config
93 * @mmc: mmc
94 * Following is used when Driver Model is enabled for MMC
95 * @dev: pointer for the device
Peng Fana4d36f72016-03-25 14:16:56 +080096 * @cd_gpio: gpio for card detection
Peng Fan01eb1c42016-06-15 10:53:02 +080097 * @wp_gpio: gpio for write protection
Peng Fana4d36f72016-03-25 14:16:56 +080098 */
99struct fsl_esdhc_priv {
100 struct fsl_esdhc *esdhc_regs;
101 unsigned int sdhc_clk;
Yangbo Lu1ca7a9f2019-12-19 18:59:30 +0800102 bool is_sdhc_per_clk;
Peng Fanc4142702018-01-21 19:00:24 +0800103 unsigned int clock;
Yangbo Lu77f26322019-10-21 18:09:07 +0800104#if !CONFIG_IS_ENABLED(DM_MMC)
Peng Fana4d36f72016-03-25 14:16:56 +0800105 struct mmc *mmc;
Simon Glass407025d2017-07-29 11:35:24 -0600106#endif
Peng Fana4d36f72016-03-25 14:16:56 +0800107 struct udevice *dev;
Michael Walle081d4012020-10-12 10:07:14 +0200108 struct sdhci_adma_desc *adma_desc_table;
Michael Wallec9bba2e2020-09-23 12:42:48 +0200109 dma_addr_t dma_addr;
Peng Fana4d36f72016-03-25 14:16:56 +0800110};
111
Andy Fleminge52ffb82008-10-30 16:47:16 -0500112/* Return the XFERTYP flags for a given command and data packet */
Kim Phillipsf9e0b602012-10-29 13:34:44 +0000113static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data)
Andy Fleminge52ffb82008-10-30 16:47:16 -0500114{
115 uint xfertyp = 0;
116
117 if (data) {
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530118 xfertyp |= XFERTYP_DPSEL;
Michael Wallebc9e13e2020-10-12 10:07:13 +0200119 if (!IS_ENABLED(CONFIG_SYS_FSL_ESDHC_USE_PIO) &&
120 cmd->cmdidx != MMC_CMD_SEND_TUNING_BLOCK &&
Yangbo Lu73da9c82020-09-01 16:58:01 +0800121 cmd->cmdidx != MMC_CMD_SEND_TUNING_BLOCK_HS200)
122 xfertyp |= XFERTYP_DMAEN;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500123 if (data->blocks > 1) {
124 xfertyp |= XFERTYP_MSBSEL;
125 xfertyp |= XFERTYP_BCEN;
Michael Wallebc9e13e2020-10-12 10:07:13 +0200126 if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_ESDHC111))
127 xfertyp |= XFERTYP_AC12EN;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500128 }
129
130 if (data->flags & MMC_DATA_READ)
131 xfertyp |= XFERTYP_DTDSEL;
132 }
133
134 if (cmd->resp_type & MMC_RSP_CRC)
135 xfertyp |= XFERTYP_CCCEN;
136 if (cmd->resp_type & MMC_RSP_OPCODE)
137 xfertyp |= XFERTYP_CICEN;
138 if (cmd->resp_type & MMC_RSP_136)
139 xfertyp |= XFERTYP_RSPTYP_136;
140 else if (cmd->resp_type & MMC_RSP_BUSY)
141 xfertyp |= XFERTYP_RSPTYP_48_BUSY;
142 else if (cmd->resp_type & MMC_RSP_PRESENT)
143 xfertyp |= XFERTYP_RSPTYP_48;
144
Jason Liubef0ff02011-03-22 01:32:31 +0000145 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
146 xfertyp |= XFERTYP_CMDTYP_ABORT;
Yangbo Lub73a3d62016-01-21 17:33:19 +0800147
Andy Fleminge52ffb82008-10-30 16:47:16 -0500148 return XFERTYP_CMD(cmd->cmdidx) | xfertyp;
149}
150
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530151/*
152 * PIO Read/Write Mode reduce the performace as DMA is not used in this mode.
153 */
Simon Glass1d177d42017-07-29 11:35:17 -0600154static void esdhc_pio_read_write(struct fsl_esdhc_priv *priv,
155 struct mmc_data *data)
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530156{
Peng Fana4d36f72016-03-25 14:16:56 +0800157 struct fsl_esdhc *regs = priv->esdhc_regs;
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530158 uint blocks;
159 char *buffer;
160 uint databuf;
161 uint size;
162 uint irqstat;
Benoît Thébaudeau2a7b6f52017-10-29 22:08:58 +0100163 ulong start;
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530164
165 if (data->flags & MMC_DATA_READ) {
166 blocks = data->blocks;
167 buffer = data->dest;
168 while (blocks) {
Benoît Thébaudeau2a7b6f52017-10-29 22:08:58 +0100169 start = get_timer(0);
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530170 size = data->blocksize;
171 irqstat = esdhc_read32(&regs->irqstat);
Benoît Thébaudeau2a7b6f52017-10-29 22:08:58 +0100172 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BREN)) {
173 if (get_timer(start) > PIO_TIMEOUT) {
174 printf("\nData Read Failed in PIO Mode.");
175 return;
176 }
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530177 }
178 while (size && (!(irqstat & IRQSTAT_TC))) {
179 udelay(100); /* Wait before last byte transfer complete */
180 irqstat = esdhc_read32(&regs->irqstat);
181 databuf = in_le32(&regs->datport);
182 *((uint *)buffer) = databuf;
183 buffer += 4;
184 size -= 4;
185 }
186 blocks--;
187 }
188 } else {
189 blocks = data->blocks;
Wolfgang Denka40545c2010-05-09 23:52:59 +0200190 buffer = (char *)data->src;
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530191 while (blocks) {
Benoît Thébaudeau2a7b6f52017-10-29 22:08:58 +0100192 start = get_timer(0);
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530193 size = data->blocksize;
194 irqstat = esdhc_read32(&regs->irqstat);
Benoît Thébaudeau2a7b6f52017-10-29 22:08:58 +0100195 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BWEN)) {
196 if (get_timer(start) > PIO_TIMEOUT) {
197 printf("\nData Write Failed in PIO Mode.");
198 return;
199 }
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530200 }
201 while (size && (!(irqstat & IRQSTAT_TC))) {
202 udelay(100); /* Wait before last byte transfer complete */
203 databuf = *((uint *)buffer);
204 buffer += 4;
205 size -= 4;
206 irqstat = esdhc_read32(&regs->irqstat);
207 out_le32(&regs->datport, databuf);
208 }
209 blocks--;
210 }
211 }
212}
Dipen Dudhat5c72f352009-10-05 15:41:58 +0530213
Michael Wallebdd413f2020-09-23 12:42:49 +0200214static void esdhc_setup_watermark_level(struct fsl_esdhc_priv *priv,
215 struct mmc_data *data)
Andy Fleminge52ffb82008-10-30 16:47:16 -0500216{
Peng Fana4d36f72016-03-25 14:16:56 +0800217 struct fsl_esdhc *regs = priv->esdhc_regs;
Michael Wallebdd413f2020-09-23 12:42:49 +0200218 uint wml_value = data->blocksize / 4;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500219
220 if (data->flags & MMC_DATA_READ) {
Priyanka Jain02449632011-02-09 09:24:10 +0530221 if (wml_value > WML_RD_WML_MAX)
222 wml_value = WML_RD_WML_MAX_VAL;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500223
Roy Zange5853af2010-02-09 18:23:33 +0800224 esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500225 } else {
Priyanka Jain02449632011-02-09 09:24:10 +0530226 if (wml_value > WML_WR_WML_MAX)
227 wml_value = WML_WR_WML_MAX_VAL;
Yangbo Luf3bcc832019-10-31 18:54:25 +0800228
Roy Zange5853af2010-02-09 18:23:33 +0800229 esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK,
Michael Wallebdd413f2020-09-23 12:42:49 +0200230 wml_value << 16);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500231 }
Michael Wallebdd413f2020-09-23 12:42:49 +0200232}
Michael Wallebdd413f2020-09-23 12:42:49 +0200233
234static void esdhc_setup_dma(struct fsl_esdhc_priv *priv, struct mmc_data *data)
235{
236 uint trans_bytes = data->blocksize * data->blocks;
237 struct fsl_esdhc *regs = priv->esdhc_regs;
Michael Walle081d4012020-10-12 10:07:14 +0200238 phys_addr_t adma_addr;
Michael Wallebdd413f2020-09-23 12:42:49 +0200239 void *buf;
240
241 if (data->flags & MMC_DATA_WRITE)
242 buf = (void *)data->src;
243 else
244 buf = data->dest;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500245
Michael Wallebdd413f2020-09-23 12:42:49 +0200246 priv->dma_addr = dma_map_single(buf, trans_bytes,
247 mmc_get_dma_dir(data));
Michael Walle081d4012020-10-12 10:07:14 +0200248
249 if (IS_ENABLED(CONFIG_FSL_ESDHC_SUPPORT_ADMA2) &&
250 priv->adma_desc_table) {
251 debug("Using ADMA2\n");
252 /* prefer ADMA2 if it is available */
253 sdhci_prepare_adma_table(priv->adma_desc_table, data,
254 priv->dma_addr);
255
256 adma_addr = virt_to_phys(priv->adma_desc_table);
257 esdhc_write32(&regs->adsaddrl, lower_32_bits(adma_addr));
258 if (IS_ENABLED(CONFIG_DMA_ADDR_T_64BIT))
259 esdhc_write32(&regs->adsaddrh, upper_32_bits(adma_addr));
260 esdhc_clrsetbits32(&regs->proctl, PROCTL_DMAS_MASK,
261 PROCTL_DMAS_ADMA2);
262 } else {
263 debug("Using SDMA\n");
264 if (upper_32_bits(priv->dma_addr))
265 printf("Cannot use 64 bit addresses with SDMA\n");
266 esdhc_write32(&regs->dsaddr, lower_32_bits(priv->dma_addr));
267 esdhc_clrsetbits32(&regs->proctl, PROCTL_DMAS_MASK,
268 PROCTL_DMAS_SDMA);
269 }
270
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100271 esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
Michael Wallebdd413f2020-09-23 12:42:49 +0200272}
273
274static int esdhc_setup_data(struct fsl_esdhc_priv *priv, struct mmc *mmc,
275 struct mmc_data *data)
276{
277 int timeout;
278 bool is_write = data->flags & MMC_DATA_WRITE;
279 struct fsl_esdhc *regs = priv->esdhc_regs;
280
281 if (is_write && !(esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL)) {
282 printf("Can not write to locked SD card.\n");
283 return -EINVAL;
284 }
285
Michael Wallebc9e13e2020-10-12 10:07:13 +0200286 if (IS_ENABLED(CONFIG_SYS_FSL_ESDHC_USE_PIO))
287 esdhc_setup_watermark_level(priv, data);
288 else
289 esdhc_setup_dma(priv, data);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500290
291 /* Calculate the timeout period for data transactions */
Priyanka Jainc51b40d2011-03-03 09:18:56 +0530292 /*
293 * 1)Timeout period = (2^(timeout+13)) SD Clock cycles
294 * 2)Timeout period should be minimum 0.250sec as per SD Card spec
295 * So, Number of SD Clock cycles for 0.25sec should be minimum
296 * (SD Clock/sec * 0.25 sec) SD Clock cycles
Andrew Gabbasovd5b48662014-03-24 02:40:41 -0500297 * = (mmc->clock * 1/4) SD Clock cycles
Priyanka Jainc51b40d2011-03-03 09:18:56 +0530298 * As 1) >= 2)
Andrew Gabbasovd5b48662014-03-24 02:40:41 -0500299 * => (2^(timeout+13)) >= mmc->clock * 1/4
Priyanka Jainc51b40d2011-03-03 09:18:56 +0530300 * Taking log2 both the sides
Andrew Gabbasovd5b48662014-03-24 02:40:41 -0500301 * => timeout + 13 >= log2(mmc->clock/4)
Priyanka Jainc51b40d2011-03-03 09:18:56 +0530302 * Rounding up to next power of 2
Andrew Gabbasovd5b48662014-03-24 02:40:41 -0500303 * => timeout + 13 = log2(mmc->clock/4) + 1
304 * => timeout + 13 = fls(mmc->clock/4)
Yangbo Lu9d7f3212015-12-30 14:19:30 +0800305 *
306 * However, the MMC spec "It is strongly recommended for hosts to
307 * implement more than 500ms timeout value even if the card
308 * indicates the 250ms maximum busy length." Even the previous
309 * value of 300ms is known to be insufficient for some cards.
310 * So, we use
311 * => timeout + 13 = fls(mmc->clock/2)
Priyanka Jainc51b40d2011-03-03 09:18:56 +0530312 */
Yangbo Lu9d7f3212015-12-30 14:19:30 +0800313 timeout = fls(mmc->clock/2);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500314 timeout -= 13;
315
316 if (timeout > 14)
317 timeout = 14;
318
319 if (timeout < 0)
320 timeout = 0;
321
Michael Wallebc9e13e2020-10-12 10:07:13 +0200322 if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_ESDHC_A001) &&
323 (timeout == 4 || timeout == 8 || timeout == 12))
Kumar Gala9a878d52011-01-29 15:36:10 -0600324 timeout++;
Kumar Gala9a878d52011-01-29 15:36:10 -0600325
Michael Wallebc9e13e2020-10-12 10:07:13 +0200326 if (IS_ENABLED(ESDHCI_QUIRK_BROKEN_TIMEOUT_VALUE))
327 timeout = 0xE;
328
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100329 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500330
331 return 0;
332}
333
Andy Fleminge52ffb82008-10-30 16:47:16 -0500334/*
335 * Sends a command out on the bus. Takes the mmc pointer,
336 * a command pointer, and an optional data pointer.
337 */
Simon Glass6aa55dc2017-07-29 11:35:18 -0600338static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
339 struct mmc_cmd *cmd, struct mmc_data *data)
Andy Fleminge52ffb82008-10-30 16:47:16 -0500340{
Andrew Gabbasova04a6e02014-03-24 02:41:06 -0500341 int err = 0;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500342 uint xfertyp;
343 uint irqstat;
Peng Fanc4142702018-01-21 19:00:24 +0800344 u32 flags = IRQSTAT_CC | IRQSTAT_CTOE;
Peng Fana4d36f72016-03-25 14:16:56 +0800345 struct fsl_esdhc *regs = priv->esdhc_regs;
Fabio Estevam7300ef52018-11-19 10:31:53 -0200346 unsigned long start;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500347
Michael Wallebc9e13e2020-10-12 10:07:13 +0200348 if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_ESDHC111) &&
349 cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
Jerry Huanged413672011-01-06 23:42:19 -0600350 return 0;
Jerry Huanged413672011-01-06 23:42:19 -0600351
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100352 esdhc_write32(&regs->irqstat, -1);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500353
354 sync();
355
356 /* Wait for the bus to be idle */
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100357 while ((esdhc_read32(&regs->prsstat) & PRSSTAT_CICHB) ||
358 (esdhc_read32(&regs->prsstat) & PRSSTAT_CIDHB))
359 ;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500360
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100361 while (esdhc_read32(&regs->prsstat) & PRSSTAT_DLA)
362 ;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500363
Andy Fleminge52ffb82008-10-30 16:47:16 -0500364 /* Set up for a data transfer if we have one */
365 if (data) {
Simon Glass1d177d42017-07-29 11:35:17 -0600366 err = esdhc_setup_data(priv, mmc, data);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500367 if(err)
368 return err;
369 }
370
371 /* Figure out the transfer arguments */
372 xfertyp = esdhc_xfertyp(cmd, data);
373
Andrew Gabbasov4816b7a2013-06-11 10:34:22 -0500374 /* Mask all irqs */
375 esdhc_write32(&regs->irqsigen, 0);
376
Andy Fleminge52ffb82008-10-30 16:47:16 -0500377 /* Send the command */
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100378 esdhc_write32(&regs->cmdarg, cmd->cmdarg);
379 esdhc_write32(&regs->xfertyp, xfertyp);
Dirk Behmed8552d62012-03-26 03:13:05 +0000380
Yangbo Lu73da9c82020-09-01 16:58:01 +0800381 if (cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK ||
382 cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200)
383 flags = IRQSTAT_BRR;
384
Andy Fleminge52ffb82008-10-30 16:47:16 -0500385 /* Wait for the command to complete */
Fabio Estevam7300ef52018-11-19 10:31:53 -0200386 start = get_timer(0);
387 while (!(esdhc_read32(&regs->irqstat) & flags)) {
388 if (get_timer(start) > 1000) {
389 err = -ETIMEDOUT;
390 goto out;
391 }
392 }
Andy Fleminge52ffb82008-10-30 16:47:16 -0500393
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100394 irqstat = esdhc_read32(&regs->irqstat);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500395
Andrew Gabbasova04a6e02014-03-24 02:41:06 -0500396 if (irqstat & CMD_ERR) {
Jaehoon Chung7825d202016-07-19 16:33:36 +0900397 err = -ECOMM;
Andrew Gabbasova04a6e02014-03-24 02:41:06 -0500398 goto out;
Dirk Behmed8552d62012-03-26 03:13:05 +0000399 }
400
Andrew Gabbasova04a6e02014-03-24 02:41:06 -0500401 if (irqstat & IRQSTAT_CTOE) {
Jaehoon Chung7825d202016-07-19 16:33:36 +0900402 err = -ETIMEDOUT;
Andrew Gabbasova04a6e02014-03-24 02:41:06 -0500403 goto out;
404 }
Andy Fleminge52ffb82008-10-30 16:47:16 -0500405
Dirk Behmed8552d62012-03-26 03:13:05 +0000406 /* Workaround for ESDHC errata ENGcm03648 */
407 if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
Yangbo Lu3ffa8512015-04-15 10:13:12 +0800408 int timeout = 6000;
Dirk Behmed8552d62012-03-26 03:13:05 +0000409
Yangbo Lu3ffa8512015-04-15 10:13:12 +0800410 /* Poll on DATA0 line for cmd with busy signal for 600 ms */
Dirk Behmed8552d62012-03-26 03:13:05 +0000411 while (timeout > 0 && !(esdhc_read32(&regs->prsstat) &
412 PRSSTAT_DAT0)) {
413 udelay(100);
414 timeout--;
415 }
416
417 if (timeout <= 0) {
418 printf("Timeout waiting for DAT0 to go high!\n");
Jaehoon Chung7825d202016-07-19 16:33:36 +0900419 err = -ETIMEDOUT;
Andrew Gabbasova04a6e02014-03-24 02:41:06 -0500420 goto out;
Dirk Behmed8552d62012-03-26 03:13:05 +0000421 }
422 }
423
Andy Fleminge52ffb82008-10-30 16:47:16 -0500424 /* Copy the response to the response buffer */
425 if (cmd->resp_type & MMC_RSP_136) {
426 u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0;
427
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100428 cmdrsp3 = esdhc_read32(&regs->cmdrsp3);
429 cmdrsp2 = esdhc_read32(&regs->cmdrsp2);
430 cmdrsp1 = esdhc_read32(&regs->cmdrsp1);
431 cmdrsp0 = esdhc_read32(&regs->cmdrsp0);
Rabin Vincentb6eed942009-04-05 13:30:56 +0530432 cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
433 cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
434 cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
435 cmd->response[3] = (cmdrsp0 << 8);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500436 } else
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100437 cmd->response[0] = esdhc_read32(&regs->cmdrsp0);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500438
439 /* Wait until all of the blocks are transferred */
440 if (data) {
Michael Wallebc9e13e2020-10-12 10:07:13 +0200441 if (IS_ENABLED(CONFIG_SYS_FSL_ESDHC_USE_PIO)) {
442 esdhc_pio_read_write(priv, data);
443 } else {
444 flags = DATA_COMPLETE;
445 if (cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK ||
446 cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200)
447 flags = IRQSTAT_BRR;
Yangbo Lu73da9c82020-09-01 16:58:01 +0800448
Michael Wallebc9e13e2020-10-12 10:07:13 +0200449 do {
450 irqstat = esdhc_read32(&regs->irqstat);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500451
Michael Wallebc9e13e2020-10-12 10:07:13 +0200452 if (irqstat & IRQSTAT_DTOE) {
453 err = -ETIMEDOUT;
454 goto out;
455 }
Frans Meulenbroeks010ba982010-07-31 04:45:18 +0000456
Michael Wallebc9e13e2020-10-12 10:07:13 +0200457 if (irqstat & DATA_ERR) {
458 err = -ECOMM;
459 goto out;
460 }
461 } while ((irqstat & flags) != flags);
Ye.Li33a56b12014-02-20 18:00:57 +0800462
Michael Wallebc9e13e2020-10-12 10:07:13 +0200463 /*
464 * Need invalidate the dcache here again to avoid any
465 * cache-fill during the DMA operations such as the
466 * speculative pre-fetching etc.
467 */
468 dma_unmap_single(priv->dma_addr,
469 data->blocks * data->blocksize,
470 mmc_get_dma_dir(data));
471 }
Andy Fleminge52ffb82008-10-30 16:47:16 -0500472 }
473
Andrew Gabbasova04a6e02014-03-24 02:41:06 -0500474out:
475 /* Reset CMD and DATA portions on error */
476 if (err) {
477 esdhc_write32(&regs->sysctl, esdhc_read32(&regs->sysctl) |
478 SYSCTL_RSTC);
479 while (esdhc_read32(&regs->sysctl) & SYSCTL_RSTC)
480 ;
481
482 if (data) {
483 esdhc_write32(&regs->sysctl,
484 esdhc_read32(&regs->sysctl) |
485 SYSCTL_RSTD);
486 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTD))
487 ;
488 }
489 }
490
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100491 esdhc_write32(&regs->irqstat, -1);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500492
Andrew Gabbasova04a6e02014-03-24 02:41:06 -0500493 return err;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500494}
495
Simon Glass1d177d42017-07-29 11:35:17 -0600496static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
Andy Fleminge52ffb82008-10-30 16:47:16 -0500497{
Benoît Thébaudeau22464e02018-01-16 22:44:18 +0100498 struct fsl_esdhc *regs = priv->esdhc_regs;
Benoît Thébaudeaue16e9222017-05-03 11:59:03 +0200499 int div = 1;
Benoît Thébaudeaue16e9222017-05-03 11:59:03 +0200500 int pre_div = 2;
Yinbo Zhu101d3ef2019-07-16 15:09:11 +0800501 unsigned int sdhc_clk = priv->sdhc_clk;
502 u32 time_out;
503 u32 value;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500504 uint clk;
505
Pantelis Antoniou2c850462014-03-11 19:34:20 +0200506 if (clock < mmc->cfg->f_min)
507 clock = mmc->cfg->f_min;
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100508
Yangbo Lu4ee9b862019-10-21 18:09:09 +0800509 while (sdhc_clk / (16 * pre_div) > clock && pre_div < 256)
Lukasz Majewski2a521832019-05-07 17:47:28 +0200510 pre_div *= 2;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500511
Yangbo Lu4ee9b862019-10-21 18:09:09 +0800512 while (sdhc_clk / (div * pre_div) > clock && div < 16)
Lukasz Majewski2a521832019-05-07 17:47:28 +0200513 div++;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500514
Michael Walle148dc612021-03-17 15:01:36 +0100515 if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_A011334) &&
516 clock == 200000000 && mmc->selected_mode == MMC_HS_400) {
517 u32 div_ratio = pre_div * div;
518
519 if (div_ratio <= 4) {
520 pre_div = 4;
521 div = 1;
522 } else if (div_ratio <= 8) {
523 pre_div = 4;
524 div = 2;
525 } else if (div_ratio <= 12) {
526 pre_div = 4;
527 div = 3;
528 } else {
529 printf("unsupported clock division.\n");
530 }
531 }
532
Yangbo Ludd08eea2020-09-01 16:58:06 +0800533 mmc->clock = sdhc_clk / pre_div / div;
534 priv->clock = mmc->clock;
535
Benoît Thébaudeaue16e9222017-05-03 11:59:03 +0200536 pre_div >>= 1;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500537 div -= 1;
538
539 clk = (pre_div << 8) | (div << 4);
540
Kumar Gala09876a32010-03-18 15:51:05 -0500541 esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100542
543 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500544
Yinbo Zhu101d3ef2019-07-16 15:09:11 +0800545 time_out = 20;
546 value = PRSSTAT_SDSTB;
547 while (!(esdhc_read32(&regs->prsstat) & value)) {
548 if (time_out == 0) {
549 printf("fsl_esdhc: Internal clock never stabilised.\n");
550 break;
551 }
552 time_out--;
553 mdelay(1);
554 }
Andy Fleminge52ffb82008-10-30 16:47:16 -0500555
Eric Nelsonc8e615c2015-12-04 12:32:48 -0700556 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500557}
558
Simon Glass1d177d42017-07-29 11:35:17 -0600559static void esdhc_clock_control(struct fsl_esdhc_priv *priv, bool enable)
Yangbo Lu163beec2015-04-22 13:57:40 +0800560{
Peng Fana4d36f72016-03-25 14:16:56 +0800561 struct fsl_esdhc *regs = priv->esdhc_regs;
Yangbo Lu163beec2015-04-22 13:57:40 +0800562 u32 value;
563 u32 time_out;
564
565 value = esdhc_read32(&regs->sysctl);
566
567 if (enable)
568 value |= SYSCTL_CKEN;
569 else
570 value &= ~SYSCTL_CKEN;
571
572 esdhc_write32(&regs->sysctl, value);
573
574 time_out = 20;
575 value = PRSSTAT_SDSTB;
576 while (!(esdhc_read32(&regs->prsstat) & value)) {
577 if (time_out == 0) {
578 printf("fsl_esdhc: Internal clock never stabilised.\n");
579 break;
580 }
581 time_out--;
582 mdelay(1);
583 }
Peng Fanc4142702018-01-21 19:00:24 +0800584}
Yangbo Lu163beec2015-04-22 13:57:40 +0800585
Yangbo Lu8f9ace12020-09-01 16:58:05 +0800586static void esdhc_flush_async_fifo(struct fsl_esdhc_priv *priv)
587{
588 struct fsl_esdhc *regs = priv->esdhc_regs;
589 u32 time_out;
590
591 esdhc_setbits32(&regs->esdhcctl, ESDHCCTL_FAF);
592
593 time_out = 20;
594 while (esdhc_read32(&regs->esdhcctl) & ESDHCCTL_FAF) {
595 if (time_out == 0) {
596 printf("fsl_esdhc: Flush asynchronous FIFO timeout.\n");
597 break;
598 }
599 time_out--;
600 mdelay(1);
601 }
602}
603
604static void esdhc_tuning_block_enable(struct fsl_esdhc_priv *priv,
605 bool en)
606{
607 struct fsl_esdhc *regs = priv->esdhc_regs;
608
609 esdhc_clock_control(priv, false);
610 esdhc_flush_async_fifo(priv);
611 if (en)
612 esdhc_setbits32(&regs->tbctl, TBCTL_TB_EN);
613 else
614 esdhc_clrbits32(&regs->tbctl, TBCTL_TB_EN);
615 esdhc_clock_control(priv, true);
616}
617
618static void esdhc_exit_hs400(struct fsl_esdhc_priv *priv)
619{
620 struct fsl_esdhc *regs = priv->esdhc_regs;
621
622 esdhc_clrbits32(&regs->sdtimingctl, FLW_CTL_BG);
623 esdhc_clrbits32(&regs->sdclkctl, CMD_CLK_CTL);
624
625 esdhc_clock_control(priv, false);
626 esdhc_clrbits32(&regs->tbctl, HS400_MODE);
627 esdhc_clock_control(priv, true);
628
629 esdhc_clrbits32(&regs->dllcfg0, DLL_FREQ_SEL | DLL_ENABLE);
630 esdhc_clrbits32(&regs->tbctl, HS400_WNDW_ADJUST);
631
632 esdhc_tuning_block_enable(priv, false);
633}
634
Yangbo Lu8fbe95b2020-10-20 11:04:52 +0800635static int esdhc_set_timing(struct fsl_esdhc_priv *priv, enum bus_mode mode)
Yangbo Lu73da9c82020-09-01 16:58:01 +0800636{
637 struct fsl_esdhc *regs = priv->esdhc_regs;
Yangbo Lu8fbe95b2020-10-20 11:04:52 +0800638 ulong start;
639 u32 val;
Yangbo Lu73da9c82020-09-01 16:58:01 +0800640
Yangbo Lu8f9ace12020-09-01 16:58:05 +0800641 /* Exit HS400 mode before setting any other mode */
642 if (esdhc_read32(&regs->tbctl) & HS400_MODE &&
643 mode != MMC_HS_400)
644 esdhc_exit_hs400(priv);
645
Yangbo Lu73da9c82020-09-01 16:58:01 +0800646 esdhc_clock_control(priv, false);
647
648 if (mode == MMC_HS_200)
649 esdhc_clrsetbits32(&regs->autoc12err, UHSM_MASK,
650 UHSM_SDR104_HS200);
Yangbo Lu8f9ace12020-09-01 16:58:05 +0800651 if (mode == MMC_HS_400) {
652 esdhc_setbits32(&regs->tbctl, HS400_MODE);
653 esdhc_setbits32(&regs->sdclkctl, CMD_CLK_CTL);
654 esdhc_clock_control(priv, true);
Yangbo Lu73da9c82020-09-01 16:58:01 +0800655
Yangbo Lu9ac60a42020-09-01 16:58:07 +0800656 if (priv->clock == 200000000)
657 esdhc_setbits32(&regs->dllcfg0, DLL_FREQ_SEL);
658
659 esdhc_setbits32(&regs->dllcfg0, DLL_ENABLE);
Yangbo Lu8fbe95b2020-10-20 11:04:52 +0800660
661 esdhc_setbits32(&regs->dllcfg0, DLL_RESET);
662 udelay(1);
663 esdhc_clrbits32(&regs->dllcfg0, DLL_RESET);
664
665 start = get_timer(0);
666 val = DLL_STS_SLV_LOCK;
667 while (!(esdhc_read32(&regs->dllstat0) & val)) {
668 if (get_timer(start) > 1000) {
669 printf("fsl_esdhc: delay chain lock timeout\n");
670 return -ETIMEDOUT;
671 }
672 }
673
Yangbo Lu8f9ace12020-09-01 16:58:05 +0800674 esdhc_setbits32(&regs->tbctl, HS400_WNDW_ADJUST);
675
676 esdhc_clock_control(priv, false);
677 esdhc_flush_async_fifo(priv);
678 }
Yangbo Lu73da9c82020-09-01 16:58:01 +0800679 esdhc_clock_control(priv, true);
Yangbo Lu8fbe95b2020-10-20 11:04:52 +0800680 return 0;
Yangbo Lu73da9c82020-09-01 16:58:01 +0800681}
682
Simon Glass6aa55dc2017-07-29 11:35:18 -0600683static int esdhc_set_ios_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
Andy Fleminge52ffb82008-10-30 16:47:16 -0500684{
Peng Fana4d36f72016-03-25 14:16:56 +0800685 struct fsl_esdhc *regs = priv->esdhc_regs;
Yangbo Lu8fbe95b2020-10-20 11:04:52 +0800686 int ret;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500687
Yangbo Lu1ca7a9f2019-12-19 18:59:30 +0800688 if (priv->is_sdhc_per_clk) {
689 /* Select to use peripheral clock */
690 esdhc_clock_control(priv, false);
691 esdhc_setbits32(&regs->esdhcctl, ESDHCCTL_PCS);
692 esdhc_clock_control(priv, true);
693 }
694
Yangbo Lu8f9ace12020-09-01 16:58:05 +0800695 if (mmc->selected_mode == MMC_HS_400)
696 esdhc_tuning_block_enable(priv, true);
697
Andy Fleminge52ffb82008-10-30 16:47:16 -0500698 /* Set the clock speed */
Peng Fanc4142702018-01-21 19:00:24 +0800699 if (priv->clock != mmc->clock)
700 set_sysctl(priv, mmc, mmc->clock);
701
Yangbo Lu73da9c82020-09-01 16:58:01 +0800702 /* Set timing */
Yangbo Lu8fbe95b2020-10-20 11:04:52 +0800703 ret = esdhc_set_timing(priv, mmc->selected_mode);
704 if (ret)
705 return ret;
Yangbo Lu73da9c82020-09-01 16:58:01 +0800706
Andy Fleminge52ffb82008-10-30 16:47:16 -0500707 /* Set the bus width */
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100708 esdhc_clrbits32(&regs->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500709
710 if (mmc->bus_width == 4)
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100711 esdhc_setbits32(&regs->proctl, PROCTL_DTW_4);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500712 else if (mmc->bus_width == 8)
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100713 esdhc_setbits32(&regs->proctl, PROCTL_DTW_8);
714
Jaehoon Chungb6cd1d32016-12-30 15:30:16 +0900715 return 0;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500716}
717
Rasmus Villemoesa6d1f1a2020-01-30 12:06:45 +0000718static void esdhc_enable_cache_snooping(struct fsl_esdhc *regs)
719{
720#ifdef CONFIG_ARCH_MPC830X
721 immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
722 sysconf83xx_t *sysconf = &immr->sysconf;
723
724 setbits_be32(&sysconf->sdhccr, 0x02000000);
725#else
726 esdhc_write32(&regs->esdhcctl, 0x00000040);
727#endif
728}
729
Simon Glass6aa55dc2017-07-29 11:35:18 -0600730static int esdhc_init_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
Andy Fleminge52ffb82008-10-30 16:47:16 -0500731{
Peng Fana4d36f72016-03-25 14:16:56 +0800732 struct fsl_esdhc *regs = priv->esdhc_regs;
Simon Glass0c3ef222017-07-29 11:35:20 -0600733 ulong start;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500734
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100735 /* Reset the entire host controller */
Dirk Behmedbe67252013-07-15 15:44:29 +0200736 esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100737
738 /* Wait until the controller is available */
Simon Glass0c3ef222017-07-29 11:35:20 -0600739 start = get_timer(0);
740 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA)) {
741 if (get_timer(start) > 1000)
742 return -ETIMEDOUT;
743 }
Andy Fleminge52ffb82008-10-30 16:47:16 -0500744
Yangbo Lu573859c2020-09-01 16:58:02 +0800745 /* Clean TBCTL[TB_EN] which is not able to be reset by reset all */
746 esdhc_clrbits32(&regs->tbctl, TBCTL_TB_EN);
747
Rasmus Villemoesa6d1f1a2020-01-30 12:06:45 +0000748 esdhc_enable_cache_snooping(regs);
P.V.Suresh7b1868b2010-12-04 10:37:23 +0530749
Dirk Behmedbe67252013-07-15 15:44:29 +0200750 esdhc_setbits32(&regs->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500751
752 /* Set the initial clock speed */
Yangbo Luee2708b2020-10-20 11:04:51 +0800753 set_sysctl(priv, mmc, 400000);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500754
755 /* Disable the BRR and BWR bits in IRQSTAT */
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100756 esdhc_clrbits32(&regs->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500757
758 /* Put the PROCTL reg back to the default */
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100759 esdhc_write32(&regs->proctl, PROCTL_INIT);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500760
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100761 /* Set timout to the maximum value */
762 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
Andy Fleminge52ffb82008-10-30 16:47:16 -0500763
Michael Walle7259dc52021-03-17 15:01:37 +0100764 if (IS_ENABLED(CONFIG_SYS_FSL_ESDHC_UNRELIABLE_PULSE_DETECTION_WORKAROUND))
765 esdhc_clrbits32(&regs->dllcfg1, DLL_PD_PULSE_STRETCH_SEL);
766
Thierry Reding8cee4c982012-01-02 01:15:38 +0000767 return 0;
768}
769
Simon Glass6aa55dc2017-07-29 11:35:18 -0600770static int esdhc_getcd_common(struct fsl_esdhc_priv *priv)
Thierry Reding8cee4c982012-01-02 01:15:38 +0000771{
Peng Fana4d36f72016-03-25 14:16:56 +0800772 struct fsl_esdhc *regs = priv->esdhc_regs;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500773
Haijun.Zhang05f58542014-01-10 13:52:17 +0800774#ifdef CONFIG_ESDHC_DETECT_QUIRK
775 if (CONFIG_ESDHC_DETECT_QUIRK)
776 return 1;
777#endif
Yangbo Lu8abc0432020-05-19 11:06:43 +0800778 if (esdhc_read32(&regs->prsstat) & PRSSTAT_CINS)
779 return 1;
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100780
Yangbo Lu8abc0432020-05-19 11:06:43 +0800781 return 0;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500782}
783
Yangbo Lub64dc8d2019-10-31 18:54:23 +0800784static void fsl_esdhc_get_cfg_common(struct fsl_esdhc_priv *priv,
785 struct mmc_config *cfg)
Andy Fleminge52ffb82008-10-30 16:47:16 -0500786{
Yangbo Lub64dc8d2019-10-31 18:54:23 +0800787 struct fsl_esdhc *regs = priv->esdhc_regs;
Yangbo Lu63267b42019-10-31 18:54:21 +0800788 u32 caps;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500789
Wang Huanc9292132014-09-05 13:52:40 +0800790 caps = esdhc_read32(&regs->hostcapblt);
Yangbo Lue087cd62021-06-03 10:51:17 +0800791
792 /*
793 * For eSDHC, power supply is through peripheral circuit. Some eSDHC
794 * versions have value 0 of the bit but that does not reflect the
795 * truth. 3.3V is common for SD/MMC, and is supported for all boards
796 * with eSDHC in current u-boot. So, make 3.3V is supported in
797 * default in code. CONFIG_FSL_ESDHC_VS33_NOT_SUPPORT can be enabled
798 * if future board does not support 3.3V.
799 */
800 caps |= HOSTCAPBLT_VS33;
801 if (IS_ENABLED(CONFIG_FSL_ESDHC_VS33_NOT_SUPPORT))
802 caps &= ~HOSTCAPBLT_VS33;
803
Michael Wallebc9e13e2020-10-12 10:07:13 +0200804 if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_ESDHC135))
805 caps &= ~(HOSTCAPBLT_SRS | HOSTCAPBLT_VS18 | HOSTCAPBLT_VS30);
Yangbo Lu63267b42019-10-31 18:54:21 +0800806 if (caps & HOSTCAPBLT_VS18)
807 cfg->voltages |= MMC_VDD_165_195;
808 if (caps & HOSTCAPBLT_VS30)
809 cfg->voltages |= MMC_VDD_29_30 | MMC_VDD_30_31;
810 if (caps & HOSTCAPBLT_VS33)
811 cfg->voltages |= MMC_VDD_32_33 | MMC_VDD_33_34;
Li Yangd4933f22010-11-25 17:06:09 +0000812
Simon Glassfa02ca52017-07-29 11:35:21 -0600813 cfg->name = "FSL_SDHC";
Abbas Razae6bf9772013-03-25 09:13:34 +0000814
Yangbo Lu63267b42019-10-31 18:54:21 +0800815 if (caps & HOSTCAPBLT_HSS)
Simon Glassfa02ca52017-07-29 11:35:21 -0600816 cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
Andy Fleminge52ffb82008-10-30 16:47:16 -0500817
Simon Glassfa02ca52017-07-29 11:35:21 -0600818 cfg->f_min = 400000;
Peng Fanc4142702018-01-21 19:00:24 +0800819 cfg->f_max = min(priv->sdhc_clk, (u32)200000000);
Simon Glassfa02ca52017-07-29 11:35:21 -0600820 cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
Peng Fana4d36f72016-03-25 14:16:56 +0800821}
Anton Vorontsovf751a3c2009-06-10 00:25:29 +0400822
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100823#ifdef CONFIG_OF_LIBFDT
Yangbo Lud84139c2017-01-17 10:43:54 +0800824__weak int esdhc_status_fixup(void *blob, const char *compat)
Anton Vorontsovf751a3c2009-06-10 00:25:29 +0400825{
Michael Wallebc9e13e2020-10-12 10:07:13 +0200826 if (IS_ENABLED(CONFIG_FSL_ESDHC_PIN_MUX) && !hwconfig("esdhc")) {
Chenhui Zhao025eab02011-01-04 17:23:05 +0800827 do_fixup_by_compat(blob, compat, "status", "disabled",
Yangbo Lud84139c2017-01-17 10:43:54 +0800828 sizeof("disabled"), 1);
829 return 1;
Anton Vorontsovf751a3c2009-06-10 00:25:29 +0400830 }
Michael Wallebc9e13e2020-10-12 10:07:13 +0200831
Yangbo Lud84139c2017-01-17 10:43:54 +0800832 return 0;
833}
834
Yangbo Luce884022020-05-19 11:06:44 +0800835
Michael Wallebc9e13e2020-10-12 10:07:13 +0200836#if CONFIG_IS_ENABLED(DM_MMC)
837static int fsl_esdhc_get_cd(struct udevice *dev);
Yangbo Luce884022020-05-19 11:06:44 +0800838static void esdhc_disable_for_no_card(void *blob)
839{
840 struct udevice *dev;
841
842 for (uclass_first_device(UCLASS_MMC, &dev);
843 dev;
844 uclass_next_device(&dev)) {
845 char esdhc_path[50];
846
847 if (fsl_esdhc_get_cd(dev))
848 continue;
849
850 snprintf(esdhc_path, sizeof(esdhc_path), "/soc/esdhc@%lx",
851 (unsigned long)dev_read_addr(dev));
852 do_fixup_by_path(blob, esdhc_path, "status", "disabled",
853 sizeof("disabled"), 1);
854 }
855}
Michael Wallebc9e13e2020-10-12 10:07:13 +0200856#else
857static void esdhc_disable_for_no_card(void *blob)
858{
859}
Yangbo Luce884022020-05-19 11:06:44 +0800860#endif
861
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900862void fdt_fixup_esdhc(void *blob, struct bd_info *bd)
Yangbo Lud84139c2017-01-17 10:43:54 +0800863{
864 const char *compat = "fsl,esdhc";
865
866 if (esdhc_status_fixup(blob, compat))
867 return;
Michael Wallebc9e13e2020-10-12 10:07:13 +0200868
869 if (IS_ENABLED(CONFIG_FSL_ESDHC_33V_IO_RELIABILITY_WORKAROUND))
870 esdhc_disable_for_no_card(blob);
871
Anton Vorontsovf751a3c2009-06-10 00:25:29 +0400872 do_fixup_by_compat_u32(blob, compat, "clock-frequency",
Simon Glass9e247d12012-12-13 20:49:05 +0000873 gd->arch.sdhc_clk, 1);
Anton Vorontsovf751a3c2009-06-10 00:25:29 +0400874}
Stefano Babicff7a5ca2010-02-05 15:11:27 +0100875#endif
Peng Fana4d36f72016-03-25 14:16:56 +0800876
Yangbo Lu4fc93332019-10-31 18:54:26 +0800877#if !CONFIG_IS_ENABLED(DM_MMC)
878static int esdhc_getcd(struct mmc *mmc)
879{
880 struct fsl_esdhc_priv *priv = mmc->priv;
881
882 return esdhc_getcd_common(priv);
883}
884
885static int esdhc_init(struct mmc *mmc)
886{
887 struct fsl_esdhc_priv *priv = mmc->priv;
888
889 return esdhc_init_common(priv, mmc);
890}
891
892static int esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
893 struct mmc_data *data)
894{
895 struct fsl_esdhc_priv *priv = mmc->priv;
896
897 return esdhc_send_cmd_common(priv, mmc, cmd, data);
898}
899
900static int esdhc_set_ios(struct mmc *mmc)
901{
902 struct fsl_esdhc_priv *priv = mmc->priv;
903
904 return esdhc_set_ios_common(priv, mmc);
905}
906
907static const struct mmc_ops esdhc_ops = {
908 .getcd = esdhc_getcd,
909 .init = esdhc_init,
910 .send_cmd = esdhc_send_cmd,
911 .set_ios = esdhc_set_ios,
912};
913
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900914int fsl_esdhc_initialize(struct bd_info *bis, struct fsl_esdhc_cfg *cfg)
Yangbo Lu4fc93332019-10-31 18:54:26 +0800915{
916 struct fsl_esdhc_plat *plat;
917 struct fsl_esdhc_priv *priv;
918 struct mmc_config *mmc_cfg;
919 struct mmc *mmc;
920
921 if (!cfg)
922 return -EINVAL;
923
924 priv = calloc(sizeof(struct fsl_esdhc_priv), 1);
925 if (!priv)
926 return -ENOMEM;
927 plat = calloc(sizeof(struct fsl_esdhc_plat), 1);
928 if (!plat) {
929 free(priv);
930 return -ENOMEM;
931 }
932
933 priv->esdhc_regs = (struct fsl_esdhc *)(unsigned long)(cfg->esdhc_base);
934 priv->sdhc_clk = cfg->sdhc_clk;
Yangbo Lu1ca7a9f2019-12-19 18:59:30 +0800935 if (gd->arch.sdhc_per_clk)
936 priv->is_sdhc_per_clk = true;
Yangbo Lu4fc93332019-10-31 18:54:26 +0800937
938 mmc_cfg = &plat->cfg;
939
940 if (cfg->max_bus_width == 8) {
941 mmc_cfg->host_caps |= MMC_MODE_1BIT | MMC_MODE_4BIT |
942 MMC_MODE_8BIT;
943 } else if (cfg->max_bus_width == 4) {
944 mmc_cfg->host_caps |= MMC_MODE_1BIT | MMC_MODE_4BIT;
945 } else if (cfg->max_bus_width == 1) {
946 mmc_cfg->host_caps |= MMC_MODE_1BIT;
947 } else {
948 mmc_cfg->host_caps |= MMC_MODE_1BIT | MMC_MODE_4BIT |
949 MMC_MODE_8BIT;
950 printf("No max bus width provided. Assume 8-bit supported.\n");
951 }
952
Michael Wallebc9e13e2020-10-12 10:07:13 +0200953 if (IS_ENABLED(CONFIG_ESDHC_DETECT_8_BIT_QUIRK))
Yangbo Lu4fc93332019-10-31 18:54:26 +0800954 mmc_cfg->host_caps &= ~MMC_MODE_8BIT;
Michael Wallebc9e13e2020-10-12 10:07:13 +0200955
Yangbo Lu4fc93332019-10-31 18:54:26 +0800956 mmc_cfg->ops = &esdhc_ops;
957
958 fsl_esdhc_get_cfg_common(priv, mmc_cfg);
959
960 mmc = mmc_create(mmc_cfg, priv);
961 if (!mmc)
962 return -EIO;
963
964 priv->mmc = mmc;
965 return 0;
966}
967
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900968int fsl_esdhc_mmc_init(struct bd_info *bis)
Yangbo Lu4fc93332019-10-31 18:54:26 +0800969{
970 struct fsl_esdhc_cfg *cfg;
971
972 cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1);
973 cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR;
Yangbo Lu1ca7a9f2019-12-19 18:59:30 +0800974 /* Prefer peripheral clock which provides higher frequency. */
975 if (gd->arch.sdhc_per_clk)
976 cfg->sdhc_clk = gd->arch.sdhc_per_clk;
977 else
978 cfg->sdhc_clk = gd->arch.sdhc_clk;
Yangbo Lu4fc93332019-10-31 18:54:26 +0800979 return fsl_esdhc_initialize(bis, cfg);
980}
981#else /* DM_MMC */
Peng Fana4d36f72016-03-25 14:16:56 +0800982static int fsl_esdhc_probe(struct udevice *dev)
983{
984 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
Simon Glassfa20e932020-12-03 16:55:20 -0700985 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Peng Fana4d36f72016-03-25 14:16:56 +0800986 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
Michael Walle081d4012020-10-12 10:07:14 +0200987 u32 caps, hostver;
Peng Fana4d36f72016-03-25 14:16:56 +0800988 fdt_addr_t addr;
Simon Glass407025d2017-07-29 11:35:24 -0600989 struct mmc *mmc;
Yangbo Luce884022020-05-19 11:06:44 +0800990 int ret;
Peng Fana4d36f72016-03-25 14:16:56 +0800991
Simon Glass80e9df42017-07-29 11:35:23 -0600992 addr = dev_read_addr(dev);
Peng Fana4d36f72016-03-25 14:16:56 +0800993 if (addr == FDT_ADDR_T_NONE)
994 return -EINVAL;
Yinbo Zhu583d5e92019-04-11 11:01:50 +0000995#ifdef CONFIG_PPC
996 priv->esdhc_regs = (struct fsl_esdhc *)lower_32_bits(addr);
997#else
Peng Fana4d36f72016-03-25 14:16:56 +0800998 priv->esdhc_regs = (struct fsl_esdhc *)addr;
Yinbo Zhu583d5e92019-04-11 11:01:50 +0000999#endif
Peng Fana4d36f72016-03-25 14:16:56 +08001000 priv->dev = dev;
1001
Michael Walle081d4012020-10-12 10:07:14 +02001002 if (IS_ENABLED(CONFIG_FSL_ESDHC_SUPPORT_ADMA2)) {
1003 /*
1004 * Only newer eSDHC controllers can do ADMA2 if the ADMA flag
1005 * is set in the host capabilities register.
1006 */
1007 caps = esdhc_read32(&priv->esdhc_regs->hostcapblt);
1008 hostver = esdhc_read32(&priv->esdhc_regs->hostver);
1009 if (caps & HOSTCAPBLT_DMAS &&
1010 HOSTVER_VENDOR(hostver) > VENDOR_V_22) {
1011 priv->adma_desc_table = sdhci_adma_init();
1012 if (!priv->adma_desc_table)
1013 debug("Could not allocate ADMA tables, falling back to SDMA\n");
1014 }
1015 }
1016
Yangbo Lu1ca7a9f2019-12-19 18:59:30 +08001017 if (gd->arch.sdhc_per_clk) {
1018 priv->sdhc_clk = gd->arch.sdhc_per_clk;
1019 priv->is_sdhc_per_clk = true;
1020 } else {
1021 priv->sdhc_clk = gd->arch.sdhc_clk;
1022 }
1023
Yangbo Lub8626e42019-11-12 19:28:36 +08001024 if (priv->sdhc_clk <= 0) {
1025 dev_err(dev, "Unable to get clk for %s\n", dev->name);
1026 return -EINVAL;
Peng Fana4d36f72016-03-25 14:16:56 +08001027 }
1028
Yangbo Lub64dc8d2019-10-31 18:54:23 +08001029 fsl_esdhc_get_cfg_common(priv, &plat->cfg);
Peng Fana4d36f72016-03-25 14:16:56 +08001030
Yinbo Zhu101d3ef2019-07-16 15:09:11 +08001031 mmc_of_parse(dev, &plat->cfg);
1032
Simon Glass407025d2017-07-29 11:35:24 -06001033 mmc = &plat->mmc;
1034 mmc->cfg = &plat->cfg;
1035 mmc->dev = dev;
Yangbo Lu4cc119b2019-05-23 11:05:46 +08001036
Simon Glass407025d2017-07-29 11:35:24 -06001037 upriv->mmc = mmc;
Peng Fana4d36f72016-03-25 14:16:56 +08001038
Yangbo Luce884022020-05-19 11:06:44 +08001039 ret = esdhc_init_common(priv, mmc);
1040 if (ret)
1041 return ret;
1042
Michael Wallebc9e13e2020-10-12 10:07:13 +02001043 if (IS_ENABLED(CONFIG_FSL_ESDHC_33V_IO_RELIABILITY_WORKAROUND) &&
1044 !fsl_esdhc_get_cd(dev))
Yangbo Luce884022020-05-19 11:06:44 +08001045 esdhc_setbits32(&priv->esdhc_regs->proctl, PROCTL_VOLT_SEL);
Michael Wallebc9e13e2020-10-12 10:07:13 +02001046
Yangbo Luce884022020-05-19 11:06:44 +08001047 return 0;
Peng Fana4d36f72016-03-25 14:16:56 +08001048}
1049
Simon Glass407025d2017-07-29 11:35:24 -06001050static int fsl_esdhc_get_cd(struct udevice *dev)
1051{
Simon Glassfa20e932020-12-03 16:55:20 -07001052 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Simon Glass407025d2017-07-29 11:35:24 -06001053 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1054
Yangbo Lu9fed28d2019-10-31 18:54:24 +08001055 if (plat->cfg.host_caps & MMC_CAP_NONREMOVABLE)
1056 return 1;
1057
Simon Glass407025d2017-07-29 11:35:24 -06001058 return esdhc_getcd_common(priv);
1059}
1060
1061static int fsl_esdhc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
1062 struct mmc_data *data)
1063{
Simon Glassfa20e932020-12-03 16:55:20 -07001064 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Simon Glass407025d2017-07-29 11:35:24 -06001065 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1066
1067 return esdhc_send_cmd_common(priv, &plat->mmc, cmd, data);
1068}
1069
1070static int fsl_esdhc_set_ios(struct udevice *dev)
1071{
Simon Glassfa20e932020-12-03 16:55:20 -07001072 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Simon Glass407025d2017-07-29 11:35:24 -06001073 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1074
1075 return esdhc_set_ios_common(priv, &plat->mmc);
1076}
1077
Yangbo Lu76c74692020-09-01 16:58:00 +08001078static int fsl_esdhc_reinit(struct udevice *dev)
1079{
Simon Glassfa20e932020-12-03 16:55:20 -07001080 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Yangbo Lu76c74692020-09-01 16:58:00 +08001081 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1082
1083 return esdhc_init_common(priv, &plat->mmc);
1084}
1085
Yangbo Lu73da9c82020-09-01 16:58:01 +08001086#ifdef MMC_SUPPORTS_TUNING
Yangbo Lu73da9c82020-09-01 16:58:01 +08001087static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode)
1088{
Simon Glassfa20e932020-12-03 16:55:20 -07001089 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Yangbo Lu73da9c82020-09-01 16:58:01 +08001090 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1091 struct fsl_esdhc *regs = priv->esdhc_regs;
Michael Walle148dc612021-03-17 15:01:36 +01001092 struct mmc *mmc = &plat->mmc;
Yangbo Lu73da9c82020-09-01 16:58:01 +08001093 u32 val, irqstaten;
1094 int i;
1095
Michael Walle148dc612021-03-17 15:01:36 +01001096 if (IS_ENABLED(CONFIG_SYS_FSL_ERRATUM_A011334) &&
1097 plat->mmc.hs400_tuning)
1098 set_sysctl(priv, mmc, mmc->clock);
1099
Yangbo Lu73da9c82020-09-01 16:58:01 +08001100 esdhc_tuning_block_enable(priv, true);
1101 esdhc_setbits32(&regs->autoc12err, EXECUTE_TUNING);
1102
1103 irqstaten = esdhc_read32(&regs->irqstaten);
1104 esdhc_write32(&regs->irqstaten, IRQSTATEN_BRR);
1105
1106 for (i = 0; i < MAX_TUNING_LOOP; i++) {
Michael Walle148dc612021-03-17 15:01:36 +01001107 mmc_send_tuning(mmc, opcode, NULL);
Yangbo Lu73da9c82020-09-01 16:58:01 +08001108 mdelay(1);
1109
1110 val = esdhc_read32(&regs->autoc12err);
1111 if (!(val & EXECUTE_TUNING)) {
1112 if (val & SMPCLKSEL)
1113 break;
1114 }
1115 }
1116
1117 esdhc_write32(&regs->irqstaten, irqstaten);
1118
Yangbo Lu8f9ace12020-09-01 16:58:05 +08001119 if (i != MAX_TUNING_LOOP) {
1120 if (plat->mmc.hs400_tuning)
1121 esdhc_setbits32(&regs->sdtimingctl, FLW_CTL_BG);
Yangbo Lu73da9c82020-09-01 16:58:01 +08001122 return 0;
Yangbo Lu8f9ace12020-09-01 16:58:05 +08001123 }
Yangbo Lu73da9c82020-09-01 16:58:01 +08001124
1125 printf("fsl_esdhc: tuning failed!\n");
1126 esdhc_clrbits32(&regs->autoc12err, SMPCLKSEL);
1127 esdhc_clrbits32(&regs->autoc12err, EXECUTE_TUNING);
1128 esdhc_tuning_block_enable(priv, false);
1129 return -ETIMEDOUT;
1130}
1131#endif
1132
Yangbo Lu8f9ace12020-09-01 16:58:05 +08001133int fsl_esdhc_hs400_prepare_ddr(struct udevice *dev)
1134{
1135 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1136
1137 esdhc_tuning_block_enable(priv, false);
1138 return 0;
1139}
1140
Simon Glass407025d2017-07-29 11:35:24 -06001141static const struct dm_mmc_ops fsl_esdhc_ops = {
1142 .get_cd = fsl_esdhc_get_cd,
1143 .send_cmd = fsl_esdhc_send_cmd,
1144 .set_ios = fsl_esdhc_set_ios,
Yinbo Zhu101d3ef2019-07-16 15:09:11 +08001145#ifdef MMC_SUPPORTS_TUNING
1146 .execute_tuning = fsl_esdhc_execute_tuning,
1147#endif
Yangbo Lu76c74692020-09-01 16:58:00 +08001148 .reinit = fsl_esdhc_reinit,
Yangbo Lu8f9ace12020-09-01 16:58:05 +08001149 .hs400_prepare_ddr = fsl_esdhc_hs400_prepare_ddr,
Simon Glass407025d2017-07-29 11:35:24 -06001150};
Simon Glass407025d2017-07-29 11:35:24 -06001151
Peng Fana4d36f72016-03-25 14:16:56 +08001152static const struct udevice_id fsl_esdhc_ids[] = {
Yangbo Lu2a99b602016-12-07 11:54:31 +08001153 { .compatible = "fsl,esdhc", },
Peng Fana4d36f72016-03-25 14:16:56 +08001154 { /* sentinel */ }
1155};
1156
Simon Glass407025d2017-07-29 11:35:24 -06001157static int fsl_esdhc_bind(struct udevice *dev)
1158{
Simon Glassfa20e932020-12-03 16:55:20 -07001159 struct fsl_esdhc_plat *plat = dev_get_plat(dev);
Simon Glass407025d2017-07-29 11:35:24 -06001160
1161 return mmc_bind(dev, &plat->mmc, &plat->cfg);
1162}
Simon Glass407025d2017-07-29 11:35:24 -06001163
Peng Fana4d36f72016-03-25 14:16:56 +08001164U_BOOT_DRIVER(fsl_esdhc) = {
1165 .name = "fsl-esdhc-mmc",
1166 .id = UCLASS_MMC,
1167 .of_match = fsl_esdhc_ids,
Simon Glass407025d2017-07-29 11:35:24 -06001168 .ops = &fsl_esdhc_ops,
Simon Glass407025d2017-07-29 11:35:24 -06001169 .bind = fsl_esdhc_bind,
Peng Fana4d36f72016-03-25 14:16:56 +08001170 .probe = fsl_esdhc_probe,
Simon Glass71fa5b42020-12-03 16:55:18 -07001171 .plat_auto = sizeof(struct fsl_esdhc_plat),
Simon Glass8a2b47f2020-12-03 16:55:17 -07001172 .priv_auto = sizeof(struct fsl_esdhc_priv),
Peng Fana4d36f72016-03-25 14:16:56 +08001173};
1174#endif