summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Mooney <charliemooney@chromium.org>2012-07-24 17:29:27 -0700
committerGerrit <chrome-bot@google.com>2012-07-26 16:50:10 -0700
commit82cd5b0daad82b34c27a18a9d0a38f74977fbf59 (patch)
tree3c9c19e9dc6c8e870e2ed27a90595de8e34f15f8
parent247fdaf13d7d317465d6d04b015a309721e599a9 (diff)
downloadchrome-ec-82cd5b0daad82b34c27a18a9d0a38f74977fbf59.tar.gz
Stop keyboard scans from triggering ARM EC reset
The ARM EC was being rebooted when both the power and one of several other keys were pressed. (LCtrl, Tab, Reload, t, [, ], y, Dim Screen and Mute) It should only do this when the key combo PWR + Reload is pressed. To fix it, keyboard scanning is disabled whenever the power button is pressed. It locks a mutex indicating that scanning should be disabled, and the main keyboard scanning task blocks on the step where it sets up the keyboard and waits for the mutex to unlock. BUG=chrome-os-partner:10889 TEST=Pick one of the troublesome keys. First press it, then quickly press the power button. Then press the power button followed by the troublesome key. Repeat this process several times for each key, it should not reset the system. Press power + reload, this should still reset the system. Pressing and holding power should initiate a shutdown. Change-Id: Ib60d2ebbb57eb8a3c135662514ec622c37a7eb07 Signed-off-by: Charlie Mooney <charliemooney@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/28402 Reviewed-by: David Hendricks <dhendrix@chromium.org>
-rw-r--r--chip/stm32/keyboard_scan.c24
-rw-r--r--common/gaia_power.c5
2 files changed, 28 insertions, 1 deletions
diff --git a/chip/stm32/keyboard_scan.c b/chip/stm32/keyboard_scan.c
index 2df36fa9eb..da5df3b3af 100644
--- a/chip/stm32/keyboard_scan.c
+++ b/chip/stm32/keyboard_scan.c
@@ -39,6 +39,8 @@ enum COL_INDEX {
/* 15:14, 12:8, 2 */
#define IRQ_MASK 0xdf04
+static struct mutex scanning_enabled;
+
/* The keyboard state from the last read */
static uint8_t raw_state[KB_OUTPUTS];
@@ -364,6 +366,7 @@ int keyboard_scan_init(void)
void keyboard_scan_task(void)
{
int key_press_timer = 0;
+ uint8_t keys_changed = 0;
/* Enable interrupts for keyboard matrix inputs */
gpio_enable_interrupt(GPIO_KB_IN00);
@@ -376,7 +379,10 @@ void keyboard_scan_task(void)
gpio_enable_interrupt(GPIO_KB_IN07);
while (1) {
+ mutex_lock(&scanning_enabled);
wait_for_interrupt();
+ mutex_unlock(&scanning_enabled);
+
task_wait_event(-1);
enter_polling_mode();
@@ -385,7 +391,12 @@ void keyboard_scan_task(void)
/* sleep for debounce. */
usleep(SCAN_LOOP_DELAY);
/* Check for keys down */
- if (check_keys_changed()) {
+
+ mutex_lock(&scanning_enabled);
+ keys_changed = check_keys_changed();
+ mutex_unlock(&scanning_enabled);
+
+ if (keys_changed) {
key_press_timer = 0;
} else {
if (++key_press_timer >=
@@ -453,3 +464,14 @@ static int keyboard_get_info(struct host_cmd_handler_args *args)
DECLARE_HOST_COMMAND(EC_CMD_MKBP_INFO,
keyboard_get_info,
EC_VER_MASK(0));
+
+void keyboard_enable_scanning(int enable)
+{
+ if (enable) {
+ mutex_unlock(&scanning_enabled);
+ task_wake(TASK_ID_KEYSCAN);
+ } else {
+ mutex_lock(&scanning_enabled);
+ select_column(COL_TRI_STATE_ALL);
+ }
+}
diff --git a/common/gaia_power.c b/common/gaia_power.c
index 48377523c3..ce4577f978 100644
--- a/common/gaia_power.c
+++ b/common/gaia_power.c
@@ -174,6 +174,11 @@ static int check_for_power_off_event(void)
pressed = 1;
}
+ /* Dis/Enable keyboard scanning when the power button state changes */
+ if (pressed != power_button_was_pressed)
+ keyboard_enable_scanning(!pressed);
+
+
now = get_time();
if (pressed) {
gpio_set_level(GPIO_PMIC_PWRON_L, 0);