diff options
author | Boris Mittelberg <bmbm@google.com> | 2021-03-30 00:25:41 +0000 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-06-15 00:15:01 +0000 |
commit | 224ab6e5924e7a4bbca3bdd0089adb6199dd5395 (patch) | |
tree | 2bd902ef5cc07ee5b4e6baff2b6d06d93b44474b | |
parent | a02fbd4cf6bcb6c9bb395c7304390ef8973e7dcb (diff) | |
download | chrome-ec-224ab6e5924e7a4bbca3bdd0089adb6199dd5395.tar.gz |
mkbp: Separate MKBP_INFO host command from the keyboard driver
Detaching protocol-related info command from the keyboard driver.
BUG=b:170966461
BRANCH=main,firmware-dedede-13606.B,firmware-volteer-13672.B-main
TEST=None
Signed-off-by: Boris Mittelberg <bmbm@google.com>
Change-Id: I7943f7537bdf003145e9bd909a14f9451d922a5a
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2796381
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3700697
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Commit-Queue: Shelley Chen <shchen@chromium.org>
Tested-by: Shelley Chen <shchen@chromium.org>
-rw-r--r-- | common/build.mk | 3 | ||||
-rw-r--r-- | common/keyboard_mkbp.c | 132 | ||||
-rw-r--r-- | common/mkbp_info.c | 144 | ||||
-rw-r--r-- | include/keyboard_mkbp.h | 10 |
4 files changed, 167 insertions, 122 deletions
diff --git a/common/build.mk b/common/build.mk index 3c2068edb7..a38dbb24ac 100644 --- a/common/build.mk +++ b/common/build.mk @@ -92,7 +92,8 @@ common-$(CONFIG_I2C_VIRTUAL_BATTERY)+=virtual_battery.o common-$(CONFIG_INDUCTIVE_CHARGING)+=inductive_charging.o common-$(CONFIG_KEYBOARD_PROTOCOL_8042)+=keyboard_8042.o \ keyboard_8042_sharedlib.o -common-$(CONFIG_KEYBOARD_PROTOCOL_MKBP)+=keyboard_mkbp.o mkbp_fifo.o +common-$(CONFIG_KEYBOARD_PROTOCOL_MKBP)+=keyboard_mkbp.o mkbp_fifo.o \ + mkbp_info.o common-$(CONFIG_KEYBOARD_TEST)+=keyboard_test.o common-$(CONFIG_KEYBOARD_VIVALDI)+=keyboard_vivaldi.o common-$(CONFIG_LED_COMMON)+=led_common.o diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c index b3b11cf13e..159a0477a4 100644 --- a/common/keyboard_mkbp.c +++ b/common/keyboard_mkbp.c @@ -71,6 +71,17 @@ static struct ec_mkbp_protocol_config config = { .fifo_max_depth = FIFO_DEPTH, }; +uint32_t mkbp_get_switch_state(void) +{ + return mkbp_switch_state; +}; + +uint32_t mkbp_get_button_state(void) +{ + return mkbp_button_state; +}; + + /*****************************************************************************/ /* Interface */ @@ -231,127 +242,6 @@ void keyboard_send_battery_key(void) void clear_typematic_key(void) { } -/*****************************************************************************/ -/* Host commands */ -static uint32_t get_supported_buttons(void) -{ - uint32_t val = 0; - -#ifdef CONFIG_VOLUME_BUTTONS - val |= BIT(EC_MKBP_VOL_UP) | BIT(EC_MKBP_VOL_DOWN); -#endif /* defined(CONFIG_VOLUME_BUTTONS) */ - -#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON - val |= BIT(EC_MKBP_RECOVERY); -#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON) */ - -#ifdef CONFIG_POWER_BUTTON - val |= BIT(EC_MKBP_POWER_BUTTON); -#endif /* defined(CONFIG_POWER_BUTTON) */ - - return val; -} - -static uint32_t get_supported_switches(void) -{ - uint32_t val = 0; - -#ifdef CONFIG_LID_SWITCH - val |= BIT(EC_MKBP_LID_OPEN); -#endif -#ifdef CONFIG_TABLET_MODE_SWITCH - val |= BIT(EC_MKBP_TABLET_MODE); -#endif -#ifdef CONFIG_BASE_ATTACHED_SWITCH - val |= BIT(EC_MKBP_BASE_ATTACHED); -#endif - return val; -} - -static enum ec_status 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 = (uint32_t)host_get_events(); - args->response_size = sizeof(r->host_event); - break; - -#ifdef CONFIG_HOST_EVENT64 - case EC_MKBP_EVENT_HOST_EVENT64: - r->host_event64 = host_get_events(); - args->response_size = sizeof(r->host_event64); - break; -#endif - - 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)); - #ifndef HAS_TASK_KEYSCAN /* For boards without a keyscan task, try and simulate keyboard presses. */ static void simulate_key(int row, int col, int pressed) diff --git a/common/mkbp_info.c b/common/mkbp_info.c new file mode 100644 index 0000000000..f31852abca --- /dev/null +++ b/common/mkbp_info.c @@ -0,0 +1,144 @@ +/* Copyright 2021 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. + */ + +/* MKBP info host command */ + +#include "common.h" +#include "console.h" +#include "ec_commands.h" +#include "host_command.h" +#include "keyboard_config.h" +#include "keyboard_mkbp.h" +#include "keyboard_scan.h" +#include "util.h" + +static uint32_t get_supported_buttons(void) +{ + uint32_t val = 0; + +#ifdef CONFIG_VOLUME_BUTTONS + val |= BIT(EC_MKBP_VOL_UP) | BIT(EC_MKBP_VOL_DOWN); +#endif /* defined(CONFIG_VOLUME_BUTTONS) */ + +#ifdef CONFIG_DEDICATED_RECOVERY_BUTTON + val |= BIT(EC_MKBP_RECOVERY); +#endif /* defined(CONFIG_DEDICATED_RECOVERY_BUTTON) */ + +#ifdef CONFIG_POWER_BUTTON + val |= BIT(EC_MKBP_POWER_BUTTON); +#endif /* defined(CONFIG_POWER_BUTTON) */ + + return val; +} + +static uint32_t get_supported_switches(void) +{ + uint32_t val = 0; + +#ifdef CONFIG_LID_SWITCH + val |= BIT(EC_MKBP_LID_OPEN); +#endif +#ifdef CONFIG_TABLET_MODE_SWITCH + val |= BIT(EC_MKBP_TABLET_MODE); +#endif +#ifdef CONFIG_BASE_ATTACHED_SWITCH + val |= BIT(EC_MKBP_BASE_ATTACHED); +#endif +#ifdef CONFIG_FRONT_PROXIMITY_SWITCH + val |= BIT(EC_MKBP_FRONT_PROXIMITY); +#endif + return val; +} + +static enum ec_status 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; + +#ifdef CONFIG_KEYBOARD_PROTOCOL_MKBP + /* Version 0 just returns info about the keyboard. */ + r->rows = KEYBOARD_ROWS; + r->cols = KEYBOARD_COLS_MAX; +#else + r->rows = 0; + r->cols = 0; +#endif /* CONFIG_KEYBOARD_PROTOCOL_MKBP */ + + /* 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 = (uint32_t)host_get_events(); + args->response_size = sizeof(r->host_event); + break; + +#ifdef CONFIG_HOST_EVENT64 + case EC_MKBP_EVENT_HOST_EVENT64: + r->host_event64 = host_get_events(); + args->response_size = sizeof(r->host_event64); + break; +#endif + + case EC_MKBP_EVENT_BUTTON: + r->buttons = mkbp_get_button_state(); + args->response_size = sizeof(r->buttons); + break; + + case EC_MKBP_EVENT_SWITCH: + r->switches = mkbp_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/include/keyboard_mkbp.h b/include/keyboard_mkbp.h index c0fe0a842d..41c7357259 100644 --- a/include/keyboard_mkbp.h +++ b/include/keyboard_mkbp.h @@ -35,4 +35,14 @@ static inline void keyboard_send_battery_key(void) { } */ void mkbp_update_switches(uint32_t sw, int state); +/** + * Retrieve state of buttons [Power, Volume up/down, etc] + */ +uint32_t mkbp_get_button_state(void); + +/** + * Retrieve state of switches [Lid open/closed, tablet mode switch, etc] + */ +uint32_t mkbp_get_switch_state(void); + #endif /* __CROS_EC_KEYBOARD_MKBP_H */ |