[PATCH 3/6] mmc: mmci: stm32: introduce a private structure for the SDMMC variants

Christophe Kerello christophe.kerello at foss.st.com
Tue Dec 1 08:18:42 PST 2026


The delay block data is currently stored directly in host->variant_priv,
which leaves no room for variant specific data unrelated to the delay
block.

Introduce a private structure embedding the delay block data, and access
the latter through a helper, so that further variant specific data can be
added without touching the delay block users. No functional change.

Signed-off-by: Christophe Kerello <christophe.kerello at foss.st.com>
---
 drivers/mmc/host/mmci_stm32_sdmmc.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/drivers/mmc/host/mmci_stm32_sdmmc.c b/drivers/mmc/host/mmci_stm32_sdmmc.c
index a50dc58336de..2e5135fcd326 100644
--- a/drivers/mmc/host/mmci_stm32_sdmmc.c
+++ b/drivers/mmc/host/mmci_stm32_sdmmc.c
@@ -79,6 +79,17 @@ struct sdmmc_dlyb {
 	struct sdmmc_tuning_ops *ops;
 };
 
+struct sdmmc_priv {
+	struct sdmmc_dlyb dlyb;
+};
+
+static struct sdmmc_dlyb *sdmmc_get_dlyb(struct mmci_host *host)
+{
+	struct sdmmc_priv *priv = host->variant_priv;
+
+	return priv ? &priv->dlyb : NULL;
+}
+
 static int sdmmc_idma_validate_data(struct mmci_host *host,
 				    struct mmc_data *data)
 {
@@ -361,7 +372,7 @@ static void sdmmc_dlyb_mp15_input_ck(struct sdmmc_dlyb *dlyb)
 static void mmci_sdmmc_set_pwrreg(struct mmci_host *host, unsigned int pwr)
 {
 	struct mmc_ios ios = host->mmc->ios;
-	struct sdmmc_dlyb *dlyb = host->variant_priv;
+	struct sdmmc_dlyb *dlyb = sdmmc_get_dlyb(host);
 
 	/* adds OF options */
 	pwr = host->pwr_reg_add;
@@ -504,7 +515,7 @@ static int sdmmc_dlyb_mp15_set_cfg(struct sdmmc_dlyb *dlyb,
 
 static int sdmmc_dlyb_mp15_prepare(struct mmci_host *host)
 {
-	struct sdmmc_dlyb *dlyb = host->variant_priv;
+	struct sdmmc_dlyb *dlyb = sdmmc_get_dlyb(host);
 	u32 cfgr;
 	int i, lng, ret;
 
@@ -578,7 +589,7 @@ static int sdmmc_dlyb_mp25_set_cfg(struct sdmmc_dlyb *dlyb,
 
 static int sdmmc_dlyb_mp25_prepare(struct mmci_host *host)
 {
-	struct sdmmc_dlyb *dlyb = host->variant_priv;
+	struct sdmmc_dlyb *dlyb = sdmmc_get_dlyb(host);
 
 	dlyb->max = DLYBSD_TAPSEL_NB;
 
@@ -587,7 +598,7 @@ static int sdmmc_dlyb_mp25_prepare(struct mmci_host *host)
 
 static int sdmmc_dlyb_phase_tuning(struct mmci_host *host, u32 opcode)
 {
-	struct sdmmc_dlyb *dlyb = host->variant_priv;
+	struct sdmmc_dlyb *dlyb = sdmmc_get_dlyb(host);
 	int cur_len = 0, max_len = 0, end_of_len = 0;
 	int phase, ret;
 
@@ -633,7 +644,7 @@ static int sdmmc_dlyb_phase_tuning(struct mmci_host *host, u32 opcode)
 static int sdmmc_execute_tuning(struct mmc_host *mmc, u32 opcode)
 {
 	struct mmci_host *host = mmc_priv(mmc);
-	struct sdmmc_dlyb *dlyb = host->variant_priv;
+	struct sdmmc_dlyb *dlyb = sdmmc_get_dlyb(host);
 	u32 clk;
 	int ret;
 
@@ -737,21 +748,23 @@ static struct sdmmc_tuning_ops dlyb_tuning_mp25_ops = {
 void sdmmc_variant_init(struct mmci_host *host)
 {
 	struct device_node *np = host->mmc->parent->of_node;
-	void __iomem *base_dlyb;
+	struct sdmmc_priv *priv;
 	struct sdmmc_dlyb *dlyb;
+	void __iomem *base;
 
 	host->ops = &sdmmc_variant_ops;
 	host->pwr_reg = readl_relaxed(host->base + MMCIPOWER);
 
-	base_dlyb = devm_of_iomap(mmc_dev(host->mmc), np, 1, NULL);
-	if (IS_ERR(base_dlyb))
+	base = devm_of_iomap(mmc_dev(host->mmc), np, 1, NULL);
+	if (IS_ERR(base))
 		return;
 
-	dlyb = devm_kzalloc(mmc_dev(host->mmc), sizeof(*dlyb), GFP_KERNEL);
-	if (!dlyb)
+	priv = devm_kzalloc(mmc_dev(host->mmc), sizeof(*priv), GFP_KERNEL);
+	if (!priv)
 		return;
 
-	dlyb->base = base_dlyb;
+	dlyb = &priv->dlyb;
+	dlyb->base = base;
 	if (of_device_is_compatible(np, "st,stm32mp25-sdmmc2")) {
 		dlyb->ops = &dlyb_tuning_mp25_ops;
 		dlyb->min_freq = 100000000;
@@ -760,6 +773,6 @@ void sdmmc_variant_init(struct mmci_host *host)
 		dlyb->min_freq = 50000000;
 	}
 
-	host->variant_priv = dlyb;
+	host->variant_priv = priv;
 	host->mmc_ops->execute_tuning = sdmmc_execute_tuning;
 }

-- 
2.43.0




More information about the linux-arm-kernel mailing list