diff options
author | Vic Yang <victoryang@chromium.org> | 2014-12-25 01:24:00 -0800 |
---|---|---|
committer | ChromeOS Commit Bot <chromeos-commit-bot@chromium.org> | 2015-01-07 17:48:15 +0000 |
commit | 140aa369049a616a4d07de1a0f3f4c946b11ac40 (patch) | |
tree | 03fdd58987ae4ada9984694fd0c109a6b0aa3cb1 | |
parent | 35ea0a968caacc73e6ece2bd68db465cc21f07c2 (diff) | |
download | chrome-ec-140aa369049a616a4d07de1a0f3f4c946b11ac40.tar.gz |
pd: Show literal PD state name for 'ectool usbpd'
Currently, 'ectool usbpd' shows PD task state in numerical format. Every
time we add/remove a state, the number changes, and this makes the
command difficult to use. Modify the command to print the name of the PD
task state.
BRANCH=Samus,Ryu
BUG=chrome-os-partner:34296
TEST=Run 'ectool usbpd 0' with different combination of new/old PD
firmware and new/old ectool.
Change-Id: Ic0daa03e9f7565c1322166713c2cce3b7cb93a30
Signed-off-by: Vic Yang <victoryang@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/237623
Reviewed-by: Alec Berg <alecaberg@chromium.org>
Commit-Queue: Alec Berg <alecaberg@chromium.org>
Tested-by: Alec Berg <alecaberg@chromium.org>
-rw-r--r-- | common/usb_pd_protocol.c | 70 | ||||
-rw-r--r-- | include/ec_commands.h | 7 | ||||
-rw-r--r-- | util/ectool.c | 19 |
3 files changed, 64 insertions, 32 deletions
diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 86ccbeb0ad..ff3f28d697 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -288,6 +288,27 @@ static uint8_t pd_comm_enabled = CONFIG_USB_PD_COMM_ENABLED; struct mutex pd_crc_lock; +#ifdef CONFIG_COMMON_RUNTIME +static const char * const pd_state_names[] = { + "DISABLED", +#ifdef CONFIG_USB_PD_DUAL_ROLE + "SUSPENDED", "SNK_DISCONNECTED", "SNK_HARD_RESET_RECOVER", + "SNK_DISCOVERY", "SNK_REQUESTED", "SNK_TRANSITION", "SNK_READY", + "SNK_DR_SWAP", "SNK_SWAP_INIT", "SNK_SWAP_SNK_DISABLE", + "SNK_SWAP_SRC_DISABLE", "SNK_SWAP_STANDBY", "SNK_SWAP_COMPLETE", +#endif /* CONFIG_USB_PD_DUAL_ROLE */ + "SRC_DISCONNECTED", "SRC_HARD_RESET_RECOVER", "SRC_STARTUP", + "SRC_DISCOVERY", "SRC_NEGOCIATE", "SRC_ACCEPTED", "SRC_POWERED", + "SRC_TRANSITION", "SRC_READY", "SRC_GET_SNK_CAP", "SRC_DR_SWAP", +#ifdef CONFIG_USB_PD_DUAL_ROLE + "SRC_SWAP_INIT", "SRC_SWAP_SNK_DISABLE", "SRC_SWAP_SRC_DISABLE", + "SRC_SWAP_STANDBY", +#endif /* CONFIG_USB_PD_DUAL_ROLE */ + "SOFT_RESET", "HARD_RESET_SEND", "HARD_RESET_EXECUTE", "BIST", +}; +BUILD_ASSERT(ARRAY_SIZE(pd_state_names) == PD_STATE_COUNT); +#endif + /* * 4 entry rw_hash table of type-C devices that AP has firmware updates for. */ @@ -2897,29 +2918,6 @@ static int command_pd(int argc, char **argv) } else #endif if (!strncasecmp(argv[2], "state", 5)) { - const char * const state_names[] = { - "DISABLED", "SUSPENDED", -#ifdef CONFIG_USB_PD_DUAL_ROLE - "SNK_DISCONNECTED", "SNK_HARD_RESET_RECOVER", - "SNK_DISCOVERY", "SNK_REQUESTED", - "SNK_TRANSITION", "SNK_READY", "SNK_DR_SWAP", - "SNK_SWAP_INIT", "SNK_SWAP_SNK_DISABLE", - "SNK_SWAP_SRC_DISABLE", "SNK_SWAP_STANDBY", - "SNK_SWAP_COMPLETE", -#endif /* CONFIG_USB_PD_DUAL_ROLE */ - "SRC_DISCONNECTED", "SRC_HARD_RESET_RECOVER", - "SRC_STARTUP", "SRC_DISCOVERY", - "SRC_NEGOCIATE", "SRC_ACCEPTED", "SRC_POWERED", - "SRC_TRANSITION", "SRC_READY", "SRC_GET_SNK_CAP", - "SRC_DR_SWAP", -#ifdef CONFIG_USB_PD_DUAL_ROLE - "SRC_SWAP_INIT", "SRC_SWAP_SNK_DISABLE", - "SRC_SWAP_SRC_DISABLE", "SRC_SWAP_STANDBY", -#endif /* CONFIG_USB_PD_DUAL_ROLE */ - "SOFT_RESET", "HARD_RESET_SEND", "HARD_RESET_EXECUTE", - "BIST", - }; - BUILD_ASSERT(ARRAY_SIZE(state_names) == PD_STATE_COUNT); ccprintf("Port C%d, %s - Role: %s-%s Polarity: CC%d " "Flags: 0x%04x, State: %s\n", port, pd_comm_enabled ? "Ena" : "Dis", @@ -2927,7 +2925,7 @@ static int command_pd(int argc, char **argv) pd[port].data_role == PD_ROLE_DFP ? "DFP" : "UFP", pd[port].polarity + 1, pd[port].flags, - state_names[pd[port].task_state]); + pd_state_names[pd[port].task_state]); } else { return EC_ERROR_PARAM1; } @@ -3020,6 +3018,7 @@ static const enum typec_mux typec_mux_map[USB_PD_CTRL_MUX_COUNT] = { static int hc_usb_pd_control(struct host_cmd_handler_args *args) { const struct ec_params_usb_pd_control *p = args->params; + struct ec_response_usb_pd_control_v1 *r_v1 = args->response; struct ec_response_usb_pd_control *r = args->response; if (p->role >= USB_PD_CTRL_ROLE_COUNT || @@ -3034,16 +3033,27 @@ static int hc_usb_pd_control(struct host_cmd_handler_args *args) board_set_usb_mux(p->port, typec_mux_map[p->mux], pd_get_polarity(p->port)); #endif /* CONFIG_USBC_SS_MUX */ - r->enabled = pd_comm_enabled; - r->role = pd[p->port].power_role; - r->polarity = pd[p->port].polarity; - r->state = pd[p->port].task_state; - args->response_size = sizeof(*r); + + if (args->version == 0) { + r->enabled = pd_comm_enabled; + r->role = pd[p->port].power_role; + r->polarity = pd[p->port].polarity; + r->state = pd[p->port].task_state; + args->response_size = sizeof(*r); + } else { + r_v1->enabled = pd_comm_enabled; + r_v1->role = pd[p->port].power_role; + r_v1->polarity = pd[p->port].polarity; + strzcpy(r_v1->state, + pd_state_names[pd[p->port].task_state], + sizeof(r_v1->state)); + args->response_size = sizeof(*r_v1); + } return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_USB_PD_CONTROL, hc_usb_pd_control, - EC_VER_MASK(0)); + EC_VER_MASK(0) | EC_VER_MASK(1)); static int hc_remote_flash(struct host_cmd_handler_args *args) { diff --git a/include/ec_commands.h b/include/ec_commands.h index c06e3464a0..0f98f70a79 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -2731,6 +2731,13 @@ struct ec_response_usb_pd_control { uint8_t state; } __packed; +struct ec_response_usb_pd_control_v1 { + uint8_t enabled; + uint8_t role; + uint8_t polarity; + char state[32]; +} __packed; + #define EC_CMD_USB_PD_PORTS 0x102 struct ec_response_usb_pd_ports { diff --git a/util/ectool.c b/util/ectool.c index 4e03a90f62..8a5e63a9f4 100644 --- a/util/ectool.c +++ b/util/ectool.c @@ -2841,17 +2841,23 @@ int cmd_usb_pd(int argc, char *argv[]) const char *role_str[] = {"", "toggle", "toggle-off", "sink", "source"}; const char *mux_str[] = {"", "none", "usb", "dp", "dock", "auto"}; struct ec_params_usb_pd_control p; + struct ec_response_usb_pd_control_v1 *r_v1 = + (struct ec_response_usb_pd_control_v1 *)ec_inbuf; struct ec_response_usb_pd_control *r = (struct ec_response_usb_pd_control *)ec_inbuf; int rv, i, j; int option_ok; char *e; + int cmdver = 1; BUILD_ASSERT(ARRAY_SIZE(role_str) == USB_PD_CTRL_ROLE_COUNT); BUILD_ASSERT(ARRAY_SIZE(mux_str) == USB_PD_CTRL_MUX_COUNT); p.role = USB_PD_CTRL_ROLE_NO_CHANGE; p.mux = USB_PD_CTRL_MUX_NO_CHANGE; + if (!ec_cmd_version_supported(EC_CMD_USB_PD_CONTROL, cmdver)) + cmdver = 0; + if (argc < 2) { fprintf(stderr, "No port specified.\n"); return -1; @@ -2910,14 +2916,23 @@ int cmd_usb_pd(int argc, char *argv[]) } } - rv = ec_command(EC_CMD_USB_PD_CONTROL, 0, &p, sizeof(p), + rv = ec_command(EC_CMD_USB_PD_CONTROL, cmdver, &p, sizeof(p), ec_inbuf, ec_max_insize); - if ((rv >= 0) && (argc == 2)) + if (rv < 0 || argc != 2) + return (rv < 0) ? rv : 0; + + if (cmdver == 0) { printf("Port C%d is %sabled, Role:%s Polarity:CC%d State:%d\n", p.port, (r->enabled) ? "en" : "dis", r->role == PD_ROLE_SOURCE ? "SRC" : "SNK", r->polarity + 1, r->state); + } else { + printf("Port C%d is %sabled, Role:%s Polarity:CC%d State:%s\n", + p.port, (r_v1->enabled) ? "en" : "dis", + r_v1->role == PD_ROLE_SOURCE ? "SRC" : "SNK", + r_v1->polarity + 1, r_v1->state); + } return (rv < 0 ? rv : 0); } |