summaryrefslogtreecommitdiff
path: root/common/power_button_x86.c
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2018-09-14 02:22:03 -0700
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2018-09-25 03:19:38 +0000
commit0875fe80f8f895374f6b994a24cd4f66252627be (patch)
tree16a558f00a58c7c2e48450de77e20cb15ef8d72e /common/power_button_x86.c
parent7087ab2a0859a5ceba42367887ad998253081631 (diff)
downloadchrome-ec-0875fe80f8f895374f6b994a24cd4f66252627be.tar.gz
power_button_x86: Check init-on timeout since PB task start time
When PB state machine is in PWRBTN_STATE_INIT_ON, it first checks if current time (i.e. time since EC reset) is greater than CONFIG_POWER_BUTTON_INIT_TIMEOUT (which is typically 1 second). If yes, then it assumes that it is not okay to bring the AP out of reset (possibly because battery, charger and PD are not initialized in time). However, in case of manual recovery using power and volume buttons, user could be holding the buttons for > 30 seconds. This is required to allow user to request recovery with hardware reinitialization. In such cases, it is not right to check for current time against the timeout value of 1 second. Instead, the timeout should be considered since EC started all the tasks. This change records the timestamp when power button task starts and then uses that time to calculate the actual timeout in PWRBTN_STATE_INIT_ON. BUG=b:113165243 BRANCH=nocturne TEST=None Change-Id: Ifd5211cbd1a2fa56c9affcf656df65b11192c519 Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://chromium-review.googlesource.com/1226228 Commit-Ready: Furquan Shaikh <furquan@chromium.org> Tested-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Aseda Aboagye <aaboagye@chromium.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> (cherry picked from commit de0629592aef6e9d77821bb89b62d2a733675e2b) Reviewed-on: https://chromium-review.googlesource.com/1242208 Reviewed-by: Martin Roth <martinroth@chromium.org> Commit-Queue: Martin Roth <martinroth@chromium.org> Tested-by: Martin Roth <martinroth@chromium.org>
Diffstat (limited to 'common/power_button_x86.c')
-rw-r--r--common/power_button_x86.c29
1 files changed, 27 insertions, 2 deletions
diff --git a/common/power_button_x86.c b/common/power_button_x86.c
index 6a2c56cd81..04d43f9b9b 100644
--- a/common/power_button_x86.c
+++ b/common/power_button_x86.c
@@ -113,6 +113,18 @@ static const char * const state_names[] = {
static uint64_t tnext_state;
/*
+ * Record the time when power button task starts. It can be used by any code
+ * path that needs to compare the current time with power button task start time
+ * to identify any timeouts e.g. PB state machine checks current time to
+ * identify if it should wait more for charger and battery to be initialized. In
+ * case of recovery using buttons (where the user could be holding the buttons
+ * for >30seconds), it is not right to compare current time with the time when
+ * EC was reset since the tasks would not have started. Hence, this variable is
+ * being added to record the time at which power button task starts.
+ */
+static uint64_t tpb_task_start;
+
+/*
* Determines whether to execute power button pulse (t0 stage)
*/
static int power_button_pulse_enabled = 1;
@@ -312,9 +324,16 @@ static void state_machine(uint64_t tnow)
/*
* Before attempting to power the system on, we need to wait for
* charger and battery to be ready to supply sufficient power.
- * Check every 100 milliseconds, and give up after 1 second.
+ * Check every 100 milliseconds, and give up
+ * CONFIG_POWER_BUTTON_INIT_TIMEOUT seconds after the PB task
+ * was started. Here, it is important to check the current time
+ * against PB task start time to prevent unnecessary timeouts
+ * happening in recovery case where the tasks could start as
+ * late as 30 seconds after EC reset.
*/
- if (tnow > CONFIG_POWER_BUTTON_INIT_TIMEOUT * SECOND) {
+ if (tnow >
+ (tpb_task_start +
+ CONFIG_POWER_BUTTON_INIT_TIMEOUT * SECOND)) {
pwrbtn_state = PWRBTN_STATE_IDLE;
break;
}
@@ -394,6 +413,12 @@ void power_button_task(void *u)
uint64_t t;
uint64_t tsleep;
+ /*
+ * Record the time when the task starts so that the state machine can
+ * use this to identify any timeouts.
+ */
+ tpb_task_start = get_time().val;
+
while (1) {
t = get_time().val;