[PATCH v6 06/12] clk: Ensure the parent clocks are enabled while reparenting

Adam Ford aford173 at gmail.com
Thu Apr 3 15:03:58 CEST 2025


On Thu, Apr 3, 2025 at 2:39 AM Miquel Raynal <miquel.raynal at bootlin.com> wrote:
>
> Reparenting a clock C with a new parent P means that C will only
> continue clocking if P is already clocking when the mux is updated. In
> case the parent is currently disabled, failures (stalls) are likely to
> happen.

Marek made some changes to the clock registration to address some
parent-child relationships.  Do you know if this patch is still
needed?

adam
>
> This is exactly what happens on i.MX8 when enabling the video
> pipeline. We tell LCDIF clocks to use the VIDEO PLL as input, while the
> VIDEO PLL is currently off. This all happens as part of the
> assigned-clocks handling procedure, where the reparenting happens before
> the enable() calls. Enabling the parents as part of the reparenting
> procedure seems sane and also matches the logic applied in other parts
> of the CCM.
>
> Signed-off-by: Miquel Raynal <miquel.raynal at bootlin.com>
> ---
>  drivers/clk/clk-uclass.c | 21 +++++++++++++++++----
>  1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/clk/clk-uclass.c b/drivers/clk/clk-uclass.c
> index 90b70529a478d11d907cbd6b64d680d0c1db4d5c..4b3d812f9c6539a6b769990e3e11f14f49abb2a9 100644
> --- a/drivers/clk/clk-uclass.c
> +++ b/drivers/clk/clk-uclass.c
> @@ -623,14 +623,27 @@ int clk_set_parent(struct clk *clk, struct clk *parent)
>         if (!ops->set_parent)
>                 return -ENOSYS;
>
> -       ret = ops->set_parent(clk, parent);
> -       if (ret)
> +       ret = clk_enable(parent);
> +       if (ret) {
> +               printf("Cannot enable parent %s\n", parent->dev->name);
>                 return ret;
> +       }
>
> -       if (CONFIG_IS_ENABLED(CLK_CCF))
> +       ret = ops->set_parent(clk, parent);
> +       if (ret) {
> +               clk_disable(parent);
> +               return ret;
> +       }
> +
> +       if (CONFIG_IS_ENABLED(CLK_CCF)) {
>                 ret = device_reparent(clk->dev, parent->dev);
> +               if (ret) {
> +                       clk_disable(parent);
> +                       return ret;
> +               }
> +       }
>
> -       return ret;
> +       return 0;
>  }
>
>  int clk_enable(struct clk *clk)
>
> --
> 2.48.1
>


More information about the U-Boot mailing list