summaryrefslogtreecommitdiff
path: root/drivers/mmc/mmc.c
diff options
context:
space:
mode:
authorJean-Jacques Hiblot <jjhiblot@ti.com>2017-05-12 20:16:21 +0200
committerJason Liu <jason.hui.liu@nxp.com>2017-11-03 02:37:09 +0800
commitfa1830d0191b02fde1435946f53817f97e18e0aa (patch)
tree4af82a208226bd933437077141dbcb331561aa76 /drivers/mmc/mmc.c
parent1b227a3bebd32e9b88cb9cb12f4f7483ffb5df48 (diff)
mmc: make ext_csd part of struct mmc
The ext csd is used for comparison many times. Keep a reference content of the ext csd in the struct mmc to avoid reading multiple times Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com> Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'drivers/mmc/mmc.c')
-rw-r--r--drivers/mmc/mmc.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 1ae10d1070..4bd6a9616e 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1146,9 +1146,10 @@ static int sd_select_bus_freq_width(struct mmc *mmc)
return 0;
}
-static int mmc_select_bus_freq_width(struct mmc *mmc, const u8 *ext_csd)
+static int mmc_select_bus_freq_width(struct mmc *mmc)
{
ALLOC_CACHE_ALIGN_BUFFER(u8, test_csd, MMC_MAX_BLOCK_LEN);
+ const u8 *ext_csd = mmc->ext_csd;
/* An array of possible bus widths in order of preference */
static const unsigned ext_csd_bits[] = {
EXT_CSD_DDR_BUS_WIDTH_8,
@@ -1184,6 +1185,11 @@ static int mmc_select_bus_freq_width(struct mmc *mmc, const u8 *ext_csd)
if (mmc->version < MMC_VERSION_4)
return 0;
+ if (!mmc->ext_csd) {
+ error("No ext_csd found!\n"); /* this should enver happen */
+ return -ENOTSUPP;
+ }
+
for (idx = 0; idx < ARRAY_SIZE(ext_csd_bits); idx++) {
unsigned int extw = ext_csd_bits[idx];
unsigned int caps = ext_to_hostcaps[extw];
@@ -1250,16 +1256,23 @@ static int mmc_select_bus_freq_width(struct mmc *mmc, const u8 *ext_csd)
return err;
}
-static int mmc_startup_v4(struct mmc *mmc, u8 *ext_csd)
+static int mmc_startup_v4(struct mmc *mmc)
{
int err, i;
u64 capacity;
bool has_parts = false;
bool part_completed;
+ u8 *ext_csd;
if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4))
return 0;
+ ext_csd = malloc_cache_aligned(MMC_MAX_BLOCK_LEN);
+ if (!ext_csd)
+ return -ENOMEM;
+
+ mmc->ext_csd = ext_csd;
+
/* check ext_csd version and capacity */
err = mmc_send_ext_csd(mmc, ext_csd);
if (err)
@@ -1417,7 +1430,6 @@ static int mmc_startup(struct mmc *mmc)
uint mult, freq;
u64 cmult, csize;
struct mmc_cmd cmd;
- ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
struct blk_desc *bdesc;
#ifdef CONFIG_MMC_SPI_CRC_ON
@@ -1566,7 +1578,7 @@ static int mmc_startup(struct mmc *mmc)
mmc->erase_grp_size = 1;
mmc->part_config = MMCPART_NOAVAILABLE;
- err = mmc_startup_v4(mmc, ext_csd);
+ err = mmc_startup_v4(mmc);
if (err)
return err;
@@ -1577,7 +1589,7 @@ static int mmc_startup(struct mmc *mmc)
if (IS_SD(mmc))
err = sd_select_bus_freq_width(mmc);
else
- err = mmc_select_bus_freq_width(mmc, ext_csd);
+ err = mmc_select_bus_freq_width(mmc);
if (err)
return err;