static void s3c_bat_check_chg_current(struct chg_data *chg) { unsigned long chg_current_adc = 0; unsigned long chg_current_temp = 0; unsigned long chg_current_volt = 0; unsigned long chg_current = 0; chg_current_adc = s3c_bat_get_adc_data(S3C_ADC_CHG_CURRENT); /* get adc code value */ chg->bat_info.batt_current_adc = chg_current_adc; chg_current_temp = chg_current_adc * ADC_12BIT_RESOLUTION; chg_current_volt = chg_current_temp / ADC_12BIT_SCALE; if ((chg_current_temp % ADC_12BIT_SCALE) >= (ADC_12BIT_SCALE / 2)) { chg_current_volt += 1; } chg_current_temp = 0; chg_current_temp = (chg_current_volt * 100) / ADC_CURRENT_FACTOR; /* scaled 10 */ chg_current = chg_current_temp / 10; if ((chg_current_temp % 10) >= 5) { chg_current += 1; } chg->bat_info.batt_current = chg_current; if (chg->bat_info.batt_vcell >= FULL_CHARGE_COND_VOLTAGE) { if ((!chg->set_batt_full && chg_current_adc <= CURRENT_OF_FULL_CHG_1ST) || (chg->set_batt_full && chg_current_adc <= CURRENT_OF_FULL_CHG_2ND)) { chg->full_check_count++; if (chg->full_check_count >= FULL_CHG_COND_COUNT) s3c_bat_top_off(chg); } else chg->full_check_count = 0; } else chg->full_check_count = 0; }
static void s3c_get_v_f_adc(void) { s3c_bat_info.bat_info.batt_v_f_adc = s3c_bat_get_adc_data(S3C_ADC_V_F); dev_info(dev, "%s: vf=%d\n", __func__, s3c_bat_info.bat_info.batt_v_f_adc); }
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 unsigned int s3c_bat_check_v_f(void) { unsigned int rc = 0; int adc = 0; adc = s3c_bat_get_adc_data(S3C_ADC_V_F); dev_info(dev, "%s: V_F ADC = %d\n", __func__, adc); if (adc <= BATT_VF_MAX && adc >= BATT_VF_MIN) { if (s3c_get_bat_health() == POWER_SUPPLY_HEALTH_UNSPEC_FAILURE) { s3c_set_bat_health(POWER_SUPPLY_HEALTH_GOOD); s3c_set_chg_en(ENABLE); b_status=0; } rc = 1; } else { dev_info(dev, "%s: Unauthorized battery!\n", __func__); s3c_set_bat_health(POWER_SUPPLY_HEALTH_UNSPEC_FAILURE); rc = 0; } return rc; }
static ssize_t s3c_bat_show_attrs(struct device *dev, struct device_attribute *attr, char *buf) { struct power_supply *psy = dev_get_drvdata(dev); struct chg_data *chg = container_of(psy, struct chg_data, psy_bat); int i = 0; const ptrdiff_t off = attr - s3c_battery_attrs; union power_supply_propval value; switch (off) { case BATT_VOL: if (chg->pdata && chg->pdata->psy_fuelgauge && chg->pdata->psy_fuelgauge->get_property) { chg->pdata->psy_fuelgauge->get_property( chg->pdata->psy_fuelgauge, POWER_SUPPLY_PROP_VOLTAGE_NOW, &value); chg->bat_info.batt_vcell = value.intval; } i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", chg->bat_info.batt_vcell/1000); break; case BATT_VOL_ADC: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", 0); break; case BATT_TEMP: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", chg->bat_info.batt_temp); break; case BATT_TEMP_ADC: chg->bat_info.batt_temp_adc = s3c_bat_get_adc_data(S3C_ADC_TEMPERATURE); i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", chg->bat_info.batt_temp_adc); break; case BATT_CHARGING_SOURCE: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", chg->cable_status); break; case BATT_FG_SOC: if (chg->pdata && chg->pdata->psy_fuelgauge && chg->pdata->psy_fuelgauge->get_property) { chg->pdata->psy_fuelgauge->get_property( chg->pdata->psy_fuelgauge, POWER_SUPPLY_PROP_CAPACITY, &value); chg->bat_info.batt_soc = value.intval; } i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", chg->bat_info.batt_soc); break; case CHARGING_MODE_BOOTING: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", lpm_charging_mode); break; case BATT_TEMP_CHECK: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", chg->bat_info.batt_health); break; case BATT_FULL_CHECK: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", chg->bat_info.batt_is_full); break; case BATT_TYPE: i += scnprintf(buf + i, PAGE_SIZE - i, "SDI_SDI\n"); break; default: i = -EINVAL; } return i; }
static ssize_t s3c_bat_show_property(struct device *dev, struct device_attribute *attr, char *buf) { int i = 0; const ptrdiff_t off = attr - s3c_battery_attrs; switch (off) { case BATT_VOL: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_vol); break; case BATT_VOL_ADC: s3c_bat_info.bat_info.batt_vol_adc = 0; i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_vol_adc); break; case BATT_VOL_ADC_CAL: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_vol_adc_cal); break; case BATT_TEMP: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_temp); break; case BATT_TEMP_ADC: s3c_bat_info.bat_info.batt_temp_adc = s3c_bat_get_adc_data(S3C_ADC_TEMPERATURE); i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_temp_adc); break; #ifdef __TEST_MODE_INTERFACE__ case BATT_TEST_MODE: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_test_mode); break; #endif /* __TEST_MODE_INTERFACE__ */ case BATT_TEMP_ADC_CAL: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_temp_adc_cal); break; case BATT_VOL_ADC_AVER: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_vol_adc_aver); break; #ifdef __TEST_MODE_INTERFACE__ case BATT_VOL_AVER: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_vol_aver); break; case BATT_TEMP_AVER: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_temp_aver); break; case BATT_TEMP_ADC_AVER: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_temp_adc_aver); break; case BATT_V_F_ADC: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.batt_v_f_adc); break; #endif /* __TEST_MODE_INTERFACE__ */ case BATT_CHARGING_SOURCE: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.bat_info.charging_source); break; case BATT_FG_SOC: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", fg_read_soc()); break; case BATT_MAX_SOC: i += scnprintf(buf + i, PAGE_SIZE - i, "%d\n", s3c_bat_info.max_soc_value); break; default: i = -EINVAL; } return i; }