diff mbox series

[06/13] thermal: imx_tmu: Check the TEMP range for iMX8MM

Message ID 20200503141957.14635-7-peng.fan@nxp.com
State Accepted
Commit 951bf19dae2198c7684e4bb3f1eae10ba60d3677
Delegated to: Stefano Babic
Headers show
Series imx: tmu support and scu thermal update | expand

Commit Message

Peng Fan May 3, 2020, 2:19 p.m. UTC
On iMX8MM, the V flag in TRISTR register only reflect the state of SNSR
value, not the calibrated TEMP value. So checking this flag is not
reliable. Per IC suggestion, change to read the TEMP/AVG_TEMP directly
and check whether it in valid range 10-125C.

Signed-off-by: Ye Li <ye.li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/thermal/imx_tmu.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

Comments

Stefano Babic May 11, 2020, 10:17 a.m. UTC | #1
> On iMX8MM, the V flag in TRISTR register only reflect the state of SNSR
> value, not the calibrated TEMP value. So checking this flag is not
> reliable. Per IC suggestion, change to read the TEMP/AVG_TEMP directly
> and check whether it in valid range 10-125C.
> Signed-off-by: Ye Li <ye.li@nxp.com>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/drivers/thermal/imx_tmu.c b/drivers/thermal/imx_tmu.c
index 2a08d5085c..c577b0bd6c 100644
--- a/drivers/thermal/imx_tmu.c
+++ b/drivers/thermal/imx_tmu.c
@@ -106,16 +106,24 @@  static int read_temperature(struct udevice *dev, int *temp)
 	ulong drv_data = dev_get_driver_data(dev);
 	u32 val;
 	u32 retry = 10;
+	u32 valid = 0;
 
 	do {
 		mdelay(100);
 		retry--;
 
-		if (drv_data & FLAGS_VER2)
+		if (drv_data & FLAGS_VER2) {
 			val = readl(&pdata->regs->regs_v2.tritsr);
-		else
+			/*
+			 * Check if TEMP is in valid range, the V bit in TRITSR
+			 * only reflects the RAW uncalibrated data
+			 */
+			valid =  ((val & 0xff) < 10 || (val & 0xff) > 125) ? 0 : 1;
+		} else {
 			val = readl(&pdata->regs->regs_v1.site[pdata->id].tritsr);
-	} while (!(val & 0x80000000) && retry > 0);
+			valid = val & 0x80000000;
+		}
+	} while (!valid && retry > 0);
 
 	if (retry > 0)
 		*temp = (val & 0xff) * 1000;