From a66be5cd01bf2a9a235a08b7461dee03949decba Mon Sep 17 00:00:00 2001 From: Diana Z Date: Tue, 28 Apr 2020 14:35:51 -0600 Subject: SM5803: Only enable auto charging when battery is present Enabling auto charging bits when the battery is not present can cause Vsys to brown out when the charger believes charging is complete. This uses the battery presence in the driver as an indicator for whether these bits should be set when enabling the charger. BRANCH=None BUG=None TEST=on waddledee with no battery and charger connected to C0, Vsys does not brown out Signed-off-by: Diana Z Change-Id: I3714261f9394b101ddeb76889ebcecba6b61d456 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2173159 Reviewed-by: Aseda Aboagye --- driver/charger/sm5803.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c index 2b2ca572bf..077551a3ef 100644 --- a/driver/charger/sm5803.c +++ b/driver/charger/sm5803.c @@ -5,6 +5,7 @@ * Silicon Mitus SM5803 Buck-Boost Charger */ #include "atomic.h" +#include "battery.h" #include "battery_smart.h" #include "charger.h" #include "gpio.h" @@ -387,15 +388,17 @@ static enum ec_error_list sm5803_set_mode(int chgnum, int mode) } /* - * Note: Charge may be enabled while OTG is enabled, but should be - * disabled whenever inhibit is called. + * Note: Charge may be enabled while OTG is enabled, but charge inhibit + * should also turn off OTG. Battery charging flags should only be set + * when battery is present. */ if (mode & CHARGE_FLAG_INHIBIT_CHARGE) { flow1_reg = 0; flow2_reg &= ~SM5803_FLOW2_AUTO_ENABLED; } else { flow1_reg |= SM5803_FLOW1_CHG_EN; - flow2_reg |= SM5803_FLOW2_AUTO_ENABLED; + if (battery_is_present() == BP_YES) + flow2_reg |= SM5803_FLOW2_AUTO_ENABLED; } rv = chg_write8(chgnum, SM5803_REG_FLOW1, flow1_reg); -- cgit v1.2.1