summaryrefslogtreecommitdiff
path: root/util/ectool.c
diff options
context:
space:
mode:
authorDaisuke Nojiri <dnojiri@chromium.org>2020-11-23 15:08:55 -0800
committerCommit Bot <commit-bot@chromium.org>2020-12-10 03:16:46 +0000
commitd9b7ea8ff23a744e7a5e0f28fe7ca0e36ef11a9d (patch)
tree0ae315575f0ab2e6804b9e9e494d7e50cb1739fb /util/ectool.c
parent9b039dc93e156e720a6916cdc804b4e4575bb0c5 (diff)
downloadchrome-ec-d9b7ea8ff23a744e7a5e0f28fe7ca0e36ef11a9d.tar.gz
PCHG: Add host command
This patch adds a host command to get the peripheral charge port count and status. $ ectool pchg 1 $ ectool pchg 0 State: CHARGING (4) Battery: 50% Flags: 0x0 $ ectool pchg 0 foo Invalid parameter count Usage1: pchg Usage2: pchg <port> Usage1 prints the number of ports. Usage2 prints the status of a port. $ ectool pchg 100 Bad port index BUG=b:173235954 BRANCH=Trogdor TEST=Done on CoachZ. See the description above. Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Change-Id: I33f261e48b16d5933b6f3ca9f3c12fec476edda3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2555628 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'util/ectool.c')
-rw-r--r--util/ectool.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/util/ectool.c b/util/ectool.c
index 8c6fbdfb61..7c1ed74f67 100644
--- a/util/ectool.c
+++ b/util/ectool.c
@@ -210,6 +210,8 @@ const char help_str[] =
" Prints saved panic info\n"
" pause_in_s5 [on|off]\n"
" Whether or not the AP should pause in S5 on shutdown\n"
+ " pchg [<port>]\n"
+ " Get peripheral charge port count and status\n"
" pdcontrol [suspend|resume|reset|disable|on]\n"
" Controls the PD chip\n"
" pdchipinfo <port>\n"
@@ -9328,6 +9330,72 @@ int cmd_charge_port_override(int argc, char *argv[])
return 0;
}
+static void cmd_pchg_help(char *cmd)
+{
+ fprintf(stderr,
+ " Usage1: %s\n"
+ " Usage2: %s <port>\n"
+ "\n"
+ " Usage1 prints the number of ports.\n"
+ " Usage2 prints the status of a port.\n",
+ cmd, cmd);
+}
+
+int cmd_pchg(int argc, char *argv[])
+{
+ int port, port_count;
+ char *e;
+ int rv;
+ struct ec_response_pchg_count *rsp_count = ec_inbuf;
+ static const char * const pchg_state_text[] = EC_PCHG_STATE_TEXT;
+
+ rv = ec_command(EC_CMD_PCHG_COUNT, 0, NULL, 0, ec_inbuf, ec_max_insize);
+ if (rv < 0) {
+ fprintf(stderr, "Failed to get port count: %d\n", rv);
+ return rv;
+ }
+ port_count = rsp_count->port_count;
+
+ if (argc == 1) {
+ /* Usage1 */
+ printf("%d\n", port_count);
+ return 0;
+ }
+
+ port = strtol(argv[1], &e, 0);
+ if ((e && *e) || port >= port_count) {
+ fprintf(stderr, "Bad port index\n");
+ return -1;
+ }
+
+ if (argc < 3) {
+ /* Usage2 */
+ struct ec_params_pchg *p = ec_outbuf;
+ struct ec_response_pchg *r = ec_inbuf;
+
+ p->port = port;
+ rv = ec_command(EC_CMD_PCHG, 0, ec_outbuf, sizeof(*p),
+ ec_inbuf, ec_max_insize);
+ if (rv < 0) {
+ fprintf(stderr, "Error code: %d\n", rv);
+ return rv;
+ }
+
+ printf("State: %s (%d)\n",
+ r->state < sizeof(pchg_state_text) ?
+ pchg_state_text[r->state] : "UNDEF",
+ r->state);
+ printf("Battery: %d%%\n", r->battery_percentage);
+ printf("Flags: 0x%x\n", r->error);
+ return 0;
+ }
+
+ fprintf(stderr, "Invalid parameter count\n\n");
+ cmd_pchg_help(argv[0]);
+
+ return -1;
+}
+
int cmd_pd_log(int argc, char *argv[])
{
union {
@@ -10296,6 +10364,7 @@ const struct command commands[] = {
{"nextevent", cmd_next_event},
{"panicinfo", cmd_panic_info},
{"pause_in_s5", cmd_s5},
+ {"pchg", cmd_pchg},
{"pdgetmode", cmd_pd_get_amode},
{"pdsetmode", cmd_pd_set_amode},
{"port80read", cmd_port80_read},