summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAseda Aboagye <aaboagye@google.com>2020-09-25 10:21:21 -0700
committerJustin TerAvest <teravest@chromium.org>2020-09-28 20:30:06 +0000
commitb2af3aaad8b19b4facaa2fb8f06436f3a214fdba (patch)
tree5e1376e86c62f7ca9227f3368c74620c67bc7c2b
parentb3a033d2dfdc4bfe2b2e82207fea969cf3caee33 (diff)
downloadchrome-ec-b2af3aaad8b19b4facaa2fb8f06436f3a214fdba.tar.gz
sm5803: Enable BFET when disabled
When coming out of cutoff, the BFET can be disabled if the system is powered up from an auxiliary charge port and the battery is dead. Our attempts to regulate VSYS won't actually cause the battery to come out of cutoff. This commit adds a check to see if the BFET is disabled and tries to enable it such that the battery can actually be charged. BUG=b:168730125, b:168135339 BRANCH=None TEST=Build and flash drawcia, cutoff battery, wait 15s, plug in AC on C1, verify that DUT is able to revive battery pack and start charging. Verify that this works at 0% SoC and 50%. Signed-off-by: Aseda Aboagye <aaboagye@google.com> Change-Id: Ie452f1e82f39fb7b525db60e198ab584e2b1564e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2431693 Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Diana Z <dzigterman@chromium.org> Commit-Queue: Aseda Aboagye <aaboagye@chromium.org>
-rw-r--r--driver/charger/sm5803.c35
-rw-r--r--driver/charger/sm5803.h3
2 files changed, 32 insertions, 6 deletions
diff --git a/driver/charger/sm5803.c b/driver/charger/sm5803.c
index 8bfe5fbcf1..cf08d7d64e 100644
--- a/driver/charger/sm5803.c
+++ b/driver/charger/sm5803.c
@@ -1081,18 +1081,41 @@ static enum ec_error_list sm5803_get_voltage(int chgnum, int *voltage)
static enum ec_error_list sm5803_set_voltage(int chgnum, int voltage)
{
enum ec_error_list rv;
- int volt_bits;
+ int regval;
+ static int attempt_bfet_enable;
- volt_bits = SM5803_VOLTAGE_TO_REG(voltage);
+ regval = SM5803_VOLTAGE_TO_REG(voltage);
/*
* Note: Set both voltages on both chargers. Vbat will only be used on
* primary, which enables charging.
*/
- rv = chg_write8(chgnum, SM5803_REG_VSYS_PREREG_MSB, (volt_bits >> 3));
- rv |= chg_write8(chgnum, SM5803_REG_VSYS_PREREG_LSB, (volt_bits & 0x7));
- rv |= chg_write8(chgnum, SM5803_REG_VBAT_FAST_MSB, (volt_bits >> 3));
- rv |= chg_write8(chgnum, SM5803_REG_VBAT_FAST_LSB, (volt_bits & 0x7));
+ rv = chg_write8(chgnum, SM5803_REG_VSYS_PREREG_MSB, (regval >> 3));
+ rv |= chg_write8(chgnum, SM5803_REG_VSYS_PREREG_LSB, (regval & 0x7));
+ rv |= chg_write8(chgnum, SM5803_REG_VBAT_FAST_MSB, (regval >> 3));
+ rv |= chg_write8(chgnum, SM5803_REG_VBAT_FAST_LSB, (regval & 0x7));
+
+ if (IS_ENABLED(CONFIG_OCPC) && chgnum != CHARGER_PRIMARY) {
+ /*
+ * Check to see if the BFET is enabled. If not, enable it by
+ * toggling linear mode on the primary charger. The BFET can be
+ * disabled if the system is powered up from an auxiliary charge
+ * port and the battery is dead.
+ */
+ rv |= chg_read8(CHARGER_PRIMARY, SM5803_REG_LOG1, &regval);
+ if (!(regval & SM5803_BATFET_ON) && !attempt_bfet_enable) {
+ CPRINTS("SM5803: Attempting to turn on BFET");
+ cflush();
+ rv |= sm5803_flow1_update(CHARGER_PRIMARY,
+ SM5803_FLOW1_LINEAR_CHARGE_EN,
+ MASK_SET);
+ rv |= sm5803_flow1_update(CHARGER_PRIMARY,
+ SM5803_FLOW1_LINEAR_CHARGE_EN,
+ MASK_CLR);
+ attempt_bfet_enable = 1;
+ sm5803_vbus_sink_enable(chgnum, 1);
+ }
+ }
return rv;
}
diff --git a/driver/charger/sm5803.h b/driver/charger/sm5803.h
index 93cf9a462d..a6b3d6aaa7 100644
--- a/driver/charger/sm5803.h
+++ b/driver/charger/sm5803.h
@@ -294,6 +294,9 @@ enum sm5803_charger_modes {
/* LSB is in 1.67mOhm steps. */
#define SM5803_REG_IR_COMP2 0x40
+#define SM5803_REG_LOG1 0x42
+#define SM5803_BATFET_ON BIT(2)
+
#define SM5803_REG_PHOT1 0x72
#define SM5803_PHOT1_IBAT_PHOT_COMP_EN BIT(0)
#define SM5803_PHOT1_IBUS_PHOT_COMP_EN BIT(1)