From 7ce07a78350500d3b60f05bf5b1c132fc2910d8f Mon Sep 17 00:00:00 2001 From: Randall Spangler Date: Tue, 7 Feb 2012 09:23:38 -0800 Subject: [PATCH] Fix power button being held down for 8 sec Signed-off-by: Randall Spangler BUG=chrome-os-partner:7932 TEST=hold down power button >8 sec; PCH_PWRBTNn should stay low Change-Id: If3168984982343735f0c31fb5951374808eb1caf --- chip/lm4/power_button.c | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/chip/lm4/power_button.c b/chip/lm4/power_button.c index 4beed7e47b..4b3e3b4edc 100644 --- a/chip/lm4/power_button.c +++ b/chip/lm4/power_button.c @@ -28,11 +28,11 @@ struct debounce_isr_t debounce_isr[DEBOUNCE_ISR_ID_MAX]; enum power_button_state { PWRBTN_STATE_STOPPED = 0, - PWRBTN_STATE_START = 1, - PWRBTN_STATE_T0 = 2, - PWRBTN_STATE_T1 = 3, - PWRBTN_STATE_T2 = 4, - PWRBTN_STATE_STOPPING = 5, + PWRBTN_STATE_START, + PWRBTN_STATE_T0, + PWRBTN_STATE_T1, + PWRBTN_STATE_HELD_DOWN, + PWRBTN_STATE_STOPPING, }; static enum power_button_state pwrbtn_state = PWRBTN_STATE_STOPPED; /* The next timestamp to move onto next state if power button is still pressed. @@ -41,7 +41,6 @@ static timestamp_t pwrbtn_next_ts = {0}; #define PWRBTN_DELAY_T0 32000 /* 32ms */ #define PWRBTN_DELAY_T1 (4000000 - PWRBTN_DELAY_T0) /* 4 secs - t0 */ -#define PWRBTN_DELAY_T2 4000000 /* 4 secs */ static void lid_switch_isr(void) @@ -61,7 +60,7 @@ static void lid_switch_isr(void) * * PWRBTN# --- --------- ---- * to PCH |__| |___________| - * t0 t1 t2 + * t0 t1 held down */ static void set_pwrbtn_to_pch(int high) { @@ -88,8 +87,7 @@ static void pwrbtn_sm_stop(void) static void pwrbtn_sm_handle(timestamp_t current) { /* Not the time to move onto next state */ - if (pwrbtn_state == PWRBTN_STATE_STOPPED || - current.val < pwrbtn_next_ts.val) + if (current.val < pwrbtn_next_ts.val) return; switch (pwrbtn_state) { @@ -104,17 +102,16 @@ static void pwrbtn_sm_handle(timestamp_t current) set_pwrbtn_to_pch(1); break; case PWRBTN_STATE_T1: - pwrbtn_next_ts.val = current.val + PWRBTN_DELAY_T2; - pwrbtn_state = PWRBTN_STATE_T2; + pwrbtn_state = PWRBTN_STATE_HELD_DOWN; set_pwrbtn_to_pch(0); break; - case PWRBTN_STATE_T2: - /* T2 has passed */ case PWRBTN_STATE_STOPPING: set_pwrbtn_to_pch(1); pwrbtn_state = PWRBTN_STATE_STOPPED; break; - default: + case PWRBTN_STATE_STOPPED: + case PWRBTN_STATE_HELD_DOWN: + /* Do nothing */ break; } }