Skip to contentSkip to conversation

iio: pressure: add Sensirion SDP31 driver

PATCH In review Muhammad Abu Bakar 3 participants 7 messages Oct 7 – Oct 18 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

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

#1 lore raw

v6 cover iio: pressure: add Sensirion SDP31 driver

This series adds support for the Sensirion SDP3x family of differential pressure sensors (SDP31, SDP32 and SDP33), I2C devices that also report temperature.

The SDP3x uses a completely different I2C command protocol from the already supported SDP500, so extending the sdp500 driver does not make sense.

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 SDP32 and SDP33 differ from the SDP31 only in range and use it as a fallback compatible; the scale factor is read from the sensor at runtime. Tested on an SDP31 wired to the I2C bus of a Raspberry Pi 4.

Changes since v5:
- dt-bindings: drop the literal block marker from the description.
- driver: drop the mod_devicetable.h include and re-wrap the sdp31_read_measurement() prototype.
- Use the plain "Assisted-by: LLM" form of the tag.
- Collect Reviewed-by tags from Krzysztof (patch 1) and Andy (patch 2).
- Fix the links to earlier versions below; previous cover letters pointed at wrong Message-IDs.

v1: https://lore.kernel.org/linux-iio/[email protected]/
v2: https://lore.kernel.org/linux-iio/[email protected]/
v3: https://lore.kernel.org/linux-iio/[email protected]/
v4: https://lore.kernel.org/linux-iio/[email protected]/
v5: 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         |  51 ++++
 MAINTAINERS                                   |   6 +
 drivers/iio/pressure/Kconfig                  |  11 +
 drivers/iio/pressure/Makefile                 |   1 +
 drivers/iio/pressure/sdp31.c                  | 243 ++++++++++++++++++
 5 files changed, 312 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 v6 1/2 dt-bindings: iio: pressure: add Sensirion SDP31

Add device tree bindings for the Sensirion SDP3x family of differential pressure sensors (SDP31, SDP32 and SDP33), I2C devices that also report temperature.

---
 .../iio/pressure/sensirion,sdp31.yaml         | 51 +++++++++++++++++++
 MAINTAINERS                                   |  5 ++
 2 files changed, 56 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml
Documentation/devicetree/bindings/iio/pressure/sensirion,sdp31.yaml new file +51 -0
new file mode 100644
index 000000000..14d780962
@@ -0,0 +1,51 @@
+# 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, SDP32 and SDP33 differential pressure sensors
+
+maintainers:
+  - Muhammad Abu Bakar <[email protected]>
+
+description:
+  Differential pressure sensors from Sensirion with an I2C interface.
+  The SDP31, SDP32 and SDP33 differ only in their measurement range.
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - sensirion,sdp32
+              - sensirion,sdp33
+          - const: sensirion,sdp31
+      - const: sensirion,sdp31
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    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

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

In reply to Muhammad Abu Bakar

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.

---
 MAINTAINERS                   |   1 +
 drivers/iio/pressure/Kconfig  |  11 ++
 drivers/iio/pressure/Makefile |   1 +
 drivers/iio/pressure/sdp31.c  | 243 ++++++++++++++++++++++++++++++++++
 4 files changed, 256 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 +243 -0

243 lines not on this page · raw message

Signature · 1 line
2.43.0
Reviewed-by on v6 2/2
#4 lore raw
Quoted 12 lines · Muhammad Abu Bakar

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.

---

...

Quoted 23 lines
drivers/iio/pressure/sdp31.c new file +23 -0
+static int sdp31_probe(struct i2c_client *client)
+{
+	struct device *dev = &client->dev;
+	struct iio_dev *indio_dev;
+	struct sdp31_data *data;
+	int ret;
+
+	ret = devm_regulator_get_enable(dev, "vdd");
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to enable regulator\n");
+
+	msleep(SDP31_POWERUP_TIME_MS);
+
+	indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
+	if (!indio_dev)
+		return -ENOMEM;
+
+	data = iio_priv(indio_dev);
+	data->client = client;
+
+	ret = devm_mutex_init(dev, &data->lock);
+	if (ret)
+		return ret;

drivers/iio/pressure/sdp31.c line 210

Quoted 10 lines
drivers/iio/pressure/sdp31.c new file +10 -0
+
+	DO_ONCE(crc8_populate_msb, sdp31_crc8_table, SDP31_CRC8_POLY);
+
+	ret = sdp31_read_scale(data, &data->dp_scale);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to read from sensor\n");
+	if (!data->dp_scale)
+		return dev_err_probe(dev, -EINVAL, "invalid scale factor\n");
+
+	indio_dev->name = "sdp31";

Hmm, I'm not sure whether it is a big deal or not but, the hardcoded name might cause confusion if the part connected is sdp32 or sdp33. That's because the device name will be sdp31, but the scale will be SDP32 scale for differential pressure (or SDP33 scale if one of those would be connected). The full disambiguation solution would probably be to read the product identifier bits and match those against a table of supported devices. It could have some sort of chip_info struct to hold the device name and maybe the pressure scale as well. That will probably require some boilerplate code that might not have been necessary otherwise.

The other parts of the device driver look good to me. So, if the naming thing is not needed,

Quoted 12 lines
drivers/iio/pressure/sdp31.c new file +12 -0
+	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);
+}
+
+static const struct i2c_device_id sdp31_id[] = {
+	{ .name = "sdp31" },
+	{ }
+};
#5 lore raw
Quoted 5 lines · On Mon, 12 Oct 2026 12:09:47 -0300 Marcelo Schmitt…

drivers/iio/pressure/sdp31.c line 210

Quoted 1 line
drivers/iio/pressure/sdp31.c new file +1 -0
+	indio_dev->name = "sdp31";

Hmm, I'm not sure whether it is a big deal or not but, the hardcoded name might cause confusion if the part connected is sdp32 or sdp33. [...]
The full disambiguation solution would probably be to read the product identifier bits and match those against a table of supported devices.

Hi Marcelo,

Thanks for taking a look, and good point.

I kept the name hardcoded because, after Conor's comment on v4, the SDP32 and SDP33 use sensirion,sdp31 as a fallback compatible, the way the sdp510 does with the sdp500 driver. You're right that it isn't quite the same situation, though: the sdp500 and sdp510 are identical, while the SDP3x parts differ in range. The readings are still correct, since the scale is read from the sensor at probe, but the name would always say "sdp31".

Reading the product identifier at probe and taking the name from a small chip_info table would fix that, and I'm happy to do it in a v7. Jonathan, would you prefer that, or is the current approach fine?

Thanks,
Muhammad

maintainer
#6 lore raw
Quoted 20 lines · On Thu, 15 Oct 2026 00:45:44 +0500 Muhammad Abu Bakar…
Quoted 5 lines · On Mon, 12 Oct 2026 12:09:47 -0300 Marcelo Schmitt…

drivers/iio/pressure/sdp31.c line 210

Quoted 1 line
drivers/iio/pressure/sdp31.c new file +1 -0
+	indio_dev->name = "sdp31";  

Hmm, I'm not sure whether it is a big deal or not but, the hardcoded name might cause confusion if the part connected is sdp32 or sdp33. [...]
The full disambiguation solution would probably be to read the product identifier bits and match those against a table of supported devices.

Hi Marcelo,

Thanks for taking a look, and good point.

I kept the name hardcoded because, after Conor's comment on v4, the SDP32 and SDP33 use sensirion,sdp31 as a fallback compatible, the way the sdp510 does with the sdp500 driver. You're right that it isn't quite the same situation, though: the sdp500 and sdp510 are identical, while the SDP3x parts differ in range. The readings are still correct, since the scale is read from the sensor at probe, but the name would always say "sdp31".

Quoted 3 lines

Reading the product identifier at probe and taking the name from a small chip_info table would fix that, and I'm happy to do it in a v7. Jonathan, would you prefer that, or is the current approach fine?

A question that is more 'interesting' than it would initially seem. Normally I'd agree with Marcelo that we should be as user friendly as possible, but there is a problem..

Given how well behaved and discoverable these parts are, the driver will work fine for new parts that we don't know about (which is sadly rather unusual!) That is why we can just use a single compatible. If we were to use the right name and saw an unknown part, what would call it? spd31 or something odd like spd31-compat. Then we would want to add the new part name but run into a problem. Doing so would be potential ABI breakage if anyone happened to be matching on spd31-compat :(

So let's go the easy way and just call them all spd31 as you have it today.

Good question though. My first reply that I typed out was to what Marcelo was suggesting then I changed my mind!

Jonathan

Quoted 3 lines

Thanks,
Muhammad

maintainer
#7 lore raw
In reply to Muhammad Abu Bakar
Quoted 8 lines · On Thu, 8 Oct 2026 01:51:02 +0500 Muhammad Abu Bakar…

This series adds support for the Sensirion SDP3x family of differential pressure sensors (SDP31, SDP32 and SDP33), I2C devices that also report temperature.

The SDP3x uses a completely different I2C command protocol from the already supported SDP500, so extending the sdp500 driver does not make sense.

Quoted 7 lines

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 SDP32 and SDP33 differ from the SDP31 only in range and use it as a fallback compatible; the scale factor is read from the sensor at runtime. Tested on an SDP31 wired to the I2C bus of a Raspberry Pi 4.

Lovely little driver. Thanks!

Applied to the testing branch of iio.git. I'll rebase that on rc1 once that is available then push out for linux-next to pick up.

Jonathan