diff options
-rw-r--r-- | driver/charger/sm5803.c | 35 | ||||
-rw-r--r-- | driver/charger/sm5803.h | 3 |
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, ®val); + 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) |