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 static int curr_device = -1;
29 #ifndef CONFIG_GENERIC_MMC
30 int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
35 return cmd_usage(cmdtp);
37 if (strcmp(argv[1], "init") == 0) {
43 } else if (argc == 3) {
44 dev = (int)simple_strtoul(argv[2], NULL, 10);
46 return cmd_usage(cmdtp);
49 if (mmc_legacy_init(dev) != 0) {
50 puts("No MMC card found\n");
55 printf("mmc%d is available\n", curr_device);
56 } else if (strcmp(argv[1], "device") == 0) {
58 if (curr_device < 0) {
59 puts("No MMC device available\n");
62 } else if (argc == 3) {
63 dev = (int)simple_strtoul(argv[2], NULL, 10);
65 #ifdef CONFIG_SYS_MMC_SET_DEV
66 if (mmc_set_dev(dev) != 0)
71 return cmd_usage(cmdtp);
74 printf("mmc%d is current device\n", curr_device);
76 return cmd_usage(cmdtp);
85 "init [dev] - init MMC sub system\n"
86 "mmc device [dev] - show or set current device"
88 #else /* !CONFIG_GENERIC_MMC */
90 static void print_mmcinfo(struct mmc *mmc)
92 printf("Device: %s\n", mmc->name);
93 printf("Manufacturer ID: %x\n", mmc->cid[0] >> 24);
94 printf("OEM: %x\n", (mmc->cid[0] >> 8) & 0xffff);
95 printf("Name: %c%c%c%c%c \n", mmc->cid[0] & 0xff,
96 (mmc->cid[1] >> 24), (mmc->cid[1] >> 16) & 0xff,
97 (mmc->cid[1] >> 8) & 0xff, mmc->cid[1] & 0xff);
99 printf("Tran Speed: %d\n", mmc->tran_speed);
100 printf("Rd Block Len: %d\n", mmc->read_bl_len);
102 printf("%s version %d.%d\n", IS_SD(mmc) ? "SD" : "MMC",
103 (mmc->version >> 4) & 0xf, mmc->version & 0xf);
105 printf("High Capacity: %s\n", mmc->high_capacity ? "Yes" : "No");
107 print_size(mmc->capacity, "\n");
109 printf("Bus Width: %d-bit\n", mmc->bus_width);
112 int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
116 if (curr_device < 0) {
117 if (get_mmc_num() > 0)
120 puts("No MMC device available\n");
125 mmc = find_mmc_device(curr_device);
133 printf("no mmc device at slot %x\n", curr_device);
139 mmcinfo, 1, 0, do_mmcinfo,
141 " - device number of the device to dislay info of\n"
145 int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
148 return cmd_usage(cmdtp);
150 if (curr_device < 0) {
151 if (get_mmc_num() > 0)
154 puts("No MMC device available\n");
159 if (strcmp(argv[1], "rescan") == 0) {
160 struct mmc *mmc = find_mmc_device(curr_device);
163 printf("no mmc device at slot %x\n", curr_device);
171 } else if (strncmp(argv[1], "part", 4) == 0) {
172 block_dev_desc_t *mmc_dev;
173 struct mmc *mmc = find_mmc_device(curr_device);
176 printf("no mmc device at slot %x\n", curr_device);
180 mmc_dev = mmc_get_dev(curr_device);
181 if (mmc_dev != NULL &&
182 mmc_dev->type != DEV_TYPE_UNKNOWN) {
187 puts("get mmc type error!\n");
189 } else if (strcmp(argv[1], "list") == 0) {
190 print_mmc_devices('\n');
192 } else if (strcmp(argv[1], "dev") == 0) {
199 dev = simple_strtoul(argv[2], NULL, 10);
200 else if (argc == 4) {
201 dev = (int)simple_strtoul(argv[2], NULL, 10);
202 part = (int)simple_strtoul(argv[3], NULL, 10);
203 if (part > PART_ACCESS_MASK) {
204 printf("#part_num shouldn't be larger"
205 " than %d\n", PART_ACCESS_MASK);
209 return cmd_usage(cmdtp);
211 mmc = find_mmc_device(dev);
213 printf("no mmc device at slot %x\n", dev);
220 if (mmc->part_config == MMCPART_NOAVAILABLE) {
221 printf("Card doesn't support part_switch\n");
225 if (part != mmc->part_num) {
226 ret = mmc_switch_part(dev, part);
228 mmc->part_num = part;
230 printf("switch to partions #%d, %s\n",
231 part, (!ret) ? "OK" : "ERROR");
235 if (mmc->part_config == MMCPART_NOAVAILABLE)
236 printf("mmc%d is current device\n", curr_device);
238 printf("mmc%d(part %d) is current device\n",
239 curr_device, mmc->part_num);
242 } else if (strcmp(argv[1], "read") == 0) {
243 void *addr = (void *)simple_strtoul(argv[2], NULL, 16);
244 u32 cnt = simple_strtoul(argv[4], NULL, 16);
246 u32 blk = simple_strtoul(argv[3], NULL, 16);
247 struct mmc *mmc = find_mmc_device(curr_device);
250 printf("no mmc device at slot %x\n", curr_device);
254 printf("\nMMC read: dev # %d, block # %d, count %d ... ",
255 curr_device, blk, cnt);
259 n = mmc->block_dev.block_read(curr_device, blk, cnt, addr);
261 /* flush cache after read */
262 flush_cache((ulong)addr, cnt * 512); /* FIXME */
264 printf("%d blocks read: %s\n",
265 n, (n==cnt) ? "OK" : "ERROR");
266 return (n == cnt) ? 0 : 1;
267 } else if (strcmp(argv[1], "write") == 0) {
268 void *addr = (void *)simple_strtoul(argv[2], NULL, 16);
269 u32 cnt = simple_strtoul(argv[4], NULL, 16);
271 struct mmc *mmc = find_mmc_device(curr_device);
273 int blk = simple_strtoul(argv[3], NULL, 16);
276 printf("no mmc device at slot %x\n", curr_device);
280 printf("\nMMC write: dev # %d, block # %d, count %d ... ",
281 curr_device, blk, cnt);
285 n = mmc->block_dev.block_write(curr_device, blk, cnt, addr);
287 printf("%d blocks written: %s\n",
288 n, (n == cnt) ? "OK" : "ERROR");
289 return (n == cnt) ? 0 : 1;
292 return cmd_usage(cmdtp);
296 mmc, 6, 1, do_mmcops,
298 "read addr blk# cnt\n"
299 "mmc write addr blk# cnt\n"
301 "mmc part - lists available partition on current mmc device\n"
302 "mmc dev [dev] [part] - show or set current mmc device [partition]\n"
303 "mmc list - lists available devices");