]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
ENGR00255481 mx6: Update equation for thermal sensor
authorAnson Huang <b20788@freescale.com>
Wed, 13 Mar 2013 06:01:01 +0000 (14:01 +0800)
committerLothar Waßmann <LW@KARO-electronics.de>
Fri, 24 May 2013 06:35:59 +0000 (08:35 +0200)
Use universal equation and 25C's calibration data to
get thermal sensor's ratio.

If want to use old calibration method, please add
"use_calibration" into kernel command line.

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

index 109ea2b6cf00094745e6416020cf95df529ed919..21a87b71f5494d6863674124adde9ae65d58edd8 100644 (file)
@@ -43,6 +43,7 @@
 #include <linux/cpufreq.h>
 #include <linux/clk.h>
 #include "anatop_driver.h"
+#include <mach/hardware.h>
 
 /* register define of anatop */
 #define HW_ANADIG_ANA_MISC0    (0x00000150)
 #define ANATOP_DEBUG                   false
 #define THERMAL_FUSE_NAME              "/sys/fsl_otp/HW_OCOTP_ANA1"
 
+#define        FACTOR1         15976
+#define        FACTOR2         4297157
+
 /* variables */
 unsigned long anatop_base;
 unsigned int ratio;
@@ -147,6 +151,7 @@ static bool suspend_flag;
 static unsigned int thermal_irq;
 bool cooling_cpuhotplug;
 bool cooling_device_disable;
+static bool calibration_valid;
 unsigned long temperature_cooling;
 static const struct anatop_device_id thermal_device_ids[] = {
        {ANATOP_THERMAL_HID},
@@ -846,12 +851,22 @@ static int __init anatop_thermal_cooling_device_disable(char *str)
 }
 __setup("no_cooling_device", anatop_thermal_cooling_device_disable);
 
+static int __init anatop_thermal_use_calibration(char *str)
+{
+       calibration_valid = true;
+       pr_info("%s: use calibration data for thermal sensor!\n", __func__);
+
+       return 1;
+}
+__setup("use_calibration", anatop_thermal_use_calibration);
+
 static int anatop_thermal_counting_ratio(unsigned int fuse_data)
 {
        int ret = -EINVAL;
 
        pr_info("Thermal calibration data is 0x%x\n", fuse_data);
-       if (fuse_data == 0 || fuse_data == 0xffffffff || (fuse_data & 0xff) == 0) {
+       if (fuse_data == 0 || fuse_data == 0xffffffff ||
+               (fuse_data & 0xfff00000) == 0) {
                pr_info("%s: invalid calibration data, disable cooling!!!\n", __func__);
                cooling_device_disable = true;
                ratio = DEFAULT_RATIO;
@@ -868,7 +883,19 @@ static int anatop_thermal_counting_ratio(unsigned int fuse_data)
        raw_hot = (fuse_data & 0xfff00) >> 8;
        hot_temp = fuse_data & 0xff;
 
-       ratio = ((raw_25c - raw_hot) * 100) / (hot_temp - 25);
+       if (!calibration_valid && cpu_is_mx6q())
+               /*
+                * The universal equation for thermal sensor
+                * is slope = 0.4297157 - (0.0015976 * 25C fuse),
+                * here we convert them to integer to make them
+                * easy for counting, FACTOR1 is 15976,
+                * FACTORs is 4297157. Our ratio = -100 * slope.
+                */
+               ratio = ((FACTOR1 * raw_25c - FACTOR2) + 50000) / 100000;
+       else
+               ratio = ((raw_25c - raw_hot) * 100) / (hot_temp - 25);
+
+       pr_info("Thermal sensor with ratio = %d\n", ratio);
        raw_n40c = raw_25c + (13 * ratio) / 20;
        raw_125c = raw_25c - ratio;
        /* Init default critical temp to set alarm */