diff options
author | Wai-Hong Tam <waihong@google.com> | 2020-08-10 14:02:25 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-11 04:35:34 +0000 |
commit | 1c3aacb46b7b800b9c285692916d2a785dadcfd2 (patch) | |
tree | 56c5e369516f42fcb51b591e10936db9e0332d75 /power | |
parent | 62d62a164edce7b3462671d254bfdc5c6be72f81 (diff) | |
download | chrome-ec-1c3aacb46b7b800b9c285692916d2a785dadcfd2.tar.gz |
sc7180: Cancel the power button timer during the power state transition
A timer is created in the check_for_power_off_event(), which waits for
the power button long press. Should cancel the timer during the power
state transition; otherwise, EC will crash.
The S3 state calls the check_for_power_off_event() too. So cancel the
timer during S3->S0 and S3->S5.
BRANCH=None
BUG=b:163367454
TEST=Checked the bug scenario:
* In VT2, run powerd_dbus_suspend and EC transits the state to S3.
* Press power button
* EC transits the state to S0; no crash.
TEST=Tested the normal shutdown case:
* Hold the power button
* After 8s, EC transits to S3 and then S5 after the power button is
released.
TEST=Tested the change in check_for_power_off_event():
* Hold the power button
* In VT2, run "shutdown -H now" which makes POWER_GOOD drop
* EC transits to S3 and then S5 after the power button is released
Change-Id: Ia279e890954cf77f94ae8907a2782f94265c849a
Signed-off-by: Wai-Hong Tam <waihong@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2346600
Reviewed-by: Stephen Boyd <swboyd@chromium.org>
Diffstat (limited to 'power')
-rw-r--r-- | power/sc7180.c | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/power/sc7180.c b/power/sc7180.c index aa62c20ca2..77c3a3e7f1 100644 --- a/power/sc7180.c +++ b/power/sc7180.c @@ -743,9 +743,6 @@ static uint8_t check_for_power_off_event(void) /* POWER_GOOD released by AP : shutdown immediately */ if (!power_has_signals(IN_POWER_GOOD)) { - if (power_button_was_pressed) - timer_cancel(TASK_ID_CHIPSET); - CPRINTS("POWER_GOOD is lost"); return POWER_OFF_BY_POWER_GOOD_LOST; } @@ -753,6 +750,19 @@ static uint8_t check_for_power_off_event(void) return POWER_OFF_CANCEL; } +/** + * Cancel the power button timer. + * + * The timer was previously created in the check_for_power_off_event(), + * which waited for the power button long press. Should cancel the timer + * during the power state transition; otherwise, EC will crash. + */ +static inline void cancel_power_button_timer(void) +{ + if (power_button_was_pressed) + timer_cancel(TASK_ID_CHIPSET); +} + /*****************************************************************************/ /* Chipset interface */ @@ -989,6 +999,8 @@ enum power_state power_handle_state(enum power_state state) break; case POWER_S3S0: + cancel_power_button_timer(); + #ifdef CONFIG_CHIPSET_RESUME_INIT_HOOK /* * Notify the RESUME_INIT hooks, i.e. enabling SPI driver @@ -1019,12 +1031,7 @@ enum power_state power_handle_state(enum power_state state) break; case POWER_S0S3: - /* - * If the power button is pressing, we need cancel the long - * press timer, otherwise EC will crash. - */ - if (power_button_was_pressed) - timer_cancel(TASK_ID_CHIPSET); + cancel_power_button_timer(); #ifdef CONFIG_CHIPSET_RESUME_INIT_HOOK /* @@ -1048,6 +1055,8 @@ enum power_state power_handle_state(enum power_state state) return POWER_S3; case POWER_S3S5: + cancel_power_button_timer(); + /* Call hooks before we drop power rails */ hook_notify(HOOK_CHIPSET_SHUTDOWN); |