[PATCH v4 04/14] iio: accel: adxl345: introduce adxl345_push_event function

From: Lothar Rubusch
Date: Thu Mar 13 2025 - 12:51:50 EST


Move the fifo handling into a separate function. This is a preparation
for a generic handling of the interrupt status register results.

The interrupt status register is read into a variable int_stat. It carries
status for various sensor events, handling of which is added in follow up
patches. Evaluation of the int_stat variable is common for sensor events,
such as tap detection, freefall, activity,... and for fifo events, such as
data ready, overrun, watermark,... Also, dealing with in case error
returns shall be common to all events. Thus migrate fifo read-out and push
fifo content to iio channels into this function to be built up with
additional event handling.

Signed-off-by: Lothar Rubusch <l.rubusch@xxxxxxxxx>
---
drivers/iio/accel/adxl345_core.c | 29 ++++++++++++++++++++---------
1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/accel/adxl345_core.c b/drivers/iio/accel/adxl345_core.c
index eec3f0e17e1e..d4c1a6f1559f 100644
--- a/drivers/iio/accel/adxl345_core.c
+++ b/drivers/iio/accel/adxl345_core.c
@@ -420,6 +420,24 @@ static int adxl345_fifo_push(struct iio_dev *indio_dev,
return 0;
}

+static int adxl345_push_event(struct iio_dev *indio_dev, int int_stat)
+{
+ struct adxl345_state *st = iio_priv(indio_dev);
+ int samples;
+ int ret = -ENOENT;
+
+ if (FIELD_GET(ADXL345_INT_WATERMARK, int_stat)) {
+ samples = adxl345_get_samples(st);
+ if (samples < 0)
+ return -EINVAL;
+
+ if (adxl345_fifo_push(indio_dev, samples) < 0)
+ return -EINVAL;
+ }
+
+ return ret;
+}
+
/**
* adxl345_irq_handler() - Handle irqs of the ADXL345.
* @irq: The irq being handled.
@@ -432,19 +450,12 @@ static irqreturn_t adxl345_irq_handler(int irq, void *p)
struct iio_dev *indio_dev = p;
struct adxl345_state *st = iio_priv(indio_dev);
int int_stat;
- int samples;

if (regmap_read(st->regmap, ADXL345_REG_INT_SOURCE, &int_stat))
return IRQ_NONE;

- if (FIELD_GET(ADXL345_INT_WATERMARK, int_stat)) {
- samples = adxl345_get_samples(st);
- if (samples < 0)
- goto err;
-
- if (adxl345_fifo_push(indio_dev, samples) < 0)
- goto err;
- }
+ if (adxl345_push_event(indio_dev, int_stat))
+ goto err;

if (FIELD_GET(ADXL345_INT_OVERRUN, int_stat))
goto err;
--
2.39.5