Linux IIO development
 help / color / mirror / Atom feed
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>,
	"Chris Hall" <c-hall@ti.com>, "Patrick Edwards" <pedwards@ti.com>,
	"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 v2 8/8] iio: adc: ti-ads112c14: add measurement channel support
Date: Wed, 1 Jul 2026 21:20:19 +0100	[thread overview]
Message-ID: <20260701212019.12757df3@jic23-huawei> (raw)
In-Reply-To: <20260625-iio-adc-ti-ads122c14-v2-8-ceb9b0b561cb@baylibre.com>

On Thu, 25 Jun 2026 16:55:10 -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>

Just a few minor things inline.

Thanks,

Jonathan
> 
> diff --git a/drivers/iio/adc/ti-ads112c14.c b/drivers/iio/adc/ti-ads112c14.c
> index 0e775dbc8d50..05d9670c72a4 100644
> --- a/drivers/iio/adc/ti-ads112c14.c
> +++ b/drivers/iio/adc/ti-ads112c14.c

> @@ -441,6 +594,16 @@ static int ads112c14_read_avail(struct iio_dev *indio_dev,
>  {
>  	struct ads112c14_data *data = iio_priv(indio_dev);
>  
> +	if (chan->channel < 100) {

Perhaps we need a define for that magic channel number.

> +
> +static int ads112c14_parse_channels(struct iio_dev *indio_dev,
> +				    bool *need_avdd_ref, bool *need_ext_ref)
> +{
> +	struct ads112c14_data *data = iio_priv(indio_dev);
> +	struct device *dev = indio_dev->dev.parent;
> +	struct iio_chan_spec *channels;
> +	u32 num_child_nodes, i, pair[2];
> +	int ret;
> +
> +	*need_avdd_ref = false;
> +	*need_ext_ref = false;
> +
> +	num_child_nodes = device_get_named_child_node_count(dev, "channel");
> +
> +	data->measurements = devm_kcalloc(dev, num_child_nodes,
> +					  sizeof(*data->measurements), GFP_KERNEL);
> +	if (!data->measurements)
> +		return -ENOMEM;
> +
> +	channels = devm_kcalloc(dev, num_child_nodes +
> +				ARRAY_SIZE(ads112c14_sys_mon_channels),
> +				sizeof(*channels), GFP_KERNEL);
> +	if (!channels)
> +		return -ENOMEM;
> +
> +	i = 0;
> +	device_for_each_named_child_node_scoped(dev, child, "channel") {
> +		struct ads112c14_measurement *measurement = &data->measurements[i];
> +		struct iio_chan_spec *spec = &channels[i];
> +
> +		if (!fwnode_device_is_available(child))
> +			continue;
> +
> +		spec->indexed = 1;
> +		spec->scan_index = i;
> +		measurement->gain_val = 1;
> +
> +		fwnode_property_read_string(child, "label", &measurement->label);

Hmm.  Should check if this exists and then error out on an a parsing error
when it is there but not valid?  Seems like that would be more consistent
with other properties.

> +
> +		if (fwnode_property_present(child, "single-channel")) {
> +			ret = fwnode_property_read_u32(child, "single-channel",
> +						       &pair[0]);
> +			if (ret)
> +				return dev_err_probe(dev, ret,
> +						     "failed to read single-channel property\n");
> +
> +			if (pair[0] >= 8)
> +				return dev_err_probe(dev, -EINVAL,
> +						     "single-channel value must be between 0 and 7\n");
> +
> +			spec->channel = pair[0];
> +			/* NB: channel2 is unused by iio core code in this case. */

True, but maybe should also say why you are stuffing something in it.
What makes that only useful for single channel cases?

> +			spec->channel2 = ADS112C14_MUX_CFG_AIN_GND;
> +		} else if (fwnode_property_present(child, "diff-channels")) {
> +			ret = fwnode_property_read_u32_array(child, "diff-channels",
> +							     pair, ARRAY_SIZE(pair));
> +			if (ret)
> +				return dev_err_probe(dev, ret,
> +						     "failed to read diff-channels property\n");
> +
> +			if (pair[0] >= 8 || pair[1] >= 8)
> +				return dev_err_probe(dev, -EINVAL,
> +						     "diff-channels values must be between 0 and 7\n");
> +
> +			spec->differential = 1;
> +			spec->channel = pair[0];
> +			spec->channel2 = pair[1];
> +		} else {
> +			return dev_err_probe(dev, -EINVAL,
> +					     "channel node missing channel type property\n");
> +		}
> +
> +
...

  reply	other threads:[~2026-07-01 20:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-25 21:55 [PATCH v2 0/8] iio: adc: new ti-ads112c14 driver David Lechner
2026-06-25 21:55 ` [PATCH v2 1/8] dt-bindings: iio: adc: Add reference-sources property David Lechner
2026-06-26 16:12   ` Conor Dooley
2026-06-29  6:47   ` Kurt Borja
2026-06-25 21:55 ` [PATCH v2 2/8] dt-bindings: iio: adc: Add excitation current sources properties David Lechner
2026-06-26 16:10   ` Conor Dooley
2026-07-01 19:39   ` Jonathan Cameron
2026-07-01 22:07     ` David Lechner
2026-06-25 21:55 ` [PATCH v2 3/8] dt-bindings: iio: adc: Add burn-out current properties David Lechner
2026-06-26 16:12   ` Conor Dooley
2026-06-25 21:55 ` [PATCH v2 4/8] dt-bindings: iio: adc: add input-channel-rotation property David Lechner (TI)
2026-06-26 16:14   ` Conor Dooley
2026-06-26 18:27     ` David Lechner
2026-07-01 19:41       ` Jonathan Cameron
2026-06-25 21:55 ` [PATCH v2 5/8] dt-bindings: iio: adc: add ti,ads122c14 David Lechner (TI)
2026-06-26 16:18   ` Conor Dooley
2026-06-26 18:35     ` David Lechner
2026-06-27 14:03       ` Conor Dooley
2026-07-01 19:50   ` Jonathan Cameron
2026-06-25 21:55 ` [PATCH v2 6/8] iio: adc: add ti-ads112c14 driver David Lechner (TI)
2026-07-01 19:59   ` Jonathan Cameron
2026-06-25 21:55 ` [PATCH v2 7/8] iio: adc: ti-ads112c14: implement gain on internal short SYS_MON channel David Lechner (TI)
2026-07-01 20:02   ` Jonathan Cameron
2026-06-25 21:55 ` [PATCH v2 8/8] iio: adc: ti-ads112c14: add measurement channel support David Lechner (TI)
2026-07-01 20:20   ` Jonathan Cameron [this message]
2026-07-02  9:18     ` Andy Shevchenko
2026-07-02 14:18       ` David Lechner

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=20260701212019.12757df3@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=c-hall@ti.com \
    --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=pedwards@ti.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