omap_hsmmc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646
  1. /*
  2. * (C) Copyright 2008
  3. * Texas Instruments, <www.ti.com>
  4. * Sukumar Ghorai <s-ghorai@ti.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation's version 2 of
  12. * the License.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <config.h>
  25. #include <common.h>
  26. #include <mmc.h>
  27. #include <part.h>
  28. #include <i2c.h>
  29. #include <twl4030.h>
  30. #include <twl6030.h>
  31. #include <twl6035.h>
  32. #include <asm/gpio.h>
  33. #include <asm/io.h>
  34. #include <asm/arch/mmc_host_def.h>
  35. #include <asm/arch/sys_proto.h>
  36. /* common definitions for all OMAPs */
  37. #define SYSCTL_SRC (1 << 25)
  38. #define SYSCTL_SRD (1 << 26)
  39. struct omap_hsmmc_data {
  40. struct hsmmc *base_addr;
  41. int cd_gpio;
  42. };
  43. /* If we fail after 1 second wait, something is really bad */
  44. #define MAX_RETRY_MS 1000
  45. static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size);
  46. static int mmc_write_data(struct hsmmc *mmc_base, const char *buf,
  47. unsigned int siz);
  48. static struct mmc hsmmc_dev[3];
  49. static struct omap_hsmmc_data hsmmc_dev_data[3];
  50. #if (defined(CONFIG_OMAP_GPIO) && !defined(CONFIG_SPL_BUILD)) || \
  51. (defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_GPIO_SUPPORT))
  52. static int omap_mmc_setup_gpio_in(int gpio, const char *label)
  53. {
  54. if (!gpio_is_valid(gpio))
  55. return -1;
  56. if (gpio_request(gpio, label) < 0)
  57. return -1;
  58. if (gpio_direction_input(gpio) < 0)
  59. return -1;
  60. return gpio;
  61. }
  62. static int omap_mmc_getcd(struct mmc *mmc)
  63. {
  64. int cd_gpio = ((struct omap_hsmmc_data *)mmc->priv)->cd_gpio;
  65. return gpio_get_value(cd_gpio);
  66. }
  67. #else
  68. static inline int omap_mmc_setup_gpio_in(int gpio, const char *label)
  69. {
  70. return -1;
  71. }
  72. #define omap_mmc_getcd NULL
  73. #endif
  74. #if defined(CONFIG_OMAP44XX) && defined(CONFIG_TWL6030_POWER)
  75. static void omap4_vmmc_pbias_config(struct mmc *mmc)
  76. {
  77. u32 value = 0;
  78. struct omap_sys_ctrl_regs *const ctrl =
  79. (struct omap_sys_ctrl_regs *) SYSCTRL_GENERAL_CORE_BASE;
  80. value = readl(&ctrl->control_pbiaslite);
  81. value &= ~(MMC1_PBIASLITE_PWRDNZ | MMC1_PWRDNZ);
  82. writel(value, &ctrl->control_pbiaslite);
  83. /* set VMMC to 3V */
  84. twl6030_power_mmc_init();
  85. value = readl(&ctrl->control_pbiaslite);
  86. value |= MMC1_PBIASLITE_VMODE | MMC1_PBIASLITE_PWRDNZ | MMC1_PWRDNZ;
  87. writel(value, &ctrl->control_pbiaslite);
  88. }
  89. #endif
  90. #if defined(CONFIG_OMAP54XX) && defined(CONFIG_TWL6035_POWER)
  91. static void omap5_pbias_config(struct mmc *mmc)
  92. {
  93. u32 value = 0;
  94. struct omap_sys_ctrl_regs *const ctrl =
  95. (struct omap_sys_ctrl_regs *) SYSCTRL_GENERAL_CORE_BASE;
  96. value = readl(&ctrl->control_pbias);
  97. value &= ~(SDCARD_PWRDNZ | SDCARD_BIAS_PWRDNZ);
  98. value |= SDCARD_BIAS_HIZ_MODE;
  99. writel(value, &ctrl->control_pbias);
  100. twl6035_mmc1_poweron_ldo();
  101. value = readl(&ctrl->control_pbias);
  102. value &= ~SDCARD_BIAS_HIZ_MODE;
  103. value |= SDCARD_PBIASLITE_VMODE | SDCARD_PWRDNZ | SDCARD_BIAS_PWRDNZ;
  104. writel(value, &ctrl->control_pbias);
  105. value = readl(&ctrl->control_pbias);
  106. if (value & (1 << 23)) {
  107. value &= ~(SDCARD_PWRDNZ | SDCARD_BIAS_PWRDNZ);
  108. value |= SDCARD_BIAS_HIZ_MODE;
  109. writel(value, &ctrl->control_pbias);
  110. }
  111. }
  112. #endif
  113. unsigned char mmc_board_init(struct mmc *mmc)
  114. {
  115. #if defined(CONFIG_OMAP34XX)
  116. t2_t *t2_base = (t2_t *)T2_BASE;
  117. struct prcm *prcm_base = (struct prcm *)PRCM_BASE;
  118. u32 pbias_lite;
  119. pbias_lite = readl(&t2_base->pbias_lite);
  120. pbias_lite &= ~(PBIASLITEPWRDNZ1 | PBIASLITEPWRDNZ0);
  121. writel(pbias_lite, &t2_base->pbias_lite);
  122. #endif
  123. #if defined(CONFIG_TWL4030_POWER)
  124. twl4030_power_mmc_init();
  125. mdelay(100); /* ramp-up delay from Linux code */
  126. #endif
  127. #if defined(CONFIG_OMAP34XX)
  128. writel(pbias_lite | PBIASLITEPWRDNZ1 |
  129. PBIASSPEEDCTRL0 | PBIASLITEPWRDNZ0,
  130. &t2_base->pbias_lite);
  131. writel(readl(&t2_base->devconf0) | MMCSDIO1ADPCLKISEL,
  132. &t2_base->devconf0);
  133. writel(readl(&t2_base->devconf1) | MMCSDIO2ADPCLKISEL,
  134. &t2_base->devconf1);
  135. /* Change from default of 52MHz to 26MHz if necessary */
  136. if (!(mmc->host_caps & MMC_MODE_HS_52MHz))
  137. writel(readl(&t2_base->ctl_prog_io1) & ~CTLPROGIO1SPEEDCTRL,
  138. &t2_base->ctl_prog_io1);
  139. writel(readl(&prcm_base->fclken1_core) |
  140. EN_MMC1 | EN_MMC2 | EN_MMC3,
  141. &prcm_base->fclken1_core);
  142. writel(readl(&prcm_base->iclken1_core) |
  143. EN_MMC1 | EN_MMC2 | EN_MMC3,
  144. &prcm_base->iclken1_core);
  145. #endif
  146. #if defined(CONFIG_OMAP44XX) && defined(CONFIG_TWL6030_POWER)
  147. /* PBIAS config needed for MMC1 only */
  148. if (mmc->block_dev.dev == 0)
  149. omap4_vmmc_pbias_config(mmc);
  150. #endif
  151. #if defined(CONFIG_OMAP54XX) && defined(CONFIG_TWL6035_POWER)
  152. if (mmc->block_dev.dev == 0)
  153. omap5_pbias_config(mmc);
  154. #endif
  155. return 0;
  156. }
  157. void mmc_init_stream(struct hsmmc *mmc_base)
  158. {
  159. ulong start;
  160. writel(readl(&mmc_base->con) | INIT_INITSTREAM, &mmc_base->con);
  161. writel(MMC_CMD0, &mmc_base->cmd);
  162. start = get_timer(0);
  163. while (!(readl(&mmc_base->stat) & CC_MASK)) {
  164. if (get_timer(0) - start > MAX_RETRY_MS) {
  165. printf("%s: timedout waiting for cc!\n", __func__);
  166. return;
  167. }
  168. }
  169. writel(CC_MASK, &mmc_base->stat)
  170. ;
  171. writel(MMC_CMD0, &mmc_base->cmd)
  172. ;
  173. start = get_timer(0);
  174. while (!(readl(&mmc_base->stat) & CC_MASK)) {
  175. if (get_timer(0) - start > MAX_RETRY_MS) {
  176. printf("%s: timedout waiting for cc2!\n", __func__);
  177. return;
  178. }
  179. }
  180. writel(readl(&mmc_base->con) & ~INIT_INITSTREAM, &mmc_base->con);
  181. }
  182. static int mmc_init_setup(struct mmc *mmc)
  183. {
  184. struct hsmmc *mmc_base;
  185. unsigned int reg_val;
  186. unsigned int dsor;
  187. ulong start;
  188. mmc_base = ((struct omap_hsmmc_data *)mmc->priv)->base_addr;
  189. mmc_board_init(mmc);
  190. writel(readl(&mmc_base->sysconfig) | MMC_SOFTRESET,
  191. &mmc_base->sysconfig);
  192. start = get_timer(0);
  193. while ((readl(&mmc_base->sysstatus) & RESETDONE) == 0) {
  194. if (get_timer(0) - start > MAX_RETRY_MS) {
  195. printf("%s: timedout waiting for cc2!\n", __func__);
  196. return TIMEOUT;
  197. }
  198. }
  199. writel(readl(&mmc_base->sysctl) | SOFTRESETALL, &mmc_base->sysctl);
  200. start = get_timer(0);
  201. while ((readl(&mmc_base->sysctl) & SOFTRESETALL) != 0x0) {
  202. if (get_timer(0) - start > MAX_RETRY_MS) {
  203. printf("%s: timedout waiting for softresetall!\n",
  204. __func__);
  205. return TIMEOUT;
  206. }
  207. }
  208. writel(DTW_1_BITMODE | SDBP_PWROFF | SDVS_3V0, &mmc_base->hctl);
  209. writel(readl(&mmc_base->capa) | VS30_3V0SUP | VS18_1V8SUP,
  210. &mmc_base->capa);
  211. reg_val = readl(&mmc_base->con) & RESERVED_MASK;
  212. writel(CTPL_MMC_SD | reg_val | WPP_ACTIVEHIGH | CDP_ACTIVEHIGH |
  213. MIT_CTO | DW8_1_4BITMODE | MODE_FUNC | STR_BLOCK |
  214. HR_NOHOSTRESP | INIT_NOINIT | NOOPENDRAIN, &mmc_base->con);
  215. dsor = 240;
  216. mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK | CEN_MASK),
  217. (ICE_STOP | DTO_15THDTO | CEN_DISABLE));
  218. mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK,
  219. (dsor << CLKD_OFFSET) | ICE_OSCILLATE);
  220. start = get_timer(0);
  221. while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) {
  222. if (get_timer(0) - start > MAX_RETRY_MS) {
  223. printf("%s: timedout waiting for ics!\n", __func__);
  224. return TIMEOUT;
  225. }
  226. }
  227. writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl);
  228. writel(readl(&mmc_base->hctl) | SDBP_PWRON, &mmc_base->hctl);
  229. writel(IE_BADA | IE_CERR | IE_DEB | IE_DCRC | IE_DTO | IE_CIE |
  230. IE_CEB | IE_CCRC | IE_CTO | IE_BRR | IE_BWR | IE_TC | IE_CC,
  231. &mmc_base->ie);
  232. mmc_init_stream(mmc_base);
  233. return 0;
  234. }
  235. /*
  236. * MMC controller internal finite state machine reset
  237. *
  238. * Used to reset command or data internal state machines, using respectively
  239. * SRC or SRD bit of SYSCTL register
  240. */
  241. static void mmc_reset_controller_fsm(struct hsmmc *mmc_base, u32 bit)
  242. {
  243. ulong start;
  244. mmc_reg_out(&mmc_base->sysctl, bit, bit);
  245. start = get_timer(0);
  246. while ((readl(&mmc_base->sysctl) & bit) != 0) {
  247. if (get_timer(0) - start > MAX_RETRY_MS) {
  248. printf("%s: timedout waiting for sysctl %x to clear\n",
  249. __func__, bit);
  250. return;
  251. }
  252. }
  253. }
  254. static int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
  255. struct mmc_data *data)
  256. {
  257. struct hsmmc *mmc_base;
  258. unsigned int flags, mmc_stat;
  259. ulong start;
  260. mmc_base = ((struct omap_hsmmc_data *)mmc->priv)->base_addr;
  261. start = get_timer(0);
  262. while ((readl(&mmc_base->pstate) & (DATI_MASK | CMDI_MASK)) != 0) {
  263. if (get_timer(0) - start > MAX_RETRY_MS) {
  264. printf("%s: timedout waiting on cmd inhibit to clear\n",
  265. __func__);
  266. return TIMEOUT;
  267. }
  268. }
  269. writel(0xFFFFFFFF, &mmc_base->stat);
  270. start = get_timer(0);
  271. while (readl(&mmc_base->stat)) {
  272. if (get_timer(0) - start > MAX_RETRY_MS) {
  273. printf("%s: timedout waiting for STAT (%x) to clear\n",
  274. __func__, readl(&mmc_base->stat));
  275. return TIMEOUT;
  276. }
  277. }
  278. /*
  279. * CMDREG
  280. * CMDIDX[13:8] : Command index
  281. * DATAPRNT[5] : Data Present Select
  282. * ENCMDIDX[4] : Command Index Check Enable
  283. * ENCMDCRC[3] : Command CRC Check Enable
  284. * RSPTYP[1:0]
  285. * 00 = No Response
  286. * 01 = Length 136
  287. * 10 = Length 48
  288. * 11 = Length 48 Check busy after response
  289. */
  290. /* Delay added before checking the status of frq change
  291. * retry not supported by mmc.c(core file)
  292. */
  293. if (cmd->cmdidx == SD_CMD_APP_SEND_SCR)
  294. udelay(50000); /* wait 50 ms */
  295. if (!(cmd->resp_type & MMC_RSP_PRESENT))
  296. flags = 0;
  297. else if (cmd->resp_type & MMC_RSP_136)
  298. flags = RSP_TYPE_LGHT136 | CICE_NOCHECK;
  299. else if (cmd->resp_type & MMC_RSP_BUSY)
  300. flags = RSP_TYPE_LGHT48B;
  301. else
  302. flags = RSP_TYPE_LGHT48;
  303. /* enable default flags */
  304. flags = flags | (CMD_TYPE_NORMAL | CICE_NOCHECK | CCCE_NOCHECK |
  305. MSBS_SGLEBLK | ACEN_DISABLE | BCE_DISABLE | DE_DISABLE);
  306. if (cmd->resp_type & MMC_RSP_CRC)
  307. flags |= CCCE_CHECK;
  308. if (cmd->resp_type & MMC_RSP_OPCODE)
  309. flags |= CICE_CHECK;
  310. if (data) {
  311. if ((cmd->cmdidx == MMC_CMD_READ_MULTIPLE_BLOCK) ||
  312. (cmd->cmdidx == MMC_CMD_WRITE_MULTIPLE_BLOCK)) {
  313. flags |= (MSBS_MULTIBLK | BCE_ENABLE);
  314. data->blocksize = 512;
  315. writel(data->blocksize | (data->blocks << 16),
  316. &mmc_base->blk);
  317. } else
  318. writel(data->blocksize | NBLK_STPCNT, &mmc_base->blk);
  319. if (data->flags & MMC_DATA_READ)
  320. flags |= (DP_DATA | DDIR_READ);
  321. else
  322. flags |= (DP_DATA | DDIR_WRITE);
  323. }
  324. writel(cmd->cmdarg, &mmc_base->arg);
  325. writel((cmd->cmdidx << 24) | flags, &mmc_base->cmd);
  326. start = get_timer(0);
  327. do {
  328. mmc_stat = readl(&mmc_base->stat);
  329. if (get_timer(0) - start > MAX_RETRY_MS) {
  330. printf("%s : timeout: No status update\n", __func__);
  331. return TIMEOUT;
  332. }
  333. } while (!mmc_stat);
  334. if ((mmc_stat & IE_CTO) != 0) {
  335. mmc_reset_controller_fsm(mmc_base, SYSCTL_SRC);
  336. return TIMEOUT;
  337. } else if ((mmc_stat & ERRI_MASK) != 0)
  338. return -1;
  339. if (mmc_stat & CC_MASK) {
  340. writel(CC_MASK, &mmc_base->stat);
  341. if (cmd->resp_type & MMC_RSP_PRESENT) {
  342. if (cmd->resp_type & MMC_RSP_136) {
  343. /* response type 2 */
  344. cmd->response[3] = readl(&mmc_base->rsp10);
  345. cmd->response[2] = readl(&mmc_base->rsp32);
  346. cmd->response[1] = readl(&mmc_base->rsp54);
  347. cmd->response[0] = readl(&mmc_base->rsp76);
  348. } else
  349. /* response types 1, 1b, 3, 4, 5, 6 */
  350. cmd->response[0] = readl(&mmc_base->rsp10);
  351. }
  352. }
  353. if (data && (data->flags & MMC_DATA_READ)) {
  354. mmc_read_data(mmc_base, data->dest,
  355. data->blocksize * data->blocks);
  356. } else if (data && (data->flags & MMC_DATA_WRITE)) {
  357. mmc_write_data(mmc_base, data->src,
  358. data->blocksize * data->blocks);
  359. }
  360. return 0;
  361. }
  362. static int mmc_read_data(struct hsmmc *mmc_base, char *buf, unsigned int size)
  363. {
  364. unsigned int *output_buf = (unsigned int *)buf;
  365. unsigned int mmc_stat;
  366. unsigned int count;
  367. /*
  368. * Start Polled Read
  369. */
  370. count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size;
  371. count /= 4;
  372. while (size) {
  373. ulong start = get_timer(0);
  374. do {
  375. mmc_stat = readl(&mmc_base->stat);
  376. if (get_timer(0) - start > MAX_RETRY_MS) {
  377. printf("%s: timedout waiting for status!\n",
  378. __func__);
  379. return TIMEOUT;
  380. }
  381. } while (mmc_stat == 0);
  382. if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0)
  383. mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD);
  384. if ((mmc_stat & ERRI_MASK) != 0)
  385. return 1;
  386. if (mmc_stat & BRR_MASK) {
  387. unsigned int k;
  388. writel(readl(&mmc_base->stat) | BRR_MASK,
  389. &mmc_base->stat);
  390. for (k = 0; k < count; k++) {
  391. *output_buf = readl(&mmc_base->data);
  392. output_buf++;
  393. }
  394. size -= (count*4);
  395. }
  396. if (mmc_stat & BWR_MASK)
  397. writel(readl(&mmc_base->stat) | BWR_MASK,
  398. &mmc_base->stat);
  399. if (mmc_stat & TC_MASK) {
  400. writel(readl(&mmc_base->stat) | TC_MASK,
  401. &mmc_base->stat);
  402. break;
  403. }
  404. }
  405. return 0;
  406. }
  407. static int mmc_write_data(struct hsmmc *mmc_base, const char *buf,
  408. unsigned int size)
  409. {
  410. unsigned int *input_buf = (unsigned int *)buf;
  411. unsigned int mmc_stat;
  412. unsigned int count;
  413. /*
  414. * Start Polled Read
  415. */
  416. count = (size > MMCSD_SECTOR_SIZE) ? MMCSD_SECTOR_SIZE : size;
  417. count /= 4;
  418. while (size) {
  419. ulong start = get_timer(0);
  420. do {
  421. mmc_stat = readl(&mmc_base->stat);
  422. if (get_timer(0) - start > MAX_RETRY_MS) {
  423. printf("%s: timedout waiting for status!\n",
  424. __func__);
  425. return TIMEOUT;
  426. }
  427. } while (mmc_stat == 0);
  428. if ((mmc_stat & (IE_DTO | IE_DCRC | IE_DEB)) != 0)
  429. mmc_reset_controller_fsm(mmc_base, SYSCTL_SRD);
  430. if ((mmc_stat & ERRI_MASK) != 0)
  431. return 1;
  432. if (mmc_stat & BWR_MASK) {
  433. unsigned int k;
  434. writel(readl(&mmc_base->stat) | BWR_MASK,
  435. &mmc_base->stat);
  436. for (k = 0; k < count; k++) {
  437. writel(*input_buf, &mmc_base->data);
  438. input_buf++;
  439. }
  440. size -= (count*4);
  441. }
  442. if (mmc_stat & BRR_MASK)
  443. writel(readl(&mmc_base->stat) | BRR_MASK,
  444. &mmc_base->stat);
  445. if (mmc_stat & TC_MASK) {
  446. writel(readl(&mmc_base->stat) | TC_MASK,
  447. &mmc_base->stat);
  448. break;
  449. }
  450. }
  451. return 0;
  452. }
  453. static void mmc_set_ios(struct mmc *mmc)
  454. {
  455. struct hsmmc *mmc_base;
  456. unsigned int dsor = 0;
  457. ulong start;
  458. mmc_base = ((struct omap_hsmmc_data *)mmc->priv)->base_addr;
  459. /* configue bus width */
  460. switch (mmc->bus_width) {
  461. case 8:
  462. writel(readl(&mmc_base->con) | DTW_8_BITMODE,
  463. &mmc_base->con);
  464. break;
  465. case 4:
  466. writel(readl(&mmc_base->con) & ~DTW_8_BITMODE,
  467. &mmc_base->con);
  468. writel(readl(&mmc_base->hctl) | DTW_4_BITMODE,
  469. &mmc_base->hctl);
  470. break;
  471. case 1:
  472. default:
  473. writel(readl(&mmc_base->con) & ~DTW_8_BITMODE,
  474. &mmc_base->con);
  475. writel(readl(&mmc_base->hctl) & ~DTW_4_BITMODE,
  476. &mmc_base->hctl);
  477. break;
  478. }
  479. /* configure clock with 96Mhz system clock.
  480. */
  481. if (mmc->clock != 0) {
  482. dsor = (MMC_CLOCK_REFERENCE * 1000000 / mmc->clock);
  483. if ((MMC_CLOCK_REFERENCE * 1000000) / dsor > mmc->clock)
  484. dsor++;
  485. }
  486. mmc_reg_out(&mmc_base->sysctl, (ICE_MASK | DTO_MASK | CEN_MASK),
  487. (ICE_STOP | DTO_15THDTO | CEN_DISABLE));
  488. mmc_reg_out(&mmc_base->sysctl, ICE_MASK | CLKD_MASK,
  489. (dsor << CLKD_OFFSET) | ICE_OSCILLATE);
  490. start = get_timer(0);
  491. while ((readl(&mmc_base->sysctl) & ICS_MASK) == ICS_NOTREADY) {
  492. if (get_timer(0) - start > MAX_RETRY_MS) {
  493. printf("%s: timedout waiting for ics!\n", __func__);
  494. return;
  495. }
  496. }
  497. writel(readl(&mmc_base->sysctl) | CEN_ENABLE, &mmc_base->sysctl);
  498. }
  499. int omap_mmc_init(int dev_index, uint host_caps_mask, uint f_max, int cd_gpio)
  500. {
  501. struct mmc *mmc = &hsmmc_dev[dev_index];
  502. struct omap_hsmmc_data *priv_data = &hsmmc_dev_data[dev_index];
  503. sprintf(mmc->name, "OMAP SD/MMC");
  504. mmc->send_cmd = mmc_send_cmd;
  505. mmc->set_ios = mmc_set_ios;
  506. mmc->init = mmc_init_setup;
  507. mmc->getcd = omap_mmc_getcd;
  508. mmc->getwp = NULL;
  509. mmc->priv = priv_data;
  510. switch (dev_index) {
  511. case 0:
  512. priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE;
  513. break;
  514. #ifdef OMAP_HSMMC2_BASE
  515. case 1:
  516. priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC2_BASE;
  517. break;
  518. #endif
  519. #ifdef OMAP_HSMMC3_BASE
  520. case 2:
  521. priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC3_BASE;
  522. break;
  523. #endif
  524. default:
  525. priv_data->base_addr = (struct hsmmc *)OMAP_HSMMC1_BASE;
  526. return 1;
  527. }
  528. priv_data->cd_gpio = omap_mmc_setup_gpio_in(cd_gpio, "mmc_cd");
  529. mmc->voltages = MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195;
  530. mmc->host_caps = (MMC_MODE_4BIT | MMC_MODE_HS_52MHz | MMC_MODE_HS |
  531. MMC_MODE_HC) & ~host_caps_mask;
  532. mmc->f_min = 400000;
  533. if (f_max != 0)
  534. mmc->f_max = f_max;
  535. else {
  536. if (mmc->host_caps & MMC_MODE_HS) {
  537. if (mmc->host_caps & MMC_MODE_HS_52MHz)
  538. mmc->f_max = 52000000;
  539. else
  540. mmc->f_max = 26000000;
  541. } else
  542. mmc->f_max = 20000000;
  543. }
  544. mmc->b_max = 0;
  545. #if defined(CONFIG_OMAP34XX)
  546. /*
  547. * Silicon revs 2.1 and older do not support multiblock transfers.
  548. */
  549. if ((get_cpu_family() == CPU_OMAP34XX) && (get_cpu_rev() <= CPU_3XX_ES21))
  550. mmc->b_max = 1;
  551. #endif
  552. mmc_register(mmc);
  553. return 0;
  554. }