diff options
author | Duncan Laurie <dlaurie@google.com> | 2017-07-28 17:18:17 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-09-02 08:12:38 +0000 |
commit | 87ab3c968b29fd366276601086e47a0e1af2f8df (patch) | |
tree | 3fc2ccca0ec311383aed8a14d8130e0cf215edfd | |
parent | d1528b7dc9c441786f8cf01d1fdc1a6d0a7cf68a (diff) | |
download | chrome-ec-87ab3c968b29fd366276601086e47a0e1af2f8df.tar.gz |
eve: Delay battery presence for 1 second if disconnected
If we ever see the battery in a disconnect state then delay the
battery presence state until a 1 second timer has elapsed.
This prevents power-up until the battery has recovered from its
disconnect state, and ensures that the delay happens even if the
battery out of the disconnect state before the charger task has
started.
I also reworked the if statement checking for battery disconnect
to be explicit about the states it is checking for, and testing
cutoff/init/disconnect checks as one large "or" statement instead
of having disconnect be a separate "or" check as that was leading
to it being called every time battery_is_present is called even
after the disconnect state has been cleared.
BUG=b:63957122
BRANCH=eve
TEST=manual testing with many, many boots after battery disconnect
and cutoff state, using extra verbose debug prints (that were removed
from this commit) to ensure the right checks are happening.
Change-Id: Ib191e95febf9df15373769bea2dd047fd716189d
Signed-off-by: Duncan Laurie <dlaurie@google.com>
Reviewed-on: https://chromium-review.googlesource.com/592717
Reviewed-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2320249
Tested-by: Patryk Duda <pdk@semihalf.com>
Commit-Queue: Patryk Duda <pdk@semihalf.com>
Reviewed-by: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | board/eve/battery.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/board/eve/battery.c b/board/eve/battery.c index fd93b7d63d..0acde9259e 100644 --- a/board/eve/battery.c +++ b/board/eve/battery.c @@ -43,6 +43,9 @@ struct board_batt_params { static enum battery_present batt_pres_prev = BP_NOT_SURE; static enum battery_type board_battery_type = BATTERY_TYPE_COUNT; +/* Battery may delay reporting battery present */ +static int battery_report_present = 1; + /* * Battery info for LG A50. Note that the fields start_charging_min/max and * charging_min/max are not used for the Eve charger. The effective temperature @@ -247,6 +250,14 @@ static int battery_init(void) !!(batt_status & STATUS_INITIALIZED); } +/* Allow booting now that the battery has woke up */ +static void battery_now_present(void) +{ + CPRINTS("battery will now report present"); + battery_report_present = 1; +} +DECLARE_DEFERRED(battery_now_present); + /* * Check for case where both XCHG and XDSG bits are set indicating that even * though the FG can be read from the battery, the battery is not able to be @@ -284,6 +295,7 @@ static int battery_check_disconnect(void) enum battery_present battery_is_present(void) { enum battery_present batt_pres; + static int battery_report_present_timer_started; /* Get the physical hardware status */ batt_pres = battery_hw_present(); @@ -300,12 +312,25 @@ enum battery_present battery_is_present(void) * The device will wake up when a voltage is applied to PACK. * Battery status will be inactive until it is initialized. */ - if ((batt_pres == BP_YES && batt_pres_prev != batt_pres && - !battery_is_cut_off() && !battery_init()) || - battery_check_disconnect() != BATTERY_NOT_DISCONNECTED) { - batt_pres = BP_NO; + if (batt_pres == BP_YES && batt_pres_prev != batt_pres && + (battery_is_cut_off() != BATTERY_CUTOFF_STATE_NORMAL || + battery_check_disconnect() != BATTERY_NOT_DISCONNECTED || + battery_init() == 0)) { + battery_report_present = 0; + } else if (batt_pres == BP_YES && batt_pres_prev == BP_NO && + !battery_report_present_timer_started) { + /* + * Wait 1 second before reporting present if it was + * previously reported as not present + */ + battery_report_present_timer_started = 1; + battery_report_present = 0; + hook_call_deferred(&battery_now_present_data, SECOND); } + if (!battery_report_present) + batt_pres = BP_NO; + batt_pres_prev = batt_pres; return batt_pres; |