diff options
author | Aseda Aboagye <aaboagye@google.com> | 2016-07-08 09:24:20 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2016-07-19 18:33:39 -0700 |
commit | 824f9fadc257ecbbaab2e2296f56dfc72325dd7f (patch) | |
tree | f4a10fbe74837a5a29dd053869dc3fa7aebe078c /common | |
parent | 0325284e17c04dbd03552f2b152cf3e079d7148f (diff) | |
download | chrome-ec-824f9fadc257ecbbaab2e2296f56dfc72325dd7f.tar.gz |
mkbp: Extend EC_CMD_MKBP_GET_INFO.
- Added ability to query the buttons and switches.
- Added ability to report the available buttons or switches.
BUG=chromium:626863
BRANCH=None
TEST=make -j buildall
CQ-DEPEND=CL:358633
CQ-DEPEND=CL:358634
CQ-DEPEND=CL:358989
Change-Id: Ie821491269e8d09578eba92127895c0b6b8e91a9
Signed-off-by: Aseda Aboagye <aaboagye@google.com>
Reviewed-on: https://chromium-review.googlesource.com/358926
Commit-Ready: Aseda Aboagye <aaboagye@chromium.org>
Tested-by: Aseda Aboagye <aaboagye@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/keyboard_mkbp.c | 107 |
1 files changed, 98 insertions, 9 deletions
diff --git a/common/keyboard_mkbp.c b/common/keyboard_mkbp.c index 68665ca4db..f947413720 100644 --- a/common/keyboard_mkbp.c +++ b/common/keyboard_mkbp.c @@ -326,21 +326,110 @@ void keyboard_send_battery_key(void) /*****************************************************************************/ /* Host commands */ -static int keyboard_get_info(struct host_cmd_handler_args *args) +static uint32_t get_supported_buttons(void) { - struct ec_response_mkbp_info *r = args->response; + 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; +} - r->rows = KEYBOARD_ROWS; - r->cols = KEYBOARD_COLS; - r->switches = 0; +static uint32_t get_supported_switches(void) +{ + uint32_t val = 0; - args->response_size = sizeof(*r); +#ifdef CONFIG_LID_SWITCH + val |= (1 << EC_MKBP_LID_OPEN); +#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) { + 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; + + 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, - keyboard_get_info, - EC_VER_MASK(0)); +DECLARE_HOST_COMMAND(EC_CMD_MKBP_INFO, mkbp_get_info, + EC_VER_MASK(0) | EC_VER_MASK(1)); static void set_keyscan_config(const struct ec_mkbp_config *src, struct ec_mkbp_protocol_config *dst, |