|
|
@@ -26,7 +26,7 @@ struct gadc_thermal_info {
|
|
|
|
|
|
static int gadc_thermal_adc_to_temp(struct gadc_thermal_info *gti, int val)
|
|
|
{
|
|
|
- int temp, adc_hi, adc_lo;
|
|
|
+ int temp, temp_hi, temp_lo, adc_hi, adc_lo;
|
|
|
int i;
|
|
|
|
|
|
for (i = 0; i < gti->nlookup_table; i++) {
|
|
|
@@ -36,13 +36,17 @@ static int gadc_thermal_adc_to_temp(struct gadc_thermal_info *gti, int val)
|
|
|
|
|
|
if (i == 0) {
|
|
|
temp = gti->lookup_table[0];
|
|
|
- } else if (i >= (gti->nlookup_table - 1)) {
|
|
|
+ } else if (i >= gti->nlookup_table) {
|
|
|
temp = gti->lookup_table[2 * (gti->nlookup_table - 1)];
|
|
|
} else {
|
|
|
adc_hi = gti->lookup_table[2 * i - 1];
|
|
|
adc_lo = gti->lookup_table[2 * i + 1];
|
|
|
- temp = gti->lookup_table[2 * i];
|
|
|
- temp -= ((val - adc_lo) * 1000) / (adc_hi - adc_lo);
|
|
|
+
|
|
|
+ temp_hi = gti->lookup_table[2 * i - 2];
|
|
|
+ temp_lo = gti->lookup_table[2 * i];
|
|
|
+
|
|
|
+ temp = temp_hi + mult_frac(temp_lo - temp_hi, val - adc_hi,
|
|
|
+ adc_lo - adc_hi);
|
|
|
}
|
|
|
|
|
|
return temp;
|