Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Wadim Mueller <wafgo01@gmail.com>
Cc: "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>,
	"Maxwell Doose" <m32285159@gmail.com>,
	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:53:34 +0100	[thread overview]
Message-ID: <20260601105334.3956c09d@jic23-huawei> (raw)
In-Reply-To: <20260530205435.37326-4-wafgo01@gmail.com>

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>
Hi Wadim

A few things inline.  Biggest one is don't use direct mode claims
to do serialization of things that lie entirely in your driver.
That there is a lock in that call is an implementation detail you
should not be relying on.

Jonathan

> diff --git a/drivers/iio/flow/slf3s.c b/drivers/iio/flow/slf3s.c
> new file mode 100644
> index 000000000..497a56f59
> --- /dev/null
> +++ b/drivers/iio/flow/slf3s.c

> +
> +/*
> + * 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).

Wrap to 80 chars.  Also if following suggestion to 'warn' on mismatch
make sure to update the comment as well.


> + *
> + * 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)
> +{


> +
> +static int slf3s_set_medium(struct iio_dev *indio_dev,
> +			    const struct iio_chan_spec *chan, unsigned int mode)
> +{
> +	struct slf3s_data *sf = iio_priv(indio_dev);
> +	const u8 *start_cmd;
> +	int ret;
> +
> +	if (!iio_device_claim_direct(indio_dev))

It makes no sense to claim direct mode in a driver that doesn't
do any other modes.  I think you are just using this to serialize
commands, all of which occur in direct mode.  Don't do that, use
your own local lock. 

> +		return -EBUSY;
> +
> +	ret = slf3s_send_cmd(sf->client, slf3s_cmd_stop_meas);
> +	if (ret)
> +		goto out;
> +
> +	start_cmd = (mode == SLF3S_MEDIUM_IPA) ? slf3s_cmd_start_ipa
> +					       : slf3s_cmd_start_water;
> +
> +	ret = slf3s_send_cmd(sf->client, start_cmd);
> +	if (ret)
> +		goto out;
> +
> +	fsleep(SLF3S_MEAS_START_DELAY_US);
> +	sf->medium = mode;
> +out:
> +	iio_device_release_direct(indio_dev);
> +
> +	return ret;
> +}


> +static const struct i2c_device_id slf3s_id[] = {
> +	{ .name = "slf3s-0600f",
> +	  .driver_data = (kernel_ulong_t)&slf3s_variants[0] },

	{
		.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] },
> +	{ }
> +};
> +MODULE_DEVICE_TABLE(i2c, slf3s_id);


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

Thread overview: 38+ 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-30 21:14   ` sashiko-bot
2026-05-31 23:59   ` Maxwell Doose
2026-06-01  9:38     ` Jonathan Cameron
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 [this message]

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=20260601105334.3956c09d@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