static int sec_battery_suspend(struct device *dev) { struct chg_data *chg = dev_get_drvdata(dev); if (!chg->charging) { sec_program_alarm(chg, SLOW_POLL); chg->slow_poll = 1; } return 0; }
static void sec_battery_resume(struct device *dev) { struct chg_data *chg = dev_get_drvdata(dev); /* We might be on a slow sample cycle. If we're * resuming we should resample the battery state * if it's been over a minute since we last did * so, and move back to sampling every minute until * we suspend again. */ if (chg->slow_poll) { sec_program_alarm(chg, FAST_POLL); chg->slow_poll = 0; } }
static void sec_bat_cable_work(struct work_struct *work) { struct sec_bat_info *info = container_of(work, struct sec_bat_info, cable_work); switch (info->cable_type) { case CABLE_TYPE_NONE: info->batt_full_status = BATT_NOT_FULL; info->recharging_status = false; info->charging_start_time = 0; info->batt_temp_high_cnt = 0; info->batt_temp_low_cnt = 0; info->batt_temp_recover_cnt = 0; info->charging_status = POWER_SUPPLY_STATUS_DISCHARGING; sec_bat_enable_charging(info, false); if (info->batt_health == POWER_SUPPLY_HEALTH_OVERVOLTAGE) info->batt_health = POWER_SUPPLY_HEALTH_GOOD; wake_lock_timeout(&info->vbus_wake_lock, HZ * 2); break; case CABLE_TYPE_USB: info->charging_status = POWER_SUPPLY_STATUS_CHARGING; sec_bat_enable_charging(info, true); wake_lock(&info->vbus_wake_lock); break; case CABLE_TYPE_AC: case CABLE_TYPE_DOCK: info->charging_status = POWER_SUPPLY_STATUS_CHARGING; sec_bat_enable_charging(info, true); break; default: dev_err(info->dev, "%s: Invalid cable type\n", __func__); break;; } power_supply_changed(&info->psy_ac); power_supply_changed(&info->psy_usb); info->last_poll = alarm_get_elapsed_realtime(); sec_program_alarm(info, FAST_POLL); /* To notify framework layer, remaning 2 sec */ wake_lock_timeout(&info->cable_wake_lock, HZ * 2); }
static void sec_bat_work(struct work_struct *work) { struct chg_data *chg = container_of(work, struct chg_data, bat_work); int ret; struct timespec ts; unsigned long flags; mutex_lock(&chg->mutex); sec_get_bat_temp(chg); sec_bat_discharge_reason(chg); ret = sec_cable_status_update(chg); if (ret < 0) goto err; mutex_unlock(&chg->mutex); power_supply_changed(&chg->psy_bat); chg->last_poll = alarm_get_elapsed_realtime(); ts = ktime_to_timespec(chg->last_poll); chg->timestamp = ts.tv_sec; /* prevent suspend before starting the alarm */ local_irq_save(flags); wake_unlock(&chg->work_wake_lock); sec_program_alarm(chg, FAST_POLL); local_irq_restore(flags); return; err: mutex_unlock(&chg->mutex); wake_unlock(&chg->work_wake_lock); pr_err("battery workqueue fail\n"); }