summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/charge_state.c38
-rw-r--r--include/battery.h7
2 files changed, 33 insertions, 12 deletions
diff --git a/common/charge_state.c b/common/charge_state.c
index e13f8969ce..7612f91036 100644
--- a/common/charge_state.c
+++ b/common/charge_state.c
@@ -109,16 +109,17 @@ static void update_battery_info(void)
*/
static void poweroff_wait_ac(int hibernate_ec)
{
- /* Shutdown the main processor */
if (chipset_in_state(CHIPSET_STATE_ON)) {
- CPRINTF("[%T force shutdown to avoid damaging battery]\n");
+ /*
+ * Shut down the AP. The EC will hibernate after the AP shuts
+ * down.
+ */
+ CPRINTF("[%T charge force shutdown due to low battery]\n");
chipset_force_shutdown();
host_set_single_event(EC_HOST_EVENT_BATTERY_SHUTDOWN);
- }
-
- /* If battery level is critical, hibernate the EC too */
- if (hibernate_ec) {
- CPRINTF("[%T force EC hibernate to avoid damaging battery]\n");
+ } else if (hibernate_ec) {
+ /* If battery level is critical, hibernate the EC */
+ CPRINTF("[%T charge force EC hibernate due to low battery]\n");
system_hibernate(0, 0);
}
}
@@ -244,8 +245,7 @@ static int state_common(struct power_state_context *ctx)
!(curr->error & F_BATTERY_STATE_OF_CHARGE)) ||
(batt->voltage <= ctx->battery->voltage_min &&
!(curr->error & F_BATTERY_VOLTAGE)))
- poweroff_wait_ac(batt->state_of_charge <
- BATTERY_LEVEL_HIBERNATE_EC ? 1 : 0);
+ poweroff_wait_ac(1);
}
/* Check battery presence */
@@ -837,6 +837,22 @@ static void charge_init(void)
}
DECLARE_HOOK(HOOK_INIT, charge_init, HOOK_PRIO_DEFAULT);
+
+static void charge_shutdown(void)
+{
+ /* Hibernate immediately if battery level is too low */
+ if (charge_want_shutdown()) {
+ CPRINTF("[%T charge force EC hibernate after"
+ " shutdown due to low battery]\n");
+ system_hibernate(0, 0);
+ }
+}
+/*
+ * Run the charge shutdown hook last, since when it hibernates no subsequent
+ * hooks would be run.
+ */
+DECLARE_HOOK(HOOK_CHIPSET_SHUTDOWN, charge_shutdown, HOOK_PRIO_LAST);
+
/*****************************************************************************/
/* Host commands */
@@ -916,6 +932,10 @@ static int command_battfake(int argc, char **argv)
else
ccprintf("Reporting fake battery level %d%%\n",
fake_state_of_charge);
+
+ /* Wake charger task immediately to see new level */
+ task_wake(TASK_ID_CHARGER);
+
return EC_SUCCESS;
}
DECLARE_CONSOLE_COMMAND(battfake, command_battfake,
diff --git a/include/battery.h b/include/battery.h
index da4071e158..50b4e53f7c 100644
--- a/include/battery.h
+++ b/include/battery.h
@@ -23,10 +23,11 @@
* level.
*/
#define BATTERY_LEVEL_CRITICAL 5
-/* Shut down main processor when discharging and battery level < this level */
+/*
+ * Shut down main processor and/or hibernate EC when discharging and battery
+ * level < this level.
+ */
#define BATTERY_LEVEL_SHUTDOWN 3
-/* Hibernate EC immediately when discharging and battery level < this level */
-#define BATTERY_LEVEL_HIBERNATE_EC 2
#endif /* __CROS_EC_BATTERY_H */