mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Maxwell Doose <m32285159@gmail.com>
Cc: "Wadim Mueller" <wafgo01@gmail.com>,
	"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: Mon, 1 Jun 2026 10:38:18 +0100	[thread overview]
Message-ID: <20260601103818.69139362@jic23-huawei> (raw)
In-Reply-To: <20260531185931.1bcda47c@linuxescape>

On Sun, 31 May 2026 18:59:31 -0500
Maxwell Doose <m32285159@gmail.com> wrote:

> 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.

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!)

> 


  reply	other threads:[~2026-06-01  9:38 UTC|newest]

Thread overview: 37+ 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-06-01  9:42     ` Jonathan Cameron
2026-06-03 14:08       ` Wadim Mueller
2026-06-04  8:44         ` Jonathan Cameron
2026-06-07 10:45           ` Wadim Mueller
2026-06-08  8:53             ` Rodrigo Alencar
2026-06-08 12:24               ` Wadim Mueller
2026-06-09  8:32                 ` Rodrigo Alencar
2026-06-03 14:17   ` Andy Shevchenko
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-06-03 14:08     ` Wadim Mueller
2026-06-03 14:43       ` Marcelo Schmitt
2026-06-03 14:48         ` Krzysztof Kozlowski
2026-06-01  9:44   ` Jonathan Cameron
2026-06-01 11:53   ` Krzysztof Kozlowski
2026-06-01 14:09     ` Jonathan Cameron
2026-06-03 14:08       ` Wadim Mueller
2026-06-03 14:29       ` Krzysztof Kozlowski
2026-06-04  9:03         ` Jonathan Cameron
2026-06-04 11:22           ` Krzysztof Kozlowski
2026-06-05 12:21             ` Jonathan Cameron
2026-06-07  8:30               ` Krzysztof Kozlowski
2026-06-11 10:35                 ` Wadim Mueller
2026-06-11 10:42                   ` Krzysztof Kozlowski
2026-06-12 18:05                 ` Jonathan Cameron
2026-06-12 22:00                   ` Conor Dooley
2026-05-30 20:54 ` [PATCH v3 3/3] iio: flow: add Sensirion SLF3S liquid flow sensor driver Wadim Mueller
2026-05-31 23:59   ` Maxwell Doose
2026-06-01  9:38     ` Jonathan Cameron [this message]
2026-06-01  0:45   ` Marcelo Schmitt
2026-06-01  9:41     ` Jonathan Cameron
2026-06-03 14:08     ` Wadim Mueller
2026-06-01  9:53   ` Jonathan Cameron

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=20260601103818.69139362@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=m32285159@gmail.com \
    --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

all inboxes | Powered by JetHome®