[PATCH] PM / devfreq: sun8i-a33-mbus: Make use of devm_ functions for clks

Chen-Yu Tsai wens at csie.org
Fri Jun 28 00:08:02 PDT 2024


On Fri, Jun 28, 2024 at 2:19 PM Uwe Kleine-König
<u.kleine-koenig at baylibre.com> wrote:
>
> Using devm_clk_get_enabled() and devm_clk_rate_exclusive_get() allows to
> simplify the error paths in .probe() and the remove callback.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig at baylibre.com>

Reviewed-by: Chen-Yu Tsai <wens at csie.org>

> ---
>  drivers/devfreq/sun8i-a33-mbus.c | 38 +++++++++-----------------------
>  1 file changed, 10 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/devfreq/sun8i-a33-mbus.c b/drivers/devfreq/sun8i-a33-mbus.c
> index bcf654f4ff96..4c179d7ddf0b 100644
> --- a/drivers/devfreq/sun8i-a33-mbus.c
> +++ b/drivers/devfreq/sun8i-a33-mbus.c
> @@ -360,7 +360,7 @@ static int sun8i_a33_mbus_probe(struct platform_device *pdev)
>         if (IS_ERR(priv->reg_mbus))
>                 return PTR_ERR(priv->reg_mbus);
>
> -       priv->clk_bus = devm_clk_get(dev, "bus");
> +       priv->clk_bus = devm_clk_get_enabled(dev, "bus");
>         if (IS_ERR(priv->clk_bus))
>                 return dev_err_probe(dev, PTR_ERR(priv->clk_bus),
>                                      "failed to get bus clock\n");
> @@ -375,24 +375,17 @@ static int sun8i_a33_mbus_probe(struct platform_device *pdev)
>                 return dev_err_probe(dev, PTR_ERR(priv->clk_mbus),
>                                      "failed to get mbus clock\n");
>
> -       ret = clk_prepare_enable(priv->clk_bus);
> +       /* Lock the DRAM clock rate to keep priv->nominal_bw in sync. */
> +       ret = devm_clk_rate_exclusive_get(dev, priv->clk_dram);
>         if (ret)
>                 return dev_err_probe(dev, ret,
> -                                    "failed to enable bus clock\n");
> -
> -       /* Lock the DRAM clock rate to keep priv->nominal_bw in sync. */
> -       ret = clk_rate_exclusive_get(priv->clk_dram);
> -       if (ret) {
> -               err = "failed to lock dram clock rate\n";
> -               goto err_disable_bus;
> -       }
> +                                    "failed to lock dram clock rate\n");
>
>         /* Lock the MBUS clock rate to keep MBUS_TMR_PERIOD in sync. */
> -       ret = clk_rate_exclusive_get(priv->clk_mbus);
> -       if (ret) {
> -               err = "failed to lock mbus clock rate\n";
> -               goto err_unlock_dram;
> -       }
> +       ret = devm_clk_rate_exclusive_get(dev, priv->clk_mbus);
> +       if (ret)
> +               return dev_err_probe(dev, ret,
> +                                    "failed to lock mbus clock rate\n");
>
>         priv->gov_data.upthreshold      = 10;
>         priv->gov_data.downdifferential =  5;
> @@ -405,10 +398,8 @@ static int sun8i_a33_mbus_probe(struct platform_device *pdev)
>         priv->profile.max_state         = max_state;
>
>         ret = devm_pm_opp_set_clkname(dev, "dram");
> -       if (ret) {
> -               err = "failed to add OPP table\n";
> -               goto err_unlock_mbus;
> -       }
> +       if (ret)
> +               return dev_err_probe(dev, ret, "failed to add OPP table\n");
>
>         base_freq = clk_get_rate(clk_get_parent(priv->clk_dram));
>         for (i = 0; i < max_state; ++i) {
> @@ -448,12 +439,6 @@ static int sun8i_a33_mbus_probe(struct platform_device *pdev)
>
>  err_remove_opps:
>         dev_pm_opp_remove_all_dynamic(dev);
> -err_unlock_mbus:
> -       clk_rate_exclusive_put(priv->clk_mbus);
> -err_unlock_dram:
> -       clk_rate_exclusive_put(priv->clk_dram);
> -err_disable_bus:
> -       clk_disable_unprepare(priv->clk_bus);
>
>         return dev_err_probe(dev, ret, err);
>  }
> @@ -472,9 +457,6 @@ static void sun8i_a33_mbus_remove(struct platform_device *pdev)
>                 dev_warn(dev, "failed to restore DRAM frequency: %d\n", ret);
>
>         dev_pm_opp_remove_all_dynamic(dev);
> -       clk_rate_exclusive_put(priv->clk_mbus);
> -       clk_rate_exclusive_put(priv->clk_dram);
> -       clk_disable_unprepare(priv->clk_bus);
>  }
>
>  static const struct sun8i_a33_mbus_variant sun50i_a64_mbus = {
>
> base-commit: 642a16ca7994a50d7de85715996a8ce171a5bdfb
> --
> 2.43.0
>



More information about the linux-arm-kernel mailing list