ARM: tegra tegratab: Fix wrong calculation in ADC to temp for NTC thermistor
Jinyoung Park [Mon, 24 Jun 2013 10:54:51 +0000 (19:54 +0900)]
Fixed wrong calculation in ADC to temp for NTC thermistor.

Bug 1287901

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

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

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

index a683a58..7b6df2a 100644 (file)
@@ -749,14 +749,14 @@ static int gadc_thermal_thermistor_adc_to_temp(
                        break;
 
        if (i == 0) {
-               temp = thermistor_table[0].temp * 1000;
-       } else if (i >= table_size - 1) {
+               temp = thermistor_table[i].temp * 1000;
+       } else if (i >= (table_size - 1)) {
                temp = thermistor_table[table_size - 1].temp * 1000;
        } else {
                adc_hi = thermistor_table[i - 1].adc;
                adc_lo = thermistor_table[i].adc;
-               temp = thermistor_table[i - 1].temp * 1000;
-               temp += ((*val - adc_lo) * 1000 / (adc_hi - adc_lo));
+               temp = thermistor_table[i].temp * 1000;
+               temp -= ((*val - adc_lo) * 1000 / (adc_hi - adc_lo));
        }
 
        return temp;