Skip to contentSkip to conversation

accel: adxl380: Improve data reading from FIFO

PATCH In review Francesco Lavra 3 participants 9 messages Jan 19 – Jan 23

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

v2 cover accel: adxl380: Improve data reading from FIFO

Patch 1 fixes a bug that might cause the adxl380 interrupt handler to read from the sensor FIFO more entries than actually present. Patch 2 optimizes transfer of FIFO data by minimizing transport protocol overhead.

Changes from v1 [1]:
- replaced 2 with sizeof(*st->fifo_buf) in adxl380_irq_handler (Jonathan)

[1] https://lore.kernel.org/linux-iio/[email protected]/T/

Francesco Lavra (2):
iio: accel: adxl380: Avoid reading more entries than present in FIFO
iio: accel: adxl380: Optimize reading of FIFO entries in interrupt
handler

 drivers/iio/accel/adxl380.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
Signature · 1 line
2.39.5
#1 lore raw

PATCH v2 1/2 iio: accel: adxl380: Avoid reading more entries than present in FIFO

The interrupt handler reads FIFO entries in batches of N samples, where N is the number of scan elements that have been enabled. However, the sensor fills the FIFO one sample at a time, even when more than one channel is enabled. Therefore,the number of entries reported by the FIFO status registers may not be a multiple of N; if this number is not a multiple, the number of entries read from the FIFO may exceed the number of entries actually present.

To fix the above issue, round down the number of FIFO entries read from the status registers so that it is always a multiple of N.

Fixes df36de13677a ("iio: accel: add ADXL380 driver")
---
 drivers/iio/accel/adxl380.c | 1 +
 1 file changed, 1 insertion(+)
drivers/iio/accel/adxl380.c +1 -0
index ac20fcfd4e22..650cdbffd4a7 100644
@@ -964,6 +964,7 @@ static irqreturn_t adxl380_irq_handler(int irq, void  *p)
 	if (ret)
 		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],
Signature · 1 line
2.39.5
#2 lore raw

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

In reply to Francesco Lavra

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.

---
 drivers/iio/accel/adxl380.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/iio/accel/adxl380.c +5 -7
index 650cdbffd4a7..e3e6b182eb3d 100644
@@ -965,14 +965,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,
+				sizeof(*st->fifo_buf) * 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;
 }
Signature · 1 line
2.39.5
maintainer
#3 lore raw

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

Quoted 3 lines · On Mon, 19 Jan 2026 11:23:17 +0100 Francesco Lavra <[email protected]> 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().

It's a call to regmap_noinc_read() not regmap_bulk_read() I'll fix it.

Quoted 32 lines

This allows reading acceleration data for all 3 axes at 16 kHz sampling frequency using a 1MHz I2C bus frequency.

---
 drivers/iio/accel/adxl380.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
drivers/iio/accel/adxl380.c +5 -7
index 650cdbffd4a7..e3e6b182eb3d 100644
@@ -965,14 +965,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,
+				sizeof(*st->fifo_buf) * 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;
 }
#4 lore raw

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

Quoted 9 lines · Jonathan Cameron
Quoted 3 lines · On Mon, 19 Jan 2026 11:23:17 +0100 Francesco Lavra <[email protected]> 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().

It's a call to regmap_noinc_read() not regmap_bulk_read() I'll fix it.

This is interesting, does it mean the patch was never tested on the real HW? Or maybe noninc is intentional?

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#5 lore raw

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

Quoted 8 lines · On Fri, 23 Jan 2026 10:13:16 +0200 Andy Shevchenko…
Quoted 6 lines · Jonathan Cameron
Quoted 3 lines · On Mon, 19 Jan 2026 11:23:17 +0100 Francesco Lavra <[email protected]> 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().

Quoted 6 lines
Quoted 2 lines

It's a call to regmap_noinc_read() not regmap_bulk_read() I'll fix it.

This is interesting, does it mean the patch was never tested on the real HW? Or maybe noninc is intentional?

It's absolutely intentional. The device presents a single register address that has the fifo behind it (which is what we added noinc for years ago). So patch should definitely work. Goes from reading that register N times in each call within a loop of M to reading it N x M.

If regcache is in use this makes a difference as avoids corrupting registers after this point as the address increment expected in the hardware for a bulk read doesn't happen. Without regcache it's just "documentation" as at least for protocols used here its the same as a bulk read on the bus.

So patch is fine, it just mentioned the wrong call in the description I'd guess this is because someone is working with a tree that has the wrong call in it but might be wrong.

Jonathan

#6 lore raw

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

Quoted 13 lines · Jonathan Cameron
Quoted 10 lines · On Fri, 23 Jan 2026 10:13:16 +0200 Andy Shevchenko…
Quoted 8 lines · Jonathan Cameron

On Mon, 19 Jan 2026 11:23:17 +0100
Francesco Lavra <[email protected]> wrote:

Quoted 5 lines

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

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

It's a call to regmap_noinc_read()  not regmap_bulk_read() I'll fix it.

This is interesting, does it mean the patch was never tested on the real HW?

The driver has been tested (by me) on real hardware, both before and after this patch.

Quoted 16 lines
Quoted 2 lines

Or maybe noninc is intentional?

It's absolutely intentional.  The device presents a single register address
that has the fifo behind it (which is what we added noinc for years ago). So patch should definitely work.  Goes from reading that register N times in
each call within a loop of M to reading it N x M.

If regcache is in use this makes a difference as avoids corrupting registers
after this point as the address increment expected in the hardware for a bulk read doesn't happen.  Without regcache it's just "documentation" as
at least for protocols used here its the same as a bulk read on the bus.

Quoted 4 lines

So patch is fine, it just mentioned the wrong call in the description I'd guess this is because someone is working with a tree that has the wrong call in
it but might be wrong.

I have this patch applied also to older kernel versions where regmap_noinc_read() doesn't exist, so this is just a copy-paste error in the commit message. Sorry about that.

#7 lore raw

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

Quoted 38 lines · Francesco Lavra
Quoted 12 lines · Jonathan Cameron
Quoted 10 lines · On Fri, 23 Jan 2026 10:13:16 +0200 Andy Shevchenko…
Quoted 8 lines · Jonathan Cameron

On Mon, 19 Jan 2026 11:23:17 +0100
Francesco Lavra <[email protected]> wrote:

Quoted 5 lines

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

Quoted 5 lines
Quoted 5 lines
Quoted 2 lines

It's a call to regmap_noinc_read()  not regmap_bulk_read() I'll fix it.

This is interesting, does it mean the patch was never tested on the real HW?

The driver has been tested (by me) on real hardware, both before and after this patch.

Quoted 16 lines
Quoted 2 lines

Or maybe noninc is intentional?

It's absolutely intentional.  The device presents a single register address
that has the fifo behind it (which is what we added noinc for years ago). So patch should definitely work.  Goes from reading that register N times in
each call within a loop of M to reading it N x M.

If regcache is in use this makes a difference as avoids corrupting registers
after this point as the address increment expected in the hardware for a bulk read doesn't happen.  Without regcache it's just "documentation" as
at least for protocols used here its the same as a bulk read on the bus.

Quoted 8 lines
Quoted 4 lines

So patch is fine, it just mentioned the wrong call in the description I'd guess this is because someone is working with a tree that has the wrong call in
it but might be wrong.

I have this patch applied also to older kernel versions where regmap_noinc_read() doesn't exist, so this is just a copy-paste error in the commit message. Sorry about that.

Thanks for clarifying this!

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#8 lore raw
In reply to Francesco Lavra
Quoted 9 lines · On Mon, 19 Jan 2026 11:23:15 +0100 Francesco Lavra <[email protected]> wrote:

Patch 1 fixes a bug that might cause the adxl380 interrupt handler to read from the sensor FIFO more entries than actually present. Patch 2 optimizes transfer of FIFO data by minimizing transport protocol overhead.

Changes from v1 [1]:
- replaced 2 with sizeof(*st->fifo_buf) in adxl380_irq_handler (Jonathan)

[1] https://lore.kernel.org/linux-iio/[email protected]/T/

Series applied.

Given timing I've queued it up on the testing (soon to be togreg) branch of iio.git but marked the first patch for stable so that it'll get backported after the merge window.

Thanks,

Jonathan

Quoted 9 lines

Francesco Lavra (2):
iio: accel: adxl380: Avoid reading more entries than present in FIFO
iio: accel: adxl380: Optimize reading of FIFO entries in interrupt
handler

 drivers/iio/accel/adxl380.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)