[PATCH 1/2] mmc: add helper to query max enhanced part size
Matthias Schiffer
matthias.schiffer at ew.tq-group.com
Wed Sep 22 14:30:36 CEST 2021
From: Markus Niebel <Markus.Niebel at ew.tq-group.com>
This helper will be used later on in an extension of the mmc
command.
Signed-off-by: Markus Niebel <Markus.Niebel at ew.tq-group.com>
Signed-off-by: Matthias Schiffer <matthias.schiffer at ew.tq-group.com>
---
drivers/mmc/mmc.c | 38 ++++++++++++++++++++++++++++++++++++++
include/mmc.h | 1 +
2 files changed, 39 insertions(+)
diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index d3babbfeb1c..c1b1ef7eb0b 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -1039,6 +1039,44 @@ int mmc_switch_part(struct mmc *mmc, unsigned int part_num)
}
#if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING)
+int mmc_max_enhanced_size_sectors(struct mmc *mmc, u64 *size)
+{
+ u64 sz;
+ int err;
+
+ ALLOC_CACHE_ALIGN_BUFFER(u8, ext_csd, MMC_MAX_BLOCK_LEN);
+
+ if (IS_SD(mmc) || mmc->version < MMC_VERSION_4_41) {
+ pr_err("eMMC >= 4.4 required for enhanced user data area\n");
+ return -EMEDIUMTYPE;
+ }
+
+ if (!(mmc->part_support & PART_SUPPORT)) {
+ pr_err("Card does not support partitioning\n");
+ return -EMEDIUMTYPE;
+ }
+
+ if (!mmc->hc_wp_grp_size) {
+ pr_err("Card does not define HC WP group size\n");
+ return -EMEDIUMTYPE;
+ }
+
+ err = mmc_send_ext_csd(mmc, ext_csd);
+ if (err)
+ return err;
+
+ sz =
+ (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 2] << 16) +
+ (ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT + 1] << 8) +
+ ext_csd[EXT_CSD_MAX_ENH_SIZE_MULT];
+ sz *= ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE];
+ sz *= ext_csd[EXT_CSD_HC_WP_GRP_SIZE];
+ sz *= SZ_1K;
+ *size = sz;
+
+ return 0;
+}
+
int mmc_hwpart_config(struct mmc *mmc,
const struct mmc_hwpart_conf *conf,
enum mmc_hwpart_conf_mode mode)
diff --git a/include/mmc.h b/include/mmc.h
index b92e2553402..3e1fc82d9b4 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -846,6 +846,7 @@ void print_mmc_devices(char separator);
*/
int get_mmc_num(void);
int mmc_switch_part(struct mmc *mmc, unsigned int part_num);
+int mmc_max_enhanced_size_sectors(struct mmc *mmc, u64 *size);
int mmc_hwpart_config(struct mmc *mmc, const struct mmc_hwpart_conf *conf,
enum mmc_hwpart_conf_mode mode);
--
2.17.1
More information about the U-Boot
mailing list