diff options
author | Lei Wen <leiwen@marvell.com> | 2011-05-02 16:26:25 +0000 |
---|---|---|
committer | Andy Fleming <afleming@freescale.com> | 2011-05-18 14:36:35 -0500 |
commit | ea6ebe21772568ee97fb5c23c01e993140f0e0e6 (patch) | |
tree | 2abbfeafb64e44f214f36c685f562c0483005d05 | |
parent | ed018b21d61614e0431f6bf514bec6e4bf64fe31 (diff) | |
download | u-boot-ea6ebe21772568ee97fb5c23c01e993140f0e0e6.tar.gz u-boot-ea6ebe21772568ee97fb5c23c01e993140f0e0e6.tar.xz u-boot-ea6ebe21772568ee97fb5c23c01e993140f0e0e6.zip |
cmd_mmc: eliminate device num in the mmc command
mmc command applied device, like ide and usb...
Signed-off-by: Lei Wen <leiwen@marvell.com>
Acked-by: Andy Fleming <afleming@freescale.com>
-rw-r--r-- | common/cmd_mmc.c | 198 | ||||
-rw-r--r-- | drivers/mmc/mmc.c | 5 | ||||
-rw-r--r-- | include/mmc.h | 1 |
3 files changed, 116 insertions, 88 deletions
diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c index 6166749ad5..e266d4fa43 100644 --- a/common/cmd_mmc.c +++ b/common/cmd_mmc.c @@ -25,9 +25,8 @@ #include <command.h> #include <mmc.h> -#ifndef CONFIG_GENERIC_MMC static int curr_device = -1; - +#ifndef CONFIG_GENERIC_MMC int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { int dev; @@ -113,140 +112,163 @@ static void print_mmcinfo(struct mmc *mmc) int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { struct mmc *mmc; - int dev_num; - if (argc < 2) - dev_num = 0; - else - dev_num = simple_strtoul(argv[1], NULL, 0); + if (curr_device < 0) { + if (get_mmc_num() > 0) + curr_device = 0; + else { + puts("No MMC device available\n"); + return 1; + } + } - mmc = find_mmc_device(dev_num); + mmc = find_mmc_device(curr_device); if (mmc) { mmc_init(mmc); print_mmcinfo(mmc); + return 0; + } else { + printf("no mmc device at slot %x\n", curr_device); + return 1; } - - return 0; } U_BOOT_CMD( - mmcinfo, 2, 0, do_mmcinfo, + mmcinfo, 1, 0, do_mmcinfo, "display MMC info", - "<dev num>\n" " - device number of the device to dislay info of\n" "" ); int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) { - int rc = 0; + if (argc < 2) + return cmd_usage(cmdtp); - switch (argc) { - case 3: - if (strcmp(argv[1], "rescan") == 0) { - int dev = simple_strtoul(argv[2], NULL, 10); - struct mmc *mmc = find_mmc_device(dev); + if (curr_device < 0) { + if (get_mmc_num() > 0) + curr_device = 0; + else { + puts("No MMC device available\n"); + return 1; + } + } - if (!mmc) - return 1; + if (strcmp(argv[1], "rescan") == 0) { + struct mmc *mmc = find_mmc_device(curr_device); - mmc_init(mmc); + if (!mmc) { + printf("no mmc device at slot %x\n", curr_device); + return 1; + } + + mmc_init(mmc); + return 0; + } else if (strncmp(argv[1], "part", 4) == 0) { + block_dev_desc_t *mmc_dev; + struct mmc *mmc = find_mmc_device(curr_device); + + if (!mmc) { + printf("no mmc device at slot %x\n", curr_device); + return 1; + } + mmc_init(mmc); + mmc_dev = mmc_get_dev(curr_device); + if (mmc_dev != NULL && + mmc_dev->type != DEV_TYPE_UNKNOWN) { + print_part(mmc_dev); return 0; - } else if (strncmp(argv[1], "part", 4) == 0) { - int dev = simple_strtoul(argv[2], NULL, 10); - block_dev_desc_t *mmc_dev; - struct mmc *mmc = find_mmc_device(dev); + } - if (!mmc) { - puts("no mmc devices available\n"); - return 1; - } - mmc_init(mmc); - mmc_dev = mmc_get_dev(dev); - if (mmc_dev != NULL && - mmc_dev->type != DEV_TYPE_UNKNOWN) { - print_part(mmc_dev); - return 0; - } + puts("get mmc type error!\n"); + return 1; + } else if (strcmp(argv[1], "list") == 0) { + print_mmc_devices('\n'); + return 0; + } else if (strcmp(argv[1], "dev") == 0) { + int dev; + struct mmc *mmc; + + if (argc == 2) + dev = curr_device; + else if (argc == 3) + dev = simple_strtoul(argv[2], NULL, 10); + else + return cmd_usage(cmdtp); - puts("get mmc type error!\n"); + mmc = find_mmc_device(dev); + if (!mmc) { + printf("no mmc device at slot %x\n", dev); return 1; } - case 0: - case 1: - case 4: - return cmd_usage(cmdtp); + curr_device = dev; + printf("mmc%d is current device\n", curr_device); - case 2: - if (!strcmp(argv[1], "list")) { - print_mmc_devices('\n'); - return 0; + return 0; + } else if (strcmp(argv[1], "read") == 0) { + void *addr = (void *)simple_strtoul(argv[2], NULL, 16); + u32 cnt = simple_strtoul(argv[4], NULL, 16); + u32 n; + u32 blk = simple_strtoul(argv[3], NULL, 16); + struct mmc *mmc = find_mmc_device(curr_device); + + if (!mmc) { + printf("no mmc device at slot %x\n", curr_device); + return 1; } - return 1; - default: /* at least 5 args */ - if (strcmp(argv[1], "read") == 0) { - int dev = simple_strtoul(argv[2], NULL, 10); - void *addr = (void *)simple_strtoul(argv[3], NULL, 16); - u32 cnt = simple_strtoul(argv[5], NULL, 16); - u32 n; - u32 blk = simple_strtoul(argv[4], NULL, 16); - struct mmc *mmc = find_mmc_device(dev); - - if (!mmc) - return 1; - printf("\nMMC read: dev # %d, block # %d, count %d ... ", - dev, blk, cnt); + printf("\nMMC read: dev # %d, block # %d, count %d ... ", + curr_device, blk, cnt); - mmc_init(mmc); + mmc_init(mmc); - n = mmc->block_dev.block_read(dev, blk, cnt, addr); + n = mmc->block_dev.block_read(curr_device, blk, cnt, addr); - /* flush cache after read */ - flush_cache((ulong)addr, cnt * 512); /* FIXME */ + /* flush cache after read */ + flush_cache((ulong)addr, cnt * 512); /* FIXME */ - printf("%d blocks read: %s\n", + printf("%d blocks read: %s\n", n, (n==cnt) ? "OK" : "ERROR"); - return (n == cnt) ? 0 : 1; - } else if (strcmp(argv[1], "write") == 0) { - int dev = simple_strtoul(argv[2], NULL, 10); - void *addr = (void *)simple_strtoul(argv[3], NULL, 16); - u32 cnt = simple_strtoul(argv[5], NULL, 16); - u32 n; - struct mmc *mmc = find_mmc_device(dev); + return (n == cnt) ? 0 : 1; + } else if (strcmp(argv[1], "write") == 0) { + void *addr = (void *)simple_strtoul(argv[2], NULL, 16); + u32 cnt = simple_strtoul(argv[4], NULL, 16); + u32 n; + struct mmc *mmc = find_mmc_device(curr_device); - int blk = simple_strtoul(argv[4], NULL, 16); + int blk = simple_strtoul(argv[3], NULL, 16); - if (!mmc) - return 1; + if (!mmc) { + printf("no mmc device at slot %x\n", curr_device); + return 1; + } - printf("\nMMC write: dev # %d, block # %d, count %d ... ", - dev, blk, cnt); + printf("\nMMC write: dev # %d, block # %d, count %d ... ", + curr_device, blk, cnt); - mmc_init(mmc); + mmc_init(mmc); - n = mmc->block_dev.block_write(dev, blk, cnt, addr); + n = mmc->block_dev.block_write(curr_device, blk, cnt, addr); - printf("%d blocks written: %s\n", + printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR"); - return (n == cnt) ? 0 : 1; - } else - rc = cmd_usage(cmdtp); - - return rc; + return (n == cnt) ? 0 : 1; } + + return cmd_usage(cmdtp); } U_BOOT_CMD( mmc, 6, 1, do_mmcops, "MMC sub system", - "read <device num> addr blk# cnt\n" - "mmc write <device num> addr blk# cnt\n" - "mmc rescan <device num>\n" - "mmc part <device num> - lists available partition on mmc\n" + "read addr blk# cnt\n" + "mmc write addr blk# cnt\n" + "mmc rescan\n" + "mmc part - lists available partition on current mmc device\n" + "mmc dev [dev] - show or set current mmc device\n" "mmc list - lists available devices"); #endif diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index f6d31f5848..cdf2713bad 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1110,6 +1110,11 @@ void print_mmc_devices(char separator) printf("\n"); } +int get_mmc_num(void) +{ + return cur_dev_num; +} + int mmc_initialize(bd_t *bis) { INIT_LIST_HEAD (&mmc_devices); diff --git a/include/mmc.h b/include/mmc.h index 863b7e293b..5501f5547a 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -295,6 +295,7 @@ void mmc_set_clock(struct mmc *mmc, uint clock); struct mmc *find_mmc_device(int dev_num); int mmc_set_dev(int dev_num); void print_mmc_devices(char separator); +int get_mmc_num(void); int board_mmc_getcd(u8 *cd, struct mmc *mmc); #ifdef CONFIG_GENERIC_MMC |