[PATCH 1/3] thermal/drivers/imx91: Check status before reading data

Peng Fan (OSS) peng.fan at oss.nxp.com
Thu Dec 11 23:51:14 PST 2025


From: Peng Fan <peng.fan at nxp.com>

Per periodic mode from reference mannual:
Write 1b to CTRL1[START]. Wait until STATm[DRDYn] becomes 1.
Read DATAn[DATA_VAL]. It clears the corresponding STATm[DRDYn].
DATAn[DATA_VAL] and STATm[DRDYn_IF] keep refreshing at a periodic interval
of time, corresponding to PERIOD_CTRL[MEAS_FREQ].

Need to check STAT[DRDY] before reading the DATA register.

And check the returned temperature to make sure it fits into the supported
range (-40°C to +125°C).

Signed-off-by: Peng Fan <peng.fan at nxp.com>
---
 drivers/thermal/imx91_thermal.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/thermal/imx91_thermal.c b/drivers/thermal/imx91_thermal.c
index 9b20be03d6dec18553967548d0ca31d1c1fb387c..77e8e6a921c6af308b830c36721293c007256ca6 100644
--- a/drivers/thermal/imx91_thermal.c
+++ b/drivers/thermal/imx91_thermal.c
@@ -108,10 +108,20 @@ static int imx91_tmu_get_temp(struct thermal_zone_device *tz, int *temp)
 {
 	struct imx91_tmu *tmu = thermal_zone_device_priv(tz);
 	s16 data;
+	int ret;
+	u32 val;
+
+	ret = readl_relaxed_poll_timeout(tmu->base + IMX91_TMU_STAT0, val,
+					 val & IMX91_TMU_STAT0_DRDY0_IF_MASK, 1000,
+					 40000);
+	if (ret)
+		return -EAGAIN;
 
 	/* DATA0 is 16bit signed number */
 	data = readw_relaxed(tmu->base + IMX91_TMU_DATA0);
 	*temp = imx91_tmu_to_mcelsius(data);
+	if (*temp < IMX91_TMU_TEMP_LOW_LIMIT || *temp > IMX91_TMU_TEMP_HIGH_LIMIT)
+		return -EAGAIN;
 
 	return 0;
 }

-- 
2.37.1




More information about the linux-arm-kernel mailing list