From 911c1821f92bfadc9e0996926ee1b20f7977e562 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Sat, 7 Feb 2015 13:43:08 -0800 Subject: samus: prevent fast enable/disable charging loop Bug fix for the new samus charging software workarounds. The problem occurs occasionally, especially with 5V chargers, and causes the new software workarounds to get out of sync with the actualy state of the charging circuit such that when ACOK actually goes high, we stop charging, and then when ACOK goes low we start charging, and we end up in a high frequency loop of enabling/disabling charging. The fix is to add a 100ms delay when ACOK goes low before allowing charging again. This guarantees that the circuit will settle down before we try charging again. BUG=chrome-os-partner:36081 BRANCH=samus TEST=can reproduce with an EVT2 samus connected to a DVT samus at ~15% battery. On the DVT samus, allow charging from the other other samus with charge override. Without this change, most of the time the PD console goes back and forth between enabling and disabling charging. With this change, we don't can actually charge briefly, although there is still a problem where VBUS can dip too low and cause ACOK to actually go low. Change-Id: If83def862fb58ef3938e2a443e1a081bd27713ec Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/247460 Reviewed-by: Shawn N Reviewed-by: Duncan Laurie --- board/samus/extpower.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/board/samus/extpower.c b/board/samus/extpower.c index 5cb97c39ca..5e9e168853 100644 --- a/board/samus/extpower.c +++ b/board/samus/extpower.c @@ -157,6 +157,13 @@ static void allow_max_request(void) } DECLARE_DEFERRED(allow_max_request); +static void allow_min_charging(void) +{ + if (!charge_is_disabled && charge_circuit_state == CHARGE_CIRCUIT_OK) + host_command_pd_send_status(PD_CHARGE_5V); +} +DECLARE_DEFERRED(allow_min_charging); + static void extpower_board_hacks(int extpower, int extpower_prev) { /* Cancel deferred attempt to enable max charge request */ @@ -165,7 +172,9 @@ static void extpower_board_hacks(int extpower, int extpower_prev) /* * When AC is detected, delay briefly before allowing PD * to negotiate up to the max voltage to give charge circuit - * time to settle down. When AC goes away, set PD to only allow + * time to settle down. When AC goes away, disable charging + * for a brief time, allowing charge state machine time to + * see AC has gone away, and then set PD to only allow * 5V charging for the next time AC is connected. * * Use NVDC charger learn mode (charger_disable()) when AC @@ -186,7 +195,7 @@ static void extpower_board_hacks(int extpower, int extpower_prev) * backboost */ host_command_pd_send_status(PD_CHARGE_NONE); - } else { + } else if (!extpower && extpower_prev) { /* AC disconnected */ if (!charge_is_disabled && charge_circuit_state == CHARGE_CIRCUIT_OK) @@ -194,10 +203,7 @@ static void extpower_board_hacks(int extpower, int extpower_prev) charger_disable(1); - if (!charge_is_disabled && - charge_circuit_state == CHARGE_CIRCUIT_OK) - host_command_pd_send_status(PD_CHARGE_5V); - + hook_call_deferred(allow_min_charging, 100*MSEC); set_pp5000_in_g3(PP5000_IN_G3_AC, 0); } extpower_prev = extpower; -- cgit v1.2.1