Commit ea6ebe21 authored by Lei Wen's avatar Lei Wen Committed by Andy Fleming

cmd_mmc: eliminate device num in the mmc command

mmc command applied device, like ide and usb...
Signed-off-by: default avatarLei Wen <leiwen@marvell.com>
Acked-by: default avatarAndy Fleming <afleming@freescale.com>
parent ed018b21
......@@ -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
......@@ -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);
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment