diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2018-08-10 11:32:28 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-08-16 13:14:54 -0700 |
commit | 7f3f8308afb350e6d35cce707ca220d87a8aad21 (patch) | |
tree | b0222a3121cf8214b07036e9e4623d38efec9886 | |
parent | 39ab7a039676ef3738171ed00dc3c7f61802e7b3 (diff) | |
download | chrome-ec-7f3f8308afb350e6d35cce707ca220d87a8aad21.tar.gz |
Nami: Report error for disconnected battery on Sona
On Sona, when a battery is cutoff, the gas gauge does not clear
BATTERY_DISCHARGING_DISABLED or BATTERY_CHARGING_DISABLED until a
precharge current is supplied.
This patch makes battery_is_present return BP_NOT_SURE for the first
5 seconds after the battery is found electrically disconnected. After
5 seconds, it reports BP_NO as it normally does.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
BUG=b:112292720
BRANCH=nami
TEST=Verify the battery wakes up from cutoff mode. Verify a bad battery
eventually stops being charged.
Change-Id: I4d0e9e5ed0e9631b7bbf8565ce62c17da8a0a848
Reviewed-on: https://chromium-review.googlesource.com/1171259
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Commit-Queue: Daisuke Nojiri <dnojiri@chromium.org>
Tested-by: Daisuke Nojiri <dnojiri@chromium.org>
(cherry picked from commit 4363e098c546f09cdfcc9c10de09b0c517d52e63)
Reviewed-on: https://chromium-review.googlesource.com/1177721
Commit-Ready: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | board/nami/battery.c | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/board/nami/battery.c b/board/nami/battery.c index b34c5e18e8..d32a1b74ff 100644 --- a/board/nami/battery.c +++ b/board/nami/battery.c @@ -213,6 +213,19 @@ static int battery_init(void) !!(batt_status & STATUS_INITIALIZED); } +enum battery_disconnect_grace_period { + BATTERY_DISCONNECT_GRACE_PERIOD_OFF, + BATTERY_DISCONNECT_GRACE_PERIOD_ON, + BATTERY_DISCONNECT_GRACE_PERIOD_OVER, +}; +static enum battery_disconnect_grace_period disconnect_grace_period; + +static void battery_disconnect_timer(void) +{ + disconnect_grace_period = BATTERY_DISCONNECT_GRACE_PERIOD_OVER; +} +DECLARE_DEFERRED(battery_disconnect_timer); + /* * 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 @@ -238,8 +251,29 @@ static int battery_check_disconnect_ti_bq40z50(void) if ((data[3] & (BATTERY_DISCHARGING_DISABLED | BATTERY_CHARGING_DISABLED)) == - (BATTERY_DISCHARGING_DISABLED | BATTERY_CHARGING_DISABLED)) - return BATTERY_DISCONNECTED; + (BATTERY_DISCHARGING_DISABLED | BATTERY_CHARGING_DISABLED)) { + if (oem != PROJECT_SONA) + return BATTERY_DISCONNECTED; + /* + * For Sona, we need a workaround to wake up a battery from + * cutoff. We return DISCONNECT_ERROR for the 5 seconds after + * the first call BP_NOT_SURE is reported to chgstv2. It will + * supply precharge current and wakes up the battery from + * cutoff. If the battery is good, we won't come back here. + * If not, after 5 seconds, we will return DISCONNECTED to + * stop charging and avoid damaging the battery. + */ + if (disconnect_grace_period == + BATTERY_DISCONNECT_GRACE_PERIOD_OVER) + return BATTERY_DISCONNECTED; + if (disconnect_grace_period == + BATTERY_DISCONNECT_GRACE_PERIOD_OFF) + hook_call_deferred(&battery_disconnect_timer_data, + 5 * SECOND); + ccprintf("Battery disconnect grace period\n"); + disconnect_grace_period = BATTERY_DISCONNECT_GRACE_PERIOD_ON; + return BATTERY_DISCONNECT_ERROR; + } return BATTERY_NOT_DISCONNECTED; } |