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

Frank Li Frank.li at nxp.com
Fri Dec 12 09:25:48 PST 2025


On Fri, Dec 12, 2025 at 03:51:14PM +0800, Peng Fan (OSS) wrote:
> 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].

It should get last time sample value without check DRDYn_IF bit. it should
only be a PERIOD_CTRL[MEAS_FREQ] delay.

worst case get value at previous's PERIOD_CTRL[MEAS_FREQ] sample.

PERIOD_CTRL[MEAS_FREQ] is quite short compare to call get_temp frequency.

Do you get invalidate data?

>
> 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).

https://lore.kernel.org/imx/aAIkAF_AHta8_vuS@mai.linaro.org/

Do you answer Daniel Lezcano's question
  ""When the measured temperature can be out of limits ?"  at v6 resend
patch.

Frank
>
> 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