Devicetree
 help / color / mirror / Atom feed
From: David Lechner <dlechner@baylibre.com>
To: "Kyle Hsieh" <kylehsieh1995@gmail.com>,
	"Jonathan Cameron" <jic23@kernel.org>,
	"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>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Mark Brown" <broonie@kernel.org>,
	"Philipp Zabel" <p.zabel@pengutronix.de>
Cc: linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v6 2/2] iio: adc: ti-ads112c04: Add support for TI ADS112C04
Date: Sat, 22 Aug 2026 19:06:05 -0500	[thread overview]
Message-ID: <1b0af12a-0653-4a14-9c0b-4948eab9a4cf@baylibre.com> (raw)
In-Reply-To: <20260820-ti-ads112c04-driver-v6-2-0e8f0aacce9b@gmail.com>

On 8/20/26 2:51 AM, Kyle Hsieh wrote:
> Add IIO driver support for the Texas Instruments ADS112C04 (16-bit)
> delta-sigma ADCs.
> 

...

> +static int ads112c04_parse_channels(struct iio_dev *indio_dev,
> +				    bool *need_avdd_ref, bool *need_ext_ref)
> +{
> +	struct device *dev = indio_dev->dev.parent;
> +	struct ads112c04_state *st = iio_priv(indio_dev);
> +	struct iio_chan_spec *channels;
> +	u32 num_channels, pair[2], channel;
> +	unsigned int i;
> +	int ret;
> +
> +	num_channels = device_get_named_child_node_count(dev, "channel");
> +	if (!num_channels)
> +		return dev_err_probe(dev, -EINVAL, "no channel subnodes found\n");
> +
> +	if (num_channels > ADS112C04_MAX_CHANNELS)
> +		return dev_err_probe(dev, -EINVAL,
> +				     "num of channel nodes exceeds %d\n",
> +				     ADS112C04_MAX_CHANNELS);
> +
> +	channels = devm_kcalloc(dev, num_channels, sizeof(*channels), GFP_KERNEL);
> +	if (!channels)
> +		return -ENOMEM;
> +
> +	st->vref_source = devm_kcalloc(dev, num_channels,
> +				       sizeof(*st->vref_source), GFP_KERNEL);
> +	if (!st->vref_source)
> +		return -ENOMEM;
> +
> +	i = 0;
> +	device_for_each_named_child_node_scoped(dev, child, "channel") {
> +		const char *sp = "single-channel", *dp = "diff-channels";

What does the "p" mean? I would make the names the same as the string,
e.g. sc, dc, or s_chan, d_chan since they are used quite far from here.

> +		struct iio_chan_spec *spec = &channels[i];
> +
> +		if (fwnode_property_present(child, "excitation-channels"))
> +			return dev_err_probe(dev, -EOPNOTSUPP,
> +					     "excitation-channels is not supported yet\n");
> +
> +		st->vref_source[i] = ADS112C04_VREF_SOURCE_INTERNAL;
> +
> +		if (fwnode_property_present(child, "reference-sources")) {

ads112c04_parse_vref_source() already calls fwnode_property_present(child, "reference-sources")
and returns ADS112C04_VREF_SOURCE_INTERNAL as default, so we are duplicating that
logic here. Either drop the helper or drop the extra code here.

> +			ret = ads112c04_parse_vref_source(child);
> +			if (ret < 0)
> +				return dev_err_probe(dev, ret,
> +						     "invalid reference-sources value\n");
> +
> +			st->vref_source[i] = ret;
> +		}
> +
> +		if (st->vref_source[i] == ADS112C04_VREF_SOURCE_EXTERNAL)
> +			*need_ext_ref = true;

Can just assign these directly:

		*need_ext_ref = st->vref_source[i] == ADS112C04_VREF_SOURCE_EXTERNAL;

> +		if (st->vref_source[i] == ADS112C04_VREF_SOURCE_AVDD)
> +			*need_avdd_ref = true;
> +

...

> +
> +		i++;
> +	}
> +
> +	indio_dev->channels = channels;
> +	indio_dev->num_channels = i;
> +
> +	return 0;
> +}
> +
> +static int ads112c04_probe(struct i2c_client *client)
> +{
> +	struct device *dev = &client->dev;
> +	struct iio_dev *indio_dev;
> +	struct ads112c04_state *st;
> +	struct reset_control *reset;
> +	bool need_avdd_ref = false, need_ext_ref = false;
> +	int ret;
> +

...

> +	/* Datasheet: POR releases ~500us after supplies are stable */
> +	fsleep(500);
> +
> +	reset = devm_reset_control_get_optional_exclusive(dev, NULL);
> +	if (IS_ERR(reset))
> +		return dev_err_probe(dev, PTR_ERR(reset), "failed to get reset\n");
> +
> +	if (reset) {

I'm pretty sure devm_reset_control_get_optional_exclusive() already asserts
the reset. So the way this is usally implemented is that we get (assert)
the rest, then wait chip-specific time (usually a few microsonds) then
reset_control_deassert().

I don't see any other IIO drivers that are using reset_control_reset().
(And I think a lot might be calling reset_control_assert() unnecissaraly.)

> +		ret = reset_control_reset(reset);
> +		if (ret)
> +			return dev_err_probe(dev, ret, "failed to reset device\n");
> +	} else {
> +		ret = ads112c04_write_cmd(client, ADS112C04_CMD_RESET);
> +		if (ret < 0)
> +			return ret;
> +	}
> +

If it wasn't for the duplicate code, I might have said good enough. :-)

  parent reply	other threads:[~2026-08-23  0:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-20  7:51 [PATCH v6 0/2] iio: adc: Add support for Texas Instruments ADS112C04 Kyle Hsieh
2026-08-20  7:51 ` [PATCH v6 1/2] dt-bindings: iio: adc: ti,ads112c04: Add binding for ADS112C04 Kyle Hsieh
2026-08-20  7:58   ` sashiko-bot
2026-08-20  7:51 ` [PATCH v6 2/2] iio: adc: ti-ads112c04: Add support for TI ADS112C04 Kyle Hsieh
2026-08-20  7:58   ` sashiko-bot
2026-08-21 10:59   ` Andy Shevchenko
2026-08-24  8:09     ` Kyle Hsieh
2026-08-24  8:46       ` Andy Shevchenko
2026-08-23  0:06   ` David Lechner [this message]
2026-08-24  8:00     ` Kyle Hsieh
2026-08-21  1:25 ` [PATCH v6 0/2] iio: adc: Add support for Texas Instruments ADS112C04 Jonathan Cameron
2026-08-21  3:37   ` Kyle Hsieh

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=1b0af12a-0653-4a14-9c0b-4948eab9a4cf@baylibre.com \
    --to=dlechner@baylibre.com \
    --cc=andy@kernel.org \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=kylehsieh1995@gmail.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    /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