summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYilun Lin <yllin@google.com>2018-10-01 16:39:16 +0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-10-31 21:20:43 +0000
commit319ae8c6240f698574163388a197b0b24b9d66db (patch)
tree9ee77897825b6e424b76d42fe8861baac66ebe82
parent417695542129ade7e452c1297d8957fc0da071f4 (diff)
downloadchrome-ec-319ae8c6240f698574163388a197b0b24b9d66db.tar.gz
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: <unkn> Device: <BATT> Chem: <unkn> 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 <yllin@google.com> Reviewed-on: https://chromium-review.googlesource.com/1253372 Commit-Ready: Yilun Lin <yllin@chromium.org> Tested-by: Yilun Lin <yllin@chromium.org> Reviewed-by: Philip Chen <philipchen@chromium.org> Reviewed-by: Nicolas Boichat <drinkcat@chromium.org> (cherry picked from commit fbb47e2bc63c1b84e1509b50e2169018a2701364) Reviewed-on: https://chromium-review.googlesource.com/c/1311513 Commit-Queue: Philip Chen <philipchen@chromium.org> Tested-by: Philip Chen <philipchen@chromium.org> Trybot-Ready: Philip Chen <philipchen@chromium.org>
-rw-r--r--driver/battery/max17055.c24
1 files changed, 13 insertions, 11 deletions
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, &reg))
batt->flags |= BATT_FLAG_BAD_TEMPERATURE;
@@ -299,15 +310,6 @@ void battery_get_params(struct batt_params *batt)
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).
*/