Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Jonathan Santos <Jonathan.Santos@analog.com>
Cc: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>, <lars@metafoo.de>,
	<Michael.Hennerich@analog.com>, <dlechner@baylibre.com>,
	<nuno.sa@analog.com>, <andy@kernel.org>, <robh@kernel.org>,
	<krzk+dt@kernel.org>, <conor+dt@kernel.org>,
	<jonath4nns@gmail.com>
Subject: Re: [PATCH v5 5/5] iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family
Date: Sat, 27 Dec 2025 16:11:15 +0000	[thread overview]
Message-ID: <20251227161115.5e38e874@jic23-huawei> (raw)
In-Reply-To: <dab6e0ffc1a297d857f5a9c75184794c301d70f3.1765900411.git.Jonathan.Santos@analog.com>

On Wed, 17 Dec 2025 02:53:08 -0300
Jonathan Santos <Jonathan.Santos@analog.com> wrote:

> Add support for ADAQ7767/68/69-1 series, which includes PGIA and
> Anti-aliasing filter (AAF) gains. Unlike the AD7768-1, they do not
> provide a VCM regulator interface.
> 
> The PGA gain is configured in run-time through the scale attribute,
> if supported by the device. PGA is controlled by GPIOs provided in
> the device tree.
> 
> The AAF gain is defined by hardware connections and should be specified
> in the device tree.
> 
> Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>

Hi Jonathan

I noted one minor area where I think the code could be slightly cleaner.
If we didn't have the outstanding question about the comment in the BP definitions
patch I'd just have merged it as it stands. I don't mind that much if you
prefer the current form.

Jonathan

>  
> +static int ad7768_parse_aaf_gain(struct device *dev, struct ad7768_state *st)
> +{
> +	bool aaf_gain_provided;
> +	u32 val;
> +	int ret;
> +
> +	ret = device_property_read_u32(dev, "adi,aaf-gain-bp", &val);
> +	if (ret == -EINVAL)
> +		aaf_gain_provided = false;
> +	else if (ret)
> +		return dev_err_probe(dev, ret, "Failed to get AAF gain value\n");
> +	else
> +		aaf_gain_provided = true;
> +
> +	if (!aaf_gain_provided) {
> +		if (st->chip->has_variable_aaf)
> +			st->aaf_gain = AD7768_AAF_IN1;
> +		return 0;
> +	}
> +
> +	if (aaf_gain_provided && !st->chip->has_variable_aaf)
> +		return dev_err_probe(dev, -EOPNOTSUPP,
> +				     "AAF gain not supported for %s\n", st->chip->name);
> +

Might be simpler if we just did the actions for aaf_gain at the point of detecting it.

	if (ret == -EINVAL) {
		/* If controllable, use default */
		if (st->chip->has_variable_aaf)
			st->aaf_gain = AD7768_AAF_IN1;
		return 0;
	}
	if (ret)
		return dev_err_probe(dev, ret, "Failed to get AAF gain value\n");

	if (!st->chip->has_variable_aaf)
		return dev_err_probe(dev,, -EOPNOTSUPP,
		     "AAF gain provided, but variable AFF gain not supported for %s\n", ...)

or maybe make the gain number obvious as the default by doing.

	if (ret == -EINVAL) {
		if (!st->chip->has_variable_aaf)
			return 0;

		val = 10000; /* Matches the default from DT */
	} else if (ret) {
		return dev_err_probe(dev, ret, "Failed to get AAF gain value\n");
	} else if (!st->chip->has_variable_aaf) {
		return dev_err_probe(dev,, -EOPNOTSUPP,
		     "AAF gain provided, but variable AFF gain not supported for %s\n", ...)
	}

The first option is simpler, bu the second makes it easier to align with DT binding.


> +	switch (val) {
> +	case 10000:
> +		st->aaf_gain = AD7768_AAF_IN1;
> +		break;
> +	case 3640:
> +		st->aaf_gain = AD7768_AAF_IN2;
> +		break;
> +	case 1430:
> +		st->aaf_gain = AD7768_AAF_IN3;
> +		break;
> +	default:
> +		return dev_err_probe(dev, -EINVAL, "Invalid firmware provided AAF gain\n");
> +	}
> +
> +	return 0;
> +}

      reply	other threads:[~2025-12-27 16:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-17  5:52 [PATCH v5 0/5] Add support for ADAQ776x-1 ADC Family Jonathan Santos
2025-12-17  5:52 ` [PATCH v5 1/5] dt-bindings: iio: adc: ad7768-1: add new supported parts Jonathan Santos
2025-12-17  5:52 ` [PATCH v5 2/5] iio: adc: ad7768-1: introduce chip info for future multidevice support Jonathan Santos
2025-12-17  5:52 ` [PATCH v5 3/5] units: add PERCENT and BASIS_POINTS macros Jonathan Santos
2025-12-27 15:55   ` Jonathan Cameron
2025-12-27 16:48     ` Andy Shevchenko
2025-12-27 16:52     ` Andy Shevchenko
2025-12-27 16:53       ` Andy Shevchenko
2026-01-11  2:11       ` Jonathan Santos
2026-01-13  6:49         ` Andy Shevchenko
2025-12-17  5:52 ` [PATCH v5 4/5] iio: adc: ad7768-1: refactor ad7768_write_raw() Jonathan Santos
2025-12-17  5:53 ` [PATCH v5 5/5] iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family Jonathan Santos
2025-12-27 16:11   ` Jonathan Cameron [this message]

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=20251227161115.5e38e874@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=Jonathan.Santos@analog.com \
    --cc=Michael.Hennerich@analog.com \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=jonath4nns@gmail.com \
    --cc=krzk+dt@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nuno.sa@analog.com \
    --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