diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2021-05-25 18:09:34 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-07-15 02:40:34 +0000 |
commit | cf899742585aef846b853d4f1f06f8fdcc0fa303 (patch) | |
tree | 7786b31f31534c959f15282a7f63d4b0419b13fe | |
parent | 5323adb2f6349fa605387e30d22ffcb887957f6d (diff) | |
download | chrome-ec-cf899742585aef846b853d4f1f06f8fdcc0fa303.tar.gz |
chgstv2: Move code waking up battery to sub-routine
This patch moves the code waking up a battery to wakeup_battery.
There is no functionality change.
BUG=None
BRANCH=None
TEST=buildall
Change-Id: I1eb88a6b175744abf2868027aebf8c50ab441279
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2929341
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | common/charge_state_v2.c | 153 |
1 files changed, 78 insertions, 75 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index cc7dd9094d..aea9b3c354 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -1823,6 +1823,35 @@ static int get_desired_input_current(enum battery_present batt_present, } } +static void wakeup_battery(int *need_static) +{ + if (battery_seems_to_be_dead || battery_is_cut_off()) { + /* It's dead, do nothing */ + set_charge_state(ST_IDLE); + curr.requested_voltage = 0; + curr.requested_current = 0; + } else if (curr.state == ST_PRECHARGE + && (get_time().val > precharge_start_time.val + + PRECHARGE_TIMEOUT_US)) { + /* We've tried long enough, give up */ + CPRINTS("battery seems to be dead"); + battery_seems_to_be_dead = 1; + set_charge_state(ST_IDLE); + curr.requested_voltage = 0; + curr.requested_current = 0; + } else { + /* See if we can wake it up */ + if (curr.state != ST_PRECHARGE) { + CPRINTS("try to wake battery"); + precharge_start_time = get_time(); + *need_static = 1; + } + set_charge_state(ST_PRECHARGE); + curr.requested_voltage = batt_info->voltage_max; + curr.requested_current = batt_info->precharge_current; + } +} + /* Main loop */ void charger_task(void *u) { @@ -2035,88 +2064,62 @@ void charger_task(void *u) /* If the battery is not responsive, try to wake it up. */ if (!(curr.batt.flags & BATT_FLAG_RESPONSIVE)) { - if (battery_seems_to_be_dead || battery_is_cut_off()) { - /* It's dead, do nothing */ - set_charge_state(ST_IDLE); - curr.requested_voltage = 0; - curr.requested_current = 0; - } else if (curr.state == ST_PRECHARGE && - (get_time().val > precharge_start_time.val + - PRECHARGE_TIMEOUT_US)) { - /* We've tried long enough, give up */ - CPRINTS("battery seems to be dead"); - battery_seems_to_be_dead = 1; - set_charge_state(ST_IDLE); - curr.requested_voltage = 0; - curr.requested_current = 0; - } else { - /* See if we can wake it up */ - if (curr.state != ST_PRECHARGE) { - CPRINTS("try to wake battery"); - precharge_start_time = get_time(); - need_static = 1; - } - set_charge_state(ST_PRECHARGE); - curr.requested_voltage = - batt_info->voltage_max; - curr.requested_current = - batt_info->precharge_current; - } + wakeup_battery(&need_static); goto wait_for_it; - } else { - /* The battery is responding. Yay. Try to use it. */ + } + + /* The battery is responding. Yay. Try to use it. */ #ifdef CONFIG_BATTERY_REQUESTS_NIL_WHEN_DEAD - /* - * TODO (crosbug.com/p/29467): remove this workaround - * for dead battery that requests no voltage/current - */ - if (curr.requested_voltage == 0 && - curr.requested_current == 0 && - curr.batt.state_of_charge == 0) { - /* Battery is dead, give precharge current */ - curr.requested_voltage = - batt_info->voltage_max; - curr.requested_current = - batt_info->precharge_current; - } else + /* + * TODO (crosbug.com/p/29467): remove this workaround + * for dead battery that requests no voltage/current + */ + if (curr.requested_voltage == 0 && + curr.requested_current == 0 && + curr.batt.state_of_charge == 0) { + /* Battery is dead, give precharge current */ + curr.requested_voltage = + batt_info->voltage_max; + curr.requested_current = + batt_info->precharge_current; + } else #endif #ifdef CONFIG_BATTERY_REVIVE_DISCONNECT + /* + * Always check the disconnect state. This is because + * the battery disconnect state is one of the items used + * to decide whether or not to leave safe mode. + */ + battery_seems_to_be_disconnected = + battery_get_disconnect_state() == + BATTERY_DISCONNECTED; + + if (curr.requested_voltage == 0 && + curr.requested_current == 0 && + battery_seems_to_be_disconnected) { /* - * Always check the disconnect state. This is because - * the battery disconnect state is one of the items used - * to decide whether or not to leave safe mode. + * Battery is in disconnect state. Apply a + * current to kick it out of this state. */ - battery_seems_to_be_disconnected = - battery_get_disconnect_state() == - BATTERY_DISCONNECTED; - - if (curr.requested_voltage == 0 && - curr.requested_current == 0 && - battery_seems_to_be_disconnected) { - /* - * Battery is in disconnect state. Apply a - * current to kick it out of this state. - */ - CPRINTS("found battery in disconnect state"); - curr.requested_voltage = - batt_info->voltage_max; - curr.requested_current = - batt_info->precharge_current; - } else + CPRINTS("found battery in disconnect state"); + curr.requested_voltage = + batt_info->voltage_max; + curr.requested_current = + batt_info->precharge_current; + } else #endif - if (curr.state == ST_PRECHARGE || - battery_seems_to_be_dead || - battery_was_removed) { - CPRINTS("battery woke up"); - - /* Update the battery-specific values */ - batt_info = battery_get_info(); - need_static = 1; - } - - battery_seems_to_be_dead = battery_was_removed = 0; - set_charge_state(ST_CHARGE); - } + if (curr.state == ST_PRECHARGE || + battery_seems_to_be_dead || + battery_was_removed) { + CPRINTS("battery woke up"); + + /* Update the battery-specific values */ + batt_info = battery_get_info(); + need_static = 1; + } + + battery_seems_to_be_dead = battery_was_removed = 0; + set_charge_state(ST_CHARGE); wait_for_it: if (IS_ENABLED(CONFIG_CHARGER_PROFILE_OVERRIDE) |