Skip to contentSkip to conversation

gpio: gpio-omap: Fix lost edge wake-up interrupts

PATCH Superseded Tony Lindgren 1 participant 3 messages May 8, 2019 – May 9, 2019

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: gpio-omap: Fix lost edge wake-up interrupts

If an edge interrupt triggers while entering idle just before we save GPIO datain register to saved_datain, the triggered GPIO will not be noticed on wake-up. This is because the saved_datain and GPIO datain are the same. Let's fix this by ignoring any pending edge interrupts in saved_datain.

This can be somewhat easily reproduced by pinging an idle system with smsc911x Ethernet interface configured IRQ_TYPE_EDGE_FALLING. At some point the smsc911x interrupts will just stop triggering.

Note that in the long run we may be able to cancel entering idle by returning an error in gpio_omap_cpu_notifier(). But let's fix the bug first.

Also note that because of the recent clean-up efforts this patch does not apply directly to older kernels. This does fix a long term issue though, and can be backported as needed.

Cc Aaro Koskinen <[email protected]>
Cc Grygorii Strashko <[email protected]>
Cc Keerthy <[email protected]>
Cc Ladislav Michl <[email protected]>
Cc Peter Ujfalusi <[email protected]>
Cc Russell King <[email protected]>
Cc Tero Kristo <[email protected]>
---
 drivers/gpio/gpio-omap.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpio/gpio-omap.c +7 -0
@@ -1279,7 +1279,14 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
 	void __iomem *base = bank->base;
 	u32 nowake;
 
+	/*
+	 * Save datain register to trigger edge interrupts on unidle for GPIOS
+	 * that are not wake-up capable. Ignore any enabled_non_wakeup_gpios
+	 * that may have just triggered as we're entering idle. Otherwise unidle
+	 * will not notice them.
+	 */
 	bank->saved_datain = readl_relaxed(base + bank->regs->datain);
+	bank->saved_datain |= bank->enabled_non_wakeup_gpios;
 
 	if (!bank->enabled_non_wakeup_gpios)
 		goto update_gpio_context_count;
Signature · 1 line
2.21.0
#1 lore raw
Quoted 4 lines · Tony Lindgren
drivers/gpio/gpio-omap.c +0 -0
@@ -1279,7 +1279,14 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
 	void __iomem *base = bank->base;

drivers/gpio/gpio-omap.c static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context) · line 1289

Quoted 10 lines
drivers/gpio/gpio-omap.c +7 -0
 	u32 nowake;
 
+	/*
+	 * Save datain register to trigger edge interrupts on unidle for GPIOS
+	 * that are not wake-up capable. Ignore any enabled_non_wakeup_gpios
+	 * that may have just triggered as we're entering idle. Otherwise unidle
+	 * will not notice them.
+	 */
 	bank->saved_datain = readl_relaxed(base + bank->regs->datain);
+	bank->saved_datain |= bank->enabled_non_wakeup_gpios;

Oops, sorry this is not complete yet. We need to enable or clear the possible pending interrupt in saved_datain based on the edge interrupt polarity. I'll fix and resend.

Regards,

Tony

#2 lore raw
Quoted 7 lines · Tony Lindgren
Quoted 6 lines · Tony Lindgren
drivers/gpio/gpio-omap.c +0 -0
@@ -1279,7 +1279,14 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
 	void __iomem *base = bank->base;
 	u32 nowake;
 
Quoted 12 lines

drivers/gpio/gpio-omap.c static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context) · line 1289

Quoted 8 lines
drivers/gpio/gpio-omap.c +7 -0
+	/*
+	 * Save datain register to trigger edge interrupts on unidle for GPIOS
+	 * that are not wake-up capable. Ignore any enabled_non_wakeup_gpios
+	 * that may have just triggered as we're entering idle. Otherwise unidle
+	 * will not notice them.
+	 */
 	bank->saved_datain = readl_relaxed(base + bank->regs->datain);
+	bank->saved_datain |= bank->enabled_non_wakeup_gpios;

Oops, sorry this is not complete yet. We need to enable or clear the possible pending interrupt in saved_datain based on the edge interrupt polarity. I'll fix and resend.

Below seems to behave for me based on light testing.. Might be worth thinking about this a bit more, anybody got better ideas? :)

Regards,

Tony

8< --------------------

drivers/gpio/gpio-omap.c +15 -1
@@ -1277,10 +1277,24 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
 {
 	struct device *dev = bank->chip.parent;
 	void __iomem *base = bank->base;
-	u32 nowake;
+	u32 mask, nowake;
 
+	/*
+	 * Save datain register to trigger edge interrupts on unidle for GPIOS
+	 * that are not wake-up capable. Ignore any enabled_non_wakeup_gpios
+	 * that may have just triggered as we're entering idle. Otherwise unidle
+	 * will not notice them. Note that this does not help with EDGE_BOTH.
+	 */
 	bank->saved_datain = readl_relaxed(base + bank->regs->datain);
 
+	mask = bank->enabled_non_wakeup_gpios & bank->context.fallingdetect;
+	mask &= ~bank->context.risingdetect;
+	bank->saved_datain |= mask;
+
+	mask = bank->enabled_non_wakeup_gpios & bank->context.risingdetect;
+	mask &= ~bank->context.fallingdetect;
+	bank->saved_datain &= ~mask;
+
 	if (!bank->enabled_non_wakeup_gpios)
 		goto update_gpio_context_count;
 
Signature · 1 line
2.21.0