Re: [PATCH v3 6/8] mmc: sdhci-cadence: refactor driver structure for V6 controller support

Adrian Hunter <[email protected]> Fri, 7 Aug 2026 15:15:34 +0300
Newsgroups org.kernel.vger.linux-mmc,org.kernel.vger.linux-devicetree,org.kernel.vger.linux-kernel
Organization Intel Finland Oy, Registered Address: c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo, Business Identity Code: 0357606 - 4, Domiciled in Helsinki
Message-ID <[email protected]>
On 24/07/2026 17:50, Tanmay Kathpalia wrote:
> Refactor the sdhci-cadence driver in preparation for adding SD6HC (V6
> controller) support. Separate PHY parameter handling into a dedicated
> sdhci_cdns4_phy structure and move PHY initialization logic into a
> dedicated sdhci_cdns4_phy_probe() function. This allows different
> controller versions to manage their PHY configurations independently
> while keeping shared logic in the main driver.
> 
> Each compatible entry now carries its own driver data, so drop the
> silent fallback to sdhci_cdns4_drv_data and return an error if platform
> data is missing.
> 
> Signed-off-by: Tanmay Kathpalia <[email protected]>

Acked-by: Adrian Hunter <[email protected]>

> ---
>  drivers/mmc/host/sdhci-cadence.c | 54 ++++++++++++++++++++++----------
>  1 file changed, 37 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/mmc/host/sdhci-cadence.c b/drivers/mmc/host/sdhci-cadence.c
> index 8a6ef6d9d1dd..1fb23051a047 100644
> --- a/drivers/mmc/host/sdhci-cadence.c
> +++ b/drivers/mmc/host/sdhci-cadence.c
> @@ -83,6 +83,11 @@ struct sdhci_cdns4_phy_param {
>  	u8 data;
>  };
>  
> +struct sdhci_cdns4_phy {
> +	unsigned int nr_phy_params;
> +	struct sdhci_cdns4_phy_param phy_params[];
> +};
> +
>  struct sdhci_cdns_priv {
>  	void __iomem *hrs_addr;
>  	void __iomem *ctl_addr;	/* write control */
> @@ -90,8 +95,7 @@ struct sdhci_cdns_priv {
>  	bool enhanced_strobe;
>  	void (*priv_writel)(struct sdhci_cdns_priv *priv, u32 val, void __iomem *reg);
>  	struct reset_control *rst_hw;
> -	unsigned int nr_phy_params;
> -	struct sdhci_cdns4_phy_param phy_params[];
> +	struct sdhci_cdns4_phy *phy;
>  };
>  
>  struct sdhci_cdns4_phy_cfg {
> @@ -167,9 +171,9 @@ static unsigned int sdhci_cdns4_phy_param_count(struct device_node *np)
>  	return count;
>  }
>  
> -static void sdhci_cdns4_phy_param_parse(struct device_node *np, struct sdhci_cdns_priv *priv)
> +static void sdhci_cdns4_phy_param_parse(struct device_node *np, struct sdhci_cdns4_phy *phy)
>  {
> -	struct sdhci_cdns4_phy_param *p = priv->phy_params;
> +	struct sdhci_cdns4_phy_param *p = phy->phy_params;
>  	u32 val;
>  	int ret, i;
>  
> @@ -186,11 +190,12 @@ static void sdhci_cdns4_phy_param_parse(struct device_node *np, struct sdhci_cdn
>  
>  static int sdhci_cdns4_phy_init(struct sdhci_cdns_priv *priv)
>  {
> +	struct sdhci_cdns4_phy *phy = priv->phy;
>  	int ret, i;
>  
> -	for (i = 0; i < priv->nr_phy_params; i++) {
> -		ret = sdhci_cdns4_write_phy_reg(priv, priv->phy_params[i].addr,
> -						priv->phy_params[i].data);
> +	for (i = 0; i < phy->nr_phy_params; i++) {
> +		ret = sdhci_cdns4_write_phy_reg(priv, phy->phy_params[i].addr,
> +						phy->phy_params[i].data);
>  		if (ret)
>  			return ret;
>  	}
> @@ -539,6 +544,24 @@ static void sdhci_cdns_mmc_hw_reset(struct mmc_host *mmc)
>  	usleep_range(300, 1000);
>  }
>  
> +static int sdhci_cdns4_phy_probe(struct platform_device *pdev, struct sdhci_cdns_priv *priv)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct sdhci_cdns4_phy *phy;
> +	unsigned int nr_phy_params;
> +
> +	nr_phy_params = sdhci_cdns4_phy_param_count(dev->of_node);
> +	phy = devm_kzalloc(dev, struct_size(phy, phy_params, nr_phy_params), GFP_KERNEL);
> +	if (!phy)
> +		return -ENOMEM;
> +
> +	phy->nr_phy_params = nr_phy_params;
> +	sdhci_cdns4_phy_param_parse(dev->of_node, phy);
> +	priv->phy = phy;
> +
> +	return sdhci_cdns4_phy_init(priv);
> +}
> +
>  static int sdhci_cdns_probe(struct platform_device *pdev)
>  {
>  	struct sdhci_host *host;
> @@ -546,7 +569,6 @@ static int sdhci_cdns_probe(struct platform_device *pdev)
>  	struct sdhci_pltfm_host *pltfm_host;
>  	struct sdhci_cdns_priv *priv;
>  	struct clk *clk;
> -	unsigned int nr_phy_params;
>  	int ret;
>  	struct device *dev = &pdev->dev;
>  	static const u16 version = SDHCI_SPEC_400 << SDHCI_SPEC_VER_SHIFT;
> @@ -557,11 +579,9 @@ static int sdhci_cdns_probe(struct platform_device *pdev)
>  
>  	data = of_device_get_match_data(dev);
>  	if (!data)
> -		data = &sdhci_cdns4_drv_data;
> +		return dev_err_probe(dev, -EINVAL, "missing platform driver data\n");
>  
> -	nr_phy_params = sdhci_cdns4_phy_param_count(dev->of_node);
> -	host = sdhci_pltfm_init(pdev, &data->pltfm_data,
> -				struct_size(priv, phy_params, nr_phy_params));
> +	host = sdhci_pltfm_init(pdev, &data->pltfm_data, sizeof(*priv));
>  	if (IS_ERR(host))
>  		return PTR_ERR(host);
>  
> @@ -569,7 +589,6 @@ static int sdhci_cdns_probe(struct platform_device *pdev)
>  	pltfm_host->clk = clk;
>  
>  	priv = sdhci_pltfm_priv(pltfm_host);
> -	priv->nr_phy_params = nr_phy_params;
>  	priv->hrs_addr = host->ioaddr;
>  	priv->enhanced_strobe = false;
>  	priv->priv_writel = cdns_writel;
> @@ -590,9 +609,7 @@ static int sdhci_cdns_probe(struct platform_device *pdev)
>  	if (ret)
>  		return ret;
>  
> -	sdhci_cdns4_phy_param_parse(dev->of_node, priv);
> -
> -	ret = sdhci_cdns4_phy_init(priv);
> +	ret = sdhci_cdns4_phy_probe(pdev, priv);
>  	if (ret)
>  		return ret;
>  
> @@ -650,7 +667,10 @@ static const struct of_device_id sdhci_cdns_match[] = {
>  		.compatible = "mobileye,eyeq-sd4hc",
>  		.data = &sdhci_eyeq_drv_data,
>  	},
> -	{ .compatible = "cdns,sd4hc" },
> +	{
> +		.compatible = "cdns,sd4hc",
> +		.data = &sdhci_cdns4_drv_data,
> +	},
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, sdhci_cdns_match);