From: Maxwell Doose <m32285159@gmail.com>
To: Wadim Mueller <wafgo01@gmail.com>
Cc: "Jonathan Cameron" <jic23@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org
Subject: Re: [PATCH v3 3/3] iio: flow: add Sensirion SLF3S liquid flow sensor driver
Date: Sun, 31 May 2026 18:59:31 -0500 [thread overview]
Message-ID: <20260531185931.1bcda47c@linuxescape> (raw)
In-Reply-To: <20260530205435.37326-4-wafgo01@gmail.com>
Hi Wadim,
On Sat, 30 May 2026 22:54:32 +0200
Wadim Mueller <wafgo01@gmail.com> 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@gmail.com>
> ---
> 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.
> + 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!)
> +
> + 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.
> +
> + 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.
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!)
--
best regards,
max
next prev parent reply other threads:[~2026-05-31 23:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-30 20:54 [PATCH v3 0/3] iio: flow: Sensirion SLF3S liquid flow sensor Wadim Mueller
2026-05-30 20:54 ` [PATCH v3 1/3] iio: types: add IIO_VOLUMEFLOW channel type Wadim Mueller
2026-05-31 18:09 ` Marcelo Schmitt
2026-05-30 20:54 ` [PATCH v3 2/3] dt-bindings: iio: flow: add Sensirion SLF3S liquid flow sensor Wadim Mueller
2026-05-31 17:45 ` Marcelo Schmitt
2026-05-31 17:50 ` Marcelo Schmitt
2026-05-30 20:54 ` [PATCH v3 3/3] iio: flow: add Sensirion SLF3S liquid flow sensor driver Wadim Mueller
2026-05-30 21:14 ` sashiko-bot
2026-05-31 23:59 ` Maxwell Doose [this message]
2026-06-01 0:45 ` Marcelo Schmitt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260531185931.1bcda47c@linuxescape \
--to=m32285159@gmail.com \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=jic23@kernel.org \
--cc=krzk+dt@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nuno.sa@analog.com \
--cc=robh@kernel.org \
--cc=wafgo01@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox