Re: [PATCH v9 8/8] iio: adc: ad4030: Support common-mode channels with SPI offloading
From: Jonathan Cameron
Date: Sun Feb 22 2026 - 08:02:40 EST
On Mon, 16 Feb 2026 12:01:27 -0300
Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx> wrote:
> AD4030 and similar devices can read common-mode voltage together with
> ADC sample data. When enabled, common-mode voltage data is provided in a
> separate IIO channel since it measures something other than the primary
> ADC input signal and requires separate scaling to convert to voltage
> units. The initial SPI offload support patch for AD4030 only provided
> differential channels. Now, extend the AD4030 driver to also provide
> common-mode IIO channels when setup with SPI offloading capability.
>
> Reviewed-by: David Lechner <dlechner@xxxxxxxxxxxx>
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx>
> static int ad4030_regulators_get(struct ad4030_state *st)
> @@ -1409,43 +1422,19 @@ static int ad4030_spi_offload_setup(struct iio_dev *indio_dev,
> static int ad4030_setup_pga(struct device *dev, struct iio_dev *indio_dev,
> struct ad4030_state *st)
> {
> - unsigned int i;
> - int pga_gain_dB;
> - int ret;
> + /* Setup GPIOs for PGA control */
> + st->pga_gpios = devm_gpiod_get_array(dev, "pga", GPIOD_OUT_LOW);
> + if (IS_ERR(st->pga_gpios))
> + return dev_err_probe(dev, PTR_ERR(st->pga_gpios),
> + "Failed to get PGA gpios.\n");
>
> - ret = device_property_read_u32(dev, "adi,pga-gain-db", &pga_gain_dB);
This had me confused, but I guess is patch break up stuff you mention in reply
to Andy in patch 7. So I'll wait for v10 before taking another look.
> - if (ret == -EINVAL) {
> - /* Setup GPIOs for PGA control */
> - st->pga_gpios = devm_gpiod_get_array(dev, "pga", GPIOD_OUT_LOW);
> - if (IS_ERR(st->pga_gpios))
> - return dev_err_probe(dev, PTR_ERR(st->pga_gpios),
> - "Failed to get PGA gpios.\n");
> + if (st->pga_gpios->ndescs != ADAQ4616_PGA_PINS)
> + return dev_err_probe(dev, -EINVAL,
> + "Expected %d GPIOs for PGA control.\n",
> + ADAQ4616_PGA_PINS);
>
> - if (st->pga_gpios->ndescs != ADAQ4616_PGA_PINS)
> - return dev_err_probe(dev, -EINVAL,
> - "Expected 2 GPIOs for PGA control.\n");
> -
> - st->scale_avail_size = ARRAY_SIZE(adaq4216_hw_gains_db);
> - st->pga_index = 0;
> - return 0;
> - } else if (ret) {
> - return dev_err_probe(dev, ret, "Failed to get PGA value.\n");
> - }
> -
> - /* Set ADC driver to handle pin-strapped PGA pins setup */
> - for (i = 0; i < ARRAY_SIZE(adaq4216_hw_gains_db); i++) {
> - if (pga_gain_dB != adaq4216_hw_gains_db[i])
> - continue;
> -
> - st->pga_index = i;
> - break;
> - }
> - if (i == ARRAY_SIZE(adaq4216_hw_gains_db))
> - return dev_err_probe(dev, -EINVAL, "Invalid PGA gain: %d.\n",
> - pga_gain_dB);
> -
> - st->scale_avail_size = 1;
> - st->pga_gpios = NULL;
> + st->scale_avail_size = ARRAY_SIZE(adaq4216_hw_gains_vpv);
> + st->pga_index = 0;
>
> return 0;
> }