Re: [PATCH v4 06/11] iio: adc: ad4170: Add support for buffered data capture
From: Marcelo Schmitt
Date: Mon Jun 09 2025 - 16:39:29 EST
...
> > diff --git a/drivers/iio/adc/ad4170.c b/drivers/iio/adc/ad4170.c
> > index 3d83c3ace569..86ef70acbf21 100644
> > --- a/drivers/iio/adc/ad4170.c
> > +++ b/drivers/iio/adc/ad4170.c
> > @@ -13,7 +13,11 @@
>
> > +static bool ad4170_validate_scan_mask(struct iio_dev *indio_dev,
> > + const unsigned long *scan_mask)
> > +{
> > + unsigned int masklength = iio_get_masklength(indio_dev);
>
> If this becomes a useability issue we could probably generative appropriate
> available_scan_masks entries and let the demuxer in the IIO core deal with
> dropping the unwanted first channel. That might be preferable to just
> failing if the channel isn't enabled.
Yes, we can do that. I also think that would probably be the preferred way from
the user's perspective. Though, that tinkering may result in a few more tens of
lines of code, which I'm reluctant to add, given the size of this set.
>
> As a general rule, I think we've always used validate_scan_mask
> to prevent too many channels being turned on, or incompatible sets of channels
> rather than to prevent too few being enabled.
>
> Anyhow that would be a relaxation of constraints so can be done if it
> turns out to be needed later.
>
Added to my list of patch ideas :)
> > +
> > + /*
> > + * The channel sequencer cycles through the enabled channels in
> > + * sequential order, from channel 0 to channel 15, bypassing disabled
> > + * channels. When more than one channel is enabled, channel 0 must
> > + * always be enabled. See datasheet channel_en register description at
> > + * page 95.
> > + */
> > + if (bitmap_weight(scan_mask, masklength) > 1)
> > + return test_bit(0, scan_mask);
> > +
> > + return bitmap_weight(scan_mask, masklength) == 1;
> > +}