Linux real-time development
 help / color / mirror / Atom feed
* [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes
@ 2026-12-05  3:11 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
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Rosen Penev @ 2026-12-05  3:11 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
	Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
	Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
  Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel

Fixes for the irq mask restore on resume and for the PWM code.

Patch 1 extends commit
42269cdb3d3b ("gpio: mvebu: fix sleeping-while-atomic in mvebu_gpio_level_irq_mask()")
to Armada 7K/8K. There the
driver used the parent's syscon regmap, which has an ordinary spinlock,
so the mask/unmask callbacks still slept under the raw gc->lock on
PREEMPT_RT. The driver now maps the parent's range and uses its own
raw-locked regmap.

Patch 2 closes a race in resume. The mask registers were rebuilt from a
snapshot of the irqchip mask cache taken under gc->lock, but written
after the lock was dropped. A mask or unmask in between was lost.

Patch 3 stops the restore from masking a line that was masked at
suspend time but unmasked again before the GPIO driver resumed, for
example by enable_irq() in another driver's resume_noirq callback.

Patch 4 stops requesting the PWM's GPIO line under a spinlock, which
can sleep. Patch 5 makes the PWM state report only its own line's
enable bit.

The series is based on gpio/for-current, which has commit d8e27d042747
("gpio: mvebu: fix Armada XP per-CPU mask register save/restore").

Each patch builds with W=1 for arm (mvebu_v7_defconfig + PWM +
PREEMPT_RT + PROVE_LOCKING). None of them has been tested on hardware
yet.

Changes in v2:
- Move the Armada 7K/8K regmap patch first, so the resume patch no
  longer takes the syscon regmap's lock under gc->lock at any point in
  the series (review).
- New patch 3: keep lines unmasked during early resume unmasked
  (review).
- New patches 4 and 5: PWM fixes.
- v1: https://lore.kernel.org/linux-gpio/20261203225820.83277-1-rosenp@gmail.com/

Rosen Penev (5):
  gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too
  gpio: mvebu: restore suspend-time irq masks under gc->lock
  gpio: mvebu: don't re-mask irqs unmasked during early resume
  gpio: mvebu: don't request the PWM GPIO under a spinlock
  gpio: mvebu: report the PWM line's own enable bit

 drivers/gpio/gpio-mvebu.c | 178 +++++++++++++++++++++++---------------
 1 file changed, 107 insertions(+), 71 deletions(-)


base-commit: f4379936003e4a233ed8d7b8ab299630bae85fec
-- 
2.56.1


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

* [PATCH v2 1/5] gpio: mvebu: use a raw-locked regmap on Armada 7K/8K too
  2026-12-05  3:11 [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes Rosen Penev
@ 2026-12-05  3:11 ` Rosen Penev
  2026-12-05  3:11 ` [PATCH v2 2/5] gpio: mvebu: restore suspend-time irq masks under gc->lock Rosen Penev
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Rosen Penev @ 2026-12-05  3:11 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
	Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
	Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
  Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel

Commit 42269cdb3d3b ("gpio: mvebu: fix sleeping-while-atomic in
mvebu_gpio_level_irq_mask()") made the driver's MMIO regmaps use raw
spinlocks, because the irq_chip mask/unmask callbacks write the mask
registers while holding the generic chip's raw gc->lock.  That only
covers the regmaps the driver creates itself.  On Armada 7K/8K
("marvell,armada-8k-gpio") the GPIO block sits inside a system
controller and the driver uses the parent's syscon regmap, which syscon
creates with an ordinary spinlock.  On PREEMPT_RT that lock sleeps, so
masking or unmasking a GPIO interrupt there still sleeps in atomic
context.

The syscon regmap's lock cannot be changed from here, and nothing else
accesses the GPIO bank's registers at its offset, so the shared lock is
not protecting anything this driver needs.  Map the parent's register
range again and create a regmap of our own with the raw-locked
mvebu_gpio_regmap_config, as the non-syscon path already does.  The
mapping is not requested, as syscon does not request it either.

Fixes: b6730b20837e ("gpio: mvebu: Add support for the Armada 7K/8K SoCs")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/gpio/gpio-mvebu.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 6c2bcc5d749c..ab350c8686e3 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -42,8 +42,8 @@
 #include <linux/irq.h>
 #include <linux/irqchip/chained_irq.h>
 #include <linux/irqdomain.h>
-#include <linux/mfd/syscon.h>
 #include <linux/of.h>
+#include <linux/of_address.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/platform_device.h>
 #include <linux/property.h>
@@ -1163,7 +1163,29 @@ static int mvebu_gpio_probe_raw(struct platform_device *pdev,
 static int mvebu_gpio_probe_syscon(struct platform_device *pdev,
 				   struct mvebu_gpio_chip *mvchip)
 {
-	mvchip->regs = syscon_node_to_regmap(pdev->dev.parent->of_node);
+	struct device_node *np = pdev->dev.parent->of_node;
+	void __iomem *base;
+	struct resource res;
+	int ret;
+
+	/*
+	 * The GPIO registers live inside the parent system controller, but
+	 * don't use its syscon regmap: that one is created with a normal
+	 * spinlock, which sleeps on PREEMPT_RT, and the irq_chip callbacks
+	 * write the mask registers under the raw gc->lock. This driver is
+	 * the only user of the registers at its offset, so map the parent's
+	 * range again and access it through a raw-locked regmap of our own.
+	 */
+	ret = of_address_to_resource(np, 0, &res);
+	if (ret)
+		return ret;
+
+	base = devm_ioremap(&pdev->dev, res.start, resource_size(&res));
+	if (!base)
+		return -ENOMEM;
+
+	mvchip->regs = devm_regmap_init_mmio(&pdev->dev, base,
+					     &mvebu_gpio_regmap_config);
 	if (IS_ERR(mvchip->regs))
 		return PTR_ERR(mvchip->regs);
 
-- 
2.56.1


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

* [PATCH v2 2/5] gpio: mvebu: restore suspend-time irq masks under gc->lock
  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 ` Rosen Penev
  2026-12-05  3:11 ` [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume Rosen Penev
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Rosen Penev @ 2026-12-05  3:11 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
	Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
	Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
  Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel

mvebu_gpio_resume() snapshots the irqchip's mask_cache_priv under
gc->lock, drops the lock, and only then writes the saved edge/level
masks ANDed with that snapshot back to hardware.  A mask or unmask
handler running in that window updates the cache and the register, and
the restore then overwrites the register with the stale value.  A line
masked in the window ends up unmasked behind genirq's back, so an
asserted level line has nobody to ack it and the chained handler
storms; a line unmasked in the window stays masked in hardware and
loses its interrupts.

Hold gc->lock for the whole restore, as the mask/unmask handlers
already do for their cache update and register write, so the two
cannot interleave.  Move the per-variant register writes into
mvebu_gpio_restore_irq_masks() to keep the locked section readable,
and replace the BUG() on an unknown SoC variant with WARN_ON_ONCE().

Controllers without an irq domain no longer have their mask registers
written on resume.  Nothing unmasks lines on such a controller, so the
registers it saved at suspend time are not ones the driver set.

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

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index ab350c8686e3..a2974515b408 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -996,6 +996,45 @@ static const struct of_device_id mvebu_gpio_of_match[] = {
 	},
 };
 
+static void
+mvebu_gpio_restore_irq_masks(struct mvebu_gpio_chip *mvchip, u32 level_cache,
+			     u32 edge_cache)
+{
+	int i;
+
+	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);
+		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);
+		}
+		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);
+		}
+		break;
+	default:
+		WARN_ON_ONCE(1);
+	}
+}
+
 static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
 {
 	struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
@@ -1051,9 +1090,6 @@ static int mvebu_gpio_suspend(struct platform_device *pdev, pm_message_t state)
 static int mvebu_gpio_resume(struct platform_device *pdev)
 {
 	struct mvebu_gpio_chip *mvchip = platform_get_drvdata(pdev);
-	u32 edge_cache = ~0U, level_cache = ~0U;
-	unsigned long flags;
-	int i;
 
 	regmap_write(mvchip->regs, GPIO_OUT_OFF + mvchip->offset,
 		     mvchip->out_reg);
@@ -1069,50 +1105,18 @@ static int mvebu_gpio_resume(struct platform_device *pdev)
 	 * unmasking one behind its back leaves an asserted level line that
 	 * nobody masks. Restore only bits the irqchip cache still has set.
 	 *
-	 * Snapshot the caches under the raw spinlock, but release it before
-	 * the regmap writes below: regmap_write() takes a sleepable lock on
-	 * PREEMPT_RT.
+	 * Hold gc->lock across the writes so the restore cannot race the
+	 * mask/unmask handlers, which update the cache and write the mask
+	 * registers under the same lock.
 	 */
 	if (mvchip->domain) {
 		struct irq_chip_generic *gc;
 
 		gc = irq_get_domain_generic_chip(mvchip->domain, 0);
-		raw_spin_lock_irqsave(&gc->lock, flags);
-		level_cache = gc->chip_types[0].mask_cache_priv;
-		edge_cache = gc->chip_types[1].mask_cache_priv;
-		raw_spin_unlock_irqrestore(&gc->lock, flags);
-	}
-
-	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);
-		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);
-		}
-		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);
-		}
-		break;
-	default:
-		BUG();
+		guard(raw_spinlock_irqsave)(&gc->lock);
+		mvebu_gpio_restore_irq_masks(mvchip,
+					     gc->chip_types[0].mask_cache_priv,
+					     gc->chip_types[1].mask_cache_priv);
 	}
 
 	if (IS_REACHABLE(CONFIG_PWM) && mvchip->mvpwm)
-- 
2.56.1


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

* [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume
  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
  2026-12-05  3:25   ` 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
  4 siblings, 1 reply; 7+ messages in thread
From: Rosen Penev @ 2026-12-05  3:11 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
	Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
	Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
  Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel

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


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

* [PATCH v2 4/5] gpio: mvebu: don't request the PWM GPIO under a spinlock
  2026-12-05  3:11 [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes Rosen Penev
                   ` (2 preceding siblings ...)
  2026-12-05  3:11 ` [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume Rosen Penev
@ 2026-12-05  3:11 ` Rosen Penev
  2026-12-05  3:11 ` [PATCH v2 5/5] gpio: mvebu: report the PWM line's own enable bit Rosen Penev
  4 siblings, 0 replies; 7+ messages in thread
From: Rosen Penev @ 2026-12-05  3:11 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
	Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
	Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
  Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel

mvebu_pwm_request() calls gpiochip_request_own_desc() with mvpwm->lock
held and interrupts disabled, and mvebu_pwm_free() does the same with
gpiochip_free_own_desc().  Both can sleep: requesting the line goes
through gpiochip_generic_request() and sets the direction through
pinctrl, which takes the pinctrl mutex.

The PWM core already calls .request and .free with pwm_lock held, so
the spinlock adds nothing there.  Drop it from both callbacks.

Fixes: 757642f9a584 ("gpio: mvebu: Add limited PWM support")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/gpio/gpio-mvebu.c | 36 ++++++++++++++----------------------
 1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index eda52cfaa145..0672528e97dc 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -662,39 +662,31 @@ static int mvebu_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm)
 	struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
 	struct mvebu_gpio_chip *mvchip = mvpwm->mvchip;
 	struct gpio_desc *desc;
-	unsigned long flags;
-	int ret = 0;
 
-	spin_lock_irqsave(&mvpwm->lock, flags);
+	/*
+	 * The PWM core calls .request and .free with pwm_lock held, which
+	 * serialises them; gpiochip_request_own_desc() may sleep, so it must
+	 * not run under mvpwm->lock.
+	 */
+	if (mvpwm->gpiod)
+		return -EBUSY;
 
-	if (mvpwm->gpiod) {
-		ret = -EBUSY;
-	} else {
-		desc = gpiochip_request_own_desc(&mvchip->chip,
-						 pwm->hwpwm, "mvebu-pwm",
-						 GPIO_ACTIVE_HIGH,
-						 GPIOD_OUT_LOW);
-		if (IS_ERR(desc)) {
-			ret = PTR_ERR(desc);
-			goto out;
-		}
+	desc = gpiochip_request_own_desc(&mvchip->chip, pwm->hwpwm, "mvebu-pwm",
+					 GPIO_ACTIVE_HIGH, GPIOD_OUT_LOW);
+	if (IS_ERR(desc))
+		return PTR_ERR(desc);
 
-		mvpwm->gpiod = desc;
-	}
-out:
-	spin_unlock_irqrestore(&mvpwm->lock, flags);
-	return ret;
+	mvpwm->gpiod = desc;
+
+	return 0;
 }
 
 static void mvebu_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm)
 {
 	struct mvebu_pwm *mvpwm = to_mvebu_pwm(chip);
-	unsigned long flags;
 
-	spin_lock_irqsave(&mvpwm->lock, flags);
 	gpiochip_free_own_desc(mvpwm->gpiod);
 	mvpwm->gpiod = NULL;
-	spin_unlock_irqrestore(&mvpwm->lock, flags);
 }
 
 static int mvebu_pwm_get_state(struct pwm_chip *chip,
-- 
2.56.1


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

* [PATCH v2 5/5] gpio: mvebu: report the PWM line's own enable bit
  2026-12-05  3:11 [PATCH v2 0/5] gpio: mvebu: resume, PREEMPT_RT and PWM fixes Rosen Penev
                   ` (3 preceding siblings ...)
  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 ` Rosen Penev
  4 siblings, 0 replies; 7+ messages in thread
From: Rosen Penev @ 2026-12-05  3:11 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Sebastian Andrzej Siewior,
	Clark Williams, Steven Rostedt, Gregory CLEMENT, Rosen Penev,
	Rob Herring, Thierry Reding, Ralph Sennhauser, Andrew Lunn
  Cc: Bartosz Golaszewski, linux-gpio, linux-rt-devel

mvebu_pwm_get_state() reads GPIO_BLINK_EN and reports the PWM as
enabled if any bit in it is set.  The register has one bit per line,
so any blink bit on another line of the bank, for example one left set
by the boot loader, makes a disabled PWM read back as enabled.  The PWM
core uses get_state() to read the initial state of the PWM, so a
consumer then starts from the wrong state.

Check only the bit for this PWM's line.

Fixes: 757642f9a584 ("gpio: mvebu: Add limited PWM support")
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/gpio/gpio-mvebu.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index 0672528e97dc..bfe4721eaa9a 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -720,10 +720,7 @@ static int mvebu_pwm_get_state(struct pwm_chip *chip,
 	state->period = DIV_ROUND_UP_ULL(val * NSEC_PER_SEC, mvpwm->clk_rate);
 
 	regmap_read(mvchip->regs, GPIO_BLINK_EN_OFF + mvchip->offset, &u);
-	if (u)
-		state->enabled = true;
-	else
-		state->enabled = false;
+	state->enabled = !!(u & BIT(pwm->hwpwm));
 
 	spin_unlock_irqrestore(&mvpwm->lock, flags);
 
-- 
2.56.1


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

* Re: [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume
  2026-12-05  3:11 ` [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume Rosen Penev
@ 2026-12-05  3:25   ` sashiko-bot
  0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-12-05  3:25 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-gpio, linux-rt-devel, linux-kernel

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Low] gpio: mvebu: Fixes trailer cites 02af7eac17bc instead of
  b5b7b487431b
--

commit 274be6d5e8aaf9eb8607be44d3ba9ffbf49f09e2
Author: Rosen Penev <rosenp@gmail.com>

> gpio: mvebu: don't re-mask irqs unmasked during early resume
>
> 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>

[Severity: Low]
Should the Fixes trailer point to b5b7b487431b ("gpio: mvebu: add
suspend/resume support") instead of 02af7eac17bc ("gpio: mvebu: keep resume
masks within the irqchip cache")?

mvebu_gpio_resume() has overwritten the mask registers with suspend-time saved
values since b5b7b487431b ("gpio: mvebu: add suspend/resume support"), which
already re-masked lines unmasked during early resume.  Masking the saved value
with the irqchip cache did not change the outcome when the saved bit is 0.

Citing the introducing commit helps stable trees with suspend/resume support
track the fix:

  Fixes: b5b7b487431b ("gpio: mvebu: add suspend/resume support")

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261205031111.12306-1-rosenp@gmail.com?part=3

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

end of thread, other threads:[~2026-12-05  3:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 ` [PATCH v2 3/5] gpio: mvebu: don't re-mask irqs unmasked during early resume Rosen Penev
2026-12-05  3:25   ` 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

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