Re: [PATCH v6 04/15] clk: starfive: jh71x0: Add generic CRG probe helper

From: Jerome Brunet

Date: Mon Oct 12 2026 - 06:33:31 EST


> The StarFive JHB100 SoC has several clock and reset generators (CRGs)
> which share the same probe flow: map the registers, register all the
> clocks described by a table, add the clock provider and register the
> auxiliary reset device.
>
> Add jh71x0_crg_probe() together with struct jh71x0_crg_domain_info so
> that each CRG driver only needs to provide its clock table, external
> clock names and reset auxiliary device name. The reset auxiliary device
> is registered with jh71x0_reset_controller_register().
>
> The clock index space of these CRGs is sparse, so also make
> jh71x0_clk_get() reject indexes that were never registered when the
> domain info is available.
>
> Signed-off-by: Changhuang Liang <changhuang.liang@xxxxxxxxxxxxxxxx>
> ---
> drivers/clk/starfive/clk-starfive-jh71x0.c | 98 +++++++++++++++++++++-
> drivers/clk/starfive/clk-starfive-jh71x0.h | 12 +++
> 2 files changed, 107 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/clk/starfive/clk-starfive-jh71x0.c b/drivers/clk/starfive/clk-starfive-jh71x0.c
> index 2cc71f49ddee..c5ee82db3c92 100644
> --- a/drivers/clk/starfive/clk-starfive-jh71x0.c
> +++ b/drivers/clk/starfive/clk-starfive-jh71x0.c
> @@ -10,6 +10,8 @@
> #include <linux/debugfs.h>
> #include <linux/device.h>
> #include <linux/io.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/property.h>
> #include <linux/slab.h>
> #include <soc/starfive/reset-starfive-jh71x0.h>
>
> @@ -334,10 +336,14 @@ struct clk_hw *jh71x0_clk_get(struct of_phandle_args *clkspec, void *data)
> struct jh71x0_clk_priv *priv = data;
> unsigned int idx = clkspec->args[0];
>
> - if (idx < priv->num_reg)
> - return &priv->reg[idx].hw;
> + if (idx >= priv->num_reg)
> + return ERR_PTR(-EINVAL);
>
> - return ERR_PTR(-EINVAL);
> + /* Index space is sparse: reject holes that were never registered. */
> + if (priv->info && !priv->info->clk_data[idx].name)
> + return ERR_PTR(-ENOENT);
> +
> + return &priv->reg[idx].hw;
> }
> EXPORT_SYMBOL_GPL(jh71x0_clk_get);
>
> @@ -391,3 +397,89 @@ int jh71x0_reset_controller_register(struct jh71x0_clk_priv *priv,
> jh71x0_reset_unregister_adev, adev);
> }
> EXPORT_SYMBOL_GPL(jh71x0_reset_controller_register);
> +
> +int jh71x0_crg_probe(struct platform_device *pdev)
> +{
> + const struct jh71x0_crg_domain_info *info;
> + struct jh71x0_clk_priv *priv;
> + unsigned int idx;
> + int ret;
> +
> + info = device_get_match_data(&pdev->dev);
> + if (!info)
> + return -ENODEV;
> +
> + priv = devm_kzalloc(&pdev->dev, struct_size(priv, reg, info->num_clk),
> + GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + spin_lock_init(&priv->rmw_lock);
> + priv->info = info;
> + priv->num_reg = info->num_clk;
> + priv->dev = &pdev->dev;
> + priv->base = devm_platform_ioremap_resource(pdev, 0);
> + if (IS_ERR(priv->base))
> + return PTR_ERR(priv->base);
> +
> + if (info->power_domain) {

At the moment the appears to be dead-code since none of your controller is setting it.
I'd prefer if you drop it for now and introduce it when it actually gets used.

--
Jerome