MLK-20966 TMU: Fix for temperature out of range
authorYe Li <ye.li@nxp.com>
Fri, 22 Feb 2019 05:12:57 +0000 (21:12 -0800)
committerYe Li <ye.li@nxp.com>
Fri, 24 May 2019 09:31:10 +0000 (02:31 -0700)
When the temperature is out of sensor's range, the Valid bit won't be
set in TRITSR register. So the polling loop won't go out.

Change the codes to retry 10 times with 100ms interval for the Valid bit.
If the timeout, we give a warning for the invalid data.

Signed-off-by: Ye Li <ye.li@nxp.com>
Reviewed-by: Bai Ping <ping.bai@nxp.com>
(cherry picked from commit 7ea2168e06d4f77a872f51a167ee1ed6bf2b0632)

drivers/thermal/nxp_tmu.c

index b4004a2..f310b22 100644 (file)
@@ -106,17 +106,24 @@ static int read_temperature(struct udevice *dev, int *temp)
        struct nxp_tmu_plat *pdata = dev_get_platdata(dev);
        ulong drv_data = dev_get_driver_data(dev);
        u32 val;
+       u32 retry = 10;
 
        do {
+               mdelay(100);
+               retry--;
+
                if (drv_data & FLAGS_VER2)
                        val = readl(&pdata->regs->regs_v2.tritsr);
                else
                        val = readl(&pdata->regs->regs_v1.site[pdata->id].tritsr);
-       } while (!(val & 0x80000000));
-
-       *temp = (val & 0xff) * 1000;
+       } while (!(val & 0x80000000) && retry > 0);
 
-       return 0;
+       if (retry > 0) {
+               *temp = (val & 0xff) * 1000;
+               return 0;
+       } else {
+               return -EINVAL;
+       }
 }
 
 int nxp_tmu_get_temp(struct udevice *dev, int *temp)
@@ -126,8 +133,10 @@ int nxp_tmu_get_temp(struct udevice *dev, int *temp)
        int ret;
 
        ret = read_temperature(dev, &cpu_tmp);
-       if (ret)
+       if (ret) {
+               printf("invalid data\n");
                return ret;
+       }
 
        while (cpu_tmp >= pdata->alert) {
                printf("CPU Temperature (%dC) has beyond alert (%dC), close to critical (%dC)",
@@ -135,8 +144,10 @@ int nxp_tmu_get_temp(struct udevice *dev, int *temp)
                puts(" waiting...\n");
                mdelay(pdata->polling_delay);
                ret = read_temperature(dev, &cpu_tmp);
-               if (ret)
+               if (ret) {
+                       printf("invalid data\n");
                        return ret;
+               }
        }
 
        *temp = cpu_tmp / 1000;