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>
This commit is contained in:
Jean-Jacques Hiblot 2017-09-21 16:29:51 +02:00 committed by Jaehoon Chung
parent c744b6f6dc
commit dfda9d88e5
2 changed files with 18 additions and 5 deletions

View file

@ -1146,9 +1146,10 @@ static int sd_select_bus_freq_width(struct mmc *mmc)
return 0; 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); 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 */ /* An array of possible bus widths in order of preference */
static const unsigned int ext_csd_bits[] = { static const unsigned int ext_csd_bits[] = {
EXT_CSD_DDR_BUS_WIDTH_8, 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) if (mmc->version < MMC_VERSION_4)
return 0; return 0;
if (!mmc->ext_csd) {
debug("No ext_csd found!\n"); /* this should enver happen */
return -ENOTSUPP;
}
for (idx = 0; idx < ARRAY_SIZE(ext_csd_bits); idx++) { for (idx = 0; idx < ARRAY_SIZE(ext_csd_bits); idx++) {
unsigned int extw = ext_csd_bits[idx]; unsigned int extw = ext_csd_bits[idx];
unsigned int caps = ext_to_hostcaps[extw]; unsigned int caps = ext_to_hostcaps[extw];
@ -1249,16 +1255,23 @@ static int mmc_select_bus_freq_width(struct mmc *mmc, const u8 *ext_csd)
return err; return err;
} }
static int mmc_startup_v4(struct mmc *mmc, u8 *ext_csd) static int mmc_startup_v4(struct mmc *mmc)
{ {
int err, i; int err, i;
u64 capacity; u64 capacity;
bool has_parts = false; bool has_parts = false;
bool part_completed; bool part_completed;
u8 *ext_csd;
if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4)) if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4))
return 0; 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 */ /* check ext_csd version and capacity */
err = mmc_send_ext_csd(mmc, ext_csd); err = mmc_send_ext_csd(mmc, ext_csd);
if (err) if (err)
@ -1418,7 +1431,6 @@ static int mmc_startup(struct mmc *mmc)
uint mult, freq; uint mult, freq;
u64 cmult, csize; u64 cmult, csize;
struct mmc_cmd cmd; struct mmc_cmd cmd;
ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
struct blk_desc *bdesc; struct blk_desc *bdesc;
#ifdef CONFIG_MMC_SPI_CRC_ON #ifdef CONFIG_MMC_SPI_CRC_ON
@ -1567,7 +1579,7 @@ static int mmc_startup(struct mmc *mmc)
mmc->erase_grp_size = 1; mmc->erase_grp_size = 1;
mmc->part_config = MMCPART_NOAVAILABLE; mmc->part_config = MMCPART_NOAVAILABLE;
err = mmc_startup_v4(mmc, ext_csd); err = mmc_startup_v4(mmc);
if (err) if (err)
return err; return err;
@ -1578,7 +1590,7 @@ static int mmc_startup(struct mmc *mmc)
if (IS_SD(mmc)) if (IS_SD(mmc))
err = sd_select_bus_freq_width(mmc); err = sd_select_bus_freq_width(mmc);
else else
err = mmc_select_bus_freq_width(mmc, ext_csd); err = mmc_select_bus_freq_width(mmc);
if (err) if (err)
return err; return err;

View file

@ -462,6 +462,7 @@ struct mmc {
struct udevice *vqmmc_supply; /* IO voltage regulator (Vccq)*/ struct udevice *vqmmc_supply; /* IO voltage regulator (Vccq)*/
#endif #endif
#endif #endif
u8 *ext_csd;
}; };
struct mmc_hwpart_conf { struct mmc_hwpart_conf {