diff --git a/chip/lm4/keyboard_scan.c b/chip/lm4/keyboard_scan.c index 86516b4c59..ae7223f69f 100644 --- a/chip/lm4/keyboard_scan.c +++ b/chip/lm4/keyboard_scan.c @@ -11,6 +11,7 @@ #include "keyboard.h" #include "keyboard_scan.h" #include "lpc.h" +#include "power_button.h" #include "registers.h" #include "system.h" #include "task.h" @@ -55,7 +56,6 @@ enum COLUMN_INDEX { static int enable_scanning = 1; static uint8_t raw_state[KB_COLS]; static uint8_t raw_state_at_boot[KB_COLS]; -static int recovery_key_pressed; /* Mask with 1 bits only for keys that actually exist */ static const uint8_t *actual_key_mask; @@ -276,12 +276,6 @@ static int check_boot_key(int index, int mask) } -int keyboard_scan_recovery_pressed(void) -{ - return recovery_key_pressed; -} - - int keyboard_scan_init(void) { volatile uint32_t scratch __attribute__((unused)); @@ -323,12 +317,13 @@ int keyboard_scan_init(void) /* Proto1 used ESC key */ /* TODO: (crosbug.com/p/9561) remove once proto1 obsolete */ if (system_get_board_version() == BOARD_VERSION_PROTO1) { - recovery_key_pressed = + power_set_recovery_pressed( check_boot_key(MASK_INDEX_REFRESH, - MASK_VALUE_REFRESH); + MASK_VALUE_REFRESH)); } else { - recovery_key_pressed = - check_boot_key(MASK_INDEX_ESC, MASK_VALUE_ESC); + power_set_recovery_pressed( + check_boot_key(MASK_INDEX_ESC, + MASK_VALUE_ESC)); } #ifdef CONFIG_FAKE_DEV_SWITCH @@ -352,8 +347,6 @@ void keyboard_scan_task(void) int key_press_timer = 0; print_raw_state("init state"); - if (recovery_key_pressed) - CPUTS("[KB recovery key pressed at init!]\n"); /* Enable interrupts */ task_enable_irq(KB_SCAN_ROW_IRQ); diff --git a/chip/lm4/power_button.c b/chip/lm4/power_button.c index 17bb369011..d4fac1b77a 100644 --- a/chip/lm4/power_button.c +++ b/chip/lm4/power_button.c @@ -7,6 +7,7 @@ #include "chipset.h" #include "console.h" +#include "ec_commands.h" #include "eoption.h" #include "gpio.h" #include "hooks.h" @@ -14,7 +15,6 @@ #include "keyboard.h" #include "keyboard_scan.h" #include "lpc.h" -#include "ec_commands.h" #include "power_button.h" #include "pwm.h" #include "system.h" @@ -98,17 +98,22 @@ static int debounced_lid_open; static int debounced_power_pressed; static int ac_changed; static int simulate_power_pressed; +static int keyboard_recovery_pressed; /* Update status of non-debounced switches */ static void update_other_switches(void) { + /* Make sure this is safe to call before power_button_init() */ + if (!memmap_switches) + return; + if (gpio_get_level(GPIO_WRITE_PROTECT) == 0) *memmap_switches |= EC_SWITCH_WRITE_PROTECT_DISABLED; else *memmap_switches &= ~EC_SWITCH_WRITE_PROTECT_DISABLED; - if (keyboard_scan_recovery_pressed()) + if (keyboard_recovery_pressed) *memmap_switches |= EC_SWITCH_KEYBOARD_RECOVERY; else *memmap_switches &= ~EC_SWITCH_KEYBOARD_RECOVERY; @@ -222,9 +227,10 @@ static void lid_switch_open(uint64_t tnow) update_backlight(); lpc_set_host_events(EC_HOST_EVENT_MASK(EC_HOST_EVENT_LID_OPEN)); - /* If the chipset is off, send a power button pulse to wake up the - * chipset. */ + /* If the chipset is off, clear keyboard recovery and send a power + * button pulse to wake up the chipset. */ if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) { + power_set_recovery_pressed(0); chipset_exit_hard_off(); set_pwrbtn_to_pch(0); pwrbtn_state = PWRBTN_STATE_LID_OPEN; @@ -298,7 +304,7 @@ static void set_initial_pwrbtn_state(void) if (system_get_reset_cause() == SYSTEM_RESET_RESET_PIN) { /* Reset triggered by keyboard-controlled reset, so override * the power button signal to the PCH. */ - if (keyboard_scan_recovery_pressed()) { + if (keyboard_recovery_pressed) { /* In recovery mode, so send a power button pulse to * the PCH so it powers on. */ CPRINTF("[%T PB init-recovery]\n"); @@ -349,6 +355,25 @@ int power_lid_open_debounced(void) return debounced_lid_open; } + +int power_recovery_pressed(void) +{ + return keyboard_recovery_pressed; +} + + +void power_set_recovery_pressed(int pressed) +{ + if (keyboard_recovery_pressed == pressed) + return; + + CPRINTF("[%T PB recovery button %s]\n", + pressed ? "pressed" : "released"); + + keyboard_recovery_pressed = pressed; + update_other_switches(); +} + /*****************************************************************************/ /* Task / state machine */ @@ -365,6 +390,8 @@ static void state_machine(uint64_t tnow) switch (pwrbtn_state) { case PWRBTN_STATE_PRESSED: if (chipset_in_state(CHIPSET_STATE_ANY_OFF)) { + /* Clear keyboard recovery */ + power_set_recovery_pressed(0); /* Chipset is off, so wake the chipset and send it a * long enough pulse to wake up. After that we'll * reflect the true power button state. If we don't diff --git a/common/vboot.c b/common/vboot.c index 89bcf73789..efd5651880 100644 --- a/common/vboot.c +++ b/common/vboot.c @@ -10,7 +10,7 @@ #include "eoption.h" #include "gpio.h" #include "host_command.h" -#include "keyboard_scan.h" +#include "power_button.h" #include "system.h" #include "timer.h" #include "util.h" @@ -94,9 +94,9 @@ static int maybe_jump_to_other_image(void) if (system_get_image_copy() != SYSTEM_IMAGE_RO) return 0; -#ifdef CONFIG_TASK_KEYSCAN +#ifdef CONFIG_TASK_POWERBTN /* Don't jump if recovery requested */ - if (keyboard_scan_recovery_pressed()) { + if (power_recovery_pressed()) { CPUTS("[Vboot staying in RO because recovery key pressed]\n"); return 0; } diff --git a/include/keyboard_scan.h b/include/keyboard_scan.h index 67e09e0312..590f482317 100644 --- a/include/keyboard_scan.h +++ b/include/keyboard_scan.h @@ -13,15 +13,14 @@ /* Initializes the module. */ int keyboard_scan_init(void); -/* Returns non-zero if recovery key was pressed at boot. */ +/* Returns non-zero if recovery key was pressed at boot. Used by st32m-based + * boards only; lm4-based boards use power_recovery_pressed(). */ int keyboard_scan_recovery_pressed(void); /* clear any saved keyboard state (empty FIFO, etc) */ void keyboard_clear_state(void); - /* Enables/disables keyboard matrix scan. */ void keyboard_enable_scanning(int enable); - -#endif /* __CROS_KEYBOARD_SCAN_H */ +#endif /* __CROS_EC_KEYBOARD_SCAN_H */ diff --git a/include/power_button.h b/include/power_button.h index 3bdb8a639d..a0bb85635e 100644 --- a/include/power_button.h +++ b/include/power_button.h @@ -25,4 +25,11 @@ int power_ac_present(void); * signal from the GPIO. */ int power_lid_open_debounced(void); +/* Return non-zero if the recovery button is pressed. */ +int power_recovery_pressed(void); + +/* Set the state of the recovery button. Called by the keyboard scanner at + * init if the keyboard recovery combo was pressed. */ +void power_set_recovery_pressed(int pressed); + #endif /* __CROS_EC_POWER_BUTTON_H */