Add support for SCD30 sensor
v3 cover Add support for SCD30 sensor
Following series adds support for Sensirion SCD30 sensor module capable of measuring carbon dioxide, temperature and relative humidity. CO2 measurements base on NDIR principle while temperature and relative humidity are measured by the on board SHT31. As for sensor communication, both I2C and serial interfaces are supported.
v3:
* simplify code by scaling temperature & humidity in _read_meas()
* update realbits in scan types
* s/adjecent/adjacent
* drop IIO_CHAN_INFO_RAW from _write_raw_get_fmt because there's no raw output channel
* rework locking in _read_raw
* fix endianess problem on BE machine
* align timestamp properly before pushing to buffers
* explain why interrupt gets disabled after registration
* add trigger validation
* drop SCALE for temperature and humidity channel as they are processed
* register action which stops measuring after starting measurements
* spit generic calibration attr into two doing specific things
* add comment explaining why priv in struct scd30_state is for
* rename node in binding example to co2-sensor
v2:
* move asm/byteorder.h towards the bottom of include list
* make channel address names in enum more specific
* add postfixes to defines and extra comments
* drop unneeded i2c include from scd30 header
* break generic command sending function into specialized options
* expose automatic calibration and forced calibration via the same attr
* use SAMP_FREQ to set frequency instead of meas_interval attr
* use CALISCALE to set pressure compensation instead of pressure_comp attr
* use CALIBBIAS to set temperature offset instead of temp_offset attr
* fix order in MAINTAINERS
* drop attribute allowing one to reset sensor
* as we have dt probing drop board file based probing (i2c_device_id)
* merge patches touching related files
* use fwnode API to retrieve interrupt from dt
* fix interrupt-parent spelling
* change binding license
* drop supply from required property
Tomasz Duszynski (4):
iio: chemical: scd30: add core driver
iio: chemical: scd30: add I2C interface driver
iio: chemical: scd30: add serial interface driver
dt-bindings: iio: scd30: add device binding file
Documentation/ABI/testing/sysfs-bus-iio-scd30 | 34 + .../iio/chemical/sensirion,scd30.yaml | 68 ++ MAINTAINERS | 9 + drivers/iio/chemical/Kconfig | 33 + drivers/iio/chemical/Makefile | 3 + drivers/iio/chemical/scd30.h | 80 ++ drivers/iio/chemical/scd30_core.c | 783 ++++++++++++++++++ drivers/iio/chemical/scd30_i2c.c | 134 +++ drivers/iio/chemical/scd30_serial.c | 266 ++++++ 9 files changed, 1410 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-scd30 create mode 100644 Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml create mode 100644 drivers/iio/chemical/scd30.h create mode 100644 drivers/iio/chemical/scd30_core.c create mode 100644 drivers/iio/chemical/scd30_i2c.c create mode 100644 drivers/iio/chemical/scd30_serial.c
--
2.26.2
PATCH v3 1/4 iio: chemical: scd30: add core driver
Add Sensirion SCD30 carbon dioxide core driver.
--- Documentation/ABI/testing/sysfs-bus-iio-scd30 | 34 + MAINTAINERS | 6 + drivers/iio/chemical/Kconfig | 11 + drivers/iio/chemical/Makefile | 1 + drivers/iio/chemical/scd30.h | 80 ++ drivers/iio/chemical/scd30_core.c | 783 ++++++++++++++++++ 6 files changed, 915 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-scd30 create mode 100644 drivers/iio/chemical/scd30.h create mode 100644 drivers/iio/chemical/scd30_core.c
Documentation/ABI/testing/sysfs-bus-iio-scd30 new file +34 -0
@@ -0,0 +1,34 @@ +What: /sys/bus/iio/devices/iio:deviceX/calibration_auto_enable +Date: June 2020 +KernelVersion: 5.8 +Contact: [email protected] +Description: + Contaminants build-up in the measurement chamber or optical + elements deterioration leads to sensor drift. + + One can compensate for sensor drift by using automatic self + calibration procedure (asc). + + Writing 1 or 0 to this attribute will respectively activate or + deactivate asc. + + Upon reading current asc status is returned. + +What: /sys/bus/iio/devices/iio:deviceX/calibration_forced_value +Date: June 2020 +KernelVersion: 5.8 +Contact: [email protected] +Description: + Contaminants build-up in the measurement chamber or optical + elements deterioration leads to sensor drift. + + One can compensate for sensor drift by using forced + recalibration (frc). This is useful in case there's known + co2 reference available nearby the sensor. + + Picking value from the range [400 1 2000] and writing it to the + sensor will set frc. + + Upon reading current frc value is returned. Note that after + power cycling default value (i.e 400) is returned even though + internally sensor had recalibrated itself.
MAINTAINERS +6 -0
@@ -15137,6 +15137,12 @@ S: Maintained F: drivers/misc/phantom.c F: include/uapi/linux/phantom.h +SENSIRION SCD30 CARBON DIOXIDE SENSOR DRIVER +M: Tomasz Duszynski <[email protected]> +S: Maintained +F: drivers/iio/chemical/scd30.h +F: drivers/iio/chemical/scd30_core.c + SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER M: Tomasz Duszynski <[email protected]> S: Maintained
drivers/iio/chemical/Kconfig +11 -0
@@ -85,6 +85,17 @@ config PMS7003 To compile this driver as a module, choose M here: the module will be called pms7003. +config SCD30_CORE + tristate "SCD30 carbon dioxide sensor driver" + select IIO_BUFFER + select IIO_TRIGGERED_BUFFER + help + Say Y here to build support for the Sensirion SCD30 sensor with carbon + dioxide, relative humidity and temperature sensing capabilities. + + To compile this driver as a module, choose M here: the module will + be called scd30_core. + config SENSIRION_SGP30 tristate "Sensirion SGPxx gas sensors" depends on I2C
drivers/iio/chemical/Makefile +1 -0
@@ -12,6 +12,7 @@ obj-$(CONFIG_BME680_SPI) += bme680_spi.o obj-$(CONFIG_CCS811) += ccs811.o obj-$(CONFIG_IAQCORE) += ams-iaq-core.o obj-$(CONFIG_PMS7003) += pms7003.o +obj-$(CONFIG_SCD30_CORE) += scd30_core.o obj-$(CONFIG_SENSIRION_SGP30) += sgp30.o obj-$(CONFIG_SPS30) += sps30.o obj-$(CONFIG_VZ89X) += vz89x.o
drivers/iio/chemical/scd30.h new file +80 -0
80 lines not on this page · raw message
drivers/iio/chemical/scd30_core.c new file +783 -0
783 lines not on this page · raw message
Signature · 1 line
2.26.2
PATCH v3 2/4 iio: chemical: scd30: add I2C interface driver
In reply to Tomasz DuszynskiAdd I2C interface driver for the SCD30 sensor.
--- MAINTAINERS | 1 + drivers/iio/chemical/Kconfig | 11 +++ drivers/iio/chemical/Makefile | 1 + drivers/iio/chemical/scd30_i2c.c | 134 +++++++++++++++++++++++++++++++ 4 files changed, 147 insertions(+) create mode 100644 drivers/iio/chemical/scd30_i2c.c
MAINTAINERS +1 -0
@@ -15142,6 +15142,7 @@ M: Tomasz Duszynski <[email protected]> S: Maintained F: drivers/iio/chemical/scd30.h F: drivers/iio/chemical/scd30_core.c +F: drivers/iio/chemical/scd30_i2c.c SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER M: Tomasz Duszynski <[email protected]>
drivers/iio/chemical/Kconfig +11 -0
@@ -96,6 +96,17 @@ config SCD30_CORE To compile this driver as a module, choose M here: the module will be called scd30_core. +config SCD30_I2C + tristate "SCD30 carbon dioxide sensor I2C driver" + depends on SCD30_CORE && I2C + select CRC8 + help + Say Y here to build support for the Sensirion SCD30 I2C interface + driver. + + To compile this driver as a module, choose M here: the module will + be called scd30_i2c. + config SENSIRION_SGP30 tristate "Sensirion SGPxx gas sensors" depends on I2C
drivers/iio/chemical/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_CCS811) += ccs811.o obj-$(CONFIG_IAQCORE) += ams-iaq-core.o obj-$(CONFIG_PMS7003) += pms7003.o obj-$(CONFIG_SCD30_CORE) += scd30_core.o +obj-$(CONFIG_SCD30_I2C) += scd30_i2c.o obj-$(CONFIG_SENSIRION_SGP30) += sgp30.o obj-$(CONFIG_SPS30) += sps30.o obj-$(CONFIG_VZ89X) += vz89x.o
drivers/iio/chemical/scd30_i2c.c new file +134 -0
134 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v3 2/4] iio: chemical: scd30: add I2C interface driver
Quoted 2 lines · Tomasz Duszynski
Add I2C interface driver for the SCD30 sensor.
...
drivers/iio/chemical/scd30_i2c.c line 33
Quoted 11 lines
drivers/iio/chemical/scd30_i2c.c new file +11
-0+static u16 scd30_i2c_cmd_lookup_tbl[] = { + [CMD_START_MEAS ] =0x0010 , + [CMD_STOP_MEAS ] =0x0104 , + [CMD_MEAS_INTERVAL ] =0x4600 , + [CMD_MEAS_READY ] =0x0202 , + [CMD_READ_MEAS ] =0x0300 , + [CMD_ASC ] =0x5306 , + [CMD_FRC ] =0x5204 , + [CMD_TEMP_OFFSET ] =0x5403 , + [CMD_FW_VERSION ] =0xd100 , + [CMD_RESET ] =0xd304 ,
Keep sorted by value?
Quoted 1 line
+};
...
drivers/iio/chemical/scd30_i2c.c line 50
Quoted 4 lines
drivers/iio/chemical/scd30_i2c.c new file +3
-0+ ret =i2c_master_send (client, txbuf, txsize); +if (ret != txsize) +return ret <0 ? ret : -EIO ;
Wouldn't be better
if (ret < 0)
return ret;
if (ret != txsize)
return -EIO;?
drivers/iio/chemical/scd30_i2c.c line 57
Quoted 7 lines
drivers/iio/chemical/scd30_i2c.c new file +6
-0+if (!rxbuf) +return 0 ; + + ret =i2c_master_recv (client, rxbuf, rxsize); +if (ret != rxsize) +return ret <0 ? ret : -EIO ;
Ditto.
...
drivers/iio/chemical/scd30_i2c.c line 66
Quoted 5 lines
drivers/iio/chemical/scd30_i2c.c new file +5
-0+static int scd30_i2c_command (struct scd30_state *state,enum scd30_cmd cmd, +u16 arg,void *response,int size) +{ +char crc, buf[SCD30_I2C_MAX_BUF_SIZE ], *rsp = response; +int i, ret;
i -> offset ?
drivers/iio/chemical/scd30_i2c.c line 79
Quoted 13 lines
drivers/iio/chemical/scd30_i2c.c new file +12
-0+put_unaligned_be16 (scd30_i2c_cmd_lookup_tbl[cmd], buf); + i =2 ; + +if (rsp) { +/* each two bytes are followed by a crc8 */ + size += size /2 ; + }else { +put_unaligned_be16 (arg, buf + i); + crc =crc8 (scd30_i2c_crc8_tbl, buf + i,2 ,CRC8_INIT_VALUE ); + i +=2 ; + buf[i] = crc; + i +=1 ;
buf[offset++] = crc; ?
Quoted 9 lines
drivers/iio/chemical/scd30_i2c.c new file +9
-0+/* commands below don't take an argument */ +if ((cmd ==CMD_STOP_MEAS ) || (cmd ==CMD_RESET )) + i -=3 ; + } + + ret =scd30_i2c_xfer (state, buf, i, buf, size); +if (ret) +return ret; +
drivers/iio/chemical/scd30_i2c.c line 98
Quoted 10 lines
drivers/iio/chemical/scd30_i2c.c new file +9
-0+/* validate received data and strip off crc bytes */ +for (i =0 ; i < size; i +=3 ) { + crc =crc8 (scd30_i2c_crc8_tbl, buf + i,2 ,CRC8_INIT_VALUE ); +if (crc != buf[i +2 ]) { +dev_err (state->dev,"data integrity check failed\n" ); +return -EIO ; + } + + *rsp++ = buf[i];
+ 0 (for the sake of consistency?
Quoted 5 lines
drivers/iio/chemical/scd30_i2c.c new file +5
-0+ *rsp++ = buf[i +1 ]; + } + +return 0 ; +}
...
drivers/iio/chemical/scd30_i2c.c line 124
Quoted 4 lines
drivers/iio/chemical/scd30_i2c.c new file +3
-0+static struct i2c_driver scd30_i2c_driver = { + .driver = { + .name =KBUILD_MODNAME ,
Better to hard code.
Quoted 5 lines
drivers/iio/chemical/scd30_i2c.c new file +5
-0+ .of_match_table = scd30_i2c_of_match, + .pm = &scd30_pm_ops, + }, + .probe_new = scd30_i2c_probe, +};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 2/4] iio: chemical: scd30: add I2C interface driver
Hello Andy,
Quoted 19 lines · Andy Shevchenko
Quoted 2 lines · Tomasz Duszynski
Add I2C interface driver for the SCD30 sensor.
...
drivers/iio/chemical/scd30_i2c.c line 33
Quoted 11 lines
drivers/iio/chemical/scd30_i2c.c new file +11
-0+static u16 scd30_i2c_cmd_lookup_tbl[] = { + [CMD_START_MEAS ] =0x0010 , + [CMD_STOP_MEAS ] =0x0104 , + [CMD_MEAS_INTERVAL ] =0x4600 , + [CMD_MEAS_READY ] =0x0202 , + [CMD_READ_MEAS ] =0x0300 , + [CMD_ASC ] =0x5306 , + [CMD_FRC ] =0x5204 , + [CMD_TEMP_OFFSET ] =0x5403 , + [CMD_FW_VERSION ] =0xd100 , + [CMD_RESET ] =0xd304 ,
Quoted 2 lines
Keep sorted by value?
I'd rather leave it as is simply because order here matches order in sensor datasheet.
Quoted 9 lines
Quoted 1 line
+};
...
drivers/iio/chemical/scd30_i2c.c line 50
Quoted 4 lines
drivers/iio/chemical/scd30_i2c.c new file +3
-0+ ret =i2c_master_send (client, txbuf, txsize); +if (ret != txsize) +return ret <0 ? ret : -EIO ;
Quoted 9 lines
Wouldn't be better
if (ret < 0)
return ret; if (ret != txsize) return -EIO;?
Hmm, okay. Perhaps slightly easier to read.
Quoted 12 lines
drivers/iio/chemical/scd30_i2c.c line 57
Quoted 7 lines
drivers/iio/chemical/scd30_i2c.c new file +6
-0+if (!rxbuf) +return 0 ; + + ret =i2c_master_recv (client, rxbuf, rxsize); +if (ret != rxsize) +return ret <0 ? ret : -EIO ;Ditto.
...
Quoted 8 lines
drivers/iio/chemical/scd30_i2c.c line 66
Quoted 5 lines
drivers/iio/chemical/scd30_i2c.c new file +5
-0+static int scd30_i2c_command (struct scd30_state *state,enum scd30_cmd cmd, +u16 arg,void *response,int size) +{ +char crc, buf[SCD30_I2C_MAX_BUF_SIZE ], *rsp = response; +int i, ret;i -> offset ?
'i' is shorter and I am lazy :).
Quoted 11 lines
Quoted 10 lines
drivers/iio/chemical/scd30_i2c.c new file +10
-0+put_unaligned_be16 (scd30_i2c_cmd_lookup_tbl[cmd], buf); + i =2 ; + +if (rsp) { +/* each two bytes are followed by a crc8 */ + size += size /2 ; + }else { +put_unaligned_be16 (arg, buf + i); + crc =crc8 (scd30_i2c_crc8_tbl, buf + i,2 ,CRC8_INIT_VALUE ); + i +=2 ;
Quoted 5 lines
drivers/iio/chemical/scd30_i2c.c line 79
Quoted 2 lines
drivers/iio/chemical/scd30_i2c.c new file +2
-0+ buf[i] = crc; + i +=1 ;buf[offset++] = crc; ?
I'd rather stick to what I have now. It looks more consistent.
Quoted 18 lines
Quoted 17 lines
drivers/iio/chemical/scd30_i2c.c new file +17
-0+/* commands below don't take an argument */ +if ((cmd ==CMD_STOP_MEAS ) || (cmd ==CMD_RESET )) + i -=3 ; + } + + ret =scd30_i2c_xfer (state, buf, i, buf, size); +if (ret) +return ret; + +/* validate received data and strip off crc bytes */ +for (i =0 ; i < size; i +=3 ) { + crc =crc8 (scd30_i2c_crc8_tbl, buf + i,2 ,CRC8_INIT_VALUE ); +if (crc != buf[i +2 ]) { +dev_err (state->dev,"data integrity check failed\n" ); +return -EIO ; + } +
Quoted 4 lines
Quoted 1 line
+ *rsp++ = buf[i];
+ 0 (for the sake of consistency?
Adding 0 is a little bit odd.
Quoted 8 lines
Quoted 5 lines
drivers/iio/chemical/scd30_i2c.c new file +5
-0+ *rsp++ = buf[i +1 ]; + } + +return 0 ; +}...
Quoted 7 lines
drivers/iio/chemical/scd30_i2c.c line 124
Quoted 4 lines
drivers/iio/chemical/scd30_i2c.c new file +3
-0+static struct i2c_driver scd30_i2c_driver = { + .driver = { + .name =KBUILD_MODNAME ,Better to hard code.
I seriously doubt anyone will ever want to change module name. What for?
Quoted 9 lines
drivers/iio/chemical/scd30_i2c.c line 129
Quoted 5 lines
drivers/iio/chemical/scd30_i2c.c new file +5
-0+ .of_match_table = scd30_i2c_of_match, + .pm = &scd30_pm_ops, + }, + .probe_new = scd30_i2c_probe, +};--
With Best Regards,
Andy Shevchenko
PATCH v3 3/4 iio: chemical: scd30: add serial interface driver
In reply to Tomasz DuszynskiAdd serial interface driver for the SCD30 sensor.
--- MAINTAINERS | 1 + drivers/iio/chemical/Kconfig | 11 ++ drivers/iio/chemical/Makefile | 1 + drivers/iio/chemical/scd30_serial.c | 266 ++++++++++++++++++++++++++++ 4 files changed, 279 insertions(+) create mode 100644 drivers/iio/chemical/scd30_serial.c
MAINTAINERS +1 -0
@@ -15143,6 +15143,7 @@ S: Maintained F: drivers/iio/chemical/scd30.h F: drivers/iio/chemical/scd30_core.c F: drivers/iio/chemical/scd30_i2c.c +F: drivers/iio/chemical/scd30_serial.c SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER M: Tomasz Duszynski <[email protected]>
drivers/iio/chemical/Kconfig +11 -0
@@ -107,6 +107,17 @@ config SCD30_I2C To compile this driver as a module, choose M here: the module will be called scd30_i2c. +config SCD30_SERIAL + tristate "SCD30 carbon dioxide sensor serial driver" + depends on SCD30_CORE && SERIAL_DEV_BUS + select CRC16 + help + Say Y here to build support for the Sensirion SCD30 serial interface + driver. + + To compile this driver as a module, choose M here: the module will + be called scd30_serial. + config SENSIRION_SGP30 tristate "Sensirion SGPxx gas sensors" depends on I2C
drivers/iio/chemical/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_IAQCORE) += ams-iaq-core.o obj-$(CONFIG_PMS7003) += pms7003.o obj-$(CONFIG_SCD30_CORE) += scd30_core.o obj-$(CONFIG_SCD30_I2C) += scd30_i2c.o +obj-$(CONFIG_SCD30_SERIAL) += scd30_serial.o obj-$(CONFIG_SENSIRION_SGP30) += sgp30.o obj-$(CONFIG_SPS30) += sps30.o obj-$(CONFIG_VZ89X) += vz89x.o
drivers/iio/chemical/scd30_serial.c new file +266 -0
266 lines not on this page · raw message
Signature · 1 line
2.26.2
Re: [PATCH v3 3/4] iio: chemical: scd30: add serial interface driver
Quoted 2 lines · Tomasz Duszynski
Add serial interface driver for the SCD30 sensor.
...
drivers/iio/chemical/scd30_serial.c line 47
Quoted 11 lines
drivers/iio/chemical/scd30_serial.c new file +11
-0+static u16 scd30_serdev_cmd_lookup_tbl[] = { + [CMD_START_MEAS ] =0x0036 , + [CMD_STOP_MEAS ] =0x0037 , + [CMD_MEAS_INTERVAL ] =0x0025 , + [CMD_MEAS_READY ] =0x0027 , + [CMD_READ_MEAS ] =0x0028 , + [CMD_ASC ] =0x003a , + [CMD_FRC ] =0x0039 , + [CMD_TEMP_OFFSET ] =0x003b , + [CMD_FW_VERSION ] =0x0020 , + [CMD_RESET ] =0x0034 ,
Hmm... Can't we keep them ordered by value?
Quoted 1 line
+};
...
drivers/iio/chemical/scd30_serial.c line 77
Quoted 8 lines
drivers/iio/chemical/scd30_serial.c new file +8
-0+ ret =wait_for_completion_interruptible_timeout (&priv->meas_ready, +SCD30_SERDEV_TIMEOUT ); +if (ret >0 ) + ret =0 ; +else if (!ret) + ret = -ETIMEDOUT ; + +return ret;
Perhaps
if (ret < 0)
return ret;
if (ret == 0)
return -ETIMEDOUT;return 0;
?
...
drivers/iio/chemical/scd30_serial.c line 108
Quoted 2 lines
drivers/iio/chemical/scd30_serial.c new file +2
-0+char txbuf[SCD30_SERDEV_MAX_BUF_SIZE ] = {SCD30_SERDEV_ADDR }, + rxbuf[SCD30_SERDEV_MAX_BUF_SIZE ], *rsp = response;
Please, apply type to each variable separately.
...
drivers/iio/chemical/scd30_serial.c line 147
Quoted 4 lines
drivers/iio/chemical/scd30_serial.c new file +3
-0+switch (txbuf[1 ]) { +case SCD30_SERDEV_WRITE : +if (memcmp (txbuf, txbuf, txsize)) {
I'm not sure I understand this.
drivers/iio/chemical/scd30_serial.c line 155
Quoted 9 lines
drivers/iio/chemical/scd30_serial.c new file +8
-0+dev_err (state->dev,"wrong message received\n" ); +return -EIO ; + } +break ; +case SCD30_SERDEV_READ : +if (rxbuf[2 ] != (rxsize - +SCD30_SERDEV_RX_HEADER_SIZE - +SCD30_SERDEV_CRC_SIZE )) {
Perhaps you can come up with better indentation/ line split?
Quoted 22 lines
drivers/iio/chemical/scd30_serial.c new file +22
-0+dev_err (state->dev, +"received data size does not match header\n" ); +return -EIO ; + } + + rxsize -=SCD30_SERDEV_CRC_SIZE ; + crc =get_unaligned_le16 (rxbuf + rxsize); +if (crc !=scd30_serdev_calc_crc (rxbuf, rxsize)) { +dev_err (state->dev,"data integrity check failed\n" ); +return -EIO ; + } + + rxsize -=SCD30_SERDEV_RX_HEADER_SIZE ; +memcpy (rsp, rxbuf +SCD30_SERDEV_RX_HEADER_SIZE , rxsize); +break ; +default : +dev_err (state->dev,"received unknown op code\n" ); +return -EIO ; + } + +return 0 ; +}
...
drivers/iio/chemical/scd30_serial.c line 256
Quoted 4 lines
drivers/iio/chemical/scd30_serial.c new file +3
-0+static struct serdev_device_driver scd30_serdev_driver = { + .driver = { + .name =KBUILD_MODNAME ,
This is not the best what we can do. The name is an ABI and better if it will be constant (independent on file name).
Quoted 5 lines
drivers/iio/chemical/scd30_serial.c new file +5
-0+ .of_match_table = scd30_serdev_of_match, + .pm = &scd30_pm_ops, + }, + .probe = scd30_serdev_probe, +};
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v3 3/4] iio: chemical: scd30: add serial interface driver
Quoted 36 lines · Andy Shevchenko
Quoted 2 lines · Tomasz Duszynski
Add serial interface driver for the SCD30 sensor.
...
drivers/iio/chemical/scd30_serial.c line 47
Quoted 11 lines
drivers/iio/chemical/scd30_serial.c new file +11
-0+static u16 scd30_serdev_cmd_lookup_tbl[] = { + [CMD_START_MEAS ] =0x0036 , + [CMD_STOP_MEAS ] =0x0037 , + [CMD_MEAS_INTERVAL ] =0x0025 , + [CMD_MEAS_READY ] =0x0027 , + [CMD_READ_MEAS ] =0x0028 , + [CMD_ASC ] =0x003a , + [CMD_FRC ] =0x0039 , + [CMD_TEMP_OFFSET ] =0x003b , + [CMD_FW_VERSION ] =0x0020 , + [CMD_RESET ] =0x0034 ,Hmm... Can't we keep them ordered by value?
Quoted 1 line
+};
...
drivers/iio/chemical/scd30_serial.c line 77
Quoted 8 lines
drivers/iio/chemical/scd30_serial.c new file +8
-0+ ret =wait_for_completion_interruptible_timeout (&priv->meas_ready, +SCD30_SERDEV_TIMEOUT ); +if (ret >0 ) + ret =0 ; +else if (!ret) + ret = -ETIMEDOUT ; + +return ret;Perhaps
Quoted 7 lines
if (ret < 0)
return ret; if (ret == 0) return -ETIMEDOUT;return 0;
?
Matter of style but since I will be doing other changes I can touch that too.
Quoted 8 lines
...
drivers/iio/chemical/scd30_serial.c line 108
Quoted 2 lines
drivers/iio/chemical/scd30_serial.c new file +2
-0+char txbuf[SCD30_SERDEV_MAX_BUF_SIZE ] = {SCD30_SERDEV_ADDR }, + rxbuf[SCD30_SERDEV_MAX_BUF_SIZE ], *rsp = response;Please, apply type to each variable separately.
Fine.
Quoted 9 lines
...
drivers/iio/chemical/scd30_serial.c line 147
Quoted 4 lines
drivers/iio/chemical/scd30_serial.c new file +3
-0+switch (txbuf[1 ]) { +case SCD30_SERDEV_WRITE : +if (memcmp (txbuf, txbuf, txsize)) {I'm not sure I understand this.
Ah, thanks for catching this. tx should be compared to rx.
Quoted 6 lines
Quoted 5 lines
drivers/iio/chemical/scd30_serial.c new file +5
-0+dev_err (state->dev,"wrong message received\n" ); +return -EIO ; + } +break ; +case SCD30_SERDEV_READ :
Quoted 6 lines
drivers/iio/chemical/scd30_serial.c line 155
Quoted 3 lines
drivers/iio/chemical/scd30_serial.c new file +3
-0+if (rxbuf[2 ] != (rxsize - +SCD30_SERDEV_RX_HEADER_SIZE - +SCD30_SERDEV_CRC_SIZE )) {Perhaps you can come up with better indentation/ line split?
I'd rather leave it as is.
Quoted 42 lines
Quoted 22 lines
drivers/iio/chemical/scd30_serial.c new file +22
-0+dev_err (state->dev, +"received data size does not match header\n" ); +return -EIO ; + } + + rxsize -=SCD30_SERDEV_CRC_SIZE ; + crc =get_unaligned_le16 (rxbuf + rxsize); +if (crc !=scd30_serdev_calc_crc (rxbuf, rxsize)) { +dev_err (state->dev,"data integrity check failed\n" ); +return -EIO ; + } + + rxsize -=SCD30_SERDEV_RX_HEADER_SIZE ; +memcpy (rsp, rxbuf +SCD30_SERDEV_RX_HEADER_SIZE , rxsize); +break ; +default : +dev_err (state->dev,"received unknown op code\n" ); +return -EIO ; + } + +return 0 ; +}...
drivers/iio/chemical/scd30_serial.c line 256
Quoted 4 lines
drivers/iio/chemical/scd30_serial.c new file +3
-0+static struct serdev_device_driver scd30_serdev_driver = { + .driver = { + .name =KBUILD_MODNAME ,This is not the best what we can do. The name is an ABI and better if it will be constant (independent on file name).
drivers/iio/chemical/scd30_serial.c line 261
Quoted 5 lines
drivers/iio/chemical/scd30_serial.c new file +5
-0+ .of_match_table = scd30_serdev_of_match, + .pm = &scd30_pm_ops, + }, + .probe = scd30_serdev_probe, +};--
With Best Regards,
Andy Shevchenko
Re: [PATCH v3 3/4] iio: chemical: scd30: add serial interface driver
Quoted 77 lines · Tomasz Duszynski
Quoted 36 lines · Andy Shevchenko
Quoted 2 lines · Tomasz Duszynski
Add serial interface driver for the SCD30 sensor.
...
drivers/iio/chemical/scd30_serial.c line 47
Quoted 11 lines
drivers/iio/chemical/scd30_serial.c new file +11
-0+static u16 scd30_serdev_cmd_lookup_tbl[] = { + [CMD_START_MEAS ] =0x0036 , + [CMD_STOP_MEAS ] =0x0037 , + [CMD_MEAS_INTERVAL ] =0x0025 , + [CMD_MEAS_READY ] =0x0027 , + [CMD_READ_MEAS ] =0x0028 , + [CMD_ASC ] =0x003a , + [CMD_FRC ] =0x0039 , + [CMD_TEMP_OFFSET ] =0x003b , + [CMD_FW_VERSION ] =0x0020 , + [CMD_RESET ] =0x0034 ,Hmm... Can't we keep them ordered by value?
Quoted 1 line
+};
...
drivers/iio/chemical/scd30_serial.c line 77
Quoted 8 lines
drivers/iio/chemical/scd30_serial.c new file +8
-0+ ret =wait_for_completion_interruptible_timeout (&priv->meas_ready, +SCD30_SERDEV_TIMEOUT ); +if (ret >0 ) + ret =0 ; +else if (!ret) + ret = -ETIMEDOUT ; + +return ret;Perhaps
Quoted 7 lines
if (ret < 0)
return ret; if (ret == 0) return -ETIMEDOUT;return 0;
?
Matter of style but since I will be doing other changes I can touch that too.
Quoted 8 lines
...
drivers/iio/chemical/scd30_serial.c line 108
Quoted 2 lines
drivers/iio/chemical/scd30_serial.c new file +2
-0+char txbuf[SCD30_SERDEV_MAX_BUF_SIZE ] = {SCD30_SERDEV_ADDR }, + rxbuf[SCD30_SERDEV_MAX_BUF_SIZE ], *rsp = response;Please, apply type to each variable separately.
Fine.
Quoted 9 lines
...
drivers/iio/chemical/scd30_serial.c line 147
Quoted 4 lines
drivers/iio/chemical/scd30_serial.c new file +3
-0+switch (txbuf[1 ]) { +case SCD30_SERDEV_WRITE : +if (memcmp (txbuf, txbuf, txsize)) {I'm not sure I understand this.
Ah, thanks for catching this. tx should be compared to rx.
Quoted 6 lines
Quoted 5 lines
drivers/iio/chemical/scd30_serial.c new file +5
-0+dev_err (state->dev,"wrong message received\n" ); +return -EIO ; + } +break ; +case SCD30_SERDEV_READ :
Quoted 9 lines
Quoted 6 lines
drivers/iio/chemical/scd30_serial.c line 155
Quoted 3 lines
drivers/iio/chemical/scd30_serial.c new file +3
-0+if (rxbuf[2 ] != (rxsize - +SCD30_SERDEV_RX_HEADER_SIZE - +SCD30_SERDEV_CRC_SIZE )) {Perhaps you can come up with better indentation/ line split?
I'd rather leave it as is.
On the second thought, that would fit 100 column line.
Quoted 42 lines
Quoted 42 lines
Quoted 22 lines
drivers/iio/chemical/scd30_serial.c new file +22
-0+dev_err (state->dev, +"received data size does not match header\n" ); +return -EIO ; + } + + rxsize -=SCD30_SERDEV_CRC_SIZE ; + crc =get_unaligned_le16 (rxbuf + rxsize); +if (crc !=scd30_serdev_calc_crc (rxbuf, rxsize)) { +dev_err (state->dev,"data integrity check failed\n" ); +return -EIO ; + } + + rxsize -=SCD30_SERDEV_RX_HEADER_SIZE ; +memcpy (rsp, rxbuf +SCD30_SERDEV_RX_HEADER_SIZE , rxsize); +break ; +default : +dev_err (state->dev,"received unknown op code\n" ); +return -EIO ; + } + +return 0 ; +}...
drivers/iio/chemical/scd30_serial.c line 256
Quoted 4 lines
drivers/iio/chemical/scd30_serial.c new file +3
-0+static struct serdev_device_driver scd30_serdev_driver = { + .driver = { + .name =KBUILD_MODNAME ,This is not the best what we can do. The name is an ABI and better if it will be constant (independent on file name).
drivers/iio/chemical/scd30_serial.c line 261
Quoted 5 lines
drivers/iio/chemical/scd30_serial.c new file +5
-0+ .of_match_table = scd30_serdev_of_match, + .pm = &scd30_pm_ops, + }, + .probe = scd30_serdev_probe, +};--
With Best Regards,
Andy Shevchenko
PATCH v3 4/4 dt-bindings: iio: scd30: add device binding file
In reply to Tomasz DuszynskiAdd SCD30 sensor binding file.
--- .../iio/chemical/sensirion,scd30.yaml | 68 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 69 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml
Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml new file +68 -0
@@ -0,0 +1,68 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/chemical/sensirion,scd30.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sensirion SCD30 carbon dioxide sensor + +maintainers: + - Tomasz Duszynski <[email protected]> + +description: | + Air quality sensor capable of measuring co2 concentration, temperature + and relative humidity. + +properties: + compatible: + enum: + - sensirion,scd30 + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + vdd-supply: true + + sensirion,sel-gpios: + description: GPIO connected to the SEL line + maxItems: 1 + + sensirion,pwm-gpios: + description: GPIO connected to the PWM line + maxItems: 1 + +required: + - compatible + +additionalProperties: false + +examples: + - | + # include <dt-bindings/interrupt-controller/irq.h> + i2c { + #address-cells = <1>; + #size-cells = <0>; + + co2-sensor@61 { + compatible = "sensirion,scd30"; + reg = <0x61>; + vdd-supply = <&vdd>; + interrupt-parent = <&gpio0>; + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + }; + }; + - | + # include <dt-bindings/interrupt-controller/irq.h> + serial { + co2-sensor { + compatible = "sensirion,scd30"; + vdd-supply = <&vdd>; + interrupt-parent = <&gpio0>; + interrupts = <0 IRQ_TYPE_LEVEL_HIGH>; + }; + }; + +...
MAINTAINERS +1 -0
@@ -15140,6 +15140,7 @@ F: include/uapi/linux/phantom.h SENSIRION SCD30 CARBON DIOXIDE SENSOR DRIVER M: Tomasz Duszynski <[email protected]> S: Maintained +F: Documentation/devicetree/bindings/iio/chemical/sensirion,scd30.yaml F: drivers/iio/chemical/scd30.h F: drivers/iio/chemical/scd30_core.c F: drivers/iio/chemical/scd30_i2c.c
Signature · 1 line
2.26.2
Quoted 6 lines · Tomasz Duszynski
Following series adds support for Sensirion SCD30 sensor module capable of measuring carbon dioxide, temperature and relative humidity. CO2 measurements base on NDIR principle while temperature and relative humidity are measured by the on board SHT31. As for sensor communication, both I2C and serial interfaces are supported.
Btw, since we have relaxed 80 limit to 100, I recommend to reconsider some lines to be joined.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 12 lines · Andy Shevchenko
Quoted 6 lines · Tomasz Duszynski
Following series adds support for Sensirion SCD30 sensor module capable of measuring carbon dioxide, temperature and relative humidity. CO2 measurements base on NDIR principle while temperature and relative humidity are measured by the on board SHT31. As for sensor communication, both I2C and serial interfaces are supported.
Btw, since we have relaxed 80 limit to 100, I recommend to reconsider some lines to be joined.
Heh, that particular change is becoming more viral that corona itself these days.
Quoted 3 lines
--
With Best Regards,
Andy Shevchenko