From: Jonathan Cameron <jic23@kernel.org>
To: Donggeun Yoo <donggeunyoo.kernel@gmail.com>
Cc: "Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@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-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: proximity: Add driver for ST STHS34PF80
Date: Sun, 6 Dec 2026 00:45:10 +0000 [thread overview]
Message-ID: <20261206004510.27b1157b@jic23-hlaptop> (raw)
In-Reply-To: <20261203005055.26666-3-donggeunyoo.kernel@gmail.com>
On Thu, 3 Dec 2026 09:50:55 +0900
Donggeun Yoo <donggeunyoo.kernel@gmail.com> wrote:
> Add a driver for the STMicroelectronics STHS34PF80, an infrared sensor
> for presence and motion detection, connected over I2C.
>
> Each read triggers a one-shot measurement. The driver exposes the
> ambient temperature and the object temperature. The object temperature
> is not linear in the raw readings. The driver computes it from the raw
> object and ambient readings and the sensitivity stored in the device,
> as described in AN5867, and reports it as a processed value.
>
> Presence and motion detection, the interrupt, buffered capture and SPI
> are not supported yet.
>
> Datasheet: https://www.st.com/resource/en/datasheet/sths34pf80.pdf
> Assisted-by: LLM
> Signed-off-by: Donggeun Yoo <donggeunyoo.kernel@gmail.com>
Very nice. Just a couple of small comments inline.
Thanks,
Jonathan
> diff --git a/drivers/iio/proximity/sths34pf80.c b/drivers/iio/proximity/sths34pf80.c
> new file mode 100644
> index 0000000000000..a32e0c920a0c9
> --- /dev/null
> +++ b/drivers/iio/proximity/sths34pf80.c
> +
> +static const struct iio_chan_spec sths34pf80_channels[] = {
> + {
> + .type = IIO_TEMP,
> + .modified = 1,
> + .channel2 = IIO_MOD_TEMP_AMBIENT,
> + .address = STHS34PF80_REG_TAMBIENT_L,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |
> + BIT(IIO_CHAN_INFO_SCALE),
> + },
> + {
> + .type = IIO_TEMP,
> + .modified = 1,
> + .channel2 = IIO_MOD_TEMP_OBJECT,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> + },
> +};
> +
> +static int sths34pf80_read_s16(struct sths34pf80_data *data, unsigned int reg,
> + int *val)
> +{
> + struct regmap *map = data->regmap;
> + __le16 raw;
> + int ret;
> +
> + ret = regmap_bulk_read(map, reg, &raw, sizeof(raw));
> + if (ret)
> + return ret;
> +
> + *val = (s16)le16_to_cpu(raw);
As below. Slight preference for an explicit sign_extend32();
> +
> + return 0;
> +}
> +
> +static int sths34pf80_read_object(struct sths34pf80_data *data, int *val)
> +{
> + struct regmap *map = data->regmap;
> + int tobject, tambient;
> + /* TOBJECT and TAMBIENT are adjacent */
> + __le16 raw[2];
> + int ret;
> +
> + guard(mutex)(&data->lock);
> +
> + ret = sths34pf80_one_shot(data);
> + if (ret)
> + return ret;
> +
> + ret = regmap_bulk_read(map, STHS34PF80_REG_TOBJECT_L, raw, sizeof(raw));
> + if (ret)
> + return ret;
> +
> + tobject = (s16)le16_to_cpu(raw[0]);
> + tambient = (s16)le16_to_cpu(raw[1]);
For these, generally prefer the documentation advantage of
tobject = sign_extend32(le16_to_cpu(raw[0]), 15);
over casting to s16 to force the sign extend.
> +
> + return sths34pf80_calc_object_temp(data, tobject, tambient, val);
> +}
> +
> +static int sths34pf80_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int *val, int *val2, long mask)
> +{
> + struct sths34pf80_data *data = iio_priv(indio_dev);
> + int ret;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_RAW: {
> + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> + if (IIO_DEV_ACQUIRE_FAILED(claim))
Claiming direct mode doesn't make sense until you add support
for buffered mode.
If this is being used to serialize some of the accesses, that should
be done with a separate driver local lock instead. A driver should
not assume any particular implementation of core locking.
> + return -EBUSY;
> +
> + ret = sths34pf80_read_channel(data, chan->address, val);
> + if (ret)
> + return ret;
> +
> + return IIO_VAL_INT;
> + }
> + case IIO_CHAN_INFO_PROCESSED: {
> + IIO_DEV_ACQUIRE_DIRECT_MODE(indio_dev, claim);
> + if (IIO_DEV_ACQUIRE_FAILED(claim))
> + return -EBUSY;
> +
> + ret = sths34pf80_read_object(data, val);
> + if (ret)
> + return ret;
> +
> + return IIO_VAL_INT;
> + }
> + case IIO_CHAN_INFO_SCALE:
> + *val = MILLIDEGREE_PER_DEGREE / STHS34PF80_TAMBIENT_LSB_PER_DEG;
> + return IIO_VAL_INT;
> + default:
> + return -EINVAL;
> + }
> +}
next prev parent reply other threads:[~2026-12-06 0:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-03 0:50 [PATCH 0/2] iio: proximity: Add ST STHS34PF80 driver Donggeun Yoo
2026-12-03 0:50 ` [PATCH 1/2] dt-bindings: iio: proximity: Add ST STHS34PF80 infrared sensor Donggeun Yoo
2026-12-06 0:38 ` Jonathan Cameron
2026-12-03 0:50 ` [PATCH 2/2] iio: proximity: Add driver for ST STHS34PF80 Donggeun Yoo
2026-12-06 0:45 ` Jonathan Cameron [this message]
2026-12-03 11:52 ` [PATCH 0/2] iio: proximity: Add ST STHS34PF80 driver Andy Shevchenko
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=20261206004510.27b1157b@jic23-hlaptop \
--to=jic23@kernel.org \
--cc=andy@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=donggeunyoo.kernel@gmail.com \
--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 \
/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®