[PATCH 06/18] iio: adc: ad4170-4: Fix voltage bias programming

From: Janani Sunil

Date: Thu Dec 03 2026 - 10:20:49 EST


The adi,vbias-pins are recorded in pins_fn[] when parsing the firmware,
but V_BIAS is only written while setting up a thermocouple with
excitation properties. The bias is therefore never applied for other
channels, each thermocouple write replaces the whole register so a
later channel clears the bias of an earlier one, and a write failure is
logged and then discarded.

Program V_BIAS once with all the listed pins after parsing them, and
fail probe if the write fails.

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 | 18 +++++++-----------
1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 9bad480e69d7..f353b630834e 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -2114,7 +2114,7 @@ static int ad4170_parse_external_sensor(struct ad4170_state *st,
struct iio_chan_spec *chan,
unsigned int s_type)
{
- unsigned int num_exc_pins, reg_val;
+ unsigned int num_exc_pins;
struct device *dev = &st->spi->dev;
u32 pins[2], exc_pins[4], exc_curs[4];
bool ac_excited;
@@ -2144,15 +2144,6 @@ static int ad4170_parse_external_sensor(struct ad4170_state *st,

ac_excited = fwnode_property_read_bool(child, "adi,excitation-ac");

- if (s_type == AD4170_THERMOCOUPLE_SENSOR) {
- if (chan->channel2 < AD4170_NUM_ANALOG_PINS &&
- st->pins_fn[chan->channel2] & AD4170_PIN_VBIAS) {
- reg_val = BIT(chan->channel2);
- ret = regmap_write(st->regmap, AD4170_V_BIAS_REG, reg_val);
- if (ret)
- dev_err_probe(dev, ret, "Failed to set vbias\n");
- }
- }
if (s_type == AD4170_WEIGH_SCALE_SENSOR)
ret = ad4170_setup_bridge(st, child, setup, exc_pins, exc_curs,
num_exc_pins, ac_excited);
@@ -2521,7 +2512,7 @@ static int ad4170_parse_firmware(struct iio_dev *indio_dev)
unsigned int vbias_pins[AD4170_MAX_ANALOG_PINS];
struct ad4170_state *st = iio_priv(indio_dev);
struct device *dev = &st->spi->dev;
- unsigned int num_vbias_pins;
+ unsigned int num_vbias_pins, vbias_mask = 0;
int reg_data, ret;
u32 int_pin_sel;
unsigned int i;
@@ -2577,7 +2568,12 @@ static int ad4170_parse_firmware(struct iio_dev *indio_dev)
vbias_pins[i]);

st->pins_fn[vbias_pins[i]] |= AD4170_PIN_VBIAS;
+ vbias_mask |= BIT(vbias_pins[i]);
}
+
+ ret = regmap_write(st->regmap, AD4170_V_BIAS_REG, vbias_mask);
+ if (ret)
+ return dev_err_probe(dev, ret, "Failed to set vbias\n");
}

ret = ad4170_parse_channels(indio_dev);

--
2.43.0