From patchwork Tue May 3 02:26:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lei Wen X-Patchwork-Id: 93739 X-Patchwork-Delegate: afleming@freescale.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 66304B6FC2 for ; Tue, 3 May 2011 12:27:13 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AD1AB281A8; Tue, 3 May 2011 04:26:50 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id uhCKJKYAO8Uo; Tue, 3 May 2011 04:26:50 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EECBF281A9; Tue, 3 May 2011 04:26:36 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id E8A8A2818C for ; Tue, 3 May 2011 04:26:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id N67BzdRmyS+1 for ; Tue, 3 May 2011 04:26:32 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from dakia2.marvell.com (dakia2.marvell.com [65.219.4.35]) by theia.denx.de (Postfix) with ESMTPS id 02B6328193 for ; Tue, 3 May 2011 04:26:30 +0200 (CEST) X-ASG-Debug-ID: 1304389588-082dc01e0001-4l7tJC Received: from maili.marvell.com (maili.marvell.com [10.68.76.51]) by dakia2.marvell.com with ESMTP id 5PnOYmXo8MIEWnKL; Mon, 02 May 2011 19:26:28 -0700 (PDT) X-Barracuda-Envelope-From: leiwen@marvell.com Received: from localhost (unknown [10.38.34.104]) by maili.marvell.com (Postfix) with ESMTP id C04D98A008; Mon, 2 May 2011 19:26:27 -0700 (PDT) From: Lei Wen To: Wolfgang Denk , Andy Fleming , u-boot@lists.denx.de, adrian.wenl@gmail.com X-ASG-Orig-Subj: [PATCH V3 1/2] cmd_mmc: eliminate device num in the mmc command Date: Mon, 2 May 2011 19:26:25 -0700 X-ASG-Orig-Subj: [PATCH V3 1/2] cmd_mmc: eliminate device num in the mmc command Message-Id: <1304389586-19007-2-git-send-email-leiwen@marvell.com> X-Mailer: git-send-email 1.7.0.4 In-Reply-To: <1302920252-6274-1-git-send-email-leiwen@marvell.com> References: <1302920252-6274-1-git-send-email-leiwen@marvell.com> X-Barracuda-Connect: maili.marvell.com[10.68.76.51] X-Barracuda-Start-Time: 1304389588 X-Barracuda-URL: http://10.68.76.222:80/cgi-mod/mark.cgi X-Barracuda-Spam-Score: -1002.00 X-Barracuda-Spam-Status: No, SCORE=-1002.00 using global scores of TAG_LEVEL=1000.0 QUARANTINE_LEVEL=1000.0 KILL_LEVEL=1000.0 Subject: [U-Boot] [PATCH V3 1/2] cmd_mmc: eliminate device num in the mmc command X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.9 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 --- Changelog: V2: use the "mmc_cur_dev" to replace explicitly specify the dev num in mmc command. V3: reuse "curr_device" in hte cmd_mmc.c Modify notification message common/cmd_mmc.c | 198 +++++++++++++++++++++++++++++----------------------- drivers/mmc/mmc.c | 5 ++ include/mmc.h | 1 + 3 files changed, 116 insertions(+), 88 deletions(-) diff --git a/common/cmd_mmc.c b/common/cmd_mmc.c index 6166749..e266d4f 100644 --- a/common/cmd_mmc.c +++ b/common/cmd_mmc.c @@ -25,9 +25,8 @@ #include #include -#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", - "\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 addr blk# cnt\n" - "mmc write addr blk# cnt\n" - "mmc rescan \n" - "mmc part - 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 f6d31f5..cdf2713 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 f7f2286..b1ad086 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -294,6 +294,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