Add driver for ENS160 sensor
Subsystems (3)
Gustavo Silva
maintainerv3 cover Add driver for ENS160 sensor
This series of patches adds a driver for ScioSense ENS160 multi-gas sensor, designed for indoor air quality monitoring.
---
Changes in v3:
- Add missing $ref: /schemas/spi/spi-peripheral-props.yaml# in devicetree binding
- Move the devm_add_action_or_reset() call to right after setting the operation mode to standard
- Remove "_spi" and "_i2c" suffixes from device name
- Add a comment explaining what data the mutex is protecting
- Format register address macro
Link to v2: https://lore.kernel.org/linux-iio/[email protected]/
---
Gustavo Silva (6):
dt-bindings: vendor-prefixes: add ScioSense
dt-bindings: iio: chemical: add ENS160 sensor
iio: chemical: add driver for ENS160 sensor
iio: chemical: ens160: add triggered buffer support
iio: chemical: ens160: add power management support
MAINTAINERS: Add ScioSense ENS160
.../iio/chemical/sciosense,ens160.yaml | 70 ++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 8 + drivers/iio/chemical/Kconfig | 22 ++ drivers/iio/chemical/Makefile | 3 + drivers/iio/chemical/ens160.h | 10 + drivers/iio/chemical/ens160_core.c | 367 ++++++++++++++++++ drivers/iio/chemical/ens160_i2c.c | 62 +++ drivers/iio/chemical/ens160_spi.c | 61 +++ 9 files changed, 605 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/sciosense,ens160.yaml create mode 100644 drivers/iio/chemical/ens160.h create mode 100644 drivers/iio/chemical/ens160_core.c create mode 100644 drivers/iio/chemical/ens160_i2c.c create mode 100644 drivers/iio/chemical/ens160_spi.c
base-commit: 084eeee1d8da6b4712719264b01cb27b41307f54
Signature · 1 line
2.45.1
Gustavo Silva
maintainerPATCH v3 1/6 dt-bindings: vendor-prefixes: add ScioSense
Add vendor prefix for ScioSense B.V.
https://www.sciosense.com/
--- Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++ 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
@@ -1246,6 +1246,8 @@ patternProperties: description: Smart Battery System "^schindler,.*": description: Schindler + "^sciosense,.*": + description: ScioSense B.V. "^seagate,.*": description: Seagate Technology PLC "^seeed,.*":
Signature · 1 line
2.45.1
Gustavo Silva
maintainerPATCH v3 2/6 dt-bindings: iio: chemical: add ENS160 sensor
In reply to Gustavo SilvaAdd bindings for ScioSense ENS160 multi-gas sensor.
Datasheet: https://www.sciosense.com/wp-content/uploads/2023/12/ENS160-Datasheet.pdf
--- .../iio/chemical/sciosense,ens160.yaml | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/sciosense,ens160.yaml
Documentation/devicetree/bindings/iio/chemical/sciosense,ens160.yaml new file +70 -0
@@ -0,0 +1,70 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/chemical/sciosense,ens160.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: ScioSense ENS160 multi-gas sensor + +maintainers: + - Gustavo Silva <[email protected]> + +description: | + Digital Multi-Gas Sensor for Monitoring Indoor Air Quality. + + Datasheet: + https://www.sciosense.com/wp-content/uploads/2023/12/ENS160-Datasheet.pdf + +properties: + compatible: + enum: + - sciosense,ens160 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: true + vddio-supply: true + +required: + - compatible + - reg + +allOf: + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + gas-sensor@52 { + compatible = "sciosense,ens160"; + reg = <0x52>; + interrupt-parent = <&gpio0>; + interrupts = <19 IRQ_TYPE_EDGE_FALLING>; + }; + }; + - | + #include <dt-bindings/interrupt-controller/irq.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + gas-sensor@0 { + compatible = "sciosense,ens160"; + reg = <0>; + spi-max-frequency = <10000000>; + interrupt-parent = <&gpio>; + interrupts = <19 IRQ_TYPE_EDGE_FALLING>; + }; + }; + +...
Signature · 1 line
2.45.1
Gustavo Silva
maintainerPATCH v3 3/6 iio: chemical: add driver for ENS160 sensor
In reply to Gustavo SilvaScioSense ENS160 is a digital metal oxide multi-gas sensor, designed for indoor air quality monitoring. The driver supports readings of CO2 and VOC, and can be accessed via both SPI and I2C.
Datasheet: https://www.sciosense.com/wp-content/uploads/2023/12/ENS160-Datasheet.pdf
--- drivers/iio/chemical/Kconfig | 22 +++ drivers/iio/chemical/Makefile | 3 + drivers/iio/chemical/ens160.h | 7 + drivers/iio/chemical/ens160_core.c | 221 +++++++++++++++++++++++++++++ drivers/iio/chemical/ens160_i2c.c | 60 ++++++++ drivers/iio/chemical/ens160_spi.c | 60 ++++++++ 6 files changed, 373 insertions(+) create mode 100644 drivers/iio/chemical/ens160.h create mode 100644 drivers/iio/chemical/ens160_core.c create mode 100644 drivers/iio/chemical/ens160_i2c.c create mode 100644 drivers/iio/chemical/ens160_spi.c
drivers/iio/chemical/Kconfig +22 -0
@@ -76,6 +76,28 @@ config CCS811 Say Y here to build I2C interface support for the AMS CCS811 VOC (Volatile Organic Compounds) sensor +config ENS160 + tristate "ScioSense ENS160 sensor driver" + depends on (I2C || SPI) + select REGMAP + select ENS160_I2C if I2C + select ENS160_SPI if SPI + help + Say yes here to build support for ScioSense ENS160 multi-gas sensor. + + This driver can also be built as a module. If so, the module for I2C + would be called ens160_i2c and ens160_spi for SPI support. + +config ENS160_I2C + tristate + depends on I2C && ENS160 + select REGMAP_I2C + +config ENS160_SPI + tristate + depends on SPI && ENS160 + select REGMAP_SPI + config IAQCORE tristate "AMS iAQ-Core VOC sensors" depends on I2C
drivers/iio/chemical/Makefile +3 -0
@@ -11,6 +11,9 @@ obj-$(CONFIG_BME680) += bme680_core.o obj-$(CONFIG_BME680_I2C) += bme680_i2c.o obj-$(CONFIG_BME680_SPI) += bme680_spi.o obj-$(CONFIG_CCS811) += ccs811.o +obj-$(CONFIG_ENS160) += ens160_core.o +obj-$(CONFIG_ENS160_I2C) += ens160_i2c.o +obj-$(CONFIG_ENS160_SPI) += ens160_spi.o obj-$(CONFIG_IAQCORE) += ams-iaq-core.o obj-$(CONFIG_PMS7003) += pms7003.o obj-$(CONFIG_SCD30_CORE) += scd30_core.o
drivers/iio/chemical/ens160.h new file +7 -0
@@ -0,0 +1,7 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef ENS160_H_ +#define ENS160_H_ + +int devm_ens160_core_probe (struct device *dev,struct regmap *regmap, +const char *name); +#endif
drivers/iio/chemical/ens160_core.c new file +221 -0
221 lines not on this page · raw message
drivers/iio/chemical/ens160_i2c.c new file +60 -0
60 lines not on this page · raw message
drivers/iio/chemical/ens160_spi.c new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.45.1
Jonathan Cameron
maintainerRe: [PATCH v3 3/6] iio: chemical: add driver for ENS160 sensor
Quoted 6 lines · On Tue, 4 Jun 2024 19:57:27 -0300 Gustavo Silva <[email protected]> wrote:
ScioSense ENS160 is a digital metal oxide multi-gas sensor, designed for indoor air quality monitoring. The driver supports readings of CO2 and VOC, and can be accessed via both SPI and I2C.
Datasheet: https://www.sciosense.com/wp-content/uploads/2023/12/ENS160-Datasheet.pdf
No blank lines in tags block. Datahsheet is a semi official tag. I'll tidy up in this and previous patch if everything else fine.
Quoted 33 lines
Signed-off-by Gustavo Silva <[email protected]>--- drivers/iio/chemical/Kconfig | 22 +++ drivers/iio/chemical/Makefile | 3 + drivers/iio/chemical/ens160.h | 7 + drivers/iio/chemical/ens160_core.c | 221 +++++++++++++++++++++++++++++ drivers/iio/chemical/ens160_i2c.c | 60 ++++++++ drivers/iio/chemical/ens160_spi.c | 60 ++++++++ 6 files changed, 373 insertions(+) create mode 100644 drivers/iio/chemical/ens160.h create mode 100644 drivers/iio/chemical/ens160_core.c create mode 100644 drivers/iio/chemical/ens160_i2c.c create mode 100644 drivers/iio/chemical/ens160_spi.cdrivers/iio/chemical/Kconfig +11
-0@@ -76,6 +76,28 @@ config CCS811 Say Y here to build I2C interface support for the AMS CCS811 VOC (Volatile Organic Compounds) sensor +config ENS160 + tristate "ScioSense ENS160 sensor driver" + depends on (I2C || SPI) + select REGMAP + select ENS160_I2C if I2C + select ENS160_SPI if SPI + help + Say yes here to build support for ScioSense ENS160 multi-gas sensor. + + This driver can also be built as a module. If so, the module for I2C + would be called ens160_i2c and ens160_spi for SPI support.
drivers/iio/chemical/Kconfig config CCS811 · line 99
Quoted 10 lines
drivers/iio/chemical/Kconfig +10
-0+ +config ENS160_I2C + tristate + depends on I2C && ENS160 + select REGMAP_I2C + +config ENS160_SPI + tristate + depends on SPI && ENS160 + select REGMAP_SPI
As these two config symbols aren't exposed I think you don't need the depends lines.
See the BMA400 entry in drivers/iio/accel/Kconfig for example.
If everything else looks good I'll drop those two lines whilst applying.
Jonathan
Gustavo Silva
maintainerPATCH v3 4/6 iio: chemical: ens160: add triggered buffer support
In reply to Gustavo SilvaENS160 supports a data ready interrupt. Use it in combination with triggered buffer for continuous data readings.
--- drivers/iio/chemical/ens160.h | 2 +- drivers/iio/chemical/ens160_core.c | 141 +++++++++++++++++++++++++++-- drivers/iio/chemical/ens160_i2c.c | 3 +- drivers/iio/chemical/ens160_spi.c | 2 +- 4 files changed, 136 insertions(+), 12 deletions(-)
drivers/iio/chemical/ens160.h +1 -1
@@ -2,6 +2,6 @@#ifndef ENS160_H_ #define ENS160_H_ -int devm_ens160_core_probe (struct device *dev,struct regmap *regmap, +int devm_ens160_core_probe (struct device *dev,struct regmap *regmap,int irq,const char *name);#endif
drivers/iio/chemical/ens160_core.c +132 -9
194 lines not on this page · raw message
drivers/iio/chemical/ens160_i2c.c +2 -1
@@ -29,7 +29,8 @@ static int ens160_i2c_probe(struct i2c_client *client)return dev_err_probe (&client->dev,PTR_ERR (regmap),"Failed to register i2c regmap\n" ); -return devm_ens160_core_probe (&client->dev, regmap,"ens160" ); +return devm_ens160_core_probe (&client->dev, regmap, client->irq, +"ens160" ); }static const struct i2c_device_id ens160_i2c_id[] = {
drivers/iio/chemical/ens160_spi.c +1 -1
@@ -29,7 +29,7 @@ static int ens160_spi_probe(struct spi_device *spi)return dev_err_probe (&spi->dev,PTR_ERR (regmap),"Failed to register spi regmap\n" ); -return devm_ens160_core_probe (&spi->dev, regmap,"ens160" ); +return devm_ens160_core_probe (&spi->dev, regmap, spi->irq,"ens160" ); }static const struct of_device_id ens160_spi_of_match[] = {
Signature · 1 line
2.45.1
Gustavo Silva
maintainerPATCH v3 5/6 iio: chemical: ens160: add power management support
In reply to Gustavo SilvaENS160 supports a deep sleep mode for minimal power consumption. Use it to add PM sleep capability to the driver.
--- drivers/iio/chemical/ens160.h | 3 +++ drivers/iio/chemical/ens160_core.c | 23 +++++++++++++++++++++++ drivers/iio/chemical/ens160_i2c.c | 1 + drivers/iio/chemical/ens160_spi.c | 1 + 4 files changed, 28 insertions(+)
drivers/iio/chemical/ens160.h +3 -0
@@ -4,4 +4,7 @@int devm_ens160_core_probe (struct device *dev,struct regmap *regmap,int irq,const char *name); + +extern const struct dev_pm_ops ens160_pm_ops; +#endif
drivers/iio/chemical/ens160_core.c +23 -0
@@ -220,6 +220,29 @@ static const struct iio_info ens160_info = { .read_raw = ens160_read_raw, }; +static int ens160_suspend (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct ens160_data *data =iio_priv (indio_dev); + +return ens160_set_mode (data,ENS160_REG_MODE_DEEP_SLEEP ); +} + +static int ens160_resume (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct ens160_data *data =iio_priv (indio_dev); +int ret; + + ret =ens160_set_mode (data,ENS160_REG_MODE_IDLE ); +if (ret) +return ret; + +return ens160_set_mode (data,ENS160_REG_MODE_STANDARD ); +} +EXPORT_NS_SIMPLE_DEV_PM_OPS (ens160_pm_ops, ens160_suspend, ens160_resume, +IIO_ENS160 ); +static irqreturn_t ens160_trigger_handler (int irq,void *p) {struct iio_poll_func *pf = p;
drivers/iio/chemical/ens160_i2c.c +1 -0
@@ -49,6 +49,7 @@ static struct i2c_driver ens160_i2c_driver = { .driver = { .name = "ens160", .of_match_table = ens160_of_i2c_match, + .pm = pm_sleep_ptr(&ens160_pm_ops), }, .probe = ens160_i2c_probe, .id_table = ens160_i2c_id,
drivers/iio/chemical/ens160_spi.c +1 -0
@@ -48,6 +48,7 @@ static struct spi_driver ens160_spi_driver = { .driver = { .name = "ens160", .of_match_table = ens160_spi_of_match, + .pm = pm_sleep_ptr(&ens160_pm_ops), }, .probe = ens160_spi_probe, .id_table = ens160_spi_id,
Signature · 1 line
2.45.1
Gustavo Silva
maintainerPATCH v3 6/6 MAINTAINERS: Add ScioSense ENS160
In reply to Gustavo SilvaAdd myself as maintainer for ScioSense ENS160 multi-gas sensor driver.
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -19660,6 +19660,14 @@ F: include/linux/wait.h F: include/uapi/linux/sched.h F: kernel/sched/ +SCIOSENSE ENS160 MULTI-GAS SENSOR DRIVER +M: Gustavo Silva <[email protected]> +S: Maintained +F: drivers/iio/chemical/ens160_core.c +F: drivers/iio/chemical/ens160_i2c.c +F: drivers/iio/chemical/ens160_spi.c +F: drivers/iio/chemical/ens160.h + SCSI LIBSAS SUBSYSTEM R: John Garry <[email protected]> R: Jason Yan <[email protected]>
Signature · 1 line
2.45.1
Quoted 2 lines · On Tue, 4 Jun 2024 19:57:24 -0300 Gustavo Silva <[email protected]> wrote:
This series of patches adds a driver for ScioSense ENS160 multi-gas sensor, designed for indoor air quality monitoring.
Series applied with minor tweaks as called out for individual patches.
Applied to the togreg branch of iio.git and pushed out initially as testing for 0-day to see if it can find anything we missed.
Thanks,
Jonathan
Quoted 40 lines
---
Changes in v3:
- Add missing$ref: /schemas/spi/spi-peripheral-props.yaml#in devicetree binding
- Move thedevm_add_action_or_reset()call to right after setting the operation mode to standard
- Remove "_spi" and "_i2c" suffixes from device name
- Add a comment explaining what data the mutex is protecting
- Format register address macroLink to v2: https://lore.kernel.org/linux-iio/[email protected]/
---
Gustavo Silva (6):
dt-bindings: vendor-prefixes: add ScioSense
dt-bindings: iio: chemical: add ENS160 sensor
iio: chemical: add driver for ENS160 sensor
iio: chemical: ens160: add triggered buffer support
iio: chemical: ens160: add power management support
MAINTAINERS: Add ScioSense ENS160.../iio/chemical/sciosense,ens160.yaml | 70 ++++ .../devicetree/bindings/vendor-prefixes.yaml | 2 + MAINTAINERS | 8 + drivers/iio/chemical/Kconfig | 22 ++ drivers/iio/chemical/Makefile | 3 + drivers/iio/chemical/ens160.h | 10 + drivers/iio/chemical/ens160_core.c | 367 ++++++++++++++++++ drivers/iio/chemical/ens160_i2c.c | 62 +++ drivers/iio/chemical/ens160_spi.c | 61 +++ 9 files changed, 605 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/sciosense,ens160.yaml create mode 100644 drivers/iio/chemical/ens160.h create mode 100644 drivers/iio/chemical/ens160_core.c create mode 100644 drivers/iio/chemical/ens160_i2c.c create mode 100644 drivers/iio/chemical/ens160_spi.cbase-commit:
084eeee1d8da6b4712719264b01cb27b41307f54
Gustavo Silva
maintainerQuoted 9 lines · Jonathan Cameron
Series applied with minor tweaks as called out for individual patches.
Applied to the togreg branch of iio.git and pushed out initially as testing for 0-day to see if it can find anything we missed.
Thanks,
Jonathan
Thank you!