fsl_esdhc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <config.h>
  28. #include <common.h>
  29. #include <command.h>
  30. #include <hwconfig.h>
  31. #include <mmc.h>
  32. #include <part.h>
  33. #include <malloc.h>
  34. #include <mmc.h>
  35. #include <fsl_esdhc.h>
  36. #include <fdt_support.h>
  37. #include <asm/io.h>
  38. DECLARE_GLOBAL_DATA_PTR;
  39. struct fsl_esdhc {
  40. uint dsaddr;
  41. uint blkattr;
  42. uint cmdarg;
  43. uint xfertyp;
  44. uint cmdrsp0;
  45. uint cmdrsp1;
  46. uint cmdrsp2;
  47. uint cmdrsp3;
  48. uint datport;
  49. uint prsstat;
  50. uint proctl;
  51. uint sysctl;
  52. uint irqstat;
  53. uint irqstaten;
  54. uint irqsigen;
  55. uint autoc12err;
  56. uint hostcapblt;
  57. uint wml;
  58. uint mixctrl;
  59. char reserved1[4];
  60. uint fevt;
  61. char reserved2[168];
  62. uint hostver;
  63. char reserved3[780];
  64. uint scr;
  65. };
  66. /* Return the XFERTYP flags for a given command and data packet */
  67. static uint esdhc_xfertyp(struct mmc_cmd *cmd, struct mmc_data *data)
  68. {
  69. uint xfertyp = 0;
  70. if (data) {
  71. xfertyp |= XFERTYP_DPSEL;
  72. #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
  73. xfertyp |= XFERTYP_DMAEN;
  74. #endif
  75. if (data->blocks > 1) {
  76. xfertyp |= XFERTYP_MSBSEL;
  77. xfertyp |= XFERTYP_BCEN;
  78. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
  79. xfertyp |= XFERTYP_AC12EN;
  80. #endif
  81. }
  82. if (data->flags & MMC_DATA_READ)
  83. xfertyp |= XFERTYP_DTDSEL;
  84. }
  85. if (cmd->resp_type & MMC_RSP_CRC)
  86. xfertyp |= XFERTYP_CCCEN;
  87. if (cmd->resp_type & MMC_RSP_OPCODE)
  88. xfertyp |= XFERTYP_CICEN;
  89. if (cmd->resp_type & MMC_RSP_136)
  90. xfertyp |= XFERTYP_RSPTYP_136;
  91. else if (cmd->resp_type & MMC_RSP_BUSY)
  92. xfertyp |= XFERTYP_RSPTYP_48_BUSY;
  93. else if (cmd->resp_type & MMC_RSP_PRESENT)
  94. xfertyp |= XFERTYP_RSPTYP_48;
  95. #ifdef CONFIG_MX53
  96. if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
  97. xfertyp |= XFERTYP_CMDTYP_ABORT;
  98. #endif
  99. return XFERTYP_CMD(cmd->cmdidx) | xfertyp;
  100. }
  101. #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
  102. /*
  103. * PIO Read/Write Mode reduce the performace as DMA is not used in this mode.
  104. */
  105. static void
  106. esdhc_pio_read_write(struct mmc *mmc, struct mmc_data *data)
  107. {
  108. struct fsl_esdhc_cfg *cfg = mmc->priv;
  109. struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
  110. uint blocks;
  111. char *buffer;
  112. uint databuf;
  113. uint size;
  114. uint irqstat;
  115. uint timeout;
  116. if (data->flags & MMC_DATA_READ) {
  117. blocks = data->blocks;
  118. buffer = data->dest;
  119. while (blocks) {
  120. timeout = PIO_TIMEOUT;
  121. size = data->blocksize;
  122. irqstat = esdhc_read32(&regs->irqstat);
  123. while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BREN)
  124. && --timeout);
  125. if (timeout <= 0) {
  126. printf("\nData Read Failed in PIO Mode.");
  127. return;
  128. }
  129. while (size && (!(irqstat & IRQSTAT_TC))) {
  130. udelay(100); /* Wait before last byte transfer complete */
  131. irqstat = esdhc_read32(&regs->irqstat);
  132. databuf = in_le32(&regs->datport);
  133. *((uint *)buffer) = databuf;
  134. buffer += 4;
  135. size -= 4;
  136. }
  137. blocks--;
  138. }
  139. } else {
  140. blocks = data->blocks;
  141. buffer = (char *)data->src;
  142. while (blocks) {
  143. timeout = PIO_TIMEOUT;
  144. size = data->blocksize;
  145. irqstat = esdhc_read32(&regs->irqstat);
  146. while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_BWEN)
  147. && --timeout);
  148. if (timeout <= 0) {
  149. printf("\nData Write Failed in PIO Mode.");
  150. return;
  151. }
  152. while (size && (!(irqstat & IRQSTAT_TC))) {
  153. udelay(100); /* Wait before last byte transfer complete */
  154. databuf = *((uint *)buffer);
  155. buffer += 4;
  156. size -= 4;
  157. irqstat = esdhc_read32(&regs->irqstat);
  158. out_le32(&regs->datport, databuf);
  159. }
  160. blocks--;
  161. }
  162. }
  163. }
  164. #endif
  165. static int esdhc_setup_data(struct mmc *mmc, struct mmc_data *data)
  166. {
  167. int timeout;
  168. struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
  169. struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
  170. #ifndef CONFIG_SYS_FSL_ESDHC_USE_PIO
  171. uint wml_value;
  172. wml_value = data->blocksize/4;
  173. if (data->flags & MMC_DATA_READ) {
  174. if (wml_value > WML_RD_WML_MAX)
  175. wml_value = WML_RD_WML_MAX_VAL;
  176. esdhc_clrsetbits32(&regs->wml, WML_RD_WML_MASK, wml_value);
  177. esdhc_write32(&regs->dsaddr, (u32)data->dest);
  178. } else {
  179. flush_dcache_range((ulong)data->src,
  180. (ulong)data->src+data->blocks
  181. *data->blocksize);
  182. if (wml_value > WML_WR_WML_MAX)
  183. wml_value = WML_WR_WML_MAX_VAL;
  184. if ((esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL) == 0) {
  185. printf("\nThe SD card is locked. Can not write to a locked card.\n\n");
  186. return TIMEOUT;
  187. }
  188. esdhc_clrsetbits32(&regs->wml, WML_WR_WML_MASK,
  189. wml_value << 16);
  190. esdhc_write32(&regs->dsaddr, (u32)data->src);
  191. }
  192. #else /* CONFIG_SYS_FSL_ESDHC_USE_PIO */
  193. if (!(data->flags & MMC_DATA_READ)) {
  194. if ((esdhc_read32(&regs->prsstat) & PRSSTAT_WPSPL) == 0) {
  195. printf("\nThe SD card is locked. "
  196. "Can not write to a locked card.\n\n");
  197. return TIMEOUT;
  198. }
  199. esdhc_write32(&regs->dsaddr, (u32)data->src);
  200. } else
  201. esdhc_write32(&regs->dsaddr, (u32)data->dest);
  202. #endif /* CONFIG_SYS_FSL_ESDHC_USE_PIO */
  203. esdhc_write32(&regs->blkattr, data->blocks << 16 | data->blocksize);
  204. /* Calculate the timeout period for data transactions */
  205. /*
  206. * 1)Timeout period = (2^(timeout+13)) SD Clock cycles
  207. * 2)Timeout period should be minimum 0.250sec as per SD Card spec
  208. * So, Number of SD Clock cycles for 0.25sec should be minimum
  209. * (SD Clock/sec * 0.25 sec) SD Clock cycles
  210. * = (mmc->tran_speed * 1/4) SD Clock cycles
  211. * As 1) >= 2)
  212. * => (2^(timeout+13)) >= mmc->tran_speed * 1/4
  213. * Taking log2 both the sides
  214. * => timeout + 13 >= log2(mmc->tran_speed/4)
  215. * Rounding up to next power of 2
  216. * => timeout + 13 = log2(mmc->tran_speed/4) + 1
  217. * => timeout + 13 = fls(mmc->tran_speed/4)
  218. */
  219. timeout = fls(mmc->tran_speed/4);
  220. timeout -= 13;
  221. if (timeout > 14)
  222. timeout = 14;
  223. if (timeout < 0)
  224. timeout = 0;
  225. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC_A001
  226. if ((timeout == 4) || (timeout == 8) || (timeout == 12))
  227. timeout++;
  228. #endif
  229. esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, timeout << 16);
  230. return 0;
  231. }
  232. static void check_and_invalidate_dcache_range
  233. (struct mmc_cmd *cmd,
  234. struct mmc_data *data) {
  235. unsigned start = (unsigned)data->dest ;
  236. unsigned size = roundup(ARCH_DMA_MINALIGN,
  237. data->blocks*data->blocksize);
  238. unsigned end = start+size ;
  239. invalidate_dcache_range(start, end);
  240. }
  241. /*
  242. * Sends a command out on the bus. Takes the mmc pointer,
  243. * a command pointer, and an optional data pointer.
  244. */
  245. static int
  246. esdhc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd, struct mmc_data *data)
  247. {
  248. uint xfertyp;
  249. uint irqstat;
  250. struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
  251. volatile struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
  252. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC111
  253. if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
  254. return 0;
  255. #endif
  256. esdhc_write32(&regs->irqstat, -1);
  257. sync();
  258. /* Wait for the bus to be idle */
  259. while ((esdhc_read32(&regs->prsstat) & PRSSTAT_CICHB) ||
  260. (esdhc_read32(&regs->prsstat) & PRSSTAT_CIDHB))
  261. ;
  262. while (esdhc_read32(&regs->prsstat) & PRSSTAT_DLA)
  263. ;
  264. /* Wait at least 8 SD clock cycles before the next command */
  265. /*
  266. * Note: This is way more than 8 cycles, but 1ms seems to
  267. * resolve timing issues with some cards
  268. */
  269. udelay(1000);
  270. /* Set up for a data transfer if we have one */
  271. if (data) {
  272. int err;
  273. err = esdhc_setup_data(mmc, data);
  274. if(err)
  275. return err;
  276. }
  277. /* Figure out the transfer arguments */
  278. xfertyp = esdhc_xfertyp(cmd, data);
  279. /* Send the command */
  280. esdhc_write32(&regs->cmdarg, cmd->cmdarg);
  281. #if defined(CONFIG_FSL_USDHC)
  282. esdhc_write32(&regs->mixctrl,
  283. (esdhc_read32(&regs->mixctrl) & 0xFFFFFF80) | (xfertyp & 0x7F));
  284. esdhc_write32(&regs->xfertyp, xfertyp & 0xFFFF0000);
  285. #else
  286. esdhc_write32(&regs->xfertyp, xfertyp);
  287. #endif
  288. /* Mask all irqs */
  289. esdhc_write32(&regs->irqsigen, 0);
  290. /* Wait for the command to complete */
  291. while (!(esdhc_read32(&regs->irqstat) & (IRQSTAT_CC | IRQSTAT_CTOE)))
  292. ;
  293. if (data && (data->flags & MMC_DATA_READ))
  294. check_and_invalidate_dcache_range(cmd, data);
  295. irqstat = esdhc_read32(&regs->irqstat);
  296. esdhc_write32(&regs->irqstat, irqstat);
  297. /* Reset CMD and DATA portions on error */
  298. if (irqstat & (CMD_ERR | IRQSTAT_CTOE)) {
  299. esdhc_write32(&regs->sysctl, esdhc_read32(&regs->sysctl) |
  300. SYSCTL_RSTC);
  301. while (esdhc_read32(&regs->sysctl) & SYSCTL_RSTC)
  302. ;
  303. if (data) {
  304. esdhc_write32(&regs->sysctl,
  305. esdhc_read32(&regs->sysctl) |
  306. SYSCTL_RSTD);
  307. while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTD))
  308. ;
  309. }
  310. }
  311. if (irqstat & CMD_ERR)
  312. return COMM_ERR;
  313. if (irqstat & IRQSTAT_CTOE)
  314. return TIMEOUT;
  315. /* Workaround for ESDHC errata ENGcm03648 */
  316. if (!data && (cmd->resp_type & MMC_RSP_BUSY)) {
  317. int timeout = 2500;
  318. /* Poll on DATA0 line for cmd with busy signal for 250 ms */
  319. while (timeout > 0 && !(esdhc_read32(&regs->prsstat) &
  320. PRSSTAT_DAT0)) {
  321. udelay(100);
  322. timeout--;
  323. }
  324. if (timeout <= 0) {
  325. printf("Timeout waiting for DAT0 to go high!\n");
  326. return TIMEOUT;
  327. }
  328. }
  329. /* Copy the response to the response buffer */
  330. if (cmd->resp_type & MMC_RSP_136) {
  331. u32 cmdrsp3, cmdrsp2, cmdrsp1, cmdrsp0;
  332. cmdrsp3 = esdhc_read32(&regs->cmdrsp3);
  333. cmdrsp2 = esdhc_read32(&regs->cmdrsp2);
  334. cmdrsp1 = esdhc_read32(&regs->cmdrsp1);
  335. cmdrsp0 = esdhc_read32(&regs->cmdrsp0);
  336. cmd->response[0] = (cmdrsp3 << 8) | (cmdrsp2 >> 24);
  337. cmd->response[1] = (cmdrsp2 << 8) | (cmdrsp1 >> 24);
  338. cmd->response[2] = (cmdrsp1 << 8) | (cmdrsp0 >> 24);
  339. cmd->response[3] = (cmdrsp0 << 8);
  340. } else
  341. cmd->response[0] = esdhc_read32(&regs->cmdrsp0);
  342. /* Wait until all of the blocks are transferred */
  343. if (data) {
  344. #ifdef CONFIG_SYS_FSL_ESDHC_USE_PIO
  345. esdhc_pio_read_write(mmc, data);
  346. #else
  347. do {
  348. irqstat = esdhc_read32(&regs->irqstat);
  349. if (irqstat & IRQSTAT_DTOE)
  350. return TIMEOUT;
  351. if (irqstat & DATA_ERR)
  352. return COMM_ERR;
  353. } while (!(irqstat & IRQSTAT_TC) &&
  354. (esdhc_read32(&regs->prsstat) & PRSSTAT_DLA));
  355. #endif
  356. }
  357. esdhc_write32(&regs->irqstat, -1);
  358. return 0;
  359. }
  360. static void set_sysctl(struct mmc *mmc, uint clock)
  361. {
  362. int div, pre_div;
  363. struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
  364. volatile struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
  365. int sdhc_clk = cfg->sdhc_clk;
  366. uint clk;
  367. if (clock < mmc->f_min)
  368. clock = mmc->f_min;
  369. if (sdhc_clk / 16 > clock) {
  370. for (pre_div = 2; pre_div < 256; pre_div *= 2)
  371. if ((sdhc_clk / pre_div) <= (clock * 16))
  372. break;
  373. } else
  374. pre_div = 2;
  375. for (div = 1; div <= 16; div++)
  376. if ((sdhc_clk / (div * pre_div)) <= clock)
  377. break;
  378. pre_div >>= 1;
  379. div -= 1;
  380. clk = (pre_div << 8) | (div << 4);
  381. esdhc_clrbits32(&regs->sysctl, SYSCTL_CKEN);
  382. esdhc_clrsetbits32(&regs->sysctl, SYSCTL_CLOCK_MASK, clk);
  383. udelay(10000);
  384. clk = SYSCTL_PEREN | SYSCTL_CKEN;
  385. esdhc_setbits32(&regs->sysctl, clk);
  386. }
  387. static void esdhc_set_ios(struct mmc *mmc)
  388. {
  389. struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
  390. struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
  391. /* Set the clock speed */
  392. set_sysctl(mmc, mmc->clock);
  393. /* Set the bus width */
  394. esdhc_clrbits32(&regs->proctl, PROCTL_DTW_4 | PROCTL_DTW_8);
  395. if (mmc->bus_width == 4)
  396. esdhc_setbits32(&regs->proctl, PROCTL_DTW_4);
  397. else if (mmc->bus_width == 8)
  398. esdhc_setbits32(&regs->proctl, PROCTL_DTW_8);
  399. }
  400. static int esdhc_init(struct mmc *mmc)
  401. {
  402. struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
  403. struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
  404. int timeout = 1000;
  405. /* Reset the entire host controller */
  406. esdhc_write32(&regs->sysctl, SYSCTL_RSTA);
  407. /* Wait until the controller is available */
  408. while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
  409. udelay(1000);
  410. #ifndef ARCH_MXC
  411. /* Enable cache snooping */
  412. esdhc_write32(&regs->scr, 0x00000040);
  413. #endif
  414. esdhc_write32(&regs->sysctl, SYSCTL_HCKEN | SYSCTL_IPGEN);
  415. /* Set the initial clock speed */
  416. mmc_set_clock(mmc, 400000);
  417. /* Disable the BRR and BWR bits in IRQSTAT */
  418. esdhc_clrbits32(&regs->irqstaten, IRQSTATEN_BRR | IRQSTATEN_BWR);
  419. /* Put the PROCTL reg back to the default */
  420. esdhc_write32(&regs->proctl, PROCTL_INIT);
  421. /* Set timout to the maximum value */
  422. esdhc_clrsetbits32(&regs->sysctl, SYSCTL_TIMEOUT_MASK, 14 << 16);
  423. return 0;
  424. }
  425. static int esdhc_getcd(struct mmc *mmc)
  426. {
  427. struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
  428. struct fsl_esdhc *regs = (struct fsl_esdhc *)cfg->esdhc_base;
  429. int timeout = 1000;
  430. while (!(esdhc_read32(&regs->prsstat) & PRSSTAT_CINS) && --timeout)
  431. udelay(1000);
  432. return timeout > 0;
  433. }
  434. static void esdhc_reset(struct fsl_esdhc *regs)
  435. {
  436. unsigned long timeout = 100; /* wait max 100 ms */
  437. /* reset the controller */
  438. esdhc_write32(&regs->sysctl, SYSCTL_RSTA);
  439. /* hardware clears the bit when it is done */
  440. while ((esdhc_read32(&regs->sysctl) & SYSCTL_RSTA) && --timeout)
  441. udelay(1000);
  442. if (!timeout)
  443. printf("MMC/SD: Reset never completed.\n");
  444. }
  445. int fsl_esdhc_initialize(bd_t *bis, struct fsl_esdhc_cfg *cfg)
  446. {
  447. struct fsl_esdhc *regs;
  448. struct mmc *mmc;
  449. u32 caps, voltage_caps;
  450. if (!cfg)
  451. return -1;
  452. mmc = malloc(sizeof(struct mmc));
  453. sprintf(mmc->name, "FSL_SDHC");
  454. regs = (struct fsl_esdhc *)cfg->esdhc_base;
  455. /* First reset the eSDHC controller */
  456. esdhc_reset(regs);
  457. esdhc_setbits32(&regs->sysctl, SYSCTL_PEREN | SYSCTL_HCKEN
  458. | SYSCTL_IPGEN | SYSCTL_CKEN);
  459. mmc->priv = cfg;
  460. mmc->send_cmd = esdhc_send_cmd;
  461. mmc->set_ios = esdhc_set_ios;
  462. mmc->init = esdhc_init;
  463. mmc->getcd = esdhc_getcd;
  464. voltage_caps = 0;
  465. caps = regs->hostcapblt;
  466. #ifdef CONFIG_SYS_FSL_ERRATUM_ESDHC135
  467. caps = caps & ~(ESDHC_HOSTCAPBLT_SRS |
  468. ESDHC_HOSTCAPBLT_VS18 | ESDHC_HOSTCAPBLT_VS30);
  469. #endif
  470. if (caps & ESDHC_HOSTCAPBLT_VS18)
  471. voltage_caps |= MMC_VDD_165_195;
  472. if (caps & ESDHC_HOSTCAPBLT_VS30)
  473. voltage_caps |= MMC_VDD_29_30 | MMC_VDD_30_31;
  474. if (caps & ESDHC_HOSTCAPBLT_VS33)
  475. voltage_caps |= MMC_VDD_32_33 | MMC_VDD_33_34;
  476. #ifdef CONFIG_SYS_SD_VOLTAGE
  477. mmc->voltages = CONFIG_SYS_SD_VOLTAGE;
  478. #else
  479. mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34;
  480. #endif
  481. if ((mmc->voltages & voltage_caps) == 0) {
  482. printf("voltage not supported by controller\n");
  483. return -1;
  484. }
  485. mmc->host_caps = MMC_MODE_4BIT | MMC_MODE_8BIT | MMC_MODE_HC;
  486. if (caps & ESDHC_HOSTCAPBLT_HSS)
  487. mmc->host_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
  488. mmc->f_min = 400000;
  489. mmc->f_max = MIN(gd->sdhc_clk, 52000000);
  490. mmc->b_max = 0;
  491. mmc_register(mmc);
  492. return 0;
  493. }
  494. int fsl_esdhc_mmc_init(bd_t *bis)
  495. {
  496. struct fsl_esdhc_cfg *cfg;
  497. cfg = malloc(sizeof(struct fsl_esdhc_cfg));
  498. memset(cfg, 0, sizeof(struct fsl_esdhc_cfg));
  499. cfg->esdhc_base = CONFIG_SYS_FSL_ESDHC_ADDR;
  500. cfg->sdhc_clk = gd->sdhc_clk;
  501. return fsl_esdhc_initialize(bis, cfg);
  502. }
  503. #ifdef CONFIG_OF_LIBFDT
  504. void fdt_fixup_esdhc(void *blob, bd_t *bd)
  505. {
  506. const char *compat = "fsl,esdhc";
  507. #ifdef CONFIG_FSL_ESDHC_PIN_MUX
  508. if (!hwconfig("esdhc")) {
  509. do_fixup_by_compat(blob, compat, "status", "disabled",
  510. 8 + 1, 1);
  511. return;
  512. }
  513. #endif
  514. do_fixup_by_compat_u32(blob, compat, "clock-frequency",
  515. gd->sdhc_clk, 1);
  516. do_fixup_by_compat(blob, compat, "status", "okay",
  517. 4 + 1, 1);
  518. }
  519. #endif