]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ENGR00270045: thermal: Add timeout for temperature update
authorAnson Huang <b20788@freescale.com>
Mon, 8 Jul 2013 07:06:40 +0000 (15:06 +0800)
committerOliver Wendt <ow@karo-electronics.de>
Mon, 30 Sep 2013 12:14:11 +0000 (14:14 +0200)
Need to add timeout for temperature update, otherwise, if suspend
comes during thermal sensor measurement, its power will be turned
off, and after resume, the delay work thread will never get
finish flag and result in thread forever loop, temperature will
never get updated. And if we wait for the measurement finish before
suspend, the time is too long for suspend, as one single measurement
would take as long as 100ms which is not good for suspend, so just
add a timeout.

Signed-off-by: Anson Huang <b20788@freescale.com>
drivers/mxc/thermal/thermal.c

index 39383e29721650a4028a65f96838f9ea719bd898..cbe771d4379ceb1092dc73bf211d5e21b80bb256 100644 (file)
@@ -276,6 +276,7 @@ static int anatop_thermal_get_temp(struct thermal_zone_device *thermal,
        struct anatop_thermal *tz = thermal->devdata;
        unsigned int tmp;
        unsigned int reg;
+       unsigned int val;
 
        if (!tz)
                return -EINVAL;
@@ -310,11 +311,16 @@ static int anatop_thermal_get_temp(struct thermal_zone_device *thermal,
                anatop_base + HW_ANADIG_TEMPSENSE0_SET);
 
        tmp = 0;
+       val = jiffies;
        /* read temperature values */
        while ((__raw_readl(anatop_base + HW_ANADIG_TEMPSENSE0)
-               & BM_ANADIG_TEMPSENSE0_FINISHED) == 0)
+               & BM_ANADIG_TEMPSENSE0_FINISHED) == 0) {
+               if (time_after(jiffies, (unsigned long)(val + HZ / 2))) {
+                       pr_info("Thermal sensor timeout, retry!\n");
+                       return 0;
+               }
                msleep(10);
-
+       }
        reg = __raw_readl(anatop_base + HW_ANADIG_TEMPSENSE0);
        tmp = (reg & BM_ANADIG_TEMPSENSE0_TEMP_VALUE)
                >> BP_ANADIG_TEMPSENSE0_TEMP_VALUE;