sh_mmcif.c 15 KB

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