summaryrefslogtreecommitdiff
path: root/common/charge_state_v2.c
diff options
context:
space:
mode:
authorNicolas Boichat <drinkcat@chromium.org>2018-03-09 14:46:05 +0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-03-10 00:39:06 +0000
commit0866be8c1f56b75ac1fce0a06be99750c005f4c1 (patch)
treedf58e5cc3f01a470cc385d1829a5bcb59d57f0b3 /common/charge_state_v2.c
parentd97accd2bf9d31d4b299a514d1a1f050bb7eb4e0 (diff)
downloadchrome-ec-0866be8c1f56b75ac1fce0a06be99750c005f4c1.tar.gz
charge_state_v2: When suspended, charge base if battery critical
The exact behaviour still needs to be optimized based on actual power consumption (for example, it might be worth providing power to base without charging it, or charge it a bit more, then let it slowly discharge). BRANCH=none BUG=b:71881017 BUG=b:74414928 TEST=Low base battery, check that lid provides power to it in S0 or suspend. TEST=Check that lid stops providing power in S5. Change-Id: Idf198ab1b4358827f9db6c0898234b6e2be45808 Signed-off-by: Nicolas Boichat <drinkcat@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/956982 Reviewed-by: Vincent Palatin <vpalatin@chromium.org> (cherry picked from commit 5734467674a57ddb48dd57bfb66869a8d9588ac9) Reviewed-on: https://chromium-review.googlesource.com/957933 Reviewed-by: Furquan Shaikh <furquan@chromium.org> Commit-Queue: Furquan Shaikh <furquan@chromium.org> Tested-by: Furquan Shaikh <furquan@chromium.org> Trybot-Ready: Furquan Shaikh <furquan@chromium.org>
Diffstat (limited to 'common/charge_state_v2.c')
-rw-r--r--common/charge_state_v2.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c
index 9e1db52790..26eeb5e0f2 100644
--- a/common/charge_state_v2.c
+++ b/common/charge_state_v2.c
@@ -458,6 +458,9 @@ static void charge_allocate_input_current_limit(void)
* but the value is currently wrong, especially during transitions.
*/
if (total_power <= 0) {
+ int base_critical = charge_base >= 0 &&
+ charge_base < db_policy.max_charge_base_batt_to_batt;
+
/* Discharging */
prev_base_battery_power = -1;
prev_lid_system_power = -1;
@@ -465,10 +468,14 @@ static void charge_allocate_input_current_limit(void)
/*
* System is suspended/off, let the lid and base run on their
- * own power.
+ * own power. However, if the base battery is critically low, we
+ * still want to provide power to the base, to make sure it
+ * stays alive to be able to wake the system on keyboard or
+ * touchpad events.
*/
- if (chipset_in_state(CHIPSET_STATE_ANY_OFF |
- CHIPSET_STATE_ANY_SUSPEND)) {
+ if (chipset_in_state(CHIPSET_STATE_ANY_OFF) ||
+ (chipset_in_state(CHIPSET_STATE_ANY_SUSPEND) &&
+ !base_critical)) {
set_base_lid_current(0, 0, 0, 0);
return;
}
@@ -485,9 +492,10 @@ static void charge_allocate_input_current_limit(void)
* Base battery is too low, apply power to it, and allow
* it to charge if it is critically low.
*
- * TODO(b:71881017): This will make the battery charge
- * oscillate between 3 and 4 percent, which might not be
- * great for battery life. We need some hysteresis.
+ * TODO(b:71881017): When suspended, this will make the
+ * battery charge oscillate between 3 and 4 percent,
+ * which might not be great for battery life. We need
+ * some hysteresis.
*/
/*
* TODO(b:71881017): Precompute (ideally, at build time)
@@ -500,10 +508,7 @@ static void charge_allocate_input_current_limit(void)
int lid_current = add_margin(base_current,
db_policy.margin_otg_current);
- int allow_charge = charge_base >= 0 &&
- charge_base < db_policy.max_charge_base_batt_to_batt;
-
- set_base_lid_current(base_current, allow_charge,
+ set_base_lid_current(base_current, base_critical,
-lid_current, 0);
}