From: Marcelo Schmitt <marcelo.schmitt1@gmail.com>
To: Thomas Bonnefille <thomas.bonnefille@bootlin.com>
Cc: "Puranjay Mohan" <puranjay@kernel.org>,
"Jonathan Cameron" <jic23@kernel.org>,
"David Lechner" <dlechner@baylibre.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Andy Shevchenko" <andy@kernel.org>,
"Rob Herring" <robh@kernel.org>,
"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
"Miquèl Raynal" <miquel.raynal@bootlin.com>,
linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/2] iio: temperature: tmp117: add support for HIGH and LOW alerts
Date: Sun, 11 Oct 2026 10:57:34 -0300 [thread overview]
Message-ID: <asuVzmd1L1hn_4ux@debian-BULLSEYE-live-builder-AMD64> (raw)
In-Reply-To: <20261005-add-tmp117-notif-v1-2-c6cef6fad64c@bootlin.com>
On 10/05, Thomas Bonnefille wrote:
> The TMP117/116/119 chips allow the user to set an alert if the
> temperature reaches a HIGH or LOW limit.
>
> Add support for setting the high and low alert limits.
> An IIO event is generated when the temperature crosses either limit
> thanks to an interrupt on the Alert pin.
>
> Signed-off-by: Thomas Bonnefille <thomas.bonnefille@bootlin.com>
> ---
...
> +static int tmp117_read_thresh(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + enum iio_event_type type,
> + enum iio_event_direction dir,
> + enum iio_event_info info,
> + int *val, int *val2)
> +{
> + struct tmp117_data *data = iio_priv(indio_dev);
> + s32 ret;
> + u8 reg;
> +
> + switch (dir) {
> + case IIO_EV_DIR_RISING:
> + reg = TMP117_REG_HIGH_LIM;
> + break;
> + case IIO_EV_DIR_FALLING:
> + reg = TMP117_REG_LOW_LIM;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + if (info != IIO_EV_INFO_VALUE || type != IIO_EV_TYPE_THRESH)
> + return -EINVAL;
> + ret = i2c_smbus_read_word_swapped(data->client, reg);
> + if (ret < 0)
> + return ret;
> +
> + /*
> + * Report the threshold in millidegrees Celsius as an exact fraction:
> + * value = raw * TMP117_LIMIT_LSB_NUM / TMP117_LIMIT_LSB_DEN.
> + */
The IIO temperature channel provides single-read data in (raw) device units
(i.e. not scaled to mili degrees Celsius). Now, in contrast with the single-read
interface, the event configuration being proposed reads/writes data in milli
degrees Celsius. And, since the event ABI doesn't yet provide clear indication
about IIO event data unit types, users might get confused when using the
different interfaces.
There are two main options for avoiding/mitigating the potential interface mismatch:
(1) provide/get raw device units in tmp117_read/write_thresh().
(2) add IIO_CHAN_INFO_PROCESSED to the IIO channel mask and implement the
handling for the channel _input interface to provide single-read data in
milli degrees Celsius units. Though, this option will also need an updated
IIO event interface. Probably something like [1] or [2]. I'll respin on that
next week. The event specs would be updated to something like
+static const struct iio_event_spec tmp11x_obj_event[] = {
+ {
+ .type = IIO_EV_TYPE_THRESH,
+ .dir = IIO_EV_DIR_RISING,
+ .unit = IIO_EV_UNIT_PROCESSED,
+ .mask_separate = BIT(IIO_EV_INFO_VALUE),
+ },
+ {
+ .type = IIO_EV_TYPE_THRESH,
+ .dir = IIO_EV_DIR_FALLING,
+ .unit = IIO_EV_UNIT_PROCESSED,
+ .mask_separate = BIT(IIO_EV_INFO_VALUE),
+ },
+};
+
[1]: https://lore.kernel.org/linux-iio/cover.1768759292.git.marcelo.schmitt1@gmail.com/
[2]: https://lore.kernel.org/linux-iio/e359fa003ebc61c8b0e37ba9810a04c70e5a300e.1791437050.git.marcelo.schmitt@analog.com/
With best regards,
Marcelo
> + *val = sign_extend32(ret, 15) * TMP117_LIMIT_LSB_NUM;
> + *val2 = TMP117_LIMIT_LSB_DEN;
> +
> + return IIO_VAL_FRACTIONAL;
> +}
> +
> +static int tmp117_write_thresh(struct iio_dev *indio_dev,
> + const struct iio_chan_spec *chan,
> + enum iio_event_type type,
> + enum iio_event_direction dir,
> + enum iio_event_info info,
> + int val, int val2)
> +{
> + struct tmp117_data *data = iio_priv(indio_dev);
> + s64 tmp;
> + u8 reg;
> +
> + switch (dir) {
> + case IIO_EV_DIR_RISING:
> + reg = TMP117_REG_HIGH_LIM;
> + break;
> + case IIO_EV_DIR_FALLING:
> + reg = TMP117_REG_LOW_LIM;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + if (info != IIO_EV_INFO_VALUE || type != IIO_EV_TYPE_THRESH)
> + return -EINVAL;
> +
> + /*
> + * The threshold is passed in millidegrees Celsius as
> + * value = val + val2 / 1000000 (val2 holds the fractional part, with
> + * the sign taken from val). Convert it back with the same LSB ratio:
> + * raw = value / (TMP117_LIMIT_LSB_NUM / TMP117_LIMIT_LSB_DEN).
> + */
> + tmp = (val < 0) ? (s64)val * 1000000 - val2
> + : (s64)val * 1000000 + val2;
> + tmp = DIV_ROUND_CLOSEST(tmp * TMP117_LIMIT_LSB_DEN,
> + (s64)TMP117_LIMIT_LSB_NUM * 1000000);
> + tmp = clamp_t(s64, tmp, S16_MIN, S16_MAX);
> +
> + return i2c_smbus_write_word_swapped(data->client,
> + reg, tmp);
> +}
> +
next prev parent reply other threads:[~2026-10-11 13:57 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-05 14:44 [PATCH 0/2] Add interrupt support on TMP117 Thomas Bonnefille
2026-10-05 14:44 ` [PATCH 1/2] dt-bindings: iio: ti,tmp117: describe interrupts for TMP117 Thomas Bonnefille
2026-10-06 14:02 ` Miquel Raynal
2026-10-07 13:05 ` Conor Dooley
2026-10-05 14:44 ` [PATCH 2/2] iio: temperature: tmp117: add support for HIGH and LOW alerts Thomas Bonnefille
2026-10-06 4:47 ` kernel test robot
2026-10-06 6:02 ` kernel test robot
2026-10-06 14:09 ` Miquel Raynal
2026-10-11 13:57 ` Marcelo Schmitt [this message]
2026-10-18 22:38 ` 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=asuVzmd1L1hn_4ux@debian-BULLSEYE-live-builder-AMD64 \
--to=marcelo.schmitt1@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=miquel.raynal@bootlin.com \
--cc=nuno.sa@analog.com \
--cc=puranjay@kernel.org \
--cc=robh@kernel.org \
--cc=thomas.bonnefille@bootlin.com \
--cc=thomas.petazzoni@bootlin.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®