linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] simplify idle gpio handling for omaps
@ 2019-03-25 22:43 Tony Lindgren
  2019-03-25 22:43 ` [PATCH 1/3] gpio: gpio-omap: limit errata 1.101 handling to wkup domain gpios only Tony Lindgren
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Tony Lindgren @ 2019-03-25 22:43 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: Tero Kristo, Grygorii Strashko, Aaro Koskinen, Keerthy,
	Peter Ujfalusi, linux-gpio, Russell King, linux-omap,
	linux-arm-kernel

Hi all,

Based on some comments from Grygorii I noticed that parts of old 24xx
errata 1.101 handling has become part of the GPIO idle handling over
the years. Here are few patches to clarify and simplify the handling
a bit.

Regards,

Tony


Tony Lindgren (3):
  gpio: gpio-omap: limit errata 1.101 handling to wkup domain gpios only
  gpio: gpio-omap: always scan for triggered non-wakeup capable
    interrupts
  gpio: gpio-omap: add check for off wake capable gpios

 drivers/gpio/gpio-omap.c | 61 ++++++++++++++++++++++------------------
 1 file changed, 33 insertions(+), 28 deletions(-)

-- 
2.21.0

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 1/3] gpio: gpio-omap: limit errata 1.101 handling to wkup domain gpios only
  2019-03-25 22:43 [PATCH 0/3] simplify idle gpio handling for omaps Tony Lindgren
@ 2019-03-25 22:43 ` Tony Lindgren
  2019-03-25 22:43 ` [PATCH 2/3] gpio: gpio-omap: always scan for triggered non-wakeup capable interrupts Tony Lindgren
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Tony Lindgren @ 2019-03-25 22:43 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: Tero Kristo, Grygorii Strashko, Aaro Koskinen, Keerthy,
	Peter Ujfalusi, linux-gpio, Russell King, linux-omap,
	linux-arm-kernel

We need to only apply errata 1.101 handling to clear non-wakeup edge gpios
for idle to the gpio bank(s) in the wkup domain to prevent spurious wake-up
events.

And we must restore what we did after idle manually as the gpio bank in
wkup domain is not restored otherwise.

Let's keep bank->saved_datain register reading separate, that's not related
to the 1.101 errata and is used separately on restore.

Cc: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Keerthy <j-keerthy@ti.com>
Cc: Peter Ujfalusi <peter.ujfalusi@ti.com>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Tero Kristo <t-kristo@ti.com>
Reported-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/gpio/gpio-omap.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -1444,7 +1444,10 @@ static void omap_gpio_restore_context(struct gpio_bank *bank);
 static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
 {
 	struct device *dev = bank->chip.parent;
-	u32 l1 = 0, l2 = 0;
+	void __iomem *base = bank->base;
+	u32 nowake;
+
+	bank->saved_datain = readl_relaxed(base + bank->regs->datain);
 
 	if (bank->funcs.idle_enable_level_quirk)
 		bank->funcs.idle_enable_level_quirk(bank);
@@ -1456,20 +1459,15 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
 		goto update_gpio_context_count;
 
 	/*
-	 * If going to OFF, remove triggering for all
+	 * If going to OFF, remove triggering for all wkup domain
 	 * non-wakeup GPIOs.  Otherwise spurious IRQs will be
 	 * generated.  See OMAP2420 Errata item 1.101.
 	 */
-	bank->saved_datain = readl_relaxed(bank->base +
-						bank->regs->datain);
-	l1 = bank->context.fallingdetect;
-	l2 = bank->context.risingdetect;
-
-	l1 &= ~bank->enabled_non_wakeup_gpios;
-	l2 &= ~bank->enabled_non_wakeup_gpios;
-
-	writel_relaxed(l1, bank->base + bank->regs->fallingdetect);
-	writel_relaxed(l2, bank->base + bank->regs->risingdetect);
+	if (!bank->loses_context && bank->enabled_non_wakeup_gpios) {
+		nowake = bank->enabled_non_wakeup_gpios;
+		omap_gpio_rmw(base, bank->regs->fallingdetect, nowake, ~nowake);
+		omap_gpio_rmw(base, bank->regs->risingdetect, nowake, ~nowake);
+	}
 
 	bank->workaround_enabled = true;
 
@@ -1518,6 +1516,12 @@ static void omap_gpio_unidle(struct gpio_bank *bank)
 				return;
 			}
 		}
+	} else {
+		/* Restore changes done for OMAP2420 errata 1.101 */
+		writel_relaxed(bank->context.fallingdetect,
+			       bank->base + bank->regs->fallingdetect);
+		writel_relaxed(bank->context.risingdetect,
+			       bank->base + bank->regs->risingdetect);
 	}
 
 	if (!bank->workaround_enabled)
-- 
2.21.0

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 2/3] gpio: gpio-omap: always scan for triggered non-wakeup capable interrupts
  2019-03-25 22:43 [PATCH 0/3] simplify idle gpio handling for omaps Tony Lindgren
  2019-03-25 22:43 ` [PATCH 1/3] gpio: gpio-omap: limit errata 1.101 handling to wkup domain gpios only Tony Lindgren
@ 2019-03-25 22:43 ` Tony Lindgren
  2019-03-25 22:43 ` [PATCH 3/3] gpio: gpio-omap: add check for off wake capable gpios Tony Lindgren
  2019-03-27 13:29 ` [PATCH 0/3] simplify idle gpio handling for omaps Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Tony Lindgren @ 2019-03-25 22:43 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: Tero Kristo, Grygorii Strashko, Aaro Koskinen, Keerthy,
	Peter Ujfalusi, linux-gpio, Russell King, linux-omap,
	linux-arm-kernel

The bank->workaround_enabled should be for omap24xx erratum 1.101 but is not
needed any longer as erratum 1.101 handling only needs to happen based on
!bank->loses_context with patch "gpio: omap: Limit errata 1.101 handling to
wkup domain gpios only".

Further Grygorii Strashko <grygorii.strashko@ti.com> points out that we are
now tagging all edge GPIOs as non-wakeup GPIOs and rely on original erratum
1.101 handling for scacnning for edge interrupts that have triggered during
idle.

Also the TI Android kernel tree has an earlier commit "GPIO: OMAP: Always
scan gpios during runtime resume" by Tero Kristo <t-kristo@ti.com> saying:

 "This allows the driver to generate interrupts for GPIOs that can't
  wakeup but have changed state during runtime suspend. We cannot
  depend on the decision based on no need to restore, as the system
  state might change and pending events could gather up."

So let's remove bank->workaround_enabled and always scan for triggered edge
interrupts on resume. We do that based on bank->enabled_non_wakeup_gpios.

Cc: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Keerthy <j-keerthy@ti.com>
Cc: Peter Ujfalusi <peter.ujfalusi@ti.com>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Tero Kristo <t-kristo@ti.com>
Reported-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/gpio/gpio-omap.c | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -83,7 +83,6 @@ struct gpio_bank {
 	int stride;
 	u32 width;
 	int context_loss_count;
-	bool workaround_enabled;
 	u32 quirks;
 
 	void (*set_dataout)(struct gpio_bank *bank, unsigned gpio, int enable);
@@ -1469,8 +1468,6 @@ static void omap_gpio_idle(struct gpio_bank *bank, bool may_lose_context)
 		omap_gpio_rmw(base, bank->regs->risingdetect, nowake, ~nowake);
 	}
 
-	bank->workaround_enabled = true;
-
 update_gpio_context_count:
 	if (bank->get_context_loss_count)
 		bank->context_loss_count =
@@ -1524,9 +1521,6 @@ static void omap_gpio_unidle(struct gpio_bank *bank)
 			       bank->base + bank->regs->risingdetect);
 	}
 
-	if (!bank->workaround_enabled)
-		return;
-
 	l = readl_relaxed(bank->base + bank->regs->datain);
 
 	/*
@@ -1576,8 +1570,6 @@ static void omap_gpio_unidle(struct gpio_bank *bank)
 		writel_relaxed(old0, bank->base + bank->regs->leveldetect0);
 		writel_relaxed(old1, bank->base + bank->regs->leveldetect1);
 	}
-
-	bank->workaround_enabled = false;
 }
 
 static void omap_gpio_init_context(struct gpio_bank *p)
-- 
2.21.0

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* [PATCH 3/3] gpio: gpio-omap: add check for off wake capable gpios
  2019-03-25 22:43 [PATCH 0/3] simplify idle gpio handling for omaps Tony Lindgren
  2019-03-25 22:43 ` [PATCH 1/3] gpio: gpio-omap: limit errata 1.101 handling to wkup domain gpios only Tony Lindgren
  2019-03-25 22:43 ` [PATCH 2/3] gpio: gpio-omap: always scan for triggered non-wakeup capable interrupts Tony Lindgren
@ 2019-03-25 22:43 ` Tony Lindgren
  2019-03-27 13:29 ` [PATCH 0/3] simplify idle gpio handling for omaps Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Tony Lindgren @ 2019-03-25 22:43 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: Tero Kristo, Grygorii Strashko, Aaro Koskinen, Keerthy,
	Peter Ujfalusi, linux-gpio, Russell King, linux-omap,
	linux-arm-kernel

We are currently assuming all GPIOs are non-wakeup capable GPIOs as we
not configuring the bank->non_wakeup_gpios like we used to earlier with
platform_data.

Let's add omap_gpio_is_off_wakeup_capable() to make the handling clearer
while considering that later patches may want to configure SoC specific
bank->non_wakeup_gpios for the GPIOs in wakeup domain.

Cc: Aaro Koskinen <aaro.koskinen@iki.fi>
Cc: Grygorii Strashko <grygorii.strashko@ti.com>
Cc: Keerthy <j-keerthy@ti.com>
Cc: Peter Ujfalusi <peter.ujfalusi@ti.com>
Cc: Russell King <rmk+kernel@armlinux.org.uk>
Cc: Tero Kristo <t-kristo@ti.com>
Reported-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/gpio/gpio-omap.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/gpio/gpio-omap.c b/drivers/gpio/gpio-omap.c
--- a/drivers/gpio/gpio-omap.c
+++ b/drivers/gpio/gpio-omap.c
@@ -352,6 +352,22 @@ static void omap_clear_gpio_debounce(struct gpio_bank *bank, unsigned offset)
 	}
 }
 
+/*
+ * Off mode wake-up capable GPIOs in bank(s) that are in the wakeup domain.
+ * See TRM section for GPIO for "Wake-Up Generation" for the list of GPIOs
+ * in wakeup domain. If bank->non_wakeup_gpios is not configured, assume none
+ * are capable waking up the system from off mode.
+ */
+static bool omap_gpio_is_off_wakeup_capable(struct gpio_bank *bank, u32 gpio_mask)
+{
+	u32 no_wake = bank->non_wakeup_gpios;
+
+	if (no_wake)
+		return !!(~no_wake & gpio_mask);
+
+	return false;
+}
+
 static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
 						unsigned trigger)
 {
@@ -383,13 +399,7 @@ static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
 	}
 
 	/* This part needs to be executed always for OMAP{34xx, 44xx} */
-	if (!bank->regs->irqctrl) {
-		/* On omap24xx proceed only when valid GPIO bit is set */
-		if (bank->non_wakeup_gpios) {
-			if (!(bank->non_wakeup_gpios & gpio_bit))
-				goto exit;
-		}
-
+	if (!bank->regs->irqctrl && !omap_gpio_is_off_wakeup_capable(bank, gpio)) {
 		/*
 		 * Log the edge gpio and manually trigger the IRQ
 		 * after resume if the input level changes
@@ -402,7 +412,6 @@ static inline void omap_set_gpio_trigger(struct gpio_bank *bank, int gpio,
 			bank->enabled_non_wakeup_gpios &= ~gpio_bit;
 	}
 
-exit:
 	bank->level_mask =
 		readl_relaxed(bank->base + bank->regs->leveldetect0) |
 		readl_relaxed(bank->base + bank->regs->leveldetect1);
-- 
2.21.0

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

* Re: [PATCH 0/3] simplify idle gpio handling for omaps
  2019-03-25 22:43 [PATCH 0/3] simplify idle gpio handling for omaps Tony Lindgren
                   ` (2 preceding siblings ...)
  2019-03-25 22:43 ` [PATCH 3/3] gpio: gpio-omap: add check for off wake capable gpios Tony Lindgren
@ 2019-03-27 13:29 ` Bartosz Golaszewski
  3 siblings, 0 replies; 5+ messages in thread
From: Bartosz Golaszewski @ 2019-03-27 13:29 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Tero Kristo, Grygorii Strashko, Aaro Koskinen, Keerthy,
	Linus Walleij, Peter Ujfalusi, linux-gpio, Russell King,
	Linux-OMAP, arm-soc

pon., 25 mar 2019 o 23:43 Tony Lindgren <tony@atomide.com> napisał(a):
>
> Hi all,
>
> Based on some comments from Grygorii I noticed that parts of old 24xx
> errata 1.101 handling has become part of the GPIO idle handling over
> the years. Here are few patches to clarify and simplify the handling
> a bit.
>
> Regards,
>
> Tony
>
>
> Tony Lindgren (3):
>   gpio: gpio-omap: limit errata 1.101 handling to wkup domain gpios only
>   gpio: gpio-omap: always scan for triggered non-wakeup capable
>     interrupts
>   gpio: gpio-omap: add check for off wake capable gpios
>
>  drivers/gpio/gpio-omap.c | 61 ++++++++++++++++++++++------------------
>  1 file changed, 33 insertions(+), 28 deletions(-)
>
> --
> 2.21.0

All three applied.

Bart

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

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

end of thread, other threads:[~2019-03-27 13:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-25 22:43 [PATCH 0/3] simplify idle gpio handling for omaps Tony Lindgren
2019-03-25 22:43 ` [PATCH 1/3] gpio: gpio-omap: limit errata 1.101 handling to wkup domain gpios only Tony Lindgren
2019-03-25 22:43 ` [PATCH 2/3] gpio: gpio-omap: always scan for triggered non-wakeup capable interrupts Tony Lindgren
2019-03-25 22:43 ` [PATCH 3/3] gpio: gpio-omap: add check for off wake capable gpios Tony Lindgren
2019-03-27 13:29 ` [PATCH 0/3] simplify idle gpio handling for omaps Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).