Linux real-time development
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Clark Williams <clrkwllms@kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Gregory CLEMENT <gregory.clement@bootlin.com>,
	Rosen Penev <rosenp@gmail.com>, Rob Herring <robh@kernel.org>,
	Thierry Reding <thierry.reding@gmail.com>,
	Ralph Sennhauser <ralph.sennhauser@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>
Cc: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>,
	linux-gpio@vger.kernel.org, linux-rt-devel@lists.linux.dev
Subject: [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume
Date: Fri,  4 Dec 2026 19:11:09 -0800	[thread overview]
Message-ID: <20261205031111.12306-4-rosenp@gmail.com> (raw)
In-Reply-To: <20261205031111.12306-1-rosenp@gmail.com>

mvebu_gpio_resume() writes back the mask registers saved at suspend
time, ANDed with the irqchip mask cache.  A line that was masked at
suspend time and unmasked before mvebu_gpio_resume() runs, for example
by enable_irq() in another driver's resume_noirq callback, is set in
both the cache and the hardware, but not in the saved value.  The
restore then masks it again behind genirq's back and its interrupts
are lost.

Include the current register value when restoring: keep a line
unmasked if it was unmasked at suspend time or is unmasked now, and
only while the cache still has it unmasked.  After a power loss the
mask registers come back as zero, so this changes nothing there.

Fixes: 02af7eac17bc ("gpio: mvebu: keep resume masks within the irqchip cache")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/gpio/gpio-mvebu.c | 55 +++++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 17 deletions(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index a2974515b408..eda52cfaa145 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -996,6 +996,20 @@ static const struct of_device_id mvebu_gpio_of_match[] = {
 	},
 };
 
+/*
+ * Keep a line unmasked if it was unmasked at suspend time or has been unmasked
+ * since, for example by enable_irq() from another driver's resume_noirq
+ * callback, and only while the irqchip cache still has it unmasked.
+ */
+static void mvebu_gpio_restore_mask(struct regmap *map, unsigned int reg,
+				    u32 saved, u32 cache)
+{
+	u32 cur;
+
+	regmap_read(map, reg, &cur);
+	regmap_write(map, reg, (saved | cur) & cache);
+}
+
 static void
 mvebu_gpio_restore_irq_masks(struct mvebu_gpio_chip *mvchip, u32 level_cache,
 			     u32 edge_cache)
@@ -1005,29 +1019,35 @@ mvebu_gpio_restore_irq_masks(struct mvebu_gpio_chip *mvchip, u32 level_cache,
 	switch (mvchip->soc_variant) {
 	case MVEBU_GPIO_SOC_VARIANT_ORION:
 	case MVEBU_GPIO_SOC_VARIANT_A8K:
-		regmap_write(mvchip->regs, GPIO_EDGE_MASK_OFF + mvchip->offset,
-			     mvchip->edge_mask_regs[0] & edge_cache);
-		regmap_write(mvchip->regs, GPIO_LEVEL_MASK_OFF + mvchip->offset,
-			     mvchip->level_mask_regs[0] & level_cache);
+		mvebu_gpio_restore_mask(mvchip->regs,
+					GPIO_EDGE_MASK_OFF + mvchip->offset,
+					mvchip->edge_mask_regs[0], edge_cache);
+		mvebu_gpio_restore_mask(mvchip->regs,
+					GPIO_LEVEL_MASK_OFF + mvchip->offset,
+					mvchip->level_mask_regs[0], level_cache);
 		break;
 	case MVEBU_GPIO_SOC_VARIANT_MV78200:
 		for (i = 0; i < 2; i++) {
-			regmap_write(mvchip->regs,
-				     GPIO_EDGE_MASK_MV78200_OFF(i),
-				     mvchip->edge_mask_regs[i] & edge_cache);
-			regmap_write(mvchip->regs,
-				     GPIO_LEVEL_MASK_MV78200_OFF(i),
-				     mvchip->level_mask_regs[i] & level_cache);
+			mvebu_gpio_restore_mask(mvchip->regs,
+						GPIO_EDGE_MASK_MV78200_OFF(i),
+						mvchip->edge_mask_regs[i],
+						edge_cache);
+			mvebu_gpio_restore_mask(mvchip->regs,
+						GPIO_LEVEL_MASK_MV78200_OFF(i),
+						mvchip->level_mask_regs[i],
+						level_cache);
 		}
 		break;
 	case MVEBU_GPIO_SOC_VARIANT_ARMADAXP:
 		for (i = 0; i < 4; i++) {
-			regmap_write(mvchip->percpu_regs,
-				     GPIO_EDGE_MASK_ARMADAXP_OFF(i),
-				     mvchip->edge_mask_regs[i] & edge_cache);
-			regmap_write(mvchip->percpu_regs,
-				     GPIO_LEVEL_MASK_ARMADAXP_OFF(i),
-				     mvchip->level_mask_regs[i] & level_cache);
+			mvebu_gpio_restore_mask(mvchip->percpu_regs,
+						GPIO_EDGE_MASK_ARMADAXP_OFF(i),
+						mvchip->edge_mask_regs[i],
+						edge_cache);
+			mvebu_gpio_restore_mask(mvchip->percpu_regs,
+						GPIO_LEVEL_MASK_ARMADAXP_OFF(i),
+						mvchip->level_mask_regs[i],
+						level_cache);
 		}
 		break;
 	default:
@@ -1103,7 +1123,8 @@ static int mvebu_gpio_resume(struct platform_device *pdev)
 	/*
 	 * genirq skips mask_irq() for a line it already considers masked, so
 	 * unmasking one behind its back leaves an asserted level line that
-	 * nobody masks. Restore only bits the irqchip cache still has set.
+	 * nobody masks. Restore only bits the irqchip cache still has set; see
+	 * mvebu_gpio_restore_mask().
 	 *
 	 * Hold gc->lock across the writes so the restore cannot race the
 	 * mask/unmask handlers, which update the cache and write the mask
-- 
2.56.1


  parent reply	other threads:[~2026-12-05  3:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  3:11 [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes Rosen Penev
2026-12-05  3:11 ` [PATCH v2 1/5] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too Rosen Penev
2026-12-05  3:11 ` [PATCH v2 2/5] gpio: mvebu: restore suspend-time irq masks under gc->lock Rosen Penev
2026-12-05  3:11 ` Rosen Penev [this message]
2026-12-05  3:25   ` [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume sashiko-bot
2026-12-05  3:11 ` [PATCH v2 4/5] gpio: mvebu: don't request the PWM GPIO under a spinlock Rosen Penev
2026-12-05  3:11 ` [PATCH v2 5/5] gpio: mvebu: report the PWM line's own enable bit Rosen Penev

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261205031111.12306-4-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=bartosz.golaszewski@oss.qualcomm.com \
    --cc=bigeasy@linutronix.de \
    --cc=brgl@kernel.org \
    --cc=clrkwllms@kernel.org \
    --cc=gregory.clement@bootlin.com \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=ralph.sennhauser@gmail.com \
    --cc=robh@kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=thierry.reding@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox