From adac37bf0c99e90ef4767681ba9f1a293cdae518 Mon Sep 17 00:00:00 2001 From: Shawn Nematbakhsh Date: Wed, 29 Jun 2016 18:17:19 -0700 Subject: [PATCH] keyboard_scan: Support boot key recognition with stuck KSI2 For certain board configurations, KSI2 will be stuck asserted for all scan columns if the power button is held. We must be aware of this case in order to correctly handle recovery mode key combinations. BUG=chrome-os-partner:54602 BRANCH=None TEST=Manual on gru. Do three-key salute, verify EC detects recovery mode. Signed-off-by: Shawn Nematbakhsh Change-Id: I03d76e1121107484f79520745858388f6cae096c Reviewed-on: https://chromium-review.googlesource.com/357590 Commit-Ready: Shawn N Tested-by: Shawn N Reviewed-by: Randall Spangler --- board/kevin/board.h | 1 + common/keyboard_scan.c | 15 +++++++++++++++ include/config.h | 7 +++++++ include/keyboard_config.h | 1 + 4 files changed, 24 insertions(+) diff --git a/board/kevin/board.h b/board/kevin/board.h index dea839bb54..2dc334228a 100644 --- a/board/kevin/board.h +++ b/board/kevin/board.h @@ -45,6 +45,7 @@ #define CONFIG_KEYBOARD_BOARD_CONFIG #define CONFIG_KEYBOARD_COL2_INVERTED #define CONFIG_KEYBOARD_PROTOCOL_MKBP /* Instead of 8042 protocol of keyboard */ +#define CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI2 #define CONFIG_LTO #define CONFIG_POWER_BUTTON #define CONFIG_VBOOT_HASH diff --git a/common/keyboard_scan.c b/common/keyboard_scan.c index 58fe77d677..73a6e6fdaf 100644 --- a/common/keyboard_scan.c +++ b/common/keyboard_scan.c @@ -524,6 +524,21 @@ static int check_key(const uint8_t *state, int index, int mask) allowed_mask[index] |= mask; allowed_mask[KEYBOARD_COL_REFRESH] |= KEYBOARD_MASK_REFRESH; +#ifdef CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI2 + /* + * Check if KSI2 is asserted for all columns due to power button hold, + * and ignore it if so. + */ + for (c = 0; c < KEYBOARD_COLS; c++) + if ((keyscan_config.actual_key_mask[c] & KEYBOARD_MASK_KSI2) && + !(state[c] & KEYBOARD_MASK_KSI2)) + break; + + if (c == KEYBOARD_COLS) + for (c = 0; c < KEYBOARD_COLS; c++) + allowed_mask[c] |= KEYBOARD_MASK_KSI2; +#endif + for (c = 0; c < KEYBOARD_COLS; c++) { if (state[c] & ~allowed_mask[c]) return 0; /* Disallowed key pressed */ diff --git a/include/config.h b/include/config.h index 2db396f0a2..7595c796a1 100644 --- a/include/config.h +++ b/include/config.h @@ -1227,6 +1227,13 @@ */ #define CONFIG_KEYBOARD_KSO_BASE 0 +/* + * For certain board configurations, KSI2 will be stuck asserted for all + * scan columns if the power button is held. We must be aware of this case + * in order to correctly handle recovery mode key combinations. + */ +#undef CONFIG_KEYBOARD_PWRBTN_ASSERTS_KSI2 + /* Enable extra debugging output from keyboard modules */ #undef CONFIG_KEYBOARD_DEBUG diff --git a/include/keyboard_config.h b/include/keyboard_config.h index 286b6d7560..6cb1b53a52 100644 --- a/include/keyboard_config.h +++ b/include/keyboard_config.h @@ -59,5 +59,6 @@ #define KEYBOARD_COL_KEY_2 4 #define KEYBOARD_ROW_KEY_2 6 #define KEYBOARD_MASK_KEY_2 KEYBOARD_ROW_TO_MASK(KEYBOARD_ROW_KEY_2) +#define KEYBOARD_MASK_KSI2 KEYBOARD_ROW_TO_MASK(2) #endif /* __CROS_EC_KEYBOARD_CONFIG_H */