/** * adc_to_temp - converts the ADC code to temperature in C * @direct: true if ths channel is direct index * @adc_val: the adc_val that needs to be converted * @tp: temperature return value * * Linear approximation is used to covert the skin adc value into temperature. * This technique is used to avoid very long look-up table to get * the appropriate temp value from ADC value. * The adc code vs sensor temp curve is split into five parts * to achieve very close approximate temp value with less than * 0.5C error */ static int adc_to_temp(int direct, uint16_t adc_val, unsigned long *tp) { int temp; /* Direct conversion for die temperature */ if (direct) { if (is_valid_adc(adc_val, MSIC_DIE_ADC_MIN, MSIC_DIE_ADC_MAX)) { *tp = to_msic_die_temp(adc_val) * 1000; return 0; } return -ERANGE; } if (!is_valid_adc(adc_val, ADC_MIN, ADC_MAX)) return -ERANGE; /* Linear approximation for skin temperature */ if (adc_val > ADC_VAL0C) temp = 177 - (adc_val/5); else if ((adc_val <= ADC_VAL0C) && (adc_val > ADC_VAL20C)) temp = 111 - (adc_val/8); else if ((adc_val <= ADC_VAL20C) && (adc_val > ADC_VAL40C)) temp = 92 - (adc_val/10); else if ((adc_val <= ADC_VAL40C) && (adc_val > ADC_VAL60C)) temp = 91 - (adc_val/10); else temp = 112 - (adc_val/6); /* Convert temperature in celsius to milli degree celsius */ *tp = temp * 1000; return 0; }
static int adc_to_temp(int direct, uint16_t adc_val, unsigned long *tp) { int temp; if (direct) { if (is_valid_adc(adc_val, MSIC_DIE_ADC_MIN, MSIC_DIE_ADC_MAX)) { *tp = to_msic_die_temp(adc_val) * 1000; return 0; } return -ERANGE; } if (!is_valid_adc(adc_val, ADC_MIN, ADC_MAX)) return -ERANGE; if (adc_val > ADC_VAL0C) temp = 177 - (adc_val/5); else if ((adc_val <= ADC_VAL0C) && (adc_val > ADC_VAL20C)) temp = 111 - (adc_val/8); else if ((adc_val <= ADC_VAL20C) && (adc_val > ADC_VAL40C)) temp = 92 - (adc_val/10); else if ((adc_val <= ADC_VAL40C) && (adc_val > ADC_VAL60C)) temp = 91 - (adc_val/10); else temp = 112 - (adc_val/6); *tp = temp * 1000; return 0; }