>From now on, follow the general rule "mmc dev [dev]" to change the mmc command applied device, like ide and usb...
Signed-off-by: Lei Wen <lei...@marvell.com> --- Changelog: V2: use the "mmc_cur_dev" to replace explicitly specify the dev num in mmc command. common/cmd_mmc.c | 173 +++++++++++++++++++++++++++------------------------- drivers/mmc/mmc.c | 16 ++++- include/mmc.h | 3 + 3 files changed, 105 insertions(+), 87 deletions(-) diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c index 4323f76..dd4ee23 100644 --- a/common/cmd_mmc.c +++ b/common/cmd_mmc.c @@ -112,14 +112,13 @@ 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 (mmc_cur_dev < 0) { + puts("No MMC card found\n"); + return 1; + } - mmc = find_mmc_device(dev_num); + mmc = find_mmc_device(mmc_cur_dev); if (mmc) { mmc_init(mmc); @@ -131,121 +130,129 @@ int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } 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 (strcmp(argv[1], "rescan") == 0) { + struct mmc *mmc = find_mmc_device(mmc_cur_dev); - if (!mmc) - return 1; + if (!mmc) + return 1; + + mmc_init(mmc); - 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(mmc_cur_dev); + if (!mmc) { + puts("no mmc devices available\n"); + return 1; + } + mmc_init(mmc); + mmc_dev = mmc_get_dev(mmc_cur_dev); + 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"); + 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 = mmc_cur_dev; + struct mmc *mmc; + + if (argc == 2) { + if (mmc_cur_dev < 0) { + puts("No MMC device 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; - } + } 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("There is no MMC device on slot %d\n", dev); return 1; } - case 0: - case 1: - case 4: - return cmd_usage(cmdtp); + mmc_cur_dev = dev; + printf("mmc%d is current device\n", mmc_cur_dev); - case 2: - if (!strcmp(argv[1], "list")) { - print_mmc_devices('\n'); - return 0; - } - 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; + 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(mmc_cur_dev); - printf("\nMMC read: dev # %d, block # %d, count %d ... ", - dev, blk, cnt); + if (!mmc) + return 1; - mmc_init(mmc); + printf("\nMMC read: dev # %d, block # %d, count %d ... ", + mmc_cur_dev, blk, cnt); - n = mmc->block_dev.block_read(dev, blk, cnt, addr); + mmc_init(mmc); - /* flush cache after read */ - flush_cache((ulong)addr, cnt * 512); /* FIXME */ + n = mmc->block_dev.block_read(mmc_cur_dev, blk, cnt, addr); - printf("%d blocks read: %s\n", + /* flush cache after read */ + flush_cache((ulong)addr, cnt * 512); /* FIXME */ + + 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(mmc_cur_dev); - int blk = simple_strtoul(argv[4], NULL, 16); + int blk = simple_strtoul(argv[3], NULL, 16); - if (!mmc) - return 1; + if (!mmc) + return 1; - printf("\nMMC write: dev # %d, block # %d, count %d ... ", - dev, blk, cnt); + printf("\nMMC write: dev # %d, block # %d, count %d ... ", + mmc_cur_dev, blk, cnt); - mmc_init(mmc); + mmc_init(mmc); - n = mmc->block_dev.block_write(dev, blk, cnt, addr); + n = mmc->block_dev.block_write(mmc_cur_dev, 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 6805b33..377f13a 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -34,7 +34,7 @@ #include <div64.h> static struct list_head mmc_devices; -static int cur_dev_num = -1; +int mmc_cur_dev = -1; int __board_mmc_getcd(u8 *cd, struct mmc *mmc) { return -1; @@ -849,7 +849,7 @@ int mmc_register(struct mmc *mmc) { /* Setup the universal parts of the block interface just once */ mmc->block_dev.if_type = IF_TYPE_MMC; - mmc->block_dev.dev = cur_dev_num++; + mmc->block_dev.dev = mmc_cur_dev++; mmc->block_dev.removable = 1; mmc->block_dev.block_read = mmc_bread; mmc->block_dev.block_write = mmc_bwrite; @@ -936,12 +936,20 @@ void print_mmc_devices(char separator) int mmc_initialize(bd_t *bis) { + int ret = -1; INIT_LIST_HEAD (&mmc_devices); - cur_dev_num = 0; + mmc_cur_dev = 0; if (board_mmc_init(bis) < 0) - cpu_mmc_init(bis); + ret = cpu_mmc_init(bis); + else + ret = 0; + /* Put the device 0 as the default */ + if (ret < 0) + mmc_cur_dev = -1; + else + mmc_cur_dev = 0; print_mmc_devices(','); return 0; diff --git a/include/mmc.h b/include/mmc.h index fcd0fd1..dd9bf15 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -295,4 +295,7 @@ int atmel_mci_init(void *regs); int mmc_legacy_init(int verbose); #endif +#ifdef CONFIG_GENERIC_MMC +extern int mmc_cur_dev; +#endif #endif /* _MMC_H_ */ -- 1.7.0.4 _______________________________________________ U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot