Add Sensirion STS30 temperature sensor driver
Subsystems (2)
cover Add Sensirion STS30 temperature sensor driver
Hi all,
This patch adds support for the Sensirion STS30 family of temperature sensor drivers. It currently supports single-shot non-clock stretched readings as well as the entirety of the STS30 family.
I'm sending this as an RFC patch as I unfortunately do not have the hardware right now. I have compile-tested it successfully and have done a tad bit of testing on QEMU, with it properly registering with no errors reported in dmesg. Unfortunately due to the way I had compiled the kernel used to test the driver it did not expose the I2C bus to userspace properly and I was not able to retrieve values from the driver, but I can continue more testing over the next few days and am happy to answer any questions anyone may have. Additionally, regarding dmesg logs, I neglected to save them while in my testing, but as stated previously, I can continue more testing over the next couple of days.
Maxwell Doose (3):
dt-bindings: iio: temperature: Add STS30 devicetree bindings
iio: temperature: Add STS30 temperature sensor driver
MAINTAINERS: Add entry for Sensirion STS30 driver
.../iio/temperature/sensirion,sts30.yaml | 49 +++ MAINTAINERS | 6 + drivers/iio/temperature/Kconfig | 11 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/sts30.c | 321 ++++++++++++++++++ 5 files changed, 388 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml create mode 100644 drivers/iio/temperature/sts30.c
Signature · 1 line
2.54.0
RFC PATCH 1/3 dt-bindings: iio: temperature: Add STS30 devicetree bindings
Add the devicetree bindings for the STS30 family of temperature sensors. The STS30 family of sensors includes the STS30, STS31, and STS35.
All devices in the STS30 family share the same commands, timings, etc. The only difference between them is their measurement accuracy and tolerance.
--- .../iio/temperature/sensirion,sts30.yaml | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml
Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml new file +49 -0
@@ -0,0 +1,49 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/temperature/sensirion,sts30.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: STS30, STS31, and STS35 temperature iio sensors + +maintainers: + - Maxwell Doose <[email protected]> + +description: | + Family of digital temperature sensors from Sensirion with I2C interface. + All devices are compatible with each other, their only differences are + their levels of accuracy. + + Datasheet available at: + https://sensirion.com/media/documents/1DA31AFD/65D613A8/Datasheet_STS3x_DIS.pdf + +properties: + compatible: + enum: + - sensirion,sts30 + - sensirion,sts31 + - sensirion,sts35 + + reg: + maxItems: 1 + + vdd-supply: true + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + temperature@4a { + compatible = "sensirion,sts30"; + reg = <0x4a>; + vdd-supply = <®_3v3>; + }; + };
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [RFC PATCH 1/3] dt-bindings: iio: temperature: Add STS30 devicetree bindings
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The STS30 device tree binding omits the `interrupts` property, preventing users from modeling…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The STS30 device tree binding omits the interrupts property, preventing users from modeling the hardware's ALERT pin. --
commit 91523cd6a186b322c33e0fb78f1316cdc24a39af
Author: Maxwell Doose <[email protected]>
dt-bindings: iio: temperature: Add STS30 devicetree bindings
This commit adds device tree bindings for the Sensirion STS30 family of digital temperature sensors, which includes the STS30, STS31, and STS35.
Quoted 5 lines
Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml new file +0
-0
[ ... ]
Quoted 7 lines
Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml new file +7
-0+properties: + compatible: + enum: + - sensirion,sts30 + - sensirion,sts31 + - sensirion,sts35 +
Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml line 36
Quoted 10 lines
Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml new file +10
-0+ reg: + maxItems: 1 + + vdd-supply: true + +required: + - compatible + - reg + +additionalProperties: false
[Severity: Medium]
Does this schema prevent modeling the hardware's ALERT pin?
The Sensirion STS3x family hardware features an ALERT pin that can be wired to an interrupt controller to signal high and low temperature thresholds. Because this schema enforces additionalProperties: false but omits the interrupts property from the properties block, any device tree that accurately models the physical hardware connection will fail dt_binding_check.
Should the interrupts property be explicitly listed to allow accurately describing the hardware capabilities, even if the current IIO driver does not yet utilize the ALERT pin?
Quoted 2 lines
Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml new file +2
-0+ +examples:
[ ... ]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
RFC PATCH 2/3 iio: temperature: Add STS30 temperature sensor driver
In reply to Maxwell DooseAdd a driver for the Sensirion STS30 family of temperature sensor drivers over I2C. The STS30 family of sensors includes the STS30, STS31, and STS35, all of which are supported by this driver, since they all share the same commands, etc. and only differ in accuracy and tolerance.
The driver currently supports single-shot non-clock stretched readings, by using a specified delay based on the repeatability/delay specified by the user. The repeatability/delay can be changed at any time through sysfs.
Additionally add Kconfig and Makefile entries for the driver.
--- drivers/iio/temperature/Kconfig | 11 ++ drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/sts30.c | 321 +++++++++++++++++++++++++++++++ 3 files changed, 333 insertions(+) create mode 100644 drivers/iio/temperature/sts30.c
drivers/iio/temperature/Kconfig +11 -0
@@ -88,6 +88,17 @@ config MLX90635 This driver can also be built as a module. If so, the module will be called mlx90635. +config STS30 + tristate "STS30/STS31/STS35 temperature sensor" + depends on I2C + select CRC8 + help + If you say yes here you get support for the Sensirion STS30, + STS31, and STS35 temperature sensors over I2C. + + This driver can also be built as a module. If so, the module will + be called sts30. + config TMP006 tristate "TMP006 infrared thermopile sensor" depends on I2C
drivers/iio/temperature/Makefile +1 -0
@@ -14,6 +14,7 @@ obj-$(CONFIG_MCP9600) += mcp9600.o obj-$(CONFIG_MLX90614) += mlx90614.o obj-$(CONFIG_MLX90632) += mlx90632.o obj-$(CONFIG_MLX90632) += mlx90635.o +obj-$(CONFIG_STS30) += sts30.o obj-$(CONFIG_TMP006) += tmp006.o obj-$(CONFIG_TMP007) += tmp007.o obj-$(CONFIG_TMP117) += tmp117.o
drivers/iio/temperature/sts30.c new file +321 -0
321 lines not on this page · raw message
Signature · 1 line
2.54.0
[email protected]
AI reviewRe: [RFC PATCH 2/3] iio: temperature: Add STS30 temperature sensor driver
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The return value of `sts30_reset()` is ignored during probe, allowing phantom device registration…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The return value of sts30_reset() is ignored during probe, allowing phantom device registration on failure.
- [High] The driver implements a Clock Stretching Disabled I2C sequence but uses Clock Stretching Enabled command codes, resulting in a protocol mismatch. --
commit 1a183c37bbba5fe87dfcc6019f964e51526fec2b
Author: Maxwell Doose <[email protected]>
iio: temperature: Add STS30 temperature sensor driver
Add a driver for the Sensirion STS30 family of temperature sensor drivers over I2C. The driver supports single-shot non-clock stretched readings using a specified delay based on the repeatability/delay.
Quoted 5 lines
drivers/iio/temperature/sts30.c new file +0
-0
[ ... ]
drivers/iio/temperature/sts30.c line 33
Quoted 5 lines
drivers/iio/temperature/sts30.c new file +5
-0+#define STS30_MEAS_SIZE 3 + +#define STS30_COMMAND_READ_HIGH_REPEAT 0x2C06 +#define STS30_COMMAND_READ_MED_REPEAT 0x2C0D +#define STS30_COMMAND_READ_LOW_REPEAT 0x2C10
[Severity: High]
The commit message mentions using non-clock stretched readings, but are these the correct commands? According to the STS3x datasheet, the 0x2Cxx series commands are for "Clock Stretching Enabled", which require a Repeated START condition between the write and read phases.
[ ... ]
Quoted 5 lines
drivers/iio/temperature/sts30.c new file +5
-0+static int sts30_read (struct sts30_data *data,u16 command,u16 *val) +{ +u8 tmp[2 ]; +u8 buf[STS30_MEAS_SIZE ]; +int ret;
drivers/iio/temperature/sts30.c line 100
Quoted 10 lines
drivers/iio/temperature/sts30.c new file +10
-0+ +put_unaligned_be16 (command, tmp); + + ret =i2c_master_send (data->client, tmp,sizeof (tmp)); +if (ret <0 ) +return ret; +if (ret !=sizeof (tmp)) +return -EIO ; + +fsleep (data->delay);
[Severity: High]
Will sending a STOP condition here abort the measurement? Since i2c_master_send() issues a STOP condition rather than a Repeated START, this sequence violates the protocol for the Clock Stretching Enabled commands (0x2Cxx) defined above.
Should this use the "Clock Stretching Disabled" commands (e.g., 0x2400) instead, or alternatively use a single i2c_transfer() with a Repeated START?
[ ... ]
Quoted 5 lines
drivers/iio/temperature/sts30.c new file +5
-0+static int sts30_probe (struct i2c_client *client) +{ +struct iio_dev *indio_dev; +struct sts30_data *data; +int ret;
[ ... ]
drivers/iio/temperature/sts30.c line 286
Quoted 4 lines
drivers/iio/temperature/sts30.c new file +4
-0+ ret =sts30_reset (data); + +return devm_iio_device_register (&client->dev, indio_dev); +}
[Severity: High]
Is it intentional to ignore the return value of sts30_reset() here?
If the reset fails due to the hardware being missing or a broken I2C bus, this will unconditionally register a phantom device to userspace. Should we check 'ret' and return the error code instead?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [RFC PATCH 2/3] iio: temperature: Add STS30 temperature sensor driver
In reply to Maxwell DooseHi Max,
comments inline, some nits, some more serious, some Sashiko reviews.
Josh
drivers/iio/temperature/sts30.c line 9
Quoted 9 lines · On Fri, 19 Jun 2026 23:40:06 -0500 Maxwell Doose <[email protected]> wrote:
drivers/iio/temperature/sts30.c new file +9
-0+// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2026 Maxwell Doose +* +* Sensirion STS30 temperature sensor driver +* +* Datasheet: https://sensirion.com/media/documents/1DA31AFD/65D613A8/Datasheet_STS3x_DIS.pdf +* +* Author: Maxwell Doose <[email protected]>
Nit, but this is probably unnecessary since you already have the copyright statement above.
Quoted 2 lines
+ */
+
You're missing array_size.h, as used in probe.
drivers/iio/temperature/sts30.c line 20
Quoted 9 lines
drivers/iio/temperature/sts30.c new file +9
-0+#include <linux/bits.h> +#include <linux/cleanup.h> +#include <linux/crc8.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/errno.h> +#include <linux/export.h> +#include <linux/iio/iio.h> +#include <linux/iio/types.h>
Move the IIO specific headers below the generic linux headers and group them separately.
drivers/iio/temperature/sts30.c line 22
Quoted 2 lines
drivers/iio/temperature/sts30.c new file +2
-0+#include <linux/i2c.h> +#include <linux/kernel.h>
Don't use kernel.h for new entries, you should include what you actually use instead of relying on this. (there is a tool that can help with this, it's called iwyu-tool).
drivers/iio/temperature/sts30.c line 35
Quoted 13 lines
drivers/iio/temperature/sts30.c new file +13
-0+#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/types.h> +#include <linux/unaligned.h> + +/* Amount of bytes received from the STS30 after a read command */ +#define STS30_MEAS_SIZE 3 + +#define STS30_COMMAND_READ_HIGH_REPEAT 0x2C06 +#define STS30_COMMAND_READ_MED_REPEAT 0x2C0D +#define STS30_COMMAND_READ_LOW_REPEAT 0x2C10 + +/* Soft reset command */
No point in having a comment if your macro is sensibly named.
Quoted 14 lines
drivers/iio/temperature/sts30.c new file +14
-0+#define STS30_COMMAND_RESET 0x30A2 + +/* +* sts30 includes a CRC8 checksum at the end of its i2c responses. The polynomial +* is used to generate the CRC8 table and the seed is the starting value. +*/ +#define STS30_CRC8_POLYNOMIAL 0x31 +#define STS30_CRC8_SEED 0xFF + +DECLARE_CRC8_TABLE (sts30_crc_table); + +enum sts30_read_delays { +STS30_REPEAT_LOW =4500 , +STS30_REPEAT_MED =6000 ,
drivers/iio/temperature/sts30.c line 59
Quoted 10 lines
drivers/iio/temperature/sts30.c new file +10
-0+ STS30_REPEAT_HIGH = 15000 +}; + +/** +* struct sts30_data - data structure for STS30 driver +* +* @client: underlying i2c client data structure +* @lock: mutex for serialized communication on the i2c bus +* @delay: measurement duration for the current repeatability mode +*/
I'd remove this comment altogether and just add a comment on why you need a mutex.
Quoted 7 lines
drivers/iio/temperature/sts30.c new file +7
-0+struct sts30_data { +struct i2c_client *client; +struct mutex lock; +/* +* sts30 has three potential repeatability/measurement durations. We need to +* account for them while reading the i2c bus. +*
drivers/iio/temperature/sts30.c line 76
Quoted 10 lines
drivers/iio/temperature/sts30.c new file +10
-0+* See section 2.2 in the datasheet for more info on processing times. +*/ +enum sts30_read_delays delay; +}; + +static int sts30_verify_crc8 (struct sts30_data *data,u8 buf[STS30_MEAS_SIZE ]) +{ +int crc; + + crc =crc8 (sts30_crc_table, buf,2 ,STS30_CRC8_SEED );
Please use sizeof() instead of hard coding the buffer length.
drivers/iio/temperature/sts30.c line 89
Quoted 13 lines
drivers/iio/temperature/sts30.c new file +13
-0+if (crc != buf[2 ]) { +dev_err (&data->client->dev,"Expected CRC8 value of 0x%02x, got 0x%02x\n" , + buf[2 ], crc); +return -EIO ; + } + +return 0 ; +} + +static int sts30_read (struct sts30_data *data,u16 command,u16 *val) +{ +u8 tmp[2 ]; +u8 buf[STS30_MEAS_SIZE ];
Reverse christmas tree order.
drivers/iio/temperature/sts30.c line 100
Quoted 11 lines
drivers/iio/temperature/sts30.c new file +11
-0+int ret; + +put_unaligned_be16 (command, tmp); + + ret =i2c_master_send (data->client, tmp,sizeof (tmp)); +if (ret <0 ) +return ret; +if (ret !=sizeof (tmp)) +return -EIO ; + +fsleep (data->delay);
Adding Sashiko's comment:
Will sending a STOP condition here abort the measurement? Since i2c_master_send() issues a STOP condition rather than a Repeated START, this sequence violates the protocol for the Clock Stretching Enabled commands (0x2Cxx) defined above.
Should this use the "Clock Stretching Disabled" commands (e.g., 0x2400) instead, or alternatively use a single i2c_transfer() with a Repeated START?
Quoted 15 lines
drivers/iio/temperature/sts30.c new file +15
-0+ + ret =i2c_master_recv (data->client, buf,sizeof (buf)); +if (ret <0 ) +return ret; +if (ret !=sizeof (buf)) +return -EIO ; + + *val =get_unaligned_be16 (buf); + + ret =sts30_verify_crc8 (data, buf); +if (ret) +return ret; + +return 0 ; +}
...
drivers/iio/temperature/sts30.c line 143
Quoted 11 lines
drivers/iio/temperature/sts30.c new file +11
-0+static int sts30_reset (struct sts30_data *data) +{ +int ret; + +guard (mutex)(&data->lock); + + ret =sts30_write (data,STS30_COMMAND_RESET ); +if (ret) +return ret; + +fsleep (1500 );
Add a comment or change this to a macro to explain why 1500 specifically.
Quoted 19 lines
drivers/iio/temperature/sts30.c new file +19
-0+ +return 0 ; +} + +static int sts30_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val,int *val2, +long mask) +{ +struct sts30_data *data =iio_priv (indio_dev); +int ret; +u16 tmp; + +guard (mutex)(&data->lock); + +switch (mask) { +case IIO_CHAN_INFO_RAW : +switch (data->delay) { +case STS30_REPEAT_LOW : + ret =sts30_read (data,STS30_COMMAND_READ_LOW_REPEAT , &tmp);
drivers/iio/temperature/sts30.c line 172
Quoted 10 lines
drivers/iio/temperature/sts30.c new file +10
-0+break ; +case STS30_REPEAT_MED : + ret =sts30_read (data,STS30_COMMAND_READ_MED_REPEAT , &tmp); +break ; +case STS30_REPEAT_HIGH : + ret =sts30_read (data,STS30_COMMAND_READ_HIGH_REPEAT , &tmp); +break ; +default : +dev_warn (&data->client->dev,"Repeatability state corrupted, got: %d\n" , + data->delay);
Do we need this warning? Returning -EINVAL is sufficient enough.
Quoted 5 lines
drivers/iio/temperature/sts30.c new file +5
-0+return -EINVAL ; + } + +if (ret) +return ret;
drivers/iio/temperature/sts30.c line 187
Quoted 10 lines
drivers/iio/temperature/sts30.c new file +10
-0+ + *val = tmp; +return IIO_VAL_INT ; +case IIO_CHAN_INFO_OFFSET : +/* +* We use this constant -16852 as calculated using the formula +* in the datasheet. See section 4.12 in the data sheet for more +* info. +*/ + *val =-16852 ;
Okay, this would definitely be better if it were a macro. I'd even be tempted to add the formula in a comment for safe keeping.
...
drivers/iio/temperature/sts30.c line 255
Quoted 7 lines
drivers/iio/temperature/sts30.c new file +7
-0+static const struct i2c_device_id sts30_id[] = { + {"sts30" }, + {"sts31" }, + {"sts35" }, + { } +}; +MODULE_DEVICE_TABLE (i2c, sts30_id);
Move the struct i2c_device_id struct after probe(). Additionally, use the .name named initializer when defining the IDs (this reflects on Uwe Kleine-Konig's effort in IIO).
Quoted 18 lines
drivers/iio/temperature/sts30.c new file +18
-0+ +static int sts30_probe (struct i2c_client *client) +{ +struct iio_dev *indio_dev; +struct sts30_data *data; +int ret; + + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); +if (!indio_dev) +return -ENOMEM ; + + indio_dev->name = client->name; + indio_dev->info = &sts30_info; + indio_dev->channels = sts30_channels; + indio_dev->num_channels =ARRAY_SIZE (sts30_channels); + indio_dev->modes =INDIO_DIRECT_MODE ; + + data =iio_priv (indio_dev);
drivers/iio/temperature/sts30.c line 283
Quoted 10 lines
drivers/iio/temperature/sts30.c new file +10
-0+ data->client = client; + data->delay =STS30_REPEAT_HIGH ; + + ret =devm_mutex_init (&client->dev, &data->lock); +if (ret) +return ret; + +i2c_set_clientdata (client, indio_dev); + + ret =sts30_reset (data);
You're not checking ret here.
Quoted 4 lines
drivers/iio/temperature/sts30.c new file +4
-0+ +return devm_iio_device_register (&client->dev, indio_dev); +} +
Signature · 3 lines
Kind regards CJD
Re: [RFC PATCH 2/3] iio: temperature: Add STS30 temperature sensor driver
Hi Joshua,
Sorry about the bugs, this is my first driver submission.
Quoted 9 lines · Joshua Crofts
Hi Max,
comments inline, some nits, some more serious, some Sashiko reviews.
Josh
On Fri, 19 Jun 2026 23:40:06 -0500
Maxwell Doose <[email protected]> wrote:
Quoted 13 lines
drivers/iio/temperature/sts30.c line 9
Quoted 9 lines
drivers/iio/temperature/sts30.c new file +9
-0+// SPDX-License-Identifier: GPL-2.0-only +/* +* Copyright (c) 2026 Maxwell Doose +* +* Sensirion STS30 temperature sensor driver +* +* Datasheet: https://sensirion.com/media/documents/1DA31AFD/65D613A8/Datasheet_STS3x_DIS.pdf +* +* Author: Maxwell Doose <[email protected]> Nit, but this is probably unnecessary since you already have the copyright statement above.
Fair, will remove.
Quoted 5 lines
Quoted 2 lines
+ */
+You're missing
array_size.h, as used in probe.
Nice catch, I didn't see that in my final compilation.
Quoted 4 lines
Quoted 4 lines
drivers/iio/temperature/sts30.c new file +4
-0+#include <linux/bits.h> +#include <linux/cleanup.h> +#include <linux/crc8.h> +#include <linux/delay.h>
Quoted 9 lines
drivers/iio/temperature/sts30.c line 20
Quoted 5 lines
drivers/iio/temperature/sts30.c new file +5
-0+#include <linux/device.h> +#include <linux/errno.h> +#include <linux/export.h> +#include <linux/iio/iio.h> +#include <linux/iio/types.h> Move the IIO specific headers below the generic linux headers and group them separately.
Will do.
Quoted 4 lines
drivers/iio/temperature/sts30.c line 22
Quoted 2 lines
drivers/iio/temperature/sts30.c new file +2
-0+#include <linux/i2c.h> +#include <linux/kernel.h> Don't use
kernel.hfor new entries, you should include what
Righty oh, will remove. I guess that's why it compiled fine on my end because it's a catch-all.
Quoted 3 lines
you actually use instead of relying on this. (there is a tool that can help with this, it's called
iwyu-tool).
I've heard of iwyu-tool, I just don't know how to configure it :(
Quoted 7 lines
Quoted 7 lines
drivers/iio/temperature/sts30.c new file +7
-0+#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/types.h> +#include <linux/unaligned.h> + +/* Amount of bytes received from the STS30 after a read command */ +#define STS30_MEAS_SIZE 3
Quoted 9 lines
drivers/iio/temperature/sts30.c line 35
Quoted 6 lines
drivers/iio/temperature/sts30.c new file +6
-0+ +#define STS30_COMMAND_READ_HIGH_REPEAT 0x2C06 +#define STS30_COMMAND_READ_MED_REPEAT 0x2C0D +#define STS30_COMMAND_READ_LOW_REPEAT 0x2C10 + +/* Soft reset command */ No point in having a comment if your macro is sensibly named.
Fair point, I'll see about renaming it and removing the comment in v2.
Quoted 19 lines
Quoted 19 lines
drivers/iio/temperature/sts30.c new file +19
-0+#define STS30_COMMAND_RESET 0x30A2 + +/* +* sts30 includes a CRC8 checksum at the end of its i2c responses. The polynomial +* is used to generate the CRC8 table and the seed is the starting value. +*/ +#define STS30_CRC8_POLYNOMIAL 0x31 +#define STS30_CRC8_SEED 0xFF + +DECLARE_CRC8_TABLE (sts30_crc_table); + +enum sts30_read_delays { +STS30_REPEAT_LOW =4500 , +STS30_REPEAT_MED =6000 , +STS30_REPEAT_HIGH =15000 +}; + +/** +* struct sts30_data - data structure for STS30 driver
Quoted 9 lines
Quoted 5 lines
+ *
+ * @client: underlying i2c client data structure
+ * @lock: mutex for serialized communication on the i2c bus
+ * @delay: measurement duration for the current repeatability mode
+ */I'd remove this comment altogether and just add a comment on why you need a mutex.
Alright then.
Quoted 11 lines
Quoted 11 lines
drivers/iio/temperature/sts30.c new file +11
-0+struct sts30_data { +struct i2c_client *client; +struct mutex lock; +/* +* sts30 has three potential repeatability/measurement durations. We need to +* account for them while reading the i2c bus. +* +* See section 2.2 in the datasheet for more info on processing times. +*/ +enum sts30_read_delays delay; +};
Quoted 9 lines
drivers/iio/temperature/sts30.c line 76
Quoted 6 lines
drivers/iio/temperature/sts30.c new file +6
-0+ +static int sts30_verify_crc8 (struct sts30_data *data,u8 buf[STS30_MEAS_SIZE ]) +{ +int crc; + + crc =crc8 (sts30_crc_table, buf,2 ,STS30_CRC8_SEED );Please use
sizeof()instead of hard coding the buffer length.
I suppose that we can do sizeof(buf) - 1 since we know the last byte in the buffer has to be the checksum.
Quoted 7 lines
Quoted 7 lines
drivers/iio/temperature/sts30.c new file +7
-0+if (crc != buf[2 ]) { +dev_err (&data->client->dev,"Expected CRC8 value of 0x%02x, got 0x%02x\n" , + buf[2 ], crc); +return -EIO ; + } + +return 0 ;
Quoted 9 lines
drivers/iio/temperature/sts30.c line 89
Quoted 6 lines
drivers/iio/temperature/sts30.c new file +6
-0+} + +static int sts30_read (struct sts30_data *data,u16 command,u16 *val) +{ +u8 tmp[2 ]; +u8 buf[STS30_MEAS_SIZE ];Reverse christmas tree order.
Sounds good.
Quoted 14 lines
drivers/iio/temperature/sts30.c line 100
Quoted 11 lines
drivers/iio/temperature/sts30.c new file +11
-0+int ret; + +put_unaligned_be16 (command, tmp); + + ret =i2c_master_send (data->client, tmp,sizeof (tmp)); +if (ret <0 ) +return ret; +if (ret !=sizeof (tmp)) +return -EIO ; + +fsleep (data->delay);Adding Sashiko's comment:
Quoted 7 lines
Will sending a STOP condition here abort the measurement? Since
i2c_master_send()issues a STOP condition rather than a Repeated START, this sequence violates the protocol for the Clock Stretching Enabled commands (0x2Cxx) defined above.
Should this use the "Clock Stretching Disabled" commands (e.g.,0x2400) instead, or alternatively use a singlei2c_transfer()with a Repeated START?
Yea, I accidentally mixed up the commands, I saw this on sashiko when I submitted it last night. It seems like a five minute fix in any case though.
Quoted 18 lines
Quoted 15 lines
drivers/iio/temperature/sts30.c new file +15
-0+ + ret =i2c_master_recv (data->client, buf,sizeof (buf)); +if (ret <0 ) +return ret; +if (ret !=sizeof (buf)) +return -EIO ; + + *val =get_unaligned_be16 (buf); + + ret =sts30_verify_crc8 (data, buf); +if (ret) +return ret; + +return 0 ; +}...
Quoted 15 lines
drivers/iio/temperature/sts30.c line 143
Quoted 11 lines
drivers/iio/temperature/sts30.c new file +11
-0+static int sts30_reset (struct sts30_data *data) +{ +int ret; + +guard (mutex)(&data->lock); + + ret =sts30_write (data,STS30_COMMAND_RESET ); +if (ret) +return ret; + +fsleep (1500 );Add a comment or change this to a macro to explain why 1500 specifically.
Alright. Can also explain here:
Datasheet dictates that maximum soft reset time is 1.5ms or 1500us. We fsleep() here to ensure that the device is ready before we continue.
Quoted 24 lines
Quoted 24 lines
drivers/iio/temperature/sts30.c new file +24
-0+ +return 0 ; +} + +static int sts30_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val,int *val2, +long mask) +{ +struct sts30_data *data =iio_priv (indio_dev); +int ret; +u16 tmp; + +guard (mutex)(&data->lock); + +switch (mask) { +case IIO_CHAN_INFO_RAW : +switch (data->delay) { +case STS30_REPEAT_LOW : + ret =sts30_read (data,STS30_COMMAND_READ_LOW_REPEAT , &tmp); +break ; +case STS30_REPEAT_MED : + ret =sts30_read (data,STS30_COMMAND_READ_MED_REPEAT , &tmp); +break ; +case STS30_REPEAT_HIGH :
Quoted 9 lines
drivers/iio/temperature/sts30.c line 172
Quoted 5 lines
drivers/iio/temperature/sts30.c new file +5
-0+ ret =sts30_read (data,STS30_COMMAND_READ_HIGH_REPEAT , &tmp); +break ; +default : +dev_warn (&data->client->dev,"Repeatability state corrupted, got: %d\n" , + data->delay);Do we need this warning? Returning
-EINVALis sufficient enough.
Since this is read_raw() the warning might help the user resolve the error rather than just getting "Invalid argument".
Quoted 10 lines
Quoted 10 lines
drivers/iio/temperature/sts30.c new file +10
-0+return -EINVAL ; + } + +if (ret) +return ret; + + *val = tmp; +return IIO_VAL_INT ; +case IIO_CHAN_INFO_OFFSET : +/*
Quoted 9 lines
drivers/iio/temperature/sts30.c line 187
Quoted 5 lines
drivers/iio/temperature/sts30.c new file +5
-0+* We use this constant -16852 as calculated using the formula +* in the datasheet. See section 4.12 in the data sheet for more +* info. +*/ + *val =-16852 ;Okay, this would definitely be better if it were a macro. I'd even be tempted to add the formula in a comment for safe keeping.
At this point I agree, it's probably a good idea to put our constants at the top of the file as macros and put the formula there :/
Quoted 14 lines
...
drivers/iio/temperature/sts30.c line 255
Quoted 7 lines
drivers/iio/temperature/sts30.c new file +7
-0+static const struct i2c_device_id sts30_id[] = { + {"sts30" }, + {"sts31" }, + {"sts35" }, + { } +}; +MODULE_DEVICE_TABLE (i2c, sts30_id);Move the struct
i2c_device_idstruct afterprobe(). Additionally, use the.namenamed initializer when defining the IDs (this reflects on Uwe Kleine-Konig's effort in IIO).
Right. When I was first writing up the driver I'd ended up using i2c_match_id() but after removing it I'd forgotten to put it back at the bottom. Will fix (alongside the named initializers).
Quoted 22 lines
Quoted 22 lines
drivers/iio/temperature/sts30.c new file +22
-0+ +static int sts30_probe (struct i2c_client *client) +{ +struct iio_dev *indio_dev; +struct sts30_data *data; +int ret; + + indio_dev =devm_iio_device_alloc (&client->dev,sizeof (*data)); +if (!indio_dev) +return -ENOMEM ; + + indio_dev->name = client->name; + indio_dev->info = &sts30_info; + indio_dev->channels = sts30_channels; + indio_dev->num_channels =ARRAY_SIZE (sts30_channels); + indio_dev->modes =INDIO_DIRECT_MODE ; + + data =iio_priv (indio_dev); + data->client = client; + data->delay =STS30_REPEAT_HIGH ; + + ret =devm_mutex_init (&client->dev, &data->lock);
Quoted 9 lines
drivers/iio/temperature/sts30.c line 283
Quoted 6 lines
drivers/iio/temperature/sts30.c new file +6
-0+if (ret) +return ret; + +i2c_set_clientdata (client, indio_dev); + + ret =sts30_reset (data);You're not checking ret here.
Also saw that from sashiko, and will fix.
Signature · 2 lines
best regards, max
RFC PATCH 3/3 MAINTAINERS: Add entry for Sensirion STS30 driver
In reply to Maxwell DooseAdd the entry for the STS30 temperature sensor driver in MAINTAINERS.
--- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -24487,6 +24487,12 @@ F: drivers/iio/chemical/sps30.c F: drivers/iio/chemical/sps30_i2c.c F: drivers/iio/chemical/sps30_serial.c +SENSIRION STS30 TEMPERATURE SENSOR DRIVER +M: Maxwell Doose <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml +F: drivers/iio/temperature/sts30.c + SERIAL DEVICE BUS M: Rob Herring <[email protected]> L: [email protected]
Signature · 1 line
2.54.0
Re: [RFC PATCH 3/3] MAINTAINERS: Add entry for Sensirion STS30 driver
MAINTAINERS F: drivers/iio/chemical/sps30.c · line 24493
Quoted 4 lines · On Fri, 19 Jun 2026 23:40:07 -0500 Maxwell Doose <[email protected]> wrote:
MAINTAINERS +4
-0+SENSIRION STS30 TEMPERATURE SENSOR DRIVER +M: Maxwell Doose <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml
Fold the above changes into your dt-bindings patch.
Quoted 1 line
+F:
drivers/iio/temperature/sts30.c
This change then goes into the driver code patch. If you're adding new files, ensure that your patch also adds a mention to said file to MAINTAINERS (IIRC b4 actually checks for this when you run prep --check).
Signature · 3 lines
Kind regards CJD
Jonathan Cameron
maintainerQuoted 6 lines · On Fri, 19 Jun 2026 23:40:04 -0500 Maxwell Doose <[email protected]> wrote:
Hi all,
This patch adds support for the Sensirion STS30 family of temperature sensor drivers. It currently supports single-shot non-clock stretched readings as well as the entirety of the STS30 family.
Quoted 10 lines
I'm sending this as an RFC patch as I unfortunately do not have the hardware right now. I have compile-tested it successfully and have done a tad bit of testing on QEMU, with it properly registering with no errors reported in dmesg. Unfortunately due to the way I had compiled the kernel used to test the driver it did not expose the I2C bus to userspace properly and I was not able to retrieve values from the driver, but I can continue more testing over the next few days and am happy to answer any questions anyone may have. Additionally, regarding dmesg logs, I neglected to save them while in my testing, but as stated previously, I can continue more testing over the next couple of days.
Hi Maxwell,
If sending a driver out prior to getting access to hardware (nothing wrong with doing that to get early feebdack!) Then mark it RFC and state at top of cover letter it's because it is untested on real hardware.
Note there are exceptions to this where we will merge kernel code against emulation but that is normally about large cross industry standards or similar not small drivers like this one.
Thanks,
Jonathan
Quoted 15 lines
Maxwell Doose (3):
dt-bindings: iio: temperature: Add STS30 devicetree bindings
iio: temperature: Add STS30 temperature sensor driver
MAINTAINERS: Add entry for Sensirion STS30 driver.../iio/temperature/sensirion,sts30.yaml | 49 +++ MAINTAINERS | 6 + drivers/iio/temperature/Kconfig | 11 + drivers/iio/temperature/Makefile | 1 + drivers/iio/temperature/sts30.c | 321 ++++++++++++++++++ 5 files changed, 388 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/temperature/sensirion,sts30.yaml create mode 100644 drivers/iio/temperature/sts30.c