]> git.ipfire.org Git - people/ms/u-boot.git/blobdiff - common/cmd_mmc.c
correct a syntax typo in at91_matrix.h
[people/ms/u-boot.git] / common / cmd_mmc.c
index 71f4971f49152b7d4dc6002c9653fa0f2913127d..c67c9cf728f5815ac2024d500e03ade756497737 100644 (file)
 #include <mmc.h>
 
 #ifndef CONFIG_GENERIC_MMC
+static int curr_device = -1;
+
 int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
-       if (mmc_legacy_init (1) != 0) {
-               printf ("No MMC card found\n");
+       int dev;
+
+       if (argc < 2) {
+               cmd_usage(cmdtp);
+               return 1;
+       }
+
+       if (strcmp(argv[1], "init") == 0) {
+               if (argc == 2) {
+                       if (curr_device < 0)
+                               dev = 1;
+                       else
+                               dev = curr_device;
+               } else if (argc == 3) {
+                       dev = (int)simple_strtoul(argv[2], NULL, 10);
+               } else {
+                       cmd_usage(cmdtp);
+                       return 1;
+               }
+
+               if (mmc_legacy_init(dev) != 0) {
+                       puts("No MMC card found\n");
+                       return 1;
+               }
+
+               curr_device = dev;
+               printf("mmc%d is available\n", curr_device);
+       } else if (strcmp(argv[1], "device") == 0) {
+               if (argc == 2) {
+                       if (curr_device < 0) {
+                               puts("No MMC device available\n");
+                               return 1;
+                       }
+               } else if (argc == 3) {
+                       dev = (int)simple_strtoul(argv[2], NULL, 10);
+
+#ifdef CONFIG_SYS_MMC_SET_DEV
+                       if (mmc_set_dev(dev) != 0)
+                               return 1;
+#endif
+                       curr_device = dev;
+               } else {
+                       cmd_usage(cmdtp);
+                       return 1;
+               }
+
+               printf("mmc%d is current device\n", curr_device);
+       } else {
+               cmd_usage(cmdtp);
                return 1;
        }
+
        return 0;
 }
 
 U_BOOT_CMD(
-       mmcinit,        1,      0,      do_mmc,
-       "init mmc card",
-       NULL
+       mmc, 3, 1, do_mmc,
+       "MMC sub-system",
+       "init [dev] - init MMC sub system\n"
+       "mmc device [dev] - show or set current device"
 );
-#endif /* !CONFIG_GENERIC_MMC */
+#else /* !CONFIG_GENERIC_MMC */
 
 static void print_mmcinfo(struct mmc *mmc)
 {
@@ -84,8 +135,10 @@ int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
        return 0;
 }
 
-U_BOOT_CMD(mmcinfo, 2, 0, do_mmcinfo, "mmcinfo <dev num>-- display MMC info\n",
-               NULL);
+U_BOOT_CMD(mmcinfo, 2, 0, do_mmcinfo,
+       "mmcinfo <dev num>-- display MMC info",
+       ""
+);
 
 int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 {
@@ -97,6 +150,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        int dev = simple_strtoul(argv[2], NULL, 10);
                        struct mmc *mmc = find_mmc_device(dev);
 
+                       if (!mmc)
+                               return 1;
+
                        mmc_init(mmc);
 
                        return 0;
@@ -123,6 +179,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        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);
 
@@ -131,7 +190,7 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
                        n = mmc->block_dev.block_read(dev, blk, cnt, addr);
 
                        /* flush cache after read */
-                       flush_cache((ulong)addr, cnt * 512); //FIXME
+                       flush_cache((ulong)addr, cnt * 512); /* FIXME */
 
                        printf("%d blocks read: %s\n",
                                n, (n==cnt) ? "OK" : "ERROR");
@@ -145,6 +204,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
                        int blk = simple_strtoul(argv[4], NULL, 16);
 
+                       if (!mmc)
+                               return 1;
+
                        printf("\nMMC write: dev # %d, block # %d, count %d ... ",
                                dev, blk, cnt);
 
@@ -166,8 +228,9 @@ int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
 
 U_BOOT_CMD(
        mmc, 6, 1, do_mmcops,
-       "mmc    - MMC sub system\n",
-       "mmc read <device num> addr blk# cnt\n"
+       "MMC sub system",
+       "read <device num> addr blk# cnt\n"
        "mmc write <device num> addr blk# cnt\n"
        "mmc rescan <device num>\n"
-       "mmc list - lists available devices\n");
+       "mmc list - lists available devices");
+#endif