gpio: gpio-omap: fix level interrupt idling
Subsystems (2)
PATCH 1/1 gpio: gpio-omap: fix level interrupt idling
From: Russell King <[email protected]>
Tony notes that the GPIO module does not idle when level interrupts are in use, as the wakeup appears to get stuck.
After extensive investigation, it appears that the wakeup will only be cleared if the interrupt status register is cleared while the interrupt is enabled. However, we are currently clearing it with the interrupt disabled for level-based interrupts.
It is acknowledged that this observed behaviour conflicts with a statement in the TRM:
CAUTION
After servicing the interrupt, the status bit in the interrupt status register (GPIOi.GPIO_IRQSTATUS_0 or GPIOi.GPIO_IRQSTATUS_1) must be reset and the interrupt line released (by setting the corresponding bit of the interrupt status register to 1) before enabling an interrupt for the GPIO channel in the interrupt-enable register (GPIOi.GPIO_IRQSTATUS_SET_0 or GPIOi.GPIO_IRQSTATUS_SET_1) to prevent the occurrence of unexpected interrupts when enabling an interrupt for the GPIO channel.
However, this does not appear to be a practical problem.
Further, as reported by Grygorii Strashko <[email protected]>, the TI Android kernel tree has an earlier similar patch as "GPIO: OMAP:
Fix the sequence to clear the IRQ status" saying:
if the status is cleared after disabling the IRQ then sWAKEUP will not be cleared and gates the module transition
When we unmask the level interrupt after the interrupt has been handled, enable the interrupt and only then clear the interrupt. If the interrupt is still pending, the hardware will re-assert the interrupt status.
Should the caution note in the TRM prove to be a problem, we could use a clear-enable-clear sequence instead.
---
Obviously no rush to get this into v5.0-rc cycle, but this should be tagged with Cc stable after people have reviewed and tested this.
--- drivers/gpio/gpio-omap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/gpio/gpio-omap.c +8 -6
@@ -883,14 +883,16 @@ static void omap_gpio_unmask_irq(struct irq_data *d)if (trigger)omap_set_gpio_triggering (bank, offset, trigger); -/* For level-triggered GPIOs, the clearing must be done after -* the HW source is cleared, thus after the handler has run */ -if (bank->level_mask &BIT (offset)) { -omap_set_gpio_irqenable (bank, offset,0 ); +omap_set_gpio_irqenable (bank, offset,1 ); + +/* +* For level-triggered GPIOs, clearing must be done after the source +* is cleared, thus after the handler has run. OMAP4 needs this done +* after enabing the interrupt to clear the wakeup status. +*/ +if (bank->level_mask &BIT (offset))omap_clear_gpio_irqstatus (bank, offset); - } -omap_set_gpio_irqenable (bank, offset,1 );raw_spin_unlock_irqrestore (&bank->lock, flags); }
Signature · 1 line
2.21.0
Quoted 46 lines · Tony Lindgren
From: Russell King <[email protected]>
Tony notes that the GPIO module does not idle when level interrupts are in use, as the wakeup appears to get stuck.
After extensive investigation, it appears that the wakeup will only be cleared if the interrupt status register is cleared while the interrupt is enabled. However, we are currently clearing it with the interrupt disabled for level-based interrupts.
It is acknowledged that this observed behaviour conflicts with a statement in the TRM:
CAUTION
After servicing the interrupt, the status bit in the interrupt status register (GPIOi.GPIO_IRQSTATUS_0 or GPIOi.GPIO_IRQSTATUS_1) must be reset and the interrupt line released (by setting the corresponding bit of the interrupt status register to 1) before enabling an interrupt for the GPIO channel in the interrupt-enable register (GPIOi.GPIO_IRQSTATUS_SET_0 or GPIOi.GPIO_IRQSTATUS_SET_1) to prevent the occurrence of unexpected interrupts when enabling an interrupt for the GPIO channel.However, this does not appear to be a practical problem.
Further, as reported by Grygorii Strashko <[email protected]>, the TI Android kernel tree has an earlier similar patch as "GPIO: OMAP:
Fix the sequence to clear the IRQ status" saying:if the status is cleared after disabling the IRQ then sWAKEUP will not be cleared and gates the module transition
When we unmask the level interrupt after the interrupt has been handled, enable the interrupt and only then clear the interrupt. If the interrupt is still pending, the hardware will re-assert the interrupt status.
Should the caution note in the TRM prove to be a problem, we could use a clear-enable-clear sequence instead.
Cc Aaro Koskinen <[email protected]>Cc Grygorii Strashko <[email protected]>Cc Keerthy <[email protected]>Cc Peter Ujfalusi <[email protected]>Signed-off-by Russell King <[email protected]>[[email protected]: updated comments based on an earlier TI patch]Signed-off-by Tony Lindgren <[email protected]>
Quoted 9 lines
---
Obviously no rush to get this into v5.0-rc cycle, but this should be tagged with Cc stable after people have reviewed and tested this.
--- drivers/gpio/gpio-omap.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
Thank you.
Signature · 2 lines
Best regards, grygorii
Quoted 39 lines · Tony Lindgren
From: Russell King <[email protected]>
Tony notes that the GPIO module does not idle when level interrupts are in use, as the wakeup appears to get stuck.
After extensive investigation, it appears that the wakeup will only be cleared if the interrupt status register is cleared while the interrupt is enabled. However, we are currently clearing it with the interrupt disabled for level-based interrupts.
It is acknowledged that this observed behaviour conflicts with a statement in the TRM:
CAUTION
After servicing the interrupt, the status bit in the interrupt status register (GPIOi.GPIO_IRQSTATUS_0 or GPIOi.GPIO_IRQSTATUS_1) must be reset and the interrupt line released (by setting the corresponding bit of the interrupt status register to 1) before enabling an interrupt for the GPIO channel in the interrupt-enable register (GPIOi.GPIO_IRQSTATUS_SET_0 or GPIOi.GPIO_IRQSTATUS_SET_1) to prevent the occurrence of unexpected interrupts when enabling an interrupt for the GPIO channel.However, this does not appear to be a practical problem.
Further, as reported by Grygorii Strashko <[email protected]>, the TI Android kernel tree has an earlier similar patch as "GPIO: OMAP:
Fix the sequence to clear the IRQ status" saying:if the status is cleared after disabling the IRQ then sWAKEUP will not be cleared and gates the module transition
When we unmask the level interrupt after the interrupt has been handled, enable the interrupt and only then clear the interrupt. If the interrupt is still pending, the hardware will re-assert the interrupt status.
Should the caution note in the TRM prove to be a problem, we could use a clear-enable-clear sequence instead.
Quoted 7 lines
Cc Aaro Koskinen <[email protected]>Cc Grygorii Strashko <[email protected]>Cc Keerthy <[email protected]>Cc Peter Ujfalusi <[email protected]>Signed-off-by Russell King <[email protected]>[[email protected]: updated comments based on an earlier TI patch]Signed-off-by Tony Lindgren <[email protected]>
Patch applied! Really nice debugging here.
Yours,
Linus Walleij