Re: [PATCH v4 2/2] iio: pressure: add Sensirion SDP31 driver
From: Andy Shevchenko
Date: Mon Sep 28 2026 - 18:04:32 EST
On Tue, Sep 29, 2026 at 02:54:22AM +0500, Muhammad Abu Bakar wrote:
> Add an IIO driver for the Sensirion SDP3x family of differential pressure
> sensors (SDP31, SDP32 and SDP33). The devices are accessed over I2C and
> report differential pressure and temperature. Each measurement is
> validated using the sensor's CRC-8 checksum. The scale factor is read
> from the sensor at runtime, so all three parts are supported.
>
> Tested on an SDP31 connected to a Raspberry Pi 4 I2C bus.
...
> +#include <linux/cleanup.h>
> +#include <linux/crc8.h>
> +#include <linux/delay.h>
> +#include <linux/i2c.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/once.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/unaligned.h>
Follow IWYU principle.
At least types.h, err.h or errno.h are absent.
...
> +static int sdp31_read_measurement(struct sdp31_data *data, s16 *pressure,
> + s16 *temp)
> +{
> + u8 rx[6];
> + int ret;
> +
> + ret = sdp31_trigger_read(data, rx, sizeof(rx));
> + if (ret)
> + return ret;
> +
> + if (sdp31_check_crc(&rx[0]) || sdp31_check_crc(&rx[3]))
> + return -EIO;
> + *pressure = (s16)get_unaligned_be16(&rx[0]);
> + *temp = (s16)get_unaligned_be16(&rx[3]);
And casting is for...?
> + return 0;
> +}
...
> + case IIO_CHAN_INFO_SCALE:
> + switch (chan->type) {
> + case IIO_PRESSURE:
> + *val = 1;
> + *val2 = data->dp_scale * 1000;
KILO?
> + return IIO_VAL_FRACTIONAL;
> + case IIO_TEMP:
> + /* raw / 200 = degC, so raw * 5 = milli-degC */
> + *val = 5;
> + return IIO_VAL_INT;
> + default:
> + return -EINVAL;
> + }
--
With Best Regards,
Andy Shevchenko