[PATCH 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler

Francesco Lavra posted 2 patches 1 month ago
[PATCH 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler
Posted by Francesco Lavra 1 month ago
In order to minimize the time required for transferring FIFO data from the
sensor to the host machine, perform the read from the FIFO in a single call
to regmap_bulk_read().
This allows reading acceleration data for all 3 axes at 16 kHz
sampling frequency using a 1MHz I2C bus frequency.

Signed-off-by: Francesco Lavra <flavra@baylibre.com>
---
 drivers/iio/accel/adxl380.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/drivers/iio/accel/adxl380.c b/drivers/iio/accel/adxl380.c
index 9f6c0e02575a..ce3643c5deb8 100644
--- a/drivers/iio/accel/adxl380.c
+++ b/drivers/iio/accel/adxl380.c
@@ -950,14 +950,12 @@ static irqreturn_t adxl380_irq_handler(int irq, void  *p)
 		return IRQ_HANDLED;
 
 	fifo_entries = rounddown(fifo_entries, st->fifo_set_size);
-	for (i = 0; i < fifo_entries; i += st->fifo_set_size) {
-		ret = regmap_noinc_read(st->regmap, ADXL380_FIFO_DATA,
-					&st->fifo_buf[i],
-					2 * st->fifo_set_size);
-		if (ret)
-			return IRQ_HANDLED;
+	ret = regmap_noinc_read(st->regmap, ADXL380_FIFO_DATA,
+				&st->fifo_buf, 2 * fifo_entries);
+	if (ret)
+		return IRQ_HANDLED;
+	for (i = 0; i < fifo_entries; i += st->fifo_set_size)
 		iio_push_to_buffers(indio_dev, &st->fifo_buf[i]);
-	}
 
 	return IRQ_HANDLED;
 }
-- 
2.39.5
Re: [PATCH 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler
Posted by Jonathan Cameron 4 weeks ago
On Tue,  6 Jan 2026 20:36:27 +0100
Francesco Lavra <flavra@baylibre.com> wrote:

> In order to minimize the time required for transferring FIFO data from the
> sensor to the host machine, perform the read from the FIFO in a single call
> to regmap_bulk_read().
> This allows reading acceleration data for all 3 axes at 16 kHz
> sampling frequency using a 1MHz I2C bus frequency.
> 
> Signed-off-by: Francesco Lavra <flavra@baylibre.com>
> ---
>  drivers/iio/accel/adxl380.c | 12 +++++-------
>  1 file changed, 5 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/iio/accel/adxl380.c b/drivers/iio/accel/adxl380.c
> index 9f6c0e02575a..ce3643c5deb8 100644
> --- a/drivers/iio/accel/adxl380.c
> +++ b/drivers/iio/accel/adxl380.c
> @@ -950,14 +950,12 @@ static irqreturn_t adxl380_irq_handler(int irq, void  *p)
>  		return IRQ_HANDLED;
>  
>  	fifo_entries = rounddown(fifo_entries, st->fifo_set_size);
> -	for (i = 0; i < fifo_entries; i += st->fifo_set_size) {
> -		ret = regmap_noinc_read(st->regmap, ADXL380_FIFO_DATA,
> -					&st->fifo_buf[i],
> -					2 * st->fifo_set_size);
> -		if (ret)
> -			return IRQ_HANDLED;
> +	ret = regmap_noinc_read(st->regmap, ADXL380_FIFO_DATA,
> +				&st->fifo_buf, 2 * fifo_entries);

Whilst we are here can we replace that 2 with sizeof(*st->fifo_buf)?

Otherwise, Antoniu, can you take a look at these change.
Seem reasonable to me.  Given we are fairly late in the cycle I'll
probably merge them both for the next merge window and we'll have
to wait until after that for the fix to make it to stable.

Jonathan


> +	if (ret)
> +		return IRQ_HANDLED;
> +	for (i = 0; i < fifo_entries; i += st->fifo_set_size)
>  		iio_push_to_buffers(indio_dev, &st->fifo_buf[i]);
> -	}
>  
>  	return IRQ_HANDLED;
>  }