[PATCH 13/18] iio: adc: ad4170-4: Restrict current sources and AC excitation to supported parts

From: Janani Sunil

Date: Thu Dec 03 2026 - 10:21:11 EST


The AD4190-4 and AD4195-4 have two excitation current sources instead
of four, and their CHOP_ADC field reserves the GPIO AC excitation codes
10 and 11. The driver allocates current sources across all channels
from four slots regardless of the device, so a third current-excited
channel programs the absent CURRENT_SOURCE2, and an AC-excited bridge
without excitation currents programs a reserved CHOP_ADC value.

Add the number of current sources and GPIO AC excitation support to
chip_info, bound the allocation by the former and reject the GPIO AC
excitation mode on devices without it.

Fixes: 6098df897d13 ("iio: adc: ad4170-4: Add support for weigh scale, thermocouple, and RTD sens")
Signed-off-by: Janani Sunil <janani.sunil@xxxxxxxxxx>
---
drivers/iio/adc/ad4170-4.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 5ffc845266a2..b96b6810e6ac 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -380,6 +380,8 @@ struct ad4170_chip_info {
const unsigned int *sinc5_filt_fs_tbl;
unsigned int sinc5_filt_fs_tbl_size;
unsigned int clock_div;
+ unsigned int num_current_src;
+ bool has_gpio_ac_excitation;
};

static const struct ad4170_chip_info ad4170_chip_info = {
@@ -387,6 +389,8 @@ static const struct ad4170_chip_info ad4170_chip_info = {
.sinc5_filt_fs_tbl = ad4170_sinc5_filt_fs_tbl,
.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl),
.clock_div = 1,
+ .num_current_src = 4,
+ .has_gpio_ac_excitation = true,
};

static const struct ad4170_chip_info ad4190_chip_info = {
@@ -394,6 +398,7 @@ static const struct ad4170_chip_info ad4190_chip_info = {
.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
.clock_div = 2,
+ .num_current_src = 2,
};

static const struct ad4170_chip_info ad4195_chip_info = {
@@ -401,6 +406,7 @@ static const struct ad4170_chip_info ad4195_chip_info = {
.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
.clock_div = 2,
+ .num_current_src = 2,
};

/*
@@ -1947,11 +1953,11 @@ static int ad4170_setup_current_src(struct ad4170_state *st,
unsigned int pin = exc_pins[i];
unsigned int current_src = 0;

- for (j = 0; j < AD4170_NUM_CURRENT_SRC; j++)
+ for (j = 0; j < st->chip->num_current_src; j++)
if (st->cur_src_pins[j] == AD4170_CURRENT_SRC_DISABLED)
break;

- if (j == AD4170_NUM_CURRENT_SRC)
+ if (j == st->chip->num_current_src)
return dev_err_probe(&st->spi->dev, -EINVAL,
"Too many excitation current sources\n");

@@ -2040,6 +2046,10 @@ static int ad4170_setup_bridge(struct ad4170_state *st,
exc_curs, num_exc_pins,
ac_excited);

+ if (!st->chip->has_gpio_ac_excitation)
+ return dev_err_probe(&st->spi->dev, -EINVAL,
+ "AC excitation through GPIOs not supported\n");
+
/*
* Else, use predefined ACX1, ACX1 negated, ACX2, ACX2 negated signals
* to AC excite the bridge. Those signals are output on GPIO2, GPIO0,

--
2.43.0