From d0cf3227ce425cb65015d49c0c734f3ee64fa1d5 Mon Sep 17 00:00:00 2001 From: Wonjoon Lee Date: Thu, 12 Nov 2015 18:24:48 +0900 Subject: [PATCH] charge_state_v2: Set charger input current in the task When task creating, input_current will be set as condition. But there is no more handling for this value. so it will remain even if condition is changed. This will put input current decision int the loop so that we can proper input current as battery existence. BUG=chrome-os-partner:47546 TEST=make buildall, command 'charger' with/without battery. and see it is changed dynamically BRANCH=None (cherry picked from commit d2ac89d58c34d7cc0a2a3fb591fcdcddbe2e9feb) Change-Id: Ib72e20faf7c7f302a4e39d43b23176247e5176fa Signed-off-by: Wonjoon Lee Reviewed-on: https://chromium-review.googlesource.com/312950 Commit-Ready: Shawn N Reviewed-by: Alec Berg --- common/charge_state_v2.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 26c41324be..1d4eee5236 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -44,6 +44,7 @@ static const struct battery_info *batt_info; static struct charge_state_data curr; static int prev_ac, prev_charge, prev_full; +static enum battery_present prev_bp; static int is_full; /* battery not accepting current */ static int state_machine_force_idle; static int manual_mode; /* volt/curr are no longer maintained by charger */ @@ -560,6 +561,15 @@ void charger_init(void) } DECLARE_HOOK(HOOK_INIT, charger_init, HOOK_PRIO_DEFAULT); +int get_desired_input_current(enum battery_present batt_present, + const struct charger_info * const info) +{ + if (batt_present == BP_YES || system_is_locked()) + return CONFIG_CHARGER_INPUT_CURRENT; + else + return info->input_current_max; +} + /* Main loop */ void charger_task(void) { @@ -581,10 +591,8 @@ void charger_task(void) * as needed. */ battery_get_params(&curr.batt); - if (curr.batt.is_present == BP_YES || system_is_locked()) - curr.desired_input_current = CONFIG_CHARGER_INPUT_CURRENT; - else - curr.desired_input_current = info->input_current_max; + prev_bp = curr.batt.is_present; + curr.desired_input_current = get_desired_input_current(prev_bp, info); while (1) { @@ -629,6 +637,13 @@ void charger_task(void) charger_get_params(&curr.chg); battery_get_params(&curr.batt); + if (prev_bp != curr.batt.is_present) { + prev_bp = curr.batt.is_present; + curr.desired_input_current = + get_desired_input_current(prev_bp, info); + charger_set_input_current(curr.desired_input_current); + } + curr.chg.flags |= CHG_FLAG_INITIALIZED; /*