Re: [PATCH 2/2] iio: proximity: Add driver for ST STHS34PF80
From: Jonathan Cameron
Date: Sat Dec 05 2026 - 19:45:24 EST
On Thu, 3 Dec 2026 09:50:55 +0900
Donggeun Yoo <donggeunyoo.kernel@xxxxxxxxx> 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@xxxxxxxxx>
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;
> + }
> +}