From fbb47e2bc63c1b84e1509b50e2169018a2701364 Mon Sep 17 00:00:00 2001 From: Yilun Lin Date: Mon, 1 Oct 2018 16:39:16 +0800 Subject: max17055: Invalidate all batt info when batt not present. BUG=b:117061273 TEST=on kukui, remove batt, connect pd, see battery output in console > battery Status: 0x0000 Param flags:000007fc Temp: 0x0000 = 0.0 K (-273.1 C) V: 0x0000 = 0 mV V-desired: 0x0000 = 0 mV I: 0x0000 = 0 mA I-desired: 0x0000 = 0 mA Charging: Not Allowed Charge: 0 % Manuf: Device: Chem: Serial: 0xffffffff V-design: 0x0f14 = 3860 mV Mode: (unsupported) Abs charge:(unsupported) Remaining: 6334 mAh Cap-full: 6910 mAh Design: 6910 mAh Time-full: 0h:0 Empty: 102h:23 TEST=on connect batt, connect pd, see battery output in console BRANCH=None Change-Id: Ied338266fa0f7713da408438460bc97d4db01e6f Signed-off-by: Yilun Lin Reviewed-on: https://chromium-review.googlesource.com/1253372 Commit-Ready: Yilun Lin Tested-by: Yilun Lin Reviewed-by: Philip Chen Reviewed-by: Nicolas Boichat --- driver/battery/max17055.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'driver/battery') diff --git a/driver/battery/max17055.c b/driver/battery/max17055.c index db8b798a3b..07ecc473dd 100644 --- a/driver/battery/max17055.c +++ b/driver/battery/max17055.c @@ -264,8 +264,19 @@ void battery_get_params(struct batt_params *batt) { int reg = 0; - /* Reset flags */ - batt->flags = 0; + /* Reset params */ + memset(batt, 0, sizeof(struct batt_params)); + /* + * 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; + else if (batt->is_present == BP_NO) + /* Battery is not present, gauge won't report useful info. */ + return; if (max17055_read(REG_TEMPERATURE, ®)) batt->flags |= BATT_FLAG_BAD_TEMPERATURE; @@ -298,15 +309,6 @@ void battery_get_params(struct batt_params *batt) if (battery_full_charge_capacity(&batt->full_capacity)) batt->flags |= BATT_FLAG_BAD_FULL_CAPACITY; - /* - * 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; - /* * Charging allowed if both desired voltage and current are nonzero * and battery isn't full (and we read them all correctly). -- cgit v1.2.1