From c3deceae6aefd783aa1f1686c446ff6d2f228a95 Mon Sep 17 00:00:00 2001 From: Philip Chen Date: Thu, 22 Feb 2018 16:56:51 -0800 Subject: battery/max17055: Report battery presence properly For boards using max17055 and dumb battery, we can always read battery parameters from max17055 regs, even if the read values are out of whack. So it doesn't make sense to determine battery is present because we can read these parameters from max17055. Meanwhile, we have to set CONFIG.TSEL on max17055 as early as possible because this is required for max17055 to detect battery presense. BUG=b:72697658 BRANCH=scarlet TEST=boot scarlet rev3 w/o battery on Type-C/PD chargers Change-Id: Id190f0c2aa5bcd62dbe3edccca6460bf145cff01 Signed-off-by: Philip Chen Reviewed-on: https://chromium-review.googlesource.com/933702 Commit-Ready: Philip Chen Tested-by: Philip Chen Reviewed-by: Aseda Aboagye --- driver/battery/max17055.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c index 1a38c2748f..4836cf242d 100644 --- a/driver/battery/max17055.c +++ b/driver/battery/max17055.c @@ -206,10 +206,6 @@ enum battery_present battery_is_present(void) void battery_get_params(struct batt_params *batt) { int reg = 0; - const uint32_t flags_to_check = BATT_FLAG_BAD_TEMPERATURE | - BATT_FLAG_BAD_STATE_OF_CHARGE | - BATT_FLAG_BAD_VOLTAGE | - BATT_FLAG_BAD_CURRENT; /* Reset flags */ batt->flags = 0; @@ -245,12 +241,14 @@ void battery_get_params(struct batt_params *batt) if (battery_full_charge_capacity(&batt->full_capacity)) batt->flags |= BATT_FLAG_BAD_FULL_CAPACITY; - /* If any of those reads worked, the battery is responsive */ - if ((batt->flags & flags_to_check) != flags_to_check) { + /* + * Assuming the battery is responsive as long as + * max17055 finds battery is present. + */ + batt->is_present = battery_is_present(); + + if (batt->is_present == BP_YES) batt->flags |= BATT_FLAG_RESPONSIVE; - batt->is_present = BP_YES; - } else - batt->is_present = BP_NOT_SURE; /* * Charging allowed if both desired voltage and current are nonzero @@ -369,6 +367,14 @@ static void max17055_init(void) return; } + /* + * Set CONFIG.TSEL to measure temperature using external thermistor. + * Set it as early as possible because max17055 takes up to 1000ms to + * have the first reliable external temperature reading. + */ + MAX17055_READ_DEBUG(REG_CONFIG, ®); + MAX17055_WRITE_DEBUG(REG_CONFIG, (reg | CONF_TSEL)); + MAX17055_READ_DEBUG(REG_STATUS, ®); /* Check for POR */ @@ -396,10 +402,6 @@ static void max17055_init(void) MAX17055_READ_DEBUG(REG_STATUS, ®); MAX17055_WRITE_DEBUG(REG_STATUS, (reg & ~STATUS_POR)); - /* Set CONFIG.TSEL to measure temperature using external thermistor */ - MAX17055_READ_DEBUG(REG_CONFIG, ®); - MAX17055_WRITE_DEBUG(REG_CONFIG, (reg | CONF_TSEL)); - CPRINTS("max17055 configuration succeeded!"); } DECLARE_HOOK(HOOK_INIT, max17055_init, HOOK_PRIO_DEFAULT); -- cgit v1.2.1