sh_mmcif.c 15 KB

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