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 * const argv[])
36 return cmd_usage(cmdtp);
38 if (strcmp(argv[1], "init") == 0) {
44 } else if (argc == 3) {
45 dev = (int)simple_strtoul(argv[2], NULL, 10);
47 return cmd_usage(cmdtp);
50 if (mmc_legacy_init(dev) != 0) {
51 puts("No MMC card found\n");
56 printf("mmc%d is available\n", curr_device);
57 } else if (strcmp(argv[1], "device") == 0) {
59 if (curr_device < 0) {
60 puts("No MMC device available\n");
63 } else if (argc == 3) {
64 dev = (int)simple_strtoul(argv[2], NULL, 10);
66 #ifdef CONFIG_SYS_MMC_SET_DEV
67 if (mmc_set_dev(dev) != 0)
72 return cmd_usage(cmdtp);
75 printf("mmc%d is current device\n", curr_device);
77 return cmd_usage(cmdtp);
86 "init [dev] - init MMC sub system\n"
87 "mmc device [dev] - show or set current device"
89 #else /* !CONFIG_GENERIC_MMC */
91 static void print_mmcinfo(struct mmc *mmc)
93 printf("Device: %s\n", mmc->name);
94 printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
95 printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
96 printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
97 (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
98 (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
100 printf("Tran Speed: %d\n", mmc->tran_speed);
101 printf("Rd Block Len: %d\n", mmc->read_bl_len);
103 printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC",
104 (mmc->version >> 4) & 0xf, mmc->version & 0xf);
106 printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
108 print_size(mmc->capacity, "\n");
110 printf("Bus Width: %d-bit\n", mmc->bus_width);
113 int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
121 dev_num = simple_strtoul(argv[1], NULL, 0);
123 mmc = find_mmc_device(dev_num);
135 mmcinfo, 2, 0, do_mmcinfo,
138 " - device number of the device to dislay info of\n"
142 int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
148 if (strcmp(argv[1], "rescan") == 0) {
149 int dev = simple_strtoul(argv[2], NULL, 10);
150 struct mmc *mmc = find_mmc_device(dev);
158 } else if (strncmp(argv[1], "part", 4) == 0) {
159 int dev = simple_strtoul(argv[2], NULL, 10);
160 block_dev_desc_t *mmc_dev;
161 struct mmc *mmc = find_mmc_device(dev);
164 puts("no mmc devices available\n");
168 mmc_dev = mmc_get_dev(dev);
169 if (mmc_dev != NULL &&
170 mmc_dev->type != DEV_TYPE_UNKNOWN) {
175 puts("get mmc type error!\n");
182 return cmd_usage(cmdtp);
185 if (!strcmp(argv[1], "list")) {
186 print_mmc_devices('\n');
190 default: /* at least 5 args */
191 if (strcmp(argv[1], "read") == 0) {
192 int dev = simple_strtoul(argv[2], NULL, 10);
193 void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
194 u32 cnt = simple_strtoul(argv[5], NULL, 16);
196 u32 blk = simple_strtoul(argv[4], NULL, 16);
197 struct mmc *mmc = find_mmc_device(dev);
202 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
207 n = mmc->block_dev.block_read(dev, blk, cnt, addr);
209 /* flush cache after read */
210 flush_cache((ulong)addr, cnt * 512); /* FIXME */
212 printf("%d blocks read: %s\n",
213 n, (n==cnt) ? "OK" : "ERROR");
214 return (n == cnt) ? 0 : 1;
215 } else if (strcmp(argv[1], "write") == 0) {
216 int dev = simple_strtoul(argv[2], NULL, 10);
217 void *addr = (void *)simple_strtoul(argv[3], NULL, 16);
218 u32 cnt = simple_strtoul(argv[5], NULL, 16);
220 struct mmc *mmc = find_mmc_device(dev);
222 int blk = simple_strtoul(argv[4], NULL, 16);
227 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
232 n = mmc->block_dev.block_write(dev, blk, cnt, addr);
234 printf("%d blocks written: %s\n",
235 n, (n == cnt) ? "OK" : "ERROR");
236 return (n == cnt) ? 0 : 1;
238 rc = cmd_usage(cmdtp);
245 mmc, 6, 1, do_mmcops,
247 "read <device num> addr blk# cnt\n"
248 "mmc write <device num> addr blk# cnt\n"
249 "mmc rescan <device num>\n"
250 "mmc part <device num> - lists available partition on mmc\n"
251 "mmc list - lists available devices");