Skip to contentSkip to conversation

iio: pressure: add Sensirion SDP31 driver

PATCH Superseded Muhammad Abu Bakar 3 participants 6 messages Sep 26 – Sep 27 1 message not in the archive

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

v3 cover iio: pressure: add Sensirion SDP31 driver

This series adds support for the Sensirion SDP31 differential pressure sensor, an I2C device that also reports temperature.

The SDP31 uses a completely different I2C command protocol from the already supported SDP500 (command-triggered measurements with a per-word CRC-8), so extending the sdp500 driver does not make sense. No compatible parts from other vendors were found.

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.

Changes since v2:
- Remove leftover development annotation comments from the driver.
- Drop the SDP31_TEMP_SCALE define and use the value inline.
- In sdp31_send_cmd(), separate the declaration of ret from the call so the call sits next to its error check.
- Add blank lines before the trailing return statements.
- Wait for the sensor's power-up time (datasheet t_PU) after enabling the regulator, before the first I2C transaction.

Changes since v1:
- dt-bindings: make vdd-supply required, and enable the regulator in the driver using devm_regulator_get_enable().
- Move the MAINTAINERS entry into the dt-bindings patch; the driver patch only adds its own file.
- Populate the CRC-8 table with DO_ONCE() to avoid a race between concurrent probes.
- Use devm_mutex_init() and take the lock inside sdp31_measure() using guard(mutex).
- Build the command with __be16/cpu_to_be16() and parse the reply with get_unaligned_be16().
- Use a named initializer in the i2c_device_id table.

v1: https://lore.kernel.org/linux-iio/[email protected]/
v2: https://lore.kernel.org/linux-iio/[email protected]/

Muhammad Abu Bakar (2):
dt-bindings: iio: pressure: add Sensirion SDP31
iio: pressure: add Sensirion SDP31 driver

 .../iio/pressure/sensirion,sdp31.yaml         |  41 ++++
 MAINTAINERS                                   |   6 +
 drivers/iio/pressure/Kconfig                  |  11 +
 drivers/iio/pressure/Makefile                 |   1 +
 drivers/iio/pressure/sdp31.c                  | 213 ++++++++++++++++++
 5 files changed, 272 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
 create mode 100644 drivers/iio/pressure/sdp31.c
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 1/2 dt-bindings: iio: pressure: add Sensirion SDP31

Add device tree bindings for the Sensirion SDP31 differential pressure sensor, an I2C device that also reports temperature.

---
 .../iio/pressure/sensirion,sdp31.yaml         | 41 +++++++++++++++++++
 MAINTAINERS                                   |  5 +++
 2 files changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml new file +41 -0
new file mode 100644
index 000000000..a98e7c97e
@@ -0,0 +1,41 @@
+# 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 <[email protected]>
+
+description: |
+  Differential pressure sensor from Sensirion with an I2C interface.
+
+properties:
+  compatible:
+    const: sensirion,sdp31
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      pressure@21 {
+        compatible = "sensirion,sdp31";
+        reg = <0x21>;
+        vdd-supply = <&vdd_3v3>;
+      };
+    };
MAINTAINERS +5 -0
index 214aeee76..e285147be 100644
@@ -24855,6 +24855,11 @@ 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 <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
+
 SENSIRION SDP500 DIFFERENTIAL PRESSURE SENSOR DRIVER
 M:	Petar Stoykov <[email protected]>
 S:	Maintained
Signature · 1 line
2.43.0
#3 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: pressure: add Sensirion SDP31

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] dt-bindings: missing interrupts property for IRQ pin --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dt-bindings: missing interrupts property for IRQ pin
--

commit 4db91d50e49cd1f9c9265de070c68dad6d777537
Author: Muhammad Abu Bakar <[email protected]>

dt-bindings: iio: pressure: add Sensirion SDP31

This commit adds device tree bindings for the Sensirion SDP31 differential pressure sensor. The sensor is an I2C device that reports both pressure and temperature.

Quoted 5 lines
Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml new file +0 -0
new file mode 100644
index 0000000000000..a98e7c97ef160

[ ... ]

Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml line 29

Quoted 6 lines
Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml new file +6 -0
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+additionalProperties: false

[Severity: Medium]
Does this schema fully describe the hardware capabilities?

The Sensirion SDP31 has an IRQ/ADDR pin (Pin 4) that a board designer might wire to an interrupt controller. Because additionalProperties is set to false here, if a device tree includes the interrupts property to describe this hardware connection, the schema validation will fail.

Device tree bindings typically describe the full capabilities of the hardware, rather than just what the current OS driver supports. Should the interrupts property be explicitly defined in this schema to prevent validation errors for complete hardware descriptions?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#4 lore raw

Re: [PATCH v3 1/2] dt-bindings: iio: pressure: add Sensirion SDP31

In reply to Muhammad Abu Bakar
Quoted 4 lines · On Sat, 26 Sep 2026 20:41:17 +0500 Muhammad Abu Bakar…

Add device tree bindings for the Sensirion SDP31 differential pressure sensor, an I2C device that also reports temperature.

I think you have been missing some replies for some reason.

See https://lore.kernel.org/all/20260920014032.2cc3c851@jic23-hlaptop/
Also the reply Krzysztof sent to point out you hadn't addressed all the feedback on v1.

If you disagree with any suggestions then reply to that email.

Reviewers tend to stop reviewing very quickly if they see that stuff they raised in previous versions hasn't been addressed yet.

Jonathan

Quoted 69 lines
---
 .../iio/pressure/sensirion,sdp31.yaml         | 41 +++++++++++++++++++
 MAINTAINERS                                   |  5 +++
 2 files changed, 46 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml new file +41 -0
new file mode 100644
index 000000000..a98e7c97e
@@ -0,0 +1,41 @@
+# 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 <[email protected]>
+
+description: |
+  Differential pressure sensor from Sensirion with an I2C interface.
+
+properties:
+  compatible:
+    const: sensirion,sdp31
+
+  reg:
+    maxItems: 1
+
+  vdd-supply: true
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+      pressure@21 {
+        compatible = "sensirion,sdp31";
+        reg = <0x21>;
+        vdd-supply = <&vdd_3v3>;
+      };
+    };
MAINTAINERS +5 -0
index 214aeee76..e285147be 100644
@@ -24855,6 +24855,11 @@ 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 <[email protected]>
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
+
 SENSIRION SDP500 DIFFERENTIAL PRESSURE SENSOR DRIVER
 M:	Petar Stoykov <[email protected]>
 S:	Maintained
#5 lore raw

PATCH v3 2/2 iio: pressure: add Sensirion SDP31 driver

In reply to 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.

---
 MAINTAINERS                   |   1 +
 drivers/iio/pressure/Kconfig  |  11 ++
 drivers/iio/pressure/Makefile |   1 +
 drivers/iio/pressure/sdp31.c  | 213 ++++++++++++++++++++++++++++++++++
 4 files changed, 226 insertions(+)
 create mode 100644 drivers/iio/pressure/sdp31.c
MAINTAINERS +1 -0
index e285147be..a053a530e 100644
@@ -24859,6 +24859,7 @@ SENSIRION SDP31 DIFFERENTIAL PRESSURE SENSOR DRIVER
 M:	Muhammad Abu Bakar <[email protected]>
 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 <[email protected]>
drivers/iio/pressure/Kconfig +11 -0
index 838a8340c..58172639c 100644
@@ -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
drivers/iio/pressure/Makefile +1 -0
index bc0d11a20..5279a0ebd 100644
@@ -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
drivers/iio/pressure/sdp31.c new file +213 -0

213 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#6 lore raw
Quoted 8 lines · On Sat, 26 Sep 2026 20:41:18 +0500 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.

Hi.

Given you are going to probably need to changes stuff in the dt binding and so do a v4, various comments inline. Mostly optimization suggestions.

Jonathan

Quoted 11 lines

st_pressure-y := st_pressure_core.o

drivers/iio/pressure/sdp31.c new file +4 -0
new file mode 100644
index 000000000..fd7cac027
 
+static int sdp31_measure(struct sdp31_data *data, struct sdp31_reading *out)
+{
+	u8 rx[9];
+	int ret;

drivers/iio/pressure/sdp31.c line 67

Quoted 10 lines
drivers/iio/pressure/sdp31.c new file +10 -0
+
+	guard(mutex)(&data->lock);
+
+	ret = sdp31_send_cmd(data->client, SDP31_CMD_TRIG_DP);
+	if (ret)
+		return ret;
+
+	msleep(SDP31_MEAS_DELAY_MS);
+
+	ret = i2c_master_recv(data->client, rx, sizeof(rx));

Given there is only a one time read of scale and that i2c is a rather slow bus, can we do a short read when we only want the temperature and pressure? The datasheet mentions Nack + stop is sufficient to stop the read out sequence and that is IIRC the normal end of an i2c read sequence. So it 'should' be fine to just read fewer bytes.

Quoted 35 lines
drivers/iio/pressure/sdp31.c new file +34 -0
+	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)get_unaligned_be16(&rx[0]);
+	out->temp = (s16)get_unaligned_be16(&rx[3]);
+	out->scale = get_unaligned_be16(&rx[6]);
+
+	return 0;
+}
 
+
+static int sdp31_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct iio_dev *indio_dev;
+	struct sdp31_data *data;
+	struct sdp31_reading r;
+	int ret;
+
+	ret = devm_regulator_get_enable(dev, "vdd");
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to enable regulator\n");
+
+	/* Wait for the sensor to be ready after power-up (datasheet t_PU). */
+	msleep(SDP31_POWERUP_TIME_MS);
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+	if (!indio_dev)

drivers/iio/pressure/sdp31.c line 169

Quoted 10 lines
drivers/iio/pressure/sdp31.c new file +10 -0
+		return -ENOMEM;
+
+	data = iio_priv(indio_dev);
+	data->client = client;
+
+	ret = devm_mutex_init(dev, &data->lock);
+	if (ret)
+		return ret;
+
+	/* The CRC table is shared by all instances; initialise it once. */

I would argue that is obvious, so no comment needed.

drivers/iio/pressure/sdp31.c line 172

Quoted 3 lines
drivers/iio/pressure/sdp31.c new file +3 -0
+	DO_ONCE(crc8_populate_msb, sdp31_crc8_table, SDP31_CRC8_POLY);
+
+	/* Confirm the sensor is present and learn its scale factor. */

If you end up with with a specific call to get the scale factor this comment will become excessive (see below).

drivers/iio/pressure/sdp31.c line 177

Quoted 5 lines
drivers/iio/pressure/sdp31.c new file +5 -0
+	ret = sdp31_measure(data, &r);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to read from sensor\n");
+	if (!r.scale)
+		return dev_err_probe(dev, -EINVAL, "invalid scale factor\n");

See above. This is the only time we actually read the scale - so perhaps we can save some traffic on every other access. Most likely that would give you a different command for this scale read back.

Quoted 10 lines
drivers/iio/pressure/sdp31.c new file +10 -0
+	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(dev, indio_dev);
+}