]> git.kernelconcepts.de Git - karo-tx-uboot.git/blobdiff - common/cmd_mmc.c
powerpc/8xxx: Improvement to DDR parameters
[karo-tx-uboot.git] / common / cmd_mmc.c
index 73ec7bfc16a14f97e63da54ef6c49aa4f48fcc19..e5f5e944dafff330b86b80733fc03d73e1d93ef1 100644 (file)
 #include <mmc.h>
 
 #ifndef CONFIG_GENERIC_MMC
-int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+static int curr_device = -1;
+
+int do_mmc (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
-       if (mmc_legacy_init (1) != 0) {
-               printf ("No MMC card found\n");
-               return 1;
+       int dev;
+
+       if (argc < 2)
+               return cmd_usage(cmdtp);
+
+       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 {
+                       return cmd_usage(cmdtp);
+               }
+
+               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 {
+                       return cmd_usage(cmdtp);
+               }
+
+               printf("mmc%d is current device\n", curr_device);
+       } else {
+               return cmd_usage(cmdtp);
        }
+
        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)
 {
@@ -63,7 +109,7 @@ static void print_mmcinfo(struct mmc *mmc)
        printf("Bus Width: %d-bit\n", mmc->bus_width);
 }
 
-int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
+int do_mmcinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        struct mmc *mmc;
        int dev_num;
@@ -84,10 +130,12 @@ 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[])
+int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
        int rc = 0;
 
@@ -97,6 +145,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 +174,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);
 
@@ -145,6 +199,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 +223,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