sh_mmcif.c 15 KB

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