ARM: tegra: tegratab: Add ADC temperature conversion for thermal diode
Jinyoung Park [Fri, 21 Jun 2013 07:54:01 +0000 (16:54 +0900)]
Added ADC temperature conversion for thermal diode.

Bug 1287901

Signed-off-by: Jinyoung Park <jinyoungp@nvidia.com>
Reviewed-on: http://git-master/r/241376
(cherry picked from commit 8db34a07b76b486f537905698cabe56aadc6ca62)

Change-Id: I2e9a013b0b24e88babcecabf190e385df556b8de
Signed-off-by: Jinyoung Park <jinyoungp@nvidia.com>
Reviewed-on: http://git-master/r/252884
Reviewed-by: Mrutyunjay Sawant <msawant@nvidia.com>
Tested-by: Mrutyunjay Sawant <msawant@nvidia.com>

arch/arm/mach-tegra/board-tegratab-power.c
arch/arm/mach-tegra/board-tegratab-sensors.c

index fcaed67..a5ec9ba 100644 (file)
@@ -399,7 +399,12 @@ static struct iio_map palmas_adc_iio_maps[] = {
 };
 
 static struct palmas_gpadc_platform_data palmas_adc_pdata = {
-       .channel3_current_uA = 400,
+       /* If ch3_dual_current is true, it will measure ch3 input signal with
+        * ch3_current and the next current of ch3_current.
+        * So this system will use 400uA and 800uA for ch3 measurement. */
+       .ch3_current_uA = 400,  /* 0uA, 10uA, 400uA, 800uA */
+       .ch3_dual_current = true,
+       .extended_delay = true,
        .iio_maps = palmas_adc_iio_maps,
 };
 
index 1ce050d..a683a58 100644 (file)
@@ -762,12 +762,30 @@ static int gadc_thermal_thermistor_adc_to_temp(
        return temp;
 };
 
+#define TDIODE_PRECISION_MULTIPLIER    1000000000LL
+
 static int gadc_thermal_tdiode_adc_to_temp(
                struct gadc_thermal_platform_data *pdata, int *val, int *val2)
 {
-       /* TODO: add adc raw to temp conversion. */
-       pr_warn("%s: No adc raw to temp conversion.\n", __func__);
-       return *val;
+       /*
+        * Series resistance cancellation using multi-current ADC measurement.
+        * diode temp = ((adc2 - k * adc1) - (b2 - k * b1)) / (m2 - k * m1)
+        * - adc1 : ADC raw with current source 400uA
+        * - m1, b1 : calculated with current source 400uA
+        * - adc2 : ADC raw with current source 800uA
+        * - m2, b2 : calculated with current source 800uA
+        * - k : 2 (= 800uA / 400uA)
+        */
+       const s64 m1 = -0.00571005 * TDIODE_PRECISION_MULTIPLIER;
+       const s64 b1 = 2524.29891 * TDIODE_PRECISION_MULTIPLIER;
+       const s64 m2 = -0.005519811 * TDIODE_PRECISION_MULTIPLIER;
+       const s64 b2 = 2579.354349 * TDIODE_PRECISION_MULTIPLIER;
+       s64 temp = TDIODE_PRECISION_MULTIPLIER;
+
+       temp *= (s64)((*val2) - 2 * (*val));
+       temp -= (b2 - 2 * b1);
+       temp = div64_s64(temp, (m2 - 2 * m1));
+       return temp;
 };
 
 static struct gadc_thermal_platform_data gadc_thermal_thermistor_pdata = {