mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCHv2] gpio: mvebu: convert to noirq suspend/resume to prevent interrupt storm on resume
@ 2026-07-10  7:07 Rosen Penev
  2026-09-07  1:20 ` Rosen Penev
  2026-09-16 13:33 ` Linus Walleij
  0 siblings, 2 replies; 4+ messages in thread
From: Rosen Penev @ 2026-07-10  7:07 UTC (permalink / raw)
  To: linux-gpio; +Cc: Linus Walleij, Bartosz Golaszewski, open list

The driver uses the legacy .suspend/.resume callbacks, but sets
IRQCHIP_MASK_ON_SUSPEND on the irq_chip. During resume, the PM core
runs dpm_resume_noirq() first, which calls irq_pm_resume() to unmask
interrupts, and only then runs dpm_resume() which invokes the driver's
.resume callback to restore GPIO registers (GPIO_IN_POL, GPIO_IO_CONF,
mask registers).

This ordering means interrupts are unmasked while the hardware is still
in its reset state, potentially with incorrect polarities, causing
spurious level-triggered interrupts before local IRQs are re-enabled.

Convert the driver from legacy .suspend/.resume callbacks to noirq
callbacks via dev_pm_ops. The noirq phase runs before resume_device_irqs()
on resume and after suspend_device_irqs() on suspend, ensuring GPIO
registers are restored before interrupts are unmasked.

Assisted-by: opencode:big-pickle
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 v2: add __maybe_unused to fix compilation
 drivers/gpio/gpio-mvebu.c | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 7094ab34020c..bd31acf779e6 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -979,9 +979,9 @@ static const struct of_device_id mvebu_gpio_of_match[] = {
 	},
 };
 
-static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
+static __maybe_unused int mvebu_gpio_suspend(struct device *dev)
 {
-	struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
+	struct mvebu_gpio_chip *mvchip = dev_get_drvdata(dev);
 	int i;
 
 	regmap_read(mvchip->regs, GPIO_OUT_OFF + mvchip->offset,
@@ -1031,9 +1031,9 @@ static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
 	return 0;
 }
 
-static int mvebu_gpio_resume(struct platform_device *pdev)
+static __maybe_unused int mvebu_gpio_resume(struct device *dev)
 {
-	struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
+	struct mvebu_gpio_chip *mvchip = dev_get_drvdata(dev);
 	int i;
 
 	regmap_write(mvchip->regs, GPIO_OUT_OFF + mvchip->offset,
@@ -1339,13 +1339,16 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static const struct dev_pm_ops mvebu_gpio_pm_ops = {
+	SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mvebu_gpio_suspend, mvebu_gpio_resume)
+};
+
 static struct platform_driver mvebu_gpio_driver = {
 	.driver		= {
 		.name		= "mvebu-gpio",
 		.of_match_table = mvebu_gpio_of_match,
+		.pm		= pm_sleep_ptr(&mvebu_gpio_pm_ops),
 	},
 	.probe		= mvebu_gpio_probe,
-	.suspend        = mvebu_gpio_suspend,
-	.resume         = mvebu_gpio_resume,
 };
 builtin_platform_driver(mvebu_gpio_driver);
-- 
2.55.0


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

* Re: [PATCHv2] gpio: mvebu: convert to noirq suspend/resume to prevent interrupt storm on resume
  2026-07-10  7:07 [PATCHv2] gpio: mvebu: convert to noirq suspend/resume to prevent interrupt storm on resume Rosen Penev
@ 2026-09-07  1:20 ` Rosen Penev
  2026-09-16 13:33 ` Linus Walleij
  1 sibling, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-09-07  1:20 UTC (permalink / raw)
  To: linux-gpio; +Cc: Linus Walleij, Bartosz Golaszewski, open list

On Fri, Jul 10, 2026 at 12:07 AM Rosen Penev <rosenp@gmail.com> wrote:
>
> The driver uses the legacy .suspend/.resume callbacks, but sets
> IRQCHIP_MASK_ON_SUSPEND on the irq_chip. During resume, the PM core
> runs dpm_resume_noirq() first, which calls irq_pm_resume() to unmask
> interrupts, and only then runs dpm_resume() which invokes the driver's
> .resume callback to restore GPIO registers (GPIO_IN_POL, GPIO_IO_CONF,
> mask registers).
>
> This ordering means interrupts are unmasked while the hardware is still
> in its reset state, potentially with incorrect polarities, causing
> spurious level-triggered interrupts before local IRQs are re-enabled.
>
> Convert the driver from legacy .suspend/.resume callbacks to noirq
> callbacks via dev_pm_ops. The noirq phase runs before resume_device_irqs()
> on resume and after suspend_device_irqs() on suspend, ensuring GPIO
> registers are restored before interrupts are unmasked.
>
> Assisted-by: opencode:big-pickle
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  v2: add __maybe_unused to fix compilation
Should I resend?
>  drivers/gpio/gpio-mvebu.c | 15 +++++++++------
>  1 file changed, 9 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
> index 7094ab34020c..bd31acf779e6 100644
> --- a/drivers/gpio/gpio-mvebu.c
> +++ b/drivers/gpio/gpio-mvebu.c
> @@ -979,9 +979,9 @@ static const struct of_device_id mvebu_gpio_of_match[] = {
>         },
>  };
>
> -static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
> +static __maybe_unused int mvebu_gpio_suspend(struct device *dev)
>  {
> -       struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
> +       struct mvebu_gpio_chip *mvchip = dev_get_drvdata(dev);
>         int i;
>
>         regmap_read(mvchip->regs, GPIO_OUT_OFF + mvchip->offset,
> @@ -1031,9 +1031,9 @@ static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
>         return 0;
>  }
>
> -static int mvebu_gpio_resume(struct platform_device *pdev)
> +static __maybe_unused int mvebu_gpio_resume(struct device *dev)
>  {
> -       struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
> +       struct mvebu_gpio_chip *mvchip = dev_get_drvdata(dev);
>         int i;
>
>         regmap_write(mvchip->regs, GPIO_OUT_OFF + mvchip->offset,
> @@ -1339,13 +1339,16 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
>         return 0;
>  }
>
> +static const struct dev_pm_ops mvebu_gpio_pm_ops = {
> +       SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(mvebu_gpio_suspend, mvebu_gpio_resume)
> +};
> +
>  static struct platform_driver mvebu_gpio_driver = {
>         .driver         = {
>                 .name           = "mvebu-gpio",
>                 .of_match_table = mvebu_gpio_of_match,
> +               .pm             = pm_sleep_ptr(&mvebu_gpio_pm_ops),
>         },
>         .probe          = mvebu_gpio_probe,
> -       .suspend        = mvebu_gpio_suspend,
> -       .resume         = mvebu_gpio_resume,
>  };
>  builtin_platform_driver(mvebu_gpio_driver);
> --
> 2.55.0
>

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

* Re: [PATCHv2] gpio: mvebu: convert to noirq suspend/resume to prevent interrupt storm on resume
  2026-07-10  7:07 [PATCHv2] gpio: mvebu: convert to noirq suspend/resume to prevent interrupt storm on resume Rosen Penev
  2026-09-07  1:20 ` Rosen Penev
@ 2026-09-16 13:33 ` Linus Walleij
  2026-09-16 18:17   ` Rosen Penev
  1 sibling, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2026-09-16 13:33 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-gpio, Bartosz Golaszewski, open list

On Fri, Jul 10, 2026 at 9:07 AM Rosen Penev <rosenp@gmail.com> wrote:

> The driver uses the legacy .suspend/.resume callbacks, but sets
> IRQCHIP_MASK_ON_SUSPEND on the irq_chip. During resume, the PM core
> runs dpm_resume_noirq() first, which calls irq_pm_resume() to unmask
> interrupts, and only then runs dpm_resume() which invokes the driver's
> .resume callback to restore GPIO registers (GPIO_IN_POL, GPIO_IO_CONF,
> mask registers).
>
> This ordering means interrupts are unmasked while the hardware is still
> in its reset state, potentially with incorrect polarities, causing
> spurious level-triggered interrupts before local IRQs are re-enabled.
>
> Convert the driver from legacy .suspend/.resume callbacks to noirq
> callbacks via dev_pm_ops. The noirq phase runs before resume_device_irqs()
> on resume and after suspend_device_irqs() on suspend, ensuring GPIO
> registers are restored before interrupts are unmasked.
>
> Assisted-by: opencode:big-pickle

Should be
Assisted-by: LLM
these days (Bartosz can probs fix when applying)

> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij

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

* Re: [PATCHv2] gpio: mvebu: convert to noirq suspend/resume to prevent interrupt storm on resume
  2026-09-16 13:33 ` Linus Walleij
@ 2026-09-16 18:17   ` Rosen Penev
  0 siblings, 0 replies; 4+ messages in thread
From: Rosen Penev @ 2026-09-16 18:17 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, Bartosz Golaszewski, open list

On Wed, Sep 16, 2026 at 6:34 AM Linus Walleij <linusw@kernel.org> wrote:
>
> On Fri, Jul 10, 2026 at 9:07 AM Rosen Penev <rosenp@gmail.com> wrote:
>
> > The driver uses the legacy .suspend/.resume callbacks, but sets
> > IRQCHIP_MASK_ON_SUSPEND on the irq_chip. During resume, the PM core
> > runs dpm_resume_noirq() first, which calls irq_pm_resume() to unmask
> > interrupts, and only then runs dpm_resume() which invokes the driver's
> > .resume callback to restore GPIO registers (GPIO_IN_POL, GPIO_IO_CONF,
> > mask registers).
> >
> > This ordering means interrupts are unmasked while the hardware is still
> > in its reset state, potentially with incorrect polarities, causing
> > spurious level-triggered interrupts before local IRQs are re-enabled.
> >
> > Convert the driver from legacy .suspend/.resume callbacks to noirq
> > callbacks via dev_pm_ops. The noirq phase runs before resume_device_irqs()
> > on resume and after suspend_device_irqs() on suspend, ensuring GPIO
> > registers are restored before interrupts are unmasked.
> >
> > Assisted-by: opencode:big-pickle
>
> Should be
> Assisted-by: LLM
> these days (Bartosz can probs fix when applying)
I'll post a v3. There's a better way than __maybe_unused.
>
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
>
> Reviewed-by: Linus Walleij <linusw@kernel.org>
>
> Yours,
> Linus Walleij

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

end of thread, other threads:[~2026-09-16 18:17 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-10  7:07 [PATCHv2] gpio: mvebu: convert to noirq suspend/resume to prevent interrupt storm on resume Rosen Penev
2026-09-07  1:20 ` Rosen Penev
2026-09-16 13:33 ` Linus Walleij
2026-09-16 18:17   ` Rosen Penev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®