[PATCH v3 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 v3 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 | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/gpio/gpio-pxa.c b/drivers/gpio/gpio-pxa.c
index fa22f3faa163..288c72f9c015 100644
--- a/drivers/gpio/gpio-pxa.c
+++ b/drivers/gpio/gpio-pxa.c
@@ -66,13 +66,10 @@ struct pxa_gpio_bank {
 	unsigned long	irq_mask;
 	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 +743,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 +783,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 v3 05/15] gpio: pxa: Use modern PM macros
Posted by Andy Shevchenko 1 week, 5 days ago
On Wed, Nov 19, 2025 at 10:43:17PM +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.

...

> struct pxa_gpio_bank {

...

>  	unsigned long	irq_mask;
>  	unsigned long	irq_edge_rise;
>  	unsigned long	irq_edge_fall;

> -

As I already pointed out this is stray change. Why you ignored my comment?

> -#ifdef CONFIG_PM
>  	unsigned long	saved_gplr;
>  	unsigned long	saved_gpdr;
>  	unsigned long	saved_grer;
>  	unsigned long	saved_gfer;
> -#endif

Same Q as per dwapb driver. The CONFIG_PM=n doesn't need these.

>  };

...

>  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),
>  };

This is not a device PM ops actually. Is there any guarantees on the
relationship with CONFIG_PM and these callbacks? If so, I think we
need to have special macros somewhere in include/linux/syscore_ops.h.

Otherwise I'm not sure this will be a good patch at all.

-- 
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 05/15] gpio: pxa: Use modern PM macros
Posted by Jisheng Zhang 1 week, 5 days ago
On Wed, Nov 19, 2025 at 05:47:41PM +0200, Andy Shevchenko wrote:
> On Wed, Nov 19, 2025 at 10:43:17PM +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.
> 
> ...
> 
> > struct pxa_gpio_bank {
> 
> ...
> 
> >  	unsigned long	irq_mask;
> >  	unsigned long	irq_edge_rise;
> >  	unsigned long	irq_edge_fall;
> 
> > -
> 
> As I already pointed out this is stray change. Why you ignored my comment?
> 
> > -#ifdef CONFIG_PM
> >  	unsigned long	saved_gplr;
> >  	unsigned long	saved_gpdr;
> >  	unsigned long	saved_grer;
> >  	unsigned long	saved_gfer;
> > -#endif
> 
> Same Q as per dwapb driver. The CONFIG_PM=n doesn't need these.

Now, I know why you commented like these... 
the pm_ptr() and pm_sleep_ptr() can optimize out the PM
functions, but those functions still need to be compiled. So if
we keep these #ifdef, there will be build errors in case of !PM

> 
> >  };
> 
> ...
> 
> >  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),
> >  };
> 
> This is not a device PM ops actually. Is there any guarantees on the
> relationship with CONFIG_PM and these callbacks? If so, I think we
> need to have special macros somewhere in include/linux/syscore_ops.h.
> 
> Otherwise I'm not sure this will be a good patch at all.
> 
> -- 
> With Best Regards,
> Andy Shevchenko
> 
>
Re: [PATCH v3 05/15] gpio: pxa: Use modern PM macros
Posted by Andy Shevchenko 1 week, 5 days ago
On Wed, Nov 19, 2025 at 11:58:19PM +0800, Jisheng Zhang wrote:
> On Wed, Nov 19, 2025 at 05:47:41PM +0200, Andy Shevchenko wrote:
> > On Wed, Nov 19, 2025 at 10:43:17PM +0800, Jisheng Zhang wrote:

...

> > > -#ifdef CONFIG_PM
> > >  	unsigned long	saved_gplr;
> > >  	unsigned long	saved_gpdr;
> > >  	unsigned long	saved_grer;
> > >  	unsigned long	saved_gfer;
> > > -#endif
> > 
> > Same Q as per dwapb driver. The CONFIG_PM=n doesn't need these.
> 
> Now, I know why you commented like these... 
> the pm_ptr() and pm_sleep_ptr() can optimize out the PM
> functions, but those functions still need to be compiled. So if
> we keep these #ifdef, there will be build errors in case of !PM

My bad. I haven't realised that it's not just being discarded...

Thanks for your patience. Then please, fix the typos and we will go
with the v4.

-- 
With Best Regards,
Andy Shevchenko