Re: [PATCH v3 1/4] staging: iio: adc: ad7816: redefine mode constants to start from 0

Jonathan Cameron
2026-04-12T18:49:24Z

On Tue, 31 Mar 2026 14:06:04 +0300
Andy Shevchenko <andriy.shevchenko@intel.com> wrote:

> On Tue, Mar 31, 2026 at 01:53:29PM +0300, Dan Carpenter wrote:
> > On Tue, Mar 31, 2026 at 12:17:07AM +0600, Md. Mahmudul Hasan Mabud wrote:
>
> ...
>
> > > /*
> > > * AD7816 config masks
> > > */
> > > -#define AD7816_FULL 0x1
> > > -#define AD7816_PD 0x2
> > > +#define AD7816_FULL 0
> > > +#define AD7816_PD 1
> >
> > I don't love this. AD7816_PD used to be related to the spec but now
> > it's just a random number which tricks you into thinking it has
> > meaning but it doesn't.
> >
> > if (chip->mode == AD7816_PD) { /* operating mode 2 */
>
> We can leave that and add a new member to the string array
>
> [_DEFAULT] = "default";
>
> and associate it with the default choice which seems to be _FULL as per
> kzalloc() in the IIO core.

Hmm. This ABI is pretty bad anyway, good not to introduce more values that
don't actually occur. Like pretty much all IIO drivers, I'd suggest
this shouldn't ultimately be exposed to userspace at all. This is
what we have runtime PM for which removes the need for userspace to
do anything specific to bring the device out of power down mode.

The only place we allow these is when it's an output channel an
powering down is entering a specific state (typically a pull high
or something like that).

Jonathan

>
>