Commit dfda9d88e5062620952956f7ed8e2a31ceffa6e6

Authored by Jean-Jacques Hiblot
Committed by Jaehoon Chung
1 parent c744b6f6dc

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>

Showing 2 changed files with 18 additions and 5 deletions Side-by-side Diff

... ... @@ -1146,9 +1146,10 @@
1146 1146 return 0;
1147 1147 }
1148 1148  
1149   -static int mmc_select_bus_freq_width(struct mmc *mmc, const u8 *ext_csd)
  1149 +static int mmc_select_bus_freq_width(struct mmc *mmc)
1150 1150 {
1151 1151 ALLOC_CACHE_ALIGN_BUFFER(u8, test_csd, MMC_MAX_BLOCK_LEN);
  1152 + const u8 *ext_csd = mmc->ext_csd;
1152 1153 /* An array of possible bus widths in order of preference */
1153 1154 static const unsigned int ext_csd_bits[] = {
1154 1155 EXT_CSD_DDR_BUS_WIDTH_8,
... ... @@ -1184,6 +1185,11 @@
1184 1185 if (mmc->version < MMC_VERSION_4)
1185 1186 return 0;
1186 1187  
  1188 + if (!mmc->ext_csd) {
  1189 + debug("No ext_csd found!\n"); /* this should enver happen */
  1190 + return -ENOTSUPP;
  1191 + }
  1192 +
1187 1193 for (idx = 0; idx < ARRAY_SIZE(ext_csd_bits); idx++) {
1188 1194 unsigned int extw = ext_csd_bits[idx];
1189 1195 unsigned int caps = ext_to_hostcaps[extw];
1190 1196  
1191 1197  
... ... @@ -1249,16 +1255,23 @@
1249 1255 return err;
1250 1256 }
1251 1257  
1252   -static int mmc_startup_v4(struct mmc *mmc, u8 *ext_csd)
  1258 +static int mmc_startup_v4(struct mmc *mmc)
1253 1259 {
1254 1260 int err, i;
1255 1261 u64 capacity;
1256 1262 bool has_parts = false;
1257 1263 bool part_completed;
  1264 + u8 *ext_csd;
1258 1265  
1259 1266 if (IS_SD(mmc) || (mmc->version < MMC_VERSION_4))
1260 1267 return 0;
1261 1268  
  1269 + ext_csd = malloc_cache_aligned(MMC_MAX_BLOCK_LEN);
  1270 + if (!ext_csd)
  1271 + return -ENOMEM;
  1272 +
  1273 + mmc->ext_csd = ext_csd;
  1274 +
1262 1275 /* check ext_csd version and capacity */
1263 1276 err = mmc_send_ext_csd(mmc, ext_csd);
1264 1277 if (err)
... ... @@ -1418,7 +1431,6 @@
1418 1431 uint mult, freq;
1419 1432 u64 cmult, csize;
1420 1433 struct mmc_cmd cmd;
1421   - ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
1422 1434 struct blk_desc *bdesc;
1423 1435  
1424 1436 #ifdef CONFIG_MMC_SPI_CRC_ON
... ... @@ -1567,7 +1579,7 @@
1567 1579 mmc->erase_grp_size = 1;
1568 1580 mmc->part_config = MMCPART_NOAVAILABLE;
1569 1581  
1570   - err = mmc_startup_v4(mmc, ext_csd);
  1582 + err = mmc_startup_v4(mmc);
1571 1583 if (err)
1572 1584 return err;
1573 1585  
... ... @@ -1578,7 +1590,7 @@
1578 1590 if (IS_SD(mmc))
1579 1591 err = sd_select_bus_freq_width(mmc);
1580 1592 else
1581   - err = mmc_select_bus_freq_width(mmc, ext_csd);
  1593 + err = mmc_select_bus_freq_width(mmc);
1582 1594  
1583 1595 if (err)
1584 1596 return err;
... ... @@ -462,6 +462,7 @@
462 462 struct udevice *vqmmc_supply; /* IO voltage regulator (Vccq)*/
463 463 #endif
464 464 #endif
  465 + u8 *ext_csd;
465 466 };
466 467  
467 468 struct mmc_hwpart_conf {