From 8dab5788f3563821c703320835b47d6e33a8b72d Mon Sep 17 00:00:00 2001 From: Stefan Adolfsson Date: Tue, 24 Apr 2018 11:34:41 +0200 Subject: CEC: Add cecwrite command to ectool cecwrite can be used to write a sequence of bytes on the CEC bus. Signed-off-by: Stefan Adolfsson BUG=b:76467407 BRANCH=none TEST=Using EC firmware with CEC support, turn on/off TV: ectool cecwrite 0x40 0x04 ectool cecwrite 0x40 0x36 CQ-DEPEND=CL:1030214 Change-Id: I5bc1efcaaf6ea4c7f92d3654d6e0fcc8717ab757 Reviewed-on: https://chromium-review.googlesource.com/1030215 Commit-Ready: Stefan Adolfsson Tested-by: Stefan Adolfsson Reviewed-by: Randall Spangler Reviewed-by: Daisuke Nojiri --- util/ectool.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/util/ectool.c b/util/ectool.c index be26e96829..501bb40f64 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" + " cecwrite [write bytes...]\n" + " Write data on the CEC bus\n" " echash [CMDS]\n" " Various EC hash commands\n" " eventclear \n" @@ -7828,6 +7830,36 @@ int cmd_wait_event(int argc, char *argv[]) return 0; } +int cmd_cec_write(int argc, char *argv[]) +{ + char *e; + long val; + int i, msg_len; + struct ec_params_cec_write p; + + if (argc < 2 || argc > 17) { + fprintf(stderr, "%s [MSG[1] ... MSG[15]]>\n", argv[0]); + return -1; + } + + msg_len = argc - 1; + for (i = 0; i < msg_len; i++) { + val = strtol(argv[i + 1], &e, 16); + if (e && *e) + return -1; + if (val < 0 || val > 0xff) + return -1; + p.msg[i] = (uint8_t)val; + } + + printf("Write to CEC: "); + for (i = 0; i < msg_len; i++) + printf("0x%02x ", p.msg[i]); + printf("\n"); + + return ec_command(EC_CMD_CEC_WRITE_MSG, 0, &p, msg_len, NULL, 0); +} + /* NULL-terminated list of commands */ const struct command commands[] = { {"autofanctrl", cmd_thermal_auto_fan_ctrl}, @@ -7844,6 +7876,7 @@ const struct command commands[] = { {"chipinfo", cmd_chipinfo}, {"cmdversions", cmd_cmdversions}, {"console", cmd_console}, + {"cecwrite", cmd_cec_write}, {"echash", cmd_ec_hash}, {"eventclear", cmd_host_event_clear}, {"eventclearb", cmd_host_event_clear_b}, -- cgit v1.2.1