From: Jonathan Cameron <jic23@kernel.org>
To: "David Lechner (TI)" <dlechner@baylibre.com>
Cc: "Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Kurt Borja" <kuurtb@gmail.com>,
"Nguyen Minh Tien" <zizuzacker@gmail.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] iio: adc: ti-ads112c14: add measurement channel support
Date: Sun, 21 Jun 2026 20:08:21 +0100 [thread overview]
Message-ID: <20260621200821.0cfffe34@jic23-huawei> (raw)
In-Reply-To: <20260615-iio-adc-ti-ads122c14-v1-4-e6bdadf7cb2b@baylibre.com>
On Mon, 15 Jun 2026 17:00:02 -0500
"David Lechner (TI)" <dlechner@baylibre.com> 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@baylibre.com>
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");
> + }
next prev parent reply other threads:[~2026-06-21 19:08 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-15 21:59 [PATCH 0/4] iio: adc: new ti-ads112c14 driver David Lechner (TI)
2026-06-15 21:59 ` [PATCH 1/4] dt-bindings: iio: adc: add ti,ads122c14 David Lechner (TI)
2026-06-15 22:10 ` sashiko-bot
2026-06-16 0:26 ` Kurt Borja
2026-06-16 15:22 ` David Lechner
2026-06-16 17:31 ` Kurt Borja
2026-06-16 16:07 ` Conor Dooley
2026-06-16 19:54 ` David Lechner
2026-06-16 20:50 ` Conor Dooley
2026-06-16 21:04 ` David Lechner
2026-06-17 15:34 ` Conor Dooley
2026-06-21 18:41 ` Jonathan Cameron
2026-06-21 21:14 ` David Lechner
2026-06-15 22:00 ` [PATCH 2/4] iio: adc: add ti-ads112c14 driver David Lechner (TI)
2026-06-15 22:11 ` sashiko-bot
2026-06-16 7:32 ` Andy Shevchenko
2026-06-16 15:38 ` David Lechner
2026-06-17 10:07 ` Andy Shevchenko
2026-06-21 18:52 ` Jonathan Cameron
2026-06-15 22:00 ` [PATCH 3/4] iio: adc: ti-ads112c14: implement gain on internal short SYS_MON channel David Lechner (TI)
2026-06-15 22:14 ` sashiko-bot
2026-06-16 7:58 ` Andy Shevchenko
2026-06-16 10:03 ` Nuno Sá
2026-06-15 22:00 ` [PATCH 4/4] iio: adc: ti-ads112c14: add measurement channel support David Lechner (TI)
2026-06-15 22:13 ` sashiko-bot
2026-06-16 8:36 ` Andy Shevchenko
2026-06-16 15:55 ` David Lechner
2026-06-17 10:16 ` Andy Shevchenko
2026-06-16 15:30 ` David Lechner
2026-06-21 19:08 ` Jonathan Cameron [this message]
2026-06-16 0:18 ` [PATCH 0/4] iio: adc: new ti-ads112c14 driver Kurt Borja
2026-06-16 15:21 ` David Lechner
2026-06-16 17:26 ` Kurt Borja
2026-06-16 18:16 ` David Lechner
2026-06-21 19:14 ` Jonathan Cameron
2026-06-22 0:32 ` Kurt Borja
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260621200821.0cfffe34@jic23-huawei \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=krzk+dt@kernel.org \
--cc=kuurtb@gmail.com \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=zizuzacker@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox