iio: accel: merge adis16203 into mainline adis16201 and remove from staging
Subsystems (5)
v2 cover iio: accel: merge adis16203 into mainline adis16201 and remove from staging
This v2 series addresses review feedbacks on the previous attempt to move ADIS16203 from staging into the mainline ADIS16201 driver [1].
Key changes from v1:
- Introduced adis16201_chip_info and adis16201_state infrastructure
- Added SPI and OF device ID tables with proper MODULE_DEVICE_TABLE
- Fixed adis_data stack lifetime issue in probe
- Fixed IIO_CHAN_SOFT_TIMESTAMP index collision in adis16203_channels
Patches 5 and 6 carry Reviewed-by tags from prior review.
[1] https://lore.kernel.org/all/[email protected]/
Shehryar Ahmad (6):
iio: accel: adis16201: add SPI device ID table
iio: accel: adis16201: add OF device ID table
iio: accel: adis16201: prepare driver to support additional parts
iio: accel: adis16201: add ADIS16203 support
staging: iio: accel: remove adis16203, merged into mainline adis16201
driver
dt-bindings: iio: accel: adi,adis16201: add adis16203 compatible
.../bindings/iio/accel/adi,adis16201.yaml | 6 +- drivers/iio/accel/Kconfig | 6 +- drivers/iio/accel/adis16201.c | 123 +++++-- drivers/staging/iio/Kconfig | 1 - drivers/staging/iio/Makefile | 1 - drivers/staging/iio/accel/Kconfig | 19 -- drivers/staging/iio/accel/Makefile | 6 - drivers/staging/iio/accel/adis16203.c | 315 ------------------ 8 files changed, 106 insertions(+), 371 deletions(-) delete mode 100644 drivers/staging/iio/accel/Kconfig delete mode 100644 drivers/staging/iio/accel/Makefile delete mode 100644 drivers/staging/iio/accel/adis16203.c
Signature · 1 line
2.43.0
PATCH v2 1/6 iio: accel: adis16201: add SPI device ID table
Add spi_device_id table for ADIS16201. Replace MODULE_ALIAS() with MODULE_DEVICE_TABLE() which automatically generates the same module alias.
--- drivers/iio/accel/adis16201.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/iio/accel/adis16201.c +8 -1
@@ -288,16 +288,23 @@ static int adis16201_probe(struct spi_device *spi)return devm_iio_device_register (&spi->dev, indio_dev); } +static const struct spi_device_id adis16201_ids[] = { + { .name ="adis16201" ,0 }, + { }, +}; + +MODULE_DEVICE_TABLE (spi, adis16201_ids); +static struct spi_driver adis16201_driver = { .driver = { .name ="adis16201" , }, .probe = adis16201_probe, + .id_table = adis16201_ids, };module_spi_driver (adis16201_driver);MODULE_AUTHOR ("Barry Song <[email protected]>" );MODULE_DESCRIPTION ("Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer" );MODULE_LICENSE ("GPL v2" ); -MODULE_ALIAS ("spi:adis16201" );MODULE_IMPORT_NS ("IIO_ADISLIB" );
Signature · 1 line
2.43.0
PATCH v2 2/6 iio: accel: adis16201: add OF device ID table
In reply to Shehryar AhmadAdd of_device_id table for adis16201 and register it with MODULE_DEVICE_TABLE() to enable device tree based matching.
--- drivers/iio/accel/adis16201.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/iio/accel/adis16201.c +8 -0
@@ -288,6 +288,13 @@ static int adis16201_probe(struct spi_device *spi)return devm_iio_device_register (&spi->dev, indio_dev); } +static const struct of_device_id adis16201_of_match[] = { + { .compatible ="adi,adis16201" }, + { }, +}; + +MODULE_DEVICE_TABLE (of, adis16201_of_match); +static const struct spi_device_id adis16201_ids[] = { { .name ="adis16201" ,0 }, { },
@@ -298,6 +305,7 @@ MODULE_DEVICE_TABLE(spi, adis16201_ids);static struct spi_driver adis16201_driver = { .driver = { .name ="adis16201" , + .of_match_table = adis16201_of_match, }, .probe = adis16201_probe, .id_table = adis16201_ids,
Signature · 1 line
2.43.0
PATCH v2 3/6 iio: accel: adis16201: prepare driver to support additional parts
In reply to Shehryar AhmadIntroduce adis16201_chip_info to hold per chip data and adis16201_state to wrap struct adis. Move adis16201 to this infrastructure. This prepares the driver to support additional chip variants by keeping chip-specific parameters in adis16201_chip_info. Additionally, adis16201_write_raw applies mask directly on value.
--- drivers/iio/accel/adis16201.c | 78 ++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 23 deletions(-)
drivers/iio/accel/adis16201.c +55 -23
@@ -87,6 +87,22 @@ enum adis16201_scan { ADIS16201_SCAN_TEMP, }; +struct adis16201_chip_info { +const char *name; +const struct iio_chan_spec *arr_channels; +unsigned int incli_scale_val2; +u16 write_mask_incli; +u16 diag_stat_mask; +unsigned int read_bits_incli; +unsigned int num_channels; +}; + +struct adis16201_state { +struct adis adis; +const struct adis16201_chip_info *info; +struct adis_data data; +}; +static const u8 adis16201_addresses[] = { [ADIS16201_SCAN_ACC_X ] =ADIS16201_XACCL_OFFS_REG , [ADIS16201_SCAN_ACC_Y ] =ADIS16201_YACCL_OFFS_REG ,
@@ -99,7 +115,7 @@ static int adis16201_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { - struct adis *st = iio_priv(indio_dev); + struct adis16201_state *st = iio_priv(indio_dev);int ret;int bits;u8 addr;
@@ -137,7 +153,7 @@ static int adis16201_read_raw(struct iio_dev *indio_dev,return IIO_VAL_INT_PLUS_NANO ;case IIO_INCLI : *val =0 ; - *val2 =100000 ; + *val2 = st->info->incli_scale_val2;return IIO_VAL_INT_PLUS_MICRO ;default :return -EINVAL ;
@@ -157,13 +173,13 @@ static int adis16201_read_raw(struct iio_dev *indio_dev, bits =12 ;break ;case IIO_INCLI : - bits =9 ; + bits = st->info->read_bits_incli;break ;default :return -EINVAL ; } addr = adis16201_addresses[chan->scan_index]; - ret =adis_read_reg_16 (st, addr, &val16); + ret =adis_read_reg_16 (&st->adis, addr, &val16);if (ret)return ret;
@@ -180,25 +196,24 @@ static int adis16201_write_raw(struct iio_dev *indio_dev, int val2, long mask) { -struct adis *st =iio_priv (indio_dev); -int m; +struct adis16201_state *st =iio_priv (indio_dev);if (mask !=IIO_CHAN_INFO_CALIBBIAS )return -EINVAL ;switch (chan->type) {case IIO_ACCEL : - m =GENMASK (11 ,0 ); + val &=GENMASK (11 ,0 );break ;case IIO_INCLI : - m =GENMASK (8 ,0 ); + val &= st->info->write_mask_incli;break ;default :return -EINVAL ; } -return adis_write_reg_16 (st, adis16201_addresses[chan->scan_index], - val & m); +return adis_write_reg_16 (&st->adis, adis16201_addresses[chan->scan_index], + val); }static const struct iio_chan_spec adis16201_channels[] = {
@@ -217,6 +232,20 @@ static const struct iio_chan_spec adis16201_channels[] = {IIO_CHAN_SOFT_TIMESTAMP (7 ) }; +static const struct adis16201_chip_info adis16201_chip_data = { + .arr_channels = adis16201_channels, + .incli_scale_val2 =100000 , + .write_mask_incli =GENMASK (8 ,0 ), + .diag_stat_mask = +BIT (ADIS16201_DIAG_STAT_SPI_FAIL_BIT ) | +BIT (ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT ) | +BIT (ADIS16201_DIAG_STAT_POWER_HIGH_BIT ) | +BIT (ADIS16201_DIAG_STAT_POWER_LOW_BIT ), + .read_bits_incli =9 , + .num_channels =ARRAY_SIZE (adis16201_channels), + .name ="adis16201" , +}; +static const struct iio_info adis16201_info = { .read_raw = adis16201_read_raw, .write_raw = adis16201_write_raw,
@@ -248,16 +277,12 @@ static const struct adis_data adis16201_data = { .timeouts = &adis16201_timeouts, .status_error_msgs = adis16201_status_error_msgs, - .status_error_mask =BIT (ADIS16201_DIAG_STAT_SPI_FAIL_BIT ) | -BIT (ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT ) | -BIT (ADIS16201_DIAG_STAT_POWER_HIGH_BIT ) | - BIT(ADIS16201_DIAG_STAT_POWER_LOW_BIT), };static int adis16201_probe (struct spi_device *spi) {struct iio_dev *indio_dev; -struct adis *st; +struct adis16201_state *st;int ret; indio_dev =devm_iio_device_alloc (&spi->dev,sizeof (*st));
@@ -266,22 +291,29 @@ static int adis16201_probe(struct spi_device *spi) st =iio_priv (indio_dev); - indio_dev->name = spi->dev.driver->name; + st->info =spi_get_device_match_data (spi); +if (!st->info) +return -ENODATA ; + + indio_dev->name = st->info->name; indio_dev->info = &adis16201_info; - indio_dev->channels = adis16201_channels; - indio_dev->num_channels =ARRAY_SIZE (adis16201_channels); + indio_dev->channels = st->info->arr_channels; + indio_dev->num_channels = st->info->num_channels; indio_dev->modes =INDIO_DIRECT_MODE ; - ret =adis_init (st, indio_dev, spi, &adis16201_data); + st->data = adis16201_data; + st->data.status_error_mask = st->info->diag_stat_mask; + + ret =adis_init (&st->adis, indio_dev, spi, &st->data);if (ret)return ret; - ret =devm_adis_setup_buffer_and_trigger (st, indio_dev,NULL ); + ret =devm_adis_setup_buffer_and_trigger (&st->adis, indio_dev,NULL );if (ret)return ret; - ret =__adis_initial_startup (st); + ret =__adis_initial_startup (&st->adis);if (ret)return ret;
@@ -289,14 +321,14 @@ static int adis16201_probe(struct spi_device *spi) }static const struct of_device_id adis16201_of_match[] = { - { .compatible ="adi,adis16201" }, + { .compatible ="adi,adis16201" , .data = &adis16201_chip_data }, { }, };MODULE_DEVICE_TABLE (of, adis16201_of_match);static const struct spi_device_id adis16201_ids[] = { - { .name ="adis16201" ,0 }, + { .name ="adis16201" , .driver_data = (kernel_ulong_t)&adis16201_chip_data }, { }, };
Signature · 1 line
2.43.0
PATCH v2 4/6 iio: accel: adis16201: add ADIS16203 support
In reply to Shehryar AhmadAdd ADIS16203 from staging to mainline ADIS16201. ADIS16203 shares same SPI protocol and register addresses. Differing parameters are handled by adis16201_chip_info structure.
ADIS16203 specific support includes DIAG_STAT_SELFTEST_FAIL_BIT, which is supported only on ADIS16203, and a separate channel array.
Kconfig is updated accordingly.
--- drivers/iio/accel/Kconfig | 6 +++--- drivers/iio/accel/adis16201.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-)
drivers/iio/accel/Kconfig +3 -3
@@ -7,13 +7,13 @@ menu "Accelerometers" config ADIS16201 - tristate "Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer" + tristate "ADIS16201 Digital Inclinometer and similar" depends on SPI select IIO_ADIS_LIB select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help - Say Y here to build support for Analog Devices adis16201 dual-axis - digital inclinometer and accelerometer. + Say Y here to build support for Analog Devices adis16201 Digital + Inclinometer and similar To compile this driver as a module, say M here: the module will be called adis16201.
drivers/iio/accel/adis16201.c +30 -2
@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0-or-later /* -* ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer +* ADIS16201 Digital Inclinometer and similar * * Copyright 2010 Analog Devices Inc. */
@@ -63,6 +63,7 @@#define ADIS16201_DIAG_STAT_REG 0x3C#define ADIS16201_DIAG_STAT_ALARM2 BIT(9)#define ADIS16201_DIAG_STAT_ALARM1 BIT(8) +#define ADIS16203_DIAG_STAT_SELFTEST_FAIL_BIT 5/* ADIS16203 only */ #define ADIS16201_DIAG_STAT_SPI_FAIL_BIT 3#define ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT 2/* Power supply above 3.625 V */
@@ -232,6 +233,15 @@ static const struct iio_chan_spec adis16201_channels[] = {IIO_CHAN_SOFT_TIMESTAMP (7 ) }; +static const struct iio_chan_spec adis16203_channels[] = { +ADIS_SUPPLY_CHAN (ADIS16201_SUPPLY_OUT_REG ,ADIS16201_SCAN_SUPPLY ,0 ,12 ), +ADIS_TEMP_CHAN (ADIS16201_TEMP_OUT_REG ,ADIS16201_SCAN_TEMP ,0 ,12 ), +ADIS_AUX_ADC_CHAN (ADIS16201_AUX_ADC_REG ,ADIS16201_SCAN_AUX_ADC ,0 ,12 ), +ADIS_INCLI_CHAN (X ,ADIS16201_XINCL_OUT_REG ,ADIS16201_SCAN_INCLI_X , +BIT (IIO_CHAN_INFO_CALIBBIAS ),0 ,14 ), +IIO_CHAN_SOFT_TIMESTAMP (7 ), +}; +static const struct adis16201_chip_info adis16201_chip_data = { .arr_channels = adis16201_channels, .incli_scale_val2 =100000 ,
@@ -246,6 +256,21 @@ static const struct adis16201_chip_info adis16201_chip_data = { .name = "adis16201", }; +static const struct adis16201_chip_info adis16203_chip_data = { + .arr_channels = adis16203_channels, + .incli_scale_val2 =25000 , + .write_mask_incli =GENMASK (13 ,0 ), + .diag_stat_mask = +BIT (ADIS16203_DIAG_STAT_SELFTEST_FAIL_BIT ) | +BIT (ADIS16201_DIAG_STAT_SPI_FAIL_BIT ) | +BIT (ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT ) | +BIT (ADIS16201_DIAG_STAT_POWER_HIGH_BIT ) | +BIT (ADIS16201_DIAG_STAT_POWER_LOW_BIT ), + .read_bits_incli =14 , + .num_channels =ARRAY_SIZE (adis16203_channels), + .name ="adis16203" , +}; +static const struct iio_info adis16201_info = { .read_raw = adis16201_read_raw, .write_raw = adis16201_write_raw,
@@ -253,6 +278,7 @@ static const struct iio_info adis16201_info = { };static const char *const adis16201_status_error_msgs[] = { + [ADIS16203_DIAG_STAT_SELFTEST_FAIL_BIT ] ="Self test failure" , [ADIS16201_DIAG_STAT_SPI_FAIL_BIT ] ="SPI failure" , [ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT ] ="Flash update failed" , [ADIS16201_DIAG_STAT_POWER_HIGH_BIT ] ="Power supply above 3.625V" ,
@@ -322,6 +348,7 @@ static int adis16201_probe(struct spi_device *spi)static const struct of_device_id adis16201_of_match[] = { { .compatible ="adi,adis16201" , .data = &adis16201_chip_data }, + { .compatible ="adi,adis16203" , .data = &adis16203_chip_data }, { }, };
@@ -329,6 +356,7 @@ MODULE_DEVICE_TABLE(of, adis16201_of_match);static const struct spi_device_id adis16201_ids[] = { { .name ="adis16201" , .driver_data = (kernel_ulong_t)&adis16201_chip_data }, + { .name ="adis16203" , .driver_data = (kernel_ulong_t)&adis16203_chip_data }, { }, };
@@ -345,6 +373,6 @@ static struct spi_driver adis16201_driver = {module_spi_driver (adis16201_driver);MODULE_AUTHOR ("Barry Song <[email protected]>" ); -MODULE_DESCRIPTION ("Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer" ); +MODULE_DESCRIPTION ("Analog Devices ADIS16201 Inclinometer and similar" );MODULE_LICENSE ("GPL v2" );MODULE_IMPORT_NS ("IIO_ADISLIB" );
Signature · 1 line
2.43.0
PATCH v2 5/6 staging: iio: accel: remove adis16203, merged into mainline adis16201 driver
In reply to Shehryar AhmadThe ADIS16203 is merged with mainline ADIS16201 in previous patch of series, remove the staging copy and its build system entries.
--- drivers/staging/iio/Kconfig | 1 - drivers/staging/iio/Makefile | 1 - drivers/staging/iio/accel/Kconfig | 19 -- drivers/staging/iio/accel/Makefile | 6 - drivers/staging/iio/accel/adis16203.c | 315 -------------------------- 5 files changed, 342 deletions(-) delete mode 100644 drivers/staging/iio/accel/Kconfig delete mode 100644 drivers/staging/iio/accel/Makefile delete mode 100644 drivers/staging/iio/accel/adis16203.c
drivers/staging/iio/Kconfig +0 -1
@@ -5,7 +5,6 @@ menu "IIO staging drivers" depends on IIO -source "drivers/staging/iio/accel/Kconfig" source "drivers/staging/iio/adc/Kconfig" source "drivers/staging/iio/addac/Kconfig" source "drivers/staging/iio/frequency/Kconfig"
drivers/staging/iio/Makefile +0 -1
@@ -3,7 +3,6 @@ # Makefile for the industrial I/O core. # -obj-y += accel/ obj-y += adc/ obj-y += addac/ obj-y += frequency/
drivers/staging/iio/accel/Kconfig deleted +0 -19
@@ -1,19 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Accelerometer drivers -# -menu "Accelerometers" - -config ADIS16203 - tristate "Analog Devices ADIS16203 Programmable 360 Degrees Inclinometer" - depends on SPI - select IIO_ADIS_LIB - select IIO_ADIS_LIB_BUFFER if IIO_BUFFER - help - Say Y here to build support for Analog Devices adis16203 Programmable - 360 Degrees Inclinometer. - - To compile this driver as a module, say M here: the module will be - called adis16203. - -endmenu
drivers/staging/iio/accel/Makefile deleted +0 -6
@@ -1,6 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -# -# Makefile for industrial I/O accelerometer drivers -# - -obj-$(CONFIG_ADIS16203) += adis16203.o
drivers/staging/iio/accel/adis16203.c deleted +0 -315
315 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 6/6 dt-bindings: iio: accel: adi,adis16201: add adis16203 compatible
In reply to Shehryar AhmadThe ADIS16203 has the same external interface as the already documented ADIS16201/ADIS16209, for the properties covered by this binding (compatible/reg, the DIO-based interrupt pin, and VDD supply), verified by datasheets Table 5, Pin Function Descriptions, in the respective Analog Devices datasheets. Some Auxiliary pins differ (e.g. adis16209 marks a few pins DNC where adis16201/adis16203 use them as AUX COM), but these are not represented in this binding. Add adis16203 to the existing enum rather than creating a separate file.
--- .../devicetree/bindings/iio/accel/adi,adis16201.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
Documentation/devicetree/bindings/iio/accel/adi,adis16201.yaml +4 -2
@@ -4,21 +4,23 @@ $id: http://devicetree.org/schemas/iio/accel/adi,adis16201.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: ADIS16201 Dual Axis Inclinometer and similar +title: ADIS16201 Inclinometer and similar maintainers: - Jonathan Cameron <[email protected]> description: | - Two similar parts from external interface point of view. + Three similar parts from external interface point of view. SPI interface. https://www.analog.com/en/products/adis16201.html + https://www.analog.com/en/products/adis16203.html https://www.analog.com/en/products/adis16209.html properties: compatible: enum: - adi,adis16201 + - adi,adis16203 - adi,adis16209 reg:
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v2 4/6] iio: accel: adis16201: add ADIS16203 support
In reply to Shehryar AhmadThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] Channel array is not sorted by scan_index, causing mismatched buffer data --
commit e8653b6ce4ef8334200ed8d297acf21b7bdc91a8
Author: Shehryar Ahmad <[email protected]>
iio: accel: adis16201: add ADIS16203 support
Add ADIS16203 from staging to mainline ADIS16201. ADIS16203 shares same SPI protocol and register addresses. Differing parameters are handled by adis16201_chip_info structure.
Quoted 4 lines
drivers/iio/accel/adis16201.c +0
-0
[ ... ]
drivers/iio/accel/adis16201.c static const struct iio_chan_spec adis16201_channels[] = { · line 243
Quoted 12 lines
drivers/iio/accel/adis16201.c +8
-0@@ -232,6 +233,15 @@ static const struct iio_chan_spec adis16201_channels[] = { IIO_CHAN_SOFT_TIMESTAMP(7) }; +static const struct iio_chan_spec adis16203_channels[] = { +ADIS_SUPPLY_CHAN (ADIS16201_SUPPLY_OUT_REG ,ADIS16201_SCAN_SUPPLY ,0 ,12 ), +ADIS_TEMP_CHAN (ADIS16201_TEMP_OUT_REG ,ADIS16201_SCAN_TEMP ,0 ,12 ), +ADIS_AUX_ADC_CHAN (ADIS16201_AUX_ADC_REG ,ADIS16201_SCAN_AUX_ADC ,0 ,12 ), +ADIS_INCLI_CHAN (X ,ADIS16201_XINCL_OUT_REG ,ADIS16201_SCAN_INCLI_X , +BIT (IIO_CHAN_INFO_CALIBBIAS ),0 ,14 ), +IIO_CHAN_SOFT_TIMESTAMP (7 ), +};
[Severity: High]
This is a pre-existing issue, but by copying the channel layout from adis16201_channels into the new adis16203_channels array, this propagates a bug where the channels are not sorted by scan_index.
Can this cause data corruption during IIO core demultiplexing?
The array defines the channels in this order: SUPPLY (scan_index 4), TEMP (scan_index 6), AUX_ADC (scan_index 5), INCLI_X (scan_index 2), and TIMESTAMP (scan_index 7).
The IIO ADIS library's adis_update_scan_mode() iterates over the indio_dev->channels array sequentially to build the SPI transfer list, so the raw buffer memory is populated in array order.
However, the IIO core demux logic iterates over the active channels using for_each_set_bit(buffer->scan_mask) in iio_buffer_update_demux(). This processes bits from least significant to most significant, which means it expects the buffer data in ascending scan_index order.
Because the raw buffer layout does not match the scan_index order, won't the IIO core extract data from the wrong byte offsets, mapping data from one physical channel to a completely different IIO channel?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Jonathan Cameron
maintainerRe: [PATCH v2 3/6] iio: accel: adis16201: prepare driver to support additional parts
In reply to Shehryar AhmadQuoted 7 lines · On Sun, 13 Sep 2026 13:53:04 +0500 Shehryar Ahmad <[email protected]>…
Introduce
adis16201_chip_infoto hold per chip data andadis16201_stateto wrap struct adis. Move adis16201 to this infrastructure. This prepares the driver to support additional chip variants by keeping chip-specific parameters inadis16201_chip_info. Additionally,adis16201_write_rawapplies mask directly on value.Signed-off-by Shehryar Ahmad <[email protected]>
Sashiko spotted what seems to be an interesting bug.. Seems the adis_buffer library code relies on channel ordering matching scan_index ordering and that isn't true in this driver.
https://sashiko.dev/#/patchset/20260913085307.13846-1-shehryar.amd%40gmail.com
There should be no negative side effects reordering the channels so I think that would makes sense to do.
The buffered data will be in a different order but that will at least be the order the sysfs interface claims it is in! If you don't mind doing that as a precursor to this series that would be great.
See the spi transaction building in adis_update_scan_modes() for where it is going wrong.
One small review comment inline that means making one more thing const to simplify the code a little.
Thanks,
Jonathan
Quoted 10 lines
--- drivers/iio/accel/adis16201.c | 78 ++++++++++++++++++++++++----------- 1 file changed, 55 insertions(+), 23 deletions(-)drivers/iio/accel/adis16201.c +0
-0@@ -87,6 +87,22 @@ enum adis16201_scan { ADIS16201_SCAN_TEMP,
drivers/iio/accel/adis16201.c enum adis16201_scan { · line 97
Quoted 10 lines
drivers/iio/accel/adis16201.c +8
-0}; +struct adis16201_chip_info { +const char *name; +const struct iio_chan_spec *arr_channels; +unsigned int incli_scale_val2; +u16 write_mask_incli; +u16 diag_stat_mask; +unsigned int read_bits_incli; +unsigned int num_channels;
As mentioned below add:
const struct adis_data *data;
drivers/iio/accel/adis16201.c enum adis16201_scan { · line 103
Quoted 6 lines
drivers/iio/accel/adis16201.c +6
-0+}; + +struct adis16201_state { +struct adis adis; +const struct adis16201_chip_info *info; +struct adis_data data;
and drop this.
Quoted 26 lines
drivers/iio/accel/adis16201.c +15
-0+};static const struct iio_chan_spec adis16201_channels[] = {@@ -217,6 +232,20 @@ static const struct iio_chan_spec adis16201_channels[] = {IIO_CHAN_SOFT_TIMESTAMP (7 ) }; +static const struct adis16201_chip_info adis16201_chip_data = { + .arr_channels = adis16201_channels, + .incli_scale_val2 =100000 , + .write_mask_incli =GENMASK (8 ,0 ), + .diag_stat_mask = +BIT (ADIS16201_DIAG_STAT_SPI_FAIL_BIT ) | +BIT (ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT ) | +BIT (ADIS16201_DIAG_STAT_POWER_HIGH_BIT ) | +BIT (ADIS16201_DIAG_STAT_POWER_LOW_BIT ), + .read_bits_incli =9 , + .num_channels =ARRAY_SIZE (adis16201_channels), + .name ="adis16201" , +}; +static const struct iio_info adis16201_info = { .read_raw = adis16201_read_raw, .write_raw = adis16201_write_raw,
drivers/iio/accel/adis16201.c static const struct adis_data adis16201_data = { · line 254
Quoted 7 lines
drivers/iio/accel/adis16201.c +0
-4@@ -248,16 +277,12 @@ static const struct adis_data adis16201_data = { .timeouts = &adis16201_timeouts, .status_error_msgs = adis16201_status_error_msgs, - .status_error_mask =BIT (ADIS16201_DIAG_STAT_SPI_FAIL_BIT ) | -BIT (ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT ) | -BIT (ADIS16201_DIAG_STAT_POWER_HIGH_BIT ) | - BIT(ADIS16201_DIAG_STAT_POWER_LOW_BIT),
As below, leave this here. Just look to access this whole structure via info.
Quoted 21 lines
drivers/iio/accel/adis16201.c +6
-2};static int adis16201_probe (struct spi_device *spi) {struct iio_dev *indio_dev; -struct adis *st; +struct adis16201_state *st;int ret; indio_dev =devm_iio_device_alloc (&spi->dev,sizeof (*st));@@ -266,22 +291,29 @@ static int adis16201_probe(struct spi_device *spi) st =iio_priv (indio_dev); - indio_dev->name = spi->dev.driver->name; + st->info =spi_get_device_match_data (spi); +if (!st->info) +return -ENODATA ; + + indio_dev->name = st->info->name; indio_dev->info = &adis16201_info;
drivers/iio/accel/adis16201.c static int adis16201_probe(struct spi_device *spi) · line 306
Quoted 10 lines
drivers/iio/accel/adis16201.c +4
-3- indio_dev->channels = adis16201_channels; - indio_dev->num_channels =ARRAY_SIZE (adis16201_channels); + indio_dev->channels = st->info->arr_channels; + indio_dev->num_channels = st->info->num_channels; indio_dev->modes =INDIO_DIRECT_MODE ; - ret =adis_init (st, indio_dev, spi, &adis16201_data); + st->data = adis16201_data; + st->data.status_error_mask = st->info->diag_stat_mask;
Given we don't have too many variants, I think rather than this copy and update pattern I'd just have multiple instances of the structure type of adis16201_data. Then put a pointer to the relevant one in the info structure and just pass in to adis_init() st->info->data.
Then you won't need the diag_stat_mask element.
Costs a little more static const data but simplifies the code and I think that is the right trade off to make.
Quoted 32 lines
drivers/iio/accel/adis16201.c +6
-4+ + ret =adis_init (&st->adis, indio_dev, spi, &st->data);if (ret)return ret; - ret =devm_adis_setup_buffer_and_trigger (st, indio_dev,NULL ); + ret =devm_adis_setup_buffer_and_trigger (&st->adis, indio_dev,NULL );if (ret)return ret; - ret =__adis_initial_startup (st); + ret =__adis_initial_startup (&st->adis);if (ret)return ret;@@ -289,14 +321,14 @@ static int adis16201_probe(struct spi_device *spi) }static const struct of_device_id adis16201_of_match[] = { - { .compatible ="adi,adis16201" }, + { .compatible ="adi,adis16201" , .data = &adis16201_chip_data }, { }, };MODULE_DEVICE_TABLE (of, adis16201_of_match);static const struct spi_device_id adis16201_ids[] = { - { .name ="adis16201" ,0 }, + { .name ="adis16201" , .driver_data = (kernel_ulong_t)&adis16201_chip_data }, { }, };
Jonathan Cameron
maintainerRe: [PATCH v2 4/6] iio: accel: adis16201: add ADIS16203 support
In reply to Shehryar AhmadQuoted 23 lines · On Sun, 13 Sep 2026 13:53:05 +0500 Shehryar Ahmad <[email protected]>…
Add ADIS16203 from staging to mainline ADIS16201. ADIS16203 shares same SPI protocol and register addresses. Differing parameters are handled by
adis16201_chip_infostructure.ADIS16203 specific support includes
DIAG_STAT_SELFTEST_FAIL_BIT, which is supported only on ADIS16203, and a separate channel array.
Kconfigis updated accordingly.Signed-off-by Shehryar Ahmad <[email protected]>--- drivers/iio/accel/Kconfig | 6 +++--- drivers/iio/accel/adis16201.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-)drivers/iio/accel/Kconfig +0
-0@@ -7,13 +7,13 @@ menu "Accelerometers" config ADIS16201
drivers/iio/accel/Kconfig line 16
Quoted 10 lines
drivers/iio/accel/Kconfig +3
-3- tristate "Analog Devices ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer" + tristate "ADIS16201 Digital Inclinometer and similar" depends on SPI select IIO_ADIS_LIB select IIO_ADIS_LIB_BUFFER if IIO_BUFFER help - Say Y here to build support for Analog Devices adis16201 dual-axis - digital inclinometer and accelerometer. + Say Y here to build support for Analog Devices adis16201 Digital + Inclinometer and similar
Here is where the names should be.
Say Y here to build support for Analog Devices Digital Inclinometers:
- ADIS16201
- ADIS16203
or something like that. Key is that a new device being supported is a single line added with no churn of the surrounding text.
Quoted 24 lines
drivers/iio/accel/Kconfig +0
-0To compile this driver as a module, say M here: the module will be called adis16201.drivers/iio/accel/adis16201.c +2
-1@@ -1,6 +1,6 @@// SPDX-License-Identifier: GPL-2.0-or-later /* -* ADIS16201 Dual-Axis Digital Inclinometer and Accelerometer +* ADIS16201 Digital Inclinometer and similar * * Copyright 2010 Analog Devices Inc. */ @@ -63,6 +63,7 @@#define ADIS16201_DIAG_STAT_REG 0x3C#define ADIS16201_DIAG_STAT_ALARM2 BIT(9)#define ADIS16201_DIAG_STAT_ALARM1 BIT(8) +#define ADIS16203_DIAG_STAT_SELFTEST_FAIL_BIT 5/* ADIS16203 only */ #define ADIS16201_DIAG_STAT_SPI_FAIL_BIT 3#define ADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT 2/* Power supply above 3.625 V */
drivers/iio/accel/adis16201.c static const struct iio_chan_spec adis16201_channels[] = { · line 242
Quoted 10 lines
drivers/iio/accel/adis16201.c +7
-0@@ -232,6 +233,15 @@ static const struct iio_chan_spec adis16201_channels[] = {IIO_CHAN_SOFT_TIMESTAMP (7 ) }; +static const struct iio_chan_spec adis16203_channels[] = { +ADIS_SUPPLY_CHAN (ADIS16201_SUPPLY_OUT_REG ,ADIS16201_SCAN_SUPPLY ,0 ,12 ), +ADIS_TEMP_CHAN (ADIS16201_TEMP_OUT_REG ,ADIS16201_SCAN_TEMP ,0 ,12 ), +ADIS_AUX_ADC_CHAN (ADIS16201_AUX_ADC_REG ,ADIS16201_SCAN_AUX_ADC ,0 ,12 ), +ADIS_INCLI_CHAN (X ,ADIS16201_XINCL_OUT_REG ,ADIS16201_SCAN_INCLI_X , +BIT (IIO_CHAN_INFO_CALIBBIAS ),0 ,14 ), +IIO_CHAN_SOFT_TIMESTAMP (7 ),
As per the sashiko feedback on previous, this needs reordering so they are in scan index ordering.
drivers/iio/accel/adis16201.c static const struct iio_chan_spec adis16201_channels[] = { · line 243
Quoted 1 line
drivers/iio/accel/adis16201.c +1
-0+};
Otherwise this is coming together nicely.
Thanks
Jonathan
Re: [PATCH v2 1/6] iio: accel: adis16201: add SPI device ID table
In reply to Shehryar Ahmaddrivers/iio/accel/adis16201.c static int adis16201_probe(struct spi_device *spi) · line 293
Quoted 7 lines · Shehryar Ahmad
Add
spi_device_idtable for ADIS16201. ReplaceMODULE_ALIAS()withMODULE_DEVICE_TABLE()which automatically generates the same module alias.drivers/iio/accel/adis16201.c +3
-0+static const struct spi_device_id adis16201_ids[] = { + { .name ="adis16201" ,0 }, + { },
Learn the style what we use (hint: check last max half a year old new code in IIO).
Review
Quoted 2 lines
(quoted diff) +2
-0+}; +
This blank line is also the subject of the common style.
Quoted 1 line
+MODULE_DEVICE_TABLE(spi,
adis16201_ids);
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 2/6] iio: accel: adis16201: add OF device ID table
In reply to Shehryar AhmadQuoted 2 lines · Shehryar Ahmad
Add
of_device_idtable for adis16201 and register it withMODULE_DEVICE_TABLE()to enable device tree based matching.
Same comments as per previous patch.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v2 4/6] iio: accel: adis16201: add ADIS16203 support
In reply to Shehryar AhmadQuoted 8 lines · Shehryar Ahmad
Add ADIS16203 from staging to mainline ADIS16201. ADIS16203 shares same SPI protocol and register addresses. Differing parameters are handled by
adis16201_chip_infostructure.ADIS16203 specific support includes
DIAG_STAT_SELFTEST_FAIL_BIT, which is supported only on ADIS16203, and a separate channel array.
Kconfigis updated accordingly.
...
Quoted 4 lines
#define
ADIS16201_DIAG_STAT_REG0x3C
#defineADIS16201_DIAG_STAT_ALARM2BIT(9)
#defineADIS16201_DIAG_STAT_ALARM1BIT(8)
+#defineADIS16203_DIAG_STAT_SELFTEST_FAIL_BIT5 /* ADIS16203 only */
Two issues with this:
- indentation
- useless comment (we may kinda deduct this from the prefix)
Quoted 2 lines
#define
ADIS16201_DIAG_STAT_SPI_FAIL_BIT3
#defineADIS16201_DIAG_STAT_FLASH_UPT_FAIL_BIT2
...
drivers/iio/accel/adis16201.c static int adis16201_probe(struct spi_device *spi) · line 352
Quoted 4 lines
static const struct
of_device_idadis16201_of_match[] = {drivers/iio/accel/adis16201.c +1
-0{ .compatible = "adi,adis16201", .data = &adis16201_chip_data }, + { .compatible = "adi,adis16203", .data = &adis16203_chip_data }, { },
We want to have the common style for the terminator entries. Perhaps you need an additional patch to fix that.
Quoted 2 lines
};
(this blank line included).
...
drivers/iio/accel/adis16201.c MODULE_DEVICE_TABLE(of, adis16201_of_match); · line 361
Quoted 6 lines
static const struct
spi_device_idadis16201_ids[] = {drivers/iio/accel/adis16201.c +1
-0{ .name = "adis16201", .driver_data = (kernel_ulong_t)&adis16201_chip_data }, + { .name = "adis16203", .driver_data = (kernel_ulong_t)&adis16203_chip_data }, { }, };
Same as per above.
Quoted 1 line
module_spi_driver(adis16201_driver);
Signature · 2 lines
With Best Regards, Andy Shevchenko