[PATCH v4 05/15] gpio: pxa: Use modern PM macros

Jisheng Zhang posted 15 patches 1 week, 5 days ago
There is a newer version of this series
[PATCH v4 05/15] gpio: pxa: Use modern PM macros
Posted by Jisheng Zhang 1 week, 5 days ago
Use the modern PM macros for the suspend and resume functions to be
automatically dropped by the compiler when CONFIG_PM or
CONFIG_PM_SLEEP are disabled, without having to use #ifdef guards.

This has the advantage of always compiling these functions in,
independently of any Kconfig option. Thanks to that, bugs and other
regressions are subsequently easier to catch.

Signed-off-by: Jisheng Zhang <jszhang@kernel.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/gpio-pxa.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index fa22f3faa163..17350fea2113 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -67,12 +67,10 @@ struct pxa_gpio_bank {
 	unsigned long	irq_edge_rise;
 	unsigned long	irq_edge_fall;
 
-#ifdef CONFIG_PM
 	unsigned long	saved_gplr;
 	unsigned long	saved_gpdr;
 	unsigned long	saved_grer;
 	unsigned long	saved_gfer;
-#endif
 };
 
 struct pxa_gpio_chip {
@@ -746,7 +744,6 @@ static int __init pxa_gpio_dt_init(void)
 }
 device_initcall(pxa_gpio_dt_init);
 
-#ifdef CONFIG_PM
 static int pxa_gpio_suspend(void)
 {
 	struct pxa_gpio_chip *pchip = pxa_gpio_chip;
@@ -787,14 +784,10 @@ static void pxa_gpio_resume(void)
 		writel_relaxed(c->saved_gpdr, c->regbase + GPDR_OFFSET);
 	}
 }
-#else
-#define pxa_gpio_suspend	NULL
-#define pxa_gpio_resume		NULL
-#endif
 
 static struct syscore_ops pxa_gpio_syscore_ops = {
-	.suspend	= pxa_gpio_suspend,
-	.resume		= pxa_gpio_resume,
+	.suspend	= pm_ptr(pxa_gpio_suspend),
+	.resume		= pm_ptr(pxa_gpio_resume),
 };
 
 static int __init pxa_gpio_sysinit(void)
-- 
2.51.0
Re: [PATCH v4 05/15] gpio: pxa: Use modern PM macros
Posted by Andy Shevchenko 1 week, 5 days ago
On Thu, Nov 20, 2025 at 12:33:17AM +0800, Jisheng Zhang wrote:
> Use the modern PM macros for the suspend and resume functions to be
> automatically dropped by the compiler when CONFIG_PM or
> CONFIG_PM_SLEEP are disabled, without having to use #ifdef guards.
> 
> This has the advantage of always compiling these functions in,
> independently of any Kconfig option. Thanks to that, bugs and other
> regressions are subsequently easier to catch.

...

>  static struct syscore_ops pxa_gpio_syscore_ops = {
> -	.suspend	= pxa_gpio_suspend,
> -	.resume		= pxa_gpio_resume,
> +	.suspend	= pm_ptr(pxa_gpio_suspend),
> +	.resume		= pm_ptr(pxa_gpio_resume),
>  };

I believe this needs to be thoroughly checked and thought through as
this is *not* a dev_pm_ops.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v4 05/15] gpio: pxa: Use modern PM macros
Posted by Jisheng Zhang 1 week, 5 days ago
On Wed, Nov 19, 2025 at 07:41:44PM +0200, Andy Shevchenko wrote:
> On Thu, Nov 20, 2025 at 12:33:17AM +0800, Jisheng Zhang wrote:
> > Use the modern PM macros for the suspend and resume functions to be
> > automatically dropped by the compiler when CONFIG_PM or
> > CONFIG_PM_SLEEP are disabled, without having to use #ifdef guards.
> > 
> > This has the advantage of always compiling these functions in,
> > independently of any Kconfig option. Thanks to that, bugs and other
> > regressions are subsequently easier to catch.
> 
> ...
> 
> >  static struct syscore_ops pxa_gpio_syscore_ops = {
> > -	.suspend	= pxa_gpio_suspend,
> > -	.resume		= pxa_gpio_resume,
> > +	.suspend	= pm_ptr(pxa_gpio_suspend),
> > +	.resume		= pm_ptr(pxa_gpio_resume),
> >  };
> 
> I believe this needs to be thoroughly checked and thought through as
> this is *not* a dev_pm_ops.

pm_ptr()/pm_sleep_ptr() is defined in pm.h, so I think we can make use
of it for syscore_ops as well.
E.g This patch makes use of pm_ptr() to optimize out .suspend/.resume when !PM
while get in them when PM. Thus the same result can be acchieved between
before and after this patch.

> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
>
Re: [PATCH v4 05/15] gpio: pxa: Use modern PM macros
Posted by Andy Shevchenko 1 week, 4 days ago
On Thu, Nov 20, 2025 at 2:42 AM Jisheng Zhang <jszhang@kernel.org> wrote:
> On Wed, Nov 19, 2025 at 07:41:44PM +0200, Andy Shevchenko wrote:
> > On Thu, Nov 20, 2025 at 12:33:17AM +0800, Jisheng Zhang wrote:
> > > Use the modern PM macros for the suspend and resume functions to be
> > > automatically dropped by the compiler when CONFIG_PM or
> > > CONFIG_PM_SLEEP are disabled, without having to use #ifdef guards.
> > >
> > > This has the advantage of always compiling these functions in,
> > > independently of any Kconfig option. Thanks to that, bugs and other
> > > regressions are subsequently easier to catch.

...

> > >  static struct syscore_ops pxa_gpio_syscore_ops = {
> > > -   .suspend        = pxa_gpio_suspend,
> > > -   .resume         = pxa_gpio_resume,
> > > +   .suspend        = pm_ptr(pxa_gpio_suspend),
> > > +   .resume         = pm_ptr(pxa_gpio_resume),
> > >  };
> >
> > I believe this needs to be thoroughly checked and thought through as
> > this is *not* a dev_pm_ops.
>
> pm_ptr()/pm_sleep_ptr() is defined in pm.h, so I think we can make use
> of it for syscore_ops as well.
> E.g This patch makes use of pm_ptr() to optimize out .suspend/.resume when !PM
> while get in them when PM. Thus the same result can be acchieved between
> before and after this patch.

At bare minimum this should be mentioned in the commit message that
you were/are aware of the data type differences.

-- 
With Best Regards,
Andy Shevchenko