fsl_esdhc.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201
  1. /*
  2. * Copyright 2007, 2010-2011 Freescale Semiconductor, Inc
  3. * Andy Fleming
  4. *
  5. * Based vaguely on the pxa mmc code:
  6. * (C) Copyright 2003
  7. * Kyle Harris, Nexus Technologies, Inc. kharris@nexus-tech.net
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <config.h>
  12. #include <common.h>
  13. #include <command.h>
  14. #include <errno.h>
  15. #include <hwconfig.h>
  16. #include <mmc.h>
  17. #include <part.h>
  18. #include <power/regulator.h>
  19. #include <malloc.h>
  20. #include <fsl_esdhc.h>
  21. #include <fdt_support.h>
  22. #include <asm/io.h>
  23. #include <dm.h>
  24. #include <asm-generic/gpio.h>
  25. DECLARE_GLOBAL_DATA_PTR;
  26. #define SDHCI_IRQ_EN_BITS (IRQSTATEN_CC | IRQSTATEN_TC | \
  27. IRQSTATEN_CINT | \
  28. IRQSTATEN_CTOE | IRQSTATEN_CCE | IRQSTATEN_CEBE | \
  29. IRQSTATEN_CIE | IRQSTATEN_DTOE | IRQSTATEN_DCE | \
  30. IRQSTATEN_DEBE | IRQSTATEN_BRR | IRQSTATEN_BWR | \
  31. IRQSTATEN_DINT)
  32. struct fsl_esdhc {
  33. uint dsaddr; /* SDMA system address register */
  34. uint blkattr; /* Block attributes register */
  35. uint cmdarg; /* Command argument register */
  36. uint xfertyp; /* Transfer type register */
  37. uint cmdrsp0; /* Command response 0 register */
  38. uint cmdrsp1; /* Command response 1 register */
  39. uint cmdrsp2; /* Command response 2 register */
  40. uint cmdrsp3; /* Command response 3 register */
  41. uint datport; /* Buffer data port register */
  42. uint prsstat; /* Present state register */
  43. uint proctl; /* Protocol control register */
  44. uint sysctl; /* System Control Register */
  45. uint irqstat; /* Interrupt status register */
  46. uint irqstaten; /* Interrupt status enable register */
  47. uint irqsigen; /* Interrupt signal enable register */
  48. uint autoc12err; /* Auto CMD error status register */
  49. uint hostcapblt; /* Host controller capabilities register */
  50. uint wml; /* Watermark level register */
  51. uint mixctrl; /* For USDHC */
  52. char reserved1[4]; /* reserved */
  53. uint fevt; /* Force event register */
  54. uint admaes; /* ADMA error status register */
  55. uint adsaddr; /* ADMA system address register */
  56. char reserved2[4];
  57. uint dllctrl;
  58. uint dllstat;
  59. uint clktunectrlstatus;
  60. char reserved3[84];
  61. uint vendorspec;
  62. uint mmcboot;
  63. uint vendorspec2;
  64. char reserved4[48];
  65. uint hostver; /* Host controller version register */
  66. char reserved5[4]; /* reserved */
  67. uint dmaerraddr; /* DMA error address register */
  68. char reserved6[4]; /* reserved */
  69. uint dmaerrattr; /* DMA error attribute register */
  70. char reserved7[4]; /* reserved */
  71. uint hostcapblt2; /* Host controller capabilities register 2 */
  72. char reserved8[8]; /* reserved */
  73. uint tcr; /* Tuning control register */
  74. char reserved9[28]; /* reserved */
  75. uint sddirctl; /* SD direction control register */
  76. char reserved10[712];/* reserved */
  77. uint scr; /* eSDHC control register */
  78. };
  79. struct fsl_esdhc_plat {
  80. struct mmc_config cfg;
  81. struct mmc mmc;
  82. };
  83. /**
  84. * struct fsl_esdhc_priv
  85. *
  86. * @esdhc_regs: registers of the sdhc controller
  87. * @sdhc_clk: Current clk of the sdhc controller
  88. * @bus_width: bus width, 1bit, 4bit or 8bit
  89. * @cfg: mmc config
  90. * @mmc: mmc
  91. * Following is used when Driver Model is enabled for MMC
  92. * @dev: pointer for the device
  93. * @non_removable: 0: removable; 1: non-removable
  94. * @wp_enable: 1: enable checking wp; 0: no check
  95. * @vs18_enable: 1: use 1.8V voltage; 0: use 3.3V
  96. * @cd_gpio: gpio for card detection
  97. * @wp_gpio: gpio for write protection
  98. */
  99. struct fsl_esdhc_priv {
  100. struct fsl_esdhc *esdhc_regs;
  101. unsigned int sdhc_clk;
  102. unsigned int bus_width;
  103. #if !CONFIG_IS_ENABLED(BLK)
  104. struct mmc *mmc;
  105. #endif
  106. struct udevice *dev;
  107. int non_removable;
  108. int wp_enable;
  109. int vs18_enable;
  110. #ifdef CONFIG_DM_GPIO
  111. struct gpio_desc cd_gpio;
  112. struct gpio_desc wp_gpio;
  113. #endif
  114. };
  115. /* Return the XFERTYP flags for a given command and data packet */
  116. static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data)
  117. {
  118. uint xfertyp = 0;
  119. if (data) {
  120. xfertyp |= XFERTYP_DPSEL;
  121. #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
  122. xfertyp |= XFERTYP_DMAEN;
  123. #endif
  124. if (data->blocks > 1) {
  125. xfertyp |= XFERTYP_MSBSEL;
  126. xfertyp |= XFERTYP_BCEN;
  127. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
  128. xfertyp |= XFERTYP_AC12EN;
  129. #endif
  130. }
  131. if (data->flags & MMC_DATA_READ)
  132. xfertyp |= XFERTYP_DTDSEL;
  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. if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
  145. xfertyp |= XFERTYP_CMDTYP_ABORT;
  146. return XFERTYP_CMD(cmd->cmdidx) | xfertyp;
  147. }
  148. #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
  149. /*
  150. * PIO Read/Write Mode reduce the performace as DMA is not used in this mode.
  151. */
  152. static void esdhc_pio_read_write(struct fsl_esdhc_priv *priv,
  153. struct mmc_data *data)
  154. {
  155. struct fsl_esdhc *regs = priv->esdhc_regs;
  156. uint blocks;
  157. char *buffer;
  158. uint databuf;
  159. uint size;
  160. uint irqstat;
  161. ulong start;
  162. if (data->flags & MMC_DATA_READ) {
  163. blocks = data->blocks;
  164. buffer = data->dest;
  165. while (blocks) {
  166. start = get_timer(0);
  167. size = data->blocksize;
  168. irqstat = esdhc_read32(&regs->irqstat);
  169. while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BREN)) {
  170. if (get_timer(start) > PIO_TIMEOUT) {
  171. printf("\nData Read Failed in PIO Mode.");
  172. return;
  173. }
  174. }
  175. while (size && (!(irqstat & IRQSTAT_TC))) {
  176. udelay(100); /* Wait before last byte transfer complete */
  177. irqstat = esdhc_read32(&regs->irqstat);
  178. databuf = in_le32(&regs->datport);
  179. *((uint *)buffer) = databuf;
  180. buffer += 4;
  181. size -= 4;
  182. }
  183. blocks--;
  184. }
  185. } else {
  186. blocks = data->blocks;
  187. buffer = (char *)data->src;
  188. while (blocks) {
  189. start = get_timer(0);
  190. size = data->blocksize;
  191. irqstat = esdhc_read32(&regs->irqstat);
  192. while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BWEN)) {
  193. if (get_timer(start) > PIO_TIMEOUT) {
  194. printf("\nData Write Failed in PIO Mode.");
  195. return;
  196. }
  197. }
  198. while (size && (!(irqstat & IRQSTAT_TC))) {
  199. udelay(100); /* Wait before last byte transfer complete */
  200. databuf = *((uint *)buffer);
  201. buffer += 4;
  202. size -= 4;
  203. irqstat = esdhc_read32(&regs->irqstat);
  204. out_le32(&regs->datport, databuf);
  205. }
  206. blocks--;
  207. }
  208. }
  209. }
  210. #endif
  211. static int esdhc_setup_data(struct fsl_esdhc_priv *priv, struct mmc *mmc,
  212. struct mmc_data *data)
  213. {
  214. int timeout;
  215. struct fsl_esdhc *regs = priv->esdhc_regs;
  216. #if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234)
  217. dma_addr_t addr;
  218. #endif
  219. uint wml_value;
  220. wml_value = data->blocksize/4;
  221. if (data->flags & MMC_DATA_READ) {
  222. if (wml_value > WML_RD_WML_MAX)
  223. wml_value = WML_RD_WML_MAX_VAL;
  224. esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
  225. #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
  226. #if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234)
  227. addr = virt_to_phys((void *)(data->dest));
  228. if (upper_32_bits(addr))
  229. printf("Error found for upper 32 bits\n");
  230. else
  231. esdhc_write32(&regs->dsaddr, lower_32_bits(addr));
  232. #else
  233. esdhc_write32(&regs->dsaddr, (u32)data->dest);
  234. #endif
  235. #endif
  236. } else {
  237. #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
  238. flush_dcache_range((ulong)data->src,
  239. (ulong)data->src+data->blocks
  240. *data->blocksize);
  241. #endif
  242. if (wml_value > WML_WR_WML_MAX)
  243. wml_value = WML_WR_WML_MAX_VAL;
  244. if (priv->wp_enable) {
  245. if ((esdhc_read32(&regs->prsstat) &
  246. PRSSTAT_WPSPL) == 0) {
  247. printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
  248. return -ETIMEDOUT;
  249. }
  250. }
  251. esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK,
  252. wml_value << 16);
  253. #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
  254. #if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234)
  255. addr = virt_to_phys((void *)(data->src));
  256. if (upper_32_bits(addr))
  257. printf("Error found for upper 32 bits\n");
  258. else
  259. esdhc_write32(&regs->dsaddr, lower_32_bits(addr));
  260. #else
  261. esdhc_write32(&regs->dsaddr, (u32)data->src);
  262. #endif
  263. #endif
  264. }
  265. esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
  266. /* Calculate the timeout period for data transactions */
  267. /*
  268. * 1)Timeout period = (2^(timeout+13)) SD Clock cycles
  269. * 2)Timeout period should be minimum 0.250sec as per SD Card spec
  270. * So, Number of SD Clock cycles for 0.25sec should be minimum
  271. * (SD Clock/sec * 0.25 sec) SD Clock cycles
  272. * = (mmc->clock * 1/4) SD Clock cycles
  273. * As 1) >= 2)
  274. * => (2^(timeout+13)) >= mmc->clock * 1/4
  275. * Taking log2 both the sides
  276. * => timeout + 13 >= log2(mmc->clock/4)
  277. * Rounding up to next power of 2
  278. * => timeout + 13 = log2(mmc->clock/4) + 1
  279. * => timeout + 13 = fls(mmc->clock/4)
  280. *
  281. * However, the MMC spec "It is strongly recommended for hosts to
  282. * implement more than 500ms timeout value even if the card
  283. * indicates the 250ms maximum busy length." Even the previous
  284. * value of 300ms is known to be insufficient for some cards.
  285. * So, we use
  286. * => timeout + 13 = fls(mmc->clock/2)
  287. */
  288. timeout = fls(mmc->clock/2);
  289. timeout -= 13;
  290. if (timeout > 14)
  291. timeout = 14;
  292. if (timeout < 0)
  293. timeout = 0;
  294. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC_A001
  295. if ((timeout == 4) || (timeout == 8) || (timeout == 12))
  296. timeout++;
  297. #endif
  298. #ifdef ESDHCI_QUIRK_BROKEN_TIMEOUT_VALUE
  299. timeout = 0xE;
  300. #endif
  301. esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16);
  302. return 0;
  303. }
  304. static void check_and_invalidate_dcache_range
  305. (struct mmc_cmd *cmd,
  306. struct mmc_data *data) {
  307. unsigned start = 0;
  308. unsigned end = 0;
  309. unsigned size = roundup(ARCH_DMA_MINALIGN,
  310. data->blocks*data->blocksize);
  311. #if defined(CONFIG_FSL_LAYERSCAPE) || defined(CONFIG_S32V234)
  312. dma_addr_t addr;
  313. addr = virt_to_phys((void *)(data->dest));
  314. if (upper_32_bits(addr))
  315. printf("Error found for upper 32 bits\n");
  316. else
  317. start = lower_32_bits(addr);
  318. #else
  319. start = (unsigned)data->dest;
  320. #endif
  321. end = start + size;
  322. invalidate_dcache_range(start, end);
  323. }
  324. /*
  325. * Sends a command out on the bus. Takes the mmc pointer,
  326. * a command pointer, and an optional data pointer.
  327. */
  328. static int esdhc_send_cmd_common(struct fsl_esdhc_priv *priv, struct mmc *mmc,
  329. struct mmc_cmd *cmd, struct mmc_data *data)
  330. {
  331. int err = 0;
  332. uint xfertyp;
  333. uint irqstat;
  334. struct fsl_esdhc *regs = priv->esdhc_regs;
  335. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
  336. if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
  337. return 0;
  338. #endif
  339. esdhc_write32(&regs->irqstat, -1);
  340. sync();
  341. /* Wait for the bus to be idle */
  342. while ((esdhc_read32(&regs->prsstat) & PRSSTAT_CICHB) ||
  343. (esdhc_read32(&regs->prsstat) & PRSSTAT_CIDHB))
  344. ;
  345. while (esdhc_read32(&regs->prsstat) & PRSSTAT_DLA)
  346. ;
  347. /* Wait at least 8 SD clock cycles before the next command */
  348. /*
  349. * Note: This is way more than 8 cycles, but 1ms seems to
  350. * resolve timing issues with some cards
  351. */
  352. udelay(1000);
  353. /* Set up for a data transfer if we have one */
  354. if (data) {
  355. err = esdhc_setup_data(priv, mmc, data);
  356. if(err)
  357. return err;
  358. if (data->flags & MMC_DATA_READ)
  359. check_and_invalidate_dcache_range(cmd, data);
  360. }
  361. /* Figure out the transfer arguments */
  362. xfertyp = esdhc_xfertyp(cmd, data);
  363. /* Mask all irqs */
  364. esdhc_write32(&regs->irqsigen, 0);
  365. /* Send the command */
  366. esdhc_write32(&regs->cmdarg, cmd->cmdarg);
  367. #if defined(CONFIG_FSL_USDHC)
  368. esdhc_write32(&regs->mixctrl,
  369. (esdhc_read32(&regs->mixctrl) & 0xFFFFFF80) | (xfertyp & 0x7F)
  370. | (mmc->ddr_mode ? XFERTYP_DDREN : 0));
  371. esdhc_write32(&regs->xfertyp, xfertyp & 0xFFFF0000);
  372. #else
  373. esdhc_write32(&regs->xfertyp, xfertyp);
  374. #endif
  375. /* Wait for the command to complete */
  376. while (!(esdhc_read32(&regs->irqstat) & (IRQSTAT_CC | IRQSTAT_CTOE)))
  377. ;
  378. irqstat = esdhc_read32(&regs->irqstat);
  379. if (irqstat & CMD_ERR) {
  380. err = -ECOMM;
  381. goto out;
  382. }
  383. if (irqstat & IRQSTAT_CTOE) {
  384. err = -ETIMEDOUT;
  385. goto out;
  386. }
  387. /* Switch voltage to 1.8V if CMD11 succeeded */
  388. if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V) {
  389. esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
  390. printf("Run CMD11 1.8V switch\n");
  391. /* Sleep for 5 ms - max time for card to switch to 1.8V */
  392. udelay(5000);
  393. }
  394. /* Workaround for ESDHC errata ENGcm03648 */
  395. if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
  396. int timeout = 6000;
  397. /* Poll on DATA0 line for cmd with busy signal for 600 ms */
  398. while (timeout > 0 && !(esdhc_read32(&regs->prsstat) &
  399. PRSSTAT_DAT0)) {
  400. udelay(100);
  401. timeout--;
  402. }
  403. if (timeout <= 0) {
  404. printf("Timeout waiting for DAT0 to go high!\n");
  405. err = -ETIMEDOUT;
  406. goto out;
  407. }
  408. }
  409. /* Copy the response to the response buffer */
  410. if (cmd->resp_type & MMC_RSP_136) {
  411. u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0;
  412. cmdrsp3 = esdhc_read32(&regs->cmdrsp3);
  413. cmdrsp2 = esdhc_read32(&regs->cmdrsp2);
  414. cmdrsp1 = esdhc_read32(&regs->cmdrsp1);
  415. cmdrsp0 = esdhc_read32(&regs->cmdrsp0);
  416. cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
  417. cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
  418. cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
  419. cmd->response[3] = (cmdrsp0 << 8);
  420. } else
  421. cmd->response[0] = esdhc_read32(&regs->cmdrsp0);
  422. /* Wait until all of the blocks are transferred */
  423. if (data) {
  424. #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
  425. esdhc_pio_read_write(priv, data);
  426. #else
  427. do {
  428. irqstat = esdhc_read32(&regs->irqstat);
  429. if (irqstat & IRQSTAT_DTOE) {
  430. err = -ETIMEDOUT;
  431. goto out;
  432. }
  433. if (irqstat & DATA_ERR) {
  434. err = -ECOMM;
  435. goto out;
  436. }
  437. } while ((irqstat & DATA_COMPLETE) != DATA_COMPLETE);
  438. /*
  439. * Need invalidate the dcache here again to avoid any
  440. * cache-fill during the DMA operations such as the
  441. * speculative pre-fetching etc.
  442. */
  443. if (data->flags & MMC_DATA_READ)
  444. check_and_invalidate_dcache_range(cmd, data);
  445. #endif
  446. }
  447. out:
  448. /* Reset CMD and DATA portions on error */
  449. if (err) {
  450. esdhc_write32(&regs->sysctl, esdhc_read32(&regs->sysctl) |
  451. SYSCTL_RSTC);
  452. while (esdhc_read32(&regs->sysctl) & SYSCTL_RSTC)
  453. ;
  454. if (data) {
  455. esdhc_write32(&regs->sysctl,
  456. esdhc_read32(&regs->sysctl) |
  457. SYSCTL_RSTD);
  458. while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTD))
  459. ;
  460. }
  461. /* If this was CMD11, then notify that power cycle is needed */
  462. if (cmd->cmdidx == SD_CMD_SWITCH_UHS18V)
  463. printf("CMD11 to switch to 1.8V mode failed, card requires power cycle.\n");
  464. }
  465. esdhc_write32(&regs->irqstat, -1);
  466. return err;
  467. }
  468. static void set_sysctl(struct fsl_esdhc_priv *priv, struct mmc *mmc, uint clock)
  469. {
  470. struct fsl_esdhc *regs = priv->esdhc_regs;
  471. int div = 1;
  472. #ifdef ARCH_MXC
  473. #ifdef CONFIG_MX53
  474. /* For i.MX53 eSDHCv3, SYSCTL.SDCLKFS may not be set to 0. */
  475. int pre_div = (regs == (struct fsl_esdhc *)MMC_SDHC3_BASE_ADDR) ? 2 : 1;
  476. #else
  477. int pre_div = 1;
  478. #endif
  479. #else
  480. int pre_div = 2;
  481. #endif
  482. int ddr_pre_div = mmc->ddr_mode ? 2 : 1;
  483. int sdhc_clk = priv->sdhc_clk;
  484. uint clk;
  485. if (clock < mmc->cfg->f_min)
  486. clock = mmc->cfg->f_min;
  487. while (sdhc_clk / (16 * pre_div * ddr_pre_div) > clock && pre_div < 256)
  488. pre_div *= 2;
  489. while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16)
  490. div++;
  491. pre_div >>= 1;
  492. div -= 1;
  493. clk = (pre_div << 8) | (div << 4);
  494. #ifdef CONFIG_FSL_USDHC
  495. esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_CKEN);
  496. #else
  497. esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
  498. #endif
  499. esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
  500. udelay(10000);
  501. #ifdef CONFIG_FSL_USDHC
  502. esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN | VENDORSPEC_CKEN);
  503. #else
  504. esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
  505. #endif
  506. }
  507. #ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
  508. static void esdhc_clock_control(struct fsl_esdhc_priv *priv, bool enable)
  509. {
  510. struct fsl_esdhc *regs = priv->esdhc_regs;
  511. u32 value;
  512. u32 time_out;
  513. value = esdhc_read32(&regs->sysctl);
  514. if (enable)
  515. value |= SYSCTL_CKEN;
  516. else
  517. value &= ~SYSCTL_CKEN;
  518. esdhc_write32(&regs->sysctl, value);
  519. time_out = 20;
  520. value = PRSSTAT_SDSTB;
  521. while (!(esdhc_read32(&regs->prsstat) & value)) {
  522. if (time_out == 0) {
  523. printf("fsl_esdhc: Internal clock never stabilised.\n");
  524. break;
  525. }
  526. time_out--;
  527. mdelay(1);
  528. }
  529. }
  530. #endif
  531. static int esdhc_set_ios_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
  532. {
  533. struct fsl_esdhc *regs = priv->esdhc_regs;
  534. #ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
  535. /* Select to use peripheral clock */
  536. esdhc_clock_control(priv, false);
  537. esdhc_setbits32(&regs->scr, ESDHCCTL_PCS);
  538. esdhc_clock_control(priv, true);
  539. #endif
  540. /* Set the clock speed */
  541. set_sysctl(priv, mmc, mmc->clock);
  542. /* Set the bus width */
  543. esdhc_clrbits32(&regs->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
  544. if (mmc->bus_width == 4)
  545. esdhc_setbits32(&regs->proctl, PROCTL_DTW_4);
  546. else if (mmc->bus_width == 8)
  547. esdhc_setbits32(&regs->proctl, PROCTL_DTW_8);
  548. return 0;
  549. }
  550. static int esdhc_init_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
  551. {
  552. struct fsl_esdhc *regs = priv->esdhc_regs;
  553. ulong start;
  554. /* Reset the entire host controller */
  555. esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
  556. /* Wait until the controller is available */
  557. start = get_timer(0);
  558. while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA)) {
  559. if (get_timer(start) > 1000)
  560. return -ETIMEDOUT;
  561. }
  562. #if defined(CONFIG_FSL_USDHC)
  563. /* RSTA doesn't reset MMC_BOOT register, so manually reset it */
  564. esdhc_write32(&regs->mmcboot, 0x0);
  565. /* Reset MIX_CTRL and CLK_TUNE_CTRL_STATUS regs to 0 */
  566. esdhc_write32(&regs->mixctrl, 0x0);
  567. esdhc_write32(&regs->clktunectrlstatus, 0x0);
  568. /* Put VEND_SPEC to default value */
  569. if (priv->vs18_enable)
  570. esdhc_write32(&regs->vendorspec, (VENDORSPEC_INIT |
  571. ESDHC_VENDORSPEC_VSELECT));
  572. else
  573. esdhc_write32(&regs->vendorspec, VENDORSPEC_INIT);
  574. /* Disable DLL_CTRL delay line */
  575. esdhc_write32(&regs->dllctrl, 0x0);
  576. #endif
  577. #ifndef ARCH_MXC
  578. /* Enable cache snooping */
  579. esdhc_write32(&regs->scr, 0x00000040);
  580. #endif
  581. #ifndef CONFIG_FSL_USDHC
  582. esdhc_setbits32(&regs->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
  583. #else
  584. esdhc_setbits32(&regs->vendorspec, VENDORSPEC_HCKEN | VENDORSPEC_IPGEN);
  585. #endif
  586. /* Set the initial clock speed */
  587. mmc_set_clock(mmc, 400000, false);
  588. /* Disable the BRR and BWR bits in IRQSTAT */
  589. esdhc_clrbits32(&regs->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR);
  590. /* Put the PROCTL reg back to the default */
  591. esdhc_write32(&regs->proctl, PROCTL_INIT);
  592. /* Set timout to the maximum value */
  593. esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
  594. return 0;
  595. }
  596. static int esdhc_getcd_common(struct fsl_esdhc_priv *priv)
  597. {
  598. struct fsl_esdhc *regs = priv->esdhc_regs;
  599. int timeout = 1000;
  600. #ifdef CONFIG_ESDHC_DETECT_QUIRK
  601. if (CONFIG_ESDHC_DETECT_QUIRK)
  602. return 1;
  603. #endif
  604. #if CONFIG_IS_ENABLED(DM_MMC)
  605. if (priv->non_removable)
  606. return 1;
  607. #ifdef CONFIG_DM_GPIO
  608. if (dm_gpio_is_valid(&priv->cd_gpio))
  609. return dm_gpio_get_value(&priv->cd_gpio);
  610. #endif
  611. #endif
  612. while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
  613. udelay(1000);
  614. return timeout > 0;
  615. }
  616. static int esdhc_reset(struct fsl_esdhc *regs)
  617. {
  618. ulong start;
  619. /* reset the controller */
  620. esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
  621. /* hardware clears the bit when it is done */
  622. start = get_timer(0);
  623. while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA)) {
  624. if (get_timer(start) > 100) {
  625. printf("MMC/SD: Reset never completed.\n");
  626. return -ETIMEDOUT;
  627. }
  628. }
  629. return 0;
  630. }
  631. #if !CONFIG_IS_ENABLED(DM_MMC)
  632. static int esdhc_getcd(struct mmc *mmc)
  633. {
  634. struct fsl_esdhc_priv *priv = mmc->priv;
  635. return esdhc_getcd_common(priv);
  636. }
  637. static int esdhc_init(struct mmc *mmc)
  638. {
  639. struct fsl_esdhc_priv *priv = mmc->priv;
  640. return esdhc_init_common(priv, mmc);
  641. }
  642. static int esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
  643. struct mmc_data *data)
  644. {
  645. struct fsl_esdhc_priv *priv = mmc->priv;
  646. return esdhc_send_cmd_common(priv, mmc, cmd, data);
  647. }
  648. static int esdhc_set_ios(struct mmc *mmc)
  649. {
  650. struct fsl_esdhc_priv *priv = mmc->priv;
  651. return esdhc_set_ios_common(priv, mmc);
  652. }
  653. static const struct mmc_ops esdhc_ops = {
  654. .getcd = esdhc_getcd,
  655. .init = esdhc_init,
  656. .send_cmd = esdhc_send_cmd,
  657. .set_ios = esdhc_set_ios,
  658. };
  659. #endif
  660. static int fsl_esdhc_init(struct fsl_esdhc_priv *priv,
  661. struct fsl_esdhc_plat *plat)
  662. {
  663. struct mmc_config *cfg;
  664. struct fsl_esdhc *regs;
  665. u32 caps, voltage_caps;
  666. int ret;
  667. if (!priv)
  668. return -EINVAL;
  669. regs = priv->esdhc_regs;
  670. /* First reset the eSDHC controller */
  671. ret = esdhc_reset(regs);
  672. if (ret)
  673. return ret;
  674. #ifndef CONFIG_FSL_USDHC
  675. esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN
  676. | SYSCTL_IPGEN | SYSCTL_CKEN);
  677. #else
  678. esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN |
  679. VENDORSPEC_HCKEN | VENDORSPEC_IPGEN | VENDORSPEC_CKEN);
  680. #endif
  681. if (priv->vs18_enable)
  682. esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
  683. writel(SDHCI_IRQ_EN_BITS, &regs->irqstaten);
  684. cfg = &plat->cfg;
  685. #ifndef CONFIG_DM_MMC
  686. memset(cfg, '\0', sizeof(*cfg));
  687. #endif
  688. voltage_caps = 0;
  689. caps = esdhc_read32(&regs->hostcapblt);
  690. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC135
  691. caps = caps & ~(ESDHC_HOSTCAPBLT_SRS |
  692. ESDHC_HOSTCAPBLT_VS18 | ESDHC_HOSTCAPBLT_VS30);
  693. #endif
  694. /* T4240 host controller capabilities register should have VS33 bit */
  695. #ifdef CONFIG_SYS_FSL_MMC_HAS_CAPBLT_VS33
  696. caps = caps | ESDHC_HOSTCAPBLT_VS33;
  697. #endif
  698. if (caps & ESDHC_HOSTCAPBLT_VS18)
  699. voltage_caps |= MMC_VDD_165_195;
  700. if (caps & ESDHC_HOSTCAPBLT_VS30)
  701. voltage_caps |= MMC_VDD_29_30 | MMC_VDD_30_31;
  702. if (caps & ESDHC_HOSTCAPBLT_VS33)
  703. voltage_caps |= MMC_VDD_32_33 | MMC_VDD_33_34;
  704. cfg->name = "FSL_SDHC";
  705. #if !CONFIG_IS_ENABLED(DM_MMC)
  706. cfg->ops = &esdhc_ops;
  707. #endif
  708. #ifdef CONFIG_SYS_SD_VOLTAGE
  709. cfg->voltages = CONFIG_SYS_SD_VOLTAGE;
  710. #else
  711. cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
  712. #endif
  713. if ((cfg->voltages & voltage_caps) == 0) {
  714. printf("voltage not supported by controller\n");
  715. return -1;
  716. }
  717. if (priv->bus_width == 8)
  718. cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
  719. else if (priv->bus_width == 4)
  720. cfg->host_caps = MMC_MODE_4BIT;
  721. cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
  722. #ifdef CONFIG_SYS_FSL_ESDHC_HAS_DDR_MODE
  723. cfg->host_caps |= MMC_MODE_DDR_52MHz;
  724. #endif
  725. if (priv->bus_width > 0) {
  726. if (priv->bus_width < 8)
  727. cfg->host_caps &= ~MMC_MODE_8BIT;
  728. if (priv->bus_width < 4)
  729. cfg->host_caps &= ~MMC_MODE_4BIT;
  730. }
  731. if (caps & ESDHC_HOSTCAPBLT_HSS)
  732. cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
  733. #ifdef CONFIG_ESDHC_DETECT_8_BIT_QUIRK
  734. if (CONFIG_ESDHC_DETECT_8_BIT_QUIRK)
  735. cfg->host_caps &= ~MMC_MODE_8BIT;
  736. #endif
  737. cfg->f_min = 400000;
  738. cfg->f_max = min(priv->sdhc_clk, (u32)52000000);
  739. cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
  740. return 0;
  741. }
  742. #if !CONFIG_IS_ENABLED(DM_MMC)
  743. static int fsl_esdhc_cfg_to_priv(struct fsl_esdhc_cfg *cfg,
  744. struct fsl_esdhc_priv *priv)
  745. {
  746. if (!cfg || !priv)
  747. return -EINVAL;
  748. priv->esdhc_regs = (struct fsl_esdhc *)(unsigned long)(cfg->esdhc_base);
  749. priv->bus_width = cfg->max_bus_width;
  750. priv->sdhc_clk = cfg->sdhc_clk;
  751. priv->wp_enable = cfg->wp_enable;
  752. priv->vs18_enable = cfg->vs18_enable;
  753. return 0;
  754. };
  755. int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
  756. {
  757. struct fsl_esdhc_plat *plat;
  758. struct fsl_esdhc_priv *priv;
  759. struct mmc *mmc;
  760. int ret;
  761. if (!cfg)
  762. return -EINVAL;
  763. priv = calloc(sizeof(struct fsl_esdhc_priv), 1);
  764. if (!priv)
  765. return -ENOMEM;
  766. plat = calloc(sizeof(struct fsl_esdhc_plat), 1);
  767. if (!plat) {
  768. free(priv);
  769. return -ENOMEM;
  770. }
  771. ret = fsl_esdhc_cfg_to_priv(cfg, priv);
  772. if (ret) {
  773. debug("%s xlate failure\n", __func__);
  774. free(plat);
  775. free(priv);
  776. return ret;
  777. }
  778. ret = fsl_esdhc_init(priv, plat);
  779. if (ret) {
  780. debug("%s init failure\n", __func__);
  781. free(plat);
  782. free(priv);
  783. return ret;
  784. }
  785. mmc = mmc_create(&plat->cfg, priv);
  786. if (!mmc)
  787. return -EIO;
  788. priv->mmc = mmc;
  789. return 0;
  790. }
  791. int fsl_esdhc_mmc_init(bd_t *bis)
  792. {
  793. struct fsl_esdhc_cfg *cfg;
  794. cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1);
  795. cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR;
  796. cfg->sdhc_clk = gd->arch.sdhc_clk;
  797. return fsl_esdhc_initialize(bis, cfg);
  798. }
  799. #endif
  800. #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
  801. void mmc_adapter_card_type_ident(void)
  802. {
  803. u8 card_id;
  804. u8 value;
  805. card_id = QIXIS_READ(present) & QIXIS_SDID_MASK;
  806. gd->arch.sdhc_adapter = card_id;
  807. switch (card_id) {
  808. case QIXIS_ESDHC_ADAPTER_TYPE_EMMC45:
  809. value = QIXIS_READ(brdcfg[5]);
  810. value |= (QIXIS_DAT4 | QIXIS_DAT5_6_7);
  811. QIXIS_WRITE(brdcfg[5], value);
  812. break;
  813. case QIXIS_ESDHC_ADAPTER_TYPE_SDMMC_LEGACY:
  814. value = QIXIS_READ(pwr_ctl[1]);
  815. value |= QIXIS_EVDD_BY_SDHC_VS;
  816. QIXIS_WRITE(pwr_ctl[1], value);
  817. break;
  818. case QIXIS_ESDHC_ADAPTER_TYPE_EMMC44:
  819. value = QIXIS_READ(brdcfg[5]);
  820. value |= (QIXIS_SDCLKIN | QIXIS_SDCLKOUT);
  821. QIXIS_WRITE(brdcfg[5], value);
  822. break;
  823. case QIXIS_ESDHC_ADAPTER_TYPE_RSV:
  824. break;
  825. case QIXIS_ESDHC_ADAPTER_TYPE_MMC:
  826. break;
  827. case QIXIS_ESDHC_ADAPTER_TYPE_SD:
  828. break;
  829. case QIXIS_ESDHC_NO_ADAPTER:
  830. break;
  831. default:
  832. break;
  833. }
  834. }
  835. #endif
  836. #ifdef CONFIG_OF_LIBFDT
  837. __weak int esdhc_status_fixup(void *blob, const char *compat)
  838. {
  839. #ifdef CONFIG_FSL_ESDHC_PIN_MUX
  840. if (!hwconfig("esdhc")) {
  841. do_fixup_by_compat(blob, compat, "status", "disabled",
  842. sizeof("disabled"), 1);
  843. return 1;
  844. }
  845. #endif
  846. return 0;
  847. }
  848. void fdt_fixup_esdhc(void *blob, bd_t *bd)
  849. {
  850. const char *compat = "fsl,esdhc";
  851. if (esdhc_status_fixup(blob, compat))
  852. return;
  853. #ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
  854. do_fixup_by_compat_u32(blob, compat, "peripheral-frequency",
  855. gd->arch.sdhc_clk, 1);
  856. #else
  857. do_fixup_by_compat_u32(blob, compat, "clock-frequency",
  858. gd->arch.sdhc_clk, 1);
  859. #endif
  860. #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
  861. do_fixup_by_compat_u32(blob, compat, "adapter-type",
  862. (u32)(gd->arch.sdhc_adapter), 1);
  863. #endif
  864. }
  865. #endif
  866. #if CONFIG_IS_ENABLED(DM_MMC)
  867. #include <asm/arch/clock.h>
  868. __weak void init_clk_usdhc(u32 index)
  869. {
  870. }
  871. static int fsl_esdhc_probe(struct udevice *dev)
  872. {
  873. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  874. struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
  875. struct fsl_esdhc_priv *priv = dev_get_priv(dev);
  876. #ifdef CONFIG_DM_REGULATOR
  877. struct udevice *vqmmc_dev;
  878. #endif
  879. fdt_addr_t addr;
  880. unsigned int val;
  881. struct mmc *mmc;
  882. int ret;
  883. addr = dev_read_addr(dev);
  884. if (addr == FDT_ADDR_T_NONE)
  885. return -EINVAL;
  886. priv->esdhc_regs = (struct fsl_esdhc *)addr;
  887. priv->dev = dev;
  888. val = dev_read_u32_default(dev, "bus-width", -1);
  889. if (val == 8)
  890. priv->bus_width = 8;
  891. else if (val == 4)
  892. priv->bus_width = 4;
  893. else
  894. priv->bus_width = 1;
  895. if (dev_read_bool(dev, "non-removable")) {
  896. priv->non_removable = 1;
  897. } else {
  898. priv->non_removable = 0;
  899. #ifdef CONFIG_DM_GPIO
  900. gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio,
  901. GPIOD_IS_IN);
  902. #endif
  903. }
  904. priv->wp_enable = 1;
  905. #ifdef CONFIG_DM_GPIO
  906. ret = gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio,
  907. GPIOD_IS_IN);
  908. if (ret)
  909. priv->wp_enable = 0;
  910. #endif
  911. priv->vs18_enable = 0;
  912. #ifdef CONFIG_DM_REGULATOR
  913. /*
  914. * If emmc I/O has a fixed voltage at 1.8V, this must be provided,
  915. * otherwise, emmc will work abnormally.
  916. */
  917. ret = device_get_supply_regulator(dev, "vqmmc-supply", &vqmmc_dev);
  918. if (ret) {
  919. dev_dbg(dev, "no vqmmc-supply\n");
  920. } else {
  921. ret = regulator_set_enable(vqmmc_dev, true);
  922. if (ret) {
  923. dev_err(dev, "fail to enable vqmmc-supply\n");
  924. return ret;
  925. }
  926. if (regulator_get_value(vqmmc_dev) == 1800000)
  927. priv->vs18_enable = 1;
  928. }
  929. #endif
  930. /*
  931. * TODO:
  932. * Because lack of clk driver, if SDHC clk is not enabled,
  933. * need to enable it first before this driver is invoked.
  934. *
  935. * we use MXC_ESDHC_CLK to get clk freq.
  936. * If one would like to make this function work,
  937. * the aliases should be provided in dts as this:
  938. *
  939. * aliases {
  940. * mmc0 = &usdhc1;
  941. * mmc1 = &usdhc2;
  942. * mmc2 = &usdhc3;
  943. * mmc3 = &usdhc4;
  944. * };
  945. * Then if your board only supports mmc2 and mmc3, but we can
  946. * correctly get the seq as 2 and 3, then let mxc_get_clock
  947. * work as expected.
  948. */
  949. init_clk_usdhc(dev->seq);
  950. priv->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK + dev->seq);
  951. if (priv->sdhc_clk <= 0) {
  952. dev_err(dev, "Unable to get clk for %s\n", dev->name);
  953. return -EINVAL;
  954. }
  955. ret = fsl_esdhc_init(priv, plat);
  956. if (ret) {
  957. dev_err(dev, "fsl_esdhc_init failure\n");
  958. return ret;
  959. }
  960. mmc = &plat->mmc;
  961. mmc->cfg = &plat->cfg;
  962. mmc->dev = dev;
  963. upriv->mmc = mmc;
  964. return esdhc_init_common(priv, mmc);
  965. }
  966. #if CONFIG_IS_ENABLED(DM_MMC)
  967. static int fsl_esdhc_get_cd(struct udevice *dev)
  968. {
  969. struct fsl_esdhc_priv *priv = dev_get_priv(dev);
  970. return true;
  971. return esdhc_getcd_common(priv);
  972. }
  973. static int fsl_esdhc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
  974. struct mmc_data *data)
  975. {
  976. struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
  977. struct fsl_esdhc_priv *priv = dev_get_priv(dev);
  978. return esdhc_send_cmd_common(priv, &plat->mmc, cmd, data);
  979. }
  980. static int fsl_esdhc_set_ios(struct udevice *dev)
  981. {
  982. struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
  983. struct fsl_esdhc_priv *priv = dev_get_priv(dev);
  984. return esdhc_set_ios_common(priv, &plat->mmc);
  985. }
  986. static const struct dm_mmc_ops fsl_esdhc_ops = {
  987. .get_cd = fsl_esdhc_get_cd,
  988. .send_cmd = fsl_esdhc_send_cmd,
  989. .set_ios = fsl_esdhc_set_ios,
  990. };
  991. #endif
  992. static const struct udevice_id fsl_esdhc_ids[] = {
  993. { .compatible = "fsl,imx6ul-usdhc", },
  994. { .compatible = "fsl,imx6sx-usdhc", },
  995. { .compatible = "fsl,imx6sl-usdhc", },
  996. { .compatible = "fsl,imx6q-usdhc", },
  997. { .compatible = "fsl,imx7d-usdhc", },
  998. { .compatible = "fsl,imx7ulp-usdhc", },
  999. { .compatible = "fsl,esdhc", },
  1000. { /* sentinel */ }
  1001. };
  1002. #if CONFIG_IS_ENABLED(BLK)
  1003. static int fsl_esdhc_bind(struct udevice *dev)
  1004. {
  1005. struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
  1006. return mmc_bind(dev, &plat->mmc, &plat->cfg);
  1007. }
  1008. #endif
  1009. U_BOOT_DRIVER(fsl_esdhc) = {
  1010. .name = "fsl-esdhc-mmc",
  1011. .id = UCLASS_MMC,
  1012. .of_match = fsl_esdhc_ids,
  1013. .ops = &fsl_esdhc_ops,
  1014. #if CONFIG_IS_ENABLED(BLK)
  1015. .bind = fsl_esdhc_bind,
  1016. #endif
  1017. .probe = fsl_esdhc_probe,
  1018. .platdata_auto_alloc_size = sizeof(struct fsl_esdhc_plat),
  1019. .priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv),
  1020. };
  1021. #endif