[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20251227161115.5e38e874@jic23-huawei>
Date: Sat, 27 Dec 2025 16:11:15 +0000
From: Jonathan Cameron <jic23@...nel.org>
To: Jonathan Santos <Jonathan.Santos@...log.com>
Cc: <linux-iio@...r.kernel.org>, <devicetree@...r.kernel.org>,
<linux-kernel@...r.kernel.org>, <lars@...afoo.de>,
<Michael.Hennerich@...log.com>, <dlechner@...libre.com>,
<nuno.sa@...log.com>, <andy@...nel.org>, <robh@...nel.org>,
<krzk+dt@...nel.org>, <conor+dt@...nel.org>, <jonath4nns@...il.com>
Subject: Re: [PATCH v5 5/5] iio: adc: ad7768-1: add support for ADAQ776x-1
ADC Family
On Wed, 17 Dec 2025 02:53:08 -0300
Jonathan Santos <Jonathan.Santos@...log.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@...log.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;
> +}
Powered by blists - more mailing lists