linux-samsung-soc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 1/2] PM / devfreq: exynos: Use Use devm_clk_get_enabled() helpers
@ 2024-04-17  4:44 Anand Moon
  2024-04-17  4:44 ` [PATCH v3 2/2] PM / devfreq: exynos: Use DEFINE_SIMPLE_DEV_PM_OPS for PM functions Anand Moon
  2024-05-08 15:45 ` [PATCH v3 1/2] PM / devfreq: exynos: Use Use devm_clk_get_enabled() helpers Chanwoo Choi
  0 siblings, 2 replies; 5+ messages in thread
From: Anand Moon @ 2024-04-17  4:44 UTC (permalink / raw)
  To: Chanwoo Choi, MyungJoo Ham, Kyungmin Park, Krzysztof Kozlowski,
	Alim Akhtar
  Cc: Anand Moon, linux-pm, linux-samsung-soc, linux-arm-kernel, linux-kernel

The devm_clk_get_enabled() helpers:
    - call devm_clk_get()
    - call clk_prepare_enable() and register what is needed in order to
     call clk_disable_unprepare() when needed, as a managed resource.

This simplifies the code and avoids the calls to clk_disable_unprepare().

While at it, use dev_err_probe consistently, and use its return value
to return the error code.

Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
v3 - No change
v2 - No change
---
 drivers/devfreq/exynos-bus.c | 21 ++++-----------------
 1 file changed, 4 insertions(+), 17 deletions(-)

diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c
index 245898f1a88e..153340b6685f 100644
--- a/drivers/devfreq/exynos-bus.c
+++ b/drivers/devfreq/exynos-bus.c
@@ -160,7 +160,6 @@ static void exynos_bus_exit(struct device *dev)
 	platform_device_unregister(bus->icc_pdev);
 
 	dev_pm_opp_of_remove_table(dev);
-	clk_disable_unprepare(bus->clk);
 	dev_pm_opp_put_regulators(bus->opp_token);
 }
 
@@ -171,7 +170,6 @@ static void exynos_bus_passive_exit(struct device *dev)
 	platform_device_unregister(bus->icc_pdev);
 
 	dev_pm_opp_of_remove_table(dev);
-	clk_disable_unprepare(bus->clk);
 }
 
 static int exynos_bus_parent_parse_of(struct device_node *np,
@@ -247,23 +245,15 @@ static int exynos_bus_parse_of(struct device_node *np,
 	int ret;
 
 	/* Get the clock to provide each bus with source clock */
-	bus->clk = devm_clk_get(dev, "bus");
-	if (IS_ERR(bus->clk)) {
-		dev_err(dev, "failed to get bus clock\n");
-		return PTR_ERR(bus->clk);
-	}
-
-	ret = clk_prepare_enable(bus->clk);
-	if (ret < 0) {
-		dev_err(dev, "failed to get enable clock\n");
-		return ret;
-	}
+	bus->clk = devm_clk_get_enabled(dev, "bus");
+	if (IS_ERR(bus->clk))
+		return dev_err_probe(dev, PTR_ERR(bus->clk), "failed to get bus clock\n");
 
 	/* Get the freq and voltage from OPP table to scale the bus freq */
 	ret = dev_pm_opp_of_add_table(dev);
 	if (ret < 0) {
 		dev_err(dev, "failed to get OPP table\n");
-		goto err_clk;
+		return ret;
 	}
 
 	rate = clk_get_rate(bus->clk);
@@ -281,8 +271,6 @@ static int exynos_bus_parse_of(struct device_node *np,
 
 err_opp:
 	dev_pm_opp_of_remove_table(dev);
-err_clk:
-	clk_disable_unprepare(bus->clk);
 
 	return ret;
 }
@@ -453,7 +441,6 @@ static int exynos_bus_probe(struct platform_device *pdev)
 
 err:
 	dev_pm_opp_of_remove_table(dev);
-	clk_disable_unprepare(bus->clk);
 err_reg:
 	dev_pm_opp_put_regulators(bus->opp_token);
 
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v3 2/2] PM / devfreq: exynos: Use DEFINE_SIMPLE_DEV_PM_OPS for PM functions
  2024-04-17  4:44 [PATCH v3 1/2] PM / devfreq: exynos: Use Use devm_clk_get_enabled() helpers Anand Moon
@ 2024-04-17  4:44 ` Anand Moon
  2024-05-08 15:42   ` Chanwoo Choi
  2024-05-08 15:45 ` [PATCH v3 1/2] PM / devfreq: exynos: Use Use devm_clk_get_enabled() helpers Chanwoo Choi
  1 sibling, 1 reply; 5+ messages in thread
From: Anand Moon @ 2024-04-17  4:44 UTC (permalink / raw)
  To: Chanwoo Choi, MyungJoo Ham, Kyungmin Park, Krzysztof Kozlowski,
	Alim Akhtar
  Cc: Anand Moon, linux-pm, linux-samsung-soc, linux-arm-kernel, linux-kernel

This macro has the advantage over SET_SYSTEM_SLEEP_PM_OPS that we don't
have to care about when the functions are actually used.

Also make use of pm_sleep_ptr() to discard all PM_SLEEP related
stuff if CONFIG_PM_SLEEP isn't enabled.

Signed-off-by: Anand Moon <linux.amoon@gmail.com>
---
v3: fix using new DEFINE_SIMPLE_DEV_PM_OPS PM macro hence
    change the $subject and the commit message

v2: add __maybe_unused to suspend/resume functions in case CONFIG_PM
   is disabled
---
 drivers/devfreq/exynos-bus.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c
index 153340b6685f..b89e04eb8430 100644
--- a/drivers/devfreq/exynos-bus.c
+++ b/drivers/devfreq/exynos-bus.c
@@ -454,7 +454,6 @@ static void exynos_bus_shutdown(struct platform_device *pdev)
 	devfreq_suspend_device(bus->devfreq);
 }
 
-#ifdef CONFIG_PM_SLEEP
 static int exynos_bus_resume(struct device *dev)
 {
 	struct exynos_bus *bus = dev_get_drvdata(dev);
@@ -482,11 +481,9 @@ static int exynos_bus_suspend(struct device *dev)
 
 	return 0;
 }
-#endif
 
-static const struct dev_pm_ops exynos_bus_pm = {
-	SET_SYSTEM_SLEEP_PM_OPS(exynos_bus_suspend, exynos_bus_resume)
-};
+static DEFINE_SIMPLE_DEV_PM_OPS(exynos_bus_pm,
+				exynos_bus_suspend, exynos_bus_resume);
 
 static const struct of_device_id exynos_bus_of_match[] = {
 	{ .compatible = "samsung,exynos-bus", },
@@ -499,7 +496,7 @@ static struct platform_driver exynos_bus_platdrv = {
 	.shutdown	= exynos_bus_shutdown,
 	.driver = {
 		.name	= "exynos-bus",
-		.pm	= &exynos_bus_pm,
+		.pm	= pm_sleep_ptr(&exynos_bus_pm),
 		.of_match_table = exynos_bus_of_match,
 	},
 };
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 2/2] PM / devfreq: exynos: Use DEFINE_SIMPLE_DEV_PM_OPS for PM functions
  2024-04-17  4:44 ` [PATCH v3 2/2] PM / devfreq: exynos: Use DEFINE_SIMPLE_DEV_PM_OPS for PM functions Anand Moon
@ 2024-05-08 15:42   ` Chanwoo Choi
  0 siblings, 0 replies; 5+ messages in thread
From: Chanwoo Choi @ 2024-05-08 15:42 UTC (permalink / raw)
  To: Anand Moon
  Cc: Chanwoo Choi, MyungJoo Ham, Kyungmin Park, Krzysztof Kozlowski,
	Alim Akhtar, linux-pm, linux-samsung-soc, linux-arm-kernel,
	linux-kernel

On Wed, Apr 17, 2024 at 1:45 PM Anand Moon <linux.amoon@gmail.com> wrote:
>
> This macro has the advantage over SET_SYSTEM_SLEEP_PM_OPS that we don't
> have to care about when the functions are actually used.
>
> Also make use of pm_sleep_ptr() to discard all PM_SLEEP related
> stuff if CONFIG_PM_SLEEP isn't enabled.
>
> Signed-off-by: Anand Moon <linux.amoon@gmail.com>
> ---
> v3: fix using new DEFINE_SIMPLE_DEV_PM_OPS PM macro hence
>     change the $subject and the commit message
>
> v2: add __maybe_unused to suspend/resume functions in case CONFIG_PM
>    is disabled
> ---
>  drivers/devfreq/exynos-bus.c | 9 +++------
>  1 file changed, 3 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c
> index 153340b6685f..b89e04eb8430 100644
> --- a/drivers/devfreq/exynos-bus.c
> +++ b/drivers/devfreq/exynos-bus.c
> @@ -454,7 +454,6 @@ static void exynos_bus_shutdown(struct platform_device *pdev)
>         devfreq_suspend_device(bus->devfreq);
>  }
>
> -#ifdef CONFIG_PM_SLEEP
>  static int exynos_bus_resume(struct device *dev)
>  {
>         struct exynos_bus *bus = dev_get_drvdata(dev);
> @@ -482,11 +481,9 @@ static int exynos_bus_suspend(struct device *dev)
>
>         return 0;
>  }
> -#endif
>
> -static const struct dev_pm_ops exynos_bus_pm = {
> -       SET_SYSTEM_SLEEP_PM_OPS(exynos_bus_suspend, exynos_bus_resume)
> -};
> +static DEFINE_SIMPLE_DEV_PM_OPS(exynos_bus_pm,
> +                               exynos_bus_suspend, exynos_bus_resume);
>
>  static const struct of_device_id exynos_bus_of_match[] = {
>         { .compatible = "samsung,exynos-bus", },
> @@ -499,7 +496,7 @@ static struct platform_driver exynos_bus_platdrv = {
>         .shutdown       = exynos_bus_shutdown,
>         .driver = {
>                 .name   = "exynos-bus",
> -               .pm     = &exynos_bus_pm,
> +               .pm     = pm_sleep_ptr(&exynos_bus_pm),
>                 .of_match_table = exynos_bus_of_match,
>         },
>  };
> --
> 2.44.0
>
>

Applied it. Thanks.

-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 1/2] PM / devfreq: exynos: Use Use devm_clk_get_enabled() helpers
  2024-04-17  4:44 [PATCH v3 1/2] PM / devfreq: exynos: Use Use devm_clk_get_enabled() helpers Anand Moon
  2024-04-17  4:44 ` [PATCH v3 2/2] PM / devfreq: exynos: Use DEFINE_SIMPLE_DEV_PM_OPS for PM functions Anand Moon
@ 2024-05-08 15:45 ` Chanwoo Choi
  2024-05-08 17:23   ` Anand Moon
  1 sibling, 1 reply; 5+ messages in thread
From: Chanwoo Choi @ 2024-05-08 15:45 UTC (permalink / raw)
  To: Anand Moon
  Cc: Chanwoo Choi, MyungJoo Ham, Kyungmin Park, Krzysztof Kozlowski,
	Alim Akhtar, linux-pm, linux-samsung-soc, linux-arm-kernel,
	linux-kernel

On Wed, Apr 17, 2024 at 1:45 PM Anand Moon <linux.amoon@gmail.com> wrote:
>
> The devm_clk_get_enabled() helpers:
>     - call devm_clk_get()
>     - call clk_prepare_enable() and register what is needed in order to
>      call clk_disable_unprepare() when needed, as a managed resource.
>
> This simplifies the code and avoids the calls to clk_disable_unprepare().
>
> While at it, use dev_err_probe consistently, and use its return value
> to return the error code.
>
> Signed-off-by: Anand Moon <linux.amoon@gmail.com>
> ---
> v3 - No change
> v2 - No change
> ---
>  drivers/devfreq/exynos-bus.c | 21 ++++-----------------
>  1 file changed, 4 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c
> index 245898f1a88e..153340b6685f 100644
> --- a/drivers/devfreq/exynos-bus.c
> +++ b/drivers/devfreq/exynos-bus.c
> @@ -160,7 +160,6 @@ static void exynos_bus_exit(struct device *dev)
>         platform_device_unregister(bus->icc_pdev);
>
>         dev_pm_opp_of_remove_table(dev);
> -       clk_disable_unprepare(bus->clk);
>         dev_pm_opp_put_regulators(bus->opp_token);
>  }
>
> @@ -171,7 +170,6 @@ static void exynos_bus_passive_exit(struct device *dev)
>         platform_device_unregister(bus->icc_pdev);
>
>         dev_pm_opp_of_remove_table(dev);
> -       clk_disable_unprepare(bus->clk);
>  }
>
>  static int exynos_bus_parent_parse_of(struct device_node *np,
> @@ -247,23 +245,15 @@ static int exynos_bus_parse_of(struct device_node *np,
>         int ret;
>
>         /* Get the clock to provide each bus with source clock */
> -       bus->clk = devm_clk_get(dev, "bus");
> -       if (IS_ERR(bus->clk)) {
> -               dev_err(dev, "failed to get bus clock\n");
> -               return PTR_ERR(bus->clk);
> -       }
> -
> -       ret = clk_prepare_enable(bus->clk);
> -       if (ret < 0) {
> -               dev_err(dev, "failed to get enable clock\n");
> -               return ret;
> -       }
> +       bus->clk = devm_clk_get_enabled(dev, "bus");
> +       if (IS_ERR(bus->clk))
> +               return dev_err_probe(dev, PTR_ERR(bus->clk), "failed to get bus clock\n");

nitpick. I recommend that better to keep 80 char on one line as following
for the readability.

               return dev_err_probe(dev, PTR_ERR(bus->clk),
                                          "failed to get bus clock\n");


>
>         /* Get the freq and voltage from OPP table to scale the bus freq */
>         ret = dev_pm_opp_of_add_table(dev);
>         if (ret < 0) {
>                 dev_err(dev, "failed to get OPP table\n");
> -               goto err_clk;
> +               return ret;
>         }
>
>         rate = clk_get_rate(bus->clk);
> @@ -281,8 +271,6 @@ static int exynos_bus_parse_of(struct device_node *np,
>
>  err_opp:
>         dev_pm_opp_of_remove_table(dev);
> -err_clk:
> -       clk_disable_unprepare(bus->clk);
>
>         return ret;
>  }
> @@ -453,7 +441,6 @@ static int exynos_bus_probe(struct platform_device *pdev)
>
>  err:
>         dev_pm_opp_of_remove_table(dev);
> -       clk_disable_unprepare(bus->clk);
>  err_reg:
>         dev_pm_opp_put_regulators(bus->opp_token);
>
> --
> 2.44.0
>
>


-- 
Best Regards,
Chanwoo Choi
Samsung Electronics

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3 1/2] PM / devfreq: exynos: Use Use devm_clk_get_enabled() helpers
  2024-05-08 15:45 ` [PATCH v3 1/2] PM / devfreq: exynos: Use Use devm_clk_get_enabled() helpers Chanwoo Choi
@ 2024-05-08 17:23   ` Anand Moon
  0 siblings, 0 replies; 5+ messages in thread
From: Anand Moon @ 2024-05-08 17:23 UTC (permalink / raw)
  To: Chanwoo Choi
  Cc: Chanwoo Choi, MyungJoo Ham, Kyungmin Park, Krzysztof Kozlowski,
	Alim Akhtar, linux-pm, linux-samsung-soc, linux-arm-kernel,
	linux-kernel

Hi Chanwoo

On Wed, 8 May 2024 at 21:16, Chanwoo Choi <chanwoo@kernel.org> wrote:
>
> On Wed, Apr 17, 2024 at 1:45 PM Anand Moon <linux.amoon@gmail.com> wrote:
> >
> > The devm_clk_get_enabled() helpers:
> >     - call devm_clk_get()
> >     - call clk_prepare_enable() and register what is needed in order to
> >      call clk_disable_unprepare() when needed, as a managed resource.
> >
> > This simplifies the code and avoids the calls to clk_disable_unprepare().
> >
> > While at it, use dev_err_probe consistently, and use its return value
> > to return the error code.
> >
> > Signed-off-by: Anand Moon <linux.amoon@gmail.com>
> > ---
> > v3 - No change
> > v2 - No change
> > ---
> >  drivers/devfreq/exynos-bus.c | 21 ++++-----------------
> >  1 file changed, 4 insertions(+), 17 deletions(-)
> >
> > diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c
> > index 245898f1a88e..153340b6685f 100644
> > --- a/drivers/devfreq/exynos-bus.c
> > +++ b/drivers/devfreq/exynos-bus.c
> > @@ -160,7 +160,6 @@ static void exynos_bus_exit(struct device *dev)
> >         platform_device_unregister(bus->icc_pdev);
> >
> >         dev_pm_opp_of_remove_table(dev);
> > -       clk_disable_unprepare(bus->clk);
> >         dev_pm_opp_put_regulators(bus->opp_token);
> >  }
> >
> > @@ -171,7 +170,6 @@ static void exynos_bus_passive_exit(struct device *dev)
> >         platform_device_unregister(bus->icc_pdev);
> >
> >         dev_pm_opp_of_remove_table(dev);
> > -       clk_disable_unprepare(bus->clk);
> >  }
> >
> >  static int exynos_bus_parent_parse_of(struct device_node *np,
> > @@ -247,23 +245,15 @@ static int exynos_bus_parse_of(struct device_node *np,
> >         int ret;
> >
> >         /* Get the clock to provide each bus with source clock */
> > -       bus->clk = devm_clk_get(dev, "bus");
> > -       if (IS_ERR(bus->clk)) {
> > -               dev_err(dev, "failed to get bus clock\n");
> > -               return PTR_ERR(bus->clk);
> > -       }
> > -
> > -       ret = clk_prepare_enable(bus->clk);
> > -       if (ret < 0) {
> > -               dev_err(dev, "failed to get enable clock\n");
> > -               return ret;
> > -       }
> > +       bus->clk = devm_clk_get_enabled(dev, "bus");
> > +       if (IS_ERR(bus->clk))
> > +               return dev_err_probe(dev, PTR_ERR(bus->clk), "failed to get bus clock\n");
>
> nitpick. I recommend that better to keep 80 char on one line as following
> for the readability.
>
>                return dev_err_probe(dev, PTR_ERR(bus->clk),
>                                           "failed to get bus clock\n");
>
Ok
>
I will update this in the next version.

Thanks
-Anand

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-05-08 17:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-17  4:44 [PATCH v3 1/2] PM / devfreq: exynos: Use Use devm_clk_get_enabled() helpers Anand Moon
2024-04-17  4:44 ` [PATCH v3 2/2] PM / devfreq: exynos: Use DEFINE_SIMPLE_DEV_PM_OPS for PM functions Anand Moon
2024-05-08 15:42   ` Chanwoo Choi
2024-05-08 15:45 ` [PATCH v3 1/2] PM / devfreq: exynos: Use Use devm_clk_get_enabled() helpers Chanwoo Choi
2024-05-08 17:23   ` Anand Moon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).