Re: [PATCH v2 2/2] iio: chemical: acd10: Add driver for ACD10 CO2 sensor

From: Jonathan Cameron

Date: Sat Dec 05 2026 - 19:14:31 EST


On Wed, 2 Dec 2026 12:25:22 +0000
Akhilesh Patil <akhilesh.patil@xxxxxxxxx> wrote:

> Add driver for Aosong ASAIR ACD10 carbon dioxide sensor.
> Use serdev interface to communicate with sensor over UART.
> Implement read co2, get software revision, get instrument number
> commands.
>
> Tested on TI am62x sk board on UART5 with 1200 baud rate.
>
> Signed-off-by: Akhilesh Patil <akhilesh.patil@xxxxxxxxx>
There is one bit off feedback from sashiko.
https://sashiko.dev/#/patchset/cover.1796211342.git.akhilesh.patil%40linux.dev

I think it is a 'yes but we don't care' case but please take
a look and confirm if so.

Just a couple of other small things to add to Uwe's comments

Thanks

Jonathan
> diff --git a/drivers/iio/chemical/acd10.c b/drivers/iio/chemical/acd10.c
> new file mode 100644
> index 000000000000..a77dde636ea7
> --- /dev/null
> +++ b/drivers/iio/chemical/acd10.c

> +struct acd10_state {
> + struct serdev_device *serdev;
> +
> + /* Lock to acquire during CMD/RESP sequence */
> + struct mutex lock;
> + struct completion buf_ready;
> +
> + /* Single buffer to hold tx and rx data */
> + u8 buf[16];
> + u8 buf_idx;
> + u8 rx_expected_len;
> +
> + u8 sw_rev[16];

Noted below that this is only used in one function, don't
store it in here. If you need it at all, it is small enough to
have on the stack.

> + u8 inst_num[16];
> +};

> +
> +static int acd10_get_sw_rev(struct iio_dev *indio_dev)
> +{
> + struct acd10_state *drv_state = iio_priv(indio_dev);
> + struct device *dev = &indio_dev->dev;
> + int ret;
> +
> + guard(mutex)(&drv_state->lock);
> +
> + ret = acd10_serdev_transfer(drv_state, ACD10_CMD_READ_SWREV);
> + if (ret)
> + return ret;
> +
> + memcpy(drv_state->sw_rev, &drv_state->buf[ACD10_FRAME_DATA_START_IDX], 10);
> + drv_state->sw_rev[10] = '\0';

No point in keeping a copy around as only used for this print.

> +
> + dev_dbg(dev, "Software revision: %s\n", drv_state->sw_rev);

Can you use
dev_dbg(dev, "Software revision: %.10s\n", &drv_state->buf[ACD10_FRAME_DATA_START_IDX]);
to get same result?

> +
> + return 0;
> +}


> +
> +static IIO_DEVICE_ATTR_RO(serialnumber, 0);
> +
> +static struct attribute *acd10_attrs[] = {
> + &iio_dev_attr_serialnumber.dev_attr.attr,
> + NULL,

No trailing comma on a terminating entry like this.
Nothing can come after it, so let us not make it easy for anyone to
make a mistake and add something there!

> +};