diff mbox series

[v2,09/10] pinctrl: renesas: Switch to use DEFINE_NOIRQ_DEV_PM_OPS() helper

Message ID 20230717172821.62827-10-andriy.shevchenko@linux.intel.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series pinctrl: Provide NOIRQ PM helper and use it | expand

Commit Message

Andy Shevchenko July 17, 2023, 5:28 p.m. UTC
Since pm.h provides a helper for system no-IRQ PM callbacks,
switch the driver to use it instead of open coded variant.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/pinctrl/renesas/core.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

Comments

Paul Cercueil July 17, 2023, 7:12 p.m. UTC | #1
Hi Andy,


Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a écrit :
> Since pm.h provides a helper for system no-IRQ PM callbacks,
> switch the driver to use it instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  drivers/pinctrl/renesas/core.c | 16 +++++++---------
>  1 file changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/pinctrl/renesas/core.c
> b/drivers/pinctrl/renesas/core.c
> index 0c8d081da6a8..34232b016960 100644
> --- a/drivers/pinctrl/renesas/core.c
> +++ b/drivers/pinctrl/renesas/core.c
> @@ -649,7 +649,7 @@ static const struct of_device_id
> sh_pfc_of_table[] = {
>  };
>  #endif
>  
> -#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM_PSCI_FW)
> +#if defined(CONFIG_ARM_PSCI_FW)
>  static void sh_pfc_nop_reg(struct sh_pfc *pfc, u32 reg, unsigned int
> idx)
>  {
>  }
> @@ -732,15 +732,13 @@ static int sh_pfc_resume_noirq(struct device
> *dev)
>                 sh_pfc_walk_regs(pfc, sh_pfc_restore_reg);
>         return 0;
>  }
> -
> -static const struct dev_pm_ops sh_pfc_pm  = {
> -       SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sh_pfc_suspend_noirq,
> sh_pfc_resume_noirq)
> -};
> -#define DEV_PM_OPS     &sh_pfc_pm
>  #else
>  static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; }
> -#define DEV_PM_OPS     NULL
> -#endif /* CONFIG_PM_SLEEP && CONFIG_ARM_PSCI_FW */
> +static int sh_pfc_suspend_noirq(struct device *dev) { return 0; }
> +static int sh_pfc_resume_noirq(struct device *dev) { return 0; }
> +#endif /* CONFIG_ARM_PSCI_FW */
> +
> +static DEFINE_NOIRQ_DEV_PM_OPS(sh_pfc_pm, sh_pfc_suspend_noirq,
> sh_pfc_resume_noirq);
>  
>  #ifdef DEBUG
>  #define SH_PFC_MAX_REGS                300
> @@ -1418,7 +1416,7 @@ static struct platform_driver sh_pfc_driver = {
>         .driver         = {
>                 .name   = DRV_NAME,
>                 .of_match_table = of_match_ptr(sh_pfc_of_table),
> -               .pm     = DEV_PM_OPS,
> +               .pm     = pm_sleep_ptr(&sh_pfc_pm),

I think you could do:

.pm = IF_PTR(IS_ENABLED(CONFIG_ARM_PSCI_FW), pm_sleep_ptr(&sh_pfc_pm)),

Then you wouldn't need the #if defined(CONFIG_ARM_PSCI_FW) guard either
(as long as the code still compiles fine when that config option is
disabled), and you wouldn't need those dummy callbacks.

Cheers,
-Paul

>         },
>  };
>
Andy Shevchenko July 17, 2023, 7:38 p.m. UTC | #2
On Mon, Jul 17, 2023 at 10:12 PM Paul Cercueil <paul@crapouillou.net> wrote:
> Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a écrit :

...

> I think you could do:
>
> .pm = IF_PTR(IS_ENABLED(CONFIG_ARM_PSCI_FW), pm_sleep_ptr(&sh_pfc_pm)),
>
> Then you wouldn't need the #if defined(CONFIG_ARM_PSCI_FW) guard either
> (as long as the code still compiles fine when that config option is
> disabled), and you wouldn't need those dummy callbacks.

Thanks for the hint, but it's ugly looking code.
If we go this direction, we would need local arm_psci_fw_ptr() macro or so.
Paul Cercueil July 17, 2023, 7:57 p.m. UTC | #3
Le lundi 17 juillet 2023 à 22:38 +0300, Andy Shevchenko a écrit :
> On Mon, Jul 17, 2023 at 10:12 PM Paul Cercueil <paul@crapouillou.net>
> wrote:
> > Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a écrit :
> 
> ...
> 
> > I think you could do:
> > 
> > .pm = IF_PTR(IS_ENABLED(CONFIG_ARM_PSCI_FW),
> > pm_sleep_ptr(&sh_pfc_pm)),
> > 
> > Then you wouldn't need the #if defined(CONFIG_ARM_PSCI_FW) guard
> > either
> > (as long as the code still compiles fine when that config option is
> > disabled), and you wouldn't need those dummy callbacks.
> 
> Thanks for the hint, but it's ugly looking code.
> If we go this direction, we would need local arm_psci_fw_ptr() macro
> or so.
> 

Sure, a small macro works too.

-Paul
Geert Uytterhoeven July 18, 2023, 10:01 a.m. UTC | #4
On Mon, Jul 17, 2023 at 7:28 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
> Since pm.h provides a helper for system no-IRQ PM callbacks,
> switch the driver to use it instead of open coded variant.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Acked-by: Geert Uytterhoeven <geert+renesas@glider.be>

Gr{oetje,eeting}s,

                        Geert
Geert Uytterhoeven July 18, 2023, 10:05 a.m. UTC | #5
Hi Paul,

On Mon, Jul 17, 2023 at 9:12 PM Paul Cercueil <paul@crapouillou.net> wrote:
> Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a écrit :
> > Since pm.h provides a helper for system no-IRQ PM callbacks,
> > switch the driver to use it instead of open coded variant.
> >
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  drivers/pinctrl/renesas/core.c | 16 +++++++---------
> >  1 file changed, 7 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/pinctrl/renesas/core.c
> > b/drivers/pinctrl/renesas/core.c
> > index 0c8d081da6a8..34232b016960 100644
> > --- a/drivers/pinctrl/renesas/core.c
> > +++ b/drivers/pinctrl/renesas/core.c
> > @@ -649,7 +649,7 @@ static const struct of_device_id
> > sh_pfc_of_table[] = {
> >  };
> >  #endif
> >
> > -#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM_PSCI_FW)
> > +#if defined(CONFIG_ARM_PSCI_FW)
> >  static void sh_pfc_nop_reg(struct sh_pfc *pfc, u32 reg, unsigned int
> > idx)
> >  {
> >  }
> > @@ -732,15 +732,13 @@ static int sh_pfc_resume_noirq(struct device
> > *dev)
> >                 sh_pfc_walk_regs(pfc, sh_pfc_restore_reg);
> >         return 0;
> >  }
> > -
> > -static const struct dev_pm_ops sh_pfc_pm  = {
> > -       SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sh_pfc_suspend_noirq,
> > sh_pfc_resume_noirq)
> > -};
> > -#define DEV_PM_OPS     &sh_pfc_pm
> >  #else
> >  static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; }
> > -#define DEV_PM_OPS     NULL
> > -#endif /* CONFIG_PM_SLEEP && CONFIG_ARM_PSCI_FW */
> > +static int sh_pfc_suspend_noirq(struct device *dev) { return 0; }
> > +static int sh_pfc_resume_noirq(struct device *dev) { return 0; }
> > +#endif /* CONFIG_ARM_PSCI_FW */
> > +
> > +static DEFINE_NOIRQ_DEV_PM_OPS(sh_pfc_pm, sh_pfc_suspend_noirq,
> > sh_pfc_resume_noirq);
> >
> >  #ifdef DEBUG
> >  #define SH_PFC_MAX_REGS                300
> > @@ -1418,7 +1416,7 @@ static struct platform_driver sh_pfc_driver = {
> >         .driver         = {
> >                 .name   = DRV_NAME,
> >                 .of_match_table = of_match_ptr(sh_pfc_of_table),
> > -               .pm     = DEV_PM_OPS,
> > +               .pm     = pm_sleep_ptr(&sh_pfc_pm),
>
> I think you could do:
>
> .pm = IF_PTR(IS_ENABLED(CONFIG_ARM_PSCI_FW), pm_sleep_ptr(&sh_pfc_pm)),
>
> Then you wouldn't need the #if defined(CONFIG_ARM_PSCI_FW) guard either
> (as long as the code still compiles fine when that config option is
> disabled), and you wouldn't need those dummy callbacks.

Unfortunately not, as the code refers to psci_ops.cpu_suspend.

You could create a small wrapper for that, though.

Gr{oetje,eeting}s,

                        Geert
Jonathan Cameron July 18, 2023, 10:10 a.m. UTC | #6
On Mon, 17 Jul 2023 20:28:20 +0300
Andy Shevchenko <andriy.shevchenko@linux.intel.com> wrote:

> Since pm.h provides a helper for system no-IRQ PM callbacks,
> switch the driver to use it instead of open coded variant.
> 
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Slightly more complex case, but looks fine to me.
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Andy Shevchenko July 18, 2023, 12:43 p.m. UTC | #7
On Tue, Jul 18, 2023 at 1:12 PM Geert Uytterhoeven <geert@linux-m68k.org> wrote:
> On Mon, Jul 17, 2023 at 9:12 PM Paul Cercueil <paul@crapouillou.net> wrote:
> > Le lundi 17 juillet 2023 à 20:28 +0300, Andy Shevchenko a écrit :

...

> > I think you could do:
> >
> > .pm = IF_PTR(IS_ENABLED(CONFIG_ARM_PSCI_FW), pm_sleep_ptr(&sh_pfc_pm)),
> >
> > Then you wouldn't need the #if defined(CONFIG_ARM_PSCI_FW) guard either
> > (as long as the code still compiles fine when that config option is
> > disabled), and you wouldn't need those dummy callbacks.
>
> Unfortunately not, as the code refers to psci_ops.cpu_suspend.
>
> You could create a small wrapper for that, though.

 I think it's already too many wrappers mentioned and since you
reviewed and acknowledged the change (thanks!) I will stick with my
initial version.
diff mbox series

Patch

diff --git a/drivers/pinctrl/renesas/core.c b/drivers/pinctrl/renesas/core.c
index 0c8d081da6a8..34232b016960 100644
--- a/drivers/pinctrl/renesas/core.c
+++ b/drivers/pinctrl/renesas/core.c
@@ -649,7 +649,7 @@  static const struct of_device_id sh_pfc_of_table[] = {
 };
 #endif
 
-#if defined(CONFIG_PM_SLEEP) && defined(CONFIG_ARM_PSCI_FW)
+#if defined(CONFIG_ARM_PSCI_FW)
 static void sh_pfc_nop_reg(struct sh_pfc *pfc, u32 reg, unsigned int idx)
 {
 }
@@ -732,15 +732,13 @@  static int sh_pfc_resume_noirq(struct device *dev)
 		sh_pfc_walk_regs(pfc, sh_pfc_restore_reg);
 	return 0;
 }
-
-static const struct dev_pm_ops sh_pfc_pm  = {
-	SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(sh_pfc_suspend_noirq, sh_pfc_resume_noirq)
-};
-#define DEV_PM_OPS	&sh_pfc_pm
 #else
 static int sh_pfc_suspend_init(struct sh_pfc *pfc) { return 0; }
-#define DEV_PM_OPS	NULL
-#endif /* CONFIG_PM_SLEEP && CONFIG_ARM_PSCI_FW */
+static int sh_pfc_suspend_noirq(struct device *dev) { return 0; }
+static int sh_pfc_resume_noirq(struct device *dev) { return 0; }
+#endif	/* CONFIG_ARM_PSCI_FW */
+
+static DEFINE_NOIRQ_DEV_PM_OPS(sh_pfc_pm, sh_pfc_suspend_noirq, sh_pfc_resume_noirq);
 
 #ifdef DEBUG
 #define SH_PFC_MAX_REGS		300
@@ -1418,7 +1416,7 @@  static struct platform_driver sh_pfc_driver = {
 	.driver		= {
 		.name	= DRV_NAME,
 		.of_match_table = of_match_ptr(sh_pfc_of_table),
-		.pm     = DEV_PM_OPS,
+		.pm	= pm_sleep_ptr(&sh_pfc_pm),
 	},
 };