* [PATCH 0/2] iio: pressure: add Sensirion SDP31 driver
[not found] <20260919223854.13437-1-m.abubakar365.ref@yahoo.com>
@ 2026-09-19 22:38 ` Muhammad Abu Bakar
2026-09-19 22:38 ` [PATCH 1/2] dt-bindings: iio: pressure: add Sensirion SDP31 Muhammad Abu Bakar
` (2 more replies)
0 siblings, 3 replies; 7+ messages in thread
From: Muhammad Abu Bakar @ 2026-09-19 22:38 UTC (permalink / raw)
To: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: dlechner, nuno.sa, andy, linux-iio, devicetree, linux-kernel,
Muhammad Abu Bakar
This series adds support for the Sensirion SDP31 differential pressure
sensor, an I2C device that also reports temperature.
Patch 1 adds the device tree binding.
Patch 2 adds the IIO driver, which exposes differential pressure and
temperature channels and validates each measurement using the sensor's
CRC-8 checksum.
The driver was developed and tested on an SDP31 wired to the I2C bus of
a Raspberry Pi 4.
Muhammad Abu Bakar (2):
dt-bindings: iio: pressure: add Sensirion SDP31
iio: pressure: add Sensirion SDP31 driver
.../iio/pressure/sensirion,sdp31.yaml | 40 ++++
MAINTAINERS | 6 +
drivers/iio/pressure/Kconfig | 11 +
drivers/iio/pressure/Makefile | 1 +
drivers/iio/pressure/sdp31.c | 194 ++++++++++++++++++
5 files changed, 252 insertions(+)
create mode 100644 Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
create mode 100644 drivers/iio/pressure/sdp31.c
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/2] dt-bindings: iio: pressure: add Sensirion SDP31
2026-09-19 22:38 ` [PATCH 0/2] iio: pressure: add Sensirion SDP31 driver Muhammad Abu Bakar
@ 2026-09-19 22:38 ` Muhammad Abu Bakar
2026-09-20 0:40 ` Jonathan Cameron
2026-09-19 22:38 ` [PATCH 2/2] iio: pressure: add Sensirion SDP31 driver Muhammad Abu Bakar
2026-09-20 0:34 ` [PATCH 0/2] " Jonathan Cameron
2 siblings, 1 reply; 7+ messages in thread
From: Muhammad Abu Bakar @ 2026-09-19 22:38 UTC (permalink / raw)
To: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: dlechner, nuno.sa, andy, linux-iio, devicetree, linux-kernel,
Muhammad Abu Bakar
Add device tree bindings for the Sensirion SDP31 differential pressure
sensor, an I2C device that also reports temperature.
Signed-off-by: Muhammad Abu Bakar <m.abubakar365@yahoo.com>
---
.../iio/pressure/sensirion,sdp31.yaml | 40 +++++++++++++++++++
1 file changed, 40 insertions(+)
create mode 100644 Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
diff --git a/Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml b/Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
new file mode 100644
index 000000000..fc646eca2
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/pressure/sensirion,sdp31.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sensirion SDP31 differential pressure sensor
+
+maintainers:
+ - Muhammad Abu Bakar <m.abubakar365@yahoo.com>
+
+description: |
+ Differential pressure sensor from Sensirion with an I2C interface.
+
+properties:
+ compatible:
+ const: sensirion,sdp31
+
+ reg:
+ maxItems: 1
+
+ vdd-supply: true
+
+required:
+ - compatible
+ - reg
+
+additionalProperties: false
+
+examples:
+ - |
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ pressure@21 {
+ compatible = "sensirion,sdp31";
+ reg = <0x21>;
+ vdd-supply = <&vdd_3v3>;
+ };
+ };
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/2] iio: pressure: add Sensirion SDP31 driver
2026-09-19 22:38 ` [PATCH 0/2] iio: pressure: add Sensirion SDP31 driver Muhammad Abu Bakar
2026-09-19 22:38 ` [PATCH 1/2] dt-bindings: iio: pressure: add Sensirion SDP31 Muhammad Abu Bakar
@ 2026-09-19 22:38 ` Muhammad Abu Bakar
2026-09-20 0:53 ` Jonathan Cameron
2026-09-20 0:34 ` [PATCH 0/2] " Jonathan Cameron
2 siblings, 1 reply; 7+ messages in thread
From: Muhammad Abu Bakar @ 2026-09-19 22:38 UTC (permalink / raw)
To: Jonathan Cameron, Rob Herring, Krzysztof Kozlowski, Conor Dooley
Cc: dlechner, nuno.sa, andy, linux-iio, devicetree, linux-kernel,
Muhammad Abu Bakar
Add an IIO driver for the Sensirion SDP31 differential pressure sensor.
The device is accessed over I2C and reports differential pressure and
temperature. Each measurement is validated using the sensor's CRC-8
checksum.
Tested on an SDP31 connected to a Raspberry Pi 4 I2C bus.
Signed-off-by: Muhammad Abu Bakar <m.abubakar365@yahoo.com>
---
MAINTAINERS | 6 ++
drivers/iio/pressure/Kconfig | 11 ++
drivers/iio/pressure/Makefile | 1 +
drivers/iio/pressure/sdp31.c | 194 ++++++++++++++++++++++++++++++++++
4 files changed, 212 insertions(+)
create mode 100644 drivers/iio/pressure/sdp31.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 214aeee76..a053a530e 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -24855,6 +24855,12 @@ S: Maintained
F: Documentation/devicetree/bindings/iio/chemical/sensirion,scd4x.yaml
F: drivers/iio/chemical/scd4x.c
+SENSIRION SDP31 DIFFERENTIAL PRESSURE SENSOR DRIVER
+M: Muhammad Abu Bakar <m.abubakar365@yahoo.com>
+S: Maintained
+F: Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
+F: drivers/iio/pressure/sdp31.c
+
SENSIRION SDP500 DIFFERENTIAL PRESSURE SENSOR DRIVER
M: Petar Stoykov <petar.stoykov@prodrive-technologies.com>
S: Maintained
diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig
index 838a8340c..58172639c 100644
--- a/drivers/iio/pressure/Kconfig
+++ b/drivers/iio/pressure/Kconfig
@@ -286,6 +286,17 @@ config MS5637
This driver can also be built as a module. If so, the module will
be called ms5637.
+config SDP31
+ tristate "Sensirion SDP31 differential pressure sensor I2C driver"
+ depends on I2C
+ select CRC8
+ help
+ Say Y here to build support for Sensirion SDP31 differential pressure
+ sensor I2C driver.
+
+ To compile this driver as a module, choose M here: the core module
+ will be called sdp31.
+
config SDP500
tristate "Sensirion SDP500 differential pressure sensor I2C driver"
depends on I2C
diff --git a/drivers/iio/pressure/Makefile b/drivers/iio/pressure/Makefile
index bc0d11a20..5279a0ebd 100644
--- a/drivers/iio/pressure/Makefile
+++ b/drivers/iio/pressure/Makefile
@@ -35,6 +35,7 @@ obj-$(CONFIG_MS5611) += ms5611_core.o
obj-$(CONFIG_MS5611_I2C) += ms5611_i2c.o
obj-$(CONFIG_MS5611_SPI) += ms5611_spi.o
obj-$(CONFIG_MS5637) += ms5637.o
+obj-$(CONFIG_SDP31) += sdp31.o
obj-$(CONFIG_SDP500) += sdp500.o
obj-$(CONFIG_IIO_ST_PRESS) += st_pressure.o
st_pressure-y := st_pressure_core.o
diff --git a/drivers/iio/pressure/sdp31.c b/drivers/iio/pressure/sdp31.c
new file mode 100644
index 000000000..934a3afcd
--- /dev/null
+++ b/drivers/iio/pressure/sdp31.c
@@ -0,0 +1,194 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+#include <linux/i2c.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/mutex.h>
+#include <linux/crc8.h>
+#include <linux/iio/iio.h>
+
+#define SDP31_CMD_TRIG_DP 0x362F
+#define SDP31_MEAS_DELAY_MS 50
+#define SDP31_TEMP_SCALE 5
+#define SDP31_CRC8_POLY 0x31
+#define SDP31_CRC8_INIT 0xff
+
+DECLARE_CRC8_TABLE(sdp31_crc8_table);
+
+struct sdp31_data {
+ struct i2c_client *client;
+ struct mutex lock; /* serializes multi-step measurements */
+ u16 dp_scale; /* diff-pressure scale factor read from the sensor */
+};
+
+struct sdp31_reading {
+ s16 pressure;
+ s16 temp;
+ u16 scale;
+};
+
+static int sdp31_send_cmd(struct i2c_client *client, u16 cmd)
+{
+ u8 buf[2] = { cmd >> 8, cmd & 0xff };
+ int ret = i2c_master_send(client, buf, sizeof(buf));
+
+ if (ret < 0)
+ return ret;
+ return (ret == sizeof(buf)) ? 0 : -EIO;
+}
+
+static int sdp31_check_crc(const u8 *word)
+{
+ if (crc8(sdp31_crc8_table, word, 2, SDP31_CRC8_INIT) != word[2])
+ return -EIO;
+ return 0;
+}
+
+static int sdp31_measure(struct i2c_client *client, struct sdp31_reading *out)
+{
+ u8 rx[9];
+ int ret;
+
+ ret = sdp31_send_cmd(client, SDP31_CMD_TRIG_DP);
+ if (ret)
+ return ret;
+
+ msleep(SDP31_MEAS_DELAY_MS);
+
+ ret = i2c_master_recv(client, rx, sizeof(rx));
+ if (ret < 0)
+ return ret;
+ if (ret != sizeof(rx))
+ return -EIO;
+
+ if (sdp31_check_crc(&rx[0]) ||
+ sdp31_check_crc(&rx[3]) ||
+ sdp31_check_crc(&rx[6]))
+ return -EIO;
+
+ out->pressure = (s16)((rx[0] << 8) | rx[1]);
+ out->temp = (s16)((rx[3] << 8) | rx[4]);
+ out->scale = (rx[6] << 8) | rx[7];
+ return 0;
+}
+
+static int sdp31_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+ struct sdp31_data *data = iio_priv(indio_dev);
+ struct sdp31_reading r;
+ int ret;
+
+ switch (mask) {
+ case IIO_CHAN_INFO_RAW:
+ mutex_lock(&data->lock);
+ ret = sdp31_measure(data->client, &r);
+ mutex_unlock(&data->lock);
+ if (ret)
+ return ret;
+ switch (chan->type) {
+ case IIO_PRESSURE:
+ *val = r.pressure;
+ return IIO_VAL_INT;
+ case IIO_TEMP:
+ *val = r.temp;
+ return IIO_VAL_INT;
+ default:
+ return -EINVAL;
+ }
+ case IIO_CHAN_INFO_SCALE:
+ switch (chan->type) {
+ case IIO_PRESSURE:
+ /* raw / dp_scale = Pa; /1000 => kPa (IIO unit) */
+ *val = 1;
+ *val2 = data->dp_scale * 1000;
+ return IIO_VAL_FRACTIONAL;
+ case IIO_TEMP:
+ *val = SDP31_TEMP_SCALE;
+ return IIO_VAL_INT;
+ default:
+ return -EINVAL;
+ }
+ default:
+ return -EINVAL;
+ }
+}
+
+static const struct iio_info sdp31_info = {
+ .read_raw = sdp31_read_raw,
+};
+
+static const struct iio_chan_spec sdp31_channels[] = {
+ {
+ .type = IIO_PRESSURE,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE),
+ },
+ {
+ .type = IIO_TEMP,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
+ BIT(IIO_CHAN_INFO_SCALE),
+ },
+};
+
+static int sdp31_probe(struct i2c_client *client)
+{
+ struct iio_dev *indio_dev;
+ struct sdp31_data *data;
+ struct sdp31_reading r;
+ int ret;
+
+ indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+ if (!indio_dev)
+ return -ENOMEM;
+
+ data = iio_priv(indio_dev);
+ data->client = client;
+ mutex_init(&data->lock);
+
+ crc8_populate_msb(sdp31_crc8_table, SDP31_CRC8_POLY);
+
+ /* Confirm the sensor is present and learn its scale factor. */
+ ret = sdp31_measure(client, &r);
+ if (ret)
+ return dev_err_probe(&client->dev, ret,
+ "failed to read from sensor\n");
+ if (!r.scale)
+ return dev_err_probe(&client->dev, -EINVAL,
+ "invalid scale factor\n");
+ data->dp_scale = r.scale;
+
+ indio_dev->name = "sdp31";
+ indio_dev->info = &sdp31_info;
+ indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->channels = sdp31_channels;
+ indio_dev->num_channels = ARRAY_SIZE(sdp31_channels);
+
+ return devm_iio_device_register(&client->dev, indio_dev);
+}
+
+static const struct i2c_device_id sdp31_id[] = {
+ { "sdp31" },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, sdp31_id);
+
+static const struct of_device_id sdp31_of_match[] = {
+ { .compatible = "sensirion,sdp31" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, sdp31_of_match);
+
+static struct i2c_driver sdp31_driver = {
+ .driver = {
+ .name = "sdp31",
+ .of_match_table = sdp31_of_match,
+ },
+ .probe = sdp31_probe,
+ .id_table = sdp31_id,
+};
+module_i2c_driver(sdp31_driver);
+
+MODULE_AUTHOR("Muhammad Abu Bakar");
+MODULE_DESCRIPTION("Sensirion SDP31 differential pressure sensor");
+MODULE_LICENSE("GPL");
--
2.43.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/2] iio: pressure: add Sensirion SDP31 driver
2026-09-19 22:38 ` [PATCH 0/2] iio: pressure: add Sensirion SDP31 driver Muhammad Abu Bakar
2026-09-19 22:38 ` [PATCH 1/2] dt-bindings: iio: pressure: add Sensirion SDP31 Muhammad Abu Bakar
2026-09-19 22:38 ` [PATCH 2/2] iio: pressure: add Sensirion SDP31 driver Muhammad Abu Bakar
@ 2026-09-20 0:34 ` Jonathan Cameron
2 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2026-09-20 0:34 UTC (permalink / raw)
To: Muhammad Abu Bakar
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, dlechner,
nuno.sa, andy, linux-iio, devicetree, linux-kernel
On Sun, 20 Sep 2026 03:38:52 +0500
Muhammad Abu Bakar <m.abubakar365@yahoo.com> wrote:
> This series adds support for the Sensirion SDP31 differential pressure
> sensor, an I2C device that also reports temperature.
>
> Patch 1 adds the device tree binding.
> Patch 2 adds the IIO driver, which exposes differential pressure and
> temperature channels and validates each measurement using the sensor's
> CRC-8 checksum.
Hi,
Given we have another sensirion pressure sensor supported already (the SDP500)
I'd expect a brief note here on why it doesn't make sense to add support to
that driver for this new part. Also check other similar drivers as sometimes
we get compatible parts from multiple vendors.
FWIW the two parts don't look to be that similar so probably a very short note :)
Jonathan
>
> The driver was developed and tested on an SDP31 wired to the I2C bus of
> a Raspberry Pi 4.
>
> Muhammad Abu Bakar (2):
> dt-bindings: iio: pressure: add Sensirion SDP31
> iio: pressure: add Sensirion SDP31 driver
>
> .../iio/pressure/sensirion,sdp31.yaml | 40 ++++
> MAINTAINERS | 6 +
> drivers/iio/pressure/Kconfig | 11 +
> drivers/iio/pressure/Makefile | 1 +
> drivers/iio/pressure/sdp31.c | 194 ++++++++++++++++++
> 5 files changed, 252 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
> create mode 100644 drivers/iio/pressure/sdp31.c
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] dt-bindings: iio: pressure: add Sensirion SDP31
2026-09-19 22:38 ` [PATCH 1/2] dt-bindings: iio: pressure: add Sensirion SDP31 Muhammad Abu Bakar
@ 2026-09-20 0:40 ` Jonathan Cameron
2026-09-28 20:45 ` Muhammad Abu Bakar
0 siblings, 1 reply; 7+ messages in thread
From: Jonathan Cameron @ 2026-09-20 0:40 UTC (permalink / raw)
To: Muhammad Abu Bakar
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, dlechner,
nuno.sa, andy, linux-iio, devicetree, linux-kernel
On Sun, 20 Sep 2026 03:38:53 +0500
Muhammad Abu Bakar <m.abubakar365@yahoo.com> wrote:
> Add device tree bindings for the Sensirion SDP31 differential pressure
> sensor, an I2C device that also reports temperature.
>
> Signed-off-by: Muhammad Abu Bakar <m.abubakar365@yahoo.com>
> ---
> .../iio/pressure/sensirion,sdp31.yaml | 40 +++++++++++++++++++
> 1 file changed, 40 insertions(+)
> create mode 100644 Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
>
> diff --git a/Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml b/Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
> new file mode 100644
> index 000000000..fc646eca2
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
> @@ -0,0 +1,40 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/iio/pressure/sensirion,sdp31.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Sensirion SDP31 differential pressure sensor
> +
> +maintainers:
> + - Muhammad Abu Bakar <m.abubakar365@yahoo.com>
> +
> +description: |
> + Differential pressure sensor from Sensirion with an I2C interface.
> +
> +properties:
> + compatible:
> + const: sensirion,sdp31
It looks like there several similar parts that only differ in
range. Would be nice to support them all out of the box. Fine
to just test on one in a family like this. If there are more differences
then ignore this feedback!
> +
> + reg:
> + maxItems: 1
> +
> + vdd-supply: true
> +
Where is the irq? Even if a driver doesn't yet support all the
features, the dt binding should describe them if at all possible.
> +required:
> + - compatible
> + - reg
Sashiko correctly points out that devices tend to need vdd-supply to work.
Hence it should be in the required. That's not to say in practice it needs
to be in the dts given the regulator subsystem handling of missing regs
is to fake one on the basis the power is probably always on.
> +
> +additionalProperties: false
> +
> +examples:
> + - |
> + i2c {
> + #address-cells = <1>;
> + #size-cells = <0>;
> + pressure@21 {
> + compatible = "sensirion,sdp31";
> + reg = <0x21>;
> + vdd-supply = <&vdd_3v3>;
> + };
> + };
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 2/2] iio: pressure: add Sensirion SDP31 driver
2026-09-19 22:38 ` [PATCH 2/2] iio: pressure: add Sensirion SDP31 driver Muhammad Abu Bakar
@ 2026-09-20 0:53 ` Jonathan Cameron
0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2026-09-20 0:53 UTC (permalink / raw)
To: Muhammad Abu Bakar
Cc: Rob Herring, Krzysztof Kozlowski, Conor Dooley, dlechner,
nuno.sa, andy, linux-iio, devicetree, linux-kernel
On Sun, 20 Sep 2026 03:38:54 +0500
Muhammad Abu Bakar <m.abubakar365@yahoo.com> wrote:
> Add an IIO driver for the Sensirion SDP31 differential pressure sensor.
> The device is accessed over I2C and reports differential pressure and
> temperature. Each measurement is validated using the sensor's CRC-8
> checksum.
>
> Tested on an SDP31 connected to a Raspberry Pi 4 I2C bus.
>
> Signed-off-by: Muhammad Abu Bakar <m.abubakar365@yahoo.com>
Welcome to IIO.
Sashiko has some feedback on this one. Please take a look.
https://sashiko.dev/#/patchset/20260919223854.13437-1-m.abubakar365%40yahoo.com
the DO_ONCE is a sensible suggestion and cleaner than what we
used to do with the crc setup in init(). Note there may well
be other drivers doing this wrong today - I haven't checked!
Generally a nice little driver. Some stuff in here looks quite
like how we did things a while back. I'm guessing you perhaps
modelled it on an older driver? Anyhow, nothing major - just changing
conventions.
Thanks,
Jonathan
> ---
> MAINTAINERS | 6 ++
> drivers/iio/pressure/Kconfig | 11 ++
> drivers/iio/pressure/Makefile | 1 +
> drivers/iio/pressure/sdp31.c | 194 ++++++++++++++++++++++++++++++++++
> 4 files changed, 212 insertions(+)
> create mode 100644 drivers/iio/pressure/sdp31.c
>
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 214aeee76..a053a530e 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -24855,6 +24855,12 @@ S: Maintained
> F: Documentation/devicetree/bindings/iio/chemical/sensirion,scd4x.yaml
> F: drivers/iio/chemical/scd4x.c
>
> +SENSIRION SDP31 DIFFERENTIAL PRESSURE SENSOR DRIVER
> +M: Muhammad Abu Bakar <m.abubakar365@yahoo.com>
> +S: Maintained
> +F: Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
> +F: drivers/iio/pressure/sdp31.c
>
Add the initial Maintainers entry in the dt-binding patch, then add
just the new file here.
> diff --git a/drivers/iio/pressure/sdp31.c b/drivers/iio/pressure/sdp31.c
> new file mode 100644
> index 000000000..934a3afcd
> --- /dev/null
> +++ b/drivers/iio/pressure/sdp31.c
> +
> +static int sdp31_send_cmd(struct i2c_client *client, u16 cmd)
> +{
> + u8 buf[2] = { cmd >> 8, cmd & 0xff };
Given it seems to be handled as a be16, I'd just use one for it
complete with a cpu_to_be16() to put the data in the right order.
> + int ret = i2c_master_send(client, buf, sizeof(buf));
> +
> + if (ret < 0)
> + return ret;
> + return (ret == sizeof(buf)) ? 0 : -EIO;
> +}
> +
> +static int sdp31_check_crc(const u8 *word)
> +{
> + if (crc8(sdp31_crc8_table, word, 2, SDP31_CRC8_INIT) != word[2])
> + return -EIO;
> + return 0;
> +}
> +
> +static int sdp31_measure(struct i2c_client *client, struct sdp31_reading *out)
For below, pass in your spd31_data structure instead of client.
> +{
> + u8 rx[9];
> + int ret;
The thing being serialized by the lock is the contents of this. As such
I'd lock in here rather than at caller with
guard(mutex)(&data->lock);
That to me makes the lock scope more obvious.
> +
> + ret = sdp31_send_cmd(client, SDP31_CMD_TRIG_DP);
> + if (ret)
> + return ret;
> +
> + msleep(SDP31_MEAS_DELAY_MS);
> +
> + ret = i2c_master_recv(client, rx, sizeof(rx));
> + if (ret < 0)
> + return ret;
> + if (ret != sizeof(rx))
> + return -EIO;
> +
> + if (sdp31_check_crc(&rx[0]) ||
> + sdp31_check_crc(&rx[3]) ||
> + sdp31_check_crc(&rx[6]))
> + return -EIO;
> +
> + out->pressure = (s16)((rx[0] << 8) | rx[1]);
> + out->temp = (s16)((rx[3] << 8) | rx[4]);
> + out->scale = (rx[6] << 8) | rx[7];
get_unaligned_be16() for each of these + appropriate include
for that.
> + return 0;
> +}
> +
> +static int sdp31_probe(struct i2c_client *client)
> +{
Quite useful to have a local device pointer given how often it is used
struct device *dev = &client->dev;
> + struct iio_dev *indio_dev;
> + struct sdp31_data *data;
> + struct sdp31_reading r;
> + int ret;
> +
> + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + data = iio_priv(indio_dev);
> + data->client = client;
> + mutex_init(&data->lock);
For new code
ret = devm_mutex_init(dev, &data->lock);
if (ret)
return ret;
It adds some lock debugging related stuff. Whilst it tends not
to be that useful for how we use these locks in an IIO driver, it
is near free to turn on so we prefer that we do that.
> +
> + crc8_populate_msb(sdp31_crc8_table, SDP31_CRC8_POLY);
Sashiko got the race here if multiple instances of this devices are
connected and probing in parallel. The DO_ONCE() magic should deal
with that for you.
> +
> + /* Confirm the sensor is present and learn its scale factor. */
> + ret = sdp31_measure(client, &r);
> + if (ret)
> + return dev_err_probe(&client->dev, ret,
> + "failed to read from sensor\n");
Once you have dev as a local variable these sort of prints that only
go a little over 80 chars are fine on one line.
> + if (!r.scale)
> + return dev_err_probe(&client->dev, -EINVAL,
> + "invalid scale factor\n");
> + data->dp_scale = r.scale;
> +
> + indio_dev->name = "sdp31";
> + indio_dev->info = &sdp31_info;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->channels = sdp31_channels;
> + indio_dev->num_channels = ARRAY_SIZE(sdp31_channels);
> +
> + return devm_iio_device_register(&client->dev, indio_dev);
> +}
> +
> +static const struct i2c_device_id sdp31_id[] = {
> + { "sdp31" },
As sashiko calls out. Standard now is named initializers
for all the ID tables.
> + { }
> +};
> +MODULE_DEVICE_TABLE(i2c, sdp31_id);
> +
> +static const struct of_device_id sdp31_of_match[] = {
> + { .compatible = "sensirion,sdp31" },
> + { }
> +};
> +MODULE_DEVICE_TABLE(of, sdp31_of_match);
> +
> +static struct i2c_driver sdp31_driver = {
> + .driver = {
> + .name = "sdp31",
> + .of_match_table = sdp31_of_match,
> + },
> + .probe = sdp31_probe,
> + .id_table = sdp31_id,
> +};
> +module_i2c_driver(sdp31_driver);
> +
> +MODULE_AUTHOR("Muhammad Abu Bakar");
> +MODULE_DESCRIPTION("Sensirion SDP31 differential pressure sensor");
> +MODULE_LICENSE("GPL");
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/2] dt-bindings: iio: pressure: add Sensirion SDP31
2026-09-20 0:40 ` Jonathan Cameron
@ 2026-09-28 20:45 ` Muhammad Abu Bakar
0 siblings, 0 replies; 7+ messages in thread
From: Muhammad Abu Bakar @ 2026-09-28 20:45 UTC (permalink / raw)
To: Jonathan Cameron
Cc: robh, krzk+dt, conor+dt, dlechner, nuno.sa, andy, linux-iio,
devicetree, linux-kernel, m.abubakar365
On Sun, 20 Sep 2026 01:40:32 +0100
Jonathan Cameron <jic23@kernel.org> wrote:
Hi Jonathan,
Apologies - your v1 review replies were going to my spam folder and I
only saw them now. I have fixed that. I agree with all of the feedback
and will address it in v4.
> > + compatible:
> > + const: sensirion,sdp31
>
> It looks like there several similar parts that only differ in
> range. Would be nice to support them all out of the box. Fine
> to just test on one in a family like this.
The SDP31/SDP32/SDP33 differ only in measurement range, and the driver
already reads the scale factor from the sensor at runtime, so I will add
compatibles for all three (tested on the SDP31).
> > + vdd-supply: true
>
> Where is the irq? Even if a driver doesn't yet support all the
> features, the dt binding should describe them if at all possible.
I will add an optional interrupts property in v4.
> > +required:
> > + - compatible
> > + - reg
>
> Sashiko correctly points out that devices tend to need vdd-supply to
> work. Hence it should be in the required.
Agreed - vdd-supply has been in the required list since v2.
I will also address your v3 driver comments (shorter I2C reads for the
normal measurement, and reading the scale factor separately) in v4.
Thanks for your patience, and for flagging the missed replies.
Muhammad Abu Bakar
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-09-28 20:45 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20260919223854.13437-1-m.abubakar365.ref@yahoo.com>
2026-09-19 22:38 ` [PATCH 0/2] iio: pressure: add Sensirion SDP31 driver Muhammad Abu Bakar
2026-09-19 22:38 ` [PATCH 1/2] dt-bindings: iio: pressure: add Sensirion SDP31 Muhammad Abu Bakar
2026-09-20 0:40 ` Jonathan Cameron
2026-09-28 20:45 ` Muhammad Abu Bakar
2026-09-19 22:38 ` [PATCH 2/2] iio: pressure: add Sensirion SDP31 driver Muhammad Abu Bakar
2026-09-20 0:53 ` Jonathan Cameron
2026-09-20 0:34 ` [PATCH 0/2] " Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®