dw_mmc.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2012 SAMSUNG Electronics
  4. * Jaehoon Chung <jh80.chung@samsung.com>
  5. * Rajeshawari Shinde <rajeshwari.s@samsung.com>
  6. */
  7. #include <bouncebuf.h>
  8. #include <common.h>
  9. #include <cpu_func.h>
  10. #include <errno.h>
  11. #include <log.h>
  12. #include <malloc.h>
  13. #include <memalign.h>
  14. #include <mmc.h>
  15. #include <dwmmc.h>
  16. #include <wait_bit.h>
  17. #include <asm/cache.h>
  18. #include <linux/delay.h>
  19. #include <power/regulator.h>
  20. #define PAGE_SIZE 4096
  21. static int dwmci_wait_reset(struct dwmci_host *host, u32 value)
  22. {
  23. unsigned long timeout = 1000;
  24. u32 ctrl;
  25. dwmci_writel(host, DWMCI_CTRL, value);
  26. while (timeout--) {
  27. ctrl = dwmci_readl(host, DWMCI_CTRL);
  28. if (!(ctrl & DWMCI_RESET_ALL))
  29. return 1;
  30. }
  31. return 0;
  32. }
  33. #if !CONFIG_IS_ENABLED(MMC_TINY)
  34. static void dwmci_set_idma_desc(struct dwmci_idmac *idmac,
  35. u32 desc0, u32 desc1, u32 desc2)
  36. {
  37. struct dwmci_idmac *desc = idmac;
  38. desc->flags = desc0;
  39. desc->cnt = desc1;
  40. desc->addr = desc2;
  41. desc->next_addr = (ulong)desc + sizeof(struct dwmci_idmac);
  42. }
  43. static void dwmci_prepare_data(struct dwmci_host *host,
  44. struct mmc_data *data,
  45. struct dwmci_idmac *cur_idmac,
  46. void *bounce_buffer)
  47. {
  48. unsigned long ctrl;
  49. unsigned int i = 0, flags, cnt, blk_cnt;
  50. ulong data_start, data_end;
  51. blk_cnt = data->blocks;
  52. dwmci_wait_reset(host, DWMCI_CTRL_FIFO_RESET);
  53. /* Clear IDMAC interrupt */
  54. dwmci_writel(host, DWMCI_IDSTS, 0xFFFFFFFF);
  55. data_start = (ulong)cur_idmac;
  56. dwmci_writel(host, DWMCI_DBADDR, (ulong)cur_idmac);
  57. do {
  58. flags = DWMCI_IDMAC_OWN | DWMCI_IDMAC_CH ;
  59. flags |= (i == 0) ? DWMCI_IDMAC_FS : 0;
  60. if (blk_cnt <= 8) {
  61. flags |= DWMCI_IDMAC_LD;
  62. cnt = data->blocksize * blk_cnt;
  63. } else
  64. cnt = data->blocksize * 8;
  65. dwmci_set_idma_desc(cur_idmac, flags, cnt,
  66. (ulong)bounce_buffer + (i * PAGE_SIZE));
  67. cur_idmac++;
  68. if (blk_cnt <= 8)
  69. break;
  70. blk_cnt -= 8;
  71. i++;
  72. } while(1);
  73. data_end = (ulong)cur_idmac;
  74. flush_dcache_range(data_start, roundup(data_end, ARCH_DMA_MINALIGN));
  75. ctrl = dwmci_readl(host, DWMCI_CTRL);
  76. ctrl |= DWMCI_IDMAC_EN | DWMCI_DMA_EN;
  77. dwmci_writel(host, DWMCI_CTRL, ctrl);
  78. ctrl = dwmci_readl(host, DWMCI_BMOD);
  79. ctrl |= DWMCI_BMOD_IDMAC_FB | DWMCI_BMOD_IDMAC_EN;
  80. dwmci_writel(host, DWMCI_BMOD, ctrl);
  81. dwmci_writel(host, DWMCI_BLKSIZ, data->blocksize);
  82. dwmci_writel(host, DWMCI_BYTCNT, data->blocksize * data->blocks);
  83. }
  84. #endif
  85. static int dwmci_fifo_ready(struct dwmci_host *host, u32 bit, u32 *len)
  86. {
  87. u32 timeout = 20000;
  88. *len = dwmci_readl(host, DWMCI_STATUS);
  89. while (--timeout && (*len & bit)) {
  90. udelay(200);
  91. *len = dwmci_readl(host, DWMCI_STATUS);
  92. }
  93. if (!timeout) {
  94. debug("%s: FIFO underflow timeout\n", __func__);
  95. return -ETIMEDOUT;
  96. }
  97. return 0;
  98. }
  99. static unsigned int dwmci_get_timeout(struct mmc *mmc, const unsigned int size)
  100. {
  101. unsigned int timeout;
  102. timeout = size * 8; /* counting in bits */
  103. timeout *= 10; /* wait 10 times as long */
  104. timeout /= mmc->clock;
  105. timeout /= mmc->bus_width;
  106. timeout /= mmc->ddr_mode ? 2 : 1;
  107. timeout *= 1000; /* counting in msec */
  108. timeout = (timeout < 1000) ? 1000 : timeout;
  109. return timeout;
  110. }
  111. static int dwmci_data_transfer(struct dwmci_host *host, struct mmc_data *data)
  112. {
  113. struct mmc *mmc = host->mmc;
  114. int ret = 0;
  115. u32 timeout, mask, size, i, len = 0;
  116. u32 *buf = NULL;
  117. ulong start = get_timer(0);
  118. u32 fifo_depth = (((host->fifoth_val & RX_WMARK_MASK) >>
  119. RX_WMARK_SHIFT) + 1) * 2;
  120. size = data->blocksize * data->blocks;
  121. if (data->flags == MMC_DATA_READ)
  122. buf = (unsigned int *)data->dest;
  123. else
  124. buf = (unsigned int *)data->src;
  125. timeout = dwmci_get_timeout(mmc, size);
  126. size /= 4;
  127. for (;;) {
  128. mask = dwmci_readl(host, DWMCI_RINTSTS);
  129. /* Error during data transfer. */
  130. if (mask & (DWMCI_DATA_ERR | DWMCI_DATA_TOUT)) {
  131. debug("%s: DATA ERROR!\n", __func__);
  132. ret = -EINVAL;
  133. break;
  134. }
  135. if (host->fifo_mode && size) {
  136. len = 0;
  137. if (data->flags == MMC_DATA_READ &&
  138. (mask & (DWMCI_INTMSK_RXDR | DWMCI_INTMSK_DTO))) {
  139. dwmci_writel(host, DWMCI_RINTSTS,
  140. mask & (DWMCI_INTMSK_RXDR |
  141. DWMCI_INTMSK_DTO));
  142. while (size) {
  143. ret = dwmci_fifo_ready(host,
  144. DWMCI_FIFO_EMPTY,
  145. &len);
  146. if (ret < 0)
  147. break;
  148. len = (len >> DWMCI_FIFO_SHIFT) &
  149. DWMCI_FIFO_MASK;
  150. len = min(size, len);
  151. for (i = 0; i < len; i++)
  152. *buf++ =
  153. dwmci_readl(host, DWMCI_DATA);
  154. size = size > len ? (size - len) : 0;
  155. }
  156. } else if (data->flags == MMC_DATA_WRITE &&
  157. (mask & DWMCI_INTMSK_TXDR)) {
  158. while (size) {
  159. ret = dwmci_fifo_ready(host,
  160. DWMCI_FIFO_FULL,
  161. &len);
  162. if (ret < 0)
  163. break;
  164. len = fifo_depth - ((len >>
  165. DWMCI_FIFO_SHIFT) &
  166. DWMCI_FIFO_MASK);
  167. len = min(size, len);
  168. for (i = 0; i < len; i++)
  169. dwmci_writel(host, DWMCI_DATA,
  170. *buf++);
  171. size = size > len ? (size - len) : 0;
  172. }
  173. dwmci_writel(host, DWMCI_RINTSTS,
  174. DWMCI_INTMSK_TXDR);
  175. }
  176. }
  177. /* Data arrived correctly. */
  178. if (mask & DWMCI_INTMSK_DTO) {
  179. ret = 0;
  180. break;
  181. }
  182. /* Check for timeout. */
  183. if (get_timer(start) > timeout) {
  184. debug("%s: Timeout waiting for data!\n",
  185. __func__);
  186. ret = -ETIMEDOUT;
  187. break;
  188. }
  189. }
  190. dwmci_writel(host, DWMCI_RINTSTS, mask);
  191. return ret;
  192. }
  193. static int dwmci_set_transfer_mode(struct dwmci_host *host,
  194. struct mmc_data *data)
  195. {
  196. unsigned long mode;
  197. mode = DWMCI_CMD_DATA_EXP;
  198. if (data->flags & MMC_DATA_WRITE)
  199. mode |= DWMCI_CMD_RW;
  200. return mode;
  201. }
  202. #if defined(CONFIG_DM_MMC) && !defined(CONFIG_SPL_BUILD)
  203. static int dwmci_send_cmd(struct udevice *dev, struct mmc_cmd *cmd,
  204. struct mmc_data *data)
  205. {
  206. struct mmc *mmc = mmc_get_mmc_dev(dev);
  207. #else
  208. static int dwmci_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
  209. struct mmc_data *data)
  210. {
  211. #endif
  212. struct dwmci_host *host = mmc->priv;
  213. #if !CONFIG_IS_ENABLED(MMC_TINY)
  214. ALLOC_CACHE_ALIGN_BUFFER(struct dwmci_idmac, cur_idmac,
  215. data ? DIV_ROUND_UP(data->blocks, 8) : 0);
  216. #endif
  217. int ret = 0, flags = 0, i;
  218. unsigned int timeout = 500;
  219. u32 retry = 100000;
  220. u32 mask;
  221. #if !CONFIG_IS_ENABLED(MMC_TINY)
  222. u32 ctrl;
  223. #endif
  224. ulong start = get_timer(0);
  225. #if !CONFIG_IS_ENABLED(MMC_TINY)
  226. struct bounce_buffer bbstate;
  227. #endif
  228. while (dwmci_readl(host, DWMCI_STATUS) & DWMCI_BUSY) {
  229. if (get_timer(start) > timeout) {
  230. debug("%s: Timeout on data busy\n", __func__);
  231. return -ETIMEDOUT;
  232. }
  233. }
  234. dwmci_writel(host, DWMCI_RINTSTS, DWMCI_INTMSK_ALL);
  235. if (data) {
  236. if (host->fifo_mode) {
  237. dwmci_writel(host, DWMCI_BLKSIZ, data->blocksize);
  238. dwmci_writel(host, DWMCI_BYTCNT,
  239. data->blocksize * data->blocks);
  240. dwmci_wait_reset(host, DWMCI_CTRL_FIFO_RESET);
  241. }
  242. #if !CONFIG_IS_ENABLED(MMC_TINY)
  243. else {
  244. if (data->flags == MMC_DATA_READ) {
  245. ret = bounce_buffer_start(&bbstate,
  246. (void*)data->dest,
  247. data->blocksize *
  248. data->blocks, GEN_BB_WRITE);
  249. } else {
  250. ret = bounce_buffer_start(&bbstate,
  251. (void*)data->src,
  252. data->blocksize *
  253. data->blocks, GEN_BB_READ);
  254. }
  255. if (ret)
  256. return ret;
  257. dwmci_prepare_data(host, data, cur_idmac,
  258. bbstate.bounce_buffer);
  259. }
  260. #endif
  261. }
  262. dwmci_writel(host, DWMCI_CMDARG, cmd->cmdarg);
  263. if (data)
  264. flags = dwmci_set_transfer_mode(host, data);
  265. if ((cmd->resp_type & MMC_RSP_136) && (cmd->resp_type & MMC_RSP_BUSY))
  266. return -EBUSY;
  267. if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
  268. flags |= DWMCI_CMD_ABORT_STOP;
  269. else
  270. flags |= DWMCI_CMD_PRV_DAT_WAIT;
  271. if (cmd->resp_type & MMC_RSP_PRESENT) {
  272. flags |= DWMCI_CMD_RESP_EXP;
  273. if (cmd->resp_type & MMC_RSP_136)
  274. flags |= DWMCI_CMD_RESP_LENGTH;
  275. }
  276. if (cmd->resp_type & MMC_RSP_CRC)
  277. flags |= DWMCI_CMD_CHECK_CRC;
  278. flags |= (cmd->cmdidx | DWMCI_CMD_START | DWMCI_CMD_USE_HOLD_REG);
  279. debug("Sending CMD%d\n",cmd->cmdidx);
  280. dwmci_writel(host, DWMCI_CMD, flags);
  281. for (i = 0; i < retry; i++) {
  282. mask = dwmci_readl(host, DWMCI_RINTSTS);
  283. if (mask & DWMCI_INTMSK_CDONE) {
  284. if (!data)
  285. dwmci_writel(host, DWMCI_RINTSTS, mask);
  286. break;
  287. }
  288. }
  289. if (i == retry) {
  290. debug("%s: Timeout.\n", __func__);
  291. return -ETIMEDOUT;
  292. }
  293. if (mask & DWMCI_INTMSK_RTO) {
  294. /*
  295. * Timeout here is not necessarily fatal. (e)MMC cards
  296. * will splat here when they receive CMD55 as they do
  297. * not support this command and that is exactly the way
  298. * to tell them apart from SD cards. Thus, this output
  299. * below shall be debug(). eMMC cards also do not favor
  300. * CMD8, please keep that in mind.
  301. */
  302. debug("%s: Response Timeout.\n", __func__);
  303. return -ETIMEDOUT;
  304. } else if (mask & DWMCI_INTMSK_RE) {
  305. debug("%s: Response Error.\n", __func__);
  306. return -EIO;
  307. } else if ((cmd->resp_type & MMC_RSP_CRC) &&
  308. (mask & DWMCI_INTMSK_RCRC)) {
  309. debug("%s: Response CRC Error.\n", __func__);
  310. return -EIO;
  311. }
  312. if (cmd->resp_type & MMC_RSP_PRESENT) {
  313. if (cmd->resp_type & MMC_RSP_136) {
  314. cmd->response[0] = dwmci_readl(host, DWMCI_RESP3);
  315. cmd->response[1] = dwmci_readl(host, DWMCI_RESP2);
  316. cmd->response[2] = dwmci_readl(host, DWMCI_RESP1);
  317. cmd->response[3] = dwmci_readl(host, DWMCI_RESP0);
  318. } else {
  319. cmd->response[0] = dwmci_readl(host, DWMCI_RESP0);
  320. }
  321. }
  322. if (data) {
  323. ret = dwmci_data_transfer(host, data);
  324. #if !CONFIG_IS_ENABLED(MMC_TINY)
  325. /* only dma mode need it */
  326. if (!host->fifo_mode) {
  327. if (data->flags == MMC_DATA_READ)
  328. mask = DWMCI_IDINTEN_RI;
  329. else
  330. mask = DWMCI_IDINTEN_TI;
  331. ret = wait_for_bit_le32(host->ioaddr + DWMCI_IDSTS,
  332. mask, true, 1000, false);
  333. if (ret)
  334. debug("%s: DWMCI_IDINTEN mask 0x%x timeout.\n",
  335. __func__, mask);
  336. /* clear interrupts */
  337. dwmci_writel(host, DWMCI_IDSTS, DWMCI_IDINTEN_MASK);
  338. ctrl = dwmci_readl(host, DWMCI_CTRL);
  339. ctrl &= ~(DWMCI_DMA_EN);
  340. dwmci_writel(host, DWMCI_CTRL, ctrl);
  341. bounce_buffer_stop(&bbstate);
  342. }
  343. #endif
  344. }
  345. udelay(100);
  346. return ret;
  347. }
  348. static int dwmci_setup_bus(struct dwmci_host *host, u32 freq)
  349. {
  350. u32 div, status;
  351. int timeout = 10000;
  352. unsigned long sclk;
  353. if ((freq == host->clock) || (freq == 0))
  354. return 0;
  355. /*
  356. * If host->get_mmc_clk isn't defined,
  357. * then assume that host->bus_hz is source clock value.
  358. * host->bus_hz should be set by user.
  359. */
  360. if (host->get_mmc_clk)
  361. sclk = host->get_mmc_clk(host, freq);
  362. else if (host->bus_hz)
  363. sclk = host->bus_hz;
  364. else {
  365. debug("%s: Didn't get source clock value.\n", __func__);
  366. return -EINVAL;
  367. }
  368. if (sclk == freq)
  369. div = 0; /* bypass mode */
  370. else
  371. div = DIV_ROUND_UP(sclk, 2 * freq);
  372. dwmci_writel(host, DWMCI_CLKENA, 0);
  373. dwmci_writel(host, DWMCI_CLKSRC, 0);
  374. dwmci_writel(host, DWMCI_CLKDIV, div);
  375. dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT |
  376. DWMCI_CMD_UPD_CLK | DWMCI_CMD_START);
  377. do {
  378. status = dwmci_readl(host, DWMCI_CMD);
  379. if (timeout-- < 0) {
  380. debug("%s: Timeout!\n", __func__);
  381. return -ETIMEDOUT;
  382. }
  383. } while (status & DWMCI_CMD_START);
  384. dwmci_writel(host, DWMCI_CLKENA, DWMCI_CLKEN_ENABLE |
  385. DWMCI_CLKEN_LOW_PWR);
  386. dwmci_writel(host, DWMCI_CMD, DWMCI_CMD_PRV_DAT_WAIT |
  387. DWMCI_CMD_UPD_CLK | DWMCI_CMD_START);
  388. timeout = 10000;
  389. do {
  390. status = dwmci_readl(host, DWMCI_CMD);
  391. if (timeout-- < 0) {
  392. debug("%s: Timeout!\n", __func__);
  393. return -ETIMEDOUT;
  394. }
  395. } while (status & DWMCI_CMD_START);
  396. host->clock = freq;
  397. return 0;
  398. }
  399. //#ifdef CONFIG_DM_MMC
  400. #if defined(CONFIG_DM_MMC) && !defined(CONFIG_SPL_BUILD)
  401. static int dwmci_set_ios(struct udevice *dev)
  402. {
  403. struct mmc *mmc = mmc_get_mmc_dev(dev);
  404. #else
  405. static int dwmci_set_ios(struct mmc *mmc)
  406. {
  407. #endif
  408. struct dwmci_host *host = (struct dwmci_host *)mmc->priv;
  409. u32 ctype, regs;
  410. debug("Buswidth = %d, clock: %d\n", mmc->bus_width, mmc->clock);
  411. dwmci_setup_bus(host, mmc->clock);
  412. switch (mmc->bus_width) {
  413. case 8:
  414. ctype = DWMCI_CTYPE_8BIT;
  415. break;
  416. case 4:
  417. ctype = DWMCI_CTYPE_4BIT;
  418. break;
  419. default:
  420. ctype = DWMCI_CTYPE_1BIT;
  421. break;
  422. }
  423. dwmci_writel(host, DWMCI_CTYPE, ctype);
  424. regs = dwmci_readl(host, DWMCI_UHS_REG);
  425. if (mmc->ddr_mode)
  426. regs |= DWMCI_DDR_MODE;
  427. else
  428. regs &= ~DWMCI_DDR_MODE;
  429. dwmci_writel(host, DWMCI_UHS_REG, regs);
  430. if (host->clksel) {
  431. int ret;
  432. ret = host->clksel(host);
  433. if (ret)
  434. return ret;
  435. }
  436. #if CONFIG_IS_ENABLED(DM_REGULATOR)
  437. if (mmc->vqmmc_supply) {
  438. int ret;
  439. if (mmc->signal_voltage == MMC_SIGNAL_VOLTAGE_180)
  440. regulator_set_value(mmc->vqmmc_supply, 1800000);
  441. else
  442. regulator_set_value(mmc->vqmmc_supply, 3300000);
  443. ret = regulator_set_enable_if_allowed(mmc->vqmmc_supply, true);
  444. if (ret)
  445. return ret;
  446. }
  447. #endif
  448. return 0;
  449. }
  450. static int dwmci_init(struct mmc *mmc)
  451. {
  452. struct dwmci_host *host = mmc->priv;
  453. if (host->board_init)
  454. host->board_init(host);
  455. dwmci_writel(host, DWMCI_PWREN, 1);
  456. if (!dwmci_wait_reset(host, DWMCI_RESET_ALL)) {
  457. debug("%s[%d] Fail-reset!!\n", __func__, __LINE__);
  458. return -EIO;
  459. }
  460. /* Enumerate at 400KHz */
  461. dwmci_setup_bus(host, mmc->cfg->f_min);
  462. dwmci_writel(host, DWMCI_RINTSTS, 0xFFFFFFFF);
  463. dwmci_writel(host, DWMCI_INTMASK, 0);
  464. dwmci_writel(host, DWMCI_TMOUT, 0xFFFFFFFF);
  465. dwmci_writel(host, DWMCI_IDINTEN, 0);
  466. dwmci_writel(host, DWMCI_BMOD, 1);
  467. if (!host->fifoth_val) {
  468. uint32_t fifo_size;
  469. fifo_size = dwmci_readl(host, DWMCI_FIFOTH);
  470. fifo_size = ((fifo_size & RX_WMARK_MASK) >> RX_WMARK_SHIFT) + 1;
  471. host->fifoth_val = MSIZE(0x2) | RX_WMARK(fifo_size / 2 - 1) |
  472. TX_WMARK(fifo_size / 2);
  473. }
  474. dwmci_writel(host, DWMCI_FIFOTH, host->fifoth_val);
  475. dwmci_writel(host, DWMCI_CLKENA, 0);
  476. dwmci_writel(host, DWMCI_CLKSRC, 0);
  477. if (!host->fifo_mode)
  478. dwmci_writel(host, DWMCI_IDINTEN, DWMCI_IDINTEN_MASK);
  479. return 0;
  480. }
  481. //#ifdef CONFIG_DM_MMC
  482. #if defined(CONFIG_DM_MMC) && !defined(CONFIG_SPL_BUILD)
  483. int dwmci_probe(struct udevice *dev)
  484. {
  485. struct mmc *mmc = mmc_get_mmc_dev(dev);
  486. return dwmci_init(mmc);
  487. }
  488. const struct dm_mmc_ops dm_dwmci_ops = {
  489. .send_cmd = dwmci_send_cmd,
  490. .set_ios = dwmci_set_ios,
  491. };
  492. #else
  493. static const struct mmc_ops dwmci_ops = {
  494. .send_cmd = dwmci_send_cmd,
  495. .set_ios = dwmci_set_ios,
  496. .init = dwmci_init,
  497. };
  498. #endif
  499. void dwmci_setup_cfg(struct mmc_config *cfg, struct dwmci_host *host,
  500. u32 max_clk, u32 min_clk)
  501. {
  502. cfg->name = host->name;
  503. //#ifndef CONFIG_DM_MMC
  504. #if defined(CONFIG_SPL_BUILD) || !defined(CONFIG_DM_MMC)
  505. cfg->ops = &dwmci_ops;
  506. #endif
  507. cfg->f_min = min_clk;
  508. cfg->f_max = max_clk;
  509. cfg->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
  510. cfg->host_caps = host->caps;
  511. if (host->buswidth == 8) {
  512. cfg->host_caps |= MMC_MODE_8BIT;
  513. cfg->host_caps &= ~MMC_MODE_4BIT;
  514. } else {
  515. cfg->host_caps |= MMC_MODE_4BIT;
  516. cfg->host_caps &= ~MMC_MODE_8BIT;
  517. }
  518. cfg->host_caps |= MMC_MODE_HS | MMC_MODE_HS_52MHz;
  519. cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
  520. }
  521. //#ifdef CONFIG_BLK
  522. #if defined(CONFIG_BLK) && !defined(CONFIG_SPL_BUILD)
  523. int dwmci_bind(struct udevice *dev, struct mmc *mmc, struct mmc_config *cfg)
  524. {
  525. return mmc_bind(dev, mmc, cfg);
  526. }
  527. #else
  528. int add_dwmci(struct dwmci_host *host, u32 max_clk, u32 min_clk)
  529. {
  530. dwmci_setup_cfg(&host->cfg, host, max_clk, min_clk);
  531. host->mmc = mmc_create(&host->cfg, host);
  532. if (host->mmc == NULL)
  533. return -1;
  534. return 0;
  535. }
  536. #endif