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/usb_pd_console_cmd.c | |
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/usb_pd_console_cmd.c')
-rw-r--r-- | common/usb_pd_console_cmd.c | 85 |
1 files changed, 85 insertions, 0 deletions
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 */ |