Re: [PATCH v6 05/11] iio: adc: ad7768-1: add regulator to control VCM output
From: Jonathan Santos
Date: Wed Apr 30 2025 - 19:24:27 EST
On 04/28, Andy Shevchenko wrote:
> On Mon, Apr 28, 2025 at 3:13 AM Jonathan Santos
> <Jonathan.Santos@xxxxxxxxxx> wrote:
> >
> > The VCM output voltage can be used as a common-mode voltage within the
> > amplifier preconditioning circuits external to the AD7768-1.
> >
> > This change allows the user to configure VCM output using the regulator
> > framework.
>
> ...
>
> > #include <linux/gpio/consumer.h>
> > #include <linux/kernel.h>
> > #include <linux/module.h>
> > +#include <linux/of.h>
>
> Why?
>
I was using of_match_ptr() before, but forgot to remove it, sorry.
> > #include <linux/regmap.h>
> > #include <linux/regulator/consumer.h>
> > +#include <linux/regulator/driver.h>
>
> ...
>
> > +static int ad7768_vcm_enable(struct regulator_dev *rdev)
> > +{
> > + struct iio_dev *indio_dev = rdev_get_drvdata(rdev);
> > + struct ad7768_state *st = iio_priv(indio_dev);
> > + int ret, regval;
>
> > + if (!indio_dev)
> > + return -EINVAL;
>
> Isn't it a dead code? Or i.o.w. under which circumstances can this be true?
> Ditto for other functions with the same check.
>
Yes, you're right. Since I defined the driver data below, there was no
need for the check.
> > + if (!iio_device_claim_direct(indio_dev))
> > + return -EBUSY;
> > +
> > + /* To enable, set the last selected output */
> > + regval = AD7768_REG_ANALOG2_VCM(st->vcm_output_sel + 1);
> > + ret = regmap_update_bits(st->regmap, AD7768_REG_ANALOG2,
> > + AD7768_REG_ANALOG2_VCM_MSK, regval);
> > + iio_device_release_direct(indio_dev);
> > +
> > + return ret;
> > +}
>
> ...
>
> > + return clamp(val, 1, (int)rdev->desc->n_voltages) - 1;
>
> No explicit castings in min/max/clamp, please. This may lead to subtle
> mistakes. Also, don't forget to include minmax.h.
>
Okay, thanks.
> --
> With Best Regards,
> Andy Shevchenko