sdhci.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  1. /*
  2. * Copyright 2011, Marvell Semiconductor Inc.
  3. * Lei Wen <leiwen@marvell.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. *
  7. * Back ported to the 8xx platform (from the 8260 platform) by
  8. * Murray.Jensen@cmst.csiro.au, 27-Jan-01.
  9. */
  10. #include <common.h>
  11. #include <errno.h>
  12. #include <malloc.h>
  13. #include <mmc.h>
  14. #include <sdhci.h>
  15. #if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
  16. void *aligned_buffer = (void *)CONFIG_FIXED_SDHCI_ALIGNED_BUFFER;
  17. #else
  18. void *aligned_buffer;
  19. #endif
  20. static void sdhci_reset(struct sdhci_host *host, u8 mask)
  21. {
  22. unsigned long timeout;
  23. /* Wait max 100 ms */
  24. timeout = 100;
  25. sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET);
  26. while (sdhci_readb(host, SDHCI_SOFTWARE_RESET) & mask) {
  27. if (timeout == 0) {
  28. printf("%s: Reset 0x%x never completed.\n",
  29. __func__, (int)mask);
  30. return;
  31. }
  32. timeout--;
  33. udelay(1000);
  34. }
  35. }
  36. static void sdhci_cmd_done(struct sdhci_host *host, struct mmc_cmd *cmd)
  37. {
  38. int i;
  39. if (cmd->resp_type & MMC_RSP_136) {
  40. /* CRC is stripped so we need to do some shifting. */
  41. for (i = 0; i < 4; i++) {
  42. cmd->response[i] = sdhci_readl(host,
  43. SDHCI_RESPONSE + (3-i)*4) << 8;
  44. if (i != 3)
  45. cmd->response[i] |= sdhci_readb(host,
  46. SDHCI_RESPONSE + (3-i)*4-1);
  47. }
  48. } else {
  49. cmd->response[0] = sdhci_readl(host, SDHCI_RESPONSE);
  50. }
  51. }
  52. static void sdhci_transfer_pio(struct sdhci_host *host, struct mmc_data *data)
  53. {
  54. int i;
  55. char *offs;
  56. for (i = 0; i < data->blocksize; i += 4) {
  57. offs = data->dest + i;
  58. if (data->flags == MMC_DATA_READ)
  59. *(u32 *)offs = sdhci_readl(host, SDHCI_BUFFER);
  60. else
  61. sdhci_writel(host, *(u32 *)offs, SDHCI_BUFFER);
  62. }
  63. }
  64. static int sdhci_transfer_data(struct sdhci_host *host, struct mmc_data *data,
  65. unsigned int start_addr)
  66. {
  67. unsigned int stat, rdy, mask, timeout, block = 0;
  68. #ifdef CONFIG_MMC_SDHCI_SDMA
  69. unsigned char ctrl;
  70. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  71. ctrl &= ~SDHCI_CTRL_DMA_MASK;
  72. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  73. #endif
  74. timeout = 1000000;
  75. rdy = SDHCI_INT_SPACE_AVAIL | SDHCI_INT_DATA_AVAIL;
  76. mask = SDHCI_DATA_AVAILABLE | SDHCI_SPACE_AVAILABLE;
  77. do {
  78. stat = sdhci_readl(host, SDHCI_INT_STATUS);
  79. if (stat & SDHCI_INT_ERROR) {
  80. printf("%s: Error detected in status(0x%X)!\n",
  81. __func__, stat);
  82. return -EIO;
  83. }
  84. if (stat & rdy) {
  85. if (!(sdhci_readl(host, SDHCI_PRESENT_STATE) & mask))
  86. continue;
  87. sdhci_writel(host, rdy, SDHCI_INT_STATUS);
  88. sdhci_transfer_pio(host, data);
  89. data->dest += data->blocksize;
  90. if (++block >= data->blocks)
  91. break;
  92. }
  93. #ifdef CONFIG_MMC_SDHCI_SDMA
  94. if (stat & SDHCI_INT_DMA_END) {
  95. sdhci_writel(host, SDHCI_INT_DMA_END, SDHCI_INT_STATUS);
  96. start_addr &= ~(SDHCI_DEFAULT_BOUNDARY_SIZE - 1);
  97. start_addr += SDHCI_DEFAULT_BOUNDARY_SIZE;
  98. sdhci_writel(host, start_addr, SDHCI_DMA_ADDRESS);
  99. }
  100. #endif
  101. if (timeout-- > 0)
  102. udelay(10);
  103. else {
  104. printf("%s: Transfer data timeout\n", __func__);
  105. return -ETIMEDOUT;
  106. }
  107. } while (!(stat & SDHCI_INT_DATA_END));
  108. return 0;
  109. }
  110. /*
  111. * No command will be sent by driver if card is busy, so driver must wait
  112. * for card ready state.
  113. * Every time when card is busy after timeout then (last) timeout value will be
  114. * increased twice but only if it doesn't exceed global defined maximum.
  115. * Each function call will use last timeout value.
  116. */
  117. #define SDHCI_CMD_MAX_TIMEOUT 3200
  118. #define SDHCI_CMD_DEFAULT_TIMEOUT 100
  119. #define SDHCI_READ_STATUS_TIMEOUT 1000
  120. #ifdef CONFIG_DM_MMC_OPS
  121. static int sdhci_send_command(struct udevice *dev, struct mmc_cmd *cmd,
  122. struct mmc_data *data)
  123. {
  124. struct mmc *mmc = mmc_get_mmc_dev(dev);
  125. #else
  126. static int sdhci_send_command(struct mmc *mmc, struct mmc_cmd *cmd,
  127. struct mmc_data *data)
  128. {
  129. #endif
  130. struct sdhci_host *host = mmc->priv;
  131. unsigned int stat = 0;
  132. int ret = 0;
  133. int trans_bytes = 0, is_aligned = 1;
  134. u32 mask, flags, mode;
  135. unsigned int time = 0, start_addr = 0;
  136. int mmc_dev = mmc_get_blk_desc(mmc)->devnum;
  137. unsigned start = get_timer(0);
  138. /* Timeout unit - ms */
  139. static unsigned int cmd_timeout = SDHCI_CMD_DEFAULT_TIMEOUT;
  140. sdhci_writel(host, SDHCI_INT_ALL_MASK, SDHCI_INT_STATUS);
  141. mask = SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT;
  142. /* We shouldn't wait for data inihibit for stop commands, even
  143. though they might use busy signaling */
  144. if (cmd->cmdidx == MMC_CMD_STOP_TRANSMISSION)
  145. mask &= ~SDHCI_DATA_INHIBIT;
  146. while (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) {
  147. if (time >= cmd_timeout) {
  148. printf("%s: MMC: %d busy ", __func__, mmc_dev);
  149. if (2 * cmd_timeout <= SDHCI_CMD_MAX_TIMEOUT) {
  150. cmd_timeout += cmd_timeout;
  151. printf("timeout increasing to: %u ms.\n",
  152. cmd_timeout);
  153. } else {
  154. puts("timeout.\n");
  155. return -ECOMM;
  156. }
  157. }
  158. time++;
  159. udelay(1000);
  160. }
  161. mask = SDHCI_INT_RESPONSE;
  162. if (!(cmd->resp_type & MMC_RSP_PRESENT))
  163. flags = SDHCI_CMD_RESP_NONE;
  164. else if (cmd->resp_type & MMC_RSP_136)
  165. flags = SDHCI_CMD_RESP_LONG;
  166. else if (cmd->resp_type & MMC_RSP_BUSY) {
  167. flags = SDHCI_CMD_RESP_SHORT_BUSY;
  168. if (data)
  169. mask |= SDHCI_INT_DATA_END;
  170. } else
  171. flags = SDHCI_CMD_RESP_SHORT;
  172. if (cmd->resp_type & MMC_RSP_CRC)
  173. flags |= SDHCI_CMD_CRC;
  174. if (cmd->resp_type & MMC_RSP_OPCODE)
  175. flags |= SDHCI_CMD_INDEX;
  176. if (data)
  177. flags |= SDHCI_CMD_DATA;
  178. /* Set Transfer mode regarding to data flag */
  179. if (data != 0) {
  180. sdhci_writeb(host, 0xe, SDHCI_TIMEOUT_CONTROL);
  181. mode = SDHCI_TRNS_BLK_CNT_EN;
  182. trans_bytes = data->blocks * data->blocksize;
  183. if (data->blocks > 1)
  184. mode |= SDHCI_TRNS_MULTI;
  185. if (data->flags == MMC_DATA_READ)
  186. mode |= SDHCI_TRNS_READ;
  187. #ifdef CONFIG_MMC_SDHCI_SDMA
  188. if (data->flags == MMC_DATA_READ)
  189. start_addr = (unsigned long)data->dest;
  190. else
  191. start_addr = (unsigned long)data->src;
  192. if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) &&
  193. (start_addr & 0x7) != 0x0) {
  194. is_aligned = 0;
  195. start_addr = (unsigned long)aligned_buffer;
  196. if (data->flags != MMC_DATA_READ)
  197. memcpy(aligned_buffer, data->src, trans_bytes);
  198. }
  199. #if defined(CONFIG_FIXED_SDHCI_ALIGNED_BUFFER)
  200. /*
  201. * Always use this bounce-buffer when
  202. * CONFIG_FIXED_SDHCI_ALIGNED_BUFFER is defined
  203. */
  204. is_aligned = 0;
  205. start_addr = (unsigned long)aligned_buffer;
  206. if (data->flags != MMC_DATA_READ)
  207. memcpy(aligned_buffer, data->src, trans_bytes);
  208. #endif
  209. sdhci_writel(host, start_addr, SDHCI_DMA_ADDRESS);
  210. mode |= SDHCI_TRNS_DMA;
  211. #endif
  212. sdhci_writew(host, SDHCI_MAKE_BLKSZ(SDHCI_DEFAULT_BOUNDARY_ARG,
  213. data->blocksize),
  214. SDHCI_BLOCK_SIZE);
  215. sdhci_writew(host, data->blocks, SDHCI_BLOCK_COUNT);
  216. sdhci_writew(host, mode, SDHCI_TRANSFER_MODE);
  217. } else if (cmd->resp_type & MMC_RSP_BUSY) {
  218. sdhci_writeb(host, 0xe, SDHCI_TIMEOUT_CONTROL);
  219. }
  220. sdhci_writel(host, cmd->cmdarg, SDHCI_ARGUMENT);
  221. #ifdef CONFIG_MMC_SDHCI_SDMA
  222. trans_bytes = ALIGN(trans_bytes, CONFIG_SYS_CACHELINE_SIZE);
  223. flush_cache(start_addr, trans_bytes);
  224. #endif
  225. sdhci_writew(host, SDHCI_MAKE_CMD(cmd->cmdidx, flags), SDHCI_COMMAND);
  226. start = get_timer(0);
  227. do {
  228. stat = sdhci_readl(host, SDHCI_INT_STATUS);
  229. if (stat & SDHCI_INT_ERROR)
  230. break;
  231. if (get_timer(start) >= SDHCI_READ_STATUS_TIMEOUT) {
  232. if (host->quirks & SDHCI_QUIRK_BROKEN_R1B) {
  233. return 0;
  234. } else {
  235. printf("%s: Timeout for status update!\n",
  236. __func__);
  237. return -ETIMEDOUT;
  238. }
  239. }
  240. } while ((stat & mask) != mask);
  241. if ((stat & (SDHCI_INT_ERROR | mask)) == mask) {
  242. sdhci_cmd_done(host, cmd);
  243. sdhci_writel(host, mask, SDHCI_INT_STATUS);
  244. } else
  245. ret = -1;
  246. if (!ret && data)
  247. ret = sdhci_transfer_data(host, data, start_addr);
  248. if (host->quirks & SDHCI_QUIRK_WAIT_SEND_CMD)
  249. udelay(1000);
  250. stat = sdhci_readl(host, SDHCI_INT_STATUS);
  251. sdhci_writel(host, SDHCI_INT_ALL_MASK, SDHCI_INT_STATUS);
  252. if (!ret) {
  253. if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) &&
  254. !is_aligned && (data->flags == MMC_DATA_READ))
  255. memcpy(data->dest, aligned_buffer, trans_bytes);
  256. return 0;
  257. }
  258. sdhci_reset(host, SDHCI_RESET_CMD);
  259. sdhci_reset(host, SDHCI_RESET_DATA);
  260. if (stat & SDHCI_INT_TIMEOUT)
  261. return -ETIMEDOUT;
  262. else
  263. return -ECOMM;
  264. }
  265. static int sdhci_set_clock(struct mmc *mmc, unsigned int clock)
  266. {
  267. struct sdhci_host *host = mmc->priv;
  268. unsigned int div, clk = 0, timeout;
  269. /* Wait max 20 ms */
  270. timeout = 200;
  271. while (sdhci_readl(host, SDHCI_PRESENT_STATE) &
  272. (SDHCI_CMD_INHIBIT | SDHCI_DATA_INHIBIT)) {
  273. if (timeout == 0) {
  274. printf("%s: Timeout to wait cmd & data inhibit\n",
  275. __func__);
  276. return -EBUSY;
  277. }
  278. timeout--;
  279. udelay(100);
  280. }
  281. sdhci_writew(host, 0, SDHCI_CLOCK_CONTROL);
  282. if (clock == 0)
  283. return 0;
  284. if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) {
  285. /*
  286. * Check if the Host Controller supports Programmable Clock
  287. * Mode.
  288. */
  289. if (host->clk_mul) {
  290. for (div = 1; div <= 1024; div++) {
  291. if ((host->max_clk * host->clk_mul / div)
  292. <= clock)
  293. break;
  294. }
  295. /*
  296. * Set Programmable Clock Mode in the Clock
  297. * Control register.
  298. */
  299. clk = SDHCI_PROG_CLOCK_MODE;
  300. div--;
  301. } else {
  302. /* Version 3.00 divisors must be a multiple of 2. */
  303. if (host->max_clk <= clock) {
  304. div = 1;
  305. } else {
  306. for (div = 2;
  307. div < SDHCI_MAX_DIV_SPEC_300;
  308. div += 2) {
  309. if ((host->max_clk / div) <= clock)
  310. break;
  311. }
  312. }
  313. div >>= 1;
  314. }
  315. } else {
  316. /* Version 2.00 divisors must be a power of 2. */
  317. for (div = 1; div < SDHCI_MAX_DIV_SPEC_200; div *= 2) {
  318. if ((host->max_clk / div) <= clock)
  319. break;
  320. }
  321. div >>= 1;
  322. }
  323. if (host->ops && host->ops->set_clock)
  324. host->ops->set_clock(host, div);
  325. clk |= (div & SDHCI_DIV_MASK) << SDHCI_DIVIDER_SHIFT;
  326. clk |= ((div & SDHCI_DIV_HI_MASK) >> SDHCI_DIV_MASK_LEN)
  327. << SDHCI_DIVIDER_HI_SHIFT;
  328. clk |= SDHCI_CLOCK_INT_EN;
  329. sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
  330. /* Wait max 20 ms */
  331. timeout = 20;
  332. while (!((clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL))
  333. & SDHCI_CLOCK_INT_STABLE)) {
  334. if (timeout == 0) {
  335. printf("%s: Internal clock never stabilised.\n",
  336. __func__);
  337. return -EBUSY;
  338. }
  339. timeout--;
  340. udelay(1000);
  341. }
  342. clk |= SDHCI_CLOCK_CARD_EN;
  343. sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL);
  344. return 0;
  345. }
  346. static void sdhci_set_power(struct sdhci_host *host, unsigned short power)
  347. {
  348. u8 pwr = 0;
  349. if (power != (unsigned short)-1) {
  350. switch (1 << power) {
  351. case MMC_VDD_165_195:
  352. pwr = SDHCI_POWER_180;
  353. break;
  354. case MMC_VDD_29_30:
  355. case MMC_VDD_30_31:
  356. pwr = SDHCI_POWER_300;
  357. break;
  358. case MMC_VDD_32_33:
  359. case MMC_VDD_33_34:
  360. pwr = SDHCI_POWER_330;
  361. break;
  362. }
  363. }
  364. if (pwr == 0) {
  365. sdhci_writeb(host, 0, SDHCI_POWER_CONTROL);
  366. return;
  367. }
  368. pwr |= SDHCI_POWER_ON;
  369. sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL);
  370. }
  371. #ifdef CONFIG_DM_MMC_OPS
  372. static int sdhci_set_ios(struct udevice *dev)
  373. {
  374. struct mmc *mmc = mmc_get_mmc_dev(dev);
  375. #else
  376. static int sdhci_set_ios(struct mmc *mmc)
  377. {
  378. #endif
  379. u32 ctrl;
  380. struct sdhci_host *host = mmc->priv;
  381. if (host->ops && host->ops->set_control_reg)
  382. host->ops->set_control_reg(host);
  383. if (mmc->clock != host->clock)
  384. sdhci_set_clock(mmc, mmc->clock);
  385. /* Set bus width */
  386. ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL);
  387. if (mmc->bus_width == 8) {
  388. ctrl &= ~SDHCI_CTRL_4BITBUS;
  389. if ((SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) ||
  390. (host->quirks & SDHCI_QUIRK_USE_WIDE8))
  391. ctrl |= SDHCI_CTRL_8BITBUS;
  392. } else {
  393. if ((SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) ||
  394. (host->quirks & SDHCI_QUIRK_USE_WIDE8))
  395. ctrl &= ~SDHCI_CTRL_8BITBUS;
  396. if (mmc->bus_width == 4)
  397. ctrl |= SDHCI_CTRL_4BITBUS;
  398. else
  399. ctrl &= ~SDHCI_CTRL_4BITBUS;
  400. }
  401. if (mmc->clock > 26000000)
  402. ctrl |= SDHCI_CTRL_HISPD;
  403. else
  404. ctrl &= ~SDHCI_CTRL_HISPD;
  405. if (host->quirks & SDHCI_QUIRK_NO_HISPD_BIT)
  406. ctrl &= ~SDHCI_CTRL_HISPD;
  407. sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL);
  408. return 0;
  409. }
  410. static int sdhci_init(struct mmc *mmc)
  411. {
  412. struct sdhci_host *host = mmc->priv;
  413. sdhci_reset(host, SDHCI_RESET_ALL);
  414. if ((host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) && !aligned_buffer) {
  415. aligned_buffer = memalign(8, 512*1024);
  416. if (!aligned_buffer) {
  417. printf("%s: Aligned buffer alloc failed!!!\n",
  418. __func__);
  419. return -ENOMEM;
  420. }
  421. }
  422. sdhci_set_power(host, fls(mmc->cfg->voltages) - 1);
  423. if (host->ops && host->ops->get_cd)
  424. host->ops->get_cd(host);
  425. /* Enable only interrupts served by the SD controller */
  426. sdhci_writel(host, SDHCI_INT_DATA_MASK | SDHCI_INT_CMD_MASK,
  427. SDHCI_INT_ENABLE);
  428. /* Mask all sdhci interrupt sources */
  429. sdhci_writel(host, 0x0, SDHCI_SIGNAL_ENABLE);
  430. return 0;
  431. }
  432. #ifdef CONFIG_DM_MMC_OPS
  433. int sdhci_probe(struct udevice *dev)
  434. {
  435. struct mmc *mmc = mmc_get_mmc_dev(dev);
  436. return sdhci_init(mmc);
  437. }
  438. const struct dm_mmc_ops sdhci_ops = {
  439. .send_cmd = sdhci_send_command,
  440. .set_ios = sdhci_set_ios,
  441. };
  442. #else
  443. static const struct mmc_ops sdhci_ops = {
  444. .send_cmd = sdhci_send_command,
  445. .set_ios = sdhci_set_ios,
  446. .init = sdhci_init,
  447. };
  448. #endif
  449. int sdhci_setup_cfg(struct mmc_config *cfg, struct sdhci_host *host,
  450. u32 f_max, u32 f_min)
  451. {
  452. u32 caps, caps_1;
  453. caps = sdhci_readl(host, SDHCI_CAPABILITIES);
  454. #ifdef CONFIG_MMC_SDHCI_SDMA
  455. if (!(caps & SDHCI_CAN_DO_SDMA)) {
  456. printf("%s: Your controller doesn't support SDMA!!\n",
  457. __func__);
  458. return -EINVAL;
  459. }
  460. #endif
  461. if (host->quirks & SDHCI_QUIRK_REG32_RW)
  462. host->version =
  463. sdhci_readl(host, SDHCI_HOST_VERSION - 2) >> 16;
  464. else
  465. host->version = sdhci_readw(host, SDHCI_HOST_VERSION);
  466. cfg->name = host->name;
  467. #ifndef CONFIG_DM_MMC_OPS
  468. cfg->ops = &sdhci_ops;
  469. #endif
  470. if (host->max_clk == 0) {
  471. if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300)
  472. host->max_clk = (caps & SDHCI_CLOCK_V3_BASE_MASK) >>
  473. SDHCI_CLOCK_BASE_SHIFT;
  474. else
  475. host->max_clk = (caps & SDHCI_CLOCK_BASE_MASK) >>
  476. SDHCI_CLOCK_BASE_SHIFT;
  477. host->max_clk *= 1000000;
  478. }
  479. if (host->max_clk == 0) {
  480. printf("%s: Hardware doesn't specify base clock frequency\n",
  481. __func__);
  482. return -EINVAL;
  483. }
  484. if (f_max && (f_max < host->max_clk))
  485. cfg->f_max = f_max;
  486. else
  487. cfg->f_max = host->max_clk;
  488. if (f_min)
  489. cfg->f_min = f_min;
  490. else {
  491. if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300)
  492. cfg->f_min = cfg->f_max / SDHCI_MAX_DIV_SPEC_300;
  493. else
  494. cfg->f_min = cfg->f_max / SDHCI_MAX_DIV_SPEC_200;
  495. }
  496. cfg->voltages = 0;
  497. if (caps & SDHCI_CAN_VDD_330)
  498. cfg->voltages |= MMC_VDD_32_33 | MMC_VDD_33_34;
  499. if (caps & SDHCI_CAN_VDD_300)
  500. cfg->voltages |= MMC_VDD_29_30 | MMC_VDD_30_31;
  501. if (caps & SDHCI_CAN_VDD_180)
  502. cfg->voltages |= MMC_VDD_165_195;
  503. if (host->quirks & SDHCI_QUIRK_BROKEN_VOLTAGE)
  504. cfg->voltages |= host->voltages;
  505. cfg->host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_4BIT;
  506. /* Since Host Controller Version3.0 */
  507. if (SDHCI_GET_VERSION(host) >= SDHCI_SPEC_300) {
  508. if (!(caps & SDHCI_CAN_DO_8BIT))
  509. cfg->host_caps &= ~MMC_MODE_8BIT;
  510. /* Find out whether clock multiplier is supported */
  511. caps_1 = sdhci_readl(host, SDHCI_CAPABILITIES_1);
  512. host->clk_mul = (caps_1 & SDHCI_CLOCK_MUL_MASK) >>
  513. SDHCI_CLOCK_MUL_SHIFT;
  514. }
  515. if (host->host_caps)
  516. cfg->host_caps |= host->host_caps;
  517. cfg->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
  518. return 0;
  519. }
  520. #ifdef CONFIG_BLK
  521. int sdhci_bind(struct udevice *dev, struct mmc *mmc, struct mmc_config *cfg)
  522. {
  523. return mmc_bind(dev, mmc, cfg);
  524. }
  525. #else
  526. int add_sdhci(struct sdhci_host *host, u32 f_max, u32 f_min)
  527. {
  528. int ret;
  529. ret = sdhci_setup_cfg(&host->cfg, host, f_max, f_min);
  530. if (ret)
  531. return ret;
  532. host->mmc = mmc_create(&host->cfg, host);
  533. if (host->mmc == NULL) {
  534. printf("%s: mmc create fail!\n", __func__);
  535. return -ENOMEM;
  536. }
  537. return 0;
  538. }
  539. #endif