Re: [PATCH v3] iio: chemical: ccs811: Make sampling frequency configurable

From: Andy Shevchenko

Date: Sun Oct 25 2026 - 16:58:01 EST


On Sun, Oct 25, 2026 at 11:05:45PM +0530, Nikhil Gautam wrote:
> Allow userspace to configure the CCS811 IAQ measurement rate through
> the IIO sampling_frequency attribute.
>
> Support the three IAQ measurement modes with sampling frequencies of
> 1 Hz, 0.1 Hz, and approximately 0.016667 Hz, corresponding to
> measurement intervals of 1, 10, and 60 seconds.
>
> Preserve unrelated bits in the MEAS_MODE register when updating the
> drive mode, and cache the selected mode after a successful register
> write. Expose the supported frequencies through
> sampling_frequency_available.
>
> Signed-off-by: Nikhil Gautam <nikhilgtr@xxxxxxxxx>

The cutter is missing here, we don't want to see changelog in the commit
messages and moreover this contribution is not strictly signed-off, as the tag
block is the last in the commit message. This is a show-stopper to take
the patch, even if it's desired and correct.

>
> Changes in v3:
> - Reuse the sampling frequency array instead of duplicating frequency values.
> - Separate register updates from locking and wakeup handling.
> - Use a separate variable for the updated MEAS_MODE register value.
> - Simplify the sampling frequency getter.
> - Mark the completed drive-mode configuration TODO as done.
>
> Changes in v2:
> - Fix the Clang build error caused by guard() in the switch statement.
> ---

...

> +static const int ccs811_samp_freq[] = {
> + 1, 0,
> + 0, 100000,
> + 0, 16667,
> +};

Make it double dimension array instead. Each index can be named as
CCS811_MODE_IAQ_1SEC and so on, while the shift is applied later on.

With the above being done, the code can use either a for-loop or
simple indexing.

*Yes, I see that the value(s) can be used directly in the code, but try to
explore an approach that can improve robustness and readability of the code.

...

> +{
> + struct ccs811_data *data = iio_priv(indio_dev);
> + int ret;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_SAMP_FREQ:
> + if (!iio_device_claim_direct(indio_dev))
> + return -EBUSY;

Can we use IIO_DEV_ACQUIRE_DIRECT_MODE() here?

> + ret = ccs811_set_sampling_freq(data, val, val2);
> +
> + iio_device_release_direct(indio_dev);
> + return ret;
> +
> + default:
> + return -EINVAL;
> + }
> +}

--
With Best Regards,
Andy Shevchenko