simplify idle gpio handling for omaps
Subsystems (2)
cover simplify idle gpio handling for omaps
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(-)
Signature · 1 line
2.21.0
PATCH 1/3 gpio: gpio-omap: limit errata 1.101 handling to wkup domain gpios only
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.
--- drivers/gpio/gpio-omap.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-)
drivers/gpio/gpio-omap.c +16 -12
@@ -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)
Signature · 1 line
2.21.0
PATCH 2/3 gpio: gpio-omap: always scan for triggered non-wakeup capable interrupts
In reply to Tony LindgrenThe 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 <[email protected]> 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 <[email protected]> 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.
--- drivers/gpio/gpio-omap.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/gpio/gpio-omap.c +0 -8
@@ -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)
Signature · 1 line
2.21.0
PATCH 3/3 gpio: gpio-omap: add check for off wake capable gpios
In reply to Tony LindgrenWe 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.
--- drivers/gpio/gpio-omap.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-)
drivers/gpio/gpio-omap.c +17 -8
@@ -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);
Signature · 1 line
2.21.0
pon., 25 mar 2019 o 23:43 Tony Lindgren <[email protected]> napisał(a):
Quoted 19 lines
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
Quoted 5 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel