Re: [PATCH v4 06/11] iio: adc: ad4170: Add support for buffered data capture
From: Jonathan Cameron
Date: Sat Jun 07 2025 - 13:07:23 EST
On Mon, 2 Jun 2025 08:38:46 -0300
Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx> wrote:
> Extend the AD4170 driver to allow buffered data capture in continuous read
> mode. In continuous read mode, the chip skips the instruction phase and
> outputs just ADC sample data, enabling faster sample rates to be reached.
> The internal channel sequencer always starts sampling from channel 0 and
> channel 0 must be enabled if more than one channel is selected for data
> capture. The scan mask validation callback checks if the aforementioned
> condition is met.
>
> Signed-off-by: Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx>
A comment inline about possibly relaxing the channel 0 constraint
as far as userspace is concerned anyway. Not necessary for now though.
> 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.
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.
> +
> + /*
> + * 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;
> +}