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

From: Jonathan Cameron

Date: Sun Jun 21 2026 - 15:08:43 EST


On Mon, 15 Jun 2026 17:00:02 -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>
Trivial stuff. Seems the bulk of discussion here is in the dt vs
channel mappings area. I'll probably reply to that in a few mins.

> @@ -449,25 +599,31 @@ static int ads112c14_write_raw(struct iio_dev *indio_dev,
> int val2, long mask)
> {
> struct ads112c14_data *data = iio_priv(indio_dev);
> + const int (*scale_avail)[2];
> + u8 *gain_val;
> +
> + if (chan->channel == ADS112C14_SYS_MON_CHANNEL_SHORT) {
> + scale_avail = data->sys_mon_chan_short_scale_available;
> + gain_val = &data->sys_mon_chan_short_gain_val;
> + } else if (chan->channel < 100) {
> + scale_avail = data->measurements[chan->scan_index].scale_available;
> + gain_val = &data->measurements[chan->scan_index].gain_val;
> + } else {
> + return -EINVAL;
> + }
>
> - switch (chan->channel) {
> - case ADS112C14_SYS_MON_CHANNEL_SHORT: {
> - IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> - if (IIO_DEV_ACQUIRE_FAILED(claim))
> - return -EBUSY;
> + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> + if (IIO_DEV_ACQUIRE_FAILED(claim))
> + return -EBUSY;
Anything stop you doing this in the earlier patch?

>
> - for (u32 i = 0; i < ARRAY_SIZE(data->sys_mon_chan_short_scale_available); i++) {
> - if (val == data->sys_mon_chan_short_scale_available[i][0] &&
> - val2 == data->sys_mon_chan_short_scale_available[i][1]) {
> - data->sys_mon_chan_short_gain_val = i;
> - return 0;
> - }
> + for (u32 i = 0; i < ARRAY_SIZE(ads112c14_pga_gains_x10); i++) {
> + if (val == scale_avail[i][0] && val2 == scale_avail[i][1]) {
> + *gain_val = i;
> + return 0;
> }
> - return -EINVAL;
> - }
> - default:
> - return -EINVAL;
> }
> +
> + return -EINVAL;
> }
>

>
> static int ads112c14_probe(struct i2c_client *client)
> @@ -547,6 +876,9 @@ static int ads112c14_probe(struct i2c_client *client)
> const struct ads112c14_chip_info *info;
> struct iio_dev *indio_dev;
> struct ads112c14_data *data;
> + bool need_avdd_ref, need_ext_ref;
> + u32 refp_uV = 0;
> + u32 refn_uV = 0;
> u32 reg_val;
> int ret;
>
>
> + if (device_property_present(dev, "refp-supply")) {
> + ret = devm_regulator_get_enable_read_voltage(&client->dev, "refp");
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to get refp voltage\n");
> +
> + refp_uV = ret;
> +
> + struct fwnode_handle *refp_fwnode __free(fwnode_handle) =
> + fwnode_find_reference(dev->fwnode, "refp-supply", 0);
> + if (IS_ERR(refp_fwnode))
> + return dev_err_probe(dev, PTR_ERR(refp_fwnode),
> + "failed to get refp fwnode\n");
> +
> + struct fwnode_handle *avdd_fwnode __free(fwnode_handle) =
> + fwnode_find_reference(dev->fwnode, "avdd-supply", 0);
> + if (IS_ERR(avdd_fwnode))
> + return dev_err_probe(dev, PTR_ERR(avdd_fwnode),
> + "failed to get avdd fwnode\n");
> +
> + data->refp_is_avdd = refp_fwnode == avdd_fwnode;

Add a comment somewhere on why we care. I wonder how common this is. Maybe
a generic helper? Even if it isn't common lets have a helper here!
fwnode_same_reference() or something like that.


> + }
> +
> + if (device_property_present(dev, "refn-supply")) {
> + ret = devm_regulator_get_enable_read_voltage(&client->dev, "refn");
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to get refn voltage\n");
> +
> + refn_uV = ret;
> + } else {
> + data->refn_is_gnd = true;
> + }
> +
> + data->ext_ref_uV = refp_uV - refn_uV;
> +
> + if (device_property_present(dev, "refp-refn-resistor-ohms")) {
> + if (refp_uV != 0 || refn_uV != 0)
> + return dev_err_probe(dev, -EINVAL,
> + "refp-refn-resistor-ohms property should not be present when refp-supply or refn-supply is present\n");
> +
> + ret = device_property_read_u32(dev, "refp-refn-resistor-ohms",
> + &data->ext_ref_ohms);
> + if (ret)
> + return dev_err_probe(dev, ret,
> + "failed to read refp-refn-resistor-ohms property\n");
> + } else {
> + if (need_ext_ref && data->ext_ref_uV == 0)
> + return dev_err_probe(dev, -EINVAL,
> + "external reference measurements require either refp-supply or refp-refn-resistor-ohms property\n");

> + }