diff options
author | Jean-Jacques Hiblot <jjhiblot@ti.com> | 2018-01-04 15:23:31 +0100 |
---|---|---|
committer | Jaehoon Chung <jh80.chung@samsung.com> | 2018-01-12 18:11:24 +0900 |
commit | 58a6fb7b04963d1bf353b66e27f3084037babd6c (patch) | |
tree | 37cf2e0272ab7da369260a602d365fcc09d1859c /drivers/mmc/mmc.c | |
parent | baef2070a407f14fbab10312b509732e6d104590 (diff) |
mmc: reworked version lookup in mmc_startup_v4
Using a table versus a switch() structure saves a bit of space
Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Diffstat (limited to 'drivers/mmc/mmc.c')
-rw-r--r-- | drivers/mmc/mmc.c | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 18d202d3b75..5255c0dccfc 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -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, |