Re: [PATCH v3 3/3] iio: flow: add Sensirion SLF3S liquid flow sensor driver
From: Jonathan Cameron
Date: Mon Jun 01 2026 - 05:48:03 EST
On Sun, 31 May 2026 18:59:31 -0500
Maxwell Doose <m32285159@xxxxxxxxx> wrote:
> Hi Wadim,
>
> On Sat, 30 May 2026 22:54:32 +0200
> Wadim Mueller <wafgo01@xxxxxxxxx> 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.
> >
> > 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 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.
> >
> > This driver also creates the drivers/iio/flow/ subdirectory and
> > the corresponding Kconfig/Makefile glue.
> >
> > Signed-off-by: Wadim Mueller <wafgo01@xxxxxxxxx>
> > ---
> > drivers/iio/Kconfig | 1 +
> > drivers/iio/Makefile | 1 +
> > drivers/iio/flow/Kconfig | 27 +++
> > drivers/iio/flow/Makefile | 7 +
> > drivers/iio/flow/slf3s.c | 406 ++++++++++++++++++++++++++++++++++++++
> > 5 files changed, 442 insertions(+)
> > create mode 100644 drivers/iio/flow/Kconfig
> > create mode 100644 drivers/iio/flow/Makefile
> > create mode 100644 drivers/iio/flow/slf3s.c
> >
>
> Nice code. Just have a couple of questions (+sashiko has some concerns
> as well).
>
> [snip]
> > +/*
> > + * 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 fails probe too: we cannot publish a meaningful scale
> > + * without a matching entry in slf3s_variants[].
> > + */
> > +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;
>
> Here sashiko said:
>
> "If the system goes through a warm reboot or kexec, won't the sensor
> still be running in continuous measurement mode since there is no
> .shutdown callback? If the sensor is actively measuring, will it NACK
> the 'read product ID' command sent here and cause the probe to
> unconditionally fail? Should a stop measurement command be sent before
> trying to read the product ID?"
>
> Was looking and didn't find a shutdown callback, so you'll probably
> want to add that.
It's a fair question from sashiko as seems a stop command or reset is
needed to break out of that mode and let other commands function.
There is the option of a soft reset which might make sense to implement
in probe() but it's an odd one as it's a general call (so may affect
other devices on the same bus).
Given we can never know what silly mode some other software has left
the device in, we'd normally reset (but here probably can't due
to the reset addressing all devices on the bus), we can however
just issue a stop command in probe() I think I'd prefer that to
shutdown() Note I couldn't find a statement that says stop can
be issued when not running continuous mode. So test that and see.
Hopefully it's a no-op!
>
> > + 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);
>
> This feels like something that could be dev_warn() to me (if it's
> unexpected then it means it probably shouldn't happen!)
This is about fallback compatibles - it is absolutely expected to
happen in the future (assuming this company doesn't feel the need
to keep inventing new control schemes for every device released!)
dev_info() is fine.
>
> > +
> > + for (unsigned int i = 0; i < ARRAY_SIZE(slf3s_variants); i++) {
> > + 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);
>
> Same here, if the DT says it should be x and we get y, then that also
> feels like something that shouldn't have happened.
Agree on this one.
>
> > +
> > + sf->variant = &slf3s_variants[i];
> > +
> > + return 0;
> > + }
> > +
> > + dev_err(&client->dev, "unknown SLF3S sub-type 0x%02x\n",
> > + buf[SLF3S_PRODUCT_SUBTYPE_BYTE]);
> > +
> > + return -ENODEV;
> > +}
>
> [snip]
>
> > +
> > +static struct i2c_driver slf3s_driver = {
> > + .driver = {
> > + .name = "slf3s",
> > + .of_match_table = slf3s_of_match,
> > + },
> > + .probe = slf3s_probe,
> > + .id_table = slf3s_id,
> > +};
>
> Sashiko said:
>
> "Since the driver lacks power management operations, what happens when
> the system suspends and resumes?
> If power is cut to the sensor during suspend, won't it reset to the IDLE
> state and cause subsequent IIO reads to fail because the driver never
> re-issues the start command? Or if power isn't cut, will leaving it
> actively measuring waste power?"
>
> Which it has some good points, you'll just have to issue a start
> command once the system is back from suspend.
For IIO drivers, we normally consider power management a 'feature'
that can be added later. Sure kooky things can happen if it's not
there and the 'feature' is used. That might mean you have to rebind
the driver. If a platform cuts the power to a device with a driver
that doesn't know it can happen, then it is broken at a higher level.
>
> I'd say it's very close, but please address those comments from
> sashiko (also you don't have to take my advice on the dev_warn()
> stuff, I'll be honest I haven't written a driver from scratch yet!)
>