drivers/hwmon/lm75.c | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+)
NXP P3T1750/P3T1755 does not provide readable alarm/status bits. To support
the standard tempX_alarm attribute, implement the comparator mode threshold
checks in the software using THIGH and TLOW registers.
Signed-off-by: Lakshay Piplani <lakshay.piplani@nxp.com>
---
drivers/hwmon/lm75.c | 46 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 3c23b6e8e1bf..b25c19de05d4 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -116,6 +116,7 @@ struct lm75_data {
const struct lm75_params *params;
u8 reg_buf[1];
u8 val_buf[3];
+ bool alarm_state;
};
/*-----------------------------------------------------------------------*/
@@ -229,6 +230,7 @@ static const struct lm75_params device_params[] = {
.default_sample_time = 55,
.num_sample_times = 4,
.sample_times = (unsigned int []){ 28, 55, 110, 220 },
+ .alarm = true,
},
[p3t1755] = {
.clr_mask = 1 << 1 | 1 << 7, /* disable SMBAlert and one-shot */
@@ -236,6 +238,7 @@ static const struct lm75_params device_params[] = {
.default_sample_time = 55,
.num_sample_times = 4,
.sample_times = (unsigned int []){ 28, 55, 110, 220 },
+ .alarm = true,
},
[pct2075] = {
.default_resolution = 11,
@@ -407,6 +410,49 @@ static int lm75_read(struct device *dev, enum hwmon_sensor_types type,
case tmp112:
*val = (regval >> 13) & 0x1;
break;
+
+ case p3t1750:
+ case p3t1755: {
+ unsigned int temp_raw, thigh_raw, tlow_raw;
+ s16 temp, thigh, tlow;
+
+ err = regmap_read(data->regmap, LM75_REG_TEMP, &temp_raw);
+ if (err)
+ return err;
+
+ err = regmap_read(data->regmap, LM75_REG_MAX, &thigh_raw);
+ if (err)
+ return err;
+
+ err = regmap_read(data->regmap, LM75_REG_HYST, &tlow_raw);
+ if (err)
+ return err;
+
+ temp = (s16)temp_raw;
+ thigh = (s16)thigh_raw;
+ tlow = (s16)tlow_raw;
+
+ /*
+ * Implement software-based alarm logic for P3T1750/P3T1755.
+ *
+ * These devices do not provide readable alarm bits in hardware.
+ * To comply with hwmon ABI and to support standard 'tempX_alarm'
+ * attribute, check the current temperature against THIGH and TLOW
+ * thresholds:
+ *
+ * - If temp >= thigh, set alarm = 1 (over-temperature condition).
+ * - If temp < tlow, clear alarm = 0 (clear alarm).
+ * - If temp is between tlow and thigh, keep previous alarm state
+ * to provide hysteresis behavior similar to hardware.
+ */
+ if (!data->alarm_state && temp >= thigh)
+ data->alarm_state = true;
+ else if (data->alarm_state && temp < tlow)
+ data->alarm_state = false;
+
+ *val = data->alarm_state;
+ break;
+ }
default:
return -EINVAL;
}
--
2.25.1
On Thu, Nov 13, 2025 at 04:50:11PM +0530, Lakshay Piplani wrote: > NXP P3T1750/P3T1755 does not provide readable alarm/status bits. To support > the standard tempX_alarm attribute, implement the comparator mode threshold > checks in the software using THIGH and TLOW registers. > The ABI says "The driver should just reflect the hardware implementation", which really means that it should not try to implement software based alarm attributes. This is in line with all other drivers: We don't try to simulate alarms if not provided by hardware. The key point here is that the absence of alarm attributes means that userspace has to poll temperature values to determine if there is an alarm or not. This gets lost here: As long as the alarm file is not read, the driver won't report an alarm. Userspace polling on the alarm attribute (using the poll or epoll system call, or udev events) won't get notified and miss that an alarm was triggered. This would be much worse than the current situation. Granted, many drivers don't implement interrupts and would also not get notified, but that is a driver limitation and not an argument for implementing software based alarms. Guenter
© 2016 - 2026 Red Hat, Inc.