3 * Kyle Harris, kharris@nexus-tech.net
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
28 #ifndef CONFIG_GENERIC_MMC
29 static int curr_device = -1;
31 int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
40 if (strcmp(argv[1], "init") == 0) {
46 } else if (argc == 3) {
47 dev = (int)simple_strtoul(argv[2], NULL, 10);
53 if (mmc_legacy_init(dev) != 0) {
54 puts("No MMC card found\n");
59 printf("mmc%d is available\n", curr_device);
60 } else if (strcmp(argv[1], "device") == 0) {
62 if (curr_device < 0) {
63 puts("No MMC device available\n");
66 } else if (argc == 3) {
67 dev = (int)simple_strtoul(argv[2], NULL, 10);
69 #ifdef CONFIG_SYS_MMC_SET_DEV
70 if (mmc_set_dev(dev) != 0)
79 printf("mmc%d is current device\n", curr_device);
91 "init [dev] - init MMC sub system\n"
92 "mmc device [dev] - show or set current device"
94 #else /* !CONFIG_GENERIC_MMC */
96 static void print_mmcinfo(struct mmc *mmc)
98 printf("Device: %s\n", mmc->name);
99 printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
100 printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
101 printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
102 (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
103 (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
105 printf("Tran Speed: %d\n", mmc->tran_speed);
106 printf("Rd Block Len: %d\n", mmc->read_bl_len);
108 printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC",
109 (mmc->version >> 4) & 0xf, mmc->version & 0xf);
111 printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
113 if (mmc->high_capacity)
114 printf("Capacity: %lld MByte\n", mmc->capacity >> 11);
116 printf("Capacity: %lld\n", mmc->capacity);
118 printf("Bus Width: %d-bit\n", mmc->bus_width);
121 int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
129 dev_num = simple_strtoul(argv[1], NULL, 0);
131 mmc = find_mmc_device(dev_num);
142 U_BOOT_CMD(mmcinfo, 2, 0, do_mmcinfo,
143 "mmcinfo <dev num>-- display MMC info",
147 int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
153 if (strcmp(argv[1], "rescan") == 0) {
154 int dev = simple_strtoul(argv[2], NULL, 10);
155 struct mmc *mmc = find_mmc_device(dev);
168 printf("Usage:\n%s\n", cmdtp->usage);
172 if (!strcmp(argv[1], "list")) {
173 print_mmc_devices('\n');
177 default: /* at least 5 args */
178 if (strcmp(argv[1], "read") == 0) {
179 int dev = simple_strtoul(argv[2], NULL, 10);
180 void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
181 u32 cnt = simple_strtoul(argv[5], NULL, 16);
183 u32 blk = simple_strtoul(argv[4], NULL, 16);
184 struct mmc *mmc = find_mmc_device(dev);
189 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
194 n = mmc->block_dev.block_read(dev, blk, cnt, addr);
196 /* flush cache after read */
197 flush_cache((ulong)addr, cnt * 512); /* FIXME */
199 printf("%d blocks read: %s\n",
200 n, (n==cnt) ? "OK" : "ERROR");
201 return (n == cnt) ? 0 : 1;
202 } else if (strcmp(argv[1], "write") == 0) {
203 int dev = simple_strtoul(argv[2], NULL, 10);
204 void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
205 u32 cnt = simple_strtoul(argv[5], NULL, 16);
207 struct mmc *mmc = find_mmc_device(dev);
209 int blk = simple_strtoul(argv[4], NULL, 16);
214 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
219 n = mmc->block_dev.block_write(dev, blk, cnt, addr);
221 printf("%d blocks written: %s\n",
222 n, (n == cnt) ? "OK" : "ERROR");
223 return (n == cnt) ? 0 : 1;
225 printf("Usage:\n%s\n", cmdtp->usage);
234 mmc, 6, 1, do_mmcops,
236 "read <device num> addr blk# cnt\n"
237 "mmc write <device num> addr blk# cnt\n"
238 "mmc rescan <device num>\n"
239 "mmc list - lists available devices");