Re: [PATCH v3 8/8] iio: adc: ti-ads112c14: add measurement channel support

From: Jonathan Cameron

Date: Sun Jul 12 2026 - 22:36:00 EST


On Fri, 10 Jul 2026 17:50:41 -0500
"David Lechner (TI)" <dlechner@xxxxxxxxxxxx> wrote:

> Add support for parsing devicetree properties for measurement channels
> and doing direct reads on these.
>
> There are quite a lot of conditions that have to be met for each
> measurement to be made, so quite a bit of state and algorithms are
> required to handle it.
>
> Channels are created dynamically since the number of possibilities is
> unreasonably large.
>
> Signed-off-by: David Lechner (TI) <dlechner@xxxxxxxxxxxx>
A few little things,

Thanks,

Jonathan

> ---
> v3 changes:
> * Checked error when getting "label" property.
> * Removed call of fwnode_device_is_available().
> * Used IIO_VAL_DECIMAL64_PICO for scale.
> * Added switch in ads112c14_read_avail() to reduce future diff.
>
> v2 changes:
> * Adapted for changes in DT bindings.
> * Fixed bug in IDAC current register value calculation.
> * Fix uninitialized variable bug.
> * Fix bug in data->num_measurements calculation.
> * Use IIO_RESISTANCE instead of IIO_VOLTAGE when external reference is
> used and it is a resistor rather than a voltage source.
> * Fix bug with negative input mux selection on single-ended measurements.
> * Fixed return checks of devm_regulator_get_enable_read_voltage().
> ---
> drivers/iio/adc/ti-ads112c14.c | 551 +++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 533 insertions(+), 18 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
> index 2ce4411a0d86..a310abd69d8f 100644
> --- a/drivers/iio/adc/ti-ads112c14.c
> +++ b/drivers/iio/adc/ti-ads112c14.c
> @@ -200,9 +222,32 @@ static const struct iio_chan_spec ads112c14_sys_mon_channels[] = {
> },
> };
>
> +struct ads112c14_measurement {
> + const char *label;
> + u32 vref_source;
> + u8 iunit;
> + u8 idac1_mag;
> + u8 idac2_mag;
> + u8 idac1_mux;
> + u8 idac2_mux;
> + u8 iadc_count;
> + u8 gain_val;
> + u8 burnout;

Sashiko calls out that this is set but not used.
I'd leave parsing the stuff to set it for now and bring that in when
you want burnt out support.

> + bool global_chop;
> + bool bipolar;
> + s64 scale_available[ARRAY_SIZE(ads112c14_pga_gains_x10)];
> +};

> @@ -257,12 +302,113 @@ static const struct regmap_config ads112c14_regmap_config = {
> .cache_type = REGCACHE_MAPLE,
> };
>
> +static int ads112c14_prepare_measurement_channel(struct ads112c14_data *data,
> + const struct iio_chan_spec *chan)
> +{
> + struct ads112c14_measurement *measurement = &data->measurements[chan->scan_index];
> + u32 refp_buf_en, refn_buf_en, ref_val, ref_sel;
> + int ret;
> +
> + ret = regmap_update_bits(data->regmap, ADS112C14_REG_MUX_CFG,
> + ADS112C14_MUX_CFG_AINP | ADS112C14_MUX_CFG_AINN,
> + FIELD_PREP(ADS112C14_MUX_CFG_AINP, chan->channel) |
> + FIELD_PREP(ADS112C14_MUX_CFG_AINN, chan->channel2));
> + if (ret)
> + return ret;
> +
> + ret = regmap_update_bits(data->regmap, ADS112C14_REG_DIGITAL_CFG,
> + ADS112C14_DIGITAL_CFG_CODING,
> + FIELD_PREP(ADS112C14_DIGITAL_CFG_CODING,
> + measurement->bipolar ? 0 : 1));

You could use regmap_assign_bits(data->regmap, ADS112C14_REG_DIGITAL_CFG,
ADS112C14_DIGITAL_CFG_CODING,
measurement->bipolar);

I'm not particularly sure that is any clearer however so up to you.


> @@ -436,14 +592,29 @@ static int ads112c14_read_avail(struct iio_dev *indio_dev,
> {
> struct ads112c14_data *data = iio_priv(indio_dev);
>
> - if (chan->channel == ADS112C14_SYS_MON_CHANNEL_SHORT) {
> - *vals = (const int *)data->sys_mon_chan_short_scale_available;
> - *length = 2 * ARRAY_SIZE(data->sys_mon_chan_short_scale_available);
> - *type = IIO_VAL_DECIMAL64_PICO;
> - return IIO_AVAIL_LIST;
> - }
> + switch (mask) {
> + case IIO_CHAN_INFO_SCALE:

Move introduction of switch to earlier patch? Doesn't look like it would
be wrong at that point and it would reduce churn a tiny bit.

> + if (chan->channel < ADS112C14_SYS_MON_CHANNEL_BASE) {
> + struct ads112c14_measurement *measurement;
> +
> + measurement = &data->measurements[chan->scan_index];
> + *vals = (const int *)measurement->scale_available;
> + *length = 2 * ARRAY_SIZE(measurement->scale_available);
> + *type = IIO_VAL_DECIMAL64_PICO;
> + return IIO_AVAIL_LIST;
> + }
> +
> + if (chan->channel == ADS112C14_SYS_MON_CHANNEL_SHORT) {
> + *vals = (const int *)data->sys_mon_chan_short_scale_available;
> + *length = 2 * ARRAY_SIZE(data->sys_mon_chan_short_scale_available);
> + *type = IIO_VAL_DECIMAL64_PICO;
> + return IIO_AVAIL_LIST;
> + }
>
> - return -EINVAL;
> + return -EINVAL;
> + default:
> + return -EINVAL;
> + }
> }