sh_mmcif.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /*
  2. * MMCIF driver.
  3. *
  4. * Copyright (C) 2011 Renesas Solutions Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License.
  9. */
  10. #include <config.h>
  11. #include <common.h>
  12. #include <watchdog.h>
  13. #include <command.h>
  14. #include <mmc.h>
  15. #include <malloc.h>
  16. #include <asm/errno.h>
  17. #include <asm/io.h>
  18. #include "sh_mmcif.h"
  19. #define DRIVER_NAME "sh_mmcif"
  20. static int sh_mmcif_intr(void *dev_id)
  21. {
  22. struct sh_mmcif_host *host = dev_id;
  23. u32 state = 0;
  24. state = sh_mmcif_read(&host->regs->ce_int);
  25. state &= sh_mmcif_read(&host->regs->ce_int_mask);
  26. if (state & INT_RBSYE) {
  27. sh_mmcif_write(~(INT_RBSYE | INT_CRSPE), &host->regs->ce_int);
  28. sh_mmcif_bitclr(MASK_MRBSYE, &host->regs->ce_int_mask);
  29. goto end;
  30. } else if (state & INT_CRSPE) {
  31. sh_mmcif_write(~INT_CRSPE, &host->regs->ce_int);
  32. sh_mmcif_bitclr(MASK_MCRSPE, &host->regs->ce_int_mask);
  33. /* one more interrupt (INT_RBSYE) */
  34. if (sh_mmcif_read(&host->regs->ce_cmd_set) & CMD_SET_RBSY)
  35. return -EAGAIN;
  36. goto end;
  37. } else if (state & INT_BUFREN) {
  38. sh_mmcif_write(~INT_BUFREN, &host->regs->ce_int);
  39. sh_mmcif_bitclr(MASK_MBUFREN, &host->regs->ce_int_mask);
  40. goto end;
  41. } else if (state & INT_BUFWEN) {
  42. sh_mmcif_write(~INT_BUFWEN, &host->regs->ce_int);
  43. sh_mmcif_bitclr(MASK_MBUFWEN, &host->regs->ce_int_mask);
  44. goto end;
  45. } else if (state & INT_CMD12DRE) {
  46. sh_mmcif_write(~(INT_CMD12DRE | INT_CMD12RBE | INT_CMD12CRE |
  47. INT_BUFRE), &host->regs->ce_int);
  48. sh_mmcif_bitclr(MASK_MCMD12DRE, &host->regs->ce_int_mask);
  49. goto end;
  50. } else if (state & INT_BUFRE) {
  51. sh_mmcif_write(~INT_BUFRE, &host->regs->ce_int);
  52. sh_mmcif_bitclr(MASK_MBUFRE, &host->regs->ce_int_mask);
  53. goto end;
  54. } else if (state & INT_DTRANE) {
  55. sh_mmcif_write(~INT_DTRANE, &host->regs->ce_int);
  56. sh_mmcif_bitclr(MASK_MDTRANE, &host->regs->ce_int_mask);
  57. goto end;
  58. } else if (state & INT_CMD12RBE) {
  59. sh_mmcif_write(~(INT_CMD12RBE | INT_CMD12CRE),
  60. &host->regs->ce_int);
  61. sh_mmcif_bitclr(MASK_MCMD12RBE, &host->regs->ce_int_mask);
  62. goto end;
  63. } else if (state & INT_ERR_STS) {
  64. /* err interrupts */
  65. sh_mmcif_write(~state, &host->regs->ce_int);
  66. sh_mmcif_bitclr(state, &host->regs->ce_int_mask);
  67. goto err;
  68. } else
  69. return -EAGAIN;
  70. err:
  71. host->sd_error = 1;
  72. debug("%s: int err state = %08x\n", DRIVER_NAME, state);
  73. end:
  74. host->wait_int = 1;
  75. return 0;
  76. }
  77. static int mmcif_wait_interrupt_flag(struct sh_mmcif_host *host)
  78. {
  79. int timeout = 10000000;
  80. while (1) {
  81. timeout--;
  82. if (timeout < 0) {
  83. printf("timeout\n");
  84. return 0;
  85. }
  86. if (!sh_mmcif_intr(host))
  87. break;
  88. udelay(1); /* 1 usec */
  89. }
  90. return 1; /* Return value: NOT 0 = complete waiting */
  91. }
  92. static void sh_mmcif_clock_control(struct sh_mmcif_host *host, unsigned int clk)
  93. {
  94. sh_mmcif_bitclr(CLK_ENABLE, &host->regs->ce_clk_ctrl);
  95. sh_mmcif_bitclr(CLK_CLEAR, &host->regs->ce_clk_ctrl);
  96. if (!clk)
  97. return;
  98. if (clk == CLKDEV_EMMC_DATA)
  99. sh_mmcif_bitset(CLK_PCLK, &host->regs->ce_clk_ctrl);
  100. else
  101. sh_mmcif_bitset((fls(DIV_ROUND_UP(host->clk,
  102. clk) - 1) - 1) << 16,
  103. &host->regs->ce_clk_ctrl);
  104. sh_mmcif_bitset(CLK_ENABLE, &host->regs->ce_clk_ctrl);
  105. }
  106. static void sh_mmcif_sync_reset(struct sh_mmcif_host *host)
  107. {
  108. u32 tmp;
  109. tmp = sh_mmcif_read(&host->regs->ce_clk_ctrl) & (CLK_ENABLE |
  110. CLK_CLEAR);
  111. sh_mmcif_write(SOFT_RST_ON, &host->regs->ce_version);
  112. sh_mmcif_write(SOFT_RST_OFF, &host->regs->ce_version);
  113. sh_mmcif_bitset(tmp | SRSPTO_256 | SRBSYTO_29 | SRWDTO_29 | SCCSTO_29,
  114. &host->regs->ce_clk_ctrl);
  115. /* byte swap on */
  116. sh_mmcif_bitset(BUF_ACC_ATYP, &host->regs->ce_buf_acc);
  117. }
  118. static int sh_mmcif_error_manage(struct sh_mmcif_host *host)
  119. {
  120. u32 state1, state2;
  121. int ret, timeout = 10000000;
  122. host->sd_error = 0;
  123. host->wait_int = 0;
  124. state1 = sh_mmcif_read(&host->regs->ce_host_sts1);
  125. state2 = sh_mmcif_read(&host->regs->ce_host_sts2);
  126. debug("%s: ERR HOST_STS1 = %08x\n", \
  127. DRIVER_NAME, sh_mmcif_read(&host->regs->ce_host_sts1));
  128. debug("%s: ERR HOST_STS2 = %08x\n", \
  129. DRIVER_NAME, sh_mmcif_read(&host->regs->ce_host_sts2));
  130. if (state1 & STS1_CMDSEQ) {
  131. debug("%s: Forced end of command sequence\n", DRIVER_NAME);
  132. sh_mmcif_bitset(CMD_CTRL_BREAK, &host->regs->ce_cmd_ctrl);
  133. sh_mmcif_bitset(~CMD_CTRL_BREAK, &host->regs->ce_cmd_ctrl);
  134. while (1) {
  135. timeout--;
  136. if (timeout < 0) {
  137. printf(DRIVER_NAME": Forceed end of " \
  138. "command sequence timeout err\n");
  139. return -EILSEQ;
  140. }
  141. if (!(sh_mmcif_read(&host->regs->ce_host_sts1)
  142. & STS1_CMDSEQ))
  143. break;
  144. }
  145. sh_mmcif_sync_reset(host);
  146. return -EILSEQ;
  147. }
  148. if (state2 & STS2_CRC_ERR)
  149. ret = -EILSEQ;
  150. else if (state2 & STS2_TIMEOUT_ERR)
  151. ret = TIMEOUT;
  152. else
  153. ret = -EILSEQ;
  154. return ret;
  155. }
  156. static int sh_mmcif_single_read(struct sh_mmcif_host *host,
  157. struct mmc_data *data)
  158. {
  159. long time;
  160. u32 blocksize, i;
  161. unsigned long *p = (unsigned long *)data->dest;
  162. if ((unsigned long)p & 0x00000001) {
  163. printf("%s: The data pointer is unaligned.", __func__);
  164. return -EIO;
  165. }
  166. host->wait_int = 0;
  167. /* buf read enable */
  168. sh_mmcif_bitset(MASK_MBUFREN, &host->regs->ce_int_mask);
  169. time = mmcif_wait_interrupt_flag(host);
  170. if (time == 0 || host->sd_error != 0)
  171. return sh_mmcif_error_manage(host);
  172. host->wait_int = 0;
  173. blocksize = (BLOCK_SIZE_MASK &
  174. sh_mmcif_read(&host->regs->ce_block_set)) + 3;
  175. for (i = 0; i < blocksize / 4; i++)
  176. *p++ = sh_mmcif_read(&host->regs->ce_data);
  177. /* buffer read end */
  178. sh_mmcif_bitset(MASK_MBUFRE, &host->regs->ce_int_mask);
  179. time = mmcif_wait_interrupt_flag(host);
  180. if (time == 0 || host->sd_error != 0)
  181. return sh_mmcif_error_manage(host);
  182. host->wait_int = 0;
  183. return 0;
  184. }
  185. static int sh_mmcif_multi_read(struct sh_mmcif_host *host,
  186. struct mmc_data *data)
  187. {
  188. long time;
  189. u32 blocksize, i, j;
  190. unsigned long *p = (unsigned long *)data->dest;
  191. if ((unsigned long)p & 0x00000001) {
  192. printf("%s: The data pointer is unaligned.", __func__);
  193. return -EIO;
  194. }
  195. host->wait_int = 0;
  196. blocksize = BLOCK_SIZE_MASK & sh_mmcif_read(&host->regs->ce_block_set);
  197. for (j = 0; j < data->blocks; j++) {
  198. sh_mmcif_bitset(MASK_MBUFREN, &host->regs->ce_int_mask);
  199. time = mmcif_wait_interrupt_flag(host);
  200. if (time == 0 || host->sd_error != 0)
  201. return sh_mmcif_error_manage(host);
  202. host->wait_int = 0;
  203. for (i = 0; i < blocksize / 4; i++)
  204. *p++ = sh_mmcif_read(&host->regs->ce_data);
  205. WATCHDOG_RESET();
  206. }
  207. return 0;
  208. }
  209. static int sh_mmcif_single_write(struct sh_mmcif_host *host,
  210. struct mmc_data *data)
  211. {
  212. long time;
  213. u32 blocksize, i;
  214. const unsigned long *p = (unsigned long *)data->dest;
  215. if ((unsigned long)p & 0x00000001) {
  216. printf("%s: The data pointer is unaligned.", __func__);
  217. return -EIO;
  218. }
  219. host->wait_int = 0;
  220. sh_mmcif_bitset(MASK_MBUFWEN, &host->regs->ce_int_mask);
  221. time = mmcif_wait_interrupt_flag(host);
  222. if (time == 0 || host->sd_error != 0)
  223. return sh_mmcif_error_manage(host);
  224. host->wait_int = 0;
  225. blocksize = (BLOCK_SIZE_MASK &
  226. sh_mmcif_read(&host->regs->ce_block_set)) + 3;
  227. for (i = 0; i < blocksize / 4; i++)
  228. sh_mmcif_write(*p++, &host->regs->ce_data);
  229. /* buffer write end */
  230. sh_mmcif_bitset(MASK_MDTRANE, &host->regs->ce_int_mask);
  231. time = mmcif_wait_interrupt_flag(host);
  232. if (time == 0 || host->sd_error != 0)
  233. return sh_mmcif_error_manage(host);
  234. host->wait_int = 0;
  235. return 0;
  236. }
  237. static int sh_mmcif_multi_write(struct sh_mmcif_host *host,
  238. struct mmc_data *data)
  239. {
  240. long time;
  241. u32 i, j, blocksize;
  242. const unsigned long *p = (unsigned long *)data->dest;
  243. if ((unsigned long)p & 0x00000001) {
  244. printf("%s: The data pointer is unaligned.", __func__);
  245. return -EIO;
  246. }
  247. host->wait_int = 0;
  248. blocksize = BLOCK_SIZE_MASK & sh_mmcif_read(&host->regs->ce_block_set);
  249. for (j = 0; j < data->blocks; j++) {
  250. sh_mmcif_bitset(MASK_MBUFWEN, &host->regs->ce_int_mask);
  251. time = mmcif_wait_interrupt_flag(host);
  252. if (time == 0 || host->sd_error != 0)
  253. return sh_mmcif_error_manage(host);
  254. host->wait_int = 0;
  255. for (i = 0; i < blocksize / 4; i++)
  256. sh_mmcif_write(*p++, &host->regs->ce_data);
  257. WATCHDOG_RESET();
  258. }
  259. return 0;
  260. }
  261. static void sh_mmcif_get_response(struct sh_mmcif_host *host,
  262. struct mmc_cmd *cmd)
  263. {
  264. if (cmd->resp_type & MMC_RSP_136) {
  265. cmd->response[0] = sh_mmcif_read(&host->regs->ce_resp3);
  266. cmd->response[1] = sh_mmcif_read(&host->regs->ce_resp2);
  267. cmd->response[2] = sh_mmcif_read(&host->regs->ce_resp1);
  268. cmd->response[3] = sh_mmcif_read(&host->regs->ce_resp0);
  269. debug(" RESP %08x, %08x, %08x, %08x\n", cmd->response[0],
  270. cmd->response[1], cmd->response[2], cmd->response[3]);
  271. } else {
  272. cmd->response[0] = sh_mmcif_read(&host->regs->ce_resp0);
  273. }
  274. }
  275. static void sh_mmcif_get_cmd12response(struct sh_mmcif_host *host,
  276. struct mmc_cmd *cmd)
  277. {
  278. cmd->response[0] = sh_mmcif_read(&host->regs->ce_resp_cmd12);
  279. }
  280. static u32 sh_mmcif_set_cmd(struct sh_mmcif_host *host,
  281. struct mmc_data *data, struct mmc_cmd *cmd)
  282. {
  283. u32 tmp = 0;
  284. u32 opc = cmd->cmdidx;
  285. /* Response Type check */
  286. switch (cmd->resp_type) {
  287. case MMC_RSP_NONE:
  288. tmp |= CMD_SET_RTYP_NO;
  289. break;
  290. case MMC_RSP_R1:
  291. case MMC_RSP_R1b:
  292. case MMC_RSP_R3:
  293. tmp |= CMD_SET_RTYP_6B;
  294. break;
  295. case MMC_RSP_R2:
  296. tmp |= CMD_SET_RTYP_17B;
  297. break;
  298. default:
  299. printf(DRIVER_NAME": Not support type response.\n");
  300. break;
  301. }
  302. /* RBSY */
  303. if (opc == MMC_CMD_SWITCH)
  304. tmp |= CMD_SET_RBSY;
  305. /* WDAT / DATW */
  306. if (host->data) {
  307. tmp |= CMD_SET_WDAT;
  308. switch (host->bus_width) {
  309. case MMC_BUS_WIDTH_1:
  310. tmp |= CMD_SET_DATW_1;
  311. break;
  312. case MMC_BUS_WIDTH_4:
  313. tmp |= CMD_SET_DATW_4;
  314. break;
  315. case MMC_BUS_WIDTH_8:
  316. tmp |= CMD_SET_DATW_8;
  317. break;
  318. default:
  319. printf(DRIVER_NAME": Not support bus width.\n");
  320. break;
  321. }
  322. }
  323. /* DWEN */
  324. if (opc == MMC_CMD_WRITE_SINGLE_BLOCK ||
  325. opc == MMC_CMD_WRITE_MULTIPLE_BLOCK)
  326. tmp |= CMD_SET_DWEN;
  327. /* CMLTE/CMD12EN */
  328. if (opc == MMC_CMD_READ_MULTIPLE_BLOCK ||
  329. opc == MMC_CMD_WRITE_MULTIPLE_BLOCK) {
  330. tmp |= CMD_SET_CMLTE | CMD_SET_CMD12EN;
  331. sh_mmcif_bitset(data->blocks << 16, &host->regs->ce_block_set);
  332. }
  333. /* RIDXC[1:0] check bits */
  334. if (opc == MMC_CMD_SEND_OP_COND || opc == MMC_CMD_ALL_SEND_CID ||
  335. opc == MMC_CMD_SEND_CSD || opc == MMC_CMD_SEND_CID)
  336. tmp |= CMD_SET_RIDXC_BITS;
  337. /* RCRC7C[1:0] check bits */
  338. if (opc == MMC_CMD_SEND_OP_COND)
  339. tmp |= CMD_SET_CRC7C_BITS;
  340. /* RCRC7C[1:0] internal CRC7 */
  341. if (opc == MMC_CMD_ALL_SEND_CID ||
  342. opc == MMC_CMD_SEND_CSD || opc == MMC_CMD_SEND_CID)
  343. tmp |= CMD_SET_CRC7C_INTERNAL;
  344. return opc = ((opc << 24) | tmp);
  345. }
  346. static u32 sh_mmcif_data_trans(struct sh_mmcif_host *host,
  347. struct mmc_data *data, u16 opc)
  348. {
  349. u32 ret;
  350. switch (opc) {
  351. case MMC_CMD_READ_MULTIPLE_BLOCK:
  352. ret = sh_mmcif_multi_read(host, data);
  353. break;
  354. case MMC_CMD_WRITE_MULTIPLE_BLOCK:
  355. ret = sh_mmcif_multi_write(host, data);
  356. break;
  357. case MMC_CMD_WRITE_SINGLE_BLOCK:
  358. ret = sh_mmcif_single_write(host, data);
  359. break;
  360. case MMC_CMD_READ_SINGLE_BLOCK:
  361. case MMC_CMD_SEND_EXT_CSD:
  362. ret = sh_mmcif_single_read(host, data);
  363. break;
  364. default:
  365. printf(DRIVER_NAME": NOT SUPPORT CMD = d'%08d\n", opc);
  366. ret = -EINVAL;
  367. break;
  368. }
  369. return ret;
  370. }
  371. static int sh_mmcif_start_cmd(struct sh_mmcif_host *host,
  372. struct mmc_data *data, struct mmc_cmd *cmd)
  373. {
  374. long time;
  375. int ret = 0, mask = 0;
  376. u32 opc = cmd->cmdidx;
  377. if (opc == MMC_CMD_STOP_TRANSMISSION) {
  378. /* MMCIF sends the STOP command automatically */
  379. if (host->last_cmd == MMC_CMD_READ_MULTIPLE_BLOCK)
  380. sh_mmcif_bitset(MASK_MCMD12DRE,
  381. &host->regs->ce_int_mask);
  382. else
  383. sh_mmcif_bitset(MASK_MCMD12RBE,
  384. &host->regs->ce_int_mask);
  385. time = mmcif_wait_interrupt_flag(host);
  386. if (time == 0 || host->sd_error != 0)
  387. return sh_mmcif_error_manage(host);
  388. sh_mmcif_get_cmd12response(host, cmd);
  389. return 0;
  390. }
  391. if (opc == MMC_CMD_SWITCH)
  392. mask = MASK_MRBSYE;
  393. else
  394. mask = MASK_MCRSPE;
  395. mask |= MASK_MCMDVIO | MASK_MBUFVIO | MASK_MWDATERR |
  396. MASK_MRDATERR | MASK_MRIDXERR | MASK_MRSPERR |
  397. MASK_MCCSTO | MASK_MCRCSTO | MASK_MWDATTO |
  398. MASK_MRDATTO | MASK_MRBSYTO | MASK_MRSPTO;
  399. if (host->data) {
  400. sh_mmcif_write(0, &host->regs->ce_block_set);
  401. sh_mmcif_write(data->blocksize, &host->regs->ce_block_set);
  402. }
  403. opc = sh_mmcif_set_cmd(host, data, cmd);
  404. sh_mmcif_write(INT_START_MAGIC, &host->regs->ce_int);
  405. sh_mmcif_write(mask, &host->regs->ce_int_mask);
  406. debug("CMD%d ARG:%08x\n", cmd->cmdidx, cmd->cmdarg);
  407. /* set arg */
  408. sh_mmcif_write(cmd->cmdarg, &host->regs->ce_arg);
  409. host->wait_int = 0;
  410. /* set cmd */
  411. sh_mmcif_write(opc, &host->regs->ce_cmd_set);
  412. time = mmcif_wait_interrupt_flag(host);
  413. if (time == 0)
  414. return sh_mmcif_error_manage(host);
  415. if (host->sd_error) {
  416. switch (cmd->cmdidx) {
  417. case MMC_CMD_ALL_SEND_CID:
  418. case MMC_CMD_SELECT_CARD:
  419. case MMC_CMD_APP_CMD:
  420. ret = TIMEOUT;
  421. break;
  422. default:
  423. printf(DRIVER_NAME": Cmd(d'%d) err\n", cmd->cmdidx);
  424. ret = sh_mmcif_error_manage(host);
  425. break;
  426. }
  427. host->sd_error = 0;
  428. host->wait_int = 0;
  429. return ret;
  430. }
  431. /* if no response */
  432. if (!(opc & 0x00C00000))
  433. return 0;
  434. if (host->wait_int == 1) {
  435. sh_mmcif_get_response(host, cmd);
  436. host->wait_int = 0;
  437. }
  438. if (host->data)
  439. ret = sh_mmcif_data_trans(host, data, cmd->cmdidx);
  440. host->last_cmd = cmd->cmdidx;
  441. return ret;
  442. }
  443. static int sh_mmcif_request(struct mmc *mmc, struct mmc_cmd *cmd,
  444. struct mmc_data *data)
  445. {
  446. struct sh_mmcif_host *host = mmc->priv;
  447. int ret;
  448. WATCHDOG_RESET();
  449. switch (cmd->cmdidx) {
  450. case MMC_CMD_APP_CMD:
  451. return TIMEOUT;
  452. case MMC_CMD_SEND_EXT_CSD: /* = SD_SEND_IF_COND (8) */
  453. if (data)
  454. /* ext_csd */
  455. break;
  456. else
  457. /* send_if_cond cmd (not support) */
  458. return TIMEOUT;
  459. default:
  460. break;
  461. }
  462. host->sd_error = 0;
  463. host->data = data;
  464. ret = sh_mmcif_start_cmd(host, data, cmd);
  465. host->data = NULL;
  466. return ret;
  467. }
  468. static void sh_mmcif_set_ios(struct mmc *mmc)
  469. {
  470. struct sh_mmcif_host *host = mmc->priv;
  471. if (mmc->clock)
  472. sh_mmcif_clock_control(host, mmc->clock);
  473. if (mmc->bus_width == 8)
  474. host->bus_width = MMC_BUS_WIDTH_8;
  475. else if (mmc->bus_width == 4)
  476. host->bus_width = MMC_BUS_WIDTH_4;
  477. else
  478. host->bus_width = MMC_BUS_WIDTH_1;
  479. debug("clock = %d, buswidth = %d\n", mmc->clock, mmc->bus_width);
  480. }
  481. static int sh_mmcif_init(struct mmc *mmc)
  482. {
  483. struct sh_mmcif_host *host = mmc->priv;
  484. sh_mmcif_sync_reset(host);
  485. sh_mmcif_write(MASK_ALL, &host->regs->ce_int_mask);
  486. return 0;
  487. }
  488. static const struct mmc_ops sh_mmcif_ops = {
  489. .send_cmd = sh_mmcif_request,
  490. .set_ios = sh_mmcif_set_ios,
  491. .init = sh_mmcif_init,
  492. };
  493. static struct mmc_config sh_mmcif_cfg = {
  494. .name = DRIVER_NAME,
  495. .ops = &sh_mmcif_ops,
  496. .host_caps = MMC_MODE_HS | MMC_MODE_HS_52MHz | MMC_MODE_4BIT |
  497. MMC_MODE_8BIT,
  498. .voltages = MMC_VDD_32_33 | MMC_VDD_33_34,
  499. .b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT,
  500. };
  501. int mmcif_mmc_init(void)
  502. {
  503. struct mmc *mmc;
  504. struct sh_mmcif_host *host = NULL;
  505. host = malloc(sizeof(struct sh_mmcif_host));
  506. if (!host)
  507. return -ENOMEM;
  508. memset(host, 0, sizeof(*host));
  509. host->regs = (struct sh_mmcif_regs *)CONFIG_SH_MMCIF_ADDR;
  510. host->clk = CONFIG_SH_MMCIF_CLK;
  511. sh_mmcif_cfg.f_min = MMC_CLK_DIV_MIN(host->clk);
  512. sh_mmcif_cfg.f_max = MMC_CLK_DIV_MAX(host->clk);
  513. mmc = mmc_create(&sh_mmcif_cfg, host);
  514. if (mmc == NULL) {
  515. free(host);
  516. return -ENOMEM;
  517. }
  518. return 0;
  519. }