[PATCH 2/2] regmap-irq: Introduce ack_after_handle option

Maxim Kochetkov posted 2 patches 4 days, 9 hours ago
[PATCH 2/2] regmap-irq: Introduce ack_after_handle option
Posted by Maxim Kochetkov 4 days, 9 hours 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 c097f8ca17b7..2400d2efb1e9 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 fd41baccbf3e..1d31e066ae59 100644
--- a/include/linux/regmap.h
+++ b/include/linux/regmap.h
@@ -1581,6 +1581,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
@@ -1644,6 +1645,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