static int s3c_cable_status_update(struct chg_data *chg) { int ret; bool vdc_status; ktime_t ktime; struct timespec cur_time; /* if max8998 has detected vdcin */ if (max8998_check_vdcin(chg)) { vdc_status = 1; if (chg->bat_info.dis_reason) { pr_info("%s : battery status discharging : %d\n", __func__, chg->bat_info.dis_reason); /* have vdcin, but cannot charge */ chg->charging = false; ret = max8998_charging_control(chg); if (ret < 0) goto err; chg->bat_info.charging_status = chg->bat_info.batt_is_full ? POWER_SUPPLY_STATUS_FULL : POWER_SUPPLY_STATUS_NOT_CHARGING; chg->discharging_time = 0; chg->set_batt_full = 0; goto update; } else if (chg->discharging_time == 0) { ktime = alarm_get_elapsed_realtime(); cur_time = ktime_to_timespec(ktime); chg->discharging_time = chg->bat_info.batt_is_full || chg->set_charge_timeout ? cur_time.tv_sec + TOTAL_RECHARGING_TIME : cur_time.tv_sec + TOTAL_CHARGING_TIME; } /* able to charge */ chg->charging = true; ret = max8998_charging_control(chg); if (ret < 0) goto err; chg->bat_info.charging_status = chg->bat_info.batt_is_full ? POWER_SUPPLY_STATUS_FULL : POWER_SUPPLY_STATUS_CHARGING; } else { /* no vdc in, not able to charge */ vdc_status = 0; chg->charging = false; ret = max8998_charging_control(chg); if (ret < 0) goto err; chg->bat_info.charging_status = POWER_SUPPLY_STATUS_DISCHARGING; chg->bat_info.batt_is_full = false; chg->set_charge_timeout = false; chg->set_batt_full = 0; chg->bat_info.dis_reason = 0; chg->discharging_time = 0; if (lpm_charging_mode && pm_power_off) pm_power_off(); } update: if ((chg->cable_status == CABLE_TYPE_USB) && vdc_status) wake_lock(&chg->vbus_wake_lock); else wake_lock_timeout(&chg->vbus_wake_lock, HZ / 2); return 0; err: return ret; }
static int s3c_cable_status_update(struct chg_data *chg) { int ret; bool vdc_status; ktime_t ktime; struct timespec cur_time; static bool prev_vdc_status = 0; /* if max8998 has detected vdcin */ if (max8998_check_vdcin(chg) == 1) { vdc_status = 1; if (chg->bat_info.dis_reason) { /* have vdcin, but cannot charge */ chg->charging = 0; ret = max8998_charging_control(chg); if (ret < 0) goto err; if (chg->bat_info.dis_reason & (DISCONNECT_TEMP_OVERHEAT | DISCONNECT_TEMP_FREEZE)) chg->set_batt_full = false; chg->bat_info.charging_status = chg->set_batt_full ? POWER_SUPPLY_STATUS_FULL : POWER_SUPPLY_STATUS_NOT_CHARGING; chg->discharging_time = 0; chg->bat_info.batt_is_full = false; goto update; } else if (chg->discharging_time == 0) { ktime = alarm_get_elapsed_realtime(); cur_time = ktime_to_timespec(ktime); chg->discharging_time = (chg->set_batt_full || chg->set_charge_timeout) ? cur_time.tv_sec + TOTAL_RECHARGING_TIME : cur_time.tv_sec + TOTAL_CHARGING_TIME; } /* able to charge */ chg->charging = 1; ret = max8998_charging_control(chg); if (ret < 0) goto err; chg->bat_info.charging_status = chg->set_batt_full ? POWER_SUPPLY_STATUS_FULL : POWER_SUPPLY_STATUS_CHARGING; } else { vdc_status = 0; /* no vdc in, not able to charge */ chg->charging = 0; ret = max8998_charging_control(chg); if (ret < 0) goto err; chg->bat_info.charging_status = POWER_SUPPLY_STATUS_DISCHARGING; chg->bat_info.batt_is_full = false; chg->set_charge_timeout = false; chg->set_batt_full = false; chg->bat_info.dis_reason = 0; chg->discharging_time = 0; if (lpm_charging_mode && pm_power_off) pm_power_off(); } update: if (vdc_status) wake_lock(&chg->vbus_wake_lock); else wake_lock_timeout(&chg->vbus_wake_lock, HZ / 5); if (vdc_status != prev_vdc_status) { set_tsp_for_ta_detect(vdc_status); prev_vdc_status = vdc_status; } return 0; err: return ret; }