]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
mmc: reworked version lookup in mmc_startup_v4
authorJean-Jacques Hiblot <jjhiblot@ti.com>
Thu, 4 Jan 2018 14:23:31 +0000 (15:23 +0100)
committerJaehoon Chung <jh80.chung@samsung.com>
Fri, 12 Jan 2018 09:11:24 +0000 (18:11 +0900)
Using a table versus a switch() structure saves a bit of space

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
drivers/mmc/mmc.c

index 18d202d3b758f3b2e9e594adaaea435d2122fbd8..5255c0dccfc24ace69592d4014fe7c2e8d6d33db 100644 (file)
@@ -1940,6 +1940,17 @@ static int mmc_startup_v4(struct mmc *mmc)
        u64 capacity;
        bool has_parts = false;
        bool part_completed;
+       static const u32 mmc_versions[] = {
+               MMC_VERSION_4,
+               MMC_VERSION_4_1,
+               MMC_VERSION_4_2,
+               MMC_VERSION_4_3,
+               MMC_VERSION_4_41,
+               MMC_VERSION_4_5,
+               MMC_VERSION_5_0,
+               MMC_VERSION_5_1
+       };
+
        ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
 
        if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4))
@@ -1957,7 +1968,12 @@ static int mmc_startup_v4(struct mmc *mmc)
                return -ENOMEM;
        memcpy(mmc->ext_csd, ext_csd, MMC_MAX_BLOCK_LEN);
 
-       if (ext_csd[EXT_CSD_REV] >= 2) {
+       if (ext_csd[EXT_CSD_REV] > ARRAY_SIZE(mmc_versions))
+               return -EINVAL;
+
+       mmc->version = mmc_versions[ext_csd[EXT_CSD_REV]];
+
+       if (mmc->version >= MMC_VERSION_4_2) {
                /*
                 * According to the JEDEC Standard, the value of
                 * ext_csd's capacity is valid if the value is more
@@ -1972,30 +1988,6 @@ static int mmc_startup_v4(struct mmc *mmc)
                        mmc->capacity_user = capacity;
        }
 
-       switch (ext_csd[EXT_CSD_REV]) {
-       case 1:
-               mmc->version = MMC_VERSION_4_1;
-               break;
-       case 2:
-               mmc->version = MMC_VERSION_4_2;
-               break;
-       case 3:
-               mmc->version = MMC_VERSION_4_3;
-               break;
-       case 5:
-               mmc->version = MMC_VERSION_4_41;
-               break;
-       case 6:
-               mmc->version = MMC_VERSION_4_5;
-               break;
-       case 7:
-               mmc->version = MMC_VERSION_5_0;
-               break;
-       case 8:
-               mmc->version = MMC_VERSION_5_1;
-               break;
-       }
-
        /* The partition data may be non-zero but it is only
         * effective if PARTITION_SETTING_COMPLETED is set in
         * EXT_CSD, so ignore any data if this bit is not set,