Skip to contentSkip to conversation

iio: chemical: add support for SGP41 sensor

PATCH New Akshat Chandra 3 participants 5 messages Nov 15

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover iio: chemical: add support for SGP41 sensor

The SGP41 is a gas sensor used for air quality monitoring by sensing VOC and NOx.

This driver follows the approach of exposing raw resistance values to userspace, where the gas-index algorithm can be applied.

Temperature and relative humidity compensation are supported and can be configured through the driver's IIO attributes.

The SGP41 is similar to the existing SGP40, but requires its own driver for the following reasons:

- It has a dedicated conditioning command that must be performed before raw measurements.
- A measurement returns a 6-byte response containing two raw tick values, each with its own CRC, rather than the SGP40's single value.
- It supports both VOC and NOx measurements and requires the heater to be powered off after use.

The series consists of two patches:

1/2: dt-bindings: iio: chemical: Add Sensirion SGP41 binding
Add a dedicated Device Tree binding, including the VDD supply.
2/2: iio: chemical: Add support for Sensirion SGP41
Add the IIO driver for the sensor.

Changes in v2:
- Split the binding and driver into separate patches.
- Add a dedicated Device Tree binding documenting the VDD supply.
- Update the driver and patch descriptions following review feedback.
- Fixed some issues in driver.

v1: https://patchew.org/linux/20260831151235.64076-1-notmissinge%40gmail.com/

#1 lore raw

PATCH v2 1/2 dt-bindings: iio: chemical: Add Sensirion SGP41 binding

Add a Device Tree binding for the Sensirion SGP41 VOC and NOx gas sensor, including its VDD supply.

---
 .../iio/chemical/sensirion,sgp41.yaml         | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/chemical/sensirion,sgp41.yaml
Documentation/devicetree/bindings/iio/chemical/sensirion,sgp41.yaml new file +43 -0
new file mode 100644
index 000000000000..28528a695cf3
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/chemical/sensirion,sgp41.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sensirion SGP41 VOC and NOx gas sensor
+
+maintainers:
+  - Akshat Chandra <[email protected]>
+
+description: |
+  Sensirion SGP41 indoor air quality sensor measuring raw VOC and NOx
+  signals over I2C.
+
+properties:
+  compatible:
+    const: sensirion,sgp41
+
+  reg:
+    const: 0x59
+
+  vdd-supply: true
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+additionalProperties: false
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      gas-sensor@59 {
+        compatible = "sensirion,sgp41";
+        reg = <0x59>;
+        vdd-supply = <&vdd>;
+      };
+    };
+...
Signature · 1 line
2.53.0
#2 lore raw

Re: [PATCH v2 1/2] dt-bindings: iio: chemical: Add Sensirion SGP41 binding

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Medium] dt-bindings: iio: chemical: sgp41: missing vddh-supply for heater pin - [Low] dt-bindings: iio…

Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Medium] dt-bindings: iio: chemical: sgp41: missing vddh-supply for heater pin
- [Low] dt-bindings: iio: chemical: sgp41: 2-space example indent and const reg
- [Low] dt-bindings: iio: chemical: sgp41: deprecated GPL-2.0 SPDX license tag
--

commit 364f23f4f9b681d905ad97232d6cdcac6d5b17e4
Author: Akshat Chandra <[email protected]>

dt-bindings: iio: chemical: Add Sensirion SGP41 binding

This commit adds a Device Tree binding schema for the Sensirion SGP41 VOC and NOx I2C gas sensor.

Documentation/devicetree/bindings/iio/chemical/sensirion,sgp41.yaml line 1

Quoted 7 lines
Documentation/devicetree/bindings/iio/chemical/sensirion,sgp41.yaml new file +1 -0
new file mode 100644
index 0000000000000..c2bb6818f4390
@@ -0,0 +1,43 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)

[Severity: Low]
Should this use (GPL-2.0-only OR BSD-2-Clause) instead of the deprecated GPL-2.0 identifier, per Documentation/devicetree/bindings/submitting-patches.rst?

Quoted 18 lines
Documentation/devicetree/bindings/iio/chemical/sensirion,sgp41.yaml new file +18 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/iio/chemical/sensirion,sgp41.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Sensirion SGP41 VOC and NOx gas sensor
+
+maintainers:
+  - Akshat Chandra <[email protected]>
+
+description: |
+  Sensirion SGP41 indoor air quality sensor measuring raw VOC and NOx
+  signals over I2C.
+
+properties:
+  compatible:
+    const: sensirion,sgp41
+

Documentation/devicetree/bindings/iio/chemical/sensirion,sgp41.yaml line 29

Quoted 10 lines
Documentation/devicetree/bindings/iio/chemical/sensirion,sgp41.yaml new file +10 -0
+  reg:
+    const: 0x59
+
+  vdd-supply: true
+
+required:
+  - compatible
+  - reg
+  - vdd-supply
+additionalProperties: false

[Severity: Medium]
Should the schema also define vddh-supply?

The SGP41 has a dedicated VDDH pin for the hotplate heater supply in addition to the logic VDD pin. Boards that power VDD (for example at 1.8 V for I2C) and VDDH from separate regulators cannot describe vddh-supply in Device Tree when additionalProperties is false without failing dtbs_check.

Documentation/devicetree/bindings/iio/chemical/sensirion,sgp41.yaml line 42

Quoted 13 lines
Documentation/devicetree/bindings/iio/chemical/sensirion,sgp41.yaml new file +13 -0
+
+examples:
+  - |
+    i2c {
+      #address-cells = <1>;
+      #size-cells = <0>;
+
+      gas-sensor@59 {
+        compatible = "sensirion,sgp41";
+        reg = <0x59>;
+        vdd-supply = <&vdd>;
+      };
+    };

[Severity: Low]
The example uses 2-space indentation instead of 4 spaces per level, which triggers an indent-unit-strict warning from scripts/dtc/dt-check-style. Also, should reg in properties use maxItems: 1 rather than const: 0x59 to follow standard IIO binding conventions and allow I2C address translation?

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

PATCH v2 2/2 iio: chemical: Add support for Sensirion SGP41

In reply to Akshat Chandra

Add a driver for the Sensirion SGP41 VOC and NOx gas sensor, connected over I2C.

Expose raw VOC and NOx signals as resistance channels and allow userspace to write temperature and relative humidity compensation values.

Run sensor conditioning lazily before the first raw measurement. Calculate an estimated VOC index and leave NOx-index calculation to userspace.

---
 drivers/iio/chemical/Kconfig  |  11 +
 drivers/iio/chemical/Makefile |   1 +
 drivers/iio/chemical/sgp41.c  | 542 ++++++++++++++++++++++++++++++++++
 3 files changed, 554 insertions(+)
 create mode 100644 drivers/iio/chemical/sgp41.c
drivers/iio/chemical/Kconfig +11 -0
index b22afa1f6d59..cbb6a51b1cfd 100644
@@ -210,6 +210,17 @@ config SENSIRION_SGP40
 	  To compile this driver as module, choose M here: the
 	  module will be called sgp40.
 
+config SENSIRION_SGP41
+	tristate "Sensirion SGP41 gas sensor"
+	depends on I2C
+	select CRC8
+	help
+	  Say Y here to build I2C interface to support Sensirion SGP41 gas
+	  sensor
+
+	  To compile this driver as module, choose M here: the
+	  module will be called sgp41.
+
 config SPS30
 	tristate
 	select IIO_BUFFER
drivers/iio/chemical/Makefile +1 -0
index 2287a00a6b75..90041aaa41fe 100644
@@ -25,6 +25,7 @@ obj-$(CONFIG_SEN0322)	+= sen0322.o
 obj-$(CONFIG_SENSEAIR_SUNRISE_CO2) += sunrise_co2.o
 obj-$(CONFIG_SENSIRION_SGP30)	+= sgp30.o
 obj-$(CONFIG_SENSIRION_SGP40)	+= sgp40.o
+obj-$(CONFIG_SENSIRION_SGP41)	+= sgp41.o
 obj-$(CONFIG_SPS30) += sps30.o
 obj-$(CONFIG_SPS30_I2C) += sps30_i2c.o
 obj-$(CONFIG_SPS30_SERIAL) += sps30_serial.o
drivers/iio/chemical/sgp41.c new file +542 -0

542 lines not on this page · raw message

+static struct i2c_driver sgp41_driver = {
+ .driver = {
+ .name = "sgp41",
+ .of_match_table = sgp41_dt_ids,
+ },
+ .probe = sgp41_probe,
+ .id_table = sgp41_id,
+ .remove = sgp41_remove,
+};
+
+module_i2c_driver(sgp41_driver);
+
+MODULE_AUTHOR("Akshat Chandra <[email protected]>"); +MODULE_DESCRIPTION("Sensirion SGP41 gas sensor"); +MODULE_LICENSE("GPL");
--
2.53.0

#4 lore raw

Re: [PATCH v2 2/2] iio: chemical: Add support for Sensirion SGP41

kernel test robot noticed the following build errors:

Hi Akshat,

kernel test robot noticed the following build errors:

[auto build test ERROR on jic23-iio/togreg]
[also build test ERROR on robh/for-next linus/master v7.4-rc2 next-20261113] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Akshat-Chandra/iio-chemical-Add-support-for-Sensirion-SGP41/20261115-112940
base:   https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg
patch link:    https://lore.kernel.org/r/20261115055941.362185-3-notmissinge%40gmail.com
patch subject: [PATCH v2 2/2] iio: chemical: Add support for Sensirion SGP41
config: nios2-allmodconfig (https://download.01.org/0day-ci/archive/20261116/[email protected]/config)
compiler: nios2-linux-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261116/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All error/warnings (new ones prefixed by >>, old ones prefixed by <<):

>> drivers/iio/chemical/sgp41.c:478:12: warning: 'sgp41_probe' defined but not used [-Wunused-function]
478 | static int sgp41_probe(struct i2c_client *client)
|            ^~~~~~~~~~~
>> drivers/iio/chemical/sgp41.c:459:13: warning: 'sgp41_remove' defined but not used [-Wunused-function]
459 | static void sgp41_remove(struct i2c_client *client)
|             ^~~~~~~~~~~~
--
>> ERROR: modpost: drivers/iio/chemical/sgp41.ko: missing MODULE_LICENSE()
>> WARNING: modpost: drivers/iio/chemical/sgp41.ko: missing MODULE_DESCRIPTION()

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki