[PATCH 18/18] iio: adc: ad4170-4: Add support for AD4171-8, AD4190-8 and AD4195-8
From: Janani Sunil
Date: Thu Dec 03 2026 - 10:21:44 EST
The AD4171-8, AD4190-8, and AD4195-8 are eight differential input members
of the AD4170 family. They expose analog inputs AIN0 to AIN15 plus a
dedicated AINCOM pin. The AD4190-8 and AD4195-8 have no integrated DAC and
share the AD4190-4 sinc5 FS range and clock divider, while the AD4171-8
keeps the AD4170-4 feature set, so its maximum output data rate is
500 kSPS.
Move the remaining per-device difference, the analog pin count, into
chip_info so input validation adapts at runtime. That also lifts the
adi,vbias-pins count limit to the nine analog input pins the four input
devices actually have.
AINCOM (input number 16) can be the positive or negative input of a
channel on these parts. Accept it during channel input validation, and
track its use separately from pins_fn[], which only tracks the regular
analog input pins, so that AINCOM follows the same rules as those pins
when shared between channel inputs and excitation current outputs.
CURRENT_SOURCEn I_OUT_PIN accepts the same set of inputs, so excitation
pin validation follows the analog pin count as well and accepts AINCOM
where it exists.
Signed-off-by: Janani Sunil <janani.sunil@xxxxxxxxxx>
---
drivers/iio/adc/Kconfig | 5 +--
drivers/iio/adc/ad4170-4.c | 85 +++++++++++++++++++++++++++++++++++++++-------
2 files changed, 76 insertions(+), 14 deletions(-)
diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig
index 82e2eb652e16..4aff5c620c8c 100644
--- a/drivers/iio/adc/Kconfig
+++ b/drivers/iio/adc/Kconfig
@@ -149,8 +149,9 @@ config AD4170_4
depends on COMMON_CLK
depends on GPIOLIB
help
- Say yes here to build support for Analog Devices AD4170-4 SPI analog
- to digital converters (ADC).
+ Say yes here to build support for Analog Devices AD4170-4, AD4171-8,
+ AD4190-4, AD4190-8, AD4195-4, and AD4195-8 SPI analog to digital
+ converters (ADC).
To compile this driver as a module, choose M here: the module will be
called ad4170-4.
diff --git a/drivers/iio/adc/ad4170-4.c b/drivers/iio/adc/ad4170-4.c
index 6c3b3b3a387a..7c16fc784c92 100644
--- a/drivers/iio/adc/ad4170-4.c
+++ b/drivers/iio/adc/ad4170-4.c
@@ -139,6 +139,7 @@
/* AD4170_CHAN_MAP_REG constants */
#define AD4170_CHAN_MAP_AIN(x) (x)
+#define AD4170_CHAN_MAP_AINCOM 16
#define AD4170_CHAN_MAP_TEMP_SENSOR 17
#define AD4170_CHAN_MAP_AVDD_AVSS_P 18
#define AD4170_CHAN_MAP_AVDD_AVSS_N 18
@@ -184,11 +185,10 @@
/* Device properties and auxiliary constants */
-#define AD4170_NUM_ANALOG_PINS 9
#define AD4170_NUM_GPIO_PINS 4
#define AD4170_MAX_ADC_CHANNELS 16
#define AD4170_MAX_IIO_CHANNELS (AD4170_MAX_ADC_CHANNELS + 1)
-#define AD4170_MAX_ANALOG_PINS 8
+#define AD4170_MAX_ANALOG_PINS 16
#define AD4170_MAX_SETUPS 8
#define AD4170_INVALID_SETUP 9
#define AD4170_SPI_INST_PHASE_LEN 2
@@ -363,8 +363,10 @@ struct ad4170_chip_info {
const char *name;
const unsigned int *sinc5_filt_fs_tbl;
unsigned int sinc5_filt_fs_tbl_size;
+ unsigned int num_analog_pins;
unsigned int clock_div;
unsigned int num_current_src;
+ bool has_aincom;
bool has_gpio_ac_excitation;
};
@@ -372,15 +374,28 @@ static const struct ad4170_chip_info ad4170_chip_info = {
.name = "ad4170-4",
.sinc5_filt_fs_tbl = ad4170_sinc5_filt_fs_tbl,
.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl),
+ .num_analog_pins = 9,
.clock_div = 1,
.num_current_src = 4,
.has_gpio_ac_excitation = true,
};
+static const struct ad4170_chip_info ad4171_8_chip_info = {
+ .name = "ad4171-8",
+ .sinc5_filt_fs_tbl = ad4170_sinc5_filt_fs_tbl,
+ .sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4170_sinc5_filt_fs_tbl),
+ .num_analog_pins = 16,
+ .clock_div = 1,
+ .num_current_src = 4,
+ .has_aincom = true,
+ .has_gpio_ac_excitation = true,
+};
+
static const struct ad4170_chip_info ad4190_chip_info = {
.name = "ad4190-4",
.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
+ .num_analog_pins = 9,
.clock_div = 2,
.num_current_src = 2,
};
@@ -389,10 +404,31 @@ static const struct ad4170_chip_info ad4195_chip_info = {
.name = "ad4195-4",
.sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
.sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
+ .num_analog_pins = 9,
.clock_div = 2,
.num_current_src = 2,
};
+static const struct ad4170_chip_info ad4190_8_chip_info = {
+ .name = "ad4190-8",
+ .sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
+ .sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
+ .num_analog_pins = 16,
+ .clock_div = 2,
+ .num_current_src = 2,
+ .has_aincom = true,
+};
+
+static const struct ad4170_chip_info ad4195_8_chip_info = {
+ .name = "ad4195-8",
+ .sinc5_filt_fs_tbl = ad4190_sinc5_filt_fs_tbl,
+ .sinc5_filt_fs_tbl_size = ARRAY_SIZE(ad4190_sinc5_filt_fs_tbl),
+ .num_analog_pins = 16,
+ .clock_div = 2,
+ .num_current_src = 2,
+ .has_aincom = true,
+};
+
/*
* There are 8 of each MISC, AFE, FILTER, FILTER_FS, OFFSET, and GAIN
* configuration registers. That is, there are 8 miscellaneous registers, MISC0
@@ -458,7 +494,8 @@ struct ad4170_state {
struct iio_trigger *trig;
struct clk_hw int_clk_hw;
unsigned int clock_ctrl;
- unsigned int pins_fn[AD4170_NUM_ANALOG_PINS];
+ unsigned int pins_fn[AD4170_MAX_ANALOG_PINS];
+ unsigned int aincom_fn;
int gpio_fn[AD4170_NUM_GPIO_PINS];
unsigned int cur_src_pins[AD4170_NUM_CURRENT_SRC];
struct gpio_chip gpiochip;
@@ -975,9 +1012,9 @@ static const struct iio_chan_spec ad4170_temp_channel_template = {
/*
* Receives the number of a multiplexed AD4170 input (ain_n), and stores the
* voltage (in µV) of the specified input into ain_voltage. If the input number
- * is a ordinary analog input (AIN0 to AIN8), stores zero into ain_voltage.
- * If a voltage regulator required by a special input is unavailable, return
- * error code. Return 0 on success.
+ * is an ordinary analog input pin, AINCOM, or the temperature sensor, stores
+ * zero into ain_voltage. If a voltage regulator required by a special input is
+ * unavailable, return error code. Return 0 on success.
*/
static int ad4170_get_ain_voltage_uv(struct ad4170_state *st, int ain_n,
int *ain_voltage)
@@ -993,7 +1030,7 @@ static int ad4170_get_ain_voltage_uv(struct ad4170_state *st, int ain_n,
* So, we do AVDD - AVSS to compute the DC voltage generated by the bias
* voltage generator.
*/
- if (ain_n < AD4170_NUM_ANALOG_PINS &&
+ if (ain_n < st->chip->num_analog_pins &&
st->pins_fn[ain_n] & AD4170_PIN_VBIAS) {
int v_diff = st->vrefs_uv[AD4170_AVDD_SUP] - st->vrefs_uv[AD4170_AVSS_SUP];
*ain_voltage = v_diff / 2;
@@ -1056,7 +1093,7 @@ static int ad4170_get_ain_voltage_uv(struct ad4170_state *st, int ain_n,
static int ad4170_validate_analog_input(struct ad4170_state *st, int pin)
{
- if (pin <= AD4170_MAX_ANALOG_PINS) {
+ if (pin < st->chip->num_analog_pins) {
if (st->pins_fn[pin] & AD4170_PIN_CURRENT_OUT)
return dev_err_probe(&st->spi->dev, -EINVAL,
"Pin %d already used with fn %u.\n",
@@ -1069,6 +1106,16 @@ static int ad4170_validate_analog_input(struct ad4170_state *st, int pin)
static int ad4170_validate_channel_input(struct ad4170_state *st, int pin, bool com)
{
+ if (st->chip->has_aincom && pin == AD4170_CHAN_MAP_AINCOM) {
+ if (st->aincom_fn & AD4170_PIN_CURRENT_OUT)
+ return dev_err_probe(&st->spi->dev, -EINVAL,
+ "AINCOM already used with fn %u.\n",
+ st->aincom_fn);
+
+ st->aincom_fn |= AD4170_PIN_ANALOG_IN;
+ return 0;
+ }
+
/* Check common-mode input pin is mapped to a special input. */
if (com && (pin < AD4170_CHAN_MAP_AVDD_AVSS_P || pin > AD4170_CHAN_MAP_REFOUT))
return dev_err_probe(&st->spi->dev, -EINVAL,
@@ -1076,7 +1123,7 @@ static int ad4170_validate_channel_input(struct ad4170_state *st, int pin, bool
pin);
/* Check differential input pin is mapped to a analog input pin. */
- if (!com && pin > AD4170_MAX_ANALOG_PINS)
+ if (!com && pin >= st->chip->num_analog_pins)
return dev_err_probe(&st->spi->dev, -EINVAL,
"Invalid analog input pin number. %d\n",
pin);
@@ -1815,7 +1862,7 @@ static int ad4170_validate_excitation_pin(struct ad4170_state *st, u32 pin)
struct device *dev = &st->spi->dev;
/* Check the pin number is valid and the pin is available */
- if (pin <= AD4170_MAX_ANALOG_PINS) {
+ if (pin < st->chip->num_analog_pins) {
if (st->pins_fn[pin] != AD4170_PIN_UNASSIGNED)
return dev_err_probe(dev, -EINVAL,
"Pin %u already used with fn %u\n",
@@ -1834,6 +1881,14 @@ static int ad4170_validate_excitation_pin(struct ad4170_state *st, u32 pin)
st->gpio_fn[gpio] |= AD4170_GPIO_AC_EXCITATION;
return 0;
+ } else if (st->chip->has_aincom && pin == AD4170_CHAN_MAP_AINCOM) {
+ if (st->aincom_fn != AD4170_PIN_UNASSIGNED)
+ return dev_err_probe(dev, -EINVAL,
+ "AINCOM already used with fn %u\n",
+ st->aincom_fn);
+
+ st->aincom_fn |= AD4170_PIN_CURRENT_OUT;
+ return 0;
}
return dev_err_probe(dev, -EINVAL, "Invalid excitation pin: %u\n", pin);
@@ -2564,7 +2619,7 @@ static int ad4170_parse_firmware(struct iio_dev *indio_dev)
ret = device_property_count_u32(dev, "adi,vbias-pins");
if (ret > 0) {
- if (ret > AD4170_MAX_ANALOG_PINS)
+ if (ret > st->chip->num_analog_pins)
return dev_err_probe(dev, -EINVAL,
"Too many vbias pins %u\n", ret);
@@ -2578,7 +2633,7 @@ static int ad4170_parse_firmware(struct iio_dev *indio_dev)
"Failed to read vbias pins\n");
for (i = 0; i < num_vbias_pins; i++) {
- if (vbias_pins[i] >= AD4170_NUM_ANALOG_PINS)
+ if (vbias_pins[i] >= st->chip->num_analog_pins)
return dev_err_probe(dev, -EINVAL,
"Invalid vbias pin %u\n",
vbias_pins[i]);
@@ -2996,16 +3051,22 @@ static int ad4170_probe(struct spi_device *spi)
static const struct spi_device_id ad4170_id_table[] = {
{ .name = "ad4170-4", .driver_data = (kernel_ulong_t)&ad4170_chip_info },
+ { .name = "ad4171-8", .driver_data = (kernel_ulong_t)&ad4171_8_chip_info },
{ .name = "ad4190-4", .driver_data = (kernel_ulong_t)&ad4190_chip_info },
+ { .name = "ad4190-8", .driver_data = (kernel_ulong_t)&ad4190_8_chip_info },
{ .name = "ad4195-4", .driver_data = (kernel_ulong_t)&ad4195_chip_info },
+ { .name = "ad4195-8", .driver_data = (kernel_ulong_t)&ad4195_8_chip_info },
{ }
};
MODULE_DEVICE_TABLE(spi, ad4170_id_table);
static const struct of_device_id ad4170_of_match[] = {
{ .compatible = "adi,ad4170-4", .data = &ad4170_chip_info },
+ { .compatible = "adi,ad4171-8", .data = &ad4171_8_chip_info },
{ .compatible = "adi,ad4190-4", .data = &ad4190_chip_info },
+ { .compatible = "adi,ad4190-8", .data = &ad4190_8_chip_info },
{ .compatible = "adi,ad4195-4", .data = &ad4195_chip_info },
+ { .compatible = "adi,ad4195-8", .data = &ad4195_8_chip_info },
{ }
};
MODULE_DEVICE_TABLE(of, ad4170_of_match);
--
2.43.0