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>
master
Lei Wen 13 years ago committed by Andy Fleming
parent ed018b21d6
commit ea6ebe2177
  1. 198
      common/cmd_mmc.c
  2. 5
      drivers/mmc/mmc.c
  3. 1
      include/mmc.h

@ -25,9 +25,8 @@
#include <command.h> #include <command.h>
#include <mmc.h> #include <mmc.h>
#ifndef CONFIG_GENERIC_MMC
static int curr_device = -1; static int curr_device = -1;
#ifndef CONFIG_GENERIC_MMC
int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{ {
int dev; 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[]) int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
{ {
struct mmc *mmc; struct mmc *mmc;
int dev_num;
if (argc < 2) if (curr_device < 0) {
dev_num = 0; if (get_mmc_num() > 0)
else curr_device = 0;
dev_num = simple_strtoul(argv[1], NULL, 0); else {
puts("No MMC device available\n");
return 1;
}
}
mmc = find_mmc_device(dev_num); mmc = find_mmc_device(curr_device);
if (mmc) { if (mmc) {
mmc_init(mmc); mmc_init(mmc);
print_mmcinfo(mmc); print_mmcinfo(mmc);
return 0;
} else {
printf("no mmc device at slot %x\n", curr_device);
return 1;
} }
return 0;
} }
U_BOOT_CMD( U_BOOT_CMD(
mmcinfo, 2, 0, do_mmcinfo, mmcinfo, 1, 0, do_mmcinfo,
"display MMC info", "display MMC info",
"<dev num>\n"
" - device number of the device to dislay info of\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 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) { if (curr_device < 0) {
case 3: if (get_mmc_num() > 0)
if (strcmp(argv[1], "rescan") == 0) { curr_device = 0;
int dev = simple_strtoul(argv[2], NULL, 10); else {
struct mmc *mmc = find_mmc_device(dev); puts("No MMC device available\n");
return 1;
}
}
if (!mmc) if (strcmp(argv[1], "rescan") == 0) {
return 1; 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; 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("get mmc type error!\n");
puts("no mmc devices available\n"); return 1;
return 1; } else if (strcmp(argv[1], "list") == 0) {
} print_mmc_devices('\n');
mmc_init(mmc); return 0;
mmc_dev = mmc_get_dev(dev); } else if (strcmp(argv[1], "dev") == 0) {
if (mmc_dev != NULL && int dev;
mmc_dev->type != DEV_TYPE_UNKNOWN) { struct mmc *mmc;
print_part(mmc_dev);
return 0; 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; return 1;
} }
case 0: curr_device = dev;
case 1: printf("mmc%d is current device\n", curr_device);
case 4:
return cmd_usage(cmdtp);
case 2: return 0;
if (!strcmp(argv[1], "list")) { } else if (strcmp(argv[1], "read") == 0) {
print_mmc_devices('\n'); void *addr = (void *)simple_strtoul(argv[2], NULL, 16);
return 0; 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 ... ", printf("\nMMC read: dev # %d, block # %d, count %d ... ",
dev, blk, cnt); 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 after read */
flush_cache((ulong)addr, cnt * 512); /* FIXME */ flush_cache((ulong)addr, cnt * 512); /* FIXME */
printf("%d blocks read: %s\n", printf("%d blocks read: %s\n",
n, (n==cnt) ? "OK" : "ERROR"); n, (n==cnt) ? "OK" : "ERROR");
return (n == cnt) ? 0 : 1; return (n == cnt) ? 0 : 1;
} else if (strcmp(argv[1], "write") == 0) { } else if (strcmp(argv[1], "write") == 0) {
int dev = simple_strtoul(argv[2], NULL, 10); void *addr = (void *)simple_strtoul(argv[2], NULL, 16);
void *addr = (void *)simple_strtoul(argv[3], NULL, 16); u32 cnt = simple_strtoul(argv[4], NULL, 16);
u32 cnt = simple_strtoul(argv[5], NULL, 16); u32 n;
u32 n; struct mmc *mmc = find_mmc_device(curr_device);
struct mmc *mmc = find_mmc_device(dev);
int blk = simple_strtoul(argv[4], NULL, 16); int blk = simple_strtoul(argv[3], NULL, 16);
if (!mmc) if (!mmc) {
return 1; printf("no mmc device at slot %x\n", curr_device);
return 1;
}
printf("\nMMC write: dev # %d, block # %d, count %d ... ", printf("\nMMC write: dev # %d, block # %d, count %d ... ",
dev, blk, cnt); 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"); n, (n == cnt) ? "OK" : "ERROR");
return (n == cnt) ? 0 : 1; return (n == cnt) ? 0 : 1;
} else
rc = cmd_usage(cmdtp);
return rc;
} }
return cmd_usage(cmdtp);
} }
U_BOOT_CMD( U_BOOT_CMD(
mmc, 6, 1, do_mmcops, mmc, 6, 1, do_mmcops,
"MMC sub system", "MMC sub system",
"read <device num> addr blk# cnt\n" "read addr blk# cnt\n"
"mmc write <device num> addr blk# cnt\n" "mmc write addr blk# cnt\n"
"mmc rescan <device num>\n" "mmc rescan\n"
"mmc part <device num> - lists available partition on mmc\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"); "mmc list - lists available devices");
#endif #endif

@ -1110,6 +1110,11 @@ void print_mmc_devices(char separator)
printf("\n"); printf("\n");
} }
int get_mmc_num(void)
{
return cur_dev_num;
}
int mmc_initialize(bd_t *bis) int mmc_initialize(bd_t *bis)
{ {
INIT_LIST_HEAD (&mmc_devices); INIT_LIST_HEAD (&mmc_devices);

@ -295,6 +295,7 @@ void mmc_set_clock(struct mmc *mmc, uint clock);
struct mmc *find_mmc_device(int dev_num); struct mmc *find_mmc_device(int dev_num);
int mmc_set_dev(int dev_num); int mmc_set_dev(int dev_num);
void print_mmc_devices(char separator); void print_mmc_devices(char separator);
int get_mmc_num(void);
int board_mmc_getcd(u8 *cd, struct mmc *mmc); int board_mmc_getcd(u8 *cd, struct mmc *mmc);
#ifdef CONFIG_GENERIC_MMC #ifdef CONFIG_GENERIC_MMC

Loading…
Cancel
Save