mmc.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  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. if ((mmc->scr[0] >> 15) & 0x1)
  615. mmc->version = SD_VERSION_3;
  616. break;
  617. default:
  618. mmc->version = SD_VERSION_1_0;
  619. break;
  620. }
  621. if (mmc->scr[0] & SD_DATA_4BIT)
  622. mmc->card_caps |= MMC_MODE_4BIT;
  623. /* Version 1.0 doesn't support switching */
  624. if (mmc->version == SD_VERSION_1_0)
  625. return 0;
  626. timeout = 4;
  627. while (timeout--) {
  628. err = sd_switch(mmc, SD_SWITCH_CHECK, 0, 1,
  629. (u8 *)switch_status);
  630. if (err)
  631. return err;
  632. /* The high-speed function is busy. Try again */
  633. if (!(__be32_to_cpu(switch_status[7]) & SD_HIGHSPEED_BUSY))
  634. break;
  635. }
  636. /* If high-speed isn't supported, we return */
  637. if (!(__be32_to_cpu(switch_status[3]) & SD_HIGHSPEED_SUPPORTED))
  638. return 0;
  639. /*
  640. * If the host doesn't support SD_HIGHSPEED, do not switch card to
  641. * HIGHSPEED mode even if the card support SD_HIGHSPPED.
  642. * This can avoid furthur problem when the card runs in different
  643. * mode between the host.
  644. */
  645. if (!((mmc->host_caps & MMC_MODE_HS_52MHz) &&
  646. (mmc->host_caps & MMC_MODE_HS)))
  647. return 0;
  648. err = sd_switch(mmc, SD_SWITCH_SWITCH, 0, 1, (u8 *)switch_status);
  649. if (err)
  650. return err;
  651. if ((__be32_to_cpu(switch_status[4]) & 0x0f000000) == 0x01000000)
  652. mmc->card_caps |= MMC_MODE_HS;
  653. return 0;
  654. }
  655. /* frequency bases */
  656. /* divided by 10 to be nice to platforms without floating point */
  657. static const int fbase[] = {
  658. 10000,
  659. 100000,
  660. 1000000,
  661. 10000000,
  662. };
  663. /* Multiplier values for TRAN_SPEED. Multiplied by 10 to be nice
  664. * to platforms without floating point.
  665. */
  666. static const int multipliers[] = {
  667. 0, /* reserved */
  668. 10,
  669. 12,
  670. 13,
  671. 15,
  672. 20,
  673. 25,
  674. 30,
  675. 35,
  676. 40,
  677. 45,
  678. 50,
  679. 55,
  680. 60,
  681. 70,
  682. 80,
  683. };
  684. static void mmc_set_ios(struct mmc *mmc)
  685. {
  686. mmc->set_ios(mmc);
  687. }
  688. void mmc_set_clock(struct mmc *mmc, uint clock)
  689. {
  690. if (clock > mmc->f_max)
  691. clock = mmc->f_max;
  692. if (clock < mmc->f_min)
  693. clock = mmc->f_min;
  694. mmc->clock = clock;
  695. mmc_set_ios(mmc);
  696. }
  697. static void mmc_set_bus_width(struct mmc *mmc, uint width)
  698. {
  699. mmc->bus_width = width;
  700. mmc_set_ios(mmc);
  701. }
  702. static int mmc_startup(struct mmc *mmc)
  703. {
  704. int err;
  705. uint mult, freq;
  706. u64 cmult, csize, capacity;
  707. struct mmc_cmd cmd;
  708. ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, 512);
  709. ALLOC_CACHE_ALIGN_BUFFER(u8, test_csd, 512);
  710. int timeout = 1000;
  711. #ifdef CONFIG_MMC_SPI_CRC_ON
  712. if (mmc_host_is_spi(mmc)) { /* enable CRC check for spi */
  713. cmd.cmdidx = MMC_CMD_SPI_CRC_ON_OFF;
  714. cmd.resp_type = MMC_RSP_R1;
  715. cmd.cmdarg = 1;
  716. err = mmc_send_cmd(mmc, &cmd, NULL);
  717. if (err)
  718. return err;
  719. }
  720. #endif
  721. /* Put the Card in Identify Mode */
  722. cmd.cmdidx = mmc_host_is_spi(mmc) ? MMC_CMD_SEND_CID :
  723. MMC_CMD_ALL_SEND_CID; /* cmd not supported in spi */
  724. cmd.resp_type = MMC_RSP_R2;
  725. cmd.cmdarg = 0;
  726. err = mmc_send_cmd(mmc, &cmd, NULL);
  727. if (err)
  728. return err;
  729. memcpy(mmc->cid, cmd.response, 16);
  730. /*
  731. * For MMC cards, set the Relative Address.
  732. * For SD cards, get the Relatvie Address.
  733. * This also puts the cards into Standby State
  734. */
  735. if (!mmc_host_is_spi(mmc)) { /* cmd not supported in spi */
  736. cmd.cmdidx = SD_CMD_SEND_RELATIVE_ADDR;
  737. cmd.cmdarg = mmc->rca << 16;
  738. cmd.resp_type = MMC_RSP_R6;
  739. err = mmc_send_cmd(mmc, &cmd, NULL);
  740. if (err)
  741. return err;
  742. if (IS_SD(mmc))
  743. mmc->rca = (cmd.response[0] >> 16) & 0xffff;
  744. }
  745. /* Get the Card-Specific Data */
  746. cmd.cmdidx = MMC_CMD_SEND_CSD;
  747. cmd.resp_type = MMC_RSP_R2;
  748. cmd.cmdarg = mmc->rca << 16;
  749. err = mmc_send_cmd(mmc, &cmd, NULL);
  750. /* Waiting for the ready status */
  751. mmc_send_status(mmc, timeout);
  752. if (err)
  753. return err;
  754. mmc->csd[0] = cmd.response[0];
  755. mmc->csd[1] = cmd.response[1];
  756. mmc->csd[2] = cmd.response[2];
  757. mmc->csd[3] = cmd.response[3];
  758. if (mmc->version == MMC_VERSION_UNKNOWN) {
  759. int version = (cmd.response[0] >> 26) & 0xf;
  760. switch (version) {
  761. case 0:
  762. mmc->version = MMC_VERSION_1_2;
  763. break;
  764. case 1:
  765. mmc->version = MMC_VERSION_1_4;
  766. break;
  767. case 2:
  768. mmc->version = MMC_VERSION_2_2;
  769. break;
  770. case 3:
  771. mmc->version = MMC_VERSION_3;
  772. break;
  773. case 4:
  774. mmc->version = MMC_VERSION_4;
  775. break;
  776. default:
  777. mmc->version = MMC_VERSION_1_2;
  778. break;
  779. }
  780. }
  781. /* divide frequency by 10, since the mults are 10x bigger */
  782. freq = fbase[(cmd.response[0] & 0x7)];
  783. mult = multipliers[((cmd.response[0] >> 3) & 0xf)];
  784. mmc->tran_speed = freq * mult;
  785. mmc->read_bl_len = 1 << ((cmd.response[1] >> 16) & 0xf);
  786. if (IS_SD(mmc))
  787. mmc->write_bl_len = mmc->read_bl_len;
  788. else
  789. mmc->write_bl_len = 1 << ((cmd.response[3] >> 22) & 0xf);
  790. if (mmc->high_capacity) {
  791. csize = (mmc->csd[1] & 0x3f) << 16
  792. | (mmc->csd[2] & 0xffff0000) >> 16;
  793. cmult = 8;
  794. } else {
  795. csize = (mmc->csd[1] & 0x3ff) << 2
  796. | (mmc->csd[2] & 0xc0000000) >> 30;
  797. cmult = (mmc->csd[2] & 0x00038000) >> 15;
  798. }
  799. mmc->capacity = (csize + 1) << (cmult + 2);
  800. mmc->capacity *= mmc->read_bl_len;
  801. if (mmc->read_bl_len > 512)
  802. mmc->read_bl_len = 512;
  803. if (mmc->write_bl_len > 512)
  804. mmc->write_bl_len = 512;
  805. /* Select the card, and put it into Transfer Mode */
  806. if (!mmc_host_is_spi(mmc)) { /* cmd not supported in spi */
  807. cmd.cmdidx = MMC_CMD_SELECT_CARD;
  808. cmd.resp_type = MMC_RSP_R1;
  809. cmd.cmdarg = mmc->rca << 16;
  810. err = mmc_send_cmd(mmc, &cmd, NULL);
  811. if (err)
  812. return err;
  813. }
  814. /*
  815. * For SD, its erase group is always one sector
  816. */
  817. mmc->erase_grp_size = 1;
  818. mmc->part_config = MMCPART_NOAVAILABLE;
  819. if (!IS_SD(mmc) && (mmc->version >= MMC_VERSION_4)) {
  820. /* check ext_csd version and capacity */
  821. err = mmc_send_ext_csd(mmc, ext_csd);
  822. if (!err && (ext_csd[EXT_CSD_REV] >= 2)) {
  823. /*
  824. * According to the JEDEC Standard, the value of
  825. * ext_csd's capacity is valid if the value is more
  826. * than 2GB
  827. */
  828. capacity = ext_csd[EXT_CSD_SEC_CNT] << 0
  829. | ext_csd[EXT_CSD_SEC_CNT + 1] << 8
  830. | ext_csd[EXT_CSD_SEC_CNT + 2] << 16
  831. | ext_csd[EXT_CSD_SEC_CNT + 3] << 24;
  832. capacity *= 512;
  833. if ((capacity >> 20) > 2 * 1024)
  834. mmc->capacity = capacity;
  835. }
  836. switch (ext_csd[EXT_CSD_REV]) {
  837. case 1:
  838. mmc->version = MMC_VERSION_4_1;
  839. break;
  840. case 2:
  841. mmc->version = MMC_VERSION_4_2;
  842. break;
  843. case 3:
  844. mmc->version = MMC_VERSION_4_3;
  845. break;
  846. case 5:
  847. mmc->version = MMC_VERSION_4_41;
  848. break;
  849. case 6:
  850. mmc->version = MMC_VERSION_4_5;
  851. break;
  852. }
  853. /*
  854. * Check whether GROUP_DEF is set, if yes, read out
  855. * group size from ext_csd directly, or calculate
  856. * the group size from the csd value.
  857. */
  858. if (ext_csd[EXT_CSD_ERASE_GROUP_DEF])
  859. mmc->erase_grp_size =
  860. ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] * 512 * 1024;
  861. else {
  862. int erase_gsz, erase_gmul;
  863. erase_gsz = (mmc->csd[2] & 0x00007c00) >> 10;
  864. erase_gmul = (mmc->csd[2] & 0x000003e0) >> 5;
  865. mmc->erase_grp_size = (erase_gsz + 1)
  866. * (erase_gmul + 1);
  867. }
  868. /* store the partition info of emmc */
  869. if ((ext_csd[EXT_CSD_PARTITIONING_SUPPORT] & PART_SUPPORT) ||
  870. ext_csd[EXT_CSD_BOOT_MULT])
  871. mmc->part_config = ext_csd[EXT_CSD_PART_CONF];
  872. }
  873. if (IS_SD(mmc))
  874. err = sd_change_freq(mmc);
  875. else
  876. err = mmc_change_freq(mmc);
  877. if (err)
  878. return err;
  879. /* Restrict card's capabilities by what the host can do */
  880. mmc->card_caps &= mmc->host_caps;
  881. if (IS_SD(mmc)) {
  882. if (mmc->card_caps & MMC_MODE_4BIT) {
  883. cmd.cmdidx = MMC_CMD_APP_CMD;
  884. cmd.resp_type = MMC_RSP_R1;
  885. cmd.cmdarg = mmc->rca << 16;
  886. err = mmc_send_cmd(mmc, &cmd, NULL);
  887. if (err)
  888. return err;
  889. cmd.cmdidx = SD_CMD_APP_SET_BUS_WIDTH;
  890. cmd.resp_type = MMC_RSP_R1;
  891. cmd.cmdarg = 2;
  892. err = mmc_send_cmd(mmc, &cmd, NULL);
  893. if (err)
  894. return err;
  895. mmc_set_bus_width(mmc, 4);
  896. }
  897. if (mmc->card_caps & MMC_MODE_HS)
  898. mmc->tran_speed = 50000000;
  899. else
  900. mmc->tran_speed = 25000000;
  901. } else {
  902. int idx;
  903. /* An array of possible bus widths in order of preference */
  904. static unsigned ext_csd_bits[] = {
  905. EXT_CSD_BUS_WIDTH_8,
  906. EXT_CSD_BUS_WIDTH_4,
  907. EXT_CSD_BUS_WIDTH_1,
  908. };
  909. /* An array to map CSD bus widths to host cap bits */
  910. static unsigned ext_to_hostcaps[] = {
  911. [EXT_CSD_BUS_WIDTH_4] = MMC_MODE_4BIT,
  912. [EXT_CSD_BUS_WIDTH_8] = MMC_MODE_8BIT,
  913. };
  914. /* An array to map chosen bus width to an integer */
  915. static unsigned widths[] = {
  916. 8, 4, 1,
  917. };
  918. for (idx=0; idx < ARRAY_SIZE(ext_csd_bits); idx++) {
  919. unsigned int extw = ext_csd_bits[idx];
  920. /*
  921. * Check to make sure the controller supports
  922. * this bus width, if it's more than 1
  923. */
  924. if (extw != EXT_CSD_BUS_WIDTH_1 &&
  925. !(mmc->host_caps & ext_to_hostcaps[extw]))
  926. continue;
  927. err = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
  928. EXT_CSD_BUS_WIDTH, extw);
  929. if (err)
  930. continue;
  931. mmc_set_bus_width(mmc, widths[idx]);
  932. err = mmc_send_ext_csd(mmc, test_csd);
  933. if (!err && ext_csd[EXT_CSD_PARTITIONING_SUPPORT] \
  934. == test_csd[EXT_CSD_PARTITIONING_SUPPORT]
  935. && ext_csd[EXT_CSD_ERASE_GROUP_DEF] \
  936. == test_csd[EXT_CSD_ERASE_GROUP_DEF] \
  937. && ext_csd[EXT_CSD_REV] \
  938. == test_csd[EXT_CSD_REV]
  939. && ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE] \
  940. == test_csd[EXT_CSD_HC_ERASE_GRP_SIZE]
  941. && memcmp(&ext_csd[EXT_CSD_SEC_CNT], \
  942. &test_csd[EXT_CSD_SEC_CNT], 4) == 0) {
  943. mmc->card_caps |= ext_to_hostcaps[extw];
  944. break;
  945. }
  946. }
  947. if (mmc->card_caps & MMC_MODE_HS) {
  948. if (mmc->card_caps & MMC_MODE_HS_52MHz)
  949. mmc->tran_speed = 52000000;
  950. else
  951. mmc->tran_speed = 26000000;
  952. }
  953. }
  954. mmc_set_clock(mmc, mmc->tran_speed);
  955. /* fill in device description */
  956. mmc->block_dev.lun = 0;
  957. mmc->block_dev.type = 0;
  958. mmc->block_dev.blksz = mmc->read_bl_len;
  959. mmc->block_dev.lba = lldiv(mmc->capacity, mmc->read_bl_len);
  960. sprintf(mmc->block_dev.vendor, "Man %06x Snr %04x%04x",
  961. mmc->cid[0] >> 24, (mmc->cid[2] & 0xffff),
  962. (mmc->cid[3] >> 16) & 0xffff);
  963. sprintf(mmc->block_dev.product, "%c%c%c%c%c%c", mmc->cid[0] & 0xff,
  964. (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
  965. (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff,
  966. (mmc->cid[2] >> 24) & 0xff);
  967. sprintf(mmc->block_dev.revision, "%d.%d", (mmc->cid[2] >> 20) & 0xf,
  968. (mmc->cid[2] >> 16) & 0xf);
  969. #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBDISK_SUPPORT)
  970. init_part(&mmc->block_dev);
  971. #endif
  972. return 0;
  973. }
  974. static int mmc_send_if_cond(struct mmc *mmc)
  975. {
  976. struct mmc_cmd cmd;
  977. int err;
  978. cmd.cmdidx = SD_CMD_SEND_IF_COND;
  979. /* We set the bit if the host supports voltages between 2.7 and 3.6 V */
  980. cmd.cmdarg = ((mmc->voltages & 0xff8000) != 0) << 8 | 0xaa;
  981. cmd.resp_type = MMC_RSP_R7;
  982. err = mmc_send_cmd(mmc, &cmd, NULL);
  983. if (err)
  984. return err;
  985. if ((cmd.response[0] & 0xff) != 0xaa)
  986. return UNUSABLE_ERR;
  987. else
  988. mmc->version = SD_VERSION_2;
  989. return 0;
  990. }
  991. int mmc_register(struct mmc *mmc)
  992. {
  993. /* Setup the universal parts of the block interface just once */
  994. mmc->block_dev.if_type = IF_TYPE_MMC;
  995. mmc->block_dev.dev = cur_dev_num++;
  996. mmc->block_dev.removable = 1;
  997. mmc->block_dev.block_read = mmc_bread;
  998. mmc->block_dev.block_write = mmc_bwrite;
  999. mmc->block_dev.block_erase = mmc_berase;
  1000. if (!mmc->b_max)
  1001. mmc->b_max = CONFIG_SYS_MMC_MAX_BLK_COUNT;
  1002. INIT_LIST_HEAD (&mmc->link);
  1003. list_add_tail (&mmc->link, &mmc_devices);
  1004. return 0;
  1005. }
  1006. #ifdef CONFIG_PARTITIONS
  1007. block_dev_desc_t *mmc_get_dev(int dev)
  1008. {
  1009. struct mmc *mmc = find_mmc_device(dev);
  1010. if (!mmc || mmc_init(mmc))
  1011. return NULL;
  1012. return &mmc->block_dev;
  1013. }
  1014. #endif
  1015. int mmc_init(struct mmc *mmc)
  1016. {
  1017. int err;
  1018. if (mmc_getcd(mmc) == 0) {
  1019. mmc->has_init = 0;
  1020. printf("MMC: no card present\n");
  1021. return NO_CARD_ERR;
  1022. }
  1023. if (mmc->has_init)
  1024. return 0;
  1025. err = mmc->init(mmc);
  1026. if (err)
  1027. return err;
  1028. mmc_set_bus_width(mmc, 1);
  1029. mmc_set_clock(mmc, 1);
  1030. /* Reset the Card */
  1031. err = mmc_go_idle(mmc);
  1032. if (err)
  1033. return err;
  1034. /* The internal partition reset to user partition(0) at every CMD0*/
  1035. mmc->part_num = 0;
  1036. /* Test for SD version 2 */
  1037. err = mmc_send_if_cond(mmc);
  1038. /* Now try to get the SD card's operating condition */
  1039. err = sd_send_op_cond(mmc);
  1040. /* If the command timed out, we check for an MMC card */
  1041. if (err == TIMEOUT) {
  1042. err = mmc_send_op_cond(mmc);
  1043. if (err) {
  1044. printf("Card did not respond to voltage select!\n");
  1045. return UNUSABLE_ERR;
  1046. }
  1047. }
  1048. err = mmc_startup(mmc);
  1049. if (err)
  1050. mmc->has_init = 0;
  1051. else
  1052. mmc->has_init = 1;
  1053. return err;
  1054. }
  1055. /*
  1056. * CPU and board-specific MMC initializations. Aliased function
  1057. * signals caller to move on
  1058. */
  1059. static int __def_mmc_init(bd_t *bis)
  1060. {
  1061. return -1;
  1062. }
  1063. int cpu_mmc_init(bd_t *bis) __attribute__((weak, alias("__def_mmc_init")));
  1064. int board_mmc_init(bd_t *bis) __attribute__((weak, alias("__def_mmc_init")));
  1065. void print_mmc_devices(char separator)
  1066. {
  1067. struct mmc *m;
  1068. struct list_head *entry;
  1069. list_for_each(entry, &mmc_devices) {
  1070. m = list_entry(entry, struct mmc, link);
  1071. printf("%s: %d", m->name, m->block_dev.dev);
  1072. if (entry->next != &mmc_devices)
  1073. printf("%c ", separator);
  1074. }
  1075. printf("\n");
  1076. }
  1077. int get_mmc_num(void)
  1078. {
  1079. return cur_dev_num;
  1080. }
  1081. int mmc_initialize(bd_t *bis)
  1082. {
  1083. INIT_LIST_HEAD (&mmc_devices);
  1084. cur_dev_num = 0;
  1085. if (board_mmc_init(bis) < 0)
  1086. cpu_mmc_init(bis);
  1087. print_mmc_devices(',');
  1088. return 0;
  1089. }