summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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);