[PATCH v4 1/2] hwrng: imx-rngc: Use optional clock

Jean-Michel Hautbois via B4 Relay posted 2 patches 5 days, 16 hours ago
[PATCH v4 1/2] hwrng: imx-rngc: Use optional clock
Posted by Jean-Michel Hautbois via B4 Relay 5 days, 16 hours ago
From: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>

Change devm_clk_get() to devm_clk_get_optional() to support platforms
where the RNG clock is always enabled and not exposed via the clock
framework (such as ColdFire MCF54418).

Reviewed-by: Frank Li <Frank.Li@nxp.com>
Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
---
 drivers/char/hw_random/imx-rngc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
index 241664a9b5d9..d6a847e48339 100644
--- a/drivers/char/hw_random/imx-rngc.c
+++ b/drivers/char/hw_random/imx-rngc.c
@@ -259,7 +259,7 @@ static int __init imx_rngc_probe(struct platform_device *pdev)
 	if (IS_ERR(rngc->base))
 		return PTR_ERR(rngc->base);
 
-	rngc->clk = devm_clk_get(&pdev->dev, NULL);
+	rngc->clk = devm_clk_get_optional(&pdev->dev, NULL);
 	if (IS_ERR(rngc->clk))
 		return dev_err_probe(&pdev->dev, PTR_ERR(rngc->clk), "Cannot get rng_clk\n");
 

-- 
2.39.5
Re: [PATCH v4 1/2] hwrng: imx-rngc: Use optional clock
Posted by Martin Kaiser 5 days, 3 hours ago
Thus wrote Jean-Michel Hautbois via B4 Relay (devnull+jeanmichel.hautbois.yoseli.org@kernel.org):

> From: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>

> Change devm_clk_get() to devm_clk_get_optional() to support platforms
> where the RNG clock is always enabled and not exposed via the clock
> framework (such as ColdFire MCF54418).

> Reviewed-by: Frank Li <Frank.Li@nxp.com>
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
> ---
>  drivers/char/hw_random/imx-rngc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

> diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
> index 241664a9b5d9..d6a847e48339 100644
> --- a/drivers/char/hw_random/imx-rngc.c
> +++ b/drivers/char/hw_random/imx-rngc.c
> @@ -259,7 +259,7 @@ static int __init imx_rngc_probe(struct platform_device *pdev)
>  	if (IS_ERR(rngc->base))
>  		return PTR_ERR(rngc->base);

> -	rngc->clk = devm_clk_get(&pdev->dev, NULL);
> +	rngc->clk = devm_clk_get_optional(&pdev->dev, NULL);
>  	if (IS_ERR(rngc->clk))
>  		return dev_err_probe(&pdev->dev, PTR_ERR(rngc->clk), "Cannot get rng_clk\n");

The clock is not optional on a standard imx25 system. If it's missing in the
device tree, the rngb will not work and we should not load the driver.

Should we call devm_clk_get or devm_clk_get_optional, depending on the
detected device?

Best regards,
Martin
Re: [PATCH v4 1/2] hwrng: imx-rngc: Use optional clock
Posted by Geert Uytterhoeven 4 days, 14 hours ago
Hi Martin,

On Wed, 26 Nov 2025 at 21:30, Martin Kaiser <martin@kaiser.cx> wrote:
> Thus wrote Jean-Michel Hautbois via B4 Relay (devnull+jeanmichel.hautbois.yoseli.org@kernel.org):
>
> > From: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
>
> > Change devm_clk_get() to devm_clk_get_optional() to support platforms
> > where the RNG clock is always enabled and not exposed via the clock
> > framework (such as ColdFire MCF54418).
>
> > Reviewed-by: Frank Li <Frank.Li@nxp.com>
> > Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
> > ---
> >  drivers/char/hw_random/imx-rngc.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
>
> > diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
> > index 241664a9b5d9..d6a847e48339 100644
> > --- a/drivers/char/hw_random/imx-rngc.c
> > +++ b/drivers/char/hw_random/imx-rngc.c
> > @@ -259,7 +259,7 @@ static int __init imx_rngc_probe(struct platform_device *pdev)
> >       if (IS_ERR(rngc->base))
> >               return PTR_ERR(rngc->base);
>
> > -     rngc->clk = devm_clk_get(&pdev->dev, NULL);
> > +     rngc->clk = devm_clk_get_optional(&pdev->dev, NULL);
> >       if (IS_ERR(rngc->clk))
> >               return dev_err_probe(&pdev->dev, PTR_ERR(rngc->clk), "Cannot get rng_clk\n");
>
> The clock is not optional on a standard imx25 system. If it's missing in the
> device tree, the rngb will not work and we should not load the driver.

As the clocks property is marked required in
Documentation/devicetree/bindings/rng/imx-rng.yaml, "make dtbs_check"
should flag a missing clock.

> Should we call devm_clk_get or devm_clk_get_optional, depending on the
> detected device?

That can quickly lead to complex code.  Nowadays it is fine to rely on
"make dtbs_check" for some part of the validation.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH v4 1/2] hwrng: imx-rngc: Use optional clock
Posted by Martin Kaiser 4 days, 10 hours ago
Hi Geert,

Thus wrote Geert Uytterhoeven (geert@linux-m68k.org):

> Hi Martin,

> On Wed, 26 Nov 2025 at 21:30, Martin Kaiser <martin@kaiser.cx> wrote:
> > Thus wrote Jean-Michel Hautbois via B4 Relay (devnull+jeanmichel.hautbois.yoseli.org@kernel.org):

> > > From: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>

> > > Change devm_clk_get() to devm_clk_get_optional() to support platforms
> > > where the RNG clock is always enabled and not exposed via the clock
> > > framework (such as ColdFire MCF54418).

> > > Reviewed-by: Frank Li <Frank.Li@nxp.com>
> > > Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>
> > > ---
> > >  drivers/char/hw_random/imx-rngc.c | 2 +-
> > >  1 file changed, 1 insertion(+), 1 deletion(-)

> > > diff --git a/drivers/char/hw_random/imx-rngc.c b/drivers/char/hw_random/imx-rngc.c
> > > index 241664a9b5d9..d6a847e48339 100644
> > > --- a/drivers/char/hw_random/imx-rngc.c
> > > +++ b/drivers/char/hw_random/imx-rngc.c
> > > @@ -259,7 +259,7 @@ static int __init imx_rngc_probe(struct platform_device *pdev)
> > >       if (IS_ERR(rngc->base))
> > >               return PTR_ERR(rngc->base);

> > > -     rngc->clk = devm_clk_get(&pdev->dev, NULL);
> > > +     rngc->clk = devm_clk_get_optional(&pdev->dev, NULL);
> > >       if (IS_ERR(rngc->clk))
> > >               return dev_err_probe(&pdev->dev, PTR_ERR(rngc->clk), "Cannot get rng_clk\n");

> > The clock is not optional on a standard imx25 system. If it's missing in the
> > device tree, the rngb will not work and we should not load the driver.

> As the clocks property is marked required in
> Documentation/devicetree/bindings/rng/imx-rng.yaml, "make dtbs_check"
> should flag a missing clock.

> > Should we call devm_clk_get or devm_clk_get_optional, depending on the
> > detected device?

> That can quickly lead to complex code.  Nowadays it is fine to rely on
> "make dtbs_check" for some part of the validation.

ok, understood. With this clarification, I'm happy with the patch.

Reviewed-by: Martin Kaiser <martin@kaiser.cx>

Thanks,
Martin