mmc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586
  1. /*
  2. * File : mmc.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2006, RT-Thread Development Team
  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, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2015-06-15 hichard first version
  23. */
  24. #include <drivers/mmcsd_core.h>
  25. #include <drivers/mmc.h>
  26. static const rt_uint32_t tran_unit[] =
  27. {
  28. 10000, 100000, 1000000, 10000000,
  29. 0, 0, 0, 0
  30. };
  31. static const rt_uint8_t tran_value[] =
  32. {
  33. 0, 10, 12, 13, 15, 20, 25, 30,
  34. 35, 40, 45, 50, 55, 60, 70, 80,
  35. };
  36. static const rt_uint32_t tacc_uint[] =
  37. {
  38. 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000,
  39. };
  40. static const rt_uint8_t tacc_value[] =
  41. {
  42. 0, 10, 12, 13, 15, 20, 25, 30,
  43. 35, 40, 45, 50, 55, 60, 70, 80,
  44. };
  45. rt_inline rt_uint32_t GET_BITS(rt_uint32_t *resp,
  46. rt_uint32_t start,
  47. rt_uint32_t size)
  48. {
  49. const rt_int32_t __size = size;
  50. const rt_uint32_t __mask = (__size < 32 ? 1 << __size : 0) - 1;
  51. const rt_int32_t __off = 3 - ((start) / 32);
  52. const rt_int32_t __shft = (start) & 31;
  53. rt_uint32_t __res;
  54. __res = resp[__off] >> __shft;
  55. if (__size + __shft > 32)
  56. __res |= resp[__off-1] << ((32 - __shft) % 32);
  57. return __res & __mask;
  58. }
  59. /*
  60. * Given a 128-bit response, decode to our card CSD structure.
  61. */
  62. static rt_int32_t mmcsd_parse_csd(struct rt_mmcsd_card *card)
  63. {
  64. rt_uint32_t a, b;
  65. struct rt_mmcsd_csd *csd = &card->csd;
  66. rt_uint32_t *resp = card->resp_csd;
  67. /*
  68. * We only understand CSD structure v1.1 and v1.2.
  69. * v1.2 has extra information in bits 15, 11 and 10.
  70. * We also support eMMC v4.4 & v4.41.
  71. */
  72. csd->csd_structure = GET_BITS(resp, 126, 2);
  73. if (csd->csd_structure == 0) {
  74. rt_kprintf("unrecognised CSD structure version %d\n", csd->csd_structure);
  75. return -RT_ERROR;
  76. }
  77. csd->taac = GET_BITS(resp, 112, 8);
  78. csd->nsac = GET_BITS(resp, 104, 8);
  79. csd->tran_speed = GET_BITS(resp, 96, 8);
  80. csd->card_cmd_class = GET_BITS(resp, 84, 12);
  81. csd->rd_blk_len = GET_BITS(resp, 80, 4);
  82. csd->rd_blk_part = GET_BITS(resp, 79, 1);
  83. csd->wr_blk_misalign = GET_BITS(resp, 78, 1);
  84. csd->rd_blk_misalign = GET_BITS(resp, 77, 1);
  85. csd->dsr_imp = GET_BITS(resp, 76, 1);
  86. csd->c_size = GET_BITS(resp, 62, 12);
  87. csd->c_size_mult = GET_BITS(resp, 47, 3);
  88. csd->r2w_factor = GET_BITS(resp, 26, 3);
  89. csd->wr_blk_len = GET_BITS(resp, 22, 4);
  90. csd->wr_blk_partial = GET_BITS(resp, 21, 1);
  91. csd->csd_crc = GET_BITS(resp, 1, 7);
  92. card->card_blksize = 1 << csd->rd_blk_len;
  93. card->tacc_clks = csd->nsac * 100;
  94. card->tacc_ns = (tacc_uint[csd->taac&0x07] * tacc_value[(csd->taac&0x78)>>3] + 9) / 10;
  95. card->max_data_rate = tran_unit[csd->tran_speed&0x07] * tran_value[(csd->tran_speed&0x78)>>3];
  96. if (csd->wr_blk_len >= 9) {
  97. a = GET_BITS(resp, 42, 5);
  98. b = GET_BITS(resp, 37, 5);
  99. card->erase_size = (a + 1) * (b + 1);
  100. card->erase_size <<= csd->wr_blk_len - 9;
  101. }
  102. return 0;
  103. }
  104. /*
  105. * Read extended CSD.
  106. */
  107. static int mmc_get_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t **new_ext_csd)
  108. {
  109. void *ext_csd;
  110. struct rt_mmcsd_req req;
  111. struct rt_mmcsd_cmd cmd;
  112. struct rt_mmcsd_data data;
  113. *new_ext_csd = RT_NULL;
  114. if (GET_BITS(card->resp_cid, 122, 4) < 4)
  115. return 0;
  116. /*
  117. * As the ext_csd is so large and mostly unused, we don't store the
  118. * raw block in mmc_card.
  119. */
  120. ext_csd = rt_malloc(512);
  121. if (!ext_csd) {
  122. rt_kprintf("alloc memory failed when get ext csd\n");
  123. return -RT_ENOMEM;
  124. }
  125. rt_memset(&req, 0, sizeof(struct rt_mmcsd_req));
  126. rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
  127. rt_memset(&data, 0, sizeof(struct rt_mmcsd_data));
  128. req.cmd = &cmd;
  129. req.data = &data;
  130. cmd.cmd_code = SEND_EXT_CSD;
  131. cmd.arg = 0;
  132. /* NOTE HACK: the RESP_SPI_R1 is always correct here, but we
  133. * rely on callers to never use this with "native" calls for reading
  134. * CSD or CID. Native versions of those commands use the R2 type,
  135. * not R1 plus a data block.
  136. */
  137. cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_ADTC;
  138. data.blksize = 512;
  139. data.blks = 1;
  140. data.flags = DATA_DIR_READ;
  141. data.buf = ext_csd;
  142. /*
  143. * Some cards require longer data read timeout than indicated in CSD.
  144. * Address this by setting the read timeout to a "reasonably high"
  145. * value. For the cards tested, 300ms has proven enough. If necessary,
  146. * this value can be increased if other problematic cards require this.
  147. */
  148. data.timeout_ns = 300000000;
  149. data.timeout_clks = 0;
  150. mmcsd_send_request(card->host, &req);
  151. if (cmd.err)
  152. return cmd.err;
  153. if (data.err)
  154. return data.err;
  155. *new_ext_csd = ext_csd;
  156. return 0;
  157. }
  158. /*
  159. * Decode extended CSD.
  160. */
  161. static int mmc_parse_ext_csd(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
  162. {
  163. card->flags |= CARD_FLAG_HIGHSPEED;
  164. card->hs_max_data_rate = 200000000;
  165. card->card_capacity = *((rt_uint32_t *)&ext_csd[EXT_CSD_SEC_CNT]);
  166. card->card_capacity *= card->card_blksize;
  167. card->card_capacity >>= 10; /* unit:KB */
  168. rt_kprintf("emmc card capacity %d KB\n", card->card_capacity);
  169. return 0;
  170. }
  171. /**
  172. * mmc_switch - modify EXT_CSD register
  173. * @card: the MMC card associated with the data transfer
  174. * @set: cmd set values
  175. * @index: EXT_CSD register index
  176. * @value: value to program into EXT_CSD register
  177. *
  178. * Modifies the EXT_CSD register for selected card.
  179. */
  180. static int mmc_switch(struct rt_mmcsd_card *card, rt_uint8_t set,
  181. rt_uint8_t index, rt_uint8_t value)
  182. {
  183. int err;
  184. struct rt_mmcsd_host *host = card->host;
  185. struct rt_mmcsd_cmd cmd = {0};
  186. cmd.cmd_code = SWITCH;
  187. cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) |
  188. (index << 16) | (value << 8) | set;
  189. cmd.flags = RESP_SPI_R1 | RESP_R1 | CMD_AC;
  190. err = mmcsd_send_cmd(host, &cmd, 3);
  191. if (err)
  192. return err;
  193. return 0;
  194. }
  195. static int mmc_compare_ext_csds(struct rt_mmcsd_card *card,
  196. rt_uint8_t *ext_csd, rt_uint32_t bus_width)
  197. {
  198. rt_uint8_t *bw_ext_csd;
  199. int err;
  200. if (bus_width == MMCSD_BUS_WIDTH_1)
  201. return 0;
  202. err = mmc_get_ext_csd(card, &bw_ext_csd);
  203. if (err || bw_ext_csd == RT_NULL) {
  204. err = -RT_ERROR;
  205. goto out;
  206. }
  207. /* only compare read only fields */
  208. err = !((ext_csd[EXT_CSD_PARTITION_SUPPORT] == bw_ext_csd[EXT_CSD_PARTITION_SUPPORT]) &&
  209. (ext_csd[EXT_CSD_ERASED_MEM_CONT] == bw_ext_csd[EXT_CSD_ERASED_MEM_CONT]) &&
  210. (ext_csd[EXT_CSD_REV] == bw_ext_csd[EXT_CSD_REV]) &&
  211. (ext_csd[EXT_CSD_STRUCTURE] == bw_ext_csd[EXT_CSD_STRUCTURE]) &&
  212. (ext_csd[EXT_CSD_CARD_TYPE] == bw_ext_csd[EXT_CSD_CARD_TYPE]) &&
  213. (ext_csd[EXT_CSD_S_A_TIMEOUT] == bw_ext_csd[EXT_CSD_S_A_TIMEOUT]) &&
  214. (ext_csd[EXT_CSD_HC_WP_GRP_SIZE] == bw_ext_csd[EXT_CSD_HC_WP_GRP_SIZE]) &&
  215. (ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT] == bw_ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]) &&
  216. (ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] == bw_ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]) &&
  217. (ext_csd[EXT_CSD_SEC_TRIM_MULT] == bw_ext_csd[EXT_CSD_SEC_TRIM_MULT]) &&
  218. (ext_csd[EXT_CSD_SEC_ERASE_MULT] == bw_ext_csd[EXT_CSD_SEC_ERASE_MULT]) &&
  219. (ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT] == bw_ext_csd[EXT_CSD_SEC_FEATURE_SUPPORT]) &&
  220. (ext_csd[EXT_CSD_TRIM_MULT] == bw_ext_csd[EXT_CSD_TRIM_MULT]) &&
  221. (ext_csd[EXT_CSD_SEC_CNT + 0] == bw_ext_csd[EXT_CSD_SEC_CNT + 0]) &&
  222. (ext_csd[EXT_CSD_SEC_CNT + 1] == bw_ext_csd[EXT_CSD_SEC_CNT + 1]) &&
  223. (ext_csd[EXT_CSD_SEC_CNT + 2] == bw_ext_csd[EXT_CSD_SEC_CNT + 2]) &&
  224. (ext_csd[EXT_CSD_SEC_CNT + 3] == bw_ext_csd[EXT_CSD_SEC_CNT + 3]) &&
  225. (ext_csd[EXT_CSD_PWR_CL_52_195] == bw_ext_csd[EXT_CSD_PWR_CL_52_195]) &&
  226. (ext_csd[EXT_CSD_PWR_CL_26_195] == bw_ext_csd[EXT_CSD_PWR_CL_26_195]) &&
  227. (ext_csd[EXT_CSD_PWR_CL_52_360] == bw_ext_csd[EXT_CSD_PWR_CL_52_360]) &&
  228. (ext_csd[EXT_CSD_PWR_CL_26_360] == bw_ext_csd[EXT_CSD_PWR_CL_26_360]) &&
  229. (ext_csd[EXT_CSD_PWR_CL_200_195] == bw_ext_csd[EXT_CSD_PWR_CL_200_195]) &&
  230. (ext_csd[EXT_CSD_PWR_CL_200_360] == bw_ext_csd[EXT_CSD_PWR_CL_200_360]) &&
  231. (ext_csd[EXT_CSD_PWR_CL_DDR_52_195] == bw_ext_csd[EXT_CSD_PWR_CL_DDR_52_195]) &&
  232. (ext_csd[EXT_CSD_PWR_CL_DDR_52_360] == bw_ext_csd[EXT_CSD_PWR_CL_DDR_52_360]) &&
  233. (ext_csd[EXT_CSD_PWR_CL_DDR_200_360] == bw_ext_csd[EXT_CSD_PWR_CL_DDR_200_360]));
  234. if (err)
  235. err = -RT_ERROR;
  236. out:
  237. rt_free(bw_ext_csd);
  238. return err;
  239. }
  240. /*
  241. * Select the bus width amoung 4-bit and 8-bit(SDR).
  242. * If the bus width is changed successfully, return the selected width value.
  243. * Zero is returned instead of error value if the wide width is not supported.
  244. */
  245. static int mmc_select_bus_width(struct rt_mmcsd_card *card, rt_uint8_t *ext_csd)
  246. {
  247. rt_uint32_t ext_csd_bits[] = {
  248. EXT_CSD_BUS_WIDTH_8,
  249. EXT_CSD_BUS_WIDTH_4,
  250. EXT_CSD_BUS_WIDTH_1
  251. };
  252. rt_uint32_t bus_widths[] = {
  253. MMCSD_BUS_WIDTH_8,
  254. MMCSD_BUS_WIDTH_4,
  255. MMCSD_BUS_WIDTH_1
  256. };
  257. struct rt_mmcsd_host *host = card->host;
  258. unsigned idx, bus_width = 0;
  259. int err = 0;
  260. if (GET_BITS(card->resp_cid, 122, 4) < 4)
  261. return 0;
  262. /*
  263. * Unlike SD, MMC cards dont have a configuration register to notify
  264. * supported bus width. So bus test command should be run to identify
  265. * the supported bus width or compare the ext csd values of current
  266. * bus width and ext csd values of 1 bit mode read earlier.
  267. */
  268. for (idx = 0; idx < sizeof(bus_widths)/sizeof(rt_uint32_t); idx++) {
  269. /*
  270. * Host is capable of 8bit transfer, then switch
  271. * the device to work in 8bit transfer mode. If the
  272. * mmc switch command returns error then switch to
  273. * 4bit transfer mode. On success set the corresponding
  274. * bus width on the host.
  275. */
  276. err = mmc_switch(card, EXT_CSD_CMD_SET_NORMAL,
  277. EXT_CSD_BUS_WIDTH,
  278. ext_csd_bits[idx]);
  279. if (err)
  280. continue;
  281. bus_width = bus_widths[idx];
  282. mmcsd_set_bus_width(host, bus_width);
  283. mmcsd_delay_ms(20); //delay 10ms
  284. err = mmc_compare_ext_csds(card, ext_csd, bus_width);
  285. if (!err) {
  286. err = bus_width;
  287. break;
  288. } else {
  289. switch(ext_csd_bits[idx]){
  290. case 0:
  291. rt_kprintf("switch to bus width 1 bit failed\n");
  292. break;
  293. case 1:
  294. rt_kprintf("switch to bus width 4 bit failed\n");
  295. break;
  296. case 2:
  297. rt_kprintf("switch to bus width 8 bit failed\n");
  298. break;
  299. default:
  300. break;
  301. }
  302. }
  303. }
  304. return err;
  305. }
  306. rt_err_t mmc_send_op_cond(struct rt_mmcsd_host *host,
  307. rt_uint32_t ocr, rt_uint32_t *rocr)
  308. {
  309. struct rt_mmcsd_cmd cmd;
  310. rt_uint32_t i;
  311. rt_err_t err = RT_EOK;
  312. rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
  313. cmd.cmd_code = SEND_OP_COND;
  314. cmd.arg = controller_is_spi(host) ? 0 : ocr;
  315. cmd.flags = RESP_SPI_R1 | RESP_R3 | CMD_BCR;
  316. for (i = 100; i; i--) {
  317. err = mmcsd_send_cmd(host, &cmd, 3);
  318. if (err)
  319. break;
  320. /* if we're just probing, do a single pass */
  321. if (ocr == 0)
  322. break;
  323. /* otherwise wait until reset completes */
  324. if (controller_is_spi(host)) {
  325. if (!(cmd.resp[0] & R1_SPI_IDLE))
  326. break;
  327. } else {
  328. if (cmd.resp[0] & CARD_BUSY)
  329. break;
  330. }
  331. err = -RT_ETIMEOUT;
  332. mmcsd_delay_ms(10); //delay 10ms
  333. }
  334. if (rocr && !controller_is_spi(host))
  335. *rocr = cmd.resp[0];
  336. return err;
  337. }
  338. static rt_err_t mmc_set_card_addr(struct rt_mmcsd_host *host, rt_uint32_t rca)
  339. {
  340. rt_err_t err;
  341. struct rt_mmcsd_cmd cmd;
  342. rt_memset(&cmd, 0, sizeof(struct rt_mmcsd_cmd));
  343. cmd.cmd_code = SET_RELATIVE_ADDR;
  344. cmd.arg = rca << 16;
  345. cmd.flags = RESP_R1 | CMD_AC;
  346. err = mmcsd_send_cmd(host, &cmd, 3);
  347. if (err)
  348. return err;
  349. return 0;
  350. }
  351. static rt_int32_t mmcsd_mmc_init_card(struct rt_mmcsd_host *host,
  352. rt_uint32_t ocr)
  353. {
  354. struct rt_mmcsd_card *card;
  355. rt_int32_t err;
  356. rt_uint32_t resp[4];
  357. rt_uint32_t rocr;
  358. rt_uint32_t max_data_rate;
  359. rt_uint8_t *ext_csd = RT_NULL;
  360. mmcsd_go_idle(host);
  361. /* The extra bit indicates that we support high capacity */
  362. err = mmc_send_op_cond(host, ocr | (1 << 30), &rocr);
  363. if (err)
  364. goto err;
  365. if (controller_is_spi(host))
  366. {
  367. err = mmcsd_spi_use_crc(host, 1);
  368. if (err)
  369. goto err1;
  370. }
  371. if (controller_is_spi(host))
  372. err = mmcsd_get_cid(host, resp);
  373. else
  374. err = mmcsd_all_get_cid(host, resp);
  375. if (err)
  376. goto err;
  377. card = rt_malloc(sizeof(struct rt_mmcsd_card));
  378. if (!card)
  379. {
  380. rt_kprintf("malloc card failed\n");
  381. err = -RT_ENOMEM;
  382. goto err;
  383. }
  384. rt_memset(card, 0, sizeof(struct rt_mmcsd_card));
  385. card->card_type = CARD_TYPE_MMC;
  386. card->host = host;
  387. card->rca = 1;
  388. rt_memcpy(card->resp_cid, resp, sizeof(card->resp_cid));
  389. /*
  390. * For native busses: get card RCA and quit open drain mode.
  391. */
  392. if (!controller_is_spi(host))
  393. {
  394. err = mmc_set_card_addr(host, card->rca);
  395. if (err)
  396. goto err1;
  397. mmcsd_set_bus_mode(host, MMCSD_BUSMODE_PUSHPULL);
  398. }
  399. err = mmcsd_get_csd(card, card->resp_csd);
  400. if (err)
  401. goto err1;
  402. err = mmcsd_parse_csd(card);
  403. if (err)
  404. goto err1;
  405. if (!controller_is_spi(host))
  406. {
  407. err = mmcsd_select_card(card);
  408. if (err)
  409. goto err1;
  410. }
  411. /*
  412. * Fetch and process extended CSD.
  413. */
  414. err = mmc_get_ext_csd(card, &ext_csd);
  415. if (err)
  416. goto err1;
  417. err = mmc_parse_ext_csd(card, ext_csd);
  418. if (err)
  419. goto err1;
  420. /* If doing byte addressing, check if required to do sector
  421. * addressing. Handle the case of <2GB cards needing sector
  422. * addressing. See section 8.1 JEDEC Standard JED84-A441;
  423. * ocr register has bit 30 set for sector addressing.
  424. */
  425. if (!(card->flags & CARD_FLAG_SDHC) && (rocr & (1<<30)))
  426. card->flags |= CARD_FLAG_SDHC;
  427. /* set bus speed */
  428. max_data_rate = (unsigned int)-1;
  429. if (card->flags & CARD_FLAG_HIGHSPEED)
  430. {
  431. if (max_data_rate > card->hs_max_data_rate)
  432. max_data_rate = card->hs_max_data_rate;
  433. }
  434. else if (max_data_rate > card->max_data_rate)
  435. {
  436. max_data_rate = card->max_data_rate;
  437. }
  438. mmcsd_set_clock(host, max_data_rate);
  439. /*switch bus width*/
  440. mmc_select_bus_width(card, ext_csd);
  441. host->card = card;
  442. rt_free(ext_csd);
  443. return 0;
  444. err1:
  445. rt_free(card);
  446. err:
  447. return err;
  448. }
  449. /*
  450. * Starting point for mmc card init.
  451. */
  452. rt_int32_t init_mmc(struct rt_mmcsd_host *host, rt_uint32_t ocr)
  453. {
  454. rt_int32_t err;
  455. rt_uint32_t current_ocr;
  456. /*
  457. * We need to get OCR a different way for SPI.
  458. */
  459. if (controller_is_spi(host))
  460. {
  461. err = mmcsd_spi_read_ocr(host, 0, &ocr);
  462. if (err)
  463. goto err;
  464. }
  465. current_ocr = mmcsd_select_voltage(host, ocr);
  466. /*
  467. * Can we support the voltage(s) of the card(s)?
  468. */
  469. if (!current_ocr)
  470. {
  471. err = -RT_ERROR;
  472. goto err;
  473. }
  474. /*
  475. * Detect and init the card.
  476. */
  477. err = mmcsd_mmc_init_card(host, current_ocr);
  478. if (err)
  479. goto err;
  480. mmcsd_host_unlock(host);
  481. err = rt_mmcsd_blk_probe(host->card);
  482. if (err)
  483. goto remove_card;
  484. mmcsd_host_lock(host);
  485. return 0;
  486. remove_card:
  487. mmcsd_host_lock(host);
  488. rt_mmcsd_blk_remove(host->card);
  489. rt_free(host->card);
  490. host->card = RT_NULL;
  491. err:
  492. rt_kprintf("init MMC card failed\n");
  493. return err;
  494. }