From d81f36efcee07464589c9afdaf0cca97bd54e33e Mon Sep 17 00:00:00 2001 From: Stefan Adolfsson Date: Tue, 24 Apr 2018 12:13:46 +0200 Subject: CEC: Wait for send-event after cec writes in ectool For factory testing purposes, make the cecwrite return-value depend on whether it got an ACK from the sink. Signed-off-by: Stefan Adolfsson BUG=b:76467407 BRANCH=none TEST=Using EC firmware with CEC support, ectool cecwrite with and without sink CQ-DEPEND=CL:1030215 Change-Id: I681243f74e4745796ac8d50e60dc0f7f9c087335 Reviewed-on: https://chromium-review.googlesource.com/1030216 Commit-Ready: Stefan Adolfsson Tested-by: Stefan Adolfsson Reviewed-by: Randall Spangler Reviewed-by: Daisuke Nojiri --- util/ectool.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'util/ectool.c') diff --git a/util/ectool.c b/util/ectool.c index 501bb40f64..9c9db78c30 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -7834,8 +7834,9 @@ int cmd_cec_write(int argc, char *argv[]) { char *e; long val; - int i, msg_len; + int rv, i, msg_len; struct ec_params_cec_write p; + struct ec_response_get_next_event buffer; if (argc < 2 || argc > 17) { fprintf(stderr, "%s [MSG[1] ... MSG[15]]>\n", argv[0]); @@ -7857,7 +7858,31 @@ int cmd_cec_write(int argc, char *argv[]) printf("0x%02x ", p.msg[i]); printf("\n"); - return ec_command(EC_CMD_CEC_WRITE_MSG, 0, &p, msg_len, NULL, 0); + rv = ec_command(EC_CMD_CEC_WRITE_MSG, 0, &p, msg_len, NULL, 0); + 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; + } + + if (buffer.data.cec_events & EC_MKBP_CEC_SEND_OK) + return 0; + + if (buffer.data.cec_events & EC_MKBP_CEC_SEND_FAILED) { + fprintf(stderr, "Send failed\n"); + return -1; + } + + fprintf(stderr, "No send result received\n"); + + return -1; } /* NULL-terminated list of commands */ -- cgit v1.2.1