static unsigned long s3c_read_temp(struct power_supply *bat_ps) { int adc = 0; dev_dbg(dev, "%s\n", __func__); adc = s3c_bat_get_adc_data(S3C_ADC_TEMPERATURE); dev_dbg(dev, "%s: adc = %d\n", __func__, adc); #ifdef __TEST_DEVICE_DRIVER__ switch (bat_temper_state) { case 0: break; case 1: adc = TEMP_HIGH_BLOCK; break; case 2: adc = TEMP_LOW_BLOCK; break; default: break; } #endif /* __TEST_DEVICE_DRIVER__ */ s3c_bat_info.bat_info.batt_temp_adc = adc; #ifdef __AVG_TEMP_ADC__ return calculate_average_adc(S3C_ADC_TEMPERATURE, adc); #else /* __AVG_TEMP_ADC__ */ return adc; #endif /* __AVG_TEMP_ADC__ */ }
static unsigned long s3c_read_temp(struct chg_data *chg) { int adc = 0; adc = s3c_bat_get_adc_data(S3C_ADC_TEMPERATURE); return calculate_average_adc(S3C_ADC_TEMPERATURE, adc, chg); }
static int sec_bat_get_adc_value( struct sec_battery_info *battery, int channel) { int adc; adc = sec_bat_get_adc_data(battery, channel, battery->pdata->adc_check_count); if (adc <= 0) { pr_err("%s: Error in ADC\n", __func__); return adc; } return calculate_average_adc(battery, channel, adc); }
static int sec_bat_check_temper(struct sec_bat_info *info) { struct power_supply *psy = power_supply_get_by_name(info->fuel_gauge_name); union power_supply_propval value; int ret; int temp; int temp_adc = s3c_read_temper_adc(info); int health = info->batt_health; int low = 0; int high = 0; int mid = 0; calculate_average_adc(info, &info->temper_adc_sample, temp_adc); if (!info->adc_table || !info->adc_arr_size) { /* using fake temp */ temp = 300; info->batt_temp = temp; return temp; } high = info->adc_arr_size - 1; while (low <= high) { mid = (low + high) / 2; if (info->adc_table[mid].adc > temp_adc) high = mid - 1; else if (info->adc_table[mid].adc < temp_adc) low = mid + 1; else break; } temp = info->adc_table[mid].temperature; info->batt_temp = temp; if (temp >= HIGH_BLOCK_TEMP) { if (health != POWER_SUPPLY_HEALTH_OVERHEAT && health != POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) if (info->batt_temp_high_cnt < TEMP_BLOCK_COUNT) info->batt_temp_high_cnt++; dev_info(info->dev, "%s: high count = %d\n", __func__, info->batt_temp_high_cnt); } else if (temp <= HIGH_RECOVER_TEMP && temp >= LOW_RECOVER_TEMP) { if (health == POWER_SUPPLY_HEALTH_OVERHEAT || health == POWER_SUPPLY_HEALTH_COLD) if (info->batt_temp_recover_cnt < TEMP_BLOCK_COUNT) info->batt_temp_recover_cnt++; dev_info(info->dev, "%s: recovery count = %d\n", __func__, info->batt_temp_recover_cnt); } else if (temp <= LOW_BLOCK_TEMP) { if (health != POWER_SUPPLY_HEALTH_COLD && health != POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) if (info->batt_temp_low_cnt < TEMP_BLOCK_COUNT) info->batt_temp_low_cnt++; dev_info(info->dev, "%s: low count = %d\n", __func__, info->batt_temp_low_cnt); } else { info->batt_temp_high_cnt = 0; info->batt_temp_low_cnt = 0; info->batt_temp_recover_cnt = 0; } if (info->batt_temp_high_cnt >= TEMP_BLOCK_COUNT) info->batt_health = POWER_SUPPLY_HEALTH_OVERHEAT; else if (info->batt_temp_low_cnt >= TEMP_BLOCK_COUNT) info->batt_health = POWER_SUPPLY_HEALTH_COLD; else if (info->batt_temp_recover_cnt >= TEMP_BLOCK_COUNT) info->batt_health = POWER_SUPPLY_HEALTH_GOOD; /* Set temperature to fuel gauge */ if (info->fuel_gauge_name) { value.intval = info->batt_temp / 10; ret = psy->set_property(psy, POWER_SUPPLY_PROP_TEMP, &value); if (ret) { dev_err(info->dev, "%s: fail to set temperature(%d)\n", __func__, ret); } } dev_info(info->dev, "%s: temp=%d, adc=%d\n", __func__, temp, temp_adc); return temp; }