fsl_esdhc.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  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. uint timeout;
  162. if (data->flags & MMC_DATA_READ) {
  163. blocks = data->blocks;
  164. buffer = data->dest;
  165. while (blocks) {
  166. timeout = PIO_TIMEOUT;
  167. size = data->blocksize;
  168. irqstat = esdhc_read32(&regs->irqstat);
  169. while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BREN)
  170. && --timeout);
  171. if (timeout <= 0) {
  172. printf("\nData Read Failed in PIO Mode.");
  173. return;
  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. timeout = PIO_TIMEOUT;
  190. size = data->blocksize;
  191. irqstat = esdhc_read32(&regs->irqstat);
  192. while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BWEN)
  193. && --timeout);
  194. if (timeout <= 0) {
  195. printf("\nData Write Failed in PIO Mode.");
  196. return;
  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. int div = 1;
  471. #ifdef ARCH_MXC
  472. int pre_div = 1;
  473. #else
  474. int pre_div = 2;
  475. #endif
  476. int ddr_pre_div = mmc->ddr_mode ? 2 : 1;
  477. struct fsl_esdhc *regs = priv->esdhc_regs;
  478. int sdhc_clk = priv->sdhc_clk;
  479. uint clk;
  480. if (clock < mmc->cfg->f_min)
  481. clock = mmc->cfg->f_min;
  482. while (sdhc_clk / (16 * pre_div * ddr_pre_div) > clock && pre_div < 256)
  483. pre_div *= 2;
  484. while (sdhc_clk / (div * pre_div * ddr_pre_div) > clock && div < 16)
  485. div++;
  486. pre_div >>= 1;
  487. div -= 1;
  488. clk = (pre_div << 8) | (div << 4);
  489. #ifdef CONFIG_FSL_USDHC
  490. esdhc_clrbits32(&regs->vendorspec, VENDORSPEC_CKEN);
  491. #else
  492. esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
  493. #endif
  494. esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
  495. udelay(10000);
  496. #ifdef CONFIG_FSL_USDHC
  497. esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN | VENDORSPEC_CKEN);
  498. #else
  499. esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_CKEN);
  500. #endif
  501. }
  502. #ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
  503. static void esdhc_clock_control(struct fsl_esdhc_priv *priv, bool enable)
  504. {
  505. struct fsl_esdhc *regs = priv->esdhc_regs;
  506. u32 value;
  507. u32 time_out;
  508. value = esdhc_read32(&regs->sysctl);
  509. if (enable)
  510. value |= SYSCTL_CKEN;
  511. else
  512. value &= ~SYSCTL_CKEN;
  513. esdhc_write32(&regs->sysctl, value);
  514. time_out = 20;
  515. value = PRSSTAT_SDSTB;
  516. while (!(esdhc_read32(&regs->prsstat) & value)) {
  517. if (time_out == 0) {
  518. printf("fsl_esdhc: Internal clock never stabilised.\n");
  519. break;
  520. }
  521. time_out--;
  522. mdelay(1);
  523. }
  524. }
  525. #endif
  526. static int esdhc_set_ios_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
  527. {
  528. struct fsl_esdhc *regs = priv->esdhc_regs;
  529. #ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
  530. /* Select to use peripheral clock */
  531. esdhc_clock_control(priv, false);
  532. esdhc_setbits32(&regs->scr, ESDHCCTL_PCS);
  533. esdhc_clock_control(priv, true);
  534. #endif
  535. /* Set the clock speed */
  536. set_sysctl(priv, mmc, mmc->clock);
  537. /* Set the bus width */
  538. esdhc_clrbits32(&regs->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
  539. if (mmc->bus_width == 4)
  540. esdhc_setbits32(&regs->proctl, PROCTL_DTW_4);
  541. else if (mmc->bus_width == 8)
  542. esdhc_setbits32(&regs->proctl, PROCTL_DTW_8);
  543. return 0;
  544. }
  545. static int esdhc_init_common(struct fsl_esdhc_priv *priv, struct mmc *mmc)
  546. {
  547. struct fsl_esdhc *regs = priv->esdhc_regs;
  548. ulong start;
  549. /* Reset the entire host controller */
  550. esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
  551. /* Wait until the controller is available */
  552. start = get_timer(0);
  553. while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA)) {
  554. if (get_timer(start) > 1000)
  555. return -ETIMEDOUT;
  556. }
  557. #if defined(CONFIG_FSL_USDHC)
  558. /* RSTA doesn't reset MMC_BOOT register, so manually reset it */
  559. esdhc_write32(&regs->mmcboot, 0x0);
  560. /* Reset MIX_CTRL and CLK_TUNE_CTRL_STATUS regs to 0 */
  561. esdhc_write32(&regs->mixctrl, 0x0);
  562. esdhc_write32(&regs->clktunectrlstatus, 0x0);
  563. /* Put VEND_SPEC to default value */
  564. esdhc_write32(&regs->vendorspec, VENDORSPEC_INIT);
  565. /* Disable DLL_CTRL delay line */
  566. esdhc_write32(&regs->dllctrl, 0x0);
  567. #endif
  568. #ifndef ARCH_MXC
  569. /* Enable cache snooping */
  570. esdhc_write32(&regs->scr, 0x00000040);
  571. #endif
  572. #ifndef CONFIG_FSL_USDHC
  573. esdhc_setbits32(&regs->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
  574. #else
  575. esdhc_setbits32(&regs->vendorspec, VENDORSPEC_HCKEN | VENDORSPEC_IPGEN);
  576. #endif
  577. /* Set the initial clock speed */
  578. mmc_set_clock(mmc, 400000);
  579. /* Disable the BRR and BWR bits in IRQSTAT */
  580. esdhc_clrbits32(&regs->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR);
  581. /* Put the PROCTL reg back to the default */
  582. esdhc_write32(&regs->proctl, PROCTL_INIT);
  583. /* Set timout to the maximum value */
  584. esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
  585. if (priv->vs18_enable)
  586. esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
  587. return 0;
  588. }
  589. static int esdhc_getcd_common(struct fsl_esdhc_priv *priv)
  590. {
  591. struct fsl_esdhc *regs = priv->esdhc_regs;
  592. int timeout = 1000;
  593. #ifdef CONFIG_ESDHC_DETECT_QUIRK
  594. if (CONFIG_ESDHC_DETECT_QUIRK)
  595. return 1;
  596. #endif
  597. #if CONFIG_IS_ENABLED(DM_MMC)
  598. if (priv->non_removable)
  599. return 1;
  600. #ifdef CONFIG_DM_GPIO
  601. if (dm_gpio_is_valid(&priv->cd_gpio))
  602. return dm_gpio_get_value(&priv->cd_gpio);
  603. #endif
  604. #endif
  605. while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
  606. udelay(1000);
  607. return timeout > 0;
  608. }
  609. static int esdhc_reset(struct fsl_esdhc *regs)
  610. {
  611. ulong start;
  612. /* reset the controller */
  613. esdhc_setbits32(&regs->sysctl, SYSCTL_RSTA);
  614. /* hardware clears the bit when it is done */
  615. start = get_timer(0);
  616. while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA)) {
  617. if (get_timer(start) > 100) {
  618. printf("MMC/SD: Reset never completed.\n");
  619. return -ETIMEDOUT;
  620. }
  621. }
  622. return 0;
  623. }
  624. #if !CONFIG_IS_ENABLED(DM_MMC)
  625. static int esdhc_getcd(struct mmc *mmc)
  626. {
  627. struct fsl_esdhc_priv *priv = mmc->priv;
  628. return esdhc_getcd_common(priv);
  629. }
  630. static int esdhc_init(struct mmc *mmc)
  631. {
  632. struct fsl_esdhc_priv *priv = mmc->priv;
  633. return esdhc_init_common(priv, mmc);
  634. }
  635. static int esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
  636. struct mmc_data *data)
  637. {
  638. struct fsl_esdhc_priv *priv = mmc->priv;
  639. return esdhc_send_cmd_common(priv, mmc, cmd, data);
  640. }
  641. static int esdhc_set_ios(struct mmc *mmc)
  642. {
  643. struct fsl_esdhc_priv *priv = mmc->priv;
  644. return esdhc_set_ios_common(priv, mmc);
  645. }
  646. static const struct mmc_ops esdhc_ops = {
  647. .getcd = esdhc_getcd,
  648. .init = esdhc_init,
  649. .send_cmd = esdhc_send_cmd,
  650. .set_ios = esdhc_set_ios,
  651. };
  652. #endif
  653. static int fsl_esdhc_init(struct fsl_esdhc_priv *priv,
  654. struct fsl_esdhc_plat *plat)
  655. {
  656. struct mmc_config *cfg;
  657. struct fsl_esdhc *regs;
  658. u32 caps, voltage_caps;
  659. int ret;
  660. if (!priv)
  661. return -EINVAL;
  662. regs = priv->esdhc_regs;
  663. /* First reset the eSDHC controller */
  664. ret = esdhc_reset(regs);
  665. if (ret)
  666. return ret;
  667. #ifndef CONFIG_FSL_USDHC
  668. esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN
  669. | SYSCTL_IPGEN | SYSCTL_CKEN);
  670. #else
  671. esdhc_setbits32(&regs->vendorspec, VENDORSPEC_PEREN |
  672. VENDORSPEC_HCKEN | VENDORSPEC_IPGEN | VENDORSPEC_CKEN);
  673. #endif
  674. if (priv->vs18_enable)
  675. esdhc_setbits32(&regs->vendorspec, ESDHC_VENDORSPEC_VSELECT);
  676. writel(SDHCI_IRQ_EN_BITS, &regs->irqstaten);
  677. cfg = &plat->cfg;
  678. #ifndef CONFIG_DM_MMC
  679. memset(cfg, '\0', sizeof(*cfg));
  680. #endif
  681. voltage_caps = 0;
  682. caps = esdhc_read32(&regs->hostcapblt);
  683. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC135
  684. caps = caps & ~(ESDHC_HOSTCAPBLT_SRS |
  685. ESDHC_HOSTCAPBLT_VS18 | ESDHC_HOSTCAPBLT_VS30);
  686. #endif
  687. /* T4240 host controller capabilities register should have VS33 bit */
  688. #ifdef CONFIG_SYS_FSL_MMC_HAS_CAPBLT_VS33
  689. caps = caps | ESDHC_HOSTCAPBLT_VS33;
  690. #endif
  691. if (caps & ESDHC_HOSTCAPBLT_VS18)
  692. voltage_caps |= MMC_VDD_165_195;
  693. if (caps & ESDHC_HOSTCAPBLT_VS30)
  694. voltage_caps |= MMC_VDD_29_30 | MMC_VDD_30_31;
  695. if (caps & ESDHC_HOSTCAPBLT_VS33)
  696. voltage_caps |= MMC_VDD_32_33 | MMC_VDD_33_34;
  697. cfg->name = "FSL_SDHC";
  698. #if !CONFIG_IS_ENABLED(DM_MMC)
  699. cfg->ops = &esdhc_ops;
  700. #endif
  701. #ifdef CONFIG_SYS_SD_VOLTAGE
  702. cfg->voltages = CONFIG_SYS_SD_VOLTAGE;
  703. #else
  704. cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
  705. #endif
  706. if ((cfg->voltages & voltage_caps) == 0) {
  707. printf("voltage not supported by controller\n");
  708. return -1;
  709. }
  710. if (priv->bus_width == 8)
  711. cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
  712. else if (priv->bus_width == 4)
  713. cfg->host_caps = MMC_MODE_4BIT;
  714. cfg->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT;
  715. #ifdef CONFIG_SYS_FSL_ESDHC_HAS_DDR_MODE
  716. cfg->host_caps |= MMC_MODE_DDR_52MHz;
  717. #endif
  718. if (priv->bus_width > 0) {
  719. if (priv->bus_width < 8)
  720. cfg->host_caps &= ~MMC_MODE_8BIT;
  721. if (priv->bus_width < 4)
  722. cfg->host_caps &= ~MMC_MODE_4BIT;
  723. }
  724. if (caps & ESDHC_HOSTCAPBLT_HSS)
  725. cfg->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
  726. #ifdef CONFIG_ESDHC_DETECT_8_BIT_QUIRK
  727. if (CONFIG_ESDHC_DETECT_8_BIT_QUIRK)
  728. cfg->host_caps &= ~MMC_MODE_8BIT;
  729. #endif
  730. cfg->f_min = 400000;
  731. cfg->f_max = min(priv->sdhc_clk, (u32)52000000);
  732. cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
  733. return 0;
  734. }
  735. #if !CONFIG_IS_ENABLED(DM_MMC)
  736. static int fsl_esdhc_cfg_to_priv(struct fsl_esdhc_cfg *cfg,
  737. struct fsl_esdhc_priv *priv)
  738. {
  739. if (!cfg || !priv)
  740. return -EINVAL;
  741. priv->esdhc_regs = (struct fsl_esdhc *)(unsigned long)(cfg->esdhc_base);
  742. priv->bus_width = cfg->max_bus_width;
  743. priv->sdhc_clk = cfg->sdhc_clk;
  744. priv->wp_enable = cfg->wp_enable;
  745. priv->vs18_enable = cfg->vs18_enable;
  746. return 0;
  747. };
  748. int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
  749. {
  750. struct fsl_esdhc_plat *plat;
  751. struct fsl_esdhc_priv *priv;
  752. struct mmc *mmc;
  753. int ret;
  754. if (!cfg)
  755. return -EINVAL;
  756. priv = calloc(sizeof(struct fsl_esdhc_priv), 1);
  757. if (!priv)
  758. return -ENOMEM;
  759. plat = calloc(sizeof(struct fsl_esdhc_plat), 1);
  760. if (!plat) {
  761. free(priv);
  762. return -ENOMEM;
  763. }
  764. ret = fsl_esdhc_cfg_to_priv(cfg, priv);
  765. if (ret) {
  766. debug("%s xlate failure\n", __func__);
  767. free(plat);
  768. free(priv);
  769. return ret;
  770. }
  771. ret = fsl_esdhc_init(priv, plat);
  772. if (ret) {
  773. debug("%s init failure\n", __func__);
  774. free(plat);
  775. free(priv);
  776. return ret;
  777. }
  778. mmc = mmc_create(&plat->cfg, priv);
  779. if (!mmc)
  780. return -EIO;
  781. priv->mmc = mmc;
  782. return 0;
  783. }
  784. int fsl_esdhc_mmc_init(bd_t *bis)
  785. {
  786. struct fsl_esdhc_cfg *cfg;
  787. cfg = calloc(sizeof(struct fsl_esdhc_cfg), 1);
  788. cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR;
  789. cfg->sdhc_clk = gd->arch.sdhc_clk;
  790. return fsl_esdhc_initialize(bis, cfg);
  791. }
  792. #endif
  793. #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
  794. void mmc_adapter_card_type_ident(void)
  795. {
  796. u8 card_id;
  797. u8 value;
  798. card_id = QIXIS_READ(present) & QIXIS_SDID_MASK;
  799. gd->arch.sdhc_adapter = card_id;
  800. switch (card_id) {
  801. case QIXIS_ESDHC_ADAPTER_TYPE_EMMC45:
  802. value = QIXIS_READ(brdcfg[5]);
  803. value |= (QIXIS_DAT4 | QIXIS_DAT5_6_7);
  804. QIXIS_WRITE(brdcfg[5], value);
  805. break;
  806. case QIXIS_ESDHC_ADAPTER_TYPE_SDMMC_LEGACY:
  807. value = QIXIS_READ(pwr_ctl[1]);
  808. value |= QIXIS_EVDD_BY_SDHC_VS;
  809. QIXIS_WRITE(pwr_ctl[1], value);
  810. break;
  811. case QIXIS_ESDHC_ADAPTER_TYPE_EMMC44:
  812. value = QIXIS_READ(brdcfg[5]);
  813. value |= (QIXIS_SDCLKIN | QIXIS_SDCLKOUT);
  814. QIXIS_WRITE(brdcfg[5], value);
  815. break;
  816. case QIXIS_ESDHC_ADAPTER_TYPE_RSV:
  817. break;
  818. case QIXIS_ESDHC_ADAPTER_TYPE_MMC:
  819. break;
  820. case QIXIS_ESDHC_ADAPTER_TYPE_SD:
  821. break;
  822. case QIXIS_ESDHC_NO_ADAPTER:
  823. break;
  824. default:
  825. break;
  826. }
  827. }
  828. #endif
  829. #ifdef CONFIG_OF_LIBFDT
  830. __weak int esdhc_status_fixup(void *blob, const char *compat)
  831. {
  832. #ifdef CONFIG_FSL_ESDHC_PIN_MUX
  833. if (!hwconfig("esdhc")) {
  834. do_fixup_by_compat(blob, compat, "status", "disabled",
  835. sizeof("disabled"), 1);
  836. return 1;
  837. }
  838. #endif
  839. return 0;
  840. }
  841. void fdt_fixup_esdhc(void *blob, bd_t *bd)
  842. {
  843. const char *compat = "fsl,esdhc";
  844. if (esdhc_status_fixup(blob, compat))
  845. return;
  846. #ifdef CONFIG_FSL_ESDHC_USE_PERIPHERAL_CLK
  847. do_fixup_by_compat_u32(blob, compat, "peripheral-frequency",
  848. gd->arch.sdhc_clk, 1);
  849. #else
  850. do_fixup_by_compat_u32(blob, compat, "clock-frequency",
  851. gd->arch.sdhc_clk, 1);
  852. #endif
  853. #ifdef CONFIG_FSL_ESDHC_ADAPTER_IDENT
  854. do_fixup_by_compat_u32(blob, compat, "adapter-type",
  855. (u32)(gd->arch.sdhc_adapter), 1);
  856. #endif
  857. }
  858. #endif
  859. #if CONFIG_IS_ENABLED(DM_MMC)
  860. #include <asm/arch/clock.h>
  861. __weak void init_clk_usdhc(u32 index)
  862. {
  863. }
  864. static int fsl_esdhc_probe(struct udevice *dev)
  865. {
  866. struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
  867. struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
  868. struct fsl_esdhc_priv *priv = dev_get_priv(dev);
  869. #ifdef CONFIG_DM_REGULATOR
  870. struct udevice *vqmmc_dev;
  871. #endif
  872. fdt_addr_t addr;
  873. unsigned int val;
  874. struct mmc *mmc;
  875. int ret;
  876. addr = dev_read_addr(dev);
  877. if (addr == FDT_ADDR_T_NONE)
  878. return -EINVAL;
  879. priv->esdhc_regs = (struct fsl_esdhc *)addr;
  880. priv->dev = dev;
  881. val = dev_read_u32_default(dev, "bus-width", -1);
  882. if (val == 8)
  883. priv->bus_width = 8;
  884. else if (val == 4)
  885. priv->bus_width = 4;
  886. else
  887. priv->bus_width = 1;
  888. if (dev_read_bool(dev, "non-removable")) {
  889. priv->non_removable = 1;
  890. } else {
  891. priv->non_removable = 0;
  892. #ifdef CONFIG_DM_GPIO
  893. gpio_request_by_name(dev, "cd-gpios", 0, &priv->cd_gpio,
  894. GPIOD_IS_IN);
  895. #endif
  896. }
  897. priv->wp_enable = 1;
  898. #ifdef CONFIG_DM_GPIO
  899. ret = gpio_request_by_name(dev, "wp-gpios", 0, &priv->wp_gpio,
  900. GPIOD_IS_IN);
  901. if (ret)
  902. priv->wp_enable = 0;
  903. #endif
  904. priv->vs18_enable = 0;
  905. #ifdef CONFIG_DM_REGULATOR
  906. /*
  907. * If emmc I/O has a fixed voltage at 1.8V, this must be provided,
  908. * otherwise, emmc will work abnormally.
  909. */
  910. ret = device_get_supply_regulator(dev, "vqmmc-supply", &vqmmc_dev);
  911. if (ret) {
  912. dev_dbg(dev, "no vqmmc-supply\n");
  913. } else {
  914. ret = regulator_set_enable(vqmmc_dev, true);
  915. if (ret) {
  916. dev_err(dev, "fail to enable vqmmc-supply\n");
  917. return ret;
  918. }
  919. if (regulator_get_value(vqmmc_dev) == 1800000)
  920. priv->vs18_enable = 1;
  921. }
  922. #endif
  923. /*
  924. * TODO:
  925. * Because lack of clk driver, if SDHC clk is not enabled,
  926. * need to enable it first before this driver is invoked.
  927. *
  928. * we use MXC_ESDHC_CLK to get clk freq.
  929. * If one would like to make this function work,
  930. * the aliases should be provided in dts as this:
  931. *
  932. * aliases {
  933. * mmc0 = &usdhc1;
  934. * mmc1 = &usdhc2;
  935. * mmc2 = &usdhc3;
  936. * mmc3 = &usdhc4;
  937. * };
  938. * Then if your board only supports mmc2 and mmc3, but we can
  939. * correctly get the seq as 2 and 3, then let mxc_get_clock
  940. * work as expected.
  941. */
  942. init_clk_usdhc(dev->seq);
  943. priv->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK + dev->seq);
  944. if (priv->sdhc_clk <= 0) {
  945. dev_err(dev, "Unable to get clk for %s\n", dev->name);
  946. return -EINVAL;
  947. }
  948. ret = fsl_esdhc_init(priv, plat);
  949. if (ret) {
  950. dev_err(dev, "fsl_esdhc_init failure\n");
  951. return ret;
  952. }
  953. mmc = &plat->mmc;
  954. mmc->cfg = &plat->cfg;
  955. mmc->dev = dev;
  956. upriv->mmc = mmc;
  957. return esdhc_init_common(priv, mmc);
  958. }
  959. #if CONFIG_IS_ENABLED(DM_MMC)
  960. static int fsl_esdhc_get_cd(struct udevice *dev)
  961. {
  962. struct fsl_esdhc_priv *priv = dev_get_priv(dev);
  963. return true;
  964. return esdhc_getcd_common(priv);
  965. }
  966. static int fsl_esdhc_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
  967. struct mmc_data *data)
  968. {
  969. struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
  970. struct fsl_esdhc_priv *priv = dev_get_priv(dev);
  971. return esdhc_send_cmd_common(priv, &plat->mmc, cmd, data);
  972. }
  973. static int fsl_esdhc_set_ios(struct udevice *dev)
  974. {
  975. struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
  976. struct fsl_esdhc_priv *priv = dev_get_priv(dev);
  977. return esdhc_set_ios_common(priv, &plat->mmc);
  978. }
  979. static const struct dm_mmc_ops fsl_esdhc_ops = {
  980. .get_cd = fsl_esdhc_get_cd,
  981. .send_cmd = fsl_esdhc_send_cmd,
  982. .set_ios = fsl_esdhc_set_ios,
  983. };
  984. #endif
  985. static const struct udevice_id fsl_esdhc_ids[] = {
  986. { .compatible = "fsl,imx6ul-usdhc", },
  987. { .compatible = "fsl,imx6sx-usdhc", },
  988. { .compatible = "fsl,imx6sl-usdhc", },
  989. { .compatible = "fsl,imx6q-usdhc", },
  990. { .compatible = "fsl,imx7d-usdhc", },
  991. { .compatible = "fsl,imx7ulp-usdhc", },
  992. { .compatible = "fsl,esdhc", },
  993. { /* sentinel */ }
  994. };
  995. #if CONFIG_IS_ENABLED(BLK)
  996. static int fsl_esdhc_bind(struct udevice *dev)
  997. {
  998. struct fsl_esdhc_plat *plat = dev_get_platdata(dev);
  999. return mmc_bind(dev, &plat->mmc, &plat->cfg);
  1000. }
  1001. #endif
  1002. U_BOOT_DRIVER(fsl_esdhc) = {
  1003. .name = "fsl-esdhc-mmc",
  1004. .id = UCLASS_MMC,
  1005. .of_match = fsl_esdhc_ids,
  1006. .ops = &fsl_esdhc_ops,
  1007. #if CONFIG_IS_ENABLED(BLK)
  1008. .bind = fsl_esdhc_bind,
  1009. #endif
  1010. .probe = fsl_esdhc_probe,
  1011. .platdata_auto_alloc_size = sizeof(struct fsl_esdhc_plat),
  1012. .priv_auto_alloc_size = sizeof(struct fsl_esdhc_priv),
  1013. };
  1014. #endif