static int s3c_get_bat_temp(struct chg_data *chg) { int temp = 0; int temp_adc = s3c_read_temp(chg); int health = chg->bat_info.batt_health; int left_side = 0; int right_side = chg->pdata->adc_array_size - 1; int mid; while (left_side <= right_side) { mid = (left_side + right_side) / 2 ; if (mid == 0 || mid == chg->pdata->adc_array_size - 1 || (chg->pdata->adc_table[mid].adc_value <= temp_adc && chg->pdata->adc_table[mid+1].adc_value > temp_adc)) { temp = chg->pdata->adc_table[mid].temperature; break; } else if (temp_adc - chg->pdata->adc_table[mid].adc_value > 0) left_side = mid + 1; else right_side = mid - 1; } chg->bat_info.batt_temp = temp; if (temp >= HIGH_BLOCK_TEMP) { if (health != POWER_SUPPLY_HEALTH_OVERHEAT && health != POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) chg->bat_info.batt_health = POWER_SUPPLY_HEALTH_OVERHEAT; } else if (temp <= HIGH_RECOVER_TEMP && temp >= LOW_RECOVER_TEMP) { if (health == POWER_SUPPLY_HEALTH_OVERHEAT || health == POWER_SUPPLY_HEALTH_COLD) chg->bat_info.batt_health = POWER_SUPPLY_HEALTH_GOOD; } else if (temp <= LOW_BLOCK_TEMP) { if (health != POWER_SUPPLY_HEALTH_COLD && health != POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) chg->bat_info.batt_health = POWER_SUPPLY_HEALTH_COLD; } pr_debug("%s : temp = %d, adc = %d\n", __func__, temp, temp_adc); return temp; }
static int s3c_get_bat_temp(struct power_supply *bat_ps) { int temp = 0; int array_size = 0; int i = 0; int temp_adc = s3c_read_temp(bat_ps); int health = s3c_get_bat_health(); #ifdef __TEST_MODE_INTERFACE__ s3c_bat_info.bat_info.batt_temp_adc_aver = temp_adc; #endif /* __TEST_MODE_INTERFACE__ */ #ifndef __REVERSE_TEMPER_ADC__ if (temp_adc <= TEMP_HIGH_BLOCK) { if (health != POWER_SUPPLY_HEALTH_OVERHEAT && health != POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) s3c_temp_control(POWER_SUPPLY_HEALTH_OVERHEAT); } else if (temp_adc >= TEMP_HIGH_RECOVER && temp_adc <= TEMP_LOW_RECOVER) { if (health == POWER_SUPPLY_HEALTH_OVERHEAT || health == POWER_SUPPLY_HEALTH_COLD) s3c_temp_control(POWER_SUPPLY_HEALTH_GOOD); } else if (temp_adc >= TEMP_LOW_BLOCK) { if (health != POWER_SUPPLY_HEALTH_COLD && health != POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) s3c_temp_control(POWER_SUPPLY_HEALTH_COLD); } array_size = ARRAY_SIZE(temper_table); for (i = 0; i < (array_size - 1); i++) { if (i == 0) { if (temp_adc >= temper_table[0][0]) { temp = temper_table[0][1]; break; } else if (temp_adc <= temper_table[array_size-1][0]) { temp = temper_table[array_size-1][1]; break; } } if (temper_table[i][0] > temp_adc && temper_table[i+1][0] <= temp_adc) { temp = temper_table[i+1][1]; } } #else /* __REVERSE_TEMPER_ADC__ */ if (temp_adc >= TEMP_HIGH_BLOCK) { if (health != POWER_SUPPLY_HEALTH_OVERHEAT && health != POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) s3c_temp_control(POWER_SUPPLY_HEALTH_OVERHEAT); } else if (temp_adc <= TEMP_HIGH_RECOVER && temp_adc >= TEMP_LOW_RECOVER) { if (health == POWER_SUPPLY_HEALTH_OVERHEAT || health == POWER_SUPPLY_HEALTH_COLD) s3c_temp_control(POWER_SUPPLY_HEALTH_GOOD); } else if (temp_adc <= TEMP_LOW_BLOCK) { if (health != POWER_SUPPLY_HEALTH_COLD && health != POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) s3c_temp_control(POWER_SUPPLY_HEALTH_COLD); } array_size = ARRAY_SIZE(temper_table); for (i = 0; i < (array_size - 1); i++) { if (i == 0) { if (temp_adc <= temper_table[0][0]) { temp = temper_table[0][1]; break; } else if (temp_adc >= temper_table[array_size-1][0]) { temp = temper_table[array_size-1][1]; break; } } if (temper_table[i][0] < temp_adc && temper_table[i+1][0] >= temp_adc) { temp = temper_table[i+1][1]; } } #endif /* __REVERSE_TEMPER_ADC__ */ dev_dbg(dev, "%s: temp = %d, adc = %d\n", __func__, temp, temp_adc); #ifdef __TEST_MODE_INTERFACE__ s3c_bat_info.bat_info.batt_temp_aver = temp; #endif /* __TEST_MODE_INTERFACE__ */ return temp; }