From bad59c215e06c3ecb28471754502aca4da180e91 Mon Sep 17 00:00:00 2001 From: Ting Shen Date: Thu, 12 Jul 2018 15:38:23 +0800 Subject: ec: make EC_CMD_MKBP_INFO supports 8042 keyboard BRANCH=eve BUG=b:111195071 TEST=BOARD=eve make (8042 keyboard) BOARD=poppy make (mkbp keyboard) make runtests Change-Id: I23ab359323cd3bef86a07d11ab03c4d163132929 Signed-off-by: Ting Shen Reviewed-on: https://chromium-review.googlesource.com/1134808 Commit-Queue: Ting Shen Tested-by: Ting Shen Reviewed-by: Randall Spangler --- common/build.mk | 2 +- common/keyboard_8042.c | 29 +++++++++ common/keyboard_info.c | 139 ++++++++++++++++++++++++++++++++++++++++++++ common/keyboard_mkbp.c | 113 ++--------------------------------- include/keyboard_protocol.h | 5 ++ 5 files changed, 179 insertions(+), 109 deletions(-) create mode 100644 common/keyboard_info.c diff --git a/common/build.mk b/common/build.mk index 126cd7a3ef..b01eaa8c81 100644 --- a/common/build.mk +++ b/common/build.mk @@ -114,7 +114,7 @@ common-$(HAS_TASK_CONSOLE)+=console.o console_output.o uart_buffering.o common-$(CONFIG_CMD_MEM)+=memory_commands.o common-$(HAS_TASK_HOSTCMD)+=host_command.o common-$(HAS_TASK_PDCMD)+=host_command_pd.o -common-$(HAS_TASK_KEYSCAN)+=keyboard_scan.o +common-$(HAS_TASK_KEYSCAN)+=keyboard_scan.o keyboard_info.o common-$(HAS_TASK_LIGHTBAR)+=lb_common.o lightbar.o common-$(HAS_TASK_MOTIONSENSE)+=motion_sense.o sensor_common.o common-$(HAS_TASK_TPM)+=tpm_registers.o diff --git a/common/keyboard_8042.c b/common/keyboard_8042.c index 41729266f0..8e325bcd4b 100644 --- a/common/keyboard_8042.c +++ b/common/keyboard_8042.c @@ -175,6 +175,9 @@ struct kblog_t { static struct kblog_t *kblog_buf; /* Log buffer; NULL if not logging */ static int kblog_len; /* Current log length */ +/* button state */ +static uint32_t button_state; + /** * Add event to keyboard log. */ @@ -927,6 +930,27 @@ test_mockable void keyboard_update_button(enum keyboard_button_type button, code_set = acting_code_set(scancode_set); button_8042 = buttons_8042[button]; + switch (button) { + case KEYBOARD_BUTTON_POWER: + button_state &= ~(1 << EC_MKBP_POWER_BUTTON); + button_state |= (is_pressed << EC_MKBP_POWER_BUTTON); + break; + + case KEYBOARD_BUTTON_VOLUME_UP: + button_state &= ~(1 << EC_MKBP_VOL_UP); + button_state |= (is_pressed << EC_MKBP_VOL_UP); + break; + + case KEYBOARD_BUTTON_VOLUME_DOWN: + button_state &= ~(1 << EC_MKBP_VOL_DOWN); + button_state |= (is_pressed << EC_MKBP_VOL_DOWN); + break; + + default: + /* ignored. */ + break; + } + switch (code_set) { case SCANCODE_SET_1: make_code = button_8042.scancode_set1; @@ -1235,3 +1259,8 @@ static void keyboard_power_button(void) } DECLARE_HOOK(HOOK_POWER_BUTTON_CHANGE, keyboard_power_button, HOOK_PRIO_DEFAULT); + +uint32_t keyboard_get_button_state(void) +{ + return button_state; +} diff --git a/common/keyboard_info.c b/common/keyboard_info.c new file mode 100644 index 0000000000..94573c939e --- /dev/null +++ b/common/keyboard_info.c @@ -0,0 +1,139 @@ +/* Copyright 2018 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +#include "button.h" +#include "console.h" +#include "ec_commands.h" +#include "host_command.h" +#include "lid_switch.h" +#include "keyboard_config.h" +#include "keyboard_protocol.h" +#include "keyboard_scan.h" +#include "tablet_mode.h" +#include "util.h" + +static uint32_t get_supported_buttons(void) +{ + uint32_t val = 0; +#ifdef CONFIG_BUTTON_COUNT + int i; + + for (i = 0; i < CONFIG_BUTTON_COUNT; i++) { + if (buttons[i].type == KEYBOARD_BUTTON_VOLUME_UP) + val |= (1 << EC_MKBP_VOL_UP); + if (buttons[i].type == KEYBOARD_BUTTON_VOLUME_DOWN) + val |= (1 << EC_MKBP_VOL_DOWN); + } +#endif +#ifdef CONFIG_POWER_BUTTON + val |= (1 << EC_MKBP_POWER_BUTTON); +#endif + return val; +} + +static uint32_t get_supported_switches(void) +{ + uint32_t val = 0; + +#ifdef CONFIG_LID_SWITCH + val |= (1 << EC_MKBP_LID_OPEN); +#endif +#ifdef CONFIG_TABLET_MODE_SWITCH + val |= (1 << EC_MKBP_TABLET_MODE); +#endif + return val; +} + +static uint32_t get_switch_state(void) +{ + uint32_t val = 0; + +#ifdef CONFIG_LID_SWITCH + if (lid_is_open()) + val |= (1 << EC_MKBP_LID_OPEN); +#endif +#ifdef CONFIG_TABLET_MODE_SWITCH + if (tablet_get_mode()) + val |= (1 << EC_MKBP_TABLET_MODE); +#endif + return val; +} + +static int mkbp_get_info(struct host_cmd_handler_args *args) +{ + const struct ec_params_mkbp_info *p = args->params; + + if (args->params_size == 0 || p->info_type == EC_MKBP_INFO_KBD) { + struct ec_response_mkbp_info *r = args->response; + + /* Version 0 just returns info about the keyboard. */ + r->rows = KEYBOARD_ROWS; + r->cols = KEYBOARD_COLS; + /* This used to be "switches" which was previously 0. */ + r->reserved = 0; + + args->response_size = sizeof(struct ec_response_mkbp_info); + } else { + union ec_response_get_next_data *r = args->response; + + /* Version 1 (other than EC_MKBP_INFO_KBD) */ + switch (p->info_type) { + case EC_MKBP_INFO_SUPPORTED: + switch (p->event_type) { + case EC_MKBP_EVENT_BUTTON: + r->buttons = get_supported_buttons(); + args->response_size = sizeof(r->buttons); + break; + + case EC_MKBP_EVENT_SWITCH: + r->switches = get_supported_switches(); + args->response_size = sizeof(r->switches); + break; + + default: + /* Don't care for now for other types. */ + return EC_RES_INVALID_PARAM; + } + break; + + case EC_MKBP_INFO_CURRENT: + switch (p->event_type) { +#ifdef HAS_TASK_KEYSCAN + case EC_MKBP_EVENT_KEY_MATRIX: + memcpy(r->key_matrix, keyboard_scan_get_state(), + sizeof(r->key_matrix)); + args->response_size = sizeof(r->key_matrix); + break; +#endif + case EC_MKBP_EVENT_HOST_EVENT: + r->host_event = host_get_events(); + args->response_size = sizeof(r->host_event); + break; + + case EC_MKBP_EVENT_BUTTON: + r->buttons = keyboard_get_button_state(); + args->response_size = sizeof(r->buttons); + break; + + case EC_MKBP_EVENT_SWITCH: + r->switches = get_switch_state(); + args->response_size = sizeof(r->switches); + break; + + default: + /* Doesn't make sense for other event types. */ + return EC_RES_INVALID_PARAM; + } + break; + + default: + /* Unsupported query. */ + return EC_RES_ERROR; + } + } + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_MKBP_INFO, mkbp_get_info, + EC_VER_MASK(0) | EC_VER_MASK(1)); + diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c index e6d06c30fb..688db832c8 100644 --- a/common/keyboard_mkbp.c +++ b/common/keyboard_mkbp.c @@ -361,114 +361,6 @@ void clear_typematic_key(void) /*****************************************************************************/ /* Host commands */ -static uint32_t get_supported_buttons(void) -{ - uint32_t val = 0; -#ifdef CONFIG_BUTTON_COUNT - int i; - - for (i = 0; i < CONFIG_BUTTON_COUNT; i++) { - if (buttons[i].type == KEYBOARD_BUTTON_VOLUME_UP) - val |= (1 << EC_MKBP_VOL_UP); - if (buttons[i].type == KEYBOARD_BUTTON_VOLUME_DOWN) - val |= (1 << EC_MKBP_VOL_DOWN); - } -#endif -#ifdef CONFIG_POWER_BUTTON - val |= (1 << EC_MKBP_POWER_BUTTON); -#endif - return val; -} - -static uint32_t get_supported_switches(void) -{ - uint32_t val = 0; - -#ifdef CONFIG_LID_SWITCH - val |= (1 << EC_MKBP_LID_OPEN); -#endif -#ifdef CONFIG_TABLET_MODE_SWITCH - val |= (1 << EC_MKBP_TABLET_MODE); -#endif - return val; -} - -static int mkbp_get_info(struct host_cmd_handler_args *args) -{ - const struct ec_params_mkbp_info *p = args->params; - - if (args->params_size == 0 || p->info_type == EC_MKBP_INFO_KBD) { - struct ec_response_mkbp_info *r = args->response; - - /* Version 0 just returns info about the keyboard. */ - r->rows = KEYBOARD_ROWS; - r->cols = KEYBOARD_COLS; - /* This used to be "switches" which was previously 0. */ - r->reserved = 0; - - args->response_size = sizeof(struct ec_response_mkbp_info); - } else { - union ec_response_get_next_data *r = args->response; - - /* Version 1 (other than EC_MKBP_INFO_KBD) */ - switch (p->info_type) { - case EC_MKBP_INFO_SUPPORTED: - switch (p->event_type) { - case EC_MKBP_EVENT_BUTTON: - r->buttons = get_supported_buttons(); - args->response_size = sizeof(r->buttons); - break; - - case EC_MKBP_EVENT_SWITCH: - r->switches = get_supported_switches(); - args->response_size = sizeof(r->switches); - break; - - default: - /* Don't care for now for other types. */ - return EC_RES_INVALID_PARAM; - } - break; - - case EC_MKBP_INFO_CURRENT: - switch (p->event_type) { -#ifdef HAS_TASK_KEYSCAN - case EC_MKBP_EVENT_KEY_MATRIX: - memcpy(r->key_matrix, keyboard_scan_get_state(), - sizeof(r->key_matrix)); - args->response_size = sizeof(r->key_matrix); - break; -#endif - case EC_MKBP_EVENT_HOST_EVENT: - r->host_event = host_get_events(); - args->response_size = sizeof(r->host_event); - break; - - case EC_MKBP_EVENT_BUTTON: - r->buttons = mkbp_button_state; - args->response_size = sizeof(r->buttons); - break; - - case EC_MKBP_EVENT_SWITCH: - r->switches = mkbp_switch_state; - args->response_size = sizeof(r->switches); - break; - - default: - /* Doesn't make sense for other event types. */ - return EC_RES_INVALID_PARAM; - } - break; - - default: - /* Unsupported query. */ - return EC_RES_ERROR; - } - } - return EC_RES_SUCCESS; -} -DECLARE_HOST_COMMAND(EC_CMD_MKBP_INFO, mkbp_get_info, - EC_VER_MASK(0) | EC_VER_MASK(1)); #ifdef HAS_TASK_KEYSCAN static void set_keyscan_config(const struct ec_mkbp_config *src, @@ -594,3 +486,8 @@ DECLARE_HOST_COMMAND(EC_CMD_MKBP_GET_CONFIG, host_command_mkbp_get_config, EC_VER_MASK(0)); #endif /* HAS_TASK_KEYSCAN */ + +uint32_t keyboard_get_button_state(void) +{ + return mkbp_button_state; +} diff --git a/include/keyboard_protocol.h b/include/keyboard_protocol.h index a8eafe308d..45d852da98 100644 --- a/include/keyboard_protocol.h +++ b/include/keyboard_protocol.h @@ -27,6 +27,11 @@ void keyboard_clear_buffer(void); */ void keyboard_update_button(enum keyboard_button_type button, int is_pressed); +/* + * Get the state of supported buttons. + */ +uint32_t keyboard_get_button_state(void); + /* Protocol-specific includes */ #ifdef CONFIG_KEYBOARD_PROTOCOL_8042 -- cgit v1.2.1