cmd_mmc.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /*
  2. * (C) Copyright 2003
  3. * Kyle Harris, kharris@nexus-tech.net
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <command.h>
  25. #include <mmc.h>
  26. #ifndef CONFIG_GENERIC_MMC
  27. int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  28. {
  29. if (mmc_legacy_init (1) != 0) {
  30. printf ("No MMC card found\n");
  31. return 1;
  32. }
  33. return 0;
  34. }
  35. U_BOOT_CMD(
  36. mmcinit, 1, 0, do_mmc,
  37. "init mmc card",
  38. NULL
  39. );
  40. #else /* !CONFIG_GENERIC_MMC */
  41. static void print_mmcinfo(struct mmc *mmc)
  42. {
  43. printf("Device: %s\n", mmc->name);
  44. printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
  45. printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
  46. printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
  47. (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
  48. (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
  49. printf("Tran Speed: %d\n", mmc->tran_speed);
  50. printf("Rd Block Len: %d\n", mmc->read_bl_len);
  51. printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC",
  52. (mmc->version >> 4) & 0xf, mmc->version & 0xf);
  53. printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
  54. printf("Capacity: %lld\n", mmc->capacity);
  55. printf("Bus Width: %d-bit\n", mmc->bus_width);
  56. }
  57. int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  58. {
  59. struct mmc *mmc;
  60. int dev_num;
  61. if (argc < 2)
  62. dev_num = 0;
  63. else
  64. dev_num = simple_strtoul(argv[1], NULL, 0);
  65. mmc = find_mmc_device(dev_num);
  66. if (mmc) {
  67. mmc_init(mmc);
  68. print_mmcinfo(mmc);
  69. }
  70. return 0;
  71. }
  72. U_BOOT_CMD(mmcinfo, 2, 0, do_mmcinfo, "mmcinfo <dev num>-- display MMC info\n",
  73. NULL);
  74. int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  75. {
  76. int rc = 0;
  77. switch (argc) {
  78. case 3:
  79. if (strcmp(argv[1], "rescan") == 0) {
  80. int dev = simple_strtoul(argv[2], NULL, 10);
  81. struct mmc *mmc = find_mmc_device(dev);
  82. mmc_init(mmc);
  83. return 0;
  84. }
  85. case 0:
  86. case 1:
  87. case 4:
  88. printf("Usage:\n%s\n", cmdtp->usage);
  89. return 1;
  90. case 2:
  91. if (!strcmp(argv[1], "list")) {
  92. print_mmc_devices('\n');
  93. return 0;
  94. }
  95. return 1;
  96. default: /* at least 5 args */
  97. if (strcmp(argv[1], "read") == 0) {
  98. int dev = simple_strtoul(argv[2], NULL, 10);
  99. void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
  100. u32 cnt = simple_strtoul(argv[5], NULL, 16);
  101. u32 n;
  102. u32 blk = simple_strtoul(argv[4], NULL, 16);
  103. struct mmc *mmc = find_mmc_device(dev);
  104. printf("\nMMC read: dev # %d, block # %d, count %d ... ",
  105. dev, blk, cnt);
  106. mmc_init(mmc);
  107. n = mmc->block_dev.block_read(dev, blk, cnt, addr);
  108. /* flush cache after read */
  109. flush_cache((ulong)addr, cnt * 512); /* FIXME */
  110. printf("%d blocks read: %s\n",
  111. n, (n==cnt) ? "OK" : "ERROR");
  112. return (n == cnt) ? 0 : 1;
  113. } else if (strcmp(argv[1], "write") == 0) {
  114. int dev = simple_strtoul(argv[2], NULL, 10);
  115. void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
  116. u32 cnt = simple_strtoul(argv[5], NULL, 16);
  117. u32 n;
  118. struct mmc *mmc = find_mmc_device(dev);
  119. int blk = simple_strtoul(argv[4], NULL, 16);
  120. printf("\nMMC write: dev # %d, block # %d, count %d ... ",
  121. dev, blk, cnt);
  122. mmc_init(mmc);
  123. n = mmc->block_dev.block_write(dev, blk, cnt, addr);
  124. printf("%d blocks written: %s\n",
  125. n, (n == cnt) ? "OK" : "ERROR");
  126. return (n == cnt) ? 0 : 1;
  127. } else {
  128. printf("Usage:\n%s\n", cmdtp->usage);
  129. rc = 1;
  130. }
  131. return rc;
  132. }
  133. }
  134. U_BOOT_CMD(
  135. mmc, 6, 1, do_mmcops,
  136. "mmc - MMC sub system\n",
  137. "mmc read <device num> addr blk# cnt\n"
  138. "mmc write <device num> addr blk# cnt\n"
  139. "mmc rescan <device num>\n"
  140. "mmc list - lists available devices\n");
  141. #endif