diff options
author | Tang Qijun <qijun.tang@ecs.corp-partner.google.com> | 2022-12-27 15:08:43 +0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-01-10 19:42:58 +0000 |
commit | f0436fe4c66f1a6759c2ae28157ec495b53eab9c (patch) | |
tree | 729d4cd2351faef5e171fcb3b04e46c44d1c32fa /common | |
parent | ac7ce85654cceb9782eb9aeb7c7904624be6ce73 (diff) | |
download | chrome-ec-f0436fe4c66f1a6759c2ae28157ec495b53eab9c.tar.gz |
chgstv2: optimization battery protection for low voltage
Deep_charge_battery needs to precharge first, and then enter the idle or
charge state. Because before entering deep_charge_battery, the curr.state
state may be the idle state, which may cause no precharge process.
Therefore, add a flag to curr.batt.flags for record whether the precharge
process has been performed.
BRANCH=trogdor
BUG=b:263921114
TEST=After the battery is discharged below voltage_min, the charging
process enters deep_charge_battery and precharges first, and when the
battery voltage is greater than voltage_min, it enters the charge
state and charges normally.
TEST=run-battery_get_params_smart
Change-Id: I3a353bbcb4149b873176006bc009fbd3e8824aab
Signed-off-by: Tang Qijun <qijun.tang@ecs.corp-partner.google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4125706
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Commit-Queue: Bob Moragues <moragues@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/charge_state_v2.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 742c94bdb6..25876ac28a 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -1556,7 +1556,8 @@ __test_only enum charge_state_v2 charge_get_state_v2(void) static void deep_charge_battery(int *need_static) { - if (curr.state == ST_IDLE) { + if ((curr.state == ST_IDLE) && + (curr.batt.flags & BATT_FLAG_DEEP_CHARGE)) { /* Deep charge time out , do nothing */ curr.requested_voltage = 0; curr.requested_current = 0; @@ -1579,6 +1580,7 @@ static void deep_charge_battery(int *need_static) set_charge_state(ST_PRECHARGE); curr.requested_voltage = batt_info->voltage_max; curr.requested_current = batt_info->precharge_current; + curr.batt.flags |= BATT_FLAG_DEEP_CHARGE; } } @@ -1831,13 +1833,26 @@ void charger_task(void *u) goto wait_for_it; } - if (IS_ENABLED(CONFIG_BATTERY_LOW_VOLTAGE_PROTECTION) && - !(curr.batt.flags & BATT_FLAG_BAD_VOLTAGE) && - (curr.batt.voltage <= batt_info->voltage_min)) { - deep_charge_battery(&need_static); - goto wait_for_it; - } + /* + * When the battery voltage is lower than voltage_min,precharge + * first to protect the battery + */ + if (IS_ENABLED(CONFIG_BATTERY_LOW_VOLTAGE_PROTECTION)) { + if (!(curr.batt.flags & BATT_FLAG_BAD_VOLTAGE) && + (curr.batt.voltage <= batt_info->voltage_min)) { + deep_charge_battery(&need_static); + goto wait_for_it; + } + /* + * Finished deep charge before timeout. Clear the flag + * so that we can do deep charge again (when it's deeply + * discharged again). + */ + if ((curr.batt.flags & BATT_FLAG_DEEP_CHARGE)) { + curr.batt.flags &= ~BATT_FLAG_DEEP_CHARGE; + } + } /* The battery is responding. Yay. Try to use it. */ /* |