]> git.karo-electronics.de Git - karo-tx-uboot.git/blobdiff - cmd/mmc.c
mmc: whitespace cleanup; add () around macro args
[karo-tx-uboot.git] / cmd / mmc.c
index 1c7156f19c5939867c30d52fdba0ffdcf3583c55..d8f96af9fae007f093a9c7cd44f80d2e83f38b2a 100644 (file)
--- a/cmd/mmc.c
+++ b/cmd/mmc.c
 #include <mmc.h>
 
 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;
-
-       if (argc < 2)
-               return CMD_RET_USAGE;
-
-       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_RET_USAGE;
-               }
-
-               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_RET_USAGE;
-               }
-
-               printf("mmc%d is current device\n", curr_device);
-       } else {
-               return CMD_RET_USAGE;
-       }
-
-       return 0;
-}
-
-U_BOOT_CMD(
-       mmc, 3, 1, do_mmc,
-       "MMC sub-system",
-       "init [dev] - init MMC sub system\n"
-       "mmc device [dev] - show or set current device"
-);
-#else /* !CONFIG_GENERIC_MMC */
 
 static void print_mmcinfo(struct mmc *mmc)
 {
@@ -142,28 +82,31 @@ static void print_mmcinfo(struct mmc *mmc)
                }
        }
 }
+
 static struct mmc *init_mmc_device(int dev, bool force_init)
 {
-       struct mmc *mmc;
-       mmc = find_mmc_device(dev);
+       struct mmc *mmc = find_mmc_device(dev);
+
        if (!mmc) {
                printf("no mmc device at slot %x\n", dev);
                return NULL;
        }
+
        if (force_init)
                mmc->has_init = 0;
        if (mmc_init(mmc))
                return NULL;
        return mmc;
 }
-static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+
+static int do_mmcinfo(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 {
        struct mmc *mmc;
 
        if (curr_device < 0) {
-               if (get_mmc_num() > 0)
+               if (get_mmc_num() > 0) {
                        curr_device = 0;
-               else {
+               else {
                        puts("No MMC device available\n");
                        return 1;
                }
@@ -189,8 +132,9 @@ static int confirm_key_prog(void)
        puts("Authentication key programming aborted\n");
        return 0;
 }
+
 static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag,
-                         int argc, char * const argv[])
+                         int argc, char *const argv[])
 {
        void *key_addr;
        struct mmc *mmc = find_mmc_device(curr_device);
@@ -207,8 +151,9 @@ static int do_mmcrpmb_key(cmd_tbl_t *cmdtp, int flag,
        }
        return CMD_RET_SUCCESS;
 }
+
 static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag,
-                          int argc, char * const argv[])
+                          int argc, char *const argv[])
 {
        u16 blk, cnt;
        void *addr;
@@ -235,8 +180,9 @@ static int do_mmcrpmb_read(cmd_tbl_t *cmdtp, int flag,
                return CMD_RET_FAILURE;
        return CMD_RET_SUCCESS;
 }
+
 static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag,
-                           int argc, char * const argv[])
+                           int argc, char *const argv[])
 {
        u16 blk, cnt;
        void *addr;
@@ -261,14 +207,16 @@ static int do_mmcrpmb_write(cmd_tbl_t *cmdtp, int flag,
                return CMD_RET_FAILURE;
        return CMD_RET_SUCCESS;
 }
+
 static int do_mmcrpmb_counter(cmd_tbl_t *cmdtp, int flag,
-                             int argc, char * const argv[])
+                             int argc, char *const argv[])
 {
        unsigned long counter;
        struct mmc *mmc = find_mmc_device(curr_device);
 
        if (mmc_rpmb_get_counter(mmc, &counter))
                return CMD_RET_FAILURE;
+
        printf("RPMB Write counter= %lx\n", counter);
        return CMD_RET_SUCCESS;
 }
@@ -281,15 +229,13 @@ static cmd_tbl_t cmd_rpmb[] = {
 };
 
 static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag,
-                     int argc, char * const argv[])
+                     int argc, char *const argv[])
 {
-       cmd_tbl_t *cp;
+       cmd_tbl_t *cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb));
        struct mmc *mmc;
        char original_part;
        int ret;
 
-       cp = find_cmd_tbl(argv[1], cmd_rpmb, ARRAY_SIZE(cmd_rpmb));
-
        /* Drop the rpmb subcommand */
        argc--;
        argv++;
@@ -312,20 +258,22 @@ static int do_mmcrpmb(cmd_tbl_t *cmdtp, int flag,
                return CMD_RET_FAILURE;
        }
        /* Switch to the RPMB partition */
-       original_part = mmc->block_dev.part_num;
-       if (mmc_select_hwpart(curr_device, MMC_PART_RPMB) != 0)
+       original_part = mmc->block_dev.hwpart;
+       if (blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, MMC_PART_RPMB) !=
+           0)
                return CMD_RET_FAILURE;
        ret = cp->cmd(cmdtp, flag, argc, argv);
 
        /* Return to original partition */
-       if (mmc_select_hwpart(curr_device, original_part) != 0)
+       if (blk_select_hwpart_devnum(IF_TYPE_MMC, curr_device, original_part) !=
+           0)
                return CMD_RET_FAILURE;
        return ret;
 }
 #endif
 
 static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
-                      int argc, char * const argv[])
+                      int argc, char *const argv[])
 {
        struct mmc *mmc;
        u32 blk, cnt, n;
@@ -345,15 +293,16 @@ static int do_mmc_read(cmd_tbl_t *cmdtp, int flag,
        printf("\nMMC read: dev # %d, block # %d, count %d ... ",
               curr_device, blk, cnt);
 
-       n = mmc->block_dev.block_read(&mmc->block_dev, blk, cnt, addr);
+       n = blk_dread(mmc_get_blk_desc(mmc), blk, cnt, addr);
        /* flush cache after read */
        flush_cache((ulong)addr, cnt * 512); /* FIXME */
        printf("%d blocks read: %s\n", n, (n == cnt) ? "OK" : "ERROR");
 
        return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
 }
+
 static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
-                       int argc, char * const argv[])
+                       int argc, char *const argv[])
 {
        struct mmc *mmc;
        u32 blk, cnt, n;
@@ -377,13 +326,14 @@ static int do_mmc_write(cmd_tbl_t *cmdtp, int flag,
                printf("Error: card is write protected!\n");
                return CMD_RET_FAILURE;
        }
-       n = mmc->block_dev.block_write(&mmc->block_dev, blk, cnt, addr);
+       n = blk_dwrite(mmc_get_blk_desc(mmc), blk, cnt, addr);
        printf("%d blocks written: %s\n", n, (n == cnt) ? "OK" : "ERROR");
 
        return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
 }
+
 static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,
-                       int argc, char * const argv[])
+                       int argc, char *const argv[])
 {
        struct mmc *mmc;
        u32 blk, cnt, n;
@@ -405,43 +355,46 @@ static int do_mmc_erase(cmd_tbl_t *cmdtp, int flag,
                printf("Error: card is write protected!\n");
                return CMD_RET_FAILURE;
        }
-       n = mmc->block_dev.block_erase(&mmc->block_dev, blk, cnt);
+       n = blk_derase(mmc_get_blk_desc(mmc), blk, cnt);
        printf("%d blocks erased: %s\n", n, (n == cnt) ? "OK" : "ERROR");
 
        return (n == cnt) ? CMD_RET_SUCCESS : CMD_RET_FAILURE;
 }
+
 static int do_mmc_rescan(cmd_tbl_t *cmdtp, int flag,
-                        int argc, char * const argv[])
+                        int argc, char *const argv[])
 {
-       struct mmc *mmc;
+       struct mmc *mmc = init_mmc_device(curr_device, true);
 
-       mmc = init_mmc_device(curr_device, true);
        if (!mmc)
                return CMD_RET_FAILURE;
 
        return CMD_RET_SUCCESS;
 }
+
 static int do_mmc_part(cmd_tbl_t *cmdtp, int flag,
-                      int argc, char * const argv[])
+                      int argc, char *const argv[])
 {
-       block_dev_desc_t *mmc_dev;
-       struct mmc *mmc;
+       struct blk_desc *mmc_dev;
+       struct mmc *mmc = init_mmc_device(curr_device, false);
 
-       mmc = init_mmc_device(curr_device, false);
        if (!mmc)
                return CMD_RET_FAILURE;
 
-       mmc_dev = mmc_get_dev(curr_device);
+       mmc_dev = blk_get_devnum_by_type(IF_TYPE_MMC, curr_device);
+printf("%s@%d: curr_device=%u mmc_dev=%p type=%08x\n", __func__, __LINE__,
+       curr_device, mmc_dev, mmc_dev ? mmc_dev->type : -1);
        if (mmc_dev != NULL && mmc_dev->type != DEV_TYPE_UNKNOWN) {
-               print_part(mmc_dev);
+               part_print(mmc_dev);
                return CMD_RET_SUCCESS;
        }
 
        puts("get mmc type error!\n");
        return CMD_RET_FAILURE;
 }
+
 static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag,
-                     int argc, char * const argv[])
+                     int argc, char *const argv[])
 {
        int dev, part = 0, ret;
        struct mmc *mmc;
@@ -466,7 +419,7 @@ static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag,
        if (!mmc)
                return CMD_RET_FAILURE;
 
-       ret = mmc_select_hwpart(dev, part);
+       ret = blk_select_hwpart_devnum(IF_TYPE_MMC, dev, part);
        printf("switch to partitions #%d, %s\n",
               part, (!ret) ? "OK" : "ERROR");
        if (ret)
@@ -477,19 +430,20 @@ static int do_mmc_dev(cmd_tbl_t *cmdtp, int flag,
                printf("mmc%d is current device\n", curr_device);
        else
                printf("mmc%d(part %d) is current device\n",
-                      curr_device, mmc->block_dev.hwpart);
+                      curr_device, mmc_get_blk_desc(mmc)->hwpart);
 
        return CMD_RET_SUCCESS;
 }
+
 static int do_mmc_list(cmd_tbl_t *cmdtp, int flag,
-                      int argc, char * const argv[])
+                      int argc, char *const argv[])
 {
        print_mmc_devices('\n');
        return CMD_RET_SUCCESS;
 }
 
 static int parse_hwpart_user(struct mmc_hwpart_conf *pconf,
-                            int argc, char * const argv[])
+                            int argc, char *const argv[])
 {
        int i = 0;
 
@@ -523,7 +477,7 @@ static int parse_hwpart_user(struct mmc_hwpart_conf *pconf,
 }
 
 static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx,
-                          int argc, char * const argv[])
+                          int argc, char *const argv[])
 {
        int i;
 
@@ -531,6 +485,7 @@ static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx,
 
        if (1 >= argc)
                return -1;
+
        pconf->gp_part[pidx].size = simple_strtoul(argv[0], NULL, 10);
 
        i = 1;
@@ -557,7 +512,7 @@ static int parse_hwpart_gp(struct mmc_hwpart_conf *pconf, int pidx,
 }
 
 static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag,
-                             int argc, char * const argv[])
+                             int argc, char *const argv[])
 {
        struct mmc *mmc;
        struct mmc_hwpart_conf pconf = { };
@@ -640,7 +595,7 @@ static int do_mmc_hwpartition(cmd_tbl_t *cmdtp, int flag,
 
 #ifdef CONFIG_SUPPORT_EMMC_BOOT
 static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag,
-                         int argc, char * const argv[])
+                         int argc, char *const argv[])
 {
        int dev;
        struct mmc *mmc;
@@ -648,6 +603,7 @@ static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag,
 
        if (argc != 5)
                return CMD_RET_USAGE;
+
        dev = simple_strtoul(argv[1], NULL, 10);
        width = simple_strtoul(argv[2], NULL, 10);
        reset = simple_strtoul(argv[3], NULL, 10);
@@ -665,8 +621,9 @@ static int do_mmc_bootbus(cmd_tbl_t *cmdtp, int flag,
        /* acknowledge to be sent during boot operation */
        return mmc_set_boot_bus_width(mmc, width, reset, mode);
 }
+
 static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
-                             int argc, char * const argv[])
+                             int argc, char *const argv[])
 {
        int dev;
        struct mmc *mmc;
@@ -696,8 +653,9 @@ static int do_mmc_boot_resize(cmd_tbl_t *cmdtp, int flag,
        printf("EMMC RPMB partition Size %d MB\n", rpmbsize);
        return CMD_RET_SUCCESS;
 }
+
 static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
-                          int argc, char * const argv[])
+                          int argc, char *const argv[])
 {
        int dev;
        struct mmc *mmc;
@@ -723,8 +681,9 @@ static int do_mmc_partconf(cmd_tbl_t *cmdtp, int flag,
        /* acknowledge to be sent during boot operation */
        return mmc_set_part_conf(mmc, ack, part_num, access);
 }
+
 static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
-                          int argc, char * const argv[])
+                          int argc, char *const argv[])
 {
        int dev;
        struct mmc *mmc;
@@ -758,8 +717,9 @@ static int do_mmc_rst_func(cmd_tbl_t *cmdtp, int flag,
        return mmc_set_rst_n_function(mmc, enable);
 }
 #endif
+
 static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag,
-                        int argc, char * const argv[])
+                        int argc, char *const argv[])
 {
        struct mmc *mmc;
        u32 val;
@@ -767,6 +727,7 @@ static int do_mmc_setdsr(cmd_tbl_t *cmdtp, int flag,
 
        if (argc != 2)
                return CMD_RET_USAGE;
+
        val = simple_strtoul(argv[2], NULL, 16);
 
        mmc = find_mmc_device(curr_device);
@@ -808,11 +769,9 @@ static cmd_tbl_t cmd_mmc[] = {
        U_BOOT_CMD_MKENT(setdsr, 2, 0, do_mmc_setdsr, "", ""),
 };
 
-static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+static int do_mmcops(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
 {
-       cmd_tbl_t *cp;
-
-       cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc));
+       cmd_tbl_t *cp = find_cmd_tbl(argv[1], cmd_mmc, ARRAY_SIZE(cmd_mmc));
 
        /* Drop the mmc command */
        argc--;
@@ -878,5 +837,3 @@ U_BOOT_CMD(
        "display MMC info",
        "- display info of the current MMC device"
 );
-
-#endif /* !CONFIG_GENERIC_MMC */