RE: [PATCH 4/6] iio: adc: versal-sysmon: add over-temperature alarm events

From: Mahapatra, Amit Kumar

Date: Mon Nov 16 2026 - 00:43:05 EST


AMD General

Hello Jonathan,

> -----Original Message-----
> From: Jonathan Cameron <jic23@xxxxxxxxxx>
> Sent: Sunday, November 8, 2026 5:13 AM
> To: Mahapatra, Amit Kumar <amit.kumar-mahapatra@xxxxxxx>
> Cc: Simek, Michal <michal.simek@xxxxxxx>; Potthuri, Sai Krishna
> <sai.krishna.potthuri@xxxxxxx>; David Lechner <dlechner@xxxxxxxxxxxx>; Nuno
> Sá <nuno.sa@xxxxxxxxxx>; Andy Shevchenko <andy@xxxxxxxxxx>; Rob Herring
> <robh@xxxxxxxxxx>; Krzysztof Kozlowski <krzk+dt@xxxxxxxxxx>; Conor Dooley
> <conor+dt@xxxxxxxxxx>; linux-iio@xxxxxxxxxxxxxxx; devicetree@xxxxxxxxxxxxxxx;
> linux-arm-kernel@xxxxxxxxxxxxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx;
> amitrkcian2002@xxxxxxxxx
> Subject: Re: [PATCH 4/6] iio: adc: versal-sysmon: add over-temperature alarm
> events
>
> On Mon, 2 Nov 2026 17:51:10 +0530
> Amit Kumar Mahapatra <amit.kumar-mahapatra@xxxxxxx> wrote:
>
> > The SysMon has two independent temperature comparators. The driver
> > exposes only DEVICE_TEMP on interrupt bit 9; the over-temperature
> > alarm on bit 8, with its own threshold pair at OT_TEMP_TH_LOWER and
> > OT_TEMP_TH_UPPER, is not reported to userspace at all.
> >
> > The two are structurally identical: an upper threshold, a lower
> > threshold acting as the hysteresis floor, and a hysteresis mode bit in
> > ALARM_CONFIG, bit 0 for OT and bit 1 for DEVICE_TEMP. Per AM006 the
> > over-temperature shutdown response is a PMC function configured at
> > design time, so the kernel's role here is threshold configuration and
> > notification rather than acting on the alarm.
> >
> > IIO identifies an event by channel, type and direction, and both
> > comparators are rising thresholds on the same aggregate temperature,
> > so they cannot share a channel. Add an event-only channel labelled "ot"
> > carrying the OT thresholds.
>
> So the reason we don't normally do multiple threshold levels is they have minimal
> use for an IIO interface - as you've discovered they've reported the same on the
> events interface.
>
> If this wasn't an existing driver, the support of this is something that would strongly
> push in favour of an hwmon driver where the concept of warn and critical thresholds
> exists. That's there precisely because the critical is often wired to a pmic or similar.
>
> However, that isn't normally a problem even in an IIO driver because that threshold
> should be a design time concern with the
> limits coming from firmware. So why is this even settable by
> userspace? Feels like an interface to create the bad type of smoke.
>
On Versal the split is slightly different. Per the SysMon architecture
manual (AM006), only the response to the OT alarm is a design-time
setting, with a system reset as the default. The OT thresholds themselves
are described as user-defined, and the manual says alarm thresholds may be
modified through the register map once the design has defined the
channels.
That said, I agree Linux userspace should not be able to move the
shutdown point. What we do want is for the user to be aware of the OT
temperature: to be able to read the threshold at which the device will
shut down, and to be notified when the alarm fires. Today that
information is not visible from Linux at all.
Would a read-only version be acceptable? The driver would not touch the
OT configuration at all. Userspace could read the OT threshold and
hysteresis currently programmed, and optionally enable notification of
the alarm, while writes to the value and hysteresis would be rejected
with -EPERM. Since event attributes are always created writable, those
files would still show as 0644.

> We have a few times discussed how we would perhaps add another layer of
> indexing to events, but it is hard given the the compact event codes and I'm not
> sure I'm seeing a usecase that justifies that complexity here.

Agreed, I'm not asking for that.
>
> I also can't work out where your new channel turns up. What does the userspace
> ABI look like for this and the existing event controls?

The existing DEVICE_TEMP alarm is on channel 0:
events/in_temp0_thresh_rising_en
events/in_temp0_thresh_rising_value
events/in_temp0_thresh_rising_hysteresis
The OT channel adds:
in_tempN_label ("ot")
events/in_tempN_thresh_rising_en
events/in_tempN_thresh_rising_value
events/in_tempN_thresh_rising_hysteresis
>
> Thanks,
>
> Jonathan
>
>
> >
> > The channel is appended after the device tree derived channels because
> > io-channels phandle arguments are raw array positions, and placing it
> > earlier would silently repoint existing consumers. It is created only
> > when the device has an interrupt, as without one it would carry no
> > events.
> >
> > Signed-off-by: Amit Kumar Mahapatra <amit.kumar-mahapatra@xxxxxxx>
> >
> W
> > @@ -880,6 +932,9 @@ static int sysmon_parse_fw(struct iio_dev
> > *indio_dev, struct device *dev, int ir
> >
> > num_static = ARRAY_SIZE(temp_channels);
> > num_chan = size_add(num_temp, size_add(num_static, num_supply));
> > + /* The over-temperature channel exists only when events do */
> > + if (irq > 0)
> > + num_chan = size_add(num_chan, 1);
> > sysmon_channels = devm_kcalloc(dev, num_chan,
> sizeof(*sysmon_channels), GFP_KERNEL);
> > if (!sysmon_channels)
> > return -ENOMEM;
> > @@ -960,6 +1015,25 @@ static int sysmon_parse_fw(struct iio_dev *indio_dev,
> struct device *dev, int ir
> > };
> > }
> >
> > + /*
> > + * Over-temperature alarm. The OT comparator watches the same
> > + * aggregate temperature as channel 0 but against its own threshold
> > + * pair, and IIO cannot express two rising thresholds on one channel.
> > + * It has no reading of its own, so only event attributes and a label
> > + * are exposed. Appended last, because io-channels phandle arguments
> > + * are raw array positions and inserting it earlier would silently
> > + * repoint every existing consumer.
> > + */
> > + if (irq > 0)
> > + sysmon_channels[idx++] = (struct iio_chan_spec) {
> > + .type = IIO_TEMP,
> > + .indexed = 1,
>
> indexed without an index? I'm not even sure what this turns up as. There are
> already 4 indexed temperature channels so why isn't this just landing on the index 0
> one?
The index is assigned afterwards by the per-type numbering loop at the
end of sysmon_parse_fw(), which numbers all temperature channels in
array order. The OT channel comes after the four static and any
satellite temperature channels, so N is 4 plus the number of satellite
channels in DT (in_temp4 on a board with none).

It can't share index 0, because IIO identifies an event by channel,
type and direction, and both comparators are rising thresholds on the
same temperature, so the two alarms would be indistinguishable.


Regards,
Amit
>
> > + .address = SYSMON_OT_TH_UP,
> > + .event_spec = sysmon_temp_events,
> > + .num_event_specs = ARRAY_SIZE(sysmon_temp_events),
> > + .datasheet_name = "ot",
> > + };
> > +