diff options
author | Stefan Adolfsson <sadolfsson@google.com> | 2018-04-24 14:42:09 +0200 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-05-10 02:27:06 -0700 |
commit | 1c941f01db0aa079a1d9c8f01bd498ee887a16c6 (patch) | |
tree | 2ca96abbcb5f5fc16b2facce64643e64da7934c0 /util | |
parent | d81f36efcee07464589c9afdaf0cca97bd54e33e (diff) | |
download | chrome-ec-1c941f01db0aa079a1d9c8f01bd498ee887a16c6.tar.gz |
CEC: Add cecread command to ectool
Wait for a CEC event and read out the new message.
Signed-off-by: Stefan Adolfsson <sadolfsson@chromium.org>
BUG=b:76467407
BRANCH=none
TEST=Using EC firmware with CEC support:
ectool cecread -- -1
Turn on TV, cecread says the same as logical analyzer
CQ-DEPEND=CL:1030216
Change-Id: Iadd2fcfad0dc647aaaa9bd8a04c5c0f582259af5
Reviewed-on: https://chromium-review.googlesource.com/1030217
Commit-Ready: Stefan Adolfsson <sadolfsson@chromium.org>
Tested-by: Stefan Adolfsson <sadolfsson@chromium.org>
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'util')
-rw-r--r-- | util/ectool.c | 86 |
1 files changed, 69 insertions, 17 deletions
diff --git a/util/ectool.c b/util/ectool.c index 9c9db78c30..1018dc4046 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -76,6 +76,8 @@ const char help_str[] = " Prints supported version mask for a command number\n" " console\n" " Prints the last output to the EC debug console\n" + " cecread [timeout]\n" + " Read data from the CEC bus\n" " cecwrite [write bytes...]\n" " Write data on the CEC bus\n" " echash [CMDS]\n" @@ -7781,6 +7783,24 @@ err: return rv < 0; } +static int wait_event(long event_type, + struct ec_response_get_next_event *buffer, + size_t buffer_size, long timeout) +{ + int rv; + + rv = ec_pollevent(1 << event_type, buffer, buffer_size, timeout); + if (rv == 0) { + fprintf(stderr, "Timeout waiting for MKBP event\n"); + return -ETIMEDOUT; + } else if (rv < 0) { + perror("Error polling for MKBP event\n"); + return -EIO; + } + + return 0; +} + int cmd_wait_event(int argc, char *argv[]) { int rv, i; @@ -7813,14 +7833,9 @@ int cmd_wait_event(int argc, char *argv[]) } } - rv = ec_pollevent(1 << event_type, &buffer, sizeof(buffer), timeout); - if (rv == 0) { - fprintf(stderr, "Timeout waitout for MKBP event\n"); - return -ETIMEDOUT; - } else if (rv < 0) { - perror("Error polling for MKBP event\n"); - return -EIO; - } + rv = wait_event(event_type, &buffer, sizeof(buffer), timeout); + if (rv < 0) + return rv; printf("MKBP event %d data: ", buffer.event_type); for (i = 0; i < rv - 1; ++i) @@ -7862,15 +7877,9 @@ int cmd_cec_write(int argc, char *argv[]) if (rv < 0) return rv; - rv = ec_pollevent(1 << EC_MKBP_EVENT_CEC, &buffer, - sizeof(buffer), 1000); - if (rv == 0) { - fprintf(stderr, "Timeout waiting CEC event\n"); - return -ETIMEDOUT; - } else if (rv < 0) { - perror("Error polling for MKBP event\n"); - return -EIO; - } + rv = wait_event(EC_MKBP_EVENT_CEC, &buffer, sizeof(buffer), 1000); + if (rv < 0) + return rv; if (buffer.data.cec_events & EC_MKBP_CEC_SEND_OK) return 0; @@ -7885,6 +7894,48 @@ int cmd_cec_write(int argc, char *argv[]) return -1; } +int cmd_cec_read(int argc, char *argv[]) +{ + int msg_len, i, rv; + char *e; + struct ec_response_cec_read r; + struct ec_response_get_next_event buffer; + long timeout = 5000; + + if (!ec_pollevent) { + fprintf(stderr, "Polling for MKBP event not supported\n"); + return -EINVAL; + } + + if (argc >= 2) { + timeout = strtol(argv[1], &e, 0); + if (e && *e) { + fprintf(stderr, "Bad timeout value '%s'.\n", argv[1]); + return -1; + } + } + + rv = wait_event(EC_MKBP_EVENT_CEC, &buffer, sizeof(buffer), timeout); + if (rv < 0) + return rv; + + printf("Got CEC events 0x%08x\n", buffer.data.cec_events); + + rv = ec_command(EC_CMD_CEC_READ_MSG, 0, NULL, 0, &r, sizeof(r)); + if (rv < 0) + return rv; + + msg_len = rv; + + printf("CEC data: "); + for (i = 0; i < msg_len; i++) + printf("0x%02x ", r.msg[i]); + printf("\n"); + + return 0; +} + + /* NULL-terminated list of commands */ const struct command commands[] = { {"autofanctrl", cmd_thermal_auto_fan_ctrl}, @@ -7902,6 +7953,7 @@ const struct command commands[] = { {"cmdversions", cmd_cmdversions}, {"console", cmd_console}, {"cecwrite", cmd_cec_write}, + {"cecread", cmd_cec_read}, {"echash", cmd_ec_hash}, {"eventclear", cmd_host_event_clear}, {"eventclearb", cmd_host_event_clear_b}, |