diff options
author | Vijay Hiremath <vijay.p.hiremath@intel.com> | 2020-01-30 20:46:54 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-02-04 21:39:01 +0000 |
commit | fadd6d704cd460ef6e9af2aae7eba08b527c5bf4 (patch) | |
tree | d4962a717714e68fcb65959d965469f7da7920de /common | |
parent | fd7576f02df537972b11098a687232a0e7a71f01 (diff) | |
download | chrome-ec-fadd6d704cd460ef6e9af2aae7eba08b527c5bf4.tar.gz |
TCPMv1/v2: Move "pe" console command to common file
BUG=b:148528713
BRANCH=none
TEST=make buildall -j
Change-Id: I71c8d491014a69ec938fa1172eee7b5322572654
Signed-off-by: Vijay Hiremath <vijay.p.hiremath@intel.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2032726
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Jett Rink <jettrink@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/build.mk | 3 | ||||
-rw-r--r-- | common/usb_pd_console_cmd.c | 85 | ||||
-rw-r--r-- | common/usb_pd_policy.c | 68 | ||||
-rw-r--r-- | common/usbc/usb_pe_drp_sm.c | 75 |
4 files changed, 87 insertions, 144 deletions
diff --git a/common/build.mk b/common/build.mk index 82ca3cb00f..fc65725863 100644 --- a/common/build.mk +++ b/common/build.mk @@ -144,7 +144,8 @@ common-$(CONFIG_USB_CONSOLE_STREAM)+=usb_console_stream.o common-$(CONFIG_USB_I2C)+=usb_i2c.o common-$(CONFIG_USB_PORT_POWER_DUMB)+=usb_port_power_dumb.o common-$(CONFIG_USB_PORT_POWER_SMART)+=usb_port_power_smart.o -common-$(CONFIG_USB_POWER_DELIVERY)+=usb_common.o usb_pd_host_cmd.o +common-$(CONFIG_USB_POWER_DELIVERY)+=usb_common.o usb_pd_host_cmd.o \ + usb_pd_console_cmd.o ifeq ($(CONFIG_USB_SM_FRAMEWORK),) common-$(CONFIG_USB_POWER_DELIVERY)+=usb_pd_protocol.o usb_pd_policy.o endif diff --git a/common/usb_pd_console_cmd.c b/common/usb_pd_console_cmd.c new file mode 100644 index 0000000000..29871956c7 --- /dev/null +++ b/common/usb_pd_console_cmd.c @@ -0,0 +1,85 @@ +/* Copyright 2020 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + * + * Console commands for USB-PD module. + */ + +#include "console.h" +#include "usb_pd.h" +#include "util.h" + +#ifdef CONFIG_USB_PD_ALT_MODE_DFP +#ifdef CONFIG_CMD_USB_PD_PE +static void dump_pe(int port) +{ + int i, j, idh_ptype; + struct svdm_amode_data *modep; + uint32_t mode_caps; + struct pd_policy *pe = pd_get_am_policy(port); + const char * const idh_ptype_names[] = { + "UNDEF", "Hub", "Periph", "PCable", "ACable", "AMA", + "RSV6", "RSV7"}; + + if (pe->identity[0] == 0) { + ccprintf("No identity discovered yet.\n"); + return; + } + + idh_ptype = PD_IDH_PTYPE(pe->identity[0]); + ccprintf("IDENT:\n"); + ccprintf("\t[ID Header] %08x :: %s, VID:%04x\n", + pe->identity[0], + idh_ptype_names[idh_ptype], + pd_get_identity_vid(port)); + + ccprintf("\t[Cert Stat] %08x\n", pe->identity[1]); + for (i = 2; i < ARRAY_SIZE(pe->identity); i++) { + ccprintf("\t"); + if (pe->identity[i]) + ccprintf("[%d] %08x ", i, pe->identity[i]); + } + ccprintf("\n"); + + if (pe->svid_cnt < 1) { + ccprintf("No SVIDS discovered yet.\n"); + return; + } + + for (i = 0; i < pe->svid_cnt; i++) { + ccprintf("SVID[%d]: %04x MODES:", i, pe->svids[i].svid); + for (j = 0; j < pe->svids[j].mode_cnt; j++) + ccprintf(" [%d] %08x", j + 1, pe->svids[i].mode_vdo[j]); + ccprintf("\n"); + + modep = pd_get_amode_data(port, pe->svids[i].svid); + if (modep) { + mode_caps = modep->data->mode_vdo[modep->opos - 1]; + ccprintf("MODE[%d]: svid:%04x caps:%08x\n", modep->opos, + modep->fx->svid, mode_caps); + } + } +} + +static int command_pe(int argc, char **argv) +{ + int port; + char *e; + + if (argc < 3) + return EC_ERROR_PARAM_COUNT; + + /* command: pe <port> <subcmd> <args> */ + port = strtoi(argv[1], &e, 10); + if (*e || port >= board_get_usb_pd_port_count()) + return EC_ERROR_PARAM2; + if (!strncasecmp(argv[2], "dump", 4)) + dump_pe(port); + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(pe, command_pe, + "<port> dump", + "USB PE"); +#endif /* CONFIG_CMD_USB_PD_PE */ +#endif /* CONFIG_USB_PD_ALT_MODE_DFP */ diff --git a/common/usb_pd_policy.c b/common/usb_pd_policy.c index c97fb697a9..74809057d7 100644 --- a/common/usb_pd_policy.c +++ b/common/usb_pd_policy.c @@ -750,74 +750,6 @@ static int enter_tbt_compat_mode(int port, uint32_t *payload) return 2; } -#ifdef CONFIG_CMD_USB_PD_PE -static void dump_pe(int port) -{ - const char * const idh_ptype_names[] = { - "UNDEF", "Hub", "Periph", "PCable", "ACable", "AMA", - "RSV6", "RSV7"}; - - int i, j, idh_ptype; - struct svdm_amode_data *modep; - uint32_t mode_caps; - - if (pe[port].identity[0] == 0) { - ccprintf("No identity discovered yet.\n"); - return; - } - idh_ptype = PD_IDH_PTYPE(pe[port].identity[0]); - ccprintf("IDENT:\n"); - ccprintf("\t[ID Header] %08x :: %s, VID:%04x\n", pe[port].identity[0], - idh_ptype_names[idh_ptype], pd_get_identity_vid(port)); - ccprintf("\t[Cert Stat] %08x\n", pe[port].identity[1]); - for (i = 2; i < ARRAY_SIZE(pe[port].identity); i++) { - ccprintf("\t"); - if (pe[port].identity[i]) - ccprintf("[%d] %08x ", i, pe[port].identity[i]); - } - ccprintf("\n"); - - if (pe[port].svid_cnt < 1) { - ccprintf("No SVIDS discovered yet.\n"); - return; - } - - for (i = 0; i < pe[port].svid_cnt; i++) { - ccprintf("SVID[%d]: %04x MODES:", i, pe[port].svids[i].svid); - for (j = 0; j < pe[port].svids[j].mode_cnt; j++) - ccprintf(" [%d] %08x", j + 1, - pe[port].svids[i].mode_vdo[j]); - ccprintf("\n"); - modep = pd_get_amode_data(port, pe[port].svids[i].svid); - if (modep) { - mode_caps = modep->data->mode_vdo[modep->opos - 1]; - ccprintf("MODE[%d]: svid:%04x caps:%08x\n", modep->opos, - modep->fx->svid, mode_caps); - } - } -} - -static int command_pe(int argc, char **argv) -{ - int port; - char *e; - if (argc < 3) - return EC_ERROR_PARAM_COUNT; - /* command: pe <port> <subcmd> <args> */ - port = strtoi(argv[1], &e, 10); - if (*e || port >= board_get_usb_pd_port_count()) - return EC_ERROR_PARAM2; - if (!strncasecmp(argv[2], "dump", 4)) - dump_pe(port); - - return EC_SUCCESS; -} - -DECLARE_CONSOLE_COMMAND(pe, command_pe, - "<port> dump", - "USB PE"); -#endif /* CONFIG_CMD_USB_PD_PE */ - /* Return the current cable speed received from Cable Discover Mode command */ __overridable enum tbt_compat_cable_speed board_get_max_tbt_speed(int port) { diff --git a/common/usbc/usb_pe_drp_sm.c b/common/usbc/usb_pe_drp_sm.c index 3bed89f8ee..7a93c3a4db 100644 --- a/common/usbc/usb_pe_drp_sm.c +++ b/common/usbc/usb_pe_drp_sm.c @@ -4608,81 +4608,6 @@ void pd_set_dfp_enter_mode_flag(int port, bool set) else PE_CLR_FLAG(port, PE_FLAGS_MODAL_OPERATION); } - -#ifdef CONFIG_CMD_USB_PD_PE -static void dump_pe(int port) -{ - const char * const idh_ptype_names[] = { - "UNDEF", "Hub", "Periph", "PCable", "ACable", "AMA", - "RSV6", "RSV7"}; - - int i, j, idh_ptype; - struct svdm_amode_data *modep; - uint32_t mode_caps; - - if (pe[port].am_policy.identity[0] == 0) { - ccprintf("No identity discovered yet.\n"); - return; - } - idh_ptype = PD_IDH_PTYPE(pe[port].am_policy.identity[0]); - ccprintf("IDENT:\n"); - ccprintf("\t[ID Header] %08x :: %s, VID:%04x\n", - pe[port].am_policy.identity[0], - idh_ptype_names[idh_ptype], - pd_get_identity_vid(port)); - ccprintf("\t[Cert Stat] %08x\n", pe[port].am_policy.identity[1]); - for (i = 2; i < ARRAY_SIZE(pe[port].am_policy.identity); i++) { - ccprintf("\t"); - if (pe[port].am_policy.identity[i]) - ccprintf("[%d] %08x ", i, - pe[port].am_policy.identity[i]); - } - ccprintf("\n"); - - if (pe[port].am_policy.svid_cnt < 1) { - ccprintf("No SVIDS discovered yet.\n"); - return; - } - - for (i = 0; i < pe[port].am_policy.svid_cnt; i++) { - ccprintf("SVID[%d]: %04x MODES:", i, - pe[port].am_policy.svids[i].svid); - for (j = 0; j < pe[port].am_policy.svids[j].mode_cnt; j++) - ccprintf(" [%d] %08x", j + 1, - pe[port].am_policy.svids[i].mode_vdo[j]); - ccprintf("\n"); - modep = pd_get_amode_data(port, - pe[port].am_policy.svids[i].svid); - if (modep) { - mode_caps = modep->data->mode_vdo[modep->opos - 1]; - ccprintf("MODE[%d]: svid:%04x caps:%08x\n", modep->opos, - modep->fx->svid, mode_caps); - } - } -} - -static int command_pe(int argc, char **argv) -{ - int port; - char *e; - - if (argc < 3) - return EC_ERROR_PARAM_COUNT; - - /* command: pe <port> <subcmd> <args> */ - port = strtoi(argv[1], &e, 10); - if (*e || port >= board_get_usb_pd_port_count()) - return EC_ERROR_PARAM2; - if (!strncasecmp(argv[2], "dump", 4)) - dump_pe(port); - - return EC_SUCCESS; -} - -DECLARE_CONSOLE_COMMAND(pe, command_pe, - "<port> dump", - "USB PE"); -#endif /* CONFIG_CMD_USB_PD_PE */ #endif /* CONFIG_USB_PD_ALT_MODE_DFP */ static const struct usb_state pe_states[] = { |