mmc.c 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354
  1. /*
  2. * Copyright 2008, Freescale Semiconductor, Inc
  3. * Andy Fleming
  4. *
  5. * Based vaguely on the Linux code
  6. *
  7. * See file CREDITS for list of people who contributed to this
  8. * project.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation; either version 2 of
  13. * the License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  23. * MA 02111-1307 USA
  24. */
  25. #include <config.h>
  26. #include <common.h>
  27. #include <command.h>
  28. #include <mmc.h>
  29. #include <part.h>
  30. #include <malloc.h>
  31. #include <linux/list.h>
  32. #include <div64.h>
  33. /* Set block count limit because of 16 bit register limit on some hardware*/
  34. #ifndef CONFIG_SYS_MMC_MAX_BLK_COUNT
  35. #define CONFIG_SYS_MMC_MAX_BLK_COUNT 65535
  36. #endif
  37. static struct list_head mmc_devices;
  38. static int cur_dev_num = -1;
  39. int __weak board_mmc_getwp(struct mmc *mmc)
  40. {
  41. return -1;
  42. }
  43. int mmc_getwp(struct mmc *mmc)
  44. {
  45. int wp;
  46. wp = board_mmc_getwp(mmc);
  47. if (wp < 0) {
  48. if (mmc->getwp)
  49. wp = mmc->getwp(mmc);
  50. else
  51. wp = 0;
  52. }
  53. return wp;
  54. }
  55. int __board_mmc_getcd(struct mmc *mmc) {
  56. return -1;
  57. }
  58. int board_mmc_getcd(struct mmc *mmc)__attribute__((weak,
  59. alias("__board_mmc_getcd")));
  60. static int mmc_send_cmd(struct mmc *mmc, struct mmc_cmd *cmd,
  61. struct mmc_data *data)
  62. {
  63. struct mmc_data backup;
  64. int ret;
  65. memset(&backup, 0, sizeof(backup));
  66. #ifdef CONFIG_MMC_TRACE
  67. int i;
  68. u8 *ptr;
  69. printf("CMD_SEND:%d\n", cmd->cmdidx);
  70. printf("\t\tARG\t\t\t 0x%08X\n", cmd->cmdarg);
  71. ret = mmc->send_cmd(mmc, cmd, data);
  72. switch (cmd->resp_type) {
  73. case MMC_RSP_NONE:
  74. printf("\t\tMMC_RSP_NONE\n");
  75. break;
  76. case MMC_RSP_R1:
  77. printf("\t\tMMC_RSP_R1,5,6,7 \t 0x%08X \n",
  78. cmd->response[0]);
  79. break;
  80. case MMC_RSP_R1b:
  81. printf("\t\tMMC_RSP_R1b\t\t 0x%08X \n",
  82. cmd->response[0]);
  83. break;
  84. case MMC_RSP_R2:
  85. printf("\t\tMMC_RSP_R2\t\t 0x%08X \n",
  86. cmd->response[0]);
  87. printf("\t\t \t\t 0x%08X \n",
  88. cmd->response[1]);
  89. printf("\t\t \t\t 0x%08X \n",
  90. cmd->response[2]);
  91. printf("\t\t \t\t 0x%08X \n",
  92. cmd->response[3]);
  93. printf("\n");
  94. printf("\t\t\t\t\tDUMPING DATA\n");
  95. for (i = 0; i < 4; i++) {
  96. int j;
  97. printf("\t\t\t\t\t%03d - ", i*4);
  98. ptr = (u8 *)&cmd->response[i];
  99. ptr += 3;
  100. for (j = 0; j < 4; j++)
  101. printf("%02X ", *ptr--);
  102. printf("\n");
  103. }
  104. break;
  105. case MMC_RSP_R3:
  106. printf("\t\tMMC_RSP_R3,4\t\t 0x%08X \n",
  107. cmd->response[0]);
  108. break;
  109. default:
  110. printf("\t\tERROR MMC rsp not supported\n");
  111. break;
  112. }
  113. #else
  114. ret = mmc->send_cmd(mmc, cmd, data);
  115. #endif
  116. return ret;
  117. }
  118. static int mmc_send_status(struct mmc *mmc, int timeout)
  119. {
  120. struct mmc_cmd cmd;
  121. int err, retries = 5;
  122. #ifdef CONFIG_MMC_TRACE
  123. int status;
  124. #endif
  125. cmd.cmdidx = MMC_CMD_SEND_STATUS;
  126. cmd.resp_type = MMC_RSP_R1;
  127. if (!mmc_host_is_spi(mmc))
  128. cmd.cmdarg = mmc->rca << 16;
  129. do {
  130. err = mmc_send_cmd(mmc, &cmd, NULL);
  131. if (!err) {
  132. if ((cmd.response[0] & MMC_STATUS_RDY_FOR_DATA) &&
  133. (cmd.response[0] & MMC_STATUS_CURR_STATE) !=
  134. MMC_STATE_PRG)
  135. break;
  136. else if (cmd.response[0] & MMC_STATUS_MASK) {
  137. printf("Status Error: 0x%08X\n",
  138. cmd.response[0]);
  139. return COMM_ERR;
  140. }
  141. } else if (--retries < 0)
  142. return err;
  143. udelay(1000);
  144. } while (timeout--);
  145. #ifdef CONFIG_MMC_TRACE
  146. status = (cmd.response[0] & MMC_STATUS_CURR_STATE) >> 9;
  147. printf("CURR STATE:%d\n", status);
  148. #endif
  149. if (timeout <= 0) {
  150. printf("Timeout waiting card ready\n");
  151. return TIMEOUT;
  152. }
  153. return 0;
  154. }
  155. static int mmc_set_blocklen(struct mmc *mmc, int len)
  156. {
  157. struct mmc_cmd cmd;
  158. cmd.cmdidx = MMC_CMD_SET_BLOCKLEN;
  159. cmd.resp_type = MMC_RSP_R1;
  160. cmd.cmdarg = len;
  161. return mmc_send_cmd(mmc, &cmd, NULL);
  162. }
  163. struct mmc *find_mmc_device(int dev_num)
  164. {
  165. struct mmc *m;
  166. struct list_head *entry;
  167. list_for_each(entry, &mmc_devices) {
  168. m = list_entry(entry, struct mmc, link);
  169. if (m->block_dev.dev == dev_num)
  170. return m;
  171. }
  172. printf("MMC Device %d not found\n", dev_num);
  173. return NULL;
  174. }
  175. static ulong mmc_erase_t(struct mmc *mmc, ulong start, lbaint_t blkcnt)
  176. {
  177. struct mmc_cmd cmd;
  178. ulong end;
  179. int err, start_cmd, end_cmd;
  180. if (mmc->high_capacity)
  181. end = start + blkcnt - 1;
  182. else {
  183. end = (start + blkcnt - 1) * mmc->write_bl_len;
  184. start *= mmc->write_bl_len;
  185. }
  186. if (IS_SD(mmc)) {
  187. start_cmd = SD_CMD_ERASE_WR_BLK_START;
  188. end_cmd = SD_CMD_ERASE_WR_BLK_END;
  189. } else {
  190. start_cmd = MMC_CMD_ERASE_GROUP_START;
  191. end_cmd = MMC_CMD_ERASE_GROUP_END;
  192. }
  193. cmd.cmdidx = start_cmd;
  194. cmd.cmdarg = start;
  195. cmd.resp_type = MMC_RSP_R1;
  196. err = mmc_send_cmd(mmc, &cmd, NULL);
  197. if (err)
  198. goto err_out;
  199. cmd.cmdidx = end_cmd;
  200. cmd.cmdarg = end;
  201. err = mmc_send_cmd(mmc, &cmd, NULL);
  202. if (err)
  203. goto err_out;
  204. cmd.cmdidx = MMC_CMD_ERASE;
  205. cmd.cmdarg = SECURE_ERASE;
  206. cmd.resp_type = MMC_RSP_R1b;
  207. err = mmc_send_cmd(mmc, &cmd, NULL);
  208. if (err)
  209. goto err_out;
  210. return 0;
  211. err_out:
  212. puts("mmc erase failed\n");
  213. return err;
  214. }
  215. static unsigned long
  216. mmc_berase(int dev_num, unsigned long start, lbaint_t blkcnt)
  217. {
  218. int err = 0;
  219. struct mmc *mmc = find_mmc_device(dev_num);
  220. lbaint_t blk = 0, blk_r = 0;
  221. int timeout = 1000;
  222. if (!mmc)
  223. return -1;
  224. if ((start % mmc->erase_grp_size) || (blkcnt % mmc->erase_grp_size))
  225. printf("\n\nCaution! Your devices Erase group is 0x%x\n"
  226. "The erase range would be change to 0x%lx~0x%lx\n\n",
  227. mmc->erase_grp_size, start & ~(mmc->erase_grp_size - 1),
  228. ((start + blkcnt + mmc->erase_grp_size)
  229. & ~(mmc->erase_grp_size - 1)) - 1);
  230. while (blk < blkcnt) {
  231. blk_r = ((blkcnt - blk) > mmc->erase_grp_size) ?
  232. mmc->erase_grp_size : (blkcnt - blk);
  233. err = mmc_erase_t(mmc, start + blk, blk_r);
  234. if (err)
  235. break;
  236. blk += blk_r;
  237. /* Waiting for the ready status */
  238. if (mmc_send_status(mmc, timeout))
  239. return 0;
  240. }
  241. return blk;
  242. }
  243. static ulong
  244. mmc_write_blocks(struct mmc *mmc, ulong start, lbaint_t blkcnt, const void*src)
  245. {
  246. struct mmc_cmd cmd;
  247. struct mmc_data data;
  248. int timeout = 1000;
  249. if ((start + blkcnt) > mmc->block_dev.lba) {
  250. printf("MMC: block number 0x%lx exceeds max(0x%lx)\n",
  251. start + blkcnt, mmc->block_dev.lba);
  252. return 0;
  253. }
  254. if (blkcnt > 1)
  255. cmd.cmdidx = MMC_CMD_WRITE_MULTIPLE_BLOCK;
  256. else
  257. cmd.cmdidx = MMC_CMD_WRITE_SINGLE_BLOCK;
  258. if (mmc->high_capacity)
  259. cmd.cmdarg = start;
  260. else
  261. cmd.cmdarg = start * mmc->write_bl_len;
  262. cmd.resp_type = MMC_RSP_R1;
  263. data.src = src;
  264. data.blocks = blkcnt;
  265. data.blocksize = mmc->write_bl_len;
  266. data.flags = MMC_DATA_WRITE;
  267. if (mmc_send_cmd(mmc, &cmd, &data)) {
  268. printf("mmc write failed\n");
  269. return 0;
  270. }
  271. /* SPI multiblock writes terminate using a special
  272. * token, not a STOP_TRANSMISSION request.
  273. */
  274. if (!mmc_host_is_spi(mmc) && blkcnt > 1) {
  275. cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
  276. cmd.cmdarg = 0;
  277. cmd.resp_type = MMC_RSP_R1b;
  278. if (mmc_send_cmd(mmc, &cmd, NULL)) {
  279. printf("mmc fail to send stop cmd\n");
  280. return 0;
  281. }
  282. }
  283. /* Waiting for the ready status */
  284. if (mmc_send_status(mmc, timeout))
  285. return 0;
  286. return blkcnt;
  287. }
  288. static ulong
  289. mmc_bwrite(int dev_num, ulong start, lbaint_t blkcnt, const void*src)
  290. {
  291. lbaint_t cur, blocks_todo = blkcnt;
  292. struct mmc *mmc = find_mmc_device(dev_num);
  293. if (!mmc)
  294. return 0;
  295. if (mmc_set_blocklen(mmc, mmc->write_bl_len))
  296. return 0;
  297. do {
  298. cur = (blocks_todo > mmc->b_max) ? mmc->b_max : blocks_todo;
  299. if(mmc_write_blocks(mmc, start, cur, src) != cur)
  300. return 0;
  301. blocks_todo -= cur;
  302. start += cur;
  303. src += cur * mmc->write_bl_len;
  304. } while (blocks_todo > 0);
  305. return blkcnt;
  306. }
  307. static int mmc_read_blocks(struct mmc *mmc, void *dst, ulong start,
  308. lbaint_t blkcnt)
  309. {
  310. struct mmc_cmd cmd;
  311. struct mmc_data data;
  312. if (blkcnt > 1)
  313. cmd.cmdidx = MMC_CMD_READ_MULTIPLE_BLOCK;
  314. else
  315. cmd.cmdidx = MMC_CMD_READ_SINGLE_BLOCK;
  316. if (mmc->high_capacity)
  317. cmd.cmdarg = start;
  318. else
  319. cmd.cmdarg = start * mmc->read_bl_len;
  320. cmd.resp_type = MMC_RSP_R1;
  321. data.dest = dst;
  322. data.blocks = blkcnt;
  323. data.blocksize = mmc->read_bl_len;
  324. data.flags = MMC_DATA_READ;
  325. if (mmc_send_cmd(mmc, &cmd, &data))
  326. return 0;
  327. if (blkcnt > 1) {
  328. cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
  329. cmd.cmdarg = 0;
  330. cmd.resp_type = MMC_RSP_R1b;
  331. if (mmc_send_cmd(mmc, &cmd, NULL)) {
  332. printf("mmc fail to send stop cmd\n");
  333. return 0;
  334. }
  335. }
  336. return blkcnt;
  337. }
  338. static ulong mmc_bread(int dev_num, ulong start, lbaint_t blkcnt, void *dst)
  339. {
  340. lbaint_t cur, blocks_todo = blkcnt;
  341. if (blkcnt == 0)
  342. return 0;
  343. struct mmc *mmc = find_mmc_device(dev_num);
  344. if (!mmc)
  345. return 0;
  346. if ((start + blkcnt) > mmc->block_dev.lba) {
  347. printf("MMC: block number 0x%lx exceeds max(0x%lx)\n",
  348. start + blkcnt, mmc->block_dev.lba);
  349. return 0;
  350. }
  351. if (mmc_set_blocklen(mmc, mmc->read_bl_len))
  352. return 0;
  353. do {
  354. cur = (blocks_todo > mmc->b_max) ? mmc->b_max : blocks_todo;
  355. if(mmc_read_blocks(mmc, dst, start, cur) != cur)
  356. return 0;
  357. blocks_todo -= cur;
  358. start += cur;
  359. dst += cur * mmc->read_bl_len;
  360. } while (blocks_todo > 0);
  361. return blkcnt;
  362. }
  363. static int mmc_go_idle(struct mmc *mmc)
  364. {
  365. struct mmc_cmd cmd;
  366. int err;
  367. udelay(1000);
  368. cmd.cmdidx = MMC_CMD_GO_IDLE_STATE;
  369. cmd.cmdarg = 0;
  370. cmd.resp_type = MMC_RSP_NONE;
  371. err = mmc_send_cmd(mmc, &cmd, NULL);
  372. if (err)
  373. return err;
  374. udelay(2000);
  375. return 0;
  376. }
  377. static int sd_send_op_cond(struct mmc *mmc)
  378. {
  379. int timeout = 1000;
  380. int err;
  381. struct mmc_cmd cmd;
  382. do {
  383. cmd.cmdidx = MMC_CMD_APP_CMD;
  384. cmd.resp_type = MMC_RSP_R1;
  385. cmd.cmdarg = 0;
  386. err = mmc_send_cmd(mmc, &cmd, NULL);
  387. if (err)
  388. return err;
  389. cmd.cmdidx = SD_CMD_APP_SEND_OP_COND;
  390. cmd.resp_type = MMC_RSP_R3;
  391. /*
  392. * Most cards do not answer if some reserved bits
  393. * in the ocr are set. However, Some controller
  394. * can set bit 7 (reserved for low voltages), but
  395. * how to manage low voltages SD card is not yet
  396. * specified.
  397. */
  398. cmd.cmdarg = mmc_host_is_spi(mmc) ? 0 :
  399. (mmc->voltages & 0xff8000);
  400. if (mmc->version == SD_VERSION_2)
  401. cmd.cmdarg |= OCR_HCS;
  402. err = mmc_send_cmd(mmc, &cmd, NULL);
  403. if (err)
  404. return err;
  405. udelay(1000);
  406. } while ((!(cmd.response[0] & OCR_BUSY)) && timeout--);
  407. if (timeout <= 0)
  408. return UNUSABLE_ERR;
  409. if (mmc->version != SD_VERSION_2)
  410. mmc->version = SD_VERSION_1_0;
  411. if (mmc_host_is_spi(mmc)) { /* read OCR for spi */
  412. cmd.cmdidx = MMC_CMD_SPI_READ_OCR;
  413. cmd.resp_type = MMC_RSP_R3;
  414. cmd.cmdarg = 0;
  415. err = mmc_send_cmd(mmc, &cmd, NULL);
  416. if (err)
  417. return err;
  418. }
  419. mmc->ocr = cmd.response[0];
  420. mmc->high_capacity = ((mmc->ocr & OCR_HCS) == OCR_HCS);
  421. mmc->rca = 0;
  422. return 0;
  423. }
  424. static int mmc_send_op_cond(struct mmc *mmc)
  425. {
  426. int timeout = 10000;
  427. struct mmc_cmd cmd;
  428. int err;
  429. /* Some cards seem to need this */
  430. mmc_go_idle(mmc);
  431. /* Asking to the card its capabilities */
  432. cmd.cmdidx = MMC_CMD_SEND_OP_COND;
  433. cmd.resp_type = MMC_RSP_R3;
  434. cmd.cmdarg = 0;
  435. err = mmc_send_cmd(mmc, &cmd, NULL);
  436. if (err)
  437. return err;
  438. udelay(1000);
  439. do {
  440. cmd.cmdidx = MMC_CMD_SEND_OP_COND;
  441. cmd.resp_type = MMC_RSP_R3;
  442. cmd.cmdarg = (mmc_host_is_spi(mmc) ? 0 :
  443. (mmc->voltages &
  444. (cmd.response[0] & OCR_VOLTAGE_MASK)) |
  445. (cmd.response[0] & OCR_ACCESS_MODE));
  446. if (mmc->host_caps & MMC_MODE_HC)
  447. cmd.cmdarg |= OCR_HCS;
  448. err = mmc_send_cmd(mmc, &cmd, NULL);
  449. if (err)
  450. return err;
  451. udelay(1000);
  452. } while (!(cmd.response[0] & OCR_BUSY) && timeout--);
  453. if (timeout <= 0)
  454. return UNUSABLE_ERR;
  455. if (mmc_host_is_spi(mmc)) { /* read OCR for spi */
  456. cmd.cmdidx = MMC_CMD_SPI_READ_OCR;
  457. cmd.resp_type = MMC_RSP_R3;
  458. cmd.cmdarg = 0;
  459. err = mmc_send_cmd(mmc, &cmd, NULL);
  460. if (err)
  461. return err;
  462. }
  463. mmc->version = MMC_VERSION_UNKNOWN;
  464. mmc->ocr = cmd.response[0];
  465. mmc->high_capacity = ((mmc->ocr & OCR_HCS) == OCR_HCS);
  466. mmc->rca = 0;
  467. return 0;
  468. }
  469. static int mmc_send_ext_csd(struct mmc *mmc, u8 *ext_csd)
  470. {
  471. struct mmc_cmd cmd;
  472. struct mmc_data data;
  473. int err;
  474. /* Get the Card Status Register */
  475. cmd.cmdidx = MMC_CMD_SEND_EXT_CSD;
  476. cmd.resp_type = MMC_RSP_R1;
  477. cmd.cmdarg = 0;
  478. data.dest = (char *)ext_csd;
  479. data.blocks = 1;
  480. data.blocksize = 512;
  481. data.flags = MMC_DATA_READ;
  482. err = mmc_send_cmd(mmc, &cmd, &data);
  483. return err;
  484. }
  485. static int mmc_switch(struct mmc *mmc, u8 set, u8 index, u8 value)
  486. {
  487. struct mmc_cmd cmd;
  488. int timeout = 1000;
  489. int ret;
  490. cmd.cmdidx = MMC_CMD_SWITCH;
  491. cmd.resp_type = MMC_RSP_R1b;
  492. cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) |
  493. (index << 16) |
  494. (value << 8);
  495. ret = mmc_send_cmd(mmc, &cmd, NULL);
  496. /* Waiting for the ready status */
  497. if (!ret)
  498. ret = mmc_send_status(mmc, timeout);
  499. return ret;
  500. }
  501. static int mmc_change_freq(struct mmc *mmc)
  502. {
  503. ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, 512);
  504. char cardtype;
  505. int err;
  506. mmc->card_caps = 0;
  507. if (mmc_host_is_spi(mmc))
  508. return 0;
  509. /* Only version 4 supports high-speed */
  510. if (mmc->version < MMC_VERSION_4)
  511. return 0;
  512. err = mmc_send_ext_csd(mmc, ext_csd);
  513. if (err)
  514. return err;
  515. cardtype = ext_csd[EXT_CSD_CARD_TYPE] & 0xf;
  516. err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_HS_TIMING, 1);
  517. if (err)
  518. return err;
  519. /* Now check to see that it worked */
  520. err = mmc_send_ext_csd(mmc, ext_csd);
  521. if (err)
  522. return err;
  523. /* No high-speed support */
  524. if (!ext_csd[EXT_CSD_HS_TIMING])
  525. return 0;
  526. /* High Speed is set, there are two types: 52MHz and 26MHz */
  527. if (cardtype & MMC_HS_52MHZ)
  528. mmc->card_caps |= MMC_MODE_HS_52MHz | MMC_MODE_HS;
  529. else
  530. mmc->card_caps |= MMC_MODE_HS;
  531. return 0;
  532. }
  533. int mmc_switch_part(int dev_num, unsigned int part_num)
  534. {
  535. struct mmc *mmc = find_mmc_device(dev_num);
  536. if (!mmc)
  537. return -1;
  538. return mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,
  539. (mmc->part_config & ~PART_ACCESS_MASK)
  540. | (part_num & PART_ACCESS_MASK));
  541. }
  542. int mmc_getcd(struct mmc *mmc)
  543. {
  544. int cd;
  545. cd = board_mmc_getcd(mmc);
  546. if (cd < 0) {
  547. if (mmc->getcd)
  548. cd = mmc->getcd(mmc);
  549. else
  550. cd = 1;
  551. }
  552. return cd;
  553. }
  554. static int sd_switch(struct mmc *mmc, int mode, int group, u8 value, u8 *resp)
  555. {
  556. struct mmc_cmd cmd;
  557. struct mmc_data data;
  558. /* Switch the frequency */
  559. cmd.cmdidx = SD_CMD_SWITCH_FUNC;
  560. cmd.resp_type = MMC_RSP_R1;
  561. cmd.cmdarg = (mode << 31) | 0xffffff;
  562. cmd.cmdarg &= ~(0xf << (group * 4));
  563. cmd.cmdarg |= value << (group * 4);
  564. data.dest = (char *)resp;
  565. data.blocksize = 64;
  566. data.blocks = 1;
  567. data.flags = MMC_DATA_READ;
  568. return mmc_send_cmd(mmc, &cmd, &data);
  569. }
  570. static int sd_change_freq(struct mmc *mmc)
  571. {
  572. int err;
  573. struct mmc_cmd cmd;
  574. ALLOC_CACHE_ALIGN_BUFFER(uint, scr, 2);
  575. ALLOC_CACHE_ALIGN_BUFFER(uint, switch_status, 16);
  576. struct mmc_data data;
  577. int timeout;
  578. mmc->card_caps = 0;
  579. if (mmc_host_is_spi(mmc))
  580. return 0;
  581. /* Read the SCR to find out if this card supports higher speeds */
  582. cmd.cmdidx = MMC_CMD_APP_CMD;
  583. cmd.resp_type = MMC_RSP_R1;
  584. cmd.cmdarg = mmc->rca << 16;
  585. err = mmc_send_cmd(mmc, &cmd, NULL);
  586. if (err)
  587. return err;
  588. cmd.cmdidx = SD_CMD_APP_SEND_SCR;
  589. cmd.resp_type = MMC_RSP_R1;
  590. cmd.cmdarg = 0;
  591. timeout = 3;
  592. retry_scr:
  593. data.dest = (char *)scr;
  594. data.blocksize = 8;
  595. data.blocks = 1;
  596. data.flags = MMC_DATA_READ;
  597. err = mmc_send_cmd(mmc, &cmd, &data);
  598. if (err) {
  599. if (timeout--)
  600. goto retry_scr;
  601. return err;
  602. }
  603. mmc->scr[0] = __be32_to_cpu(scr[0]);
  604. mmc->scr[1] = __be32_to_cpu(scr[1]);
  605. switch ((mmc->scr[0] >> 24) & 0xf) {
  606. case 0:
  607. mmc->version = SD_VERSION_1_0;
  608. break;
  609. case 1:
  610. mmc->version = SD_VERSION_1_10;
  611. break;
  612. case 2:
  613. mmc->version = SD_VERSION_2;
  614. break;
  615. default:
  616. mmc->version = SD_VERSION_1_0;
  617. break;
  618. }
  619. if (mmc->scr[0] & SD_DATA_4BIT)
  620. mmc->card_caps |= MMC_MODE_4BIT;
  621. /* Version 1.0 doesn't support switching */
  622. if (mmc->version == SD_VERSION_1_0)
  623. return 0;
  624. timeout = 4;
  625. while (timeout--) {
  626. err = sd_switch(mmc, SD_SWITCH_CHECK, 0, 1,
  627. (u8 *)switch_status);
  628. if (err)
  629. return err;
  630. /* The high-speed function is busy. Try again */
  631. if (!(__be32_to_cpu(switch_status[7]) & SD_HIGHSPEED_BUSY))
  632. break;
  633. }
  634. /* If high-speed isn't supported, we return */
  635. if (!(__be32_to_cpu(switch_status[3]) & SD_HIGHSPEED_SUPPORTED))
  636. return 0;
  637. /*
  638. * If the host doesn't support SD_HIGHSPEED, do not switch card to
  639. * HIGHSPEED mode even if the card support SD_HIGHSPPED.
  640. * This can avoid furthur problem when the card runs in different
  641. * mode between the host.
  642. */
  643. if (!((mmc->host_caps & MMC_MODE_HS_52MHz) &&
  644. (mmc->host_caps & MMC_MODE_HS)))
  645. return 0;
  646. err = sd_switch(mmc, SD_SWITCH_SWITCH, 0, 1, (u8 *)switch_status);
  647. if (err)
  648. return err;
  649. if ((__be32_to_cpu(switch_status[4]) & 0x0f000000) == 0x01000000)
  650. mmc->card_caps |= MMC_MODE_HS;
  651. return 0;
  652. }
  653. /* frequency bases */
  654. /* divided by 10 to be nice to platforms without floating point */
  655. static const int fbase[] = {
  656. 10000,
  657. 100000,
  658. 1000000,
  659. 10000000,
  660. };
  661. /* Multiplier values for TRAN_SPEED. Multiplied by 10 to be nice
  662. * to platforms without floating point.
  663. */
  664. static const int multipliers[] = {
  665. 0, /* reserved */
  666. 10,
  667. 12,
  668. 13,
  669. 15,
  670. 20,
  671. 25,
  672. 30,
  673. 35,
  674. 40,
  675. 45,
  676. 50,
  677. 55,
  678. 60,
  679. 70,
  680. 80,
  681. };
  682. static void mmc_set_ios(struct mmc *mmc)
  683. {
  684. mmc->set_ios(mmc);
  685. }
  686. void mmc_set_clock(struct mmc *mmc, uint clock)
  687. {
  688. if (clock > mmc->f_max)
  689. clock = mmc->f_max;
  690. if (clock < mmc->f_min)
  691. clock = mmc->f_min;
  692. mmc->clock = clock;
  693. mmc_set_ios(mmc);
  694. }
  695. static void mmc_set_bus_width(struct mmc *mmc, uint width)
  696. {
  697. mmc->bus_width = width;
  698. mmc_set_ios(mmc);
  699. }
  700. static int mmc_startup(struct mmc *mmc)
  701. {
  702. int err;
  703. uint mult, freq;
  704. u64 cmult, csize, capacity;
  705. struct mmc_cmd cmd;
  706. ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, 512);
  707. ALLOC_CACHE_ALIGN_BUFFER(u8, test_csd, 512);
  708. int timeout = 1000;
  709. #ifdef CONFIG_MMC_SPI_CRC_ON
  710. if (mmc_host_is_spi(mmc)) { /* enable CRC check for spi */
  711. cmd.cmdidx = MMC_CMD_SPI_CRC_ON_OFF;
  712. cmd.resp_type = MMC_RSP_R1;
  713. cmd.cmdarg = 1;
  714. err = mmc_send_cmd(mmc, &cmd, NULL);
  715. if (err)
  716. return err;
  717. }
  718. #endif
  719. /* Put the Card in Identify Mode */
  720. cmd.cmdidx = mmc_host_is_spi(mmc) ? MMC_CMD_SEND_CID :
  721. MMC_CMD_ALL_SEND_CID; /* cmd not supported in spi */
  722. cmd.resp_type = MMC_RSP_R2;
  723. cmd.cmdarg = 0;
  724. err = mmc_send_cmd(mmc, &cmd, NULL);
  725. if (err)
  726. return err;
  727. memcpy(mmc->cid, cmd.response, 16);
  728. /*
  729. * For MMC cards, set the Relative Address.
  730. * For SD cards, get the Relatvie Address.
  731. * This also puts the cards into Standby State
  732. */
  733. if (!mmc_host_is_spi(mmc)) { /* cmd not supported in spi */
  734. cmd.cmdidx = SD_CMD_SEND_RELATIVE_ADDR;
  735. cmd.cmdarg = mmc->rca << 16;
  736. cmd.resp_type = MMC_RSP_R6;
  737. err = mmc_send_cmd(mmc, &cmd, NULL);
  738. if (err)
  739. return err;
  740. if (IS_SD(mmc))
  741. mmc->rca = (cmd.response[0] >> 16) & 0xffff;
  742. }
  743. /* Get the Card-Specific Data */
  744. cmd.cmdidx = MMC_CMD_SEND_CSD;
  745. cmd.resp_type = MMC_RSP_R2;
  746. cmd.cmdarg = mmc->rca << 16;
  747. err = mmc_send_cmd(mmc, &cmd, NULL);
  748. /* Waiting for the ready status */
  749. mmc_send_status(mmc, timeout);
  750. if (err)
  751. return err;
  752. mmc->csd[0] = cmd.response[0];
  753. mmc->csd[1] = cmd.response[1];
  754. mmc->csd[2] = cmd.response[2];
  755. mmc->csd[3] = cmd.response[3];
  756. if (mmc->version == MMC_VERSION_UNKNOWN) {
  757. int version = (cmd.response[0] >> 26) & 0xf;
  758. switch (version) {
  759. case 0:
  760. mmc->version = MMC_VERSION_1_2;
  761. break;
  762. case 1:
  763. mmc->version = MMC_VERSION_1_4;
  764. break;
  765. case 2:
  766. mmc->version = MMC_VERSION_2_2;
  767. break;
  768. case 3:
  769. mmc->version = MMC_VERSION_3;
  770. break;
  771. case 4:
  772. mmc->version = MMC_VERSION_4;
  773. break;
  774. default:
  775. mmc->version = MMC_VERSION_1_2;
  776. break;
  777. }
  778. }
  779. /* divide frequency by 10, since the mults are 10x bigger */
  780. freq = fbase[(cmd.response[0] & 0x7)];
  781. mult = multipliers[((cmd.response[0] >> 3) & 0xf)];
  782. mmc->tran_speed = freq * mult;
  783. mmc->read_bl_len = 1 << ((cmd.response[1] >> 16) & 0xf);
  784. if (IS_SD(mmc))
  785. mmc->write_bl_len = mmc->read_bl_len;
  786. else
  787. mmc->write_bl_len = 1 << ((cmd.response[3] >> 22) & 0xf);
  788. if (mmc->high_capacity) {
  789. csize = (mmc->csd[1] & 0x3f) << 16
  790. | (mmc->csd[2] & 0xffff0000) >> 16;
  791. cmult = 8;
  792. } else {
  793. csize = (mmc->csd[1] & 0x3ff) << 2
  794. | (mmc->csd[2] & 0xc0000000) >> 30;
  795. cmult = (mmc->csd[2] & 0x00038000) >> 15;
  796. }
  797. mmc->capacity = (csize + 1) << (cmult + 2);
  798. mmc->capacity *= mmc->read_bl_len;
  799. if (mmc->read_bl_len > 512)
  800. mmc->read_bl_len = 512;
  801. if (mmc->write_bl_len > 512)
  802. mmc->write_bl_len = 512;
  803. /* Select the card, and put it into Transfer Mode */
  804. if (!mmc_host_is_spi(mmc)) { /* cmd not supported in spi */
  805. cmd.cmdidx = MMC_CMD_SELECT_CARD;
  806. cmd.resp_type = MMC_RSP_R1;
  807. cmd.cmdarg = mmc->rca << 16;
  808. err = mmc_send_cmd(mmc, &cmd, NULL);
  809. if (err)
  810. return err;
  811. }
  812. /*
  813. * For SD, its erase group is always one sector
  814. */
  815. mmc->erase_grp_size = 1;
  816. mmc->part_config = MMCPART_NOAVAILABLE;
  817. if (!IS_SD(mmc) && (mmc->version >= MMC_VERSION_4)) {
  818. /* check ext_csd version and capacity */
  819. err = mmc_send_ext_csd(mmc, ext_csd);
  820. if (!err && (ext_csd[EXT_CSD_REV] >= 2)) {
  821. /*
  822. * According to the JEDEC Standard, the value of
  823. * ext_csd's capacity is valid if the value is more
  824. * than 2GB
  825. */
  826. capacity = ext_csd[EXT_CSD_SEC_CNT] << 0
  827. | ext_csd[EXT_CSD_SEC_CNT + 1] << 8
  828. | ext_csd[EXT_CSD_SEC_CNT + 2] << 16
  829. | ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
  830. capacity *= 512;
  831. if ((capacity >> 20) > 2 * 1024)
  832. mmc->capacity = capacity;
  833. }
  834. /*
  835. * Check whether GROUP_DEF is set, if yes, read out
  836. * group size from ext_csd directly, or calculate
  837. * the group size from the csd value.
  838. */
  839. if (ext_csd[EXT_CSD_ERASE_GROUP_DEF])
  840. mmc->erase_grp_size =
  841. ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] * 512 * 1024;
  842. else {
  843. int erase_gsz, erase_gmul;
  844. erase_gsz = (mmc->csd[2] & 0x00007c00) >> 10;
  845. erase_gmul = (mmc->csd[2] & 0x000003e0) >> 5;
  846. mmc->erase_grp_size = (erase_gsz + 1)
  847. * (erase_gmul + 1);
  848. }
  849. /* store the partition info of emmc */
  850. if ((ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & PART_SUPPORT) ||
  851. ext_csd[EXT_CSD_BOOT_MULT])
  852. mmc->part_config = ext_csd[EXT_CSD_PART_CONF];
  853. }
  854. if (IS_SD(mmc))
  855. err = sd_change_freq(mmc);
  856. else
  857. err = mmc_change_freq(mmc);
  858. if (err)
  859. return err;
  860. /* Restrict card's capabilities by what the host can do */
  861. mmc->card_caps &= mmc->host_caps;
  862. if (IS_SD(mmc)) {
  863. if (mmc->card_caps & MMC_MODE_4BIT) {
  864. cmd.cmdidx = MMC_CMD_APP_CMD;
  865. cmd.resp_type = MMC_RSP_R1;
  866. cmd.cmdarg = mmc->rca << 16;
  867. err = mmc_send_cmd(mmc, &cmd, NULL);
  868. if (err)
  869. return err;
  870. cmd.cmdidx = SD_CMD_APP_SET_BUS_WIDTH;
  871. cmd.resp_type = MMC_RSP_R1;
  872. cmd.cmdarg = 2;
  873. err = mmc_send_cmd(mmc, &cmd, NULL);
  874. if (err)
  875. return err;
  876. mmc_set_bus_width(mmc, 4);
  877. }
  878. if (mmc->card_caps & MMC_MODE_HS)
  879. mmc->tran_speed = 50000000;
  880. else
  881. mmc->tran_speed = 25000000;
  882. } else {
  883. int idx;
  884. /* An array of possible bus widths in order of preference */
  885. static unsigned ext_csd_bits[] = {
  886. EXT_CSD_BUS_WIDTH_8,
  887. EXT_CSD_BUS_WIDTH_4,
  888. EXT_CSD_BUS_WIDTH_1,
  889. };
  890. /* An array to map CSD bus widths to host cap bits */
  891. static unsigned ext_to_hostcaps[] = {
  892. [EXT_CSD_BUS_WIDTH_4] = MMC_MODE_4BIT,
  893. [EXT_CSD_BUS_WIDTH_8] = MMC_MODE_8BIT,
  894. };
  895. /* An array to map chosen bus width to an integer */
  896. static unsigned widths[] = {
  897. 8, 4, 1,
  898. };
  899. for (idx=0; idx < ARRAY_SIZE(ext_csd_bits); idx++) {
  900. unsigned int extw = ext_csd_bits[idx];
  901. /*
  902. * Check to make sure the controller supports
  903. * this bus width, if it's more than 1
  904. */
  905. if (extw != EXT_CSD_BUS_WIDTH_1 &&
  906. !(mmc->host_caps & ext_to_hostcaps[extw]))
  907. continue;
  908. err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
  909. EXT_CSD_BUS_WIDTH, extw);
  910. if (err)
  911. continue;
  912. mmc_set_bus_width(mmc, widths[idx]);
  913. err = mmc_send_ext_csd(mmc, test_csd);
  914. if (!err && ext_csd[EXT_CSD_PARTITIONING_SUPPORT] \
  915. == test_csd[EXT_CSD_PARTITIONING_SUPPORT]
  916. && ext_csd[EXT_CSD_ERASE_GROUP_DEF] \
  917. == test_csd[EXT_CSD_ERASE_GROUP_DEF] \
  918. && ext_csd[EXT_CSD_REV] \
  919. == test_csd[EXT_CSD_REV]
  920. && ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] \
  921. == test_csd[EXT_CSD_HC_ERASE_GRP_SIZE]
  922. && memcmp(&ext_csd[EXT_CSD_SEC_CNT], \
  923. &test_csd[EXT_CSD_SEC_CNT], 4) == 0) {
  924. mmc->card_caps |= ext_to_hostcaps[extw];
  925. break;
  926. }
  927. }
  928. if (mmc->card_caps & MMC_MODE_HS) {
  929. if (mmc->card_caps & MMC_MODE_HS_52MHz)
  930. mmc->tran_speed = 52000000;
  931. else
  932. mmc->tran_speed = 26000000;
  933. }
  934. }
  935. mmc_set_clock(mmc, mmc->tran_speed);
  936. /* fill in device description */
  937. mmc->block_dev.lun = 0;
  938. mmc->block_dev.type = 0;
  939. mmc->block_dev.blksz = mmc->read_bl_len;
  940. mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len);
  941. sprintf(mmc->block_dev.vendor, "Man %06x Snr %04x%04x",
  942. mmc->cid[0] >> 24, (mmc->cid[2] & 0xffff),
  943. (mmc->cid[3] >> 16) & 0xffff);
  944. sprintf(mmc->block_dev.product, "%c%c%c%c%c%c", mmc->cid[0] & 0xff,
  945. (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
  946. (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff,
  947. (mmc->cid[2] >> 24) & 0xff);
  948. sprintf(mmc->block_dev.revision, "%d.%d", (mmc->cid[2] >> 20) & 0xf,
  949. (mmc->cid[2] >> 16) & 0xf);
  950. #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)
  951. init_part(&mmc->block_dev);
  952. #endif
  953. return 0;
  954. }
  955. static int mmc_send_if_cond(struct mmc *mmc)
  956. {
  957. struct mmc_cmd cmd;
  958. int err;
  959. cmd.cmdidx = SD_CMD_SEND_IF_COND;
  960. /* We set the bit if the host supports voltages between 2.7 and 3.6 V */
  961. cmd.cmdarg = ((mmc->voltages & 0xff8000) != 0) << 8 | 0xaa;
  962. cmd.resp_type = MMC_RSP_R7;
  963. err = mmc_send_cmd(mmc, &cmd, NULL);
  964. if (err)
  965. return err;
  966. if ((cmd.response[0] & 0xff) != 0xaa)
  967. return UNUSABLE_ERR;
  968. else
  969. mmc->version = SD_VERSION_2;
  970. return 0;
  971. }
  972. int mmc_register(struct mmc *mmc)
  973. {
  974. /* Setup the universal parts of the block interface just once */
  975. mmc->block_dev.if_type = IF_TYPE_MMC;
  976. mmc->block_dev.dev = cur_dev_num++;
  977. mmc->block_dev.removable = 1;
  978. mmc->block_dev.block_read = mmc_bread;
  979. mmc->block_dev.block_write = mmc_bwrite;
  980. mmc->block_dev.block_erase = mmc_berase;
  981. if (!mmc->b_max)
  982. mmc->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
  983. INIT_LIST_HEAD (&mmc->link);
  984. list_add_tail (&mmc->link, &mmc_devices);
  985. return 0;
  986. }
  987. #ifdef CONFIG_PARTITIONS
  988. block_dev_desc_t *mmc_get_dev(int dev)
  989. {
  990. struct mmc *mmc = find_mmc_device(dev);
  991. if (!mmc || mmc_init(mmc))
  992. return NULL;
  993. return &mmc->block_dev;
  994. }
  995. #endif
  996. int mmc_init(struct mmc *mmc)
  997. {
  998. int err;
  999. if (mmc_getcd(mmc) == 0) {
  1000. mmc->has_init = 0;
  1001. printf("MMC: no card present\n");
  1002. return NO_CARD_ERR;
  1003. }
  1004. if (mmc->has_init)
  1005. return 0;
  1006. err = mmc->init(mmc);
  1007. if (err)
  1008. return err;
  1009. mmc_set_bus_width(mmc, 1);
  1010. mmc_set_clock(mmc, 1);
  1011. /* Reset the Card */
  1012. err = mmc_go_idle(mmc);
  1013. if (err)
  1014. return err;
  1015. /* The internal partition reset to user partition(0) at every CMD0*/
  1016. mmc->part_num = 0;
  1017. /* Test for SD version 2 */
  1018. err = mmc_send_if_cond(mmc);
  1019. /* Now try to get the SD card's operating condition */
  1020. err = sd_send_op_cond(mmc);
  1021. /* If the command timed out, we check for an MMC card */
  1022. if (err == TIMEOUT) {
  1023. err = mmc_send_op_cond(mmc);
  1024. if (err) {
  1025. printf("Card did not respond to voltage select!\n");
  1026. return UNUSABLE_ERR;
  1027. }
  1028. }
  1029. err = mmc_startup(mmc);
  1030. if (err)
  1031. mmc->has_init = 0;
  1032. else
  1033. mmc->has_init = 1;
  1034. return err;
  1035. }
  1036. /*
  1037. * CPU and board-specific MMC initializations. Aliased function
  1038. * signals caller to move on
  1039. */
  1040. static int __def_mmc_init(bd_t *bis)
  1041. {
  1042. return -1;
  1043. }
  1044. int cpu_mmc_init(bd_t *bis) __attribute__((weak, alias("__def_mmc_init")));
  1045. int board_mmc_init(bd_t *bis) __attribute__((weak, alias("__def_mmc_init")));
  1046. void print_mmc_devices(char separator)
  1047. {
  1048. struct mmc *m;
  1049. struct list_head *entry;
  1050. list_for_each(entry, &mmc_devices) {
  1051. m = list_entry(entry, struct mmc, link);
  1052. printf("%s: %d", m->name, m->block_dev.dev);
  1053. if (entry->next != &mmc_devices)
  1054. printf("%c ", separator);
  1055. }
  1056. printf("\n");
  1057. }
  1058. int get_mmc_num(void)
  1059. {
  1060. return cur_dev_num;
  1061. }
  1062. int mmc_initialize(bd_t *bis)
  1063. {
  1064. INIT_LIST_HEAD (&mmc_devices);
  1065. cur_dev_num = 0;
  1066. if (board_mmc_init(bis) < 0)
  1067. cpu_mmc_init(bis);
  1068. print_mmc_devices(',');
  1069. return 0;
  1070. }