* [RFC PATCH] iio: adis_buffer: fix buffer ordering for IIO core demultiplexing @ 2026-09-25 11:02 Shehryar Ahmad 2026-09-27 17:59 ` Jonathan Cameron 2026-10-15 10:21 ` Nuno Sá 0 siblings, 2 replies; 7+ messages in thread From: Shehryar Ahmad @ 2026-09-25 11:02 UTC (permalink / raw) To: jic23 Cc: nuno.sa, Michael.Hennerich, dlechner, andy, linux, linux-iio, linux-kernel, Shehryar Ahmad Hi Jonathan, After issue raised by Sashiko in adis16203 graduation series [1], looking at other drivers if they might have same issue. It appears that the root cause is in adis_buffer.c itself. The library constructs the SPI transaction in channel array order while IIO core demultiplexes in scan_index order. adis16209 and adis16260 have the same mismatched ordering that adis16201/16203 had. Rather than reordering channel arrays in affected driver, would it be sensible to make adis_update_scan_mode() iterate in scan_index order instead of channel array order? Would this be the right approach, or is there something I'm missing? [1]: https://lore.kernel.org/all/20260914015321.7a660ab5@jic23-hlaptop/ Signed-off-by: Shehryar Ahmad <shehryar.amd@gmail.com> --- drivers/iio/imu/adis_buffer.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c index 501da4eae..45200b753 100644 --- a/drivers/iio/imu/adis_buffer.c +++ b/drivers/iio/imu/adis_buffer.c @@ -110,10 +110,10 @@ int adis_update_scan_mode(struct iio_dev *indio_dev, spi_message_add_tail(&adis->xfer[j], &adis->msg); } - chan = indio_dev->channels; - for (i = 0; i < indio_dev->num_channels; i++, chan++) { - if (!test_bit(chan->scan_index, scan_mask)) - continue; + for_each_set_bit(i, scan_mask, iio_get_masklength(indio_dev)) { + chan = iio_find_channel_from_si(indio_dev, i); + if (!chan) + return -EINVAL; if (chan->scan_type.storagebits == 32) *tx++ = cpu_to_be16((chan->address + 2) << 8); *tx++ = cpu_to_be16(chan->address << 8); -- 2.55.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC PATCH] iio: adis_buffer: fix buffer ordering for IIO core demultiplexing 2026-09-25 11:02 [RFC PATCH] iio: adis_buffer: fix buffer ordering for IIO core demultiplexing Shehryar Ahmad @ 2026-09-27 17:59 ` Jonathan Cameron 2026-10-06 17:14 ` [PING][RFC " Shehryar Ahmad 2026-10-15 10:17 ` [RFC " Nuno Sá 2026-10-15 10:21 ` Nuno Sá 1 sibling, 2 replies; 7+ messages in thread From: Jonathan Cameron @ 2026-09-27 17:59 UTC (permalink / raw) To: Shehryar Ahmad Cc: nuno.sa, Michael.Hennerich, dlechner, andy, linux, linux-iio, linux-kernel, Robert Budai, Antoniu Miclaus, Dragos Bogdan On Fri, 25 Sep 2026 16:02:39 +0500 Shehryar Ahmad <shehryar.amd@gmail.com> wrote: > Hi Jonathan, > > After issue raised by Sashiko in adis16203 graduation series [1], looking at > other drivers if they might have same issue. It appears that the root > cause is in adis_buffer.c itself. The library constructs the SPI > transaction in channel array order while IIO core demultiplexes in > scan_index order. > > adis16209 and adis16260 have the same mismatched ordering that > adis16201/16203 had. > > Rather than reordering channel arrays in affected driver, > would it be sensible to make adis_update_scan_mode() iterate > in scan_index order instead of channel array order? > > Would this be the right approach, or is there something I'm missing? It is definitely plausible. For this I'd need some input from someone who can actually test some of these parts. Nuno, you are listed as library maintainer - so can you get someone to look at this please. +CC various other folk from maintainers or who have worked in this area in last few years. Otherwise, just a comment to use a Link tag for cross references. Thanks, Jonathan > > [1]: https://lore.kernel.org/all/20260914015321.7a660ab5@jic23-hlaptop/ > Link: https://lore.kernel.org/all/20260914015321.7a660ab5@jic23-hlaptop/ #[1] > Signed-off-by: Shehryar Ahmad <shehryar.amd@gmail.com> > --- > drivers/iio/imu/adis_buffer.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c > index 501da4eae..45200b753 100644 > --- a/drivers/iio/imu/adis_buffer.c > +++ b/drivers/iio/imu/adis_buffer.c > @@ -110,10 +110,10 @@ int adis_update_scan_mode(struct iio_dev *indio_dev, > spi_message_add_tail(&adis->xfer[j], &adis->msg); > } > > - chan = indio_dev->channels; > - for (i = 0; i < indio_dev->num_channels; i++, chan++) { > - if (!test_bit(chan->scan_index, scan_mask)) > - continue; > + for_each_set_bit(i, scan_mask, iio_get_masklength(indio_dev)) { > + chan = iio_find_channel_from_si(indio_dev, i); > + if (!chan) > + return -EINVAL; > if (chan->scan_type.storagebits == 32) > *tx++ = cpu_to_be16((chan->address + 2) << 8); > *tx++ = cpu_to_be16(chan->address << 8); ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PING][RFC PATCH] iio: adis_buffer: fix buffer ordering for IIO core demultiplexing 2026-09-27 17:59 ` Jonathan Cameron @ 2026-10-06 17:14 ` Shehryar Ahmad 2026-10-15 10:17 ` [RFC " Nuno Sá 1 sibling, 0 replies; 7+ messages in thread From: Shehryar Ahmad @ 2026-10-06 17:14 UTC (permalink / raw) To: jic23 Cc: Michael.Hennerich, andy, antoniu.miclaus, dlechner, dragos.bogdan, linux-iio, linux-kernel, linux, nuno.sa, robert.budai, shehryar.amd Hi, A gentle reminder, it's been more than a week since Jonathan's review. Responses from library maintainers would be appreciated :) Thanks ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH] iio: adis_buffer: fix buffer ordering for IIO core demultiplexing 2026-09-27 17:59 ` Jonathan Cameron 2026-10-06 17:14 ` [PING][RFC " Shehryar Ahmad @ 2026-10-15 10:17 ` Nuno Sá 2026-11-24 11:33 ` Sabau, Radu bogdan 1 sibling, 1 reply; 7+ messages in thread From: Nuno Sá @ 2026-10-15 10:17 UTC (permalink / raw) To: Jonathan Cameron Cc: Shehryar Ahmad, Michael.Hennerich, dlechner, andy, linux, linux-iio, linux-kernel, Robert Budai, Antoniu Miclaus, Dragos Bogdan, Radu Sabau On Sun, Sep 27, 2026 at 06:59:29PM +0100, Jonathan Cameron wrote: > On Fri, 25 Sep 2026 16:02:39 +0500 > Shehryar Ahmad <shehryar.amd@gmail.com> wrote: > > > Hi Jonathan, > > > > After issue raised by Sashiko in adis16203 graduation series [1], looking at > > other drivers if they might have same issue. It appears that the root > > cause is in adis_buffer.c itself. The library constructs the SPI > > transaction in channel array order while IIO core demultiplexes in > > scan_index order. > > > > adis16209 and adis16260 have the same mismatched ordering that > > adis16201/16203 had. > > > > Rather than reordering channel arrays in affected driver, > > would it be sensible to make adis_update_scan_mode() iterate > > in scan_index order instead of channel array order? > > > > Would this be the right approach, or is there something I'm missing? > > It is definitely plausible. For this I'd need some input from someone > who can actually test some of these parts. > > Nuno, you are listed as library maintainer - so can you get someone to > look at this please. +CC various other folk from maintainers or who have worked > in this area in last few years. > > Otherwise, just a comment to use a Link tag for cross references. > Hmm missed this one! So the issue looks very much real (just by code inspection). Just never saw it since the more recent devices I worked with just do burst mode which is not affected by that path. Moreover I'm not sure any of the affected drivers is really using the IIO demux (though I don't think that matters - seems to me the buffer will never respect scan_index order so not sure how it was ever right). +Cc Radu as he has been working with these devices and on the library. Radu, can you give a quick test here? Worst case scenario and you only have devices with burst mode, you can just tweak the driver to disable the burst path :) Thanks! - Nuno Sá > Thanks, > > Jonathan > > > > > > [1]: https://lore.kernel.org/all/20260914015321.7a660ab5@jic23-hlaptop/ > > > Link: https://lore.kernel.org/all/20260914015321.7a660ab5@jic23-hlaptop/ #[1] > > Signed-off-by: Shehryar Ahmad <shehryar.amd@gmail.com> > > --- > > drivers/iio/imu/adis_buffer.c | 8 ++++---- > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c > > index 501da4eae..45200b753 100644 > > --- a/drivers/iio/imu/adis_buffer.c > > +++ b/drivers/iio/imu/adis_buffer.c > > @@ -110,10 +110,10 @@ int adis_update_scan_mode(struct iio_dev *indio_dev, > > spi_message_add_tail(&adis->xfer[j], &adis->msg); > > } > > > > - chan = indio_dev->channels; > > - for (i = 0; i < indio_dev->num_channels; i++, chan++) { > > - if (!test_bit(chan->scan_index, scan_mask)) > > - continue; > > + for_each_set_bit(i, scan_mask, iio_get_masklength(indio_dev)) { > > + chan = iio_find_channel_from_si(indio_dev, i); > > + if (!chan) > > + return -EINVAL; > > if (chan->scan_type.storagebits == 32) > > *tx++ = cpu_to_be16((chan->address + 2) << 8); > > *tx++ = cpu_to_be16(chan->address << 8); > ^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: [RFC PATCH] iio: adis_buffer: fix buffer ordering for IIO core demultiplexing 2026-10-15 10:17 ` [RFC " Nuno Sá @ 2026-11-24 11:33 ` Sabau, Radu bogdan 0 siblings, 0 replies; 7+ messages in thread From: Sabau, Radu bogdan @ 2026-11-24 11:33 UTC (permalink / raw) To: Sa, Nuno, Jonathan Cameron Cc: Shehryar Ahmad, Hennerich, Michael, David Lechner, andy@kernel.org, linux, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Budai, Robert, Miclaus, Antoniu, Bogdan, Dragos > -----Original Message----- > From: Sa, Nuno <nuno.sa@analog.com> > Sent: Thursday, October 15, 2026 1:17 PM ... > > > > > > Would this be the right approach, or is there something I'm missing? > > > > It is definitely plausible. For this I'd need some input from someone > > who can actually test some of these parts. > > > > Nuno, you are listed as library maintainer - so can you get someone to > > look at this please. +CC various other folk from maintainers or who have > worked > > in this area in last few years. > > > > Otherwise, just a comment to use a Link tag for cross references. > > > > Hmm missed this one! So the issue looks very much real (just by code > inspection). Just never saw it since the more recent devices I worked with > just do burst mode which is not affected by that path. Moreover I'm not > sure any of the affected drivers is really using the IIO demux (though I > don't think that matters - seems to me the buffer will never respect > scan_index order so not sure how it was ever right). > > +Cc Radu as he has been working with these devices and on the library. > > Radu, can you give a quick test here? Worst case scenario and you only > have devices with burst mode, you can just tweak the driver to disable > the burst path :) > Hi everyone, I tested this on an ADIS16470 (adis16475 driver) on a RPi4. The ADIS16470 only uses the burst path in mainline, and its channel is already in scan_index order, so it does not hit this code by default. To exercise it I used a local tweak on the driver: - set .burst_len = 0 so adis_udpate_scan_mode() takes the non-burst path, and use the generic adis_trigger_handler; - reorder adis16475_channels[] to temp, accel, gyro so the array order differs from the scan_index order. Capturing accel_z + temp with iio_readdev (hex dump of the raw buffer), compared against read_raw: Without the patch: read_raw: accel_z = 0x03174ac0, temp = 0xe7 buffer: 00 eb 03 09 fe 22 The temp word ends up in the upper half of the accel_z slot, accel_z's high word is shifted, and accel_z's low word lands in the temp slot. With the patch: accel_z and temp appear in the right slots and match read_raw (e.g. accel_z 0x02e97fba vs. a read_raw of ~48.67M, temp 0xf6 vs. 0xe6 as the board warmed up). So I can confirm the failure on hardware and that this patch fixes it. Tested-by: Radu Sabau <radu.sabau@analog.com> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH] iio: adis_buffer: fix buffer ordering for IIO core demultiplexing 2026-09-25 11:02 [RFC PATCH] iio: adis_buffer: fix buffer ordering for IIO core demultiplexing Shehryar Ahmad 2026-09-27 17:59 ` Jonathan Cameron @ 2026-10-15 10:21 ` Nuno Sá 2026-11-25 11:14 ` Nuno Sá 1 sibling, 1 reply; 7+ messages in thread From: Nuno Sá @ 2026-10-15 10:21 UTC (permalink / raw) To: Shehryar Ahmad Cc: jic23, Michael.Hennerich, dlechner, andy, linux, linux-iio, linux-kernel On Fri, Sep 25, 2026 at 04:02:39PM +0500, Shehryar Ahmad wrote: > Hi Jonathan, > > After issue raised by Sashiko in adis16203 graduation series [1], looking at > other drivers if they might have same issue. It appears that the root > cause is in adis_buffer.c itself. The library constructs the SPI > transaction in channel array order while IIO core demultiplexes in > scan_index order. > > adis16209 and adis16260 have the same mismatched ordering that > adis16201/16203 had. > > Rather than reordering channel arrays in affected driver, > would it be sensible to make adis_update_scan_mode() iterate > in scan_index order instead of channel array order? > > Would this be the right approach, or is there something I'm missing? > > [1]: https://lore.kernel.org/all/20260914015321.7a660ab5@jic23-hlaptop/ > > Signed-off-by: Shehryar Ahmad <shehryar.amd@gmail.com> > --- > drivers/iio/imu/adis_buffer.c | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c > index 501da4eae..45200b753 100644 > --- a/drivers/iio/imu/adis_buffer.c > +++ b/drivers/iio/imu/adis_buffer.c > @@ -110,10 +110,10 @@ int adis_update_scan_mode(struct iio_dev *indio_dev, > spi_message_add_tail(&adis->xfer[j], &adis->msg); > } > > - chan = indio_dev->channels; > - for (i = 0; i < indio_dev->num_channels; i++, chan++) { > - if (!test_bit(chan->scan_index, scan_mask)) > - continue; > + for_each_set_bit(i, scan_mask, iio_get_masklength(indio_dev)) { I guess it can be iio_for_each_active_channel() - Nuno Sá > + chan = iio_find_channel_from_si(indio_dev, i); > + if (!chan) > + return -EINVAL; > if (chan->scan_type.storagebits == 32) > *tx++ = cpu_to_be16((chan->address + 2) << 8); > *tx++ = cpu_to_be16(chan->address << 8); > -- > 2.55.0 > ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH] iio: adis_buffer: fix buffer ordering for IIO core demultiplexing 2026-10-15 10:21 ` Nuno Sá @ 2026-11-25 11:14 ` Nuno Sá 0 siblings, 0 replies; 7+ messages in thread From: Nuno Sá @ 2026-11-25 11:14 UTC (permalink / raw) To: Shehryar Ahmad Cc: jic23, Michael.Hennerich, dlechner, andy, linux, linux-iio, linux-kernel On Thu, Oct 15, 2026 at 11:21:07AM +0100, Nuno Sá wrote: > On Fri, Sep 25, 2026 at 04:02:39PM +0500, Shehryar Ahmad wrote: > > Hi Jonathan, > > > > After issue raised by Sashiko in adis16203 graduation series [1], looking at > > other drivers if they might have same issue. It appears that the root > > cause is in adis_buffer.c itself. The library constructs the SPI > > transaction in channel array order while IIO core demultiplexes in > > scan_index order. > > > > adis16209 and adis16260 have the same mismatched ordering that > > adis16201/16203 had. > > > > Rather than reordering channel arrays in affected driver, > > would it be sensible to make adis_update_scan_mode() iterate > > in scan_index order instead of channel array order? > > > > Would this be the right approach, or is there something I'm missing? > > > > [1]: https://lore.kernel.org/all/20260914015321.7a660ab5@jic23-hlaptop/ > > > > Signed-off-by: Shehryar Ahmad <shehryar.amd@gmail.com> > > --- > > drivers/iio/imu/adis_buffer.c | 8 ++++---- > > 1 file changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/drivers/iio/imu/adis_buffer.c b/drivers/iio/imu/adis_buffer.c > > index 501da4eae..45200b753 100644 > > --- a/drivers/iio/imu/adis_buffer.c > > +++ b/drivers/iio/imu/adis_buffer.c > > @@ -110,10 +110,10 @@ int adis_update_scan_mode(struct iio_dev *indio_dev, > > spi_message_add_tail(&adis->xfer[j], &adis->msg); > > } > > > > - chan = indio_dev->channels; > > - for (i = 0; i < indio_dev->num_channels; i++, chan++) { > > - if (!test_bit(chan->scan_index, scan_mask)) > > - continue; > > + for_each_set_bit(i, scan_mask, iio_get_masklength(indio_dev)) { > > I guess it can be iio_for_each_active_channel() So given that we confirmed and got this tested and with the above change: Reviewed-by: Nuno Sá <nuno.sa@analog.com> > > - Nuno Sá > > > + chan = iio_find_channel_from_si(indio_dev, i); > > + if (!chan) > > + return -EINVAL; > > if (chan->scan_type.storagebits == 32) > > *tx++ = cpu_to_be16((chan->address + 2) << 8); > > *tx++ = cpu_to_be16(chan->address << 8); > > -- > > 2.55.0 > > ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-11-25 11:14 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-09-25 11:02 [RFC PATCH] iio: adis_buffer: fix buffer ordering for IIO core demultiplexing Shehryar Ahmad 2026-09-27 17:59 ` Jonathan Cameron 2026-10-06 17:14 ` [PING][RFC " Shehryar Ahmad 2026-10-15 10:17 ` [RFC " Nuno Sá 2026-11-24 11:33 ` Sabau, Radu bogdan 2026-10-15 10:21 ` Nuno Sá 2026-11-25 11:14 ` Nuno Sá
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox