[PATCH 14/18] iio: adc: ad4170-4: Require equal chopped excitation currents
From: Janani Sunil
Date: Thu Dec 03 2026 - 10:21:35 EST
Excitation current chopping periodically swaps the output pins of a
pair of current sources, which the datasheets state requires both
currents to have the same value. The driver enables chopping without
checking the currents, so a pair with an omitted, zero, or different
current is accepted and chopped. It also accepts three excitation
sources, of which only the first pair can be chopped.
Reject current chopping unless it uses two or four excitation sources
and both currents of each chopped pair are nonzero and equal.
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 | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index b96b6810e6ac..424be6fb851e 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -1948,6 +1948,20 @@ static int ad4170_setup_current_src(struct ad4170_state *st,
unsigned int exc_cur_pair, i, j;
int ret;
+ if (ac_excited) {
+ if ((num_exc_pins != 2 && num_exc_pins != 4) ||
+ num_exc_pins > st->chip->num_current_src)
+ return dev_err_probe(&st->spi->dev, -EINVAL,
+ "Invalid excitation pin count for current chopping: %d\n",
+ num_exc_pins);
+
+ /* Chopped excitation currents are swapped in pairs of equal value. */
+ for (i = 0; i < num_exc_pins; i += 2)
+ if (!exc_curs[i] || exc_curs[i] != exc_curs[i + 1])
+ return dev_err_probe(&st->spi->dev, -EINVAL,
+ "Chopped excitation currents must be equal and nonzero\n");
+ }
+
for (i = 0; i < num_exc_pins; i++) {
unsigned int exc_cur = exc_curs[i];
unsigned int pin = exc_pins[i];
@@ -1973,11 +1987,6 @@ static int ad4170_setup_current_src(struct ad4170_state *st,
if (!ac_excited)
return 0;
- if (num_exc_pins < 2)
- return dev_err_probe(&st->spi->dev, -EINVAL,
- "Current chopping requested but only one pin provided: %u\n",
- exc_pins[0]);
-
/*
* Two use cases to handle here:
* - 2 pairs of excitation currents;
--
2.43.0