iio: flow: Sensirion SLF3S liquid flow sensor
Subsystems (3)
Wadim Mueller
maintainerv4 cover iio: flow: Sensirion SLF3S liquid flow sensor
Hi all,
this series adds a driver for the Sensirion SLF3S family of I2C liquid flow sensors (SLF3S-0600F / -1300F / -4000B) and a new IIO_VOLUMEFLOW channel type. As in v3 this is posted as a fresh thread.
Dependency
----------
The volume-flow scale is reported in m^3/s as a 64-bit fixed-point value (IIO_VAL_DECIMAL64_FEMTO), so this series depends on Rodrigo Alencar's "ADF41513/ADF41510 PLL frequency synthesizers" series, which adds the IIO_VAL_DECIMAL64_* core formatting (and the kstrtodec64() and div64_s64_rem() helpers it builds on):
https://lore.kernel.org/linux-iio/[email protected]/
Patch 3/4 adds the IIO_VAL_DECIMAL64_FEMTO format type on top of that.
Changes since v3
----------------
* volumeflow unit switched from l/s to m^3/s (SI), per Jonathan
* scale now reported as IIO_VAL_DECIMAL64_FEMTO instead of IIO_VAL_FRACTIONAL, so the small m^3/s values (~1.7e-12 m^3/s for the SLF3S-0600F) keep full precision; this needs the new FEMTO core type (3/4) and the dependency above
* dt-bindings: sensirion,slf3s-1300f now serves as the fallback compatible for the other variants (all variants are detectable from the product-information register), per Krzysztof; Marcelo's Reviewed-by dropped because of this change
* dt-bindings: add interrupts (maxItems: 1) back
* dt-bindings: reflow the description to 80 columns
* dt-bindings: move "F: drivers/iio/flow/slf3s.c" to the driver patch
* driver: add system PM ops following the scd30/scd4x precedent: stop the measurement and disable the supply on suspend; power back up, wait out the power-up time and restart with the previously active medium on resume
* driver: if switching the medium fails after the stop command, restart with the previous medium instead of leaving the sensor idle
* driver: a sensor reporting an unknown sub-type now falls back to the variant named in the device tree instead of failing probe, matching the fallback-compatible semantics
* driver: serialise the command/response exchanges with a local mutex instead of iio_device_claim_direct() / release_direct()
* driver: issue a stop-measurement at the start of probe(), so a sensor left in continuous mode across a warm reboot does not NACK probe
* driver: read only the 6 bytes actually used (flow + temperature) per measurement frame instead of 9
* driver: trim the per-variant list out of the Kconfig help text
* ABI: in_volumeflow_medium[_available] documented in Documentation/ABI/testing/sysfs-bus-iio-flow; KernelVersion 7.3
The signaling-flags word (air-in-line / high-flow / smoothing status) in each measurement frame is intentionally not read; exposing it can be a later follow-up.
Thanks,
Wadim
Wadim Mueller (4):
iio: types: add IIO_VOLUMEFLOW channel type
dt-bindings: iio: flow: add Sensirion SLF3S liquid flow sensor
iio: core: add IIO_VAL_DECIMAL64_FEMTO format type
iio: flow: add Sensirion SLF3S liquid flow sensor driver
Documentation/ABI/testing/sysfs-bus-iio | 11 + Documentation/ABI/testing/sysfs-bus-iio-flow | 21 + .../bindings/iio/flow/sensirion,slf3s.yaml | 58 ++ MAINTAINERS | 8 + drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/flow/Kconfig | 22 + drivers/iio/flow/Makefile | 7 + drivers/iio/flow/slf3s.c | 521 ++++++++++++++++++ drivers/iio/industrialio-core.c | 3 + include/linux/iio/types.h | 1 + include/uapi/linux/iio/types.h | 1 + tools/iio/iio_event_monitor.c | 2 + 13 files changed, 657 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-flow create mode 100644 Documentation/devicetree/bindings/iio/flow/sensirion,slf3s.yaml create mode 100644 drivers/iio/flow/Kconfig create mode 100644 drivers/iio/flow/Makefile create mode 100644 drivers/iio/flow/slf3s.c
base-commit: 3cd8b194bf3428dfa53120fee47e827a7c495815
prerequisite-patch-id: b51a25b69f7b78155e78d1a3aab809bcb57e11ae
prerequisite-patch-id: 1b26fb01ab41218c214fa58657305437565c06f8
prerequisite-patch-id: 7745e957a25b8673c7f838a9ae7a55269cd21798
prerequisite-patch-id: 5f805ccb0be820042ac732d0d8e1b188bfd2b2bc
prerequisite-patch-id: 80967f95ecb0c10fc66b3d073e99906126d5b40b
prerequisite-patch-id: 729fdedcf2055c506693d28a5dab65a6a3791598
Signature · 1 line
2.52.0
Wadim Mueller
maintainerPATCH v4 1/4 iio: types: add IIO_VOLUMEFLOW channel type
Add a new IIO channel type for liquid volumetric flow sensors. The unit exposed via the standard _scale attribute is cubic metres per second (m^3/s), following the SI convention used by the other IIO channel types.
Update iio-core's name table, the iio_event_monitor whitelist and the sysfs-bus-iio ABI document to match. The new _scale attribute is folded into the existing shared _scale block; only the per-type _raw needs a fresh entry.
--- Documentation/ABI/testing/sysfs-bus-iio | 11 +++++++++++ drivers/iio/industrialio-core.c | 1 + include/uapi/linux/iio/types.h | 1 + tools/iio/iio_event_monitor.c | 2 ++ 4 files changed, 15 insertions(+)
Documentation/ABI/testing/sysfs-bus-iio +11 -0
@@ -507,6 +507,8 @@ What: /sys/bus/iio/devices/iio:deviceX/in_intensity_red_scale What: /sys/bus/iio/devices/iio:deviceX/in_intensity_green_scale What: /sys/bus/iio/devices/iio:deviceX/in_intensity_blue_scale What: /sys/bus/iio/devices/iio:deviceX/in_concentration_co2_scale +What: /sys/bus/iio/devices/iio:deviceX/in_volumeflow_scale +What: /sys/bus/iio/devices/iio:deviceX/in_volumeflowY_scale KernelVersion: 2.6.35 Contact: [email protected] Description:
@@ -2458,3 +2460,12 @@ Description: seconds, expressed as: - a range specified as "[min step max]" + +What: /sys/bus/iio/devices/iio:deviceX/in_volumeflow_raw +What: /sys/bus/iio/devices/iio:deviceX/in_volumeflowY_raw +KernelVersion: 7.3 +Contact: [email protected] +Description: + Raw (unscaled) volumetric flow rate reading from the channel. + To convert to standard units (cubic metres per second, m^3/s) + apply the channel's _scale (and _offset, when present).
drivers/iio/industrialio-core.c +1 -0
@@ -98,6 +98,7 @@ static const char * const iio_chan_type_name_spec[] = { [IIO_CHROMATICITY] = "chromaticity", [IIO_ATTENTION] = "attention", [IIO_ALTCURRENT] = "altcurrent", + [IIO_VOLUMEFLOW] = "volumeflow", };static const char *const iio_modifier_names[] = {
include/uapi/linux/iio/types.h +1 -0
@@ -53,6 +53,7 @@ enum iio_chan_type {IIO_CHROMATICITY ,IIO_ATTENTION ,IIO_ALTCURRENT , + IIO_VOLUMEFLOW, }; enum iio_modifier {
tools/iio/iio_event_monitor.c +2 -0
@@ -65,6 +65,7 @@ static const char * const iio_chan_type_name_spec[] = { [IIO_CHROMATICITY] = "chromaticity", [IIO_ATTENTION] = "attention", [IIO_ALTCURRENT] = "altcurrent", + [IIO_VOLUMEFLOW] = "volumeflow", };static const char *const iio_ev_type_text[] = {
@@ -193,6 +194,7 @@ static bool event_is_known(struct iio_event_data *event)case IIO_CHROMATICITY :case IIO_ATTENTION :case IIO_ALTCURRENT : +case IIO_VOLUMEFLOW :break ;default :return false;
Signature · 1 line
2.52.0
Wadim Mueller
maintainerPATCH v4 2/4 dt-bindings: iio: flow: add Sensirion SLF3S liquid flow sensor
In reply to Wadim MuellerDocument the bindings for the Sensirion SLF3S family of digital liquid-flow sensors on I2C. The family currently covers the SLF3S-0600F, SLF3S-1300F and SLF3S-4000B variants.
All variants share the same register map and are fully detectable from the product-information register at probe time, so sensirion,slf3s-1300f serves as the fallback compatible for the other variants.
The active calibration medium (water / IPA) is runtime-switchable via the in_volumeflow_medium sysfs attribute and therefore not a DT property.
--- .../bindings/iio/flow/sensirion,slf3s.yaml | 58 +++++++++++++++++++ MAINTAINERS | 7 +++ 2 files changed, 65 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/flow/sensirion,slf3s.yaml
Documentation/devicetree/bindings/iio/flow/sensirion,slf3s.yaml new file +58 -0
@@ -0,0 +1,58 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/iio/flow/sensirion,slf3s.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sensirion SLF3S liquid flow sensor + +maintainers: + - Wadim Mueller <[email protected]> + +description: + Family of digital liquid-flow sensors from Sensirion with I2C interface. All + family members share the same register map; sub-types differ only in the flow + scale factor and the calibrated measurement range. The sub-type can be + identified from the product-information register. + +properties: + compatible: + oneOf: + - const: sensirion,slf3s-1300f + - items: + - enum: + - sensirion,slf3s-0600f + - sensirion,slf3s-4000b + - const: sensirion,slf3s-1300f + + reg: + maxItems: 1 + + vdd-supply: true + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + - vdd-supply + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/irq.h> + + i2c { + #address-cells = <1>; + #size-cells = <0>; + + flow-sensor@8 { + compatible = "sensirion,slf3s-0600f", "sensirion,slf3s-1300f"; + reg = <0x08>; + vdd-supply = <®_3v3>; + interrupt-parent = <&gpio0>; + interrupts = <0 IRQ_TYPE_EDGE_RISING>; + }; + };
MAINTAINERS +7 -0
@@ -24187,6 +24187,13 @@ S: Maintained F: Documentation/ABI/testing/sysfs-bus-iio-chemical-sgp40 F: drivers/iio/chemical/sgp40.c +SENSIRION SLF3S LIQUID FLOW SENSOR DRIVER +M: Wadim Mueller <[email protected]> +R: Maxwell Doose <[email protected]> +L: [email protected] +S: Maintained +F: Documentation/devicetree/bindings/iio/flow/sensirion,slf3s.yaml + SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER M: Tomasz Duszynski <[email protected]> S: Maintained
Signature · 1 line
2.52.0
Re: [PATCH v4 2/4] dt-bindings: iio: flow: add Sensirion SLF3S liquid flow sensor
Quoted 9 lines · Wadim Mueller
Document the bindings for the Sensirion SLF3S family of digital liquid-flow sensors on I2C. The family currently covers the SLF3S-0600F, SLF3S-1300F and SLF3S-4000B variants.
All variants share the same register map and are fully detectable from the product-information register at probe time, so sensirion,slf3s-1300f serves as the fallback compatible for the other variants.
Quoted 6 lines
The active calibration medium (water / IPA) is runtime-switchable via the
in_volumeflow_mediumsysfs attribute and therefore not a DT property.Signed-off-by Wadim Mueller <[email protected]>---
Best regards,
Krzysztof
Wadim Mueller
maintainerPATCH v4 3/4 iio: core: add IIO_VAL_DECIMAL64_FEMTO format type
In reply to Wadim MuellerExtend the IIO_VAL_DECIMAL64_* family with a femto-scaled variant (scale 15), following the existing MILLI/MICRO/NANO/PICO pattern. Both the read formatting path in __iio_format_value() and the write parsing path in iio_write_channel_info() (via kstrtodec64()) already derive their scale from "type - IIO_VAL_DECIMAL64_BASE", so the new type only needs to be added to the respective switch cases.
This is needed by drivers reporting very small SI quantities where the existing pico scale loses precision. For example the Sensirion SLF3S liquid flow sensor reports its volume-flow scale in m^3/s, where the SLF3S-0600F scale is ~1.667e-12 m^3/s: at pico scale only a single significant digit survives, whereas femto scale preserves the full sensor resolution.
--- drivers/iio/industrialio-core.c | 2 ++ include/linux/iio/types.h | 1 + 2 files changed, 3 insertions(+)
drivers/iio/industrialio-core.c +2 -0
@@ -713,6 +713,7 @@ static ssize_t __iio_format_value(char *buf, size_t offset, unsigned int type,case IIO_VAL_DECIMAL64_MICRO :case IIO_VAL_DECIMAL64_NANO :case IIO_VAL_DECIMAL64_PICO : +case IIO_VAL_DECIMAL64_FEMTO : {int scale = type -IIO_VAL_DECIMAL64_BASE ;s64 frac;
@@ -1030,6 +1031,7 @@ static ssize_t iio_write_channel_info(struct device *dev,case IIO_VAL_DECIMAL64_MICRO :case IIO_VAL_DECIMAL64_NANO :case IIO_VAL_DECIMAL64_PICO : +case IIO_VAL_DECIMAL64_FEMTO : dec_scale = type -IIO_VAL_DECIMAL64_BASE ; fallthrough;case IIO_VAL_INT_64 :
include/linux/iio/types.h +1 -0
@@ -41,6 +41,7 @@ enum iio_event_info {#define IIO_VAL_DECIMAL64_MICRO (IIO_VAL_DECIMAL64_BASE + 6)#define IIO_VAL_DECIMAL64_NANO (IIO_VAL_DECIMAL64_BASE + 9)#define IIO_VAL_DECIMAL64_PICO (IIO_VAL_DECIMAL64_BASE + 12) +#define IIO_VAL_DECIMAL64_FEMTO (IIO_VAL_DECIMAL64_BASE + 15)static inline s64 iio_val_s64_compose (s32 val0,s32 val1) {
Signature · 1 line
2.52.0
Re: [PATCH v4 3/4] iio: core: add IIO_VAL_DECIMAL64_FEMTO format type
Quoted 14 lines · Wadim Mueller
Extend the IIO_VAL_DECIMAL64_* family with a femto-scaled variant (scale 15), following the existing MILLI/MICRO/NANO/PICO pattern. Both the read formatting path in
__iio_format_value()and the write parsing path iniio_write_channel_info()(viakstrtodec64()) already derive their scale from "type -IIO_VAL_DECIMAL64_BASE", so the new type only needs to be added to the respective switch cases.This is needed by drivers reporting very small SI quantities where the existing pico scale loses precision. For example the Sensirion SLF3S liquid flow sensor reports its volume-flow scale in m^3/s, where the SLF3S-0600F scale is ~1.667e-12 m^3/s: at pico scale only a single significant digit survives, whereas femto scale preserves the full sensor resolution.
Quoted 2 lines
Signed-off-by Wadim Mueller <[email protected]>---
Quoted 39 lines
drivers/iio/industrialio-core.c | 2 ++ include/linux/iio/types.h | 1 + 2 files changed, 3 insertions(+)drivers/iio/industrialio-core.c +2
-0@@ -713,6 +713,7 @@ static ssize_t __iio_format_value(char *buf, size_t offset, unsigned int type,case IIO_VAL_DECIMAL64_MICRO :case IIO_VAL_DECIMAL64_NANO :case IIO_VAL_DECIMAL64_PICO : +case IIO_VAL_DECIMAL64_FEMTO : {int scale = type -IIO_VAL_DECIMAL64_BASE ;s64 frac;@@ -1030,6 +1031,7 @@ static ssize_t iio_write_channel_info(struct device *dev,case IIO_VAL_DECIMAL64_MICRO :case IIO_VAL_DECIMAL64_NANO :case IIO_VAL_DECIMAL64_PICO : +case IIO_VAL_DECIMAL64_FEMTO : dec_scale = type -IIO_VAL_DECIMAL64_BASE ; fallthrough;case IIO_VAL_INT_64 :include/linux/iio/types.h +1
-0@@ -41,6 +41,7 @@ enum iio_event_info {#define IIO_VAL_DECIMAL64_MICRO (IIO_VAL_DECIMAL64_BASE + 6)#define IIO_VAL_DECIMAL64_NANO (IIO_VAL_DECIMAL64_BASE + 9)#define IIO_VAL_DECIMAL64_PICO (IIO_VAL_DECIMAL64_BASE + 12) +#define IIO_VAL_DECIMAL64_FEMTO (IIO_VAL_DECIMAL64_BASE + 15)static inline s64 iio_val_s64_compose (s32 val0,s32 val1) {Signature · 1 line
2.52.0
Wadim Mueller
maintainerPATCH v4 4/4 iio: flow: add Sensirion SLF3S liquid flow sensor driver
In reply to Wadim MuellerAdd a driver for the Sensirion SLF3S family of digital liquid-flow sensors on I2C. Currently supported variants are SLF3S-0600F, SLF3S-1300F and SLF3S-4000B; they share the same register map and differ only in flow-scale factor and calibrated measurement range. The variant (and therefore the scale) is auto-detected from the product-information register at probe time; a sensor reporting an unknown sub-type falls back to the variant named in the device tree, as promised by the fallback compatible.
Each measurement frame returns a 16-bit signed flow value, a 16-bit signed temperature reading and a status word, each protected by a CRC-8 byte. The driver exposes the flow rate as IIO_VOLUMEFLOW and the temperature as IIO_TEMP via the standard IIO read_raw / read_scale interface.
The volume-flow scale is reported in m^3/s. As the per-LSB scale is on the order of 1e-12 m^3/s, it is emitted as a 64-bit fixed-point value with femto (1e-15) resolution (IIO_VAL_DECIMAL64_FEMTO) so the small SI value keeps full precision. This relies on the IIO_VAL_DECIMAL64_FEMTO format type added earlier in this series, which extends the IIO_VAL_DECIMAL64 core formatting introduced by Rodrigo Alencar's ADF41513 series.
The active calibration medium can be switched at runtime between the factory-calibrated water and isopropyl-alcohol modes via the in_volumeflow_medium sysfs attribute; the sensor starts in water mode after probe.
The sensor has no low-power state of its own, so system suspend stops the measurement and disables the vdd supply; resume powers the sensor back up, waits out the power-up time and restarts the measurement with the previously active medium, following the scd30/scd4x precedent.
This driver also creates the drivers/iio/flow/ subdirectory and the corresponding Kconfig/Makefile glue.
--- Documentation/ABI/testing/sysfs-bus-iio-flow | 21 + MAINTAINERS | 1 + drivers/iio/Kconfig | 1 + drivers/iio/Makefile | 1 + drivers/iio/flow/Kconfig | 22 + drivers/iio/flow/Makefile | 7 + drivers/iio/flow/slf3s.c | 521 +++++++++++++++++++ 7 files changed, 574 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-flow create mode 100644 drivers/iio/flow/Kconfig create mode 100644 drivers/iio/flow/Makefile create mode 100644 drivers/iio/flow/slf3s.c
Documentation/ABI/testing/sysfs-bus-iio-flow new file +21 -0
@@ -0,0 +1,21 @@ +What: /sys/bus/iio/devices/iio:deviceX/in_volumeflow_medium +What: /sys/bus/iio/devices/iio:deviceX/in_volumeflowY_medium +KernelVersion: 7.3 +Contact: [email protected] +Description: + The calibration medium the flow sensor uses to convert its + raw reading into a volumetric flow rate. Liquid flow sensors + are factory-calibrated per medium, so the selected medium has + to match the fluid actually flowing through the sensor for the + reported flow rate to be correct. + + Reading returns the currently active medium; writing one of the + strings listed in in_volumeflow_medium_available selects it. + +What: /sys/bus/iio/devices/iio:deviceX/in_volumeflow_medium_available +What: /sys/bus/iio/devices/iio:deviceX/in_volumeflowY_medium_available +KernelVersion: 7.3 +Contact: [email protected] +Description: + Space separated list of the calibration media supported by the + device, e.g. "water ipa".
MAINTAINERS +1 -0
@@ -24193,6 +24193,7 @@ R: Maxwell Doose <[email protected]> L: [email protected] S: Maintained F: Documentation/devicetree/bindings/iio/flow/sensirion,slf3s.yaml +F: drivers/iio/flow/slf3s.c SENSIRION SPS30 AIR POLLUTION SENSOR DRIVER M: Tomasz Duszynski <[email protected]>
drivers/iio/Kconfig +1 -0
@@ -92,6 +92,7 @@ source "drivers/iio/common/Kconfig" source "drivers/iio/dac/Kconfig" source "drivers/iio/dummy/Kconfig" source "drivers/iio/filter/Kconfig" +source "drivers/iio/flow/Kconfig" source "drivers/iio/frequency/Kconfig" source "drivers/iio/gyro/Kconfig" source "drivers/iio/health/Kconfig"
drivers/iio/Makefile +1 -0
@@ -29,6 +29,7 @@ obj-y += dac/ obj-y += dummy/ obj-y += gyro/ obj-y += filter/ +obj-y += flow/ obj-y += frequency/ obj-y += health/ obj-y += humidity/
drivers/iio/flow/Kconfig new file +22 -0
@@ -0,0 +1,22 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# Liquid / gas flow sensor drivers +# +# When adding new entries keep the list in alphabetical order + +menu "Flow sensors" + +config SENSIRION_SLF3S + tristate "Sensirion SLF3S liquid flow sensor" + depends on I2C + select CRC8 + help + Say yes here to build support for the Sensirion SLF3S family of + digital liquid-flow sensors (SLF3S-0600F, SLF3S-1300F and + SLF3S-4000B). The driver reports the volumetric flow rate and the + embedded temperature reading via the standard IIO interface. + + To compile this driver as a module, choose M here: the module + will be called slf3s. + +endmenu
drivers/iio/flow/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for industrial I/O flow sensor drivers +# + +# When adding new entries keep the list in alphabetical order +obj-$(CONFIG_SENSIRION_SLF3S) += slf3s.o
drivers/iio/flow/slf3s.c new file +521 -0
521 lines not on this page · raw message
Signature · 1 line
2.52.0
Re: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
drivers/iio/flow/slf3s.c line 503
Quoted 5 lines · Wadim Mueller
drivers/iio/flow/slf3s.c new file +5
-0+ +static const struct of_device_id slf3s_of_match[] = { + { .compatible ="sensirion,slf3s-0600f" , .data = &slf3s_variants[0 ] }, + { .compatible ="sensirion,slf3s-1300f" , .data = &slf3s_variants[1 ] }, + { .compatible ="sensirion,slf3s-4000b" , .data = &slf3s_variants[2 ] },
You should have only 1300f here and detect the variants. That was my point when I suggested to use the fallback.
Best regards,
Krzysztof
Jonathan Cameron
maintainerRe: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
Quoted 10 lines · On Thu, 11 Jun 2026 16:01:12 +0200 Krzysztof Kozlowski <[email protected]> wrote:
drivers/iio/flow/slf3s.c line 503
Quoted 5 lines · Wadim Mueller
drivers/iio/flow/slf3s.c new file +5
-0+ +static const struct of_device_id slf3s_of_match[] = { + { .compatible ="sensirion,slf3s-0600f" , .data = &slf3s_variants[0 ] }, + { .compatible ="sensirion,slf3s-1300f" , .data = &slf3s_variants[1 ] }, + { .compatible ="sensirion,slf3s-4000b" , .data = &slf3s_variants[2 ] },You should have only 1300f here and detect the variants. That was my point when I suggested to use the fallback.
I'm lost. How does that work? They cannot fallback to that part because it relies on in driver detection of the fact that they are incompatible.
Jonathan
Quoted 2 lines
Best regards,
Krzysztof
Re: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
Quoted 14 lines · Jonathan Cameron
Quoted 10 lines · On Thu, 11 Jun 2026 16:01:12 +0200 Krzysztof Kozlowski <[email protected]> wrote:
drivers/iio/flow/slf3s.c line 503
Quoted 5 lines · Wadim Mueller
drivers/iio/flow/slf3s.c new file +5
-0+ +static const struct of_device_id slf3s_of_match[] = { + { .compatible ="sensirion,slf3s-0600f" , .data = &slf3s_variants[0 ] }, + { .compatible ="sensirion,slf3s-1300f" , .data = &slf3s_variants[1 ] }, + { .compatible ="sensirion,slf3s-4000b" , .data = &slf3s_variants[2 ] },You should have only 1300f here and detect the variants. That was my point when I suggested to use the fallback.
Quoted 3 lines
I'm lost. How does that work? They cannot fallback to that part because it relies on in driver detection of the fact that they are incompatible.
I am lost too. Then why were they made compatible in the binding?
Entire discussion was that these are FULLY compatible due to variant detection. That was the entire point of discussing more generic fallback. Using specific fallback does not change that - it is the same concept.
If devices are not detectable, why were we discussing any compatibility?
Best regards,
Krzysztof
Jonathan Cameron
maintainerRe: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
Quoted 19 lines · On Sat, 13 Jun 2026 09:51:13 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 14 lines · Jonathan Cameron
Quoted 10 lines · On Thu, 11 Jun 2026 16:01:12 +0200 Krzysztof Kozlowski <[email protected]> wrote:
drivers/iio/flow/slf3s.c line 503
Quoted 5 lines · Wadim Mueller
drivers/iio/flow/slf3s.c new file +5
-0+ +static const struct of_device_id slf3s_of_match[] = { + { .compatible ="sensirion,slf3s-0600f" , .data = &slf3s_variants[0 ] }, + { .compatible ="sensirion,slf3s-1300f" , .data = &slf3s_variants[1 ] }, + { .compatible ="sensirion,slf3s-4000b" , .data = &slf3s_variants[2 ] },You should have only 1300f here and detect the variants. That was my point when I suggested to use the fallback.
Quoted 3 lines
I'm lost. How does that work? They cannot fallback to that part because it relies on in driver detection of the fact that they are incompatible.
Quoted 8 lines
I am lost too. Then why were they made compatible in the binding?
Entire discussion was that these are FULLY compatible due to variant detection. That was the entire point of discussing more generic fallback. Using specific fallback does not change that - it is the same concept.
If devices are not detectable, why were we discussing any compatibility?
They are detectable, but the feature set is not, so to me there is zero valid in a generic fallback, we have to update the driver every time a new part comes along. (i.e. I agree with Conor's reply to the previous version thread). A specific fallback to a completely compatible part would be fine as there would be sufficient info to not need the ID lookup.
The case in the binding for this version is the worst of all options because it implies it is valid to fallback to something that gives a false impression of being specific when it's relying on ID matching to say actually it's something else.
So definitely not
+ compatible:
+ oneOf:
+ - const: sensirion,slf3s-1300f
+ - items:
+ - enum:
+ - sensirion,slf3s-0600f
+ - sensirion,slf3s-4000b
+ - const: sensirion,slf3s-1300f
+
Falling back to slf3s is better than this, but I'd rather not have a fallback at all, thus allowing correct fallback to the parts listed here in future.
Jonathan
Quoted 3 lines
Best regards,
Krzysztof
Re: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
Quoted 29 lines · Jonathan Cameron
Quoted 26 lines · On Sat, 13 Jun 2026 09:51:13 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 14 lines · Jonathan Cameron
Quoted 10 lines · On Thu, 11 Jun 2026 16:01:12 +0200 Krzysztof Kozlowski <[email protected]> wrote:
drivers/iio/flow/slf3s.c line 503
Quoted 5 lines · Wadim Mueller
drivers/iio/flow/slf3s.c new file +5
-0+ +static const struct of_device_id slf3s_of_match[] = { + { .compatible ="sensirion,slf3s-0600f" , .data = &slf3s_variants[0 ] }, + { .compatible ="sensirion,slf3s-1300f" , .data = &slf3s_variants[1 ] }, + { .compatible ="sensirion,slf3s-4000b" , .data = &slf3s_variants[2 ] },You should have only 1300f here and detect the variants. That was my point when I suggested to use the fallback.
Quoted 3 lines
I'm lost. How does that work? They cannot fallback to that part because it relies on in driver detection of the fact that they are incompatible.
I am lost too. Then why were they made compatible in the binding?
Entire discussion was that these are FULLY compatible due to variant detection. That was the entire point of discussing more generic fallback. Using specific fallback does not change that - it is the same concept.
Quoted 7 lines
Quoted 1 line
If devices are not detectable, why were we discussing any compatibility?
They are detectable, but the feature set is not, so to me there is zero valid in a generic fallback, we have to update the driver every time a new part comes along. (i.e. I agree with Conor's reply to the previous version thread). A specific fallback to a completely compatible part would be fine as there would be sufficient info to not need the ID lookup.
This patch has specific fallback and we discuss this now.
Quoted 17 lines
The case in the binding for this version is the worst of all options because it implies it is valid to fallback to something that gives a false impression of being specific when it's relying on ID matching to say actually it's something else.
So definitely not
(quoted diff) +9
-0+ compatible: + oneOf: + - const: sensirion,slf3s-1300f + - items: + - enum: + - sensirion,slf3s-0600f + - sensirion,slf3s-4000b + - const: sensirion,slf3s-1300f +
Quoted 2 lines
Falling back to slf3s is better than this, but I'd rather not have a fallback at all, thus allowing correct fallback to the parts listed here in future.
Why? These devices are fully detectable thus fully compatible.
Best regards,
Krzysztof
Jonathan Cameron
maintainerRe: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
Quoted 57 lines · On Mon, 15 Jun 2026 06:27:00 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 29 lines · Jonathan Cameron
Quoted 26 lines · On Sat, 13 Jun 2026 09:51:13 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 14 lines · Jonathan Cameron
Quoted 10 lines · On Thu, 11 Jun 2026 16:01:12 +0200 Krzysztof Kozlowski <[email protected]> wrote:
drivers/iio/flow/slf3s.c line 503
Quoted 5 lines · Wadim Mueller
drivers/iio/flow/slf3s.c new file +5
-0+ +static const struct of_device_id slf3s_of_match[] = { + { .compatible ="sensirion,slf3s-0600f" , .data = &slf3s_variants[0 ] }, + { .compatible ="sensirion,slf3s-1300f" , .data = &slf3s_variants[1 ] }, + { .compatible ="sensirion,slf3s-4000b" , .data = &slf3s_variants[2 ] },You should have only 1300f here and detect the variants. That was my point when I suggested to use the fallback.
Quoted 3 lines
I'm lost. How does that work? They cannot fallback to that part because it relies on in driver detection of the fact that they are incompatible.
I am lost too. Then why were they made compatible in the binding?
Entire discussion was that these are FULLY compatible due to variant detection. That was the entire point of discussing more generic fallback. Using specific fallback does not change that - it is the same concept.
Quoted 7 lines
Quoted 1 line
If devices are not detectable, why were we discussing any compatibility?
They are detectable, but the feature set is not, so to me there is zero valid in a generic fallback, we have to update the driver every time a new part comes along. (i.e. I agree with Conor's reply to the previous version thread). A specific fallback to a completely compatible part would be fine as there would be sufficient info to not need the ID lookup.
This patch has specific fallback and we discuss this now.
Quoted 17 lines
The case in the binding for this version is the worst of all options because it implies it is valid to fallback to something that gives a false impression of being specific when it's relying on ID matching to say actually it's something else.
So definitely not
(quoted diff) +9
-0+ compatible: + oneOf: + - const: sensirion,slf3s-1300f + - items: + - enum: + - sensirion,slf3s-0600f + - sensirion,slf3s-4000b + - const: sensirion,slf3s-1300f +
Quoted 4 lines
Quoted 2 lines
Falling back to slf3s is better than this, but I'd rather not have a fallback at all, thus allowing correct fallback to the parts listed here in future.
Why? These devices are fully detectable thus fully compatible.
Ok. We aren't really making progress. Let me layout the three approaches.
+ advantages and disadvantages as I understand it.
What we have here:
compatible:
oneOf:
- const: sensirion,slf3s-1300f
- items:
- enum:
- sensirion,slf3s-0600f
- sensirion,slf3s-4000b
- const: sensirion,slf3s-1300f
Advantages: Fallback to a real part.
Disadvantages:
- Requires a driver change even for drop in replacements (which will have different WHOAMI IDs.
- To me it implies that a driver that supports slf3s-1300f should just work with parts we haven't seen yet if they have that in their fallback lists. I appreciate you think that we shouldn't put effort into supporting that case, but to me it seems more or less free to support and is useful.
Generic compatible for fallback.
compatible:
- items:
- enum:
- sensirion,slf3s-0600f
- sensirion,slf3s-1300f
- sensirion,slf3s-4000b
- const: sensirion,slf3s
Advantages: Fallback to something that doesn't imply the post fix is coming from
DT. So kind of hints we need detection code.
Disadvantages: requires driver changes for each fully compatible drop in part. Note I'm not sure what this brings us over just having one compatible... Maybe we'll some day get a non detectable difference where we need to use the binding but seems fairly unlikely (I've seen that happen once when a manufacturer failed to update a WHOAMI reg value for a new part).
No fallbacks
compatible:
enum:
- sensirion,slf3s-0600f
- sensirion,slf3s-1300f
- sensirion,slf3s-4000b
Advantages: (Common!) a future drop in compatible part works with old kernels
as the driver knows a match + part information to use if the ID match fails.
Disadvantages: Not sure I see any... However I'm guessing I'm missing something.
Note for this topic I think it would be great to capture some best practice information somewhere so we can improve consistency. I've looked around and there are some bits of feedback in numerous threads but those are hard to track down.
The Dt spec refers to these as being about programming mode + driver selection. I will note that we have very broad families of devices that have a somewhat standard register interface + do always put the WHOAMI in the same place. In the vendor drivers those match a single hydra of a driver; upstream we have multiple drivers as devices do very different things and hence in practice almost no code would have been shared - so I have no idea what we should have done for those more commplex cases. Following your logic (I may have it wrong!) I think we would have had a generic compatible for the whole family but in upstream Linux no driver would have bound to that. I guess there are different extremes:
1) This case - register interfaces is consistent for all registers, we are just matching on constant tables needed to interpret the data in those tables.
2) Similarish. Main register interface shared, but optional additional parts. If one device is a strict superset, a fallback is appropriate (in my view) but if I follow your points here then they should all have a single fallback compatible.
3) Not particularly similar, but still detectable in a consistent way. To me not appropriate to have a common fallback as based on the dt-spec thing about matching drivers, they will typically match different drivers. Maybe we should have a common fallback but typically not bind to it?
4) Detection code becomes a mess and is different for each part
(see the old i2c_detect stuff) So hopefully no one thinks we
should use a fallback once we reach
this level of complexity (unless part are genuinely compatible)
I'm a little bothered by the fuzzy boundaries between those cases so would ideally like rules that say 1-3 need fallbacks or none do but we live in a fuzzy world, so maybe best we can do is leave things flexible.
Jonathan
Quoted 3 lines
Best regards,
Krzysztof
Wadim Mueller
maintainerRe: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
Quoted 2 lines · Jonathan Cameron
Ok. We aren't really making progress. Let me layout the three approaches.
+ advantages and disadvantages as I understand it.
[three approaches snipped]
Hi Krzysztof,
short ping from my side. I have prepared already a v5 with the review comments from Andy and Jonathan fixed, but I hold it back for now, since I don't want to change the binding two times.
Did you have meanwhile a chance to look at the three approaches from Jonathan above? I can respin then with whatever you two agree on.
Thanks,
Wadim
Re: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
Hi Wadim,
Quoted 5 lines · Wadim Mueller
Quoted 2 lines · Jonathan Cameron
Ok. We aren't really making progress. Let me layout the three approaches.
+ advantages and disadvantages as I understand it.
Quoted 7 lines
[three approaches snipped]
Hi Krzysztof,
short ping from my side. I have prepared already a v5 with the review comments from Andy and Jonathan fixed, but I hold it back for now, since I don't want to change the binding two times.
Quick update, I'm going to be updating my email to [email protected] so before you submit the v5 I'm hoping that can be updated in the R:?
--
best regards,
max
Re: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
In reply to Jonathan CameronQuoted 111 lines · Jonathan Cameron
Quoted 57 lines · On Mon, 15 Jun 2026 06:27:00 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 29 lines · Jonathan Cameron
Quoted 26 lines · On Sat, 13 Jun 2026 09:51:13 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Quoted 14 lines · Jonathan Cameron
Quoted 10 lines · On Thu, 11 Jun 2026 16:01:12 +0200 Krzysztof Kozlowski <[email protected]> wrote:
Review
Quoted 5 lines · Wadim Mueller
(quoted diff) +5
-0+ +static const struct of_device_id slf3s_of_match[] = { + { .compatible = "sensirion,slf3s-0600f", .data = &slf3s_variants[0] }, + { .compatible = "sensirion,slf3s-1300f", .data = &slf3s_variants[1] }, + { .compatible = "sensirion,slf3s-4000b", .data = &slf3s_variants[2] },You should have only 1300f here and detect the variants. That was my point when I suggested to use the fallback.
Quoted 3 lines
I'm lost. How does that work? They cannot fallback to that part because it relies on in driver detection of the fact that they are incompatible.
I am lost too. Then why were they made compatible in the binding?
Entire discussion was that these are FULLY compatible due to variant detection. That was the entire point of discussing more generic fallback. Using specific fallback does not change that - it is the same concept.
Quoted 7 lines
Quoted 1 line
If devices are not detectable, why were we discussing any compatibility?
They are detectable, but the feature set is not, so to me there is zero valid in a generic fallback, we have to update the driver every time a new part comes along. (i.e. I agree with Conor's reply to the previous version thread). A specific fallback to a completely compatible part would be fine as there would be sufficient info to not need the ID lookup.
This patch has specific fallback and we discuss this now.
Quoted 17 lines
The case in the binding for this version is the worst of all options because it implies it is valid to fallback to something that gives a false impression of being specific when it's relying on ID matching to say actually it's something else.
So definitely not
(quoted diff) +9
-0+ compatible: + oneOf: + - const: sensirion,slf3s-1300f + - items: + - enum: + - sensirion,slf3s-0600f + - sensirion,slf3s-4000b + - const: sensirion,slf3s-1300f +Quoted 4 lines
Quoted 2 lines
Falling back to slf3s is better than this, but I'd rather not have a fallback at all, thus allowing correct fallback to the parts listed here in future.
Why? These devices are fully detectable thus fully compatible.
Ok. We aren't really making progress. Let me layout the three approaches.
+ advantages and disadvantages as I understand it.What we have here:
compatible:
oneOf:
- const: sensirion,slf3s-1300f
- items:
- enum:
- sensirion,slf3s-0600f
- sensirion,slf3s-4000b
- const: sensirion,slf3s-1300fAdvantages: Fallback to a real part.
Disadvantages:
- Requires a driver change even for drop in replacements (which will have different WHOAMI IDs.
- To me it implies that a driver that supports slf3s-1300f should just work with parts we haven't seen yet if they have that in their fallback lists. I appreciate you think that we shouldn't put effort into supporting that case, but to me it seems more or less free to support and is useful.Generic compatible for fallback.
compatible:
- items:
- enum:
- sensirion,slf3s-0600f
- sensirion,slf3s-1300f
- sensirion,slf3s-4000b
- const: sensirion,slf3sAdvantages: Fallback to something that doesn't imply the post fix is coming from
DT. So kind of hints we need detection code.
Disadvantages: requires driver changes for each fully compatible drop in part. Note I'm not sure what this brings us over just having one compatible... Maybe we'll some day get a non detectable difference where we need to use the binding but seems fairly unlikely (I've seen that happen once when a manufacturer failed to update a WHOAMI reg value for a new part).No fallbacks
compatible:
enum:
- sensirion,slf3s-0600f
- sensirion,slf3s-1300f
- sensirion,slf3s-4000b
Quoted 4 lines
Advantages: (Common!) a future drop in compatible part works with old kernels
as the driver knows a match + part information to use if the ID match fails.
Disadvantages: Not sure I see any... However I'm guessing I'm missing something.
The same disadvantages as in other cases:
"Requires a driver change even for drop in replacements (which will have different WHOAMI IDs."
But I think I get your main point - since we need to compare WHOAMI registers for fallback cases, then there is no benefit of using the fallback in the first place, so let's go with original approach.
Quoted 17 lines
Note for this topic I think it would be great to capture some best practice information somewhere so we can improve consistency. I've looked around and there are some bits of feedback in numerous threads but those are hard to track down.
The Dt spec refers to these as being about programming mode + driver selection. I will note that we have very broad families of devices that have a somewhat standard register interface + do always put the WHOAMI in the same place. In the vendor drivers those match a single hydra of a driver; upstream we have multiple drivers as devices do very different things and hence in practice almost no code would have been shared - so I have no idea what we should have done for those more commplex cases. Following your logic (I may have it wrong!) I think we would have had a generic compatible for the whole family but in upstream Linux no driver would have bound to that. I guess there are different extremes:
Quoted 3 lines
1) This case - register interfaces is consistent for all registers, we are just matching on constant tables needed to interpret the data in those tables.
Interpreting data in registers is the programming interface, therefore the programming interface of that part is different. However since there is reliable autodetection of a model, the programming interface is considered compatible.
Quoted 9 lines
2) Similarish. Main register interface shared, but optional additional parts. If one device is a strict superset, a fallback is appropriate (in my view) but if I follow your points here then they should all have a single fallback compatible.
3) Not particularly similar, but still detectable in a consistent way. To me not appropriate to have a common fallback as based on the dt-spec thing about matching drivers, they will typically match different drivers. Maybe we should have a common fallback but typically not bind to it?
Unused common fallback rather suggests they are not compatible. The purpose of the fallback is for SW to use. If it is not used, let's just skip the fallback.
Quoted 4 lines
4) Detection code becomes a mess and is different for each part
(see the oldi2c_detectstuff) So hopefully no one thinks we
should use a fallback once we reach
this level of complexity (unless part are genuinely compatible)
Yes.
Best regards,
Krzysztof
Re: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
In reply to Wadim MuellerQuoted 36 lines · Wadim Mueller
Add a driver for the Sensirion SLF3S family of digital liquid-flow sensors on I2C. Currently supported variants are SLF3S-0600F, SLF3S-1300F and SLF3S-4000B; they share the same register map and differ only in flow-scale factor and calibrated measurement range. The variant (and therefore the scale) is auto-detected from the product-information register at probe time; a sensor reporting an unknown sub-type falls back to the variant named in the device tree, as promised by the fallback compatible.
Each measurement frame returns a 16-bit signed flow value, a 16-bit signed temperature reading and a status word, each protected by a CRC-8 byte. The driver exposes the flow rate as
IIO_VOLUMEFLOWand the temperature asIIO_TEMPvia the standard IIOread_raw/read_scaleinterface.The volume-flow scale is reported in m^3/s. As the per-LSB scale is on the order of 1e-12 m^3/s, it is emitted as a 64-bit fixed-point value with femto (1e-15) resolution (
IIO_VAL_DECIMAL64_FEMTO) so the small SI value keeps full precision. This relies on theIIO_VAL_DECIMAL64_FEMTOformat type added earlier in this series, which extends theIIO_VAL_DECIMAL64core formatting introduced by Rodrigo Alencar's ADF41513 series.The active calibration medium can be switched at runtime between the factory-calibrated water and isopropyl-alcohol modes via the
in_volumeflow_mediumsysfs attribute; the sensor starts in water mode after probe.The sensor has no low-power state of its own, so system suspend stops the measurement and disables the vdd supply; resume powers the sensor back up, waits out the power-up time and restarts the measurement with the previously active medium, following the scd30/scd4x precedent.
This driver also creates the
drivers/iio/flow/subdirectory and the corresponding Kconfig/Makefile glue.
...
drivers/iio/flow/slf3s.c line 27
Quoted 8 lines
drivers/iio/flow/slf3s.c new file +8
-0+#include <linux/array_size.h> +#include <linux/bitops.h> +#include <linux/cleanup.h> +#include <linux/crc8.h> +#include <linux/delay.h> +#include <linux/dev_printk.h> +#include <linux/device.h> +#include <linux/errno.h>
Should be err.h // PTR_ERR(), et cetera
Quoted 10 lines
drivers/iio/flow/slf3s.c new file +10
-0+#include <linux/i2c.h> +#include <linux/math64.h> +#include <linux/mod_devicetable.h> +#include <linux/module.h> +#include <linux/mutex.h> +#include <linux/pm.h> +#include <linux/regulator/consumer.h> +#include <linux/types.h> +#include <linux/unaligned.h> +#include <linux/units.h>
...
drivers/iio/flow/slf3s.c line 81
Quoted 13 lines
drivers/iio/flow/slf3s.c new file +12
-0+/** +* struct slf3s_variant - per-variant calibration constants +* @sub_type: product-info sub-type byte returned by the sensor +* @name: name reported via @iio_dev.name +* @scale_num: flow scale numerator (l/s per LSB) +* @scale_den: flow scale denominator (l/s per LSB) +*/ +struct slf3s_variant { +u8 sub_type; +const char *name; +int scale_num; +int scale_den;
struct s32_fract scale;
Quoted 1 line
+};
...
Quoted 9 lines
drivers/iio/flow/slf3s.c new file +9
-0+static const struct slf3s_variant slf3s_variants[] = { + [0 ] = { + .sub_type =0x03 , + .name ="slf3s-0600f" , + .scale_num =1 , + .scale_den =600 *MICRO , + }, + [1 ] = { + .sub_type =0x02 ,
drivers/iio/flow/slf3s.c line 102
Quoted 10 lines
drivers/iio/flow/slf3s.c new file +10
-0+ .name = "slf3s-1300f", + .scale_num = 1, + .scale_den = 30 * MICRO, + }, + [2] = { + .sub_type = 0x05, + .name = "slf3s-4000b", + .scale_num = 1, + .scale_den = 1920 * MILLI, + },
Either split this to per HW structures, or introduce a enum for having these be robust against any indices shuffling. The plain numbers are semantic-less, easy to mess up with them.
Quoted 1 line
+};
...
Quoted 6 lines
drivers/iio/flow/slf3s.c new file +6
-0+/** +* struct slf3s_data - per-device state +* @client: I2C client this instance is bound to +* @vdd: supply regulator, disabled while suspended +* @variant: pointer into @slf3s_variants for the detected device +* @medium: currently active calibration medium
drivers/iio/flow/slf3s.c line 120
Quoted 10 lines
drivers/iio/flow/slf3s.c new file +10
-0+* @lock: serialises the multi-step command/response exchanges +* @crc_table: pre-computed CRC-8 lookup table for SLF3S_CRC8_POLY +*/ +struct slf3s_data { +struct i2c_client *client; +struct regulator *vdd; +const struct slf3s_variant *variant; +enum slf3s_medium medium; +struct mutex lock;/* serialises command/response exchanges */ +u8 crc_table[CRC8_TABLE_SIZE ];
Does pahole agree with the layout?
drivers/iio/flow/slf3s.c line 123
Quoted 3 lines
drivers/iio/flow/slf3s.c new file +3
-0+}; + +static int slf3s_send_cmd(struct i2c_client *client, const u8 cmd[at_least 2])
Hmm... Do we really need to be overprotective here?
drivers/iio/flow/slf3s.c line 127
Quoted 4 lines
drivers/iio/flow/slf3s.c new file +4
-0+{ +int ret =i2c_master_send (client, cmd,2 ); + +if (ret ==2 )
In long-term this is hard to maintain. The preferred way is to decouple the assignment and the definition as the value is getting validated in the code.
drivers/iio/flow/slf3s.c line 130
Quoted 3 lines
drivers/iio/flow/slf3s.c new file +3
-0+return 0 ; + +return ret <0 ? ret : -EIO ;
The usual pattern is to check for errors first
if (ret < 0) return ret; if (ret != 2) return -EIO; return 0;
Quoted 1 line
+}
...
drivers/iio/flow/slf3s.c line 238
Quoted 11 lines
drivers/iio/flow/slf3s.c new file +11
-0+static int slf3s_read_sample (struct slf3s_data *sf,int *flow,int *temp) +{ +/* +* A measurement frame is flow, temperature and a signaling-flags +* word, each followed by a CRC byte. Only flow and temperature are +* used, so the read is stopped after their two words (6 bytes). +*/ +u8 buf[6 ]; +int ret; + + ret =i2c_master_recv (sf->client, buf,ARRAY_SIZE (buf));
sizeof() will do the job.
drivers/iio/flow/slf3s.c line 241
Quoted 3 lines
drivers/iio/flow/slf3s.c new file +3
-0+if (ret <0 ) +return ret; +if (ret !=ARRAY_SIZE (buf))
Ditto.
drivers/iio/flow/slf3s.c line 244
Quoted 3 lines
drivers/iio/flow/slf3s.c new file +3
-0+return -EIO ; + +for (unsigned int i =0 ; i <ARRAY_SIZE (buf); i +=3 ) {
Ditto.
Quoted 9 lines
drivers/iio/flow/slf3s.c new file +9
-0+if (!slf3s_crc_valid (sf, &buf[i])) +return -EIO ; + } + + *flow =sign_extend32 (get_unaligned_be16 (&buf[0 ]),15 ); + *temp =sign_extend32 (get_unaligned_be16 (&buf[3 ]),15 ); + +return 0 ; +}
...
Quoted 20 lines
drivers/iio/flow/slf3s.c new file +20
-0+static int slf3s_read_raw (struct iio_dev *indio_dev, +struct iio_chan_spec const *chan,int *val, +int *val2,long mask) +{ +struct slf3s_data *sf =iio_priv (indio_dev); +int flow, temp, ret; + +switch (mask) { +case IIO_CHAN_INFO_RAW : +scoped_guard (mutex, &sf->lock) + ret = slf3s_read_sample(sf, &flow, &temp); +if (ret) +return ret; + + *val = (chan->type ==IIO_VOLUMEFLOW ) ? flow : temp; + +return IIO_VAL_INT ; +case IIO_CHAN_INFO_SCALE : +if (chan->type ==IIO_VOLUMEFLOW ) { +/*
drivers/iio/flow/slf3s.c line 348
Quoted 10 lines
drivers/iio/flow/slf3s.c new file +10
-0+* scale_num/scale_den is the flow per LSB in l/s, but +* IIO reports volume flow in m^3/s (1 l = 1e-3 m^3). +* These values are tiny (~1.67e-12 m^3/s for the +* SLF3S-0600F), so emit a 64-bit fixed-point value with +* femto (1e-15) resolution to preserve precision. +* Converting l/s to m^3/s (/ MILLI) and scaling to femto +* (* FEMTO) leaves a net * (FEMTO / MILLI) factor. +*/ +const struct slf3s_variant *v = sf->variant; +s64 num = (s64 )v->scale_num *FEMTO /MILLI ;
Since the FEMTO and MILLI are of the same base, there might be better to use them in parentheses. Can you check if that affects code generation? (I hope compiler is smart enough to prove the above and basically simply multiply the scale_num.)
drivers/iio/flow/slf3s.c line 356
Quoted 8 lines
drivers/iio/flow/slf3s.c new file +8
-0+s64 scale =DIV_S64_ROUND_CLOSEST (num, v->scale_den); + +iio_val_s64_decompose (scale, val, val2); + +return IIO_VAL_DECIMAL64_FEMTO ; + } +/* Temperature LSB = 1/200 degC; IIO_TEMP wants milli-degC. */ + *val =1000 /200 ;
MILLIDEGREE_PER_DEGREE ?
Quoted 6 lines
drivers/iio/flow/slf3s.c new file +6
-0+ +return IIO_VAL_INT ; +default : +return -EINVAL ; + } +}
Signature · 2 lines
With Best Regards, Andy Shevchenko
Jonathan Cameron
maintainerRe: [PATCH v4 4/4] iio: flow: add Sensirion SLF3S liquid flow sensor driver
In reply to Wadim MuellerQuoted 34 lines · On Thu, 11 Jun 2026 15:27:00 +0200 Wadim Mueller <[email protected]> wrote:
Add a driver for the Sensirion SLF3S family of digital liquid-flow sensors on I2C. Currently supported variants are SLF3S-0600F, SLF3S-1300F and SLF3S-4000B; they share the same register map and differ only in flow-scale factor and calibrated measurement range. The variant (and therefore the scale) is auto-detected from the product-information register at probe time; a sensor reporting an unknown sub-type falls back to the variant named in the device tree, as promised by the fallback compatible.
Each measurement frame returns a 16-bit signed flow value, a 16-bit signed temperature reading and a status word, each protected by a CRC-8 byte. The driver exposes the flow rate as
IIO_VOLUMEFLOWand the temperature asIIO_TEMPvia the standard IIOread_raw/read_scaleinterface.The volume-flow scale is reported in m^3/s. As the per-LSB scale is on the order of 1e-12 m^3/s, it is emitted as a 64-bit fixed-point value with femto (1e-15) resolution (
IIO_VAL_DECIMAL64_FEMTO) so the small SI value keeps full precision. This relies on theIIO_VAL_DECIMAL64_FEMTOformat type added earlier in this series, which extends theIIO_VAL_DECIMAL64core formatting introduced by Rodrigo Alencar's ADF41513 series.The active calibration medium can be switched at runtime between the factory-calibrated water and isopropyl-alcohol modes via the
in_volumeflow_mediumsysfs attribute; the sensor starts in water mode after probe.The sensor has no low-power state of its own, so system suspend stops the measurement and disables the vdd supply; resume powers the sensor back up, waits out the power-up time and restarts the measurement with the previously active medium, following the scd30/scd4x precedent.
Quoted 4 lines
This driver also creates the
drivers/iio/flow/subdirectory and the corresponding Kconfig/Makefile glue.Signed-off-by Wadim Mueller <[email protected]>
A few minor things inline.
Thanks,
Jonathan
Quoted 12 lines
drivers/iio/flow/slf3s.c new file +5
-0@@ -0,0 +1,521 @@ +/** +* struct slf3s_data - per-device state +* @client: I2C client this instance is bound to +* @vdd: supply regulator, disabled while suspended +* @variant: pointer into @slf3s_variants for the detected device
drivers/iio/flow/slf3s.c line 119
Quoted 10 lines
drivers/iio/flow/slf3s.c new file +10
-0+* @medium: currently active calibration medium +* @lock: serialises the multi-step command/response exchanges +* @crc_table: pre-computed CRC-8 lookup table for SLF3S_CRC8_POLY +*/ +struct slf3s_data { +struct i2c_client *client; +struct regulator *vdd; +const struct slf3s_variant *variant; +enum slf3s_medium medium; +struct mutex lock;/* serialises command/response exchanges */
Feel free to ignore checkpatch moaning about lack of comment. There is a perfectly good one above, duplicating that info here is pointless!
Quoted 49 lines
drivers/iio/flow/slf3s.c new file +48
-0+u8 crc_table[CRC8_TABLE_SIZE ]; +}; + +/* +* Read the product-info block and pick the matching variant. The +* sub-type byte returned by the sensor is the source of truth; a +* DT-supplied compatible only seeds an initial guess and is overridden +* on mismatch (with an informational message so misconfigured device +* trees are easy to spot). +* +* Bus / CRC failures are real errors and fail probe. An unknown +* sub-type byte falls back to the variant named in the device tree / +* I2C table: the fallback compatible promises that future family +* members work as an SLF3S-1300F, so do not reject them. Without any +* match data probe fails since no meaningful scale can be published. +*/ +static int slf3s_detect_variant (struct slf3s_data *sf) +{ +struct i2c_client *client = sf->client; +u8 buf[SLF3S_PRODUCT_ID_LEN ]; +int ret; + + ret =slf3s_send_cmd (client, slf3s_cmd_prep_pid); +if (ret) +return ret; + + ret =slf3s_send_cmd (client, slf3s_cmd_read_pid); +if (ret) +return ret; + + ret =i2c_master_recv (client, buf,sizeof (buf)); +if (ret <0 ) +return ret; +if (ret !=sizeof (buf)) +return -EIO ; + +for (unsigned int i =0 ; i <SLF3S_PRODUCT_ID_LEN ; i +=3 ) { +if (!slf3s_crc_valid (sf, &buf[i])) +return -EIO ; + } + +if (buf[SLF3S_PRODUCT_FAMILY_BYTE ] !=SLF3S_PRODUCT_FAMILY_ID ) +dev_info (&client->dev, +"unexpected family byte 0x%02x (expected 0x%02x)\n" , + buf[SLF3S_PRODUCT_FAMILY_BYTE ], +SLF3S_PRODUCT_FAMILY_ID ); + +for (unsigned int i =0 ; i <ARRAY_SIZE (slf3s_variants); i++) {
drivers/iio/flow/slf3s.c line 208
Quoted 10 lines
drivers/iio/flow/slf3s.c new file +10
-0+if (buf[SLF3S_PRODUCT_SUBTYPE_BYTE ] != + slf3s_variants[i].sub_type) +continue ; + +if (sf->variant && sf->variant != &slf3s_variants[i]) +dev_info (&client->dev, +"DT compatible says %s but sensor reports %s; using %s\n" , + sf->variant->name, + slf3s_variants[i].name, + slf3s_variants[i].name);
Two params are the same which seems unlikely to be the intent.
Quoted 21 lines
drivers/iio/flow/slf3s.c new file +18
-0+ + sf->variant = &slf3s_variants[i]; + +return 0 ; + } + +if (sf->variant) { +dev_warn (&client->dev, +"unknown SLF3S sub-type 0x%02x, assuming %s\n" , + buf[SLF3S_PRODUCT_SUBTYPE_BYTE ], sf->variant->name); +return 0 ; + } + +dev_err (&client->dev,"unknown SLF3S sub-type 0x%02x\n" , + buf[SLF3S_PRODUCT_SUBTYPE_BYTE ]); + +return -ENODEV ; +}
drivers/iio/flow/slf3s.c
Quoted 10 lines
drivers/iio/flow/slf3s.c new file +10
-0+ +static DEFINE_SIMPLE_DEV_PM_OPS(slf3s_pm_ops, slf3s_suspend, slf3s_resume); + +static const struct i2c_device_id slf3s_id[] = { + { .name ="slf3s-0600f" , + .driver_data = (kernel_ulong_t)&slf3s_variants[0 ] }, + { .name ="slf3s-1300f" , + .driver_data = (kernel_ulong_t)&slf3s_variants[1 ] }, + { .name ="slf3s-4000b" , + .driver_data = (kernel_ulong_t)&slf3s_variants[2 ] },
Format as:
{
.name = "slf3s-4000b",
.driver_data = (kernel_ulong_t)&slf3s_variants[ENUM_VAL],
}, Quoted 3 lines
drivers/iio/flow/slf3s.c new file +3
-0+ { } +}; +MODULE_DEVICE_TABLE (i2c, slf3s_id);