From 4578166a89cd0205d67070496e63f3110a83fe2f Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Thu, 18 Jun 2015 16:23:47 -0700 Subject: [PATCH] charger: Inhibit power-on until charger is initialized It's sometimes desirable to boot without a battery, but we may brown out if we don't have sufficient current. Inhibit AP power-on, even if the system is unprotected, until our charger and current limit are initialized. BUG=chrome-os-partner:41258 TEST=Manual on reworked glados with subsequent commit. Remove battery and attach Zinger. Verify EC powers on and AP doesn't boot. Run `powerbtn`, verify that AP boots. Remove all power and attach battery, verify that EC powers on and AP boots. BRANCH=None Change-Id: Ifc3d16f8288a035854e9fd05812ce6de33170d6a Signed-off-by: Shawn Nematbakhsh Reviewed-on: https://chromium-review.googlesource.com/280563 Reviewed-by: Alec Berg --- common/charge_state_v2.c | 14 ++++++++++++-- include/charger.h | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index ece7800ead..d588ae3362 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -630,6 +630,8 @@ void charger_task(void) charger_get_params(&curr.chg); battery_get_params(&curr.batt); + curr.chg.flags |= CHG_FLAG_INITIALIZED; + /* Fake state of charge if necessary */ if (fake_state_of_charge >= 0) { curr.batt.state_of_charge = fake_state_of_charge; @@ -912,6 +914,8 @@ int charge_prevent_power_on(void) #ifdef CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON struct batt_params params; struct batt_params *current_batt_params = &curr.batt; + int charger_is_uninitialized = + !(curr.chg.flags & CHG_FLAG_INITIALIZED); /* If battery params seem uninitialized then retrieve them */ if (current_batt_params->is_present == BP_NOT_SURE) { @@ -923,9 +927,15 @@ int charge_prevent_power_on(void) current_batt_params->state_of_charge < CONFIG_CHARGER_MIN_BAT_PCT_FOR_POWER_ON) prevent_power_on = 1; + + /* + * Factory override: Always allow power on if WP is disabled, + * except when EC is starting up, due to brown out potential. + */ + prevent_power_on &= (system_is_locked() || charger_is_uninitialized); #endif - /* Factory override: Always allow power on if WP is disabled */ - return prevent_power_on && system_is_locked(); + + return prevent_power_on; } enum charge_state charge_get_state(void) diff --git a/include/charger.h b/include/charger.h index d29d66ed30..c73f0b6d33 100644 --- a/include/charger.h +++ b/include/charger.h @@ -49,6 +49,8 @@ void charger_get_params(struct charger_params *chg); #define CHG_FLAG_BAD_INPUT_CURRENT 0x00000004 #define CHG_FLAG_BAD_STATUS 0x00000008 #define CHG_FLAG_BAD_OPTION 0x00000010 +/* Bit to indicate that the charger data has been initialized */ +#define CHG_FLAG_INITIALIZED 0x00000020 /* All of the above CHG_FLAG_BAD_* bits */ #define CHG_FLAG_BAD_ANY 0x0000001f