[PATCH] regmap-irq: Introduce ack_after_handle option

Maxim Kochetkov posted 1 patch 3 weeks, 1 day ago
drivers/base/regmap/regmap-irq.c | 8 +++++++-
include/linux/regmap.h           | 2 ++
2 files changed, 9 insertions(+), 1 deletion(-)
[PATCH] regmap-irq: Introduce ack_after_handle option
Posted by Maxim Kochetkov 3 weeks, 1 day ago
Some interrupt controllers may have simple level interrupt detection
without enable/disable functionality. Mask/unmask simply disables
interrupt signaling to the upstream chip. If we try to ack these
interrupts before handling, we will get a false interrupt with empty
status. So the only one possible way to handle this interrupts is
to ack them after handling.

Signed-off-by: Maxim Kochetkov <fido_max@inbox.ru>
---
 drivers/base/regmap/regmap-irq.c | 8 +++++++-
 include/linux/regmap.h           | 2 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/base/regmap/regmap-irq.c b/drivers/base/regmap/regmap-irq.c
index 7dcd2118b4d2..8ad6486fc3bd 100644
--- a/drivers/base/regmap/regmap-irq.c
+++ b/drivers/base/regmap/regmap-irq.c
@@ -479,7 +479,7 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 	for (i = 0; i < data->chip->num_regs; i++) {
 		data->status_buf[i] &= ~data->mask_buf[i];
 
-		if (data->status_buf[i])
+		if (!chip->ack_after_handle && data->status_buf[i])
 			regmap_irq_ack(data, data->status_buf[i], i);
 	}
 
@@ -491,6 +491,12 @@ static irqreturn_t regmap_irq_thread(int irq, void *d)
 		}
 	}
 
+	if (chip->ack_after_handle)
+		for (i = 0; i < data->chip->num_regs; i++) {
+			if (data->status_buf[i])
+				regmap_irq_ack(data, data->status_buf[i], i);
+		}
+
 exit:
 	if (chip->handle_post_irq)
 		chip->handle_post_irq(chip->irq_drv_data);
diff --git a/include/linux/regmap.h b/include/linux/regmap.h
index 570aa9d797b4..a6c94d2ba548 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1572,6 +1572,7 @@ struct regmap_irq_chip_data;
  * @use_ack:     Use @ack register even if it is zero.
  * @ack_invert:  Inverted ack register: cleared bits for ack.
  * @clear_ack:  Use this to set 1 and 0 or vice-versa to clear interrupts.
+ * @ack_after_handle: Use this to ack interrupts after handling.
  * @status_invert: Inverted status register: cleared bits are active interrupts.
  * @wake_invert: Inverted wake register: cleared bits are wake enabled.
  * @type_in_mask: Use the mask registers for controlling irq type. Use this if
@@ -1635,6 +1636,7 @@ struct regmap_irq_chip {
 	unsigned int use_ack:1;
 	unsigned int ack_invert:1;
 	unsigned int clear_ack:1;
+	unsigned int ack_after_handle:1;
 	unsigned int status_invert:1;
 	unsigned int wake_invert:1;
 	unsigned int type_in_mask:1;
-- 
2.45.2