From 4038bac6f39207dca025f8c333813ad77052b349 Mon Sep 17 00:00:00 2001 From: "ben.chen2@quanta.corp-partner.google.com" Date: Tue, 8 Oct 2019 19:44:32 +0800 Subject: power_button_x86: Make sure PWRBTN_STATE_INIT_ON base 100 milliseconds Fix sub function state_machine PWRBTN_STATE_INIT_ON case, should be first check charge_prevent_power_on until POWER Button Time out. BUG=b:141260790 BRANCH=Master TEST=check PB task timing with power on timing be sure the same time. Change-Id: I15a599773afe94e0730755dd60674cb4c4ea27d6 Signed-off-by: Ben Chen Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1847571 Reviewed-by: Jett Rink Reviewed-by: Tim Wawrzynczak Reviewed-by: Paul Fagerburg --- common/power_button_x86.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/common/power_button_x86.c b/common/power_button_x86.c index e5772d2f68..270d1ee2a4 100644 --- a/common/power_button_x86.c +++ b/common/power_button_x86.c @@ -321,33 +321,32 @@ static void state_machine(uint64_t tnow) pwrbtn_state = PWRBTN_STATE_IDLE; break; case PWRBTN_STATE_INIT_ON: - /* - * 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 - * 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 > - (tpb_task_start + - CONFIG_POWER_BUTTON_INIT_TIMEOUT * SECOND)) { - pwrbtn_state = PWRBTN_STATE_IDLE; - break; - } -#ifdef CONFIG_CHARGER /* - * If not able to power on, try again later, to allow time for - * charger, battery and USB-C PD initialization. + * Before attempting to power the system on, we need to allow + * time for charger, battery and USB-C PD initialization to be + * ready to supply sufficient power. 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 (charge_prevent_power_on(0)) { - tnext_state = tnow + 100 * MSEC; - break; + + if (!IS_ENABLED(CONFIG_CHARGER) || charge_prevent_power_on(0)) { + if (tnow > + (tpb_task_start + + CONFIG_POWER_BUTTON_INIT_TIMEOUT * SECOND)) { + pwrbtn_state = PWRBTN_STATE_IDLE; + break; + } + + if (IS_ENABLED(CONFIG_CHARGER)) { + tnext_state = tnow + 100 * MSEC; + break; + } } -#endif /* * Power the system on if possible. Gating due to insufficient -- cgit v1.2.1