diff options
author | Furquan Shaikh <furquan@chromium.org> | 2017-11-23 10:15:33 -0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2017-11-30 20:30:11 -0800 |
commit | 55b87f4847394935d05cdefab2dc18dff9d6fa0e (patch) | |
tree | 7e626bfb4467e738cc8898fb8912d341a3f9c131 | |
parent | 925ecb4fd225142304e00b020d20dbbf32d27828 (diff) | |
download | chrome-ec-55b87f4847394935d05cdefab2dc18dff9d6fa0e.tar.gz |
charge_state: Change CHARGE_MAX_SLEEP_USEC to 1 minute
CHARGE_MAX_SLEEP_USEC was originally set to 1 minute (i.e. equal to
POLL_PERIOD_VERY_LONG) in CL:191767. However, during re-factoring in
CL:193876 it got changed to 1 second as charge_state_v1 used this
value. Looking at the way CHARGE_MAX_SLEEP_USEC is used, value of 1
minute makes more sense because sleep_usec could be set to
POLL_PERIOD_VERY_LONG when device is off or suspended. With the
current logic in suspend/off state, sleep_usec is set to
POLL_PERIOD_VERY_LONG and immediately gets reset to
CHARGE_MAX_SLEEP_USEC in charger_task.
This change fixes the above behavior by defining CHARGE_MAX_SLEEP_USEC
as 1 minute. As a side-effect of this, we might not wake up early
enough in case of critical battery. Thus, check if we need to shutdown
on critical battery and adjust sleep time accordingly.
BUG=b:69695376
BRANCH=None
TEST=make -j buildall
Change-Id: Ieba7279dc4b02c3d64022c3c5ac09fb869a3632d
Signed-off-by: Furquan Shaikh <furquan@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/788181
Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r-- | common/charge_state_v2.c | 19 | ||||
-rw-r--r-- | include/charge_state.h | 2 |
2 files changed, 17 insertions, 4 deletions
diff --git a/common/charge_state_v2.c b/common/charge_state_v2.c index 8c6fdab03b..441d85977d 100644 --- a/common/charge_state_v2.c +++ b/common/charge_state_v2.c @@ -515,7 +515,7 @@ static inline int battery_too_low(void) * Send host event to the AP if the battery is temperature or charge level * is critical. Force-shutdown if the problem isn't corrected after timeout. */ -static void shutdown_on_critical_battery(void) +static int shutdown_on_critical_battery(void) { int batt_temp_c; int battery_critical = 0; @@ -539,7 +539,7 @@ static void shutdown_on_critical_battery(void) if (!battery_critical) { /* Reset shutdown warning time */ shutdown_warning_time.val = 0; - return; + return battery_critical; } if (!shutdown_warning_time.val) { @@ -569,6 +569,8 @@ static void shutdown_on_critical_battery(void) chipset_force_shutdown(); } } + + return battery_critical; } /* @@ -632,6 +634,7 @@ static int get_desired_input_current(enum battery_present batt_present, void charger_task(void *u) { int sleep_usec; + int battery_critical; int need_static = 1; const struct charger_info * const info = charger_get_info(); @@ -658,6 +661,7 @@ void charger_task(void *u) curr.ts = get_time(); sleep_usec = 0; problems_exist = 0; + battery_critical = 0; curr.ac = extpower_is_present(); if (curr.ac != prev_ac) { if (curr.ac) { @@ -763,7 +767,7 @@ void charger_task(void *u) curr.batt_is_charging = curr.ac && (curr.batt.current >= 0); /* Don't let the battery hurt itself. */ - shutdown_on_critical_battery(); + battery_critical = shutdown_on_critical_battery(); if (!curr.ac) { curr.state = ST_DISCHARGE; @@ -970,6 +974,15 @@ wait_for_it: else if (sleep_usec > CHARGE_MAX_SLEEP_USEC) sleep_usec = CHARGE_MAX_SLEEP_USEC; + /* + * If battery is critical, ensure that the sleep time is not + * very long since we might want to hibernate or cut-off + * battery sooner. + */ + if (battery_critical && + (sleep_usec > CRITICAL_BATTERY_SHUTDOWN_TIMEOUT_US)) + sleep_usec = CRITICAL_BATTERY_SHUTDOWN_TIMEOUT_US; + task_wait_event(sleep_usec); } } diff --git a/include/charge_state.h b/include/charge_state.h index fb1a41527a..bcf9071d6b 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -19,7 +19,7 @@ #define CHARGE_POLL_PERIOD_CHARGE (MSEC * 250) #define CHARGE_POLL_PERIOD_SHORT (MSEC * 100) #define CHARGE_MIN_SLEEP_USEC (MSEC * 50) -#define CHARGE_MAX_SLEEP_USEC SECOND +#define CHARGE_MAX_SLEEP_USEC MINUTE /* Power states */ enum charge_state { |