Skip to contentSkip to conversation

add support for Sensirion SPS30 PM sensor

PATCH Superseded Tomasz Duszynski 2 participants 5 messages Dec 12, 2018 – Dec 14, 2018

Subsystems (3)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Tomasz Duszynski

author maintainer
#0 lore raw

v3 cover add support for Sensirion SPS30 PM sensor

This patch series adds support for Sensirion SPS30 particulate matter sensor. Along with a driver itself, new channel type and modifiers for distinguishing between coarse and fine particles measurements are introduced.

Sensor datasheet can be downloaded from

https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/0_Datasheets/Particulate_Matter/Sensirion_PM_Sensors_SPS30_Datasheet.pdf

v3:
* convert be32 to cpu using predefined macro
* remove semicolon: reported by semicolon.cocci
* use capitalization consistently (particulate matter)

v2:
* add support for PM1 and PM4 measurements
* get rid of variable length arrays
* do proper cleanup via devm_add_action_or_reset()
* add extra level of precision (two decimal places) while displaying measurements
* improve comments a little bit
* slight refactoring and general improvements here and there

Tomasz Duszynski (3):
iio: add IIO_MASSCONCENTRATION channel type
iio: chemical: add support for Sensirion SPS30 sensor
iio: chemical: sps30: add device tree support

 Documentation/ABI/testing/sysfs-bus-iio       |  17 +-
 .../bindings/iio/chemical/sensirion,sps30.txt |  12 +
 drivers/iio/chemical/Kconfig                  |  11 +
 drivers/iio/chemical/Makefile                 |   1 +
 drivers/iio/chemical/sps30.c                  | 406 ++++++++++++++++++
 drivers/iio/industrialio-core.c               |   5 +
 include/uapi/linux/iio/types.h                |   5 +
 tools/iio/iio_event_monitor.c                 |  10 +
 8 files changed, 466 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/iio/chemical/sensirion,sps30.txt
 create mode 100644 drivers/iio/chemical/sps30.c

--
2.19.2

author maintainer
#1 lore raw

PATCH v3 1/3 iio: add IIO_MASSCONCENTRATION channel type

Measuring particulate matter in ug / m3 (micro-grams per cubic meter) is de facto standard. Existing air quality sensors usually follow this convention and are capable of returning measurements using this unit.

IIO currently does not offer suitable channel type for this type of measurements hence this patch adds this.

In addition, extra modifiers are introduced used for distinguishing between fine pm1, pm2p5 and coarse pm4, pm10 particle measurements, i.e IIO_MOD_PM1, IIO_MOD_PM25 and IIO_MOD_PM4, IIO_MOD_PM10.

pmX consists of particles with aerodynamic diameter less or equal to X micrometers.

---
 Documentation/ABI/testing/sysfs-bus-iio | 17 ++++++++++++++++-
 drivers/iio/industrialio-core.c         |  5 +++++
 include/uapi/linux/iio/types.h          |  5 +++++
 tools/iio/iio_event_monitor.c           | 10 ++++++++++
 4 files changed, 36 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-iio +16 -1
index 8127a08e366d..ad9579a9385f 100644
@@ -1684,4 +1684,19 @@ KernelVersion:	4.18
 Contact:	[email protected]
 Description:
 		Raw (unscaled) phase difference reading from channel Y
-		that can be processed to radians.
\ No newline at end of file
+		that can be processed to radians.
+
+What:		/sys/bus/iio/devices/iio:deviceX/in_massconcentration_pm1_input
+What:		/sys/bus/iio/devices/iio:deviceX/in_massconcentrationY_pm1_input
+What:		/sys/bus/iio/devices/iio:deviceX/in_massconcentration_pm2p5_input
+What:		/sys/bus/iio/devices/iio:deviceX/in_massconcentrationY_pm2p5_input
+What:		/sys/bus/iio/devices/iio:deviceX/in_massconcentration_pm4_input
+What:		/sys/bus/iio/devices/iio:deviceX/in_massconcentrationY_pm4_input
+What:		/sys/bus/iio/devices/iio:deviceX/in_massconcentration_pm10_input
+What:		/sys/bus/iio/devices/iio:deviceX/in_massconcentrationY_pm10_input
+KernelVersion:	4.21
+Contact:	[email protected]
+Description:
+		Mass concentration reading of particulate matter in ug / m3.
+		pmX consists of particles with aerodynamic diameter less or
+		equal to X micrometers.
drivers/iio/industrialio-core.c +5 -0
index 4f5cd9f60870..4700fd5d8c90 100644
@@ -87,6 +87,7 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_GRAVITY]  = "gravity",
 	[IIO_POSITIONRELATIVE]  = "positionrelative",
 	[IIO_PHASE] = "phase",
+	[IIO_MASSCONCENTRATION] = "massconcentration",
 };
 
 static const char * const iio_modifier_names[] = {
@@ -127,6 +128,10 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_Q] = "q",
 	[IIO_MOD_CO2] = "co2",
 	[IIO_MOD_VOC] = "voc",
+	[IIO_MOD_PM1] = "pm1",
+	[IIO_MOD_PM2P5] = "pm2p5",
+	[IIO_MOD_PM4] = "pm4",
+	[IIO_MOD_PM10] = "pm10",
 };
 
 /* relies on pairs of these shared then separate */
include/uapi/linux/iio/types.h +5 -0
index 92baabc103ac..c59adac24b1c 100644
@@ -46,6 +46,7 @@ enum iio_chan_type {
 	IIO_GRAVITY,
 	IIO_POSITIONRELATIVE,
 	IIO_PHASE,
+	IIO_MASSCONCENTRATION,
 };
 
 enum iio_modifier {
@@ -87,6 +88,10 @@ enum iio_modifier {
 	IIO_MOD_VOC,
 	IIO_MOD_LIGHT_UV,
 	IIO_MOD_LIGHT_DUV,
+	IIO_MOD_PM1,
+	IIO_MOD_PM2P5,
+	IIO_MOD_PM4,
+	IIO_MOD_PM10,
 };
 
 enum iio_event_type {
tools/iio/iio_event_monitor.c +10 -0
index ac2de6b7e89f..f6b8003fbe3c 100644
@@ -60,6 +60,7 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_GRAVITY] = "gravity",
 	[IIO_POSITIONRELATIVE] = "positionrelative",
 	[IIO_PHASE] = "phase",
+	[IIO_MASSCONCENTRATION] = "massconcentration",
 };
 
 static const char * const iio_ev_type_text[] = {
@@ -115,6 +116,10 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_Q] = "q",
 	[IIO_MOD_CO2] = "co2",
 	[IIO_MOD_VOC] = "voc",
+	[IIO_MOD_PM1] = "pm1",
+	[IIO_MOD_PM2P5] = "pm2p5",
+	[IIO_MOD_PM4] = "pm4",
+	[IIO_MOD_PM10] = "pm10",
 };
 
 static bool event_is_known(struct iio_event_data *event)
@@ -156,6 +161,7 @@ static bool event_is_known(struct iio_event_data *event)
 	case IIO_GRAVITY:
 	case IIO_POSITIONRELATIVE:
 	case IIO_PHASE:
+	case IIO_MASSCONCENTRATION:
 		break;
 	default:
 		return false;
@@ -200,6 +206,10 @@ static bool event_is_known(struct iio_event_data *event)
 	case IIO_MOD_Q:
 	case IIO_MOD_CO2:
 	case IIO_MOD_VOC:
+	case IIO_MOD_PM1:
+	case IIO_MOD_PM2P5:
+	case IIO_MOD_PM4:
+	case IIO_MOD_PM10:
 		break;
 	default:
 		return false;
Signature · 1 line
2.19.2
Acked-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] iio: add IIO_MASSCONCENTRATION channel type

Quoted 9 lines · Tomasz Duszynski

Measuring particulate matter in ug / m3 (micro-grams per cubic meter) is de facto standard. Existing air quality sensors usually follow this convention and are capable of returning measurements using this unit.

IIO currently does not offer suitable channel type for this type of measurements hence this patch adds this.

Quoted 7 lines

In addition, extra modifiers are introduced used for distinguishing between fine pm1, pm2p5 and coarse pm4, pm10 particle measurements, i.e IIO_MOD_PM1, IIO_MOD_PM25 and IIO_MOD_PM4, IIO_MOD_PM10.

pmX consists of particles with aerodynamic diameter less or equal to X micrometers.

Quoted 125 lines
---
 Documentation/ABI/testing/sysfs-bus-iio | 17 ++++++++++++++++-
 drivers/iio/industrialio-core.c         |  5 +++++
 include/uapi/linux/iio/types.h          |  5 +++++
 tools/iio/iio_event_monitor.c           | 10 ++++++++++
 4 files changed, 36 insertions(+), 1 deletion(-)
Documentation/ABI/testing/sysfs-bus-iio +16 -1
index 8127a08e366d..ad9579a9385f 100644
@@ -1684,4 +1684,19 @@ KernelVersion:   4.18
 Contact:       [email protected]
 Description:
                Raw (unscaled) phase difference reading from channel Y
-               that can be processed to radians.
\ No newline at end of file
+               that can be processed to radians.
+
+What:          /sys/bus/iio/devices/iio:deviceX/in_massconcentration_pm1_input
+What:          /sys/bus/iio/devices/iio:deviceX/in_massconcentrationY_pm1_input
+What:          /sys/bus/iio/devices/iio:deviceX/in_massconcentration_pm2p5_input
+What:          /sys/bus/iio/devices/iio:deviceX/in_massconcentrationY_pm2p5_input
+What:          /sys/bus/iio/devices/iio:deviceX/in_massconcentration_pm4_input
+What:          /sys/bus/iio/devices/iio:deviceX/in_massconcentrationY_pm4_input
+What:          /sys/bus/iio/devices/iio:deviceX/in_massconcentration_pm10_input
+What:          /sys/bus/iio/devices/iio:deviceX/in_massconcentrationY_pm10_input
+KernelVersion: 4.21
+Contact:       [email protected]
+Description:
+               Mass concentration reading of particulate matter in ug / m3.
+               pmX consists of particles with aerodynamic diameter less or
+               equal to X micrometers.
drivers/iio/industrialio-core.c +5 -0
index 4f5cd9f60870..4700fd5d8c90 100644
@@ -87,6 +87,7 @@ static const char * const iio_chan_type_name_spec[] = {
        [IIO_GRAVITY]  = "gravity",
        [IIO_POSITIONRELATIVE]  = "positionrelative",
        [IIO_PHASE] = "phase",
+       [IIO_MASSCONCENTRATION] = "massconcentration",
 };
 
 static const char * const iio_modifier_names[] = {
@@ -127,6 +128,10 @@ static const char * const iio_modifier_names[] = {
        [IIO_MOD_Q] = "q",
        [IIO_MOD_CO2] = "co2",
        [IIO_MOD_VOC] = "voc",
+       [IIO_MOD_PM1] = "pm1",
+       [IIO_MOD_PM2P5] = "pm2p5",
+       [IIO_MOD_PM4] = "pm4",
+       [IIO_MOD_PM10] = "pm10",
 };
 
 /* relies on pairs of these shared then separate */
include/uapi/linux/iio/types.h +5 -0
index 92baabc103ac..c59adac24b1c 100644
@@ -46,6 +46,7 @@ enum iio_chan_type {
        IIO_GRAVITY,
        IIO_POSITIONRELATIVE,
        IIO_PHASE,
+       IIO_MASSCONCENTRATION,
 };
 
 enum iio_modifier {
@@ -87,6 +88,10 @@ enum iio_modifier {
        IIO_MOD_VOC,
        IIO_MOD_LIGHT_UV,
        IIO_MOD_LIGHT_DUV,
+       IIO_MOD_PM1,
+       IIO_MOD_PM2P5,
+       IIO_MOD_PM4,
+       IIO_MOD_PM10,
 };
 
 enum iio_event_type {
tools/iio/iio_event_monitor.c +10 -1
index ac2de6b7e89f..f6b8003fbe3c 100644
@@ -60,6 +60,7 @@ static const char * const iio_chan_type_name_spec[] = {
        [IIO_GRAVITY] = "gravity",
        [IIO_POSITIONRELATIVE] = "positionrelative",
        [IIO_PHASE] = "phase",
+       [IIO_MASSCONCENTRATION] = "massconcentration",
 };
 
 static const char * const iio_ev_type_text[] = {
@@ -115,6 +116,10 @@ static const char * const iio_modifier_names[] = {
        [IIO_MOD_Q] = "q",
        [IIO_MOD_CO2] = "co2",
        [IIO_MOD_VOC] = "voc",
+       [IIO_MOD_PM1] = "pm1",
+       [IIO_MOD_PM2P5] = "pm2p5",
+       [IIO_MOD_PM4] = "pm4",
+       [IIO_MOD_PM10] = "pm10",
 };
 
 static bool event_is_known(struct iio_event_data *event)
@@ -156,6 +161,7 @@ static bool event_is_known(struct iio_event_data *event)
        case IIO_GRAVITY:
        case IIO_POSITIONRELATIVE:
        case IIO_PHASE:
+       case IIO_MASSCONCENTRATION:
                break;
        default:
                return false;
@@ -200,6 +206,10 @@ static bool event_is_known(struct iio_event_data *event)
        case IIO_MOD_Q:
        case IIO_MOD_CO2:
        case IIO_MOD_VOC:
+       case IIO_MOD_PM1:
+       case IIO_MOD_PM2P5:
+       case IIO_MOD_PM4:
+       case IIO_MOD_PM10:
                break;
        default:
                return false;
--

2.19.2

author maintainer
#3 lore raw

PATCH v3 2/3 iio: chemical: add support for Sensirion SPS30 sensor

In reply to Tomasz Duszynski

Add support for Sensirion SPS30 particulate matter sensor.

---
 drivers/iio/chemical/Kconfig  |  11 +
 drivers/iio/chemical/Makefile |   1 +
 drivers/iio/chemical/sps30.c  | 406 ++++++++++++++++++++++++++++++++++
 3 files changed, 418 insertions(+)
 create mode 100644 drivers/iio/chemical/sps30.c
drivers/iio/chemical/Kconfig +11 -0
index b8e005be4f87..57832b4360e9 100644
@@ -61,6 +61,17 @@ config IAQCORE
 	  iAQ-Core Continuous/Pulsed VOC (Volatile Organic Compounds)
 	  sensors
 
+config SPS30
+	tristate "SPS30 particulate matter sensor"
+	depends on I2C
+	select CRC8
+	help
+	  Say Y here to build support for the Sensirion SPS30 particulate
+	  matter sensor.
+
+	  To compile this driver as a module, choose M here: the module will
+	  be called sps30.
+
 config VZ89X
 	tristate "SGX Sensortech MiCS VZ89X VOC sensor"
 	depends on I2C
drivers/iio/chemical/Makefile +1 -0
index 2f4c4ba4d781..9f42f4252151 100644
@@ -9,4 +9,5 @@ obj-$(CONFIG_BME680_I2C) += bme680_i2c.o
 obj-$(CONFIG_BME680_SPI) += bme680_spi.o
 obj-$(CONFIG_CCS811)		+= ccs811.o
 obj-$(CONFIG_IAQCORE)		+= ams-iaq-core.o
+obj-$(CONFIG_SPS30) += sps30.o
 obj-$(CONFIG_VZ89X)		+= vz89x.o
drivers/iio/chemical/sps30.c new file +406 -0

406 lines not on this page · raw message

Signature · 1 line
2.19.2
author maintainer
#4 lore raw

PATCH v3 3/3 iio: chemical: sps30: add device tree support

In reply to Tomasz Duszynski

Add device tree support for Sensirion SPS30 particulate matter sensor.

---
 .../bindings/iio/chemical/sensirion,sps30.txt        | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/chemical/sensirion,sps30.txt
Documentation/devicetree/bindings/iio/chemical/sensirion,sps30.txt new file +12 -0
new file mode 100644
index 000000000000..6eee2709b5b6
@@ -0,0 +1,12 @@
+* Sensirion SPS30 particulate matter sensor
+
+Required properties:
+- compatible: must be "sensirion,sps30"
+- reg: the I2C address of the sensor
+
+Example:
+
+sps30@69 {
+	compatible = "sensirion,sps30";
+	reg = <0x69>;
+};
Signature · 1 line
2.19.2