From a7bae3588cb976405b90677a324de06c71fa3f48 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Tue, 16 Dec 2014 09:54:54 -0800 Subject: power_button_x86: Inhibit AP power-on if battery level is too low Allow CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON to be defined at the board level to be the minimum battery percentage required for power-on. If the battery level is below the threshold, or if the battery is missing, power button presses will be ignored. BUG=chrome-os-partner:31127 TEST=Manual on Samus with subsequent commit. Verify that AP continues to boot normally when charge level exceeds CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON. Verify that power button presses are ignored when the charge level is below the threshold, and we return to G3. BRANCH=Samus Change-Id: I0ff3f7ddabf38080332470e172c8b2e307bf1655 Signed-off-by: Shawn Nematbakhsh Reviewed-on: https://chromium-review.googlesource.com/236021 Reviewed-by: Alec Berg --- common/charge_state_v1.c | 13 +++++++++++++ common/charge_state_v2.c | 13 +++++++++++++ common/power_button_x86.c | 6 ++++-- include/charge_state.h | 6 ++++++ 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/common/charge_state_v1.c b/common/charge_state_v1.c index b4ecb74c5b..9be0d47c15 100644 --- a/common/charge_state_v1.c +++ b/common/charge_state_v1.c @@ -681,6 +681,19 @@ int charge_want_shutdown(void) charge_get_percent() < BATTERY_LEVEL_SHUTDOWN; } +int charge_prevent_power_on(void) +{ + int prevent_power_on = 0; +#ifdef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON + /* Require a minimum battery level to power on */ + if (battery_is_present() == BP_NO || + charge_get_percent() < CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON) + prevent_power_on = 1; +#endif + /* Factory override: Always allow power on if WP is disabled */ + return prevent_power_on && system_is_locked(); +} + static int charge_force_idle(int enable) { if (enable) { diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 531cc8bf83..5dd30856d7 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -812,6 +812,19 @@ int charge_want_shutdown(void) (curr.batt.state_of_charge < BATTERY_LEVEL_SHUTDOWN); } +int charge_prevent_power_on(void) +{ + int prevent_power_on = 0; +#ifdef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON + /* Require a minimum battery level to power on */ + if (curr.batt.is_present == BP_NO || + curr.batt.state_of_charge < CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON) + prevent_power_on = 1; +#endif + /* Factory override: Always allow power on if WP is disabled */ + return prevent_power_on && system_is_locked(); +} + enum charge_state charge_get_state(void) { switch (curr.state) { diff --git a/common/power_button_x86.c b/common/power_button_x86.c index 8b221b8e30..9570d9c3b3 100644 --- a/common/power_button_x86.c +++ b/common/power_button_x86.c @@ -116,10 +116,12 @@ static void set_pwrbtn_to_pch(int high) { /* * If the battery is discharging and low enough we'd shut down the - * system, don't press the power button. + * system, don't press the power button. Also, don't press the + * power button if the battery is charging but the battery level + * is too low. */ #ifdef CONFIG_CHARGER - if (!high && charge_want_shutdown()) { + if (!high && (charge_want_shutdown() || charge_prevent_power_on())) { CPRINTS("PB PCH pwrbtn ignored due to battery level"); high = 1; } diff --git a/include/charge_state.h b/include/charge_state.h index 5c81decf10..fea4231def 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -97,6 +97,12 @@ int charge_get_percent(void); */ int charge_want_shutdown(void); +/** + * Return non-zero if the battery level is too low to allow power on, even if + * a charger is attached. + */ +int charge_prevent_power_on(void); + /** * Get the last polled battery/charger temperature. * -- cgit v1.2.1