public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] accel: adxl380: Improve data reading from FIFO
@ 2026-01-19 10:23 Francesco Lavra
  2026-01-19 10:23 ` [PATCH v2 1/2] iio: accel: adxl380: Avoid reading more entries than present in FIFO Francesco Lavra
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Francesco Lavra @ 2026-01-19 10:23 UTC (permalink / raw)
  To: Ramona Gradinariu, Antoniu Miclaus, Lars-Peter Clausen,
	Michael Hennerich, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

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/20260106193627.3989930-1-flavra@baylibre.com/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(-)

-- 
2.39.5


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH v2 1/2] iio: accel: adxl380: Avoid reading more entries than present in FIFO
  2026-01-19 10:23 [PATCH v2 0/2] accel: adxl380: Improve data reading from FIFO Francesco Lavra
@ 2026-01-19 10:23 ` Francesco Lavra
  2026-01-19 10:23 ` [PATCH v2 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler Francesco Lavra
  2026-01-22 19:54 ` [PATCH v2 0/2] accel: adxl380: Improve data reading from FIFO Jonathan Cameron
  2 siblings, 0 replies; 9+ messages in thread
From: Francesco Lavra @ 2026-01-19 10:23 UTC (permalink / raw)
  To: Ramona Gradinariu, Antoniu Miclaus, Lars-Peter Clausen,
	Michael Hennerich, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

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")
Signed-off-by: Francesco Lavra <flavra@baylibre.com>
---
 drivers/iio/accel/adxl380.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/iio/accel/adxl380.c b/drivers/iio/accel/adxl380.c
index ac20fcfd4e22..650cdbffd4a7 100644
--- a/drivers/iio/accel/adxl380.c
+++ b/drivers/iio/accel/adxl380.c
@@ -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],
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH v2 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler
  2026-01-19 10:23 [PATCH v2 0/2] accel: adxl380: Improve data reading from FIFO Francesco Lavra
  2026-01-19 10:23 ` [PATCH v2 1/2] iio: accel: adxl380: Avoid reading more entries than present in FIFO Francesco Lavra
@ 2026-01-19 10:23 ` Francesco Lavra
  2026-01-22 19:53   ` Jonathan Cameron
  2026-01-22 19:54 ` [PATCH v2 0/2] accel: adxl380: Improve data reading from FIFO Jonathan Cameron
  2 siblings, 1 reply; 9+ messages in thread
From: Francesco Lavra @ 2026-01-19 10:23 UTC (permalink / raw)
  To: Ramona Gradinariu, Antoniu Miclaus, Lars-Peter Clausen,
	Michael Hennerich, Jonathan Cameron, David Lechner, Nuno Sá,
	Andy Shevchenko, linux-iio, linux-kernel

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 650cdbffd4a7..e3e6b182eb3d 100644
--- a/drivers/iio/accel/adxl380.c
+++ b/drivers/iio/accel/adxl380.c
@@ -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;
 }
-- 
2.39.5


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler
  2026-01-19 10:23 ` [PATCH v2 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler Francesco Lavra
@ 2026-01-22 19:53   ` Jonathan Cameron
  2026-01-23  8:13     ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2026-01-22 19:53 UTC (permalink / raw)
  To: Francesco Lavra
  Cc: Ramona Gradinariu, Antoniu Miclaus, Lars-Peter Clausen,
	Michael Hennerich, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel

On Mon, 19 Jan 2026 11:23:17 +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().
It's a call to regmap_noinc_read()  not regmap_bulk_read()
I'll fix it.

> 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 650cdbffd4a7..e3e6b182eb3d 100644
> --- a/drivers/iio/accel/adxl380.c
> +++ b/drivers/iio/accel/adxl380.c
> @@ -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;
>  }


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 0/2] accel: adxl380: Improve data reading from FIFO
  2026-01-19 10:23 [PATCH v2 0/2] accel: adxl380: Improve data reading from FIFO Francesco Lavra
  2026-01-19 10:23 ` [PATCH v2 1/2] iio: accel: adxl380: Avoid reading more entries than present in FIFO Francesco Lavra
  2026-01-19 10:23 ` [PATCH v2 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler Francesco Lavra
@ 2026-01-22 19:54 ` Jonathan Cameron
  2 siblings, 0 replies; 9+ messages in thread
From: Jonathan Cameron @ 2026-01-22 19:54 UTC (permalink / raw)
  To: Francesco Lavra
  Cc: Ramona Gradinariu, Antoniu Miclaus, Lars-Peter Clausen,
	Michael Hennerich, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel

On Mon, 19 Jan 2026 11:23:15 +0100
Francesco Lavra <flavra@baylibre.com> 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/20260106193627.3989930-1-flavra@baylibre.com/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

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


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler
  2026-01-22 19:53   ` Jonathan Cameron
@ 2026-01-23  8:13     ` Andy Shevchenko
  2026-01-23  9:54       ` Jonathan Cameron
  0 siblings, 1 reply; 9+ messages in thread
From: Andy Shevchenko @ 2026-01-23  8:13 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Francesco Lavra, Ramona Gradinariu, Antoniu Miclaus,
	Lars-Peter Clausen, Michael Hennerich, David Lechner,
	Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel

On Thu, Jan 22, 2026 at 07:53:13PM +0000, Jonathan Cameron wrote:
> On Mon, 19 Jan 2026 11:23:17 +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().

> 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?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler
  2026-01-23  8:13     ` Andy Shevchenko
@ 2026-01-23  9:54       ` Jonathan Cameron
  2026-01-23 11:09         ` Francesco Lavra
  0 siblings, 1 reply; 9+ messages in thread
From: Jonathan Cameron @ 2026-01-23  9:54 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Francesco Lavra, Ramona Gradinariu, Antoniu Miclaus,
	Lars-Peter Clausen, Michael Hennerich, David Lechner,
	Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel

On Fri, 23 Jan 2026 10:13:16 +0200
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Thu, Jan 22, 2026 at 07:53:13PM +0000, Jonathan Cameron wrote:
> > On Mon, 19 Jan 2026 11:23:17 +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().  
> 
> > 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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler
  2026-01-23  9:54       ` Jonathan Cameron
@ 2026-01-23 11:09         ` Francesco Lavra
  2026-01-23 11:12           ` Andy Shevchenko
  0 siblings, 1 reply; 9+ messages in thread
From: Francesco Lavra @ 2026-01-23 11:09 UTC (permalink / raw)
  To: Jonathan Cameron, Andy Shevchenko
  Cc: Ramona Gradinariu, Antoniu Miclaus, Lars-Peter Clausen,
	Michael Hennerich, David Lechner, Nuno Sá, Andy Shevchenko,
	linux-iio, linux-kernel

On Fri, 2026-01-23 at 09:54 +0000, Jonathan Cameron wrote:
> On Fri, 23 Jan 2026 10:13:16 +0200
> Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> 
> > On Thu, Jan 22, 2026 at 07:53:13PM +0000, Jonathan Cameron wrote:
> > > On Mon, 19 Jan 2026 11:23:17 +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().  
> > 
> > > 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.

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

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.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH v2 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler
  2026-01-23 11:09         ` Francesco Lavra
@ 2026-01-23 11:12           ` Andy Shevchenko
  0 siblings, 0 replies; 9+ messages in thread
From: Andy Shevchenko @ 2026-01-23 11:12 UTC (permalink / raw)
  To: Francesco Lavra
  Cc: Jonathan Cameron, Ramona Gradinariu, Antoniu Miclaus,
	Lars-Peter Clausen, Michael Hennerich, David Lechner,
	Nuno Sá, Andy Shevchenko, linux-iio, linux-kernel

On Fri, Jan 23, 2026 at 12:09:36PM +0100, Francesco Lavra wrote:
> On Fri, 2026-01-23 at 09:54 +0000, Jonathan Cameron wrote:
> > On Fri, 23 Jan 2026 10:13:16 +0200
> > Andy Shevchenko <andriy.shevchenko@intel.com> wrote:
> > > On Thu, Jan 22, 2026 at 07:53:13PM +0000, Jonathan Cameron wrote:
> > > > On Mon, 19 Jan 2026 11:23:17 +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().  
> > > 
> > > > 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.
> 
> > > 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.
> 
> 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!

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-01-23 11:12 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-19 10:23 [PATCH v2 0/2] accel: adxl380: Improve data reading from FIFO Francesco Lavra
2026-01-19 10:23 ` [PATCH v2 1/2] iio: accel: adxl380: Avoid reading more entries than present in FIFO Francesco Lavra
2026-01-19 10:23 ` [PATCH v2 2/2] iio: accel: adxl380: Optimize reading of FIFO entries in interrupt handler Francesco Lavra
2026-01-22 19:53   ` Jonathan Cameron
2026-01-23  8:13     ` Andy Shevchenko
2026-01-23  9:54       ` Jonathan Cameron
2026-01-23 11:09         ` Francesco Lavra
2026-01-23 11:12           ` Andy Shevchenko
2026-01-22 19:54 ` [PATCH v2 0/2] accel: adxl380: Improve data reading from FIFO Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox