blob: 3cdfa7f5a689789ea2f24da867d7c947ab78c002 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andy Fleming50586ef2008-10-30 16:47:16 -05002/*
Jerry Huangd621da02011-01-06 23:42:19 -06003 * Copyright 2007, 2010-2011 Freescale Semiconductor, Inc
Andy Fleming50586ef2008-10-30 16:47:16 -05004 * Andy Fleming
5 *
6 * Based vaguely on the pxa mmc code:
7 * (C) Copyright 2003
8 * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net
Andy Fleming50586ef2008-10-30 16:47:16 -05009 */
10
11#include <config.h>
12#include <common.h>
13#include <command.h>
Peng Fan3cb14502018-10-18 14:28:35 +020014#include <clk.h>
Jaehoon Chung915ffa52016-07-19 16:33:36 +090015#include <errno.h>
Anton Vorontsovb33433a2009-06-10 00:25:29 +040016#include <hwconfig.h>
Andy Fleming50586ef2008-10-30 16:47:16 -050017#include <mmc.h>
18#include <part.h>
Peng Fan4483b7e2017-06-12 17:50:54 +080019#include <power/regulator.h>
Andy Fleming50586ef2008-10-30 16:47:16 -050020#include <malloc.h>
Andy Fleming50586ef2008-10-30 16:47:16 -050021#include <fsl_esdhc.h>
Anton Vorontsovb33433a2009-06-10 00:25:29 +040022#include <fdt_support.h>
Andy Fleming50586ef2008-10-30 16:47:16 -050023#include <asm/io.h>
Peng Fan96f04072016-03-25 14:16:56 +080024#include <dm.h>
25#include <asm-generic/gpio.h>
Peng Fan51313b42018-01-21 19:00:24 +080026#include <dm/pinctrl.h>
Andy Fleming50586ef2008-10-30 16:47:16 -050027
Andy Fleming50586ef2008-10-30 16:47:16 -050028DECLARE_GLOBAL_DATA_PTR;
29
Ye.Lia3d6e382014-11-04 15:35:49 +080030#define SDHCI_IRQ_EN_BITS (IRQSTATEN_CC | IRQSTATEN_TC | \
31 IRQSTATEN_CINT | \
32 IRQSTATEN_CTOE | IRQSTATEN_CCE | IRQSTATEN_CEBE | \
33 IRQSTATEN_CIE | IRQSTATEN_DTOE | IRQSTATEN_DCE | \
34 IRQSTATEN_DEBE | IRQSTATEN_BRR | IRQSTATEN_BWR | \
35 IRQSTATEN_DINT)
Peng Fan51313b42018-01-21 19:00:24 +080036#define MAX_TUNING_LOOP 40
Ye.Lia3d6e382014-11-04 15:35:49 +080037
Andy Fleming50586ef2008-10-30 16:47:16 -050038struct fsl_esdhc {
Haijun.Zhang511948b2013-10-30 11:37:55 +080039 uint dsaddr; /* SDMA system address register */
40 uint blkattr; /* Block attributes register */
41 uint cmdarg; /* Command argument register */
42 uint xfertyp; /* Transfer type register */
43 uint cmdrsp0; /* Command response 0 register */
44 uint cmdrsp1; /* Command response 1 register */
45 uint cmdrsp2; /* Command response 2 register */
46 uint cmdrsp3; /* Command response 3 register */
47 uint datport; /* Buffer data port register */
48 uint prsstat; /* Present state register */
49 uint proctl; /* Protocol control register */
50 uint sysctl; /* System Control Register */
51 uint irqstat; /* Interrupt status register */
52 uint irqstaten; /* Interrupt status enable register */
53 uint irqsigen; /* Interrupt signal enable register */
54 uint autoc12err; /* Auto CMD error status register */
55 uint hostcapblt; /* Host controller capabilities register */
56 uint wml; /* Watermark level register */
57 uint mixctrl; /* For USDHC */
58 char reserved1[4]; /* reserved */
59 uint fevt; /* Force event register */
60 uint admaes; /* ADMA error status register */
61 uint adsaddr; /* ADMA system address register */
Peng Fanf53225c2016-06-15 10:53:00 +080062 char reserved2[4];
63 uint dllctrl;
64 uint dllstat;
65 uint clktunectrlstatus;
Peng Fan59d37822018-01-21 19:00:22 +080066 char reserved3[4];
67 uint strobe_dllctrl;
68 uint strobe_dllstat;
69 char reserved4[72];
Peng Fanf53225c2016-06-15 10:53:00 +080070 uint vendorspec;
71 uint mmcboot;
72 uint vendorspec2;
Peng Fan59d37822018-01-21 19:00:22 +080073 uint tuning_ctrl; /* on i.MX6/7/8 */
74 char reserved5[44];
Haijun.Zhang511948b2013-10-30 11:37:55 +080075 uint hostver; /* Host controller version register */
Otavio Salvadorf022d362015-02-17 10:42:43 -020076 char reserved6[4]; /* reserved */
Peng Fan59d37822018-01-21 19:00:22 +080077 uint dmaerraddr; /* DMA error address register */
Peng Fanf53225c2016-06-15 10:53:00 +080078 char reserved7[4]; /* reserved */
Peng Fan59d37822018-01-21 19:00:22 +080079 uint dmaerrattr; /* DMA error attribute register */
80 char reserved8[4]; /* reserved */
Haijun.Zhang511948b2013-10-30 11:37:55 +080081 uint hostcapblt2; /* Host controller capabilities register 2 */
Peng Fan59d37822018-01-21 19:00:22 +080082 char reserved9[8]; /* reserved */
Haijun.Zhang511948b2013-10-30 11:37:55 +080083 uint tcr; /* Tuning control register */
Peng Fan59d37822018-01-21 19:00:22 +080084 char reserved10[28]; /* reserved */
Haijun.Zhang511948b2013-10-30 11:37:55 +080085 uint sddirctl; /* SD direction control register */
Peng Fan59d37822018-01-21 19:00:22 +080086 char reserved11[712];/* reserved */
Haijun.Zhang511948b2013-10-30 11:37:55 +080087 uint scr; /* eSDHC control register */
Andy Fleming50586ef2008-10-30 16:47:16 -050088};
89
Simon Glasse88e1d92017-07-29 11:35:21 -060090struct fsl_esdhc_plat {
91 struct mmc_config cfg;
92 struct mmc mmc;
93};
94
Peng Fan51313b42018-01-21 19:00:24 +080095struct esdhc_soc_data {
96 u32 flags;
97 u32 caps;
98};
99
Peng Fan96f04072016-03-25 14:16:56 +0800100/**
101 * struct fsl_esdhc_priv
102 *
103 * @esdhc_regs: registers of the sdhc controller
104 * @sdhc_clk: Current clk of the sdhc controller
105 * @bus_width: bus width, 1bit, 4bit or 8bit
106 * @cfg: mmc config
107 * @mmc: mmc
108 * Following is used when Driver Model is enabled for MMC
109 * @dev: pointer for the device
110 * @non_removable: 0: removable; 1: non-removable
Peng Fan14831512016-06-15 10:53:02 +0800111 * @wp_enable: 1: enable checking wp; 0: no check
Peng Fan32a91792017-06-12 17:50:53 +0800112 * @vs18_enable: 1: use 1.8V voltage; 0: use 3.3V
Peng Fan51313b42018-01-21 19:00:24 +0800113 * @flags: ESDHC_FLAG_xx in include/fsl_esdhc.h
114 * @caps: controller capabilities
115 * @tuning_step: tuning step setting in tuning_ctrl register
116 * @start_tuning_tap: the start point for tuning in tuning_ctrl register
117 * @strobe_dll_delay_target: settings in strobe_dllctrl
118 * @signal_voltage: indicating the current voltage
Peng Fan96f04072016-03-25 14:16:56 +0800119 * @cd_gpio: gpio for card detection
Peng Fan14831512016-06-15 10:53:02 +0800120 * @wp_gpio: gpio for write protection
Peng Fan96f04072016-03-25 14:16:56 +0800121 */
122struct fsl_esdhc_priv {
123 struct fsl_esdhc *esdhc_regs;
124 unsigned int sdhc_clk;
Peng Fan3cb14502018-10-18 14:28:35 +0200125 struct clk per_clk;
Peng Fan51313b42018-01-21 19:00:24 +0800126 unsigned int clock;
127 unsigned int mode;
Peng Fan96f04072016-03-25 14:16:56 +0800128 unsigned int bus_width;
Simon Glass653282b2017-07-29 11:35:24 -0600129#if !CONFIG_IS_ENABLED(BLK)
Peng Fan96f04072016-03-25 14:16:56 +0800130 struct mmc *mmc;
Simon Glass653282b2017-07-29 11:35:24 -0600131#endif
Peng Fan96f04072016-03-25 14:16:56 +0800132 struct udevice *dev;
133 int non_removable;
Peng Fan14831512016-06-15 10:53:02 +0800134 int wp_enable;
Peng Fan32a91792017-06-12 17:50:53 +0800135 int vs18_enable;
Peng Fan51313b42018-01-21 19:00:24 +0800136 u32 flags;
137 u32 caps;
138 u32 tuning_step;
139 u32 tuning_start_tap;
140 u32 strobe_dll_delay_target;
141 u32 signal_voltage;
142#if IS_ENABLED(CONFIG_DM_REGULATOR)
143 struct udevice *vqmmc_dev;
144 struct udevice *vmmc_dev;
145#endif
Yangbo Lufc8048a2016-12-07 11:54:30 +0800146#ifdef CONFIG_DM_GPIO
Peng Fan96f04072016-03-25 14:16:56 +0800147 struct gpio_desc cd_gpio;
Peng Fan14831512016-06-15 10:53:02 +0800148 struct gpio_desc wp_gpio;
Yangbo Lufc8048a2016-12-07 11:54:30 +0800149#endif
Peng Fan96f04072016-03-25 14:16:56 +0800150};
151
Andy Fleming50586ef2008-10-30 16:47:16 -0500152/* Return the XFERTYP flags for a given command and data packet */
Kim Phillipseafa90a2012-10-29 13:34:44 +0000153static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data)
Andy Fleming50586ef2008-10-30 16:47:16 -0500154{
155 uint xfertyp = 0;
156
157 if (data) {
Dipen Dudhat77c14582009-10-05 15:41:58 +0530158 xfertyp |= XFERTYP_DPSEL;
159#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
160 xfertyp |= XFERTYP_DMAEN;
161#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500162 if (data->blocks > 1) {
163 xfertyp |= XFERTYP_MSBSEL;
164 xfertyp |= XFERTYP_BCEN;
Jerry Huangd621da02011-01-06 23:42:19 -0600165#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
166 xfertyp |= XFERTYP_AC12EN;
167#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500168 }
169
170 if (data->flags & MMC_DATA_READ)
171 xfertyp |= XFERTYP_DTDSEL;
172 }
173
174 if (cmd->resp_type & MMC_RSP_CRC)
175 xfertyp |= XFERTYP_CCCEN;
176 if (cmd->resp_type & MMC_RSP_OPCODE)
177 xfertyp |= XFERTYP_CICEN;
178 if (cmd->resp_type & MMC_RSP_136)
179 xfertyp |= XFERTYP_RSPTYP_136;
180 else if (cmd->resp_type & MMC_RSP_BUSY)
181 xfertyp |= XFERTYP_RSPTYP_48_BUSY;
182 else if (cmd->resp_type & MMC_RSP_PRESENT)
183 xfertyp |= XFERTYP_RSPTYP_48;
184
Jason Liu4571de32011-03-22 01:32:31 +0000185 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
186 xfertyp |= XFERTYP_CMDTYP_ABORT;
Yangbo Lu25503442016-01-21 17:33:19 +0800187
Andy Fleming50586ef2008-10-30 16:47:16 -0500188 return XFERTYP_CMD(cmd->cmdidx) | xfertyp;
189}
190
Dipen Dudhat77c14582009-10-05 15:41:58 +0530191#ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
192/*
193 * PIO Read/Write Mode reduce the performace as DMA is not used in this mode.
194 */
Simon Glass09b465f2017-07-29 11:35:17 -0600195static void esdhc_pio_read_write(struct fsl_esdhc_priv *priv,
196 struct mmc_data *data)
Dipen Dudhat77c14582009-10-05 15:41:58 +0530197{
Peng Fan96f04072016-03-25 14:16:56 +0800198 struct fsl_esdhc *regs = priv->esdhc_regs;
Dipen Dudhat77c14582009-10-05 15:41:58 +0530199 uint blocks;
200 char *buffer;
201 uint databuf;
202 uint size;
203 uint irqstat;
Benoît Thébaudeaubcfb3652017-10-29 22:08:58 +0100204 ulong start;
Dipen Dudhat77c14582009-10-05 15:41:58 +0530205
206 if (data->flags & MMC_DATA_READ) {
207 blocks = data->blocks;
208 buffer = data->dest;
209 while (blocks) {
Benoît Thébaudeaubcfb3652017-10-29 22:08:58 +0100210 start = get_timer(0);
Dipen Dudhat77c14582009-10-05 15:41:58 +0530211 size = data->blocksize;
212 irqstat = esdhc_read32(&regs->irqstat);
Benoît Thébaudeaubcfb3652017-10-29 22:08:58 +0100213 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BREN)) {
214 if (get_timer(start) > PIO_TIMEOUT) {
215 printf("\nData Read Failed in PIO Mode.");
216 return;
217 }
Dipen Dudhat77c14582009-10-05 15:41:58 +0530218 }
219 while (size && (!(irqstat & IRQSTAT_TC))) {
220 udelay(100); /* Wait before last byte transfer complete */
221 irqstat = esdhc_read32(&regs->irqstat);
222 databuf = in_le32(&regs->datport);
223 *((uint *)buffer) = databuf;
224 buffer += 4;
225 size -= 4;
226 }
227 blocks--;
228 }
229 } else {
230 blocks = data->blocks;
Wolfgang Denk7b43db92010-05-09 23:52:59 +0200231 buffer = (char *)data->src;
Dipen Dudhat77c14582009-10-05 15:41:58 +0530232 while (blocks) {
Benoît Thébaudeaubcfb3652017-10-29 22:08:58 +0100233 start = get_timer(0);
Dipen Dudhat77c14582009-10-05 15:41:58 +0530234 size = data->blocksize;
235 irqstat = esdhc_read32(&regs->irqstat);
Benoît Thébaudeaubcfb3652017-10-29 22:08:58 +0100236 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BWEN)) {
237 if (get_timer(start) > PIO_TIMEOUT) {
238 printf("\nData Write Failed in PIO Mode.");
239 return;
240 }
Dipen Dudhat77c14582009-10-05 15:41:58 +0530241 }
242 while (size && (!(irqstat & IRQSTAT_TC))) {
243 udelay(100); /* Wait before last byte transfer complete */
244 databuf = *((uint *)buffer);
245 buffer += 4;
246 size -= 4;
247 irqstat = esdhc_read32(&regs->irqstat);
248 out_le32(&regs->datport, databuf);
249 }
250 blocks--;
251 }
252 }
253}
254#endif
255
Simon Glass09b465f2017-07-29 11:35:17 -0600256static int esdhc_setup_data(struct fsl_esdhc_priv *priv, struct mmc *mmc,
257 struct mmc_data *data)
Andy Fleming50586ef2008-10-30 16:47:16 -0500258{
Andy Fleming50586ef2008-10-30 16:47:16 -0500259 int timeout;
Peng Fan96f04072016-03-25 14:16:56 +0800260 struct fsl_esdhc *regs = priv->esdhc_regs;
Peng Faneec2d432018-01-10 13:20:40 +0800261#if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234) || \
Ye Lid423c932018-10-18 14:28:34 +0200262 defined(CONFIG_IMX8) || defined(CONFIG_MX8M)
Yangbo Lu8b064602015-03-20 19:28:31 -0700263 dma_addr_t addr;
264#endif
Wolfgang Denk7b43db92010-05-09 23:52:59 +0200265 uint wml_value;
Andy Fleming50586ef2008-10-30 16:47:16 -0500266
267 wml_value = data->blocksize/4;
268
269 if (data->flags & MMC_DATA_READ) {
Priyanka Jain32c8cfb2011-02-09 09:24:10 +0530270 if (wml_value > WML_RD_WML_MAX)
271 wml_value = WML_RD_WML_MAX_VAL;
Andy Fleming50586ef2008-10-30 16:47:16 -0500272
Roy Zangab467c52010-02-09 18:23:33 +0800273 esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
Ye.Li71689772014-02-20 18:00:57 +0800274#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
Peng Faneec2d432018-01-10 13:20:40 +0800275#if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234) || \
Ye Lid423c932018-10-18 14:28:34 +0200276 defined(CONFIG_IMX8) || defined(CONFIG_MX8M)
Yangbo Lu8b064602015-03-20 19:28:31 -0700277 addr = virt_to_phys((void *)(data->dest));
278 if (upper_32_bits(addr))
279 printf("Error found for upper 32 bits\n");
280 else
281 esdhc_write32(&regs->dsaddr, lower_32_bits(addr));
282#else
Stefano Babicc67bee12010-02-05 15:11:27 +0100283 esdhc_write32(&regs->dsaddr, (u32)data->dest);
Ye.Li71689772014-02-20 18:00:57 +0800284#endif
Yangbo Lu8b064602015-03-20 19:28:31 -0700285#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500286 } else {
Ye.Li71689772014-02-20 18:00:57 +0800287#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
Eric Nelsone576bd92012-04-25 14:28:48 +0000288 flush_dcache_range((ulong)data->src,
289 (ulong)data->src+data->blocks
290 *data->blocksize);
Ye.Li71689772014-02-20 18:00:57 +0800291#endif
Priyanka Jain32c8cfb2011-02-09 09:24:10 +0530292 if (wml_value > WML_WR_WML_MAX)
293 wml_value = WML_WR_WML_MAX_VAL;
Peng Fan14831512016-06-15 10:53:02 +0800294 if (priv->wp_enable) {
295 if ((esdhc_read32(&regs->prsstat) &
296 PRSSTAT_WPSPL) == 0) {
297 printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900298 return -ETIMEDOUT;
Peng Fan14831512016-06-15 10:53:02 +0800299 }
Andy Fleming50586ef2008-10-30 16:47:16 -0500300 }
Roy Zangab467c52010-02-09 18:23:33 +0800301
302 esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK,
303 wml_value << 16);
Ye.Li71689772014-02-20 18:00:57 +0800304#ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
Peng Faneec2d432018-01-10 13:20:40 +0800305#if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234) || \
Ye Lid423c932018-10-18 14:28:34 +0200306 defined(CONFIG_IMX8) || defined(CONFIG_MX8M)
Yangbo Lu8b064602015-03-20 19:28:31 -0700307 addr = virt_to_phys((void *)(data->src));
308 if (upper_32_bits(addr))
309 printf("Error found for upper 32 bits\n");
310 else
311 esdhc_write32(&regs->dsaddr, lower_32_bits(addr));
312#else
Stefano Babicc67bee12010-02-05 15:11:27 +0100313 esdhc_write32(&regs->dsaddr, (u32)data->src);
Ye.Li71689772014-02-20 18:00:57 +0800314#endif
Yangbo Lu8b064602015-03-20 19:28:31 -0700315#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500316 }
317
Stefano Babicc67bee12010-02-05 15:11:27 +0100318 esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
Andy Fleming50586ef2008-10-30 16:47:16 -0500319
320 /* Calculate the timeout period for data transactions */
Priyanka Jainb71ea332011-03-03 09:18:56 +0530321 /*
322 * 1)Timeout period = (2^(timeout+13)) SD Clock cycles
323 * 2)Timeout period should be minimum 0.250sec as per SD Card spec
324 * So, Number of SD Clock cycles for 0.25sec should be minimum
325 * (SD Clock/sec * 0.25 sec) SD Clock cycles
Andrew Gabbasovfb823982014-03-24 02:40:41 -0500326 * = (mmc->clock * 1/4) SD Clock cycles
Priyanka Jainb71ea332011-03-03 09:18:56 +0530327 * As 1) >= 2)
Andrew Gabbasovfb823982014-03-24 02:40:41 -0500328 * => (2^(timeout+13)) >= mmc->clock * 1/4
Priyanka Jainb71ea332011-03-03 09:18:56 +0530329 * Taking log2 both the sides
Andrew Gabbasovfb823982014-03-24 02:40:41 -0500330 * => timeout + 13 >= log2(mmc->clock/4)
Priyanka Jainb71ea332011-03-03 09:18:56 +0530331 * Rounding up to next power of 2
Andrew Gabbasovfb823982014-03-24 02:40:41 -0500332 * => timeout + 13 = log2(mmc->clock/4) + 1
333 * => timeout + 13 = fls(mmc->clock/4)
Yangbo Lue978a312015-12-30 14:19:30 +0800334 *
335 * However, the MMC spec "It is strongly recommended for hosts to
336 * implement more than 500ms timeout value even if the card
337 * indicates the 250ms maximum busy length." Even the previous
338 * value of 300ms is known to be insufficient for some cards.
339 * So, we use
340 * => timeout + 13 = fls(mmc->clock/2)
Priyanka Jainb71ea332011-03-03 09:18:56 +0530341 */
Yangbo Lue978a312015-12-30 14:19:30 +0800342 timeout = fls(mmc->clock/2);
Andy Fleming50586ef2008-10-30 16:47:16 -0500343 timeout -= 13;
344
345 if (timeout > 14)
346 timeout = 14;
347
348 if (timeout < 0)
349 timeout = 0;
350
Kumar Gala5103a032011-01-29 15:36:10 -0600351#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC_A001
352 if ((timeout == 4) || (timeout == 8) || (timeout == 12))
353 timeout++;
354#endif
355
Haijun.Zhang1336e2d2014-03-18 17:04:23 +0800356#ifdef ESDHCI_QUIRK_BROKEN_TIMEOUT_VALUE
357 timeout = 0xE;
358#endif
Stefano Babicc67bee12010-02-05 15:11:27 +0100359 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16);
Andy Fleming50586ef2008-10-30 16:47:16 -0500360
361 return 0;
362}
363
Eric Nelsone576bd92012-04-25 14:28:48 +0000364static void check_and_invalidate_dcache_range
365 (struct mmc_cmd *cmd,
366 struct mmc_data *data) {
Yangbo Lu8b064602015-03-20 19:28:31 -0700367 unsigned start = 0;
Yangbo Lucc634e22016-05-12 19:12:58 +0800368 unsigned end = 0;
Eric Nelsone576bd92012-04-25 14:28:48 +0000369 unsigned size = roundup(ARCH_DMA_MINALIGN,
370 data->blocks*data->blocksize);
Peng Faneec2d432018-01-10 13:20:40 +0800371#if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234) || \
Ye Lid423c932018-10-18 14:28:34 +0200372 defined(CONFIG_IMX8) || defined(CONFIG_MX8M)
Yangbo Lu8b064602015-03-20 19:28:31 -0700373 dma_addr_t addr;
374
375 addr = virt_to_phys((void *)(data->dest));
376 if (upper_32_bits(addr))
377 printf("Error found for upper 32 bits\n");
378 else
379 start = lower_32_bits(addr);
Yangbo Lucc634e22016-05-12 19:12:58 +0800380#else
381 start = (unsigned)data->dest;
Yangbo Lu8b064602015-03-20 19:28:31 -0700382#endif
Yangbo Lucc634e22016-05-12 19:12:58 +0800383 end = start + size;
Eric Nelsone576bd92012-04-25 14:28:48 +0000384 invalidate_dcache_range(start, end);
385}
Tom Rini10dc7772014-05-23 09:19:05 -0400386
Andy Fleming50586ef2008-10-30 16:47:16 -0500387/*
388 * Sends a command out on the bus. Takes the mmc pointer,
389 * a command pointer, and an optional data pointer.
390 */
Simon Glass9586aa62017-07-29 11:35:18 -0600391static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
392 struct mmc_cmd *cmd, struct mmc_data *data)
Andy Fleming50586ef2008-10-30 16:47:16 -0500393{
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500394 int err = 0;
Andy Fleming50586ef2008-10-30 16:47:16 -0500395 uint xfertyp;
396 uint irqstat;
Peng Fan51313b42018-01-21 19:00:24 +0800397 u32 flags = IRQSTAT_CC | IRQSTAT_CTOE;
Peng Fan96f04072016-03-25 14:16:56 +0800398 struct fsl_esdhc *regs = priv->esdhc_regs;
Andy Fleming50586ef2008-10-30 16:47:16 -0500399
Jerry Huangd621da02011-01-06 23:42:19 -0600400#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
401 if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
402 return 0;
403#endif
404
Stefano Babicc67bee12010-02-05 15:11:27 +0100405 esdhc_write32(&regs->irqstat, -1);
Andy Fleming50586ef2008-10-30 16:47:16 -0500406
407 sync();
408
409 /* Wait for the bus to be idle */
Stefano Babicc67bee12010-02-05 15:11:27 +0100410 while ((esdhc_read32(&regs->prsstat) & PRSSTAT_CICHB) ||
411 (esdhc_read32(&regs->prsstat) & PRSSTAT_CIDHB))
412 ;
Andy Fleming50586ef2008-10-30 16:47:16 -0500413
Stefano Babicc67bee12010-02-05 15:11:27 +0100414 while (esdhc_read32(&regs->prsstat) & PRSSTAT_DLA)
415 ;
Andy Fleming50586ef2008-10-30 16:47:16 -0500416
417 /* Wait at least 8 SD clock cycles before the next command */
418 /*
419 * Note: This is way more than 8 cycles, but 1ms seems to
420 * resolve timing issues with some cards
421 */
422 udelay(1000);
423
424 /* Set up for a data transfer if we have one */
425 if (data) {
Simon Glass09b465f2017-07-29 11:35:17 -0600426 err = esdhc_setup_data(priv, mmc, data);
Andy Fleming50586ef2008-10-30 16:47:16 -0500427 if(err)
428 return err;
Peng Fan4683b222015-06-25 10:32:26 +0800429
430 if (data->flags & MMC_DATA_READ)
431 check_and_invalidate_dcache_range(cmd, data);
Andy Fleming50586ef2008-10-30 16:47:16 -0500432 }
433
434 /* Figure out the transfer arguments */
435 xfertyp = esdhc_xfertyp(cmd, data);
436
Andrew Gabbasov01b77352013-06-11 10:34:22 -0500437 /* Mask all irqs */
438 esdhc_write32(&regs->irqsigen, 0);
439
Andy Fleming50586ef2008-10-30 16:47:16 -0500440 /* Send the command */
Stefano Babicc67bee12010-02-05 15:11:27 +0100441 esdhc_write32(&regs->cmdarg, cmd->cmdarg);
Jason Liu46927082011-11-25 00:18:04 +0000442#if defined(CONFIG_FSL_USDHC)
443 esdhc_write32(&regs->mixctrl,
Volodymyr Riazantsev0e1bf612015-01-20 10:16:44 -0500444 (esdhc_read32(&regs->mixctrl) & 0xFFFFFF80) | (xfertyp & 0x7F)
445 | (mmc->ddr_mode ? XFERTYP_DDREN : 0));
Jason Liu46927082011-11-25 00:18:04 +0000446 esdhc_write32(&regs->xfertyp, xfertyp & 0xFFFF0000);
447#else
Stefano Babicc67bee12010-02-05 15:11:27 +0100448 esdhc_write32(&regs->xfertyp, xfertyp);
Jason Liu46927082011-11-25 00:18:04 +0000449#endif
Dirk Behme7a5b8022012-03-26 03:13:05 +0000450
Peng Fan51313b42018-01-21 19:00:24 +0800451 if ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK) ||
452 (cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200))
453 flags = IRQSTAT_BRR;
454
Andy Fleming50586ef2008-10-30 16:47:16 -0500455 /* Wait for the command to complete */
Peng Fan51313b42018-01-21 19:00:24 +0800456 while (!(esdhc_read32(&regs->irqstat) & flags))
Stefano Babicc67bee12010-02-05 15:11:27 +0100457 ;
Andy Fleming50586ef2008-10-30 16:47:16 -0500458
Stefano Babicc67bee12010-02-05 15:11:27 +0100459 irqstat = esdhc_read32(&regs->irqstat);
Andy Fleming50586ef2008-10-30 16:47:16 -0500460
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500461 if (irqstat & CMD_ERR) {
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900462 err = -ECOMM;
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500463 goto out;
Dirk Behme7a5b8022012-03-26 03:13:05 +0000464 }
465
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500466 if (irqstat & IRQSTAT_CTOE) {
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900467 err = -ETIMEDOUT;
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500468 goto out;
469 }
Andy Fleming50586ef2008-10-30 16:47:16 -0500470
Otavio Salvadorf022d362015-02-17 10:42:43 -0200471 /* Switch voltage to 1.8V if CMD11 succeeded */
472 if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V) {
473 esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
474
475 printf("Run CMD11 1.8V switch\n");
476 /* Sleep for 5 ms - max time for card to switch to 1.8V */
477 udelay(5000);
478 }
479
Dirk Behme7a5b8022012-03-26 03:13:05 +0000480 /* Workaround for ESDHC errata ENGcm03648 */
481 if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
Yangbo Lu253d5bd2015-04-15 10:13:12 +0800482 int timeout = 6000;
Dirk Behme7a5b8022012-03-26 03:13:05 +0000483
Yangbo Lu253d5bd2015-04-15 10:13:12 +0800484 /* Poll on DATA0 line for cmd with busy signal for 600 ms */
Dirk Behme7a5b8022012-03-26 03:13:05 +0000485 while (timeout > 0 && !(esdhc_read32(&regs->prsstat) &
486 PRSSTAT_DAT0)) {
487 udelay(100);
488 timeout--;
489 }
490
491 if (timeout <= 0) {
492 printf("Timeout waiting for DAT0 to go high!\n");
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900493 err = -ETIMEDOUT;
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500494 goto out;
Dirk Behme7a5b8022012-03-26 03:13:05 +0000495 }
496 }
497
Andy Fleming50586ef2008-10-30 16:47:16 -0500498 /* Copy the response to the response buffer */
499 if (cmd->resp_type & MMC_RSP_136) {
500 u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0;
501
Stefano Babicc67bee12010-02-05 15:11:27 +0100502 cmdrsp3 = esdhc_read32(&regs->cmdrsp3);
503 cmdrsp2 = esdhc_read32(&regs->cmdrsp2);
504 cmdrsp1 = esdhc_read32(&regs->cmdrsp1);
505 cmdrsp0 = esdhc_read32(&regs->cmdrsp0);
Rabin Vincent998be3d2009-04-05 13:30:56 +0530506 cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
507 cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
508 cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
509 cmd->response[3] = (cmdrsp0 << 8);
Andy Fleming50586ef2008-10-30 16:47:16 -0500510 } else
Stefano Babicc67bee12010-02-05 15:11:27 +0100511 cmd->response[0] = esdhc_read32(&regs->cmdrsp0);
Andy Fleming50586ef2008-10-30 16:47:16 -0500512
513 /* Wait until all of the blocks are transferred */
514 if (data) {
Dipen Dudhat77c14582009-10-05 15:41:58 +0530515#ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
Simon Glass09b465f2017-07-29 11:35:17 -0600516 esdhc_pio_read_write(priv, data);
Dipen Dudhat77c14582009-10-05 15:41:58 +0530517#else
Peng Fan51313b42018-01-21 19:00:24 +0800518 flags = DATA_COMPLETE;
519 if ((cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK) ||
520 (cmd->cmdidx == MMC_CMD_SEND_TUNING_BLOCK_HS200)) {
521 flags = IRQSTAT_BRR;
522 }
523
Andy Fleming50586ef2008-10-30 16:47:16 -0500524 do {
Stefano Babicc67bee12010-02-05 15:11:27 +0100525 irqstat = esdhc_read32(&regs->irqstat);
Andy Fleming50586ef2008-10-30 16:47:16 -0500526
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500527 if (irqstat & IRQSTAT_DTOE) {
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900528 err = -ETIMEDOUT;
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500529 goto out;
530 }
Frans Meulenbroeks63fb5a72010-07-31 04:45:18 +0000531
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500532 if (irqstat & DATA_ERR) {
Jaehoon Chung915ffa52016-07-19 16:33:36 +0900533 err = -ECOMM;
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500534 goto out;
535 }
Peng Fan51313b42018-01-21 19:00:24 +0800536 } while ((irqstat & flags) != flags);
Ye.Li71689772014-02-20 18:00:57 +0800537
Peng Fan4683b222015-06-25 10:32:26 +0800538 /*
539 * Need invalidate the dcache here again to avoid any
540 * cache-fill during the DMA operations such as the
541 * speculative pre-fetching etc.
542 */
Eric Nelson54899fc2013-04-03 12:31:56 +0000543 if (data->flags & MMC_DATA_READ)
544 check_and_invalidate_dcache_range(cmd, data);
Ye.Li71689772014-02-20 18:00:57 +0800545#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500546 }
547
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500548out:
549 /* Reset CMD and DATA portions on error */
550 if (err) {
551 esdhc_write32(&regs->sysctl, esdhc_read32(&regs->sysctl) |
552 SYSCTL_RSTC);
553 while (esdhc_read32(&regs->sysctl) & SYSCTL_RSTC)
554 ;
555
556 if (data) {
557 esdhc_write32(&regs->sysctl,
558 esdhc_read32(&regs->sysctl) |
559 SYSCTL_RSTD);
560 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTD))
561 ;
562 }
Otavio Salvadorf022d362015-02-17 10:42:43 -0200563
564 /* If this was CMD11, then notify that power cycle is needed */
565 if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V)
566 printf("CMD11 to switch to 1.8V mode failed, card requires power cycle.\n");
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500567 }
568
Stefano Babicc67bee12010-02-05 15:11:27 +0100569 esdhc_write32(&regs->irqstat, -1);
Andy Fleming50586ef2008-10-30 16:47:16 -0500570
Andrew Gabbasov8a573022014-03-24 02:41:06 -0500571 return err;
Andy Fleming50586ef2008-10-30 16:47:16 -0500572}
573
Simon Glass09b465f2017-07-29 11:35:17 -0600574static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
Andy Fleming50586ef2008-10-30 16:47:16 -0500575{
Benoît Thébaudeaub9b4f142018-01-16 22:44:18 +0100576 struct fsl_esdhc *regs = priv->esdhc_regs;
Benoît Thébaudeau4f425282017-05-03 11:59:03 +0200577 int div = 1;
578#ifdef ARCH_MXC
Benoît Thébaudeaub9b4f142018-01-16 22:44:18 +0100579#ifdef CONFIG_MX53
580 /* For i.MX53 eSDHCv3, SYSCTL.SDCLKFS may not be set to 0. */
581 int pre_div = (regs == (struct fsl_esdhc *)MMC_SDHC3_BASE_ADDR) ? 2 : 1;
582#else
Benoît Thébaudeau4f425282017-05-03 11:59:03 +0200583 int pre_div = 1;
Benoît Thébaudeaub9b4f142018-01-16 22:44:18 +0100584#endif
Benoît Thébaudeau4f425282017-05-03 11:59:03 +0200585#else
586 int pre_div = 2;
587#endif
588 int ddr_pre_div = mmc->ddr_mode ? 2 : 1;
Peng Fan96f04072016-03-25 14:16:56 +0800589 int sdhc_clk = priv->sdhc_clk;
Andy Fleming50586ef2008-10-30 16:47:16 -0500590 uint clk;
591
Pantelis Antoniou93bfd612014-03-11 19:34:20 +0200592 if (clock < mmc->cfg->f_min)
593 clock = mmc->cfg->f_min;
Stefano Babicc67bee12010-02-05 15:11:27 +0100594
Benoît Thébaudeau4f425282017-05-03 11:59:03 +0200595 while (sdhc_clk / (16 * pre_div * ddr_pre_div) > clock && pre_div < 256)
596 pre_div *= 2;
Andy Fleming50586ef2008-10-30 16:47:16 -0500597
Benoît Thébaudeau4f425282017-05-03 11:59:03 +0200598 while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16)
599 div++;
Andy Fleming50586ef2008-10-30 16:47:16 -0500600
Benoît Thébaudeau4f425282017-05-03 11:59:03 +0200601 pre_div >>= 1;
Andy Fleming50586ef2008-10-30 16:47:16 -0500602 div -= 1;
603
604 clk = (pre_div << 8) | (div << 4);
605
Eric Nelsonf0b5f232015-12-04 12:32:48 -0700606#ifdef CONFIG_FSL_USDHC
Ye Li84ecdf62016-06-15 10:53:01 +0800607 esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_CKEN);
Eric Nelsonf0b5f232015-12-04 12:32:48 -0700608#else
Kumar Galacc4d1222010-03-18 15:51:05 -0500609 esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
Eric Nelsonf0b5f232015-12-04 12:32:48 -0700610#endif
Stefano Babicc67bee12010-02-05 15:11:27 +0100611
612 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
Andy Fleming50586ef2008-10-30 16:47:16 -0500613
614 udelay(10000);
615
Eric Nelsonf0b5f232015-12-04 12:32:48 -0700616#ifdef CONFIG_FSL_USDHC
Ye Li84ecdf62016-06-15 10:53:01 +0800617 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN | VENDORSPEC_CKEN);
Eric Nelsonf0b5f232015-12-04 12:32:48 -0700618#else
619 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
620#endif
Stefano Babicc67bee12010-02-05 15:11:27 +0100621
Peng Fan51313b42018-01-21 19:00:24 +0800622 priv->clock = clock;
Andy Fleming50586ef2008-10-30 16:47:16 -0500623}
624
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +0800625#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
Simon Glass09b465f2017-07-29 11:35:17 -0600626static void esdhc_clock_control(struct fsl_esdhc_priv *priv, bool enable)
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +0800627{
Peng Fan96f04072016-03-25 14:16:56 +0800628 struct fsl_esdhc *regs = priv->esdhc_regs;
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +0800629 u32 value;
630 u32 time_out;
631
632 value = esdhc_read32(&regs->sysctl);
633
634 if (enable)
635 value |= SYSCTL_CKEN;
636 else
637 value &= ~SYSCTL_CKEN;
638
639 esdhc_write32(&regs->sysctl, value);
640
641 time_out = 20;
642 value = PRSSTAT_SDSTB;
643 while (!(esdhc_read32(&regs->prsstat) & value)) {
644 if (time_out == 0) {
645 printf("fsl_esdhc: Internal clock never stabilised.\n");
646 break;
647 }
648 time_out--;
649 mdelay(1);
650 }
651}
652#endif
653
Peng Fan51313b42018-01-21 19:00:24 +0800654#ifdef MMC_SUPPORTS_TUNING
655static int esdhc_change_pinstate(struct udevice *dev)
656{
657 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
658 int ret;
659
660 switch (priv->mode) {
661 case UHS_SDR50:
662 case UHS_DDR50:
663 ret = pinctrl_select_state(dev, "state_100mhz");
664 break;
665 case UHS_SDR104:
666 case MMC_HS_200:
Peng Fanc76382f2018-08-10 14:07:55 +0800667 case MMC_HS_400:
Peng Fan51313b42018-01-21 19:00:24 +0800668 ret = pinctrl_select_state(dev, "state_200mhz");
669 break;
670 default:
671 ret = pinctrl_select_state(dev, "default");
672 break;
673 }
674
675 if (ret)
676 printf("%s %d error\n", __func__, priv->mode);
677
678 return ret;
679}
680
681static void esdhc_reset_tuning(struct mmc *mmc)
682{
683 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
684 struct fsl_esdhc *regs = priv->esdhc_regs;
685
686 if (priv->flags & ESDHC_FLAG_USDHC) {
687 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
688 esdhc_clrbits32(&regs->autoc12err,
689 MIX_CTRL_SMPCLK_SEL |
690 MIX_CTRL_EXE_TUNE);
691 }
692 }
693}
694
Peng Fanc76382f2018-08-10 14:07:55 +0800695static void esdhc_set_strobe_dll(struct mmc *mmc)
696{
697 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
698 struct fsl_esdhc *regs = priv->esdhc_regs;
699 u32 val;
700
701 if (priv->clock > ESDHC_STROBE_DLL_CLK_FREQ) {
702 writel(ESDHC_STROBE_DLL_CTRL_RESET, &regs->strobe_dllctrl);
703
704 /*
705 * enable strobe dll ctrl and adjust the delay target
706 * for the uSDHC loopback read clock
707 */
708 val = ESDHC_STROBE_DLL_CTRL_ENABLE |
709 (priv->strobe_dll_delay_target <<
710 ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_SHIFT);
711 writel(val, &regs->strobe_dllctrl);
712 /* wait 1us to make sure strobe dll status register stable */
713 mdelay(1);
714 val = readl(&regs->strobe_dllstat);
715 if (!(val & ESDHC_STROBE_DLL_STS_REF_LOCK))
716 pr_warn("HS400 strobe DLL status REF not lock!\n");
717 if (!(val & ESDHC_STROBE_DLL_STS_SLV_LOCK))
718 pr_warn("HS400 strobe DLL status SLV not lock!\n");
719 }
720}
721
Peng Fan51313b42018-01-21 19:00:24 +0800722static int esdhc_set_timing(struct mmc *mmc)
723{
724 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
725 struct fsl_esdhc *regs = priv->esdhc_regs;
726 u32 mixctrl;
727
728 mixctrl = readl(&regs->mixctrl);
729 mixctrl &= ~(MIX_CTRL_DDREN | MIX_CTRL_HS400_EN);
730
731 switch (mmc->selected_mode) {
732 case MMC_LEGACY:
733 case SD_LEGACY:
734 esdhc_reset_tuning(mmc);
Peng Fanc76382f2018-08-10 14:07:55 +0800735 writel(mixctrl, &regs->mixctrl);
736 break;
737 case MMC_HS_400:
738 mixctrl |= MIX_CTRL_DDREN | MIX_CTRL_HS400_EN;
739 writel(mixctrl, &regs->mixctrl);
740 esdhc_set_strobe_dll(mmc);
Peng Fan51313b42018-01-21 19:00:24 +0800741 break;
742 case MMC_HS:
743 case MMC_HS_52:
744 case MMC_HS_200:
745 case SD_HS:
746 case UHS_SDR12:
747 case UHS_SDR25:
748 case UHS_SDR50:
749 case UHS_SDR104:
750 writel(mixctrl, &regs->mixctrl);
751 break;
752 case UHS_DDR50:
753 case MMC_DDR_52:
754 mixctrl |= MIX_CTRL_DDREN;
755 writel(mixctrl, &regs->mixctrl);
756 break;
757 default:
758 printf("Not supported %d\n", mmc->selected_mode);
759 return -EINVAL;
760 }
761
762 priv->mode = mmc->selected_mode;
763
764 return esdhc_change_pinstate(mmc->dev);
765}
766
767static int esdhc_set_voltage(struct mmc *mmc)
768{
769 struct fsl_esdhc_priv *priv = dev_get_priv(mmc->dev);
770 struct fsl_esdhc *regs = priv->esdhc_regs;
771 int ret;
772
773 priv->signal_voltage = mmc->signal_voltage;
774 switch (mmc->signal_voltage) {
775 case MMC_SIGNAL_VOLTAGE_330:
776 if (priv->vs18_enable)
777 return -EIO;
778#ifdef CONFIG_DM_REGULATOR
779 if (!IS_ERR_OR_NULL(priv->vqmmc_dev)) {
780 ret = regulator_set_value(priv->vqmmc_dev, 3300000);
781 if (ret) {
782 printf("Setting to 3.3V error");
783 return -EIO;
784 }
785 /* Wait for 5ms */
786 mdelay(5);
787 }
788#endif
789
790 esdhc_clrbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
791 if (!(esdhc_read32(&regs->vendorspec) &
792 ESDHC_VENDORSPEC_VSELECT))
793 return 0;
794
795 return -EAGAIN;
796 case MMC_SIGNAL_VOLTAGE_180:
797#ifdef CONFIG_DM_REGULATOR
798 if (!IS_ERR_OR_NULL(priv->vqmmc_dev)) {
799 ret = regulator_set_value(priv->vqmmc_dev, 1800000);
800 if (ret) {
801 printf("Setting to 1.8V error");
802 return -EIO;
803 }
804 }
805#endif
806 esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
807 if (esdhc_read32(&regs->vendorspec) & ESDHC_VENDORSPEC_VSELECT)
808 return 0;
809
810 return -EAGAIN;
811 case MMC_SIGNAL_VOLTAGE_120:
812 return -ENOTSUPP;
813 default:
814 return 0;
815 }
816}
817
818static void esdhc_stop_tuning(struct mmc *mmc)
819{
820 struct mmc_cmd cmd;
821
822 cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
823 cmd.cmdarg = 0;
824 cmd.resp_type = MMC_RSP_R1b;
825
826 dm_mmc_send_cmd(mmc->dev, &cmd, NULL);
827}
828
829static int fsl_esdhc_execute_tuning(struct udevice *dev, uint32_t opcode)
830{
831 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
832 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
833 struct fsl_esdhc *regs = priv->esdhc_regs;
834 struct mmc *mmc = &plat->mmc;
835 u32 irqstaten = readl(&regs->irqstaten);
836 u32 irqsigen = readl(&regs->irqsigen);
837 int i, ret = -ETIMEDOUT;
838 u32 val, mixctrl;
839
840 /* clock tuning is not needed for upto 52MHz */
841 if (mmc->clock <= 52000000)
842 return 0;
843
844 /* This is readw/writew SDHCI_HOST_CONTROL2 when tuning */
845 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
846 val = readl(&regs->autoc12err);
847 mixctrl = readl(&regs->mixctrl);
848 val &= ~MIX_CTRL_SMPCLK_SEL;
849 mixctrl &= ~(MIX_CTRL_FBCLK_SEL | MIX_CTRL_AUTO_TUNE_EN);
850
851 val |= MIX_CTRL_EXE_TUNE;
852 mixctrl |= MIX_CTRL_FBCLK_SEL | MIX_CTRL_AUTO_TUNE_EN;
853
854 writel(val, &regs->autoc12err);
855 writel(mixctrl, &regs->mixctrl);
856 }
857
858 /* sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE); */
859 mixctrl = readl(&regs->mixctrl);
860 mixctrl = MIX_CTRL_DTDSEL_READ | (mixctrl & ~MIX_CTRL_SDHCI_MASK);
861 writel(mixctrl, &regs->mixctrl);
862
863 writel(IRQSTATEN_BRR, &regs->irqstaten);
864 writel(IRQSTATEN_BRR, &regs->irqsigen);
865
866 /*
867 * Issue opcode repeatedly till Execute Tuning is set to 0 or the number
868 * of loops reaches 40 times.
869 */
870 for (i = 0; i < MAX_TUNING_LOOP; i++) {
871 u32 ctrl;
872
873 if (opcode == MMC_CMD_SEND_TUNING_BLOCK_HS200) {
874 if (mmc->bus_width == 8)
875 writel(0x7080, &regs->blkattr);
876 else if (mmc->bus_width == 4)
877 writel(0x7040, &regs->blkattr);
878 } else {
879 writel(0x7040, &regs->blkattr);
880 }
881
882 /* sdhci_writew(host, SDHCI_TRNS_READ, SDHCI_TRANSFER_MODE) */
883 val = readl(&regs->mixctrl);
884 val = MIX_CTRL_DTDSEL_READ | (val & ~MIX_CTRL_SDHCI_MASK);
885 writel(val, &regs->mixctrl);
886
887 /* We are using STD tuning, no need to check return value */
888 mmc_send_tuning(mmc, opcode, NULL);
889
890 ctrl = readl(&regs->autoc12err);
891 if ((!(ctrl & MIX_CTRL_EXE_TUNE)) &&
892 (ctrl & MIX_CTRL_SMPCLK_SEL)) {
893 /*
894 * need to wait some time, make sure sd/mmc fininsh
895 * send out tuning data, otherwise, the sd/mmc can't
896 * response to any command when the card still out
897 * put the tuning data.
898 */
899 mdelay(1);
900 ret = 0;
901 break;
902 }
903
904 /* Add 1ms delay for SD and eMMC */
905 mdelay(1);
906 }
907
908 writel(irqstaten, &regs->irqstaten);
909 writel(irqsigen, &regs->irqsigen);
910
911 esdhc_stop_tuning(mmc);
912
913 return ret;
914}
915#endif
916
Simon Glass9586aa62017-07-29 11:35:18 -0600917static int esdhc_set_ios_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
Andy Fleming50586ef2008-10-30 16:47:16 -0500918{
Peng Fan96f04072016-03-25 14:16:56 +0800919 struct fsl_esdhc *regs = priv->esdhc_regs;
Peng Fan51313b42018-01-21 19:00:24 +0800920 int ret __maybe_unused;
Andy Fleming50586ef2008-10-30 16:47:16 -0500921
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +0800922#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
923 /* Select to use peripheral clock */
Simon Glass09b465f2017-07-29 11:35:17 -0600924 esdhc_clock_control(priv, false);
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +0800925 esdhc_setbits32(&regs->scr, ESDHCCTL_PCS);
Simon Glass09b465f2017-07-29 11:35:17 -0600926 esdhc_clock_control(priv, true);
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +0800927#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500928 /* Set the clock speed */
Peng Fan51313b42018-01-21 19:00:24 +0800929 if (priv->clock != mmc->clock)
930 set_sysctl(priv, mmc, mmc->clock);
931
932#ifdef MMC_SUPPORTS_TUNING
933 if (mmc->clk_disable) {
934#ifdef CONFIG_FSL_USDHC
935 esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_CKEN);
936#else
937 esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
938#endif
939 } else {
940#ifdef CONFIG_FSL_USDHC
941 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN |
942 VENDORSPEC_CKEN);
943#else
944 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
945#endif
946 }
947
948 if (priv->mode != mmc->selected_mode) {
949 ret = esdhc_set_timing(mmc);
950 if (ret) {
951 printf("esdhc_set_timing error %d\n", ret);
952 return ret;
953 }
954 }
955
956 if (priv->signal_voltage != mmc->signal_voltage) {
957 ret = esdhc_set_voltage(mmc);
958 if (ret) {
959 printf("esdhc_set_voltage error %d\n", ret);
960 return ret;
961 }
962 }
963#endif
Andy Fleming50586ef2008-10-30 16:47:16 -0500964
965 /* Set the bus width */
Stefano Babicc67bee12010-02-05 15:11:27 +0100966 esdhc_clrbits32(&regs->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
Andy Fleming50586ef2008-10-30 16:47:16 -0500967
968 if (mmc->bus_width == 4)
Stefano Babicc67bee12010-02-05 15:11:27 +0100969 esdhc_setbits32(&regs->proctl, PROCTL_DTW_4);
Andy Fleming50586ef2008-10-30 16:47:16 -0500970 else if (mmc->bus_width == 8)
Stefano Babicc67bee12010-02-05 15:11:27 +0100971 esdhc_setbits32(&regs->proctl, PROCTL_DTW_8);
972
Jaehoon Chung07b0b9c2016-12-30 15:30:16 +0900973 return 0;
Andy Fleming50586ef2008-10-30 16:47:16 -0500974}
975
Simon Glass9586aa62017-07-29 11:35:18 -0600976static int esdhc_init_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
Andy Fleming50586ef2008-10-30 16:47:16 -0500977{
Peng Fan96f04072016-03-25 14:16:56 +0800978 struct fsl_esdhc *regs = priv->esdhc_regs;
Simon Glass201e8282017-07-29 11:35:20 -0600979 ulong start;
Andy Fleming50586ef2008-10-30 16:47:16 -0500980
Stefano Babicc67bee12010-02-05 15:11:27 +0100981 /* Reset the entire host controller */
Dirk Behmea61da722013-07-15 15:44:29 +0200982 esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
Stefano Babicc67bee12010-02-05 15:11:27 +0100983
984 /* Wait until the controller is available */
Simon Glass201e8282017-07-29 11:35:20 -0600985 start = get_timer(0);
986 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA)) {
987 if (get_timer(start) > 1000)
988 return -ETIMEDOUT;
989 }
Stefano Babicc67bee12010-02-05 15:11:27 +0100990
Peng Fanf53225c2016-06-15 10:53:00 +0800991#if defined(CONFIG_FSL_USDHC)
992 /* RSTA doesn't reset MMC_BOOT register, so manually reset it */
993 esdhc_write32(&regs->mmcboot, 0x0);
994 /* Reset MIX_CTRL and CLK_TUNE_CTRL_STATUS regs to 0 */
995 esdhc_write32(&regs->mixctrl, 0x0);
996 esdhc_write32(&regs->clktunectrlstatus, 0x0);
997
998 /* Put VEND_SPEC to default value */
Peng Fandb359ef2018-01-02 16:51:22 +0800999 if (priv->vs18_enable)
1000 esdhc_write32(&regs->vendorspec, (VENDORSPEC_INIT |
1001 ESDHC_VENDORSPEC_VSELECT));
1002 else
1003 esdhc_write32(&regs->vendorspec, VENDORSPEC_INIT);
Peng Fanf53225c2016-06-15 10:53:00 +08001004
1005 /* Disable DLL_CTRL delay line */
1006 esdhc_write32(&regs->dllctrl, 0x0);
1007#endif
1008
Benoît Thébaudeau16e43f32012-08-13 07:28:16 +00001009#ifndef ARCH_MXC
P.V.Suresh2c1764e2010-12-04 10:37:23 +05301010 /* Enable cache snooping */
Benoît Thébaudeau16e43f32012-08-13 07:28:16 +00001011 esdhc_write32(&regs->scr, 0x00000040);
1012#endif
P.V.Suresh2c1764e2010-12-04 10:37:23 +05301013
Eric Nelsonf0b5f232015-12-04 12:32:48 -07001014#ifndef CONFIG_FSL_USDHC
Dirk Behmea61da722013-07-15 15:44:29 +02001015 esdhc_setbits32(&regs->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
Ye Li84ecdf62016-06-15 10:53:01 +08001016#else
1017 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_HCKEN | VENDORSPEC_IPGEN);
Eric Nelsonf0b5f232015-12-04 12:32:48 -07001018#endif
Andy Fleming50586ef2008-10-30 16:47:16 -05001019
1020 /* Set the initial clock speed */
Jaehoon Chung65117182018-01-26 19:25:29 +09001021 mmc_set_clock(mmc, 400000, MMC_CLK_ENABLE);
Andy Fleming50586ef2008-10-30 16:47:16 -05001022
1023 /* Disable the BRR and BWR bits in IRQSTAT */
Stefano Babicc67bee12010-02-05 15:11:27 +01001024 esdhc_clrbits32(&regs->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR);
Andy Fleming50586ef2008-10-30 16:47:16 -05001025
1026 /* Put the PROCTL reg back to the default */
Stefano Babicc67bee12010-02-05 15:11:27 +01001027 esdhc_write32(&regs->proctl, PROCTL_INIT);
Andy Fleming50586ef2008-10-30 16:47:16 -05001028
Stefano Babicc67bee12010-02-05 15:11:27 +01001029 /* Set timout to the maximum value */
1030 esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
Andy Fleming50586ef2008-10-30 16:47:16 -05001031
Thierry Redingd48d2e22012-01-02 01:15:38 +00001032 return 0;
1033}
Andy Fleming50586ef2008-10-30 16:47:16 -05001034
Simon Glass9586aa62017-07-29 11:35:18 -06001035static int esdhc_getcd_common(struct fsl_esdhc_priv *priv)
Thierry Redingd48d2e22012-01-02 01:15:38 +00001036{
Peng Fan96f04072016-03-25 14:16:56 +08001037 struct fsl_esdhc *regs = priv->esdhc_regs;
Thierry Redingd48d2e22012-01-02 01:15:38 +00001038 int timeout = 1000;
Stefano Babicc67bee12010-02-05 15:11:27 +01001039
Haijun.Zhangf7e27cc2014-01-10 13:52:17 +08001040#ifdef CONFIG_ESDHC_DETECT_QUIRK
1041 if (CONFIG_ESDHC_DETECT_QUIRK)
1042 return 1;
1043#endif
Peng Fan96f04072016-03-25 14:16:56 +08001044
Simon Glass653282b2017-07-29 11:35:24 -06001045#if CONFIG_IS_ENABLED(DM_MMC)
Peng Fan96f04072016-03-25 14:16:56 +08001046 if (priv->non_removable)
1047 return 1;
Yangbo Lufc8048a2016-12-07 11:54:30 +08001048#ifdef CONFIG_DM_GPIO
Peng Fan96f04072016-03-25 14:16:56 +08001049 if (dm_gpio_is_valid(&priv->cd_gpio))
1050 return dm_gpio_get_value(&priv->cd_gpio);
1051#endif
Yangbo Lufc8048a2016-12-07 11:54:30 +08001052#endif
Peng Fan96f04072016-03-25 14:16:56 +08001053
Thierry Redingd48d2e22012-01-02 01:15:38 +00001054 while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
1055 udelay(1000);
1056
1057 return timeout > 0;
Andy Fleming50586ef2008-10-30 16:47:16 -05001058}
1059
Simon Glass446e0772017-07-29 11:35:19 -06001060static int esdhc_reset(struct fsl_esdhc *regs)
Jerry Huang48bb3bb2010-03-18 15:57:06 -05001061{
Simon Glass446e0772017-07-29 11:35:19 -06001062 ulong start;
Jerry Huang48bb3bb2010-03-18 15:57:06 -05001063
1064 /* reset the controller */
Dirk Behmea61da722013-07-15 15:44:29 +02001065 esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
Jerry Huang48bb3bb2010-03-18 15:57:06 -05001066
1067 /* hardware clears the bit when it is done */
Simon Glass446e0772017-07-29 11:35:19 -06001068 start = get_timer(0);
1069 while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA)) {
1070 if (get_timer(start) > 100) {
1071 printf("MMC/SD: Reset never completed.\n");
1072 return -ETIMEDOUT;
1073 }
1074 }
1075
1076 return 0;
Jerry Huang48bb3bb2010-03-18 15:57:06 -05001077}
1078
Simon Glasse7881d82017-07-29 11:35:31 -06001079#if !CONFIG_IS_ENABLED(DM_MMC)
Simon Glass9586aa62017-07-29 11:35:18 -06001080static int esdhc_getcd(struct mmc *mmc)
1081{
1082 struct fsl_esdhc_priv *priv = mmc->priv;
1083
1084 return esdhc_getcd_common(priv);
1085}
1086
1087static int esdhc_init(struct mmc *mmc)
1088{
1089 struct fsl_esdhc_priv *priv = mmc->priv;
1090
1091 return esdhc_init_common(priv, mmc);
1092}
1093
1094static int esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
1095 struct mmc_data *data)
1096{
1097 struct fsl_esdhc_priv *priv = mmc->priv;
1098
1099 return esdhc_send_cmd_common(priv, mmc, cmd, data);
1100}
1101
1102static int esdhc_set_ios(struct mmc *mmc)
1103{
1104 struct fsl_esdhc_priv *priv = mmc->priv;
1105
1106 return esdhc_set_ios_common(priv, mmc);
1107}
1108
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001109static const struct mmc_ops esdhc_ops = {
Simon Glass9586aa62017-07-29 11:35:18 -06001110 .getcd = esdhc_getcd,
1111 .init = esdhc_init,
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001112 .send_cmd = esdhc_send_cmd,
1113 .set_ios = esdhc_set_ios,
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001114};
Simon Glass653282b2017-07-29 11:35:24 -06001115#endif
Pantelis Antoniouab769f22014-02-26 19:28:45 +02001116
Simon Glasse88e1d92017-07-29 11:35:21 -06001117static int fsl_esdhc_init(struct fsl_esdhc_priv *priv,
1118 struct fsl_esdhc_plat *plat)
Andy Fleming50586ef2008-10-30 16:47:16 -05001119{
Simon Glasse88e1d92017-07-29 11:35:21 -06001120 struct mmc_config *cfg;
Stefano Babicc67bee12010-02-05 15:11:27 +01001121 struct fsl_esdhc *regs;
Li Yang030955c2010-11-25 17:06:09 +00001122 u32 caps, voltage_caps;
Simon Glass446e0772017-07-29 11:35:19 -06001123 int ret;
Andy Fleming50586ef2008-10-30 16:47:16 -05001124
Peng Fan96f04072016-03-25 14:16:56 +08001125 if (!priv)
1126 return -EINVAL;
Stefano Babicc67bee12010-02-05 15:11:27 +01001127
Peng Fan96f04072016-03-25 14:16:56 +08001128 regs = priv->esdhc_regs;
Stefano Babicc67bee12010-02-05 15:11:27 +01001129
Jerry Huang48bb3bb2010-03-18 15:57:06 -05001130 /* First reset the eSDHC controller */
Simon Glass446e0772017-07-29 11:35:19 -06001131 ret = esdhc_reset(regs);
1132 if (ret)
1133 return ret;
Jerry Huang48bb3bb2010-03-18 15:57:06 -05001134
Eric Nelsonf0b5f232015-12-04 12:32:48 -07001135#ifndef CONFIG_FSL_USDHC
Jerry Huang975324a2012-05-17 23:57:02 +00001136 esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN
1137 | SYSCTL_IPGEN | SYSCTL_CKEN);
Peng Fan51313b42018-01-21 19:00:24 +08001138 /* Clearing tuning bits in case ROM has set it already */
1139 esdhc_write32(&regs->mixctrl, 0);
1140 esdhc_write32(&regs->autoc12err, 0);
1141 esdhc_write32(&regs->clktunectrlstatus, 0);
Ye Li84ecdf62016-06-15 10:53:01 +08001142#else
1143 esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN |
1144 VENDORSPEC_HCKEN | VENDORSPEC_IPGEN | VENDORSPEC_CKEN);
Eric Nelsonf0b5f232015-12-04 12:32:48 -07001145#endif
Jerry Huang975324a2012-05-17 23:57:02 +00001146
Peng Fan32a91792017-06-12 17:50:53 +08001147 if (priv->vs18_enable)
1148 esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
1149
Ye.Lia3d6e382014-11-04 15:35:49 +08001150 writel(SDHCI_IRQ_EN_BITS, &regs->irqstaten);
Simon Glasse88e1d92017-07-29 11:35:21 -06001151 cfg = &plat->cfg;
Simon Glass653282b2017-07-29 11:35:24 -06001152#ifndef CONFIG_DM_MMC
Simon Glasse88e1d92017-07-29 11:35:21 -06001153 memset(cfg, '\0', sizeof(*cfg));
Simon Glass653282b2017-07-29 11:35:24 -06001154#endif
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001155
Li Yang030955c2010-11-25 17:06:09 +00001156 voltage_caps = 0;
Wang Huan19060bd2014-09-05 13:52:40 +08001157 caps = esdhc_read32(&regs->hostcapblt);
Roy Zang3b4456e2011-01-07 00:06:47 -06001158
1159#ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC135
1160 caps = caps & ~(ESDHC_HOSTCAPBLT_SRS |
1161 ESDHC_HOSTCAPBLT_VS18 | ESDHC_HOSTCAPBLT_VS30);
1162#endif
Haijun.Zhangef38f3f2013-10-31 09:38:19 +08001163
1164/* T4240 host controller capabilities register should have VS33 bit */
1165#ifdef CONFIG_SYS_FSL_MMC_HAS_CAPBLT_VS33
1166 caps = caps | ESDHC_HOSTCAPBLT_VS33;
1167#endif
1168
Andy Fleming50586ef2008-10-30 16:47:16 -05001169 if (caps & ESDHC_HOSTCAPBLT_VS18)
Li Yang030955c2010-11-25 17:06:09 +00001170 voltage_caps |= MMC_VDD_165_195;
Andy Fleming50586ef2008-10-30 16:47:16 -05001171 if (caps & ESDHC_HOSTCAPBLT_VS30)
Li Yang030955c2010-11-25 17:06:09 +00001172 voltage_caps |= MMC_VDD_29_30 | MMC_VDD_30_31;
Andy Fleming50586ef2008-10-30 16:47:16 -05001173 if (caps & ESDHC_HOSTCAPBLT_VS33)
Li Yang030955c2010-11-25 17:06:09 +00001174 voltage_caps |= MMC_VDD_32_33 | MMC_VDD_33_34;
1175
Simon Glasse88e1d92017-07-29 11:35:21 -06001176 cfg->name = "FSL_SDHC";
Simon Glasse7881d82017-07-29 11:35:31 -06001177#if !CONFIG_IS_ENABLED(DM_MMC)
Simon Glasse88e1d92017-07-29 11:35:21 -06001178 cfg->ops = &esdhc_ops;
Simon Glass653282b2017-07-29 11:35:24 -06001179#endif
Li Yang030955c2010-11-25 17:06:09 +00001180#ifdef CONFIG_SYS_SD_VOLTAGE
Simon Glasse88e1d92017-07-29 11:35:21 -06001181 cfg->voltages = CONFIG_SYS_SD_VOLTAGE;
Li Yang030955c2010-11-25 17:06:09 +00001182#else
Simon Glasse88e1d92017-07-29 11:35:21 -06001183 cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
Li Yang030955c2010-11-25 17:06:09 +00001184#endif
Simon Glasse88e1d92017-07-29 11:35:21 -06001185 if ((cfg->voltages & voltage_caps) == 0) {
Li Yang030955c2010-11-25 17:06:09 +00001186 printf("voltage not supported by controller\n");
1187 return -1;
1188 }
Andy Fleming50586ef2008-10-30 16:47:16 -05001189
Peng Fan96f04072016-03-25 14:16:56 +08001190 if (priv->bus_width == 8)
Simon Glasse88e1d92017-07-29 11:35:21 -06001191 cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
Peng Fan96f04072016-03-25 14:16:56 +08001192 else if (priv->bus_width == 4)
Simon Glasse88e1d92017-07-29 11:35:21 -06001193 cfg->host_caps = MMC_MODE_4BIT;
Peng Fan96f04072016-03-25 14:16:56 +08001194
Simon Glasse88e1d92017-07-29 11:35:21 -06001195 cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
Volodymyr Riazantsev0e1bf612015-01-20 10:16:44 -05001196#ifdef CONFIG_SYS_FSL_ESDHC_HAS_DDR_MODE
Simon Glasse88e1d92017-07-29 11:35:21 -06001197 cfg->host_caps |= MMC_MODE_DDR_52MHz;
Volodymyr Riazantsev0e1bf612015-01-20 10:16:44 -05001198#endif
Andy Fleming50586ef2008-10-30 16:47:16 -05001199
Peng Fan96f04072016-03-25 14:16:56 +08001200 if (priv->bus_width > 0) {
1201 if (priv->bus_width < 8)
Simon Glasse88e1d92017-07-29 11:35:21 -06001202 cfg->host_caps &= ~MMC_MODE_8BIT;
Peng Fan96f04072016-03-25 14:16:56 +08001203 if (priv->bus_width < 4)
Simon Glasse88e1d92017-07-29 11:35:21 -06001204 cfg->host_caps &= ~MMC_MODE_4BIT;
Abbas Razaaad46592013-03-25 09:13:34 +00001205 }
1206
Andy Fleming50586ef2008-10-30 16:47:16 -05001207 if (caps & ESDHC_HOSTCAPBLT_HSS)
Simon Glasse88e1d92017-07-29 11:35:21 -06001208 cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
Andy Fleming50586ef2008-10-30 16:47:16 -05001209
Haijun.Zhangd47e3d22014-01-10 13:52:18 +08001210#ifdef CONFIG_ESDHC_DETECT_8_BIT_QUIRK
1211 if (CONFIG_ESDHC_DETECT_8_BIT_QUIRK)
Simon Glasse88e1d92017-07-29 11:35:21 -06001212 cfg->host_caps &= ~MMC_MODE_8BIT;
Haijun.Zhangd47e3d22014-01-10 13:52:18 +08001213#endif
1214
Peng Fan51313b42018-01-21 19:00:24 +08001215 cfg->host_caps |= priv->caps;
1216
Simon Glasse88e1d92017-07-29 11:35:21 -06001217 cfg->f_min = 400000;
Peng Fan51313b42018-01-21 19:00:24 +08001218 cfg->f_max = min(priv->sdhc_clk, (u32)200000000);
Andy Fleming50586ef2008-10-30 16:47:16 -05001219
Simon Glasse88e1d92017-07-29 11:35:21 -06001220 cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
Pantelis Antoniou93bfd612014-03-11 19:34:20 +02001221
Peng Fan51313b42018-01-21 19:00:24 +08001222 writel(0, &regs->dllctrl);
1223 if (priv->flags & ESDHC_FLAG_USDHC) {
1224 if (priv->flags & ESDHC_FLAG_STD_TUNING) {
1225 u32 val = readl(&regs->tuning_ctrl);
1226
1227 val |= ESDHC_STD_TUNING_EN;
1228 val &= ~ESDHC_TUNING_START_TAP_MASK;
1229 val |= priv->tuning_start_tap;
1230 val &= ~ESDHC_TUNING_STEP_MASK;
1231 val |= (priv->tuning_step) << ESDHC_TUNING_STEP_SHIFT;
1232 writel(val, &regs->tuning_ctrl);
1233 }
1234 }
1235
Peng Fan96f04072016-03-25 14:16:56 +08001236 return 0;
1237}
1238
Simon Glass52489302017-07-29 11:35:28 -06001239#if !CONFIG_IS_ENABLED(DM_MMC)
Jagan Teki2e87c442017-05-12 17:18:20 +05301240static int fsl_esdhc_cfg_to_priv(struct fsl_esdhc_cfg *cfg,
1241 struct fsl_esdhc_priv *priv)
1242{
1243 if (!cfg || !priv)
1244 return -EINVAL;
1245
1246 priv->esdhc_regs = (struct fsl_esdhc *)(unsigned long)(cfg->esdhc_base);
1247 priv->bus_width = cfg->max_bus_width;
1248 priv->sdhc_clk = cfg->sdhc_clk;
1249 priv->wp_enable = cfg->wp_enable;
Peng Fan32a91792017-06-12 17:50:53 +08001250 priv->vs18_enable = cfg->vs18_enable;
Jagan Teki2e87c442017-05-12 17:18:20 +05301251
1252 return 0;
1253};
1254
Peng Fan96f04072016-03-25 14:16:56 +08001255int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
1256{
Simon Glasse88e1d92017-07-29 11:35:21 -06001257 struct fsl_esdhc_plat *plat;
Peng Fan96f04072016-03-25 14:16:56 +08001258 struct fsl_esdhc_priv *priv;
Simon Glassd6eb25e2017-07-29 11:35:22 -06001259 struct mmc *mmc;
Peng Fan96f04072016-03-25 14:16:56 +08001260 int ret;
1261
1262 if (!cfg)
1263 return -EINVAL;
1264
1265 priv = calloc(sizeof(struct fsl_esdhc_priv), 1);
1266 if (!priv)
1267 return -ENOMEM;
Simon Glasse88e1d92017-07-29 11:35:21 -06001268 plat = calloc(sizeof(struct fsl_esdhc_plat), 1);
1269 if (!plat) {
1270 free(priv);
1271 return -ENOMEM;
1272 }
Peng Fan96f04072016-03-25 14:16:56 +08001273
1274 ret = fsl_esdhc_cfg_to_priv(cfg, priv);
1275 if (ret) {
1276 debug("%s xlate failure\n", __func__);
Simon Glasse88e1d92017-07-29 11:35:21 -06001277 free(plat);
Peng Fan96f04072016-03-25 14:16:56 +08001278 free(priv);
1279 return ret;
1280 }
1281
Simon Glasse88e1d92017-07-29 11:35:21 -06001282 ret = fsl_esdhc_init(priv, plat);
Peng Fan96f04072016-03-25 14:16:56 +08001283 if (ret) {
1284 debug("%s init failure\n", __func__);
Simon Glasse88e1d92017-07-29 11:35:21 -06001285 free(plat);
Peng Fan96f04072016-03-25 14:16:56 +08001286 free(priv);
1287 return ret;
1288 }
1289
Simon Glassd6eb25e2017-07-29 11:35:22 -06001290 mmc = mmc_create(&plat->cfg, priv);
1291 if (!mmc)
1292 return -EIO;
1293
1294 priv->mmc = mmc;
1295
Andy Fleming50586ef2008-10-30 16:47:16 -05001296 return 0;
1297}
1298
1299int fsl_esdhc_mmc_init(bd_t *bis)
1300{
Stefano Babicc67bee12010-02-05 15:11:27 +01001301 struct fsl_esdhc_cfg *cfg;
1302
Fabio Estevam88227a12012-12-27 08:51:08 +00001303 cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1);
Stefano Babicc67bee12010-02-05 15:11:27 +01001304 cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR;
Simon Glasse9adeca2012-12-13 20:49:05 +00001305 cfg->sdhc_clk = gd->arch.sdhc_clk;
Stefano Babicc67bee12010-02-05 15:11:27 +01001306 return fsl_esdhc_initialize(bis, cfg);
Andy Fleming50586ef2008-10-30 16:47:16 -05001307}
Jagan Teki2e87c442017-05-12 17:18:20 +05301308#endif
Anton Vorontsovb33433a2009-06-10 00:25:29 +04001309
Yangbo Lu5a8dbdc2015-04-22 13:57:00 +08001310#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
1311void mmc_adapter_card_type_ident(void)
1312{
1313 u8 card_id;
1314 u8 value;
1315
1316 card_id = QIXIS_READ(present) & QIXIS_SDID_MASK;
1317 gd->arch.sdhc_adapter = card_id;
1318
1319 switch (card_id) {
1320 case QIXIS_ESDHC_ADAPTER_TYPE_EMMC45:
Yangbo Lucdc69552015-09-17 10:27:12 +08001321 value = QIXIS_READ(brdcfg[5]);
1322 value |= (QIXIS_DAT4 | QIXIS_DAT5_6_7);
1323 QIXIS_WRITE(brdcfg[5], value);
Yangbo Lu5a8dbdc2015-04-22 13:57:00 +08001324 break;
1325 case QIXIS_ESDHC_ADAPTER_TYPE_SDMMC_LEGACY:
Yangbo Lubf50be82015-09-17 10:27:48 +08001326 value = QIXIS_READ(pwr_ctl[1]);
1327 value |= QIXIS_EVDD_BY_SDHC_VS;
1328 QIXIS_WRITE(pwr_ctl[1], value);
Yangbo Lu5a8dbdc2015-04-22 13:57:00 +08001329 break;
1330 case QIXIS_ESDHC_ADAPTER_TYPE_EMMC44:
1331 value = QIXIS_READ(brdcfg[5]);
1332 value |= (QIXIS_SDCLKIN | QIXIS_SDCLKOUT);
1333 QIXIS_WRITE(brdcfg[5], value);
1334 break;
1335 case QIXIS_ESDHC_ADAPTER_TYPE_RSV:
1336 break;
1337 case QIXIS_ESDHC_ADAPTER_TYPE_MMC:
1338 break;
1339 case QIXIS_ESDHC_ADAPTER_TYPE_SD:
1340 break;
1341 case QIXIS_ESDHC_NO_ADAPTER:
1342 break;
1343 default:
1344 break;
1345 }
1346}
1347#endif
1348
Stefano Babicc67bee12010-02-05 15:11:27 +01001349#ifdef CONFIG_OF_LIBFDT
Yangbo Lufce1e162017-01-17 10:43:54 +08001350__weak int esdhc_status_fixup(void *blob, const char *compat)
1351{
1352#ifdef CONFIG_FSL_ESDHC_PIN_MUX
1353 if (!hwconfig("esdhc")) {
1354 do_fixup_by_compat(blob, compat, "status", "disabled",
1355 sizeof("disabled"), 1);
1356 return 1;
1357 }
1358#endif
Yangbo Lufce1e162017-01-17 10:43:54 +08001359 return 0;
1360}
1361
Anton Vorontsovb33433a2009-06-10 00:25:29 +04001362void fdt_fixup_esdhc(void *blob, bd_t *bd)
1363{
1364 const char *compat = "fsl,esdhc";
Anton Vorontsovb33433a2009-06-10 00:25:29 +04001365
Yangbo Lufce1e162017-01-17 10:43:54 +08001366 if (esdhc_status_fixup(blob, compat))
Chenhui Zhaoa6da8b82011-01-04 17:23:05 +08001367 return;
Anton Vorontsovb33433a2009-06-10 00:25:29 +04001368
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +08001369#ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
1370 do_fixup_by_compat_u32(blob, compat, "peripheral-frequency",
1371 gd->arch.sdhc_clk, 1);
1372#else
Anton Vorontsovb33433a2009-06-10 00:25:29 +04001373 do_fixup_by_compat_u32(blob, compat, "clock-frequency",
Simon Glasse9adeca2012-12-13 20:49:05 +00001374 gd->arch.sdhc_clk, 1);
Yangbo Lu2d9ca2c2015-04-22 13:57:40 +08001375#endif
Yangbo Lu5a8dbdc2015-04-22 13:57:00 +08001376#ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
1377 do_fixup_by_compat_u32(blob, compat, "adapter-type",
1378 (u32)(gd->arch.sdhc_adapter), 1);
1379#endif
Anton Vorontsovb33433a2009-06-10 00:25:29 +04001380}
Stefano Babicc67bee12010-02-05 15:11:27 +01001381#endif
Peng Fan96f04072016-03-25 14:16:56 +08001382
Simon Glass653282b2017-07-29 11:35:24 -06001383#if CONFIG_IS_ENABLED(DM_MMC)
Peng Fan96f04072016-03-25 14:16:56 +08001384#include <asm/arch/clock.h>
Peng Fanb60f1452017-02-22 16:21:55 +08001385__weak void init_clk_usdhc(u32 index)
1386{
1387}
1388
Peng Fan96f04072016-03-25 14:16:56 +08001389static int fsl_esdhc_probe(struct udevice *dev)
1390{
1391 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
Simon Glasse88e1d92017-07-29 11:35:21 -06001392 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
Peng Fan96f04072016-03-25 14:16:56 +08001393 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
Peng Fan51313b42018-01-21 19:00:24 +08001394 const void *fdt = gd->fdt_blob;
1395 int node = dev_of_offset(dev);
1396 struct esdhc_soc_data *data =
1397 (struct esdhc_soc_data *)dev_get_driver_data(dev);
York Sun9bb272e2017-08-08 15:45:13 -07001398#ifdef CONFIG_DM_REGULATOR
Peng Fan4483b7e2017-06-12 17:50:54 +08001399 struct udevice *vqmmc_dev;
York Sun9bb272e2017-08-08 15:45:13 -07001400#endif
Peng Fan96f04072016-03-25 14:16:56 +08001401 fdt_addr_t addr;
1402 unsigned int val;
Simon Glass653282b2017-07-29 11:35:24 -06001403 struct mmc *mmc;
Peng Fan96f04072016-03-25 14:16:56 +08001404 int ret;
1405
Simon Glass4aac33f2017-07-29 11:35:23 -06001406 addr = dev_read_addr(dev);
Peng Fan96f04072016-03-25 14:16:56 +08001407 if (addr == FDT_ADDR_T_NONE)
1408 return -EINVAL;
1409
1410 priv->esdhc_regs = (struct fsl_esdhc *)addr;
1411 priv->dev = dev;
Peng Fan51313b42018-01-21 19:00:24 +08001412 priv->mode = -1;
1413 if (data) {
1414 priv->flags = data->flags;
1415 priv->caps = data->caps;
1416 }
Peng Fan96f04072016-03-25 14:16:56 +08001417
Simon Glass4aac33f2017-07-29 11:35:23 -06001418 val = dev_read_u32_default(dev, "bus-width", -1);
Peng Fan96f04072016-03-25 14:16:56 +08001419 if (val == 8)
1420 priv->bus_width = 8;
1421 else if (val == 4)
1422 priv->bus_width = 4;
1423 else
1424 priv->bus_width = 1;
1425
Peng Fan51313b42018-01-21 19:00:24 +08001426 val = fdtdec_get_int(fdt, node, "fsl,tuning-step", 1);
1427 priv->tuning_step = val;
1428 val = fdtdec_get_int(fdt, node, "fsl,tuning-start-tap",
1429 ESDHC_TUNING_START_TAP_DEFAULT);
1430 priv->tuning_start_tap = val;
1431 val = fdtdec_get_int(fdt, node, "fsl,strobe-dll-delay-target",
1432 ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_DEFAULT);
1433 priv->strobe_dll_delay_target = val;
1434
Simon Glass4aac33f2017-07-29 11:35:23 -06001435 if (dev_read_bool(dev, "non-removable")) {
Peng Fan96f04072016-03-25 14:16:56 +08001436 priv->non_removable = 1;
1437 } else {
1438 priv->non_removable = 0;
Yangbo Lufc8048a2016-12-07 11:54:30 +08001439#ifdef CONFIG_DM_GPIO
Simon Glass4aac33f2017-07-29 11:35:23 -06001440 gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio,
1441 GPIOD_IS_IN);
Yangbo Lufc8048a2016-12-07 11:54:30 +08001442#endif
Peng Fan96f04072016-03-25 14:16:56 +08001443 }
1444
Peng Fan14831512016-06-15 10:53:02 +08001445 priv->wp_enable = 1;
1446
Yangbo Lufc8048a2016-12-07 11:54:30 +08001447#ifdef CONFIG_DM_GPIO
Simon Glass4aac33f2017-07-29 11:35:23 -06001448 ret = gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio,
1449 GPIOD_IS_IN);
Peng Fan14831512016-06-15 10:53:02 +08001450 if (ret)
1451 priv->wp_enable = 0;
Yangbo Lufc8048a2016-12-07 11:54:30 +08001452#endif
Peng Fan4483b7e2017-06-12 17:50:54 +08001453
1454 priv->vs18_enable = 0;
1455
1456#ifdef CONFIG_DM_REGULATOR
1457 /*
1458 * If emmc I/O has a fixed voltage at 1.8V, this must be provided,
1459 * otherwise, emmc will work abnormally.
1460 */
1461 ret = device_get_supply_regulator(dev, "vqmmc-supply", &vqmmc_dev);
1462 if (ret) {
1463 dev_dbg(dev, "no vqmmc-supply\n");
1464 } else {
1465 ret = regulator_set_enable(vqmmc_dev, true);
1466 if (ret) {
1467 dev_err(dev, "fail to enable vqmmc-supply\n");
1468 return ret;
1469 }
1470
1471 if (regulator_get_value(vqmmc_dev) == 1800000)
1472 priv->vs18_enable = 1;
1473 }
1474#endif
1475
Peng Fan51313b42018-01-21 19:00:24 +08001476 if (fdt_get_property(fdt, node, "no-1-8-v", NULL))
Peng Fanc76382f2018-08-10 14:07:55 +08001477 priv->caps &= ~(UHS_CAPS | MMC_MODE_HS200 | MMC_MODE_HS400);
Peng Fan51313b42018-01-21 19:00:24 +08001478
Peng Fan96f04072016-03-25 14:16:56 +08001479 /*
1480 * TODO:
1481 * Because lack of clk driver, if SDHC clk is not enabled,
1482 * need to enable it first before this driver is invoked.
1483 *
1484 * we use MXC_ESDHC_CLK to get clk freq.
1485 * If one would like to make this function work,
1486 * the aliases should be provided in dts as this:
1487 *
1488 * aliases {
1489 * mmc0 = &usdhc1;
1490 * mmc1 = &usdhc2;
1491 * mmc2 = &usdhc3;
1492 * mmc3 = &usdhc4;
1493 * };
1494 * Then if your board only supports mmc2 and mmc3, but we can
1495 * correctly get the seq as 2 and 3, then let mxc_get_clock
1496 * work as expected.
1497 */
Peng Fanb60f1452017-02-22 16:21:55 +08001498
1499 init_clk_usdhc(dev->seq);
1500
Peng Fan3cb14502018-10-18 14:28:35 +02001501 if (IS_ENABLED(CONFIG_CLK)) {
1502 /* Assigned clock already set clock */
1503 ret = clk_get_by_name(dev, "per", &priv->per_clk);
1504 if (ret) {
1505 printf("Failed to get per_clk\n");
1506 return ret;
1507 }
1508 ret = clk_enable(&priv->per_clk);
1509 if (ret) {
1510 printf("Failed to enable per_clk\n");
1511 return ret;
1512 }
1513
1514 priv->sdhc_clk = clk_get_rate(&priv->per_clk);
1515 } else {
1516 priv->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK + dev->seq);
1517 if (priv->sdhc_clk <= 0) {
1518 dev_err(dev, "Unable to get clk for %s\n", dev->name);
1519 return -EINVAL;
1520 }
Peng Fan96f04072016-03-25 14:16:56 +08001521 }
1522
Simon Glasse88e1d92017-07-29 11:35:21 -06001523 ret = fsl_esdhc_init(priv, plat);
Peng Fan96f04072016-03-25 14:16:56 +08001524 if (ret) {
1525 dev_err(dev, "fsl_esdhc_init failure\n");
1526 return ret;
1527 }
1528
Simon Glass653282b2017-07-29 11:35:24 -06001529 mmc = &plat->mmc;
1530 mmc->cfg = &plat->cfg;
1531 mmc->dev = dev;
1532 upriv->mmc = mmc;
Peng Fan96f04072016-03-25 14:16:56 +08001533
Simon Glass653282b2017-07-29 11:35:24 -06001534 return esdhc_init_common(priv, mmc);
Peng Fan96f04072016-03-25 14:16:56 +08001535}
1536
Simon Glasse7881d82017-07-29 11:35:31 -06001537#if CONFIG_IS_ENABLED(DM_MMC)
Simon Glass653282b2017-07-29 11:35:24 -06001538static int fsl_esdhc_get_cd(struct udevice *dev)
1539{
1540 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1541
1542 return true;
1543 return esdhc_getcd_common(priv);
1544}
1545
1546static int fsl_esdhc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
1547 struct mmc_data *data)
1548{
1549 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1550 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1551
1552 return esdhc_send_cmd_common(priv, &plat->mmc, cmd, data);
1553}
1554
1555static int fsl_esdhc_set_ios(struct udevice *dev)
1556{
1557 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1558 struct fsl_esdhc_priv *priv = dev_get_priv(dev);
1559
1560 return esdhc_set_ios_common(priv, &plat->mmc);
1561}
1562
1563static const struct dm_mmc_ops fsl_esdhc_ops = {
1564 .get_cd = fsl_esdhc_get_cd,
1565 .send_cmd = fsl_esdhc_send_cmd,
1566 .set_ios = fsl_esdhc_set_ios,
Peng Fan51313b42018-01-21 19:00:24 +08001567#ifdef MMC_SUPPORTS_TUNING
1568 .execute_tuning = fsl_esdhc_execute_tuning,
1569#endif
Simon Glass653282b2017-07-29 11:35:24 -06001570};
1571#endif
1572
Peng Fan51313b42018-01-21 19:00:24 +08001573static struct esdhc_soc_data usdhc_imx7d_data = {
1574 .flags = ESDHC_FLAG_USDHC | ESDHC_FLAG_STD_TUNING
1575 | ESDHC_FLAG_HAVE_CAP1 | ESDHC_FLAG_HS200
1576 | ESDHC_FLAG_HS400,
1577 .caps = UHS_CAPS | MMC_MODE_HS200 | MMC_MODE_DDR_52MHz |
1578 MMC_MODE_HS_52MHz | MMC_MODE_HS,
1579};
1580
Peng Fan96f04072016-03-25 14:16:56 +08001581static const struct udevice_id fsl_esdhc_ids[] = {
1582 { .compatible = "fsl,imx6ul-usdhc", },
1583 { .compatible = "fsl,imx6sx-usdhc", },
1584 { .compatible = "fsl,imx6sl-usdhc", },
1585 { .compatible = "fsl,imx6q-usdhc", },
Peng Fan51313b42018-01-21 19:00:24 +08001586 { .compatible = "fsl,imx7d-usdhc", .data = (ulong)&usdhc_imx7d_data,},
Peng Fanb60f1452017-02-22 16:21:55 +08001587 { .compatible = "fsl,imx7ulp-usdhc", },
Yangbo Lua6473f82016-12-07 11:54:31 +08001588 { .compatible = "fsl,esdhc", },
Peng Fan96f04072016-03-25 14:16:56 +08001589 { /* sentinel */ }
1590};
1591
Simon Glass653282b2017-07-29 11:35:24 -06001592#if CONFIG_IS_ENABLED(BLK)
1593static int fsl_esdhc_bind(struct udevice *dev)
1594{
1595 struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
1596
1597 return mmc_bind(dev, &plat->mmc, &plat->cfg);
1598}
1599#endif
1600
Peng Fan96f04072016-03-25 14:16:56 +08001601U_BOOT_DRIVER(fsl_esdhc) = {
1602 .name = "fsl-esdhc-mmc",
1603 .id = UCLASS_MMC,
1604 .of_match = fsl_esdhc_ids,
Simon Glass653282b2017-07-29 11:35:24 -06001605 .ops = &fsl_esdhc_ops,
Simon Glass653282b2017-07-29 11:35:24 -06001606#if CONFIG_IS_ENABLED(BLK)
1607 .bind = fsl_esdhc_bind,
1608#endif
Peng Fan96f04072016-03-25 14:16:56 +08001609 .probe = fsl_esdhc_probe,
Simon Glasse88e1d92017-07-29 11:35:21 -06001610 .platdata_auto_alloc_size = sizeof(struct fsl_esdhc_plat),
Peng Fan96f04072016-03-25 14:16:56 +08001611 .priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv),
1612};
1613#endif