diff options
author | Nicolas Boichat <drinkcat@chromium.org> | 2019-10-07 16:10:22 +0800 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-10-16 00:03:01 -0700 |
commit | 5bcfbb8956b19b327eb314cc921e6877be295a2b (patch) | |
tree | baaffee80afc0657eec4973d812ba44495d4bcb9 | |
parent | 826c22e41a500be5da388b511f958666b9bc5620 (diff) | |
download | chrome-ec-5bcfbb8956b19b327eb314cc921e6877be295a2b.tar.gz |
ectool: Add new mkbpget command to get button/switch status
The base attached switch is not exposed to userspace via /dev/input,
so provide an alternative way to read it on boot.
BRANCH=none
BUG=b:109839180
TEST=ectool mkbpget buttons/switches prints correct states
Change-Id: Id0314c7f15149ec8d863e43bd4a05a0f7bed9f02
Signed-off-by: Nicolas Boichat <drinkcat@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/1844655
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Legacy-Commit-Queue: Commit Bot <commit-bot@chromium.org>
Reviewed-by: Joel Kitching <kitching@chromium.org>
-rw-r--r-- | util/ectool.c | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/util/ectool.c b/util/ectool.c index 5c6689d398..9942142fa3 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -198,6 +198,8 @@ const char help_str[] = " Set the color of an LED or query brightness range\n" " lightbar [CMDS]\n" " Various lightbar control commands\n" + " mkbpget <buttons|switches>\n" + " Get MKBP buttons/switches supported mask and current state\n" " mkbpwakemask <get|set> <event|hostevent> [mask]\n" " Get or Set the MKBP event wake mask, or host event wake mask\n" " motionsense [CMDS]\n" @@ -8022,6 +8024,86 @@ static int cmd_keyconfig(int argc, char *argv[]) return 0; } +static const char * const mkbp_button_strings[] = { + [EC_MKBP_POWER_BUTTON] = "Power", + [EC_MKBP_VOL_UP] = "Volume up", + [EC_MKBP_VOL_DOWN] = "Volume down", + [EC_MKBP_RECOVERY] = "Recovery", +}; + +static const char * const mkbp_switch_strings[] = { + [EC_MKBP_LID_OPEN] = "Lid open", + [EC_MKBP_TABLET_MODE] = "Tablet mode", + [EC_MKBP_BASE_ATTACHED] = "Base attached", +}; + +static int cmd_mkbp_get(int argc, char *argv[]) +{ + struct ec_params_mkbp_info p; + union ec_response_get_next_data r; + int rv; + int i; + uint32_t supported; + + if (argc < 2) { + fprintf(stderr, "Usage: %s <buttons|switches>\n", argv[0]); + return -1; + } + + if (strncmp(argv[1], "button", 6) == 0) { + p.event_type = EC_MKBP_EVENT_BUTTON; + } else if (strncmp(argv[1], "switch", 6) == 0) { + p.event_type = EC_MKBP_EVENT_SWITCH; + } else { + fprintf(stderr, "Invalid param: '%s'\n", argv[1]); + return -1; + } + + p.info_type = EC_MKBP_INFO_SUPPORTED; + rv = ec_command(EC_CMD_MKBP_INFO, 0, &p, sizeof(p), &r, + sizeof(r)); + if (rv < 0) + return rv; + if (p.event_type == EC_MKBP_EVENT_BUTTON) + supported = r.buttons; + else if (p.event_type == EC_MKBP_EVENT_SWITCH) + supported = r.switches; + + p.info_type = EC_MKBP_INFO_CURRENT; + rv = ec_command(EC_CMD_MKBP_INFO, 0, &p, sizeof(p), &r, + sizeof(r)); + if (rv < 0) + return rv; + + if (p.event_type == EC_MKBP_EVENT_BUTTON) { + printf("MKBP buttons state: 0x%04x (supported: 0x%04x)\n", + r.buttons, supported); + for (i = 0; i < ARRAY_SIZE(mkbp_button_strings); i++) { + if (supported & BIT(i) && mkbp_button_strings[i]) { + printf("%s: %s\n", mkbp_button_strings[i], + r.buttons & BIT(i) ? "ON" : "OFF"); + supported &= ~BIT(i); + } + } + if (supported) + printf("Unknown buttons: 0x%04x\n", supported); + } else if (p.event_type == EC_MKBP_EVENT_SWITCH) { + printf("MKBP switches state: 0x%04x (supported: 0x%04x)\n", + r.switches, supported); + for (i = 0; i < ARRAY_SIZE(mkbp_switch_strings); i++) { + if (supported & BIT(i) && mkbp_switch_strings[i]) { + printf("%s: %s\n", mkbp_switch_strings[i], + r.switches & BIT(i) ? "ON" : "OFF"); + supported &= ~BIT(i); + } + } + if (supported) + printf("Unknown switches: 0x%04x\n", supported); + } + + return 0; +} + static int cmd_mkbp_wake_mask(int argc, char *argv[]) { struct ec_params_mkbp_event_wake_mask p; @@ -9112,6 +9194,7 @@ const struct command commands[] = { {"kbpress", cmd_kbpress}, {"keyconfig", cmd_keyconfig}, {"keyscan", cmd_keyscan}, + {"mkbpget", cmd_mkbp_get}, {"mkbpwakemask", cmd_mkbp_wake_mask}, {"motionsense", cmd_motionsense}, {"nextevent", cmd_next_event}, |