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>
struct anatop_thermal *tz = thermal->devdata;
unsigned int tmp;
unsigned int reg;
+ unsigned int val;
if (!tz)
return -EINVAL;
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;