summaryrefslogtreecommitdiff
path: root/driver/charger/sm5803.c
diff options
context:
space:
mode:
authorDiana Z <dzigterman@chromium.org>2020-12-22 11:13:28 -0700
committerCommit Bot <commit-bot@chromium.org>2021-01-13 19:35:43 +0000
commit3c628054407c6328efc8c975c161323d41be7e22 (patch)
tree7ae57addafcfdbfd9054ec42467bcb92b4f184aa /driver/charger/sm5803.c
parenta789bfc06aff8edf82e225d48b1c539ba0cd3518 (diff)
downloadchrome-ec-3c628054407c6328efc8c975c161323d41be7e22.tar.gz
SM5803: Only enable automatic fast charge with connected battery
Refrain from enabling automatic fast charge until battery is not disconnected. Automatic fast charge may cause the board to brown out when no battery is connected and a heavy load or transient load happens. BRANCH=Dedede BUG=b:175074427 TEST=on lantis and drawcia, verify: - battery can come out of cutoff on MB port - board can boot with no battery on MB port Signed-off-by: Diana Z <dzigterman@chromium.org> Change-Id: I71b23b926bd319d4d9c87143395d9f33c173d442 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2601238 Tested-by: Tommy Chung <tommy.chung@quanta.corp-partner.google.com> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org>
Diffstat (limited to 'driver/charger/sm5803.c')
-rw-r--r--driver/charger/sm5803.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c
index 49bfe382e0..7997dc09d8 100644
--- a/driver/charger/sm5803.c
+++ b/driver/charger/sm5803.c
@@ -69,6 +69,13 @@ static int active_restart_port = CHARGE_PORT_NONE;
*/
static int attempt_bfet_enable;
+/*
+ * Note if auto fast charge for the primary port is disabled due to a
+ * disconnected battery, at re-enable auto fast charge later when the battery
+ * has connected.
+ */
+static bool fast_charge_disabled;
+
#define CHARGING_FAILURE_MAX_COUNT 5
#define CHARGING_FAILURE_INTERVAL MINUTE
@@ -281,9 +288,23 @@ enum ec_error_list sm5803_vbus_sink_enable(int chgnum, int enable)
rv |= test_write8(chgnum, 0x44, 0x2);
rv |= main_write8(chgnum, 0x1F, 0);
}
- rv = sm5803_flow2_update(chgnum,
+ /*
+ * Only enable auto fast charge when a battery is
+ * connected and out of cutoff.
+ */
+ if (battery_get_disconnect_state() ==
+ BATTERY_NOT_DISCONNECTED) {
+ rv = sm5803_flow2_update(chgnum,
SM5803_FLOW2_AUTO_ENABLED,
MASK_SET);
+ fast_charge_disabled = false;
+ } else {
+ rv = sm5803_flow2_update(chgnum,
+ SM5803_FLOW2_AUTO_TRKL_EN |
+ SM5803_FLOW2_AUTO_PRECHG_EN,
+ MASK_SET);
+ fast_charge_disabled = true;
+ }
} else {
if (dev_id >= 3) {
/* Touch of magic on the primary charger */
@@ -1266,6 +1287,15 @@ static enum ec_error_list sm5803_set_voltage(int chgnum, int voltage)
rv |= chg_write8(chgnum, SM5803_REG_VBAT_FAST_MSB, (regval >> 3));
rv |= chg_write8(chgnum, SM5803_REG_VBAT_FAST_LSB, (regval & 0x7));
+ /* Once battery is connected, set up fast charge enable */
+ if (fast_charge_disabled && chgnum == CHARGER_PRIMARY &&
+ battery_get_disconnect_state() == BATTERY_NOT_DISCONNECTED) {
+ rv = sm5803_flow2_update(chgnum,
+ SM5803_FLOW2_AUTO_ENABLED,
+ MASK_SET);
+ fast_charge_disabled = false;
+ }
+
if (IS_ENABLED(CONFIG_OCPC) && chgnum != CHARGER_PRIMARY) {
/*
* Check to see if the BFET is enabled. If not, enable it by