summaryrefslogtreecommitdiff
path: root/common/charge_state_v2.c
diff options
context:
space:
mode:
authorShawn Nematbakhsh <shawnn@chromium.org>2015-01-15 14:49:04 -0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-01-16 09:45:05 +0000
commit93bb7195a8d85ff0b7078b794d24ebab2e6828ff (patch)
tree42abf679e692a0bd25c1290937eafe0545df10b9 /common/charge_state_v2.c
parent94515d9ee25c76c7813addff38599636d916931d (diff)
downloadchrome-ec-93bb7195a8d85ff0b7078b794d24ebab2e6828ff.tar.gz
charger v2: Don't report 0 battery charge if we're running off battery
Some batteries report 0 charge when their charge level is very low. powerd has a special interpretation of 0 charge, which causes low-battery shutdown to not occur. Work-around this powerd behavior by never reporting 0 charge if our battery is discharging. BUG=chrome-os-partner:35188 TEST=Manual on Samus. Drain battery to critically low level, verify that powerd correctly shuts down system. BRANCH=Samus Change-Id: I6bd50e038f0e22de7e7de754fa2ea459dc662f35 Signed-off-by: Shawn Nematbakhsh <shawnn@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/241101 Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r--common/charge_state_v2.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 85a0d661c6..13cf6d20ef 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -186,8 +186,17 @@ static void update_dynamic_battery_info(void)
if (!(curr.batt.flags & BATT_FLAG_BAD_CURRENT))
*memmap_rate = ABS(curr.batt.current);
- if (!(curr.batt.flags & BATT_FLAG_BAD_REMAINING_CAPACITY))
- *memmap_cap = curr.batt.remaining_capacity;
+ if (!(curr.batt.flags & BATT_FLAG_BAD_REMAINING_CAPACITY)) {
+ /*
+ * If we're running off the battery, it must have some charge.
+ * Don't report zero charge, as that has special meaning
+ * to Chrome OS powerd.
+ */
+ if (curr.batt.remaining_capacity == 0 && !curr.batt_is_charging)
+ *memmap_cap = 1;
+ else
+ *memmap_cap = curr.batt.remaining_capacity;
+ }
cap_changed = 0;
if (!(curr.batt.flags & BATT_FLAG_BAD_FULL_CAPACITY) &&