linux-sh.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: rcar: Fix level interrupt handling
@ 2013-11-29 13:32 Valentine Barshak
  2013-11-29 15:00 ` Laurent Pinchart
  0 siblings, 1 reply; 9+ messages in thread
From: Valentine Barshak @ 2013-11-29 13:32 UTC (permalink / raw)
  To: linux-sh, linux-gpio
  Cc: Simon Horman, Magnus Damm, Laurent Pinchart, Linus Walleij

According to the manual, if a port is set for level detection using
the corresponding bit in the edge/level select register and an external
level interrupt signal is asserted, the corresponding bit in INTDT
does not use the FF to hold the input.
Thus, writing 1 to the corresponding bits in INTCLR cannot clear the
corresponding bits in the INTDT register. Instead, when an external
input signal is stopped, the corresponding bit in INTDT is cleared
automatically.

Since the INTDT bit cannot be cleared for the level interrupts until
the interrupt signal is stopped, we end up with the infinite loop
when using deferred (threaded) IRQ handling.

Workaround the issue by dropping level interrupts from the pending
mask once the interrupt is handled. If the IRQ is not cleared by the
handler, it will be invoked again when the interrupt is re-enabled.

Signed-off-by: Valentine Barshak <valentine.barshak@cogentembedded.com>
---
 drivers/gpio/gpio-rcar.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
index d3f15ae..918a1de 100644
--- a/drivers/gpio/gpio-rcar.c
+++ b/drivers/gpio/gpio-rcar.c
@@ -166,12 +166,18 @@ static int gpio_rcar_irq_set_type(struct irq_data *d, unsigned int type)
 static irqreturn_t gpio_rcar_irq_handler(int irq, void *dev_id)
 {
 	struct gpio_rcar_priv *p = dev_id;
-	u32 pending;
+	u32 pending, mask = 0;
 	unsigned int offset, irqs_handled = 0;
 
-	while ((pending = gpio_rcar_read(p, INTDT))) {
+	/*
+	 * Level interrupts cannot be cleared in the INTDT,
+	 * so we just drop them from the pending mask when
+	 * the interrupt is handled.
+	 */
+	while ((pending = gpio_rcar_read(p, INTDT) & ~mask)) {
 		offset = __ffs(pending);
 		gpio_rcar_write(p, INTCLR, BIT(offset));
+		mask |= BIT(offset) & ~gpio_rcar_read(p, EDGLEVEL);
 		generic_handle_irq(irq_find_mapping(p->irq_domain, offset));
 		irqs_handled++;
 	}
-- 
1.8.3.1


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

end of thread, other threads:[~2013-11-29 19:42 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-11-29 13:32 [PATCH] gpio: rcar: Fix level interrupt handling Valentine Barshak
2013-11-29 15:00 ` Laurent Pinchart
2013-11-29 15:15   ` Valentine
2013-11-29 15:39     ` Laurent Pinchart
2013-11-29 17:36       ` Valentine
2013-11-29 18:06         ` Laurent Pinchart
2013-11-29 18:26           ` Valentine
2013-11-29 19:22             ` Laurent Pinchart
2013-11-29 19:42               ` Valentine

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).