[PATCH 16/18] iio: adc: ad4170-4: Drop ad4170_iout_pin_tbl

From: Janani Sunil

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


The valid CURRENT_SOURCEn I_OUT_PIN values are the analog input pins and
GPIO0 to GPIO3, which are two contiguous ranges. Check them directly
instead of looking the pin up in a table listing every value, and check
the pin availability in the same branch that identifies the pin type.

This prepares for devices with a different number of analog input pins,
for which a fixed table of valid pins would no longer fit.

No functional change intended.

Signed-off-by: Janani Sunil <janani.sunil@xxxxxxxxxx>
---
drivers/iio/adc/ad4170-4.c | 36 ++++++------------------------------
1 file changed, 6 insertions(+), 30 deletions(-)

diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 7062ef306f58..6c3b3b3a387a 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -340,22 +340,6 @@ static const unsigned int ad4190_sinc5_filt_fs_tbl[] = {
4, 8, 12, 16, 20, 40, 48, 80, 100, 256,
};

-static const unsigned int ad4170_iout_pin_tbl[] = {
- AD4170_CURRENT_SRC_I_OUT_PIN_AIN(0),
- AD4170_CURRENT_SRC_I_OUT_PIN_AIN(1),
- AD4170_CURRENT_SRC_I_OUT_PIN_AIN(2),
- AD4170_CURRENT_SRC_I_OUT_PIN_AIN(3),
- AD4170_CURRENT_SRC_I_OUT_PIN_AIN(4),
- AD4170_CURRENT_SRC_I_OUT_PIN_AIN(5),
- AD4170_CURRENT_SRC_I_OUT_PIN_AIN(6),
- AD4170_CURRENT_SRC_I_OUT_PIN_AIN(7),
- AD4170_CURRENT_SRC_I_OUT_PIN_AIN(8),
- AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(0),
- AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(1),
- AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(2),
- AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(3),
-};
-
static const unsigned int ad4170_iout_current_ua_tbl[] = {
0, 10, 50, 100, 250, 500, 1000, 1500,
};
@@ -1829,19 +1813,8 @@ static int ad4170_gpio_init(struct iio_dev *indio_dev)
static int ad4170_validate_excitation_pin(struct ad4170_state *st, u32 pin)
{
struct device *dev = &st->spi->dev;
- unsigned int i;
-
- /* Check the pin number is valid */
- for (i = 0; i < ARRAY_SIZE(ad4170_iout_pin_tbl); i++)
- if (ad4170_iout_pin_tbl[i] == pin)
- break;
-
- if (i == ARRAY_SIZE(ad4170_iout_pin_tbl))
- return dev_err_probe(dev, -EINVAL,
- "Invalid excitation pin: %u\n",
- pin);

- /* Check the pin is available */
+ /* Check the pin number is valid and the pin is available */
if (pin <= AD4170_MAX_ANALOG_PINS) {
if (st->pins_fn[pin] != AD4170_PIN_UNASSIGNED)
return dev_err_probe(dev, -EINVAL,
@@ -1849,7 +1822,9 @@ static int ad4170_validate_excitation_pin(struct ad4170_state *st, u32 pin)
pin, st->pins_fn[pin]);

st->pins_fn[pin] |= AD4170_PIN_CURRENT_OUT;
- } else {
+ return 0;
+ } else if (in_range(pin, AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(0),
+ AD4170_NUM_GPIO_PINS)) {
unsigned int gpio = pin - AD4170_CURRENT_SRC_I_OUT_PIN_GPIO(0);

if (st->gpio_fn[gpio] != AD4170_GPIO_UNASSIGNED)
@@ -1858,9 +1833,10 @@ static int ad4170_validate_excitation_pin(struct ad4170_state *st, u32 pin)
gpio, st->gpio_fn[gpio]);

st->gpio_fn[gpio] |= AD4170_GPIO_AC_EXCITATION;
+ return 0;
}

- return 0;
+ return dev_err_probe(dev, -EINVAL, "Invalid excitation pin: %u\n", pin);
}

static int ad4170_validate_excitation_pins(struct ad4170_state *st,

--
2.43.0