Re: [PATCH v5 5/5] iio: adc: ad7768-1: add support for ADAQ776x-1 ADC Family
From: Jonathan Cameron
Date: Sat Dec 27 2025 - 11:11:35 EST
On Wed, 17 Dec 2025 02:53:08 -0300
Jonathan Santos <Jonathan.Santos@xxxxxxxxxx> 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@xxxxxxxxxx>
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;
> +}