Re: [PATCH 04/11] pwm: brcmstb: Use DEFINE_SIMPLE_DEV_PM_OPS for PM functions

Jonathan Cameron
2023-10-11T11:22:47Z

On Tue, 10 Oct 2023 09:51:05 +0200
Uwe Kleine-König <u.kleine-koenig@pengutronix.de> wrote:

> This macro has the advantage over SIMPLE_DEV_PM_OPS that we don't have to
> care about when the functions are actually used, so the corresponding
> #ifdef can be dropped.
>
> Also make use of pm_ptr() to discard all PM related stuff if CONFIG_PM
> isn't enabled.

The additional change to potentially return an error when not doing so before
wants to be called out in the description.

>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> drivers/pwm/pwm-brcmstb.c | 12 ++++--------
> 1 file changed, 4 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/pwm/pwm-brcmstb.c b/drivers/pwm/pwm-brcmstb.c
> index a3faa9a3de7c..7510b85dd9dd 100644
> --- a/drivers/pwm/pwm-brcmstb.c
> +++ b/drivers/pwm/pwm-brcmstb.c
> @@ -283,7 +283,6 @@ static void brcmstb_pwm_remove(struct platform_device *pdev)
> clk_disable_unprepare(p->clk);
> }
>
> -#ifdef CONFIG_PM_SLEEP
> static int brcmstb_pwm_suspend(struct device *dev)
> {
> struct brcmstb_pwm *p = dev_get_drvdata(dev);
> @@ -297,14 +296,11 @@ static int brcmstb_pwm_resume(struct device *dev)
> {
> struct brcmstb_pwm *p = dev_get_drvdata(dev);
>
> - clk_enable(p->clk);
> -
> - return 0;
> + return clk_enable(p->clk);
> }
> -#endif
>
> -static SIMPLE_DEV_PM_OPS(brcmstb_pwm_pm_ops, brcmstb_pwm_suspend,
> - brcmstb_pwm_resume);
> +static DEFINE_SIMPLE_DEV_PM_OPS(brcmstb_pwm_pm_ops, brcmstb_pwm_suspend,
> + brcmstb_pwm_resume);
>
> static struct platform_driver brcmstb_pwm_driver = {
> .probe = brcmstb_pwm_probe,
> @@ -312,7 +308,7 @@ static struct platform_driver brcmstb_pwm_driver = {
> .driver = {
> .name = "pwm-brcmstb",
> .of_match_table = brcmstb_pwm_of_match,
> - .pm = &brcmstb_pwm_pm_ops,
> + .pm = pm_ptr(&brcmstb_pwm_pm_ops),
> },
> };
> module_platform_driver(brcmstb_pwm_driver);