static int anatop_thermal_get_temp(struct thermal_zone_device *thermal, long *temp) { struct anatop_thermal *tz = thermal->devdata; unsigned int tmp; unsigned int reg; unsigned int val; if (!tz) return -EINVAL; if (!ratio || suspend_flag) { *temp = KELVIN_TO_CEL(TEMP_ACTIVE, MKELVIN_OFFSET); return 0; } tz->last_temperature = tz->temperature; if ((__raw_readl(anatop_base + HW_ANADIG_TEMPSENSE0) & BM_ANADIG_TEMPSENSE0_POWER_DOWN) != 0) { /* need to keep sensor power up as we enable alarm function */ __raw_writel(BM_ANADIG_TEMPSENSE0_POWER_DOWN, anatop_base + HW_ANADIG_TEMPSENSE0_CLR); __raw_writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, anatop_base + HW_ANADIG_ANA_MISC0_SET); /* write measure freq */ reg = __raw_readl(anatop_base + HW_ANADIG_TEMPSENSE1); reg &= ~BM_ANADIG_TEMPSENSE1_MEASURE_FREQ; reg |= MEASURE_FREQ; __raw_writel(reg, anatop_base + HW_ANADIG_TEMPSENSE1); } __raw_writel(BM_ANADIG_TEMPSENSE0_MEASURE_TEMP, anatop_base + HW_ANADIG_TEMPSENSE0_CLR); __raw_writel(BM_ANADIG_TEMPSENSE0_FINISHED, anatop_base + HW_ANADIG_TEMPSENSE0_CLR); __raw_writel(BM_ANADIG_TEMPSENSE0_MEASURE_TEMP, 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) { 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; __raw_writel(BM_ANADIG_TEMPSENSE0_FINISHED, anatop_base + HW_ANADIG_TEMPSENSE0_CLR); if (ANATOP_DEBUG) anatop_dump_temperature_register(); /* only the temp between -40C and 125C is valid, this is for save */ if (tmp <= raw_n40c && tmp >= raw_125c) tz->temperature = REG_VALUE_TO_MCEL(ratio, tmp); else { printk(KERN_WARNING "Invalid temperature, force it to 25C\n"); tz->temperature = 25000; } if (debug_mask & DEBUG_VERBOSE) pr_info("Cooling device Temperature is %lu C\n", tz->temperature); *temp = (cooling_device_disable && tz->temperature >= KELVIN_TO_CEL(TEMP_CRITICAL, MKELVIN_OFFSET)) ? KELVIN_TO_CEL(TEMP_CRITICAL - 1, MKELVIN_OFFSET) : tz->temperature; /* Set alarm threshold if necessary */ if ((__raw_readl(anatop_base + HW_ANADIG_TEMPSENSE0) & BM_ANADIG_TEMPSENSE0_ALARM_VALUE) == 0) anatop_update_alarm(raw_critical); return 0; }
static int anatop_thermal_get_temp(struct thermal_zone_device *thermal, long *temp) { struct anatop_thermal *tz = thermal->devdata; unsigned int tmp; unsigned int reg; unsigned int i; if (!tz) return -EINVAL; #ifdef CONFIG_FSL_OTP if (!ratio) { anatop_thermal_get_calibration_data(&tmp); *temp = KELVIN_TO_CEL(TEMP_ACTIVE, KELVIN_OFFSET); return 0; } #else if (!cooling_device_disable) pr_info("%s: can't get calibration data, disable cooling!!!\n", __func__); cooling_device_disable = true; ratio = DEFAULT_RATIO; #endif tz->last_temperature = tz->temperature; /* now we only using single measure, every time we measure the temperature, we will power on/down the anadig module*/ __raw_writel(BM_ANADIG_TEMPSENSE0_POWER_DOWN, anatop_base + HW_ANADIG_TEMPSENSE0_CLR); __raw_writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, anatop_base + HW_ANADIG_ANA_MISC0_SET); /* write measure freq */ reg = __raw_readl(anatop_base + HW_ANADIG_TEMPSENSE1); reg &= ~BM_ANADIG_TEMPSENSE1_MEASURE_FREQ; reg |= MEASURE_FREQ; __raw_writel(reg, anatop_base + HW_ANADIG_TEMPSENSE1); __raw_writel(BM_ANADIG_TEMPSENSE0_MEASURE_TEMP, anatop_base + HW_ANADIG_TEMPSENSE0_CLR); __raw_writel(BM_ANADIG_TEMPSENSE0_FINISHED, anatop_base + HW_ANADIG_TEMPSENSE0_CLR); __raw_writel(BM_ANADIG_TEMPSENSE0_MEASURE_TEMP, anatop_base + HW_ANADIG_TEMPSENSE0_SET); tmp = 0; /* read five times of temperature values to get average*/ for (i = 0; i < 5; i++) { while ((__raw_readl(anatop_base + HW_ANADIG_TEMPSENSE0) & BM_ANADIG_TEMPSENSE0_FINISHED) == 0) msleep(10); reg = __raw_readl(anatop_base + HW_ANADIG_TEMPSENSE0); tmp += (reg & BM_ANADIG_TEMPSENSE0_TEMP_VALUE) >> BP_ANADIG_TEMPSENSE0_TEMP_VALUE; __raw_writel(BM_ANADIG_TEMPSENSE0_FINISHED, anatop_base + HW_ANADIG_TEMPSENSE0_CLR); if (ANATOP_DEBUG) anatop_dump_temperature_register(); } tmp = tmp / 5; if (tmp <= raw_n25c) tz->temperature = REG_VALUE_TO_CEL(ratio, tmp); else tz->temperature = -25; if (debug_mask & DEBUG_VERBOSE) pr_info("Cooling device Temperature is %lu C\n", tz->temperature); /* power down anatop thermal sensor */ __raw_writel(BM_ANADIG_TEMPSENSE0_POWER_DOWN, anatop_base + HW_ANADIG_TEMPSENSE0_SET); __raw_writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, anatop_base + HW_ANADIG_ANA_MISC0_CLR); *temp = (cooling_device_disable && tz->temperature >= KELVIN_TO_CEL(TEMP_CRITICAL, KELVIN_OFFSET)) ? KELVIN_TO_CEL(TEMP_CRITICAL - 1, KELVIN_OFFSET) : tz->temperature; return 0; }