diff options
author | Sam Hurst <shurst@google.com> | 2019-12-11 14:35:18 -0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-04-14 15:36:46 +0000 |
commit | acffdcdb357824bfa009af01290875257de30646 (patch) | |
tree | 79ef7bf3828c4e86f287b59e2a8858682b1f2527 /common | |
parent | f1d4d43109c8c97b2a84d58d4f2b3d871f8ba322 (diff) | |
download | chrome-ec-acffdcdb357824bfa009af01290875257de30646.tar.gz |
TCPMv2: Add pd console command
Add pd console commands that enables the device
to work with PD FAFT. Other pd commands such as
bist, vdm and ping will be added in another CL.
BUG=b:151481791
BUG=chromium:1021235
BRANCH=none
TEST=make -j buildall
manual:
Verified that system:
pd tryscr 0 - did not trysrc
pd tryscr 1 - did trysrc
pd tryscr 2 - normal trysrc operation
pd 0 tx - started as snk
pd 0 charger - started as src
pd 0 dev 5 - charged at 5V
pd 0 dev 12 - charged at 12V
pd 0 dev 15 - charged at 15V
pd 0 dev 20 - charged at 20V
pd 0 disable - pd was disabled
pd 0 enable - pd was enabled
pd 0 soft - sent soft reset
pd 0 hard - sent hard reset
pd 0 dualrole off - stayed in src and switched to snk on disconnect
pd 0 dualrole on - toggled from snk to src and vice versa
pd 0 dualrole sink - was a sink only
pd 0 dualrole source - was a source only
pd 0 dualrole freeze - stayed in current power role and switched
to snk on disconnect
pd 0 swap power - initiated a power role swap
pd 0 swap vconn - initiated a vconn swap
pd 0 swap data - initiated a data role swap
Change-Id: Id1542001c0e52d1d5bfbc5b9cb826b9a204e5b2e
Signed-off-by: Sam Hurst <shurst@google.com>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1962506
Commit-Queue: Denis Brockus <dbrockus@chromium.org>
Reviewed-by: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/usbc/build.mk | 1 | ||||
-rw-r--r-- | common/usbc/usb_pd_console.c | 163 |
2 files changed, 164 insertions, 0 deletions
diff --git a/common/usbc/build.mk b/common/usbc/build.mk index f8f6f5aa33..3b29d5d9ad 100644 --- a/common/usbc/build.mk +++ b/common/usbc/build.mk @@ -28,6 +28,7 @@ ifneq ($(CONFIG_USB_PE_SM),) all-obj-$(CONFIG_USB_VPD)+=$(_usbc_dir)usb_pe_ctvpd_sm.o all-obj-$(CONFIG_USB_CTVPD)+=$(_usbc_dir)usb_pe_ctvpd_sm.o all-obj-$(CONFIG_USB_DRP_ACC_TRYSRC)+=$(_usbc_dir)usb_pe_drp_sm.o +all-obj-$(CONFIG_CMD_PD)+=$(_usbc_dir)usb_pd_console.o endif # CONFIG_USB_PE_SM endif # CONFIG_USB_PD_TCPMV2 diff --git a/common/usbc/usb_pd_console.c b/common/usbc/usb_pd_console.c new file mode 100644 index 0000000000..ba2b6efeb9 --- /dev/null +++ b/common/usbc/usb_pd_console.c @@ -0,0 +1,163 @@ +/* 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. + */ + +#include "common.h" +#include "console.h" +#include "usb_common.h" +#include "usb_pe_sm.h" +#include "usb_tc_sm.h" +#include "usb_pd.h" +#include "util.h" + +test_export_static int command_pd(int argc, char **argv) +{ + int port; + char *e; + + if (argc < 2) + return EC_ERROR_PARAM_COUNT; + else if (IS_ENABLED(CONFIG_USB_PD_TRY_SRC) && + !strcasecmp(argv[1], "trysrc")) { + enum try_src_override_t ov = tc_get_try_src_override(); + + if (argc >= 3) { + ov = strtoi(argv[2], &e, 10); + if (*e || ov > TRY_SRC_NO_OVERRIDE) + return EC_ERROR_PARAM3; + tc_try_src_override(ov); + } + + if (ov == TRY_SRC_NO_OVERRIDE) + ccprintf("Try.SRC System controlled\n"); + else + ccprintf("Try.SRC Forced %s\n", ov ? "ON" : "OFF"); + + return EC_SUCCESS; + } + + /* command: pd <port> <subcmd> [args] */ + port = strtoi(argv[1], &e, 10); + if (argc < 3) + return EC_ERROR_PARAM_COUNT; + + if (*e || port >= CONFIG_USB_PD_PORT_MAX_COUNT) + return EC_ERROR_PARAM2; + + if (IS_ENABLED(CONFIG_USB_PD_DUAL_ROLE)) { + if (!strcasecmp(argv[2], "tx")) { + pe_dpm_request(port, DPM_REQUEST_SNK_STARTUP); + } else if (!strcasecmp(argv[2], "charger")) { + pe_dpm_request(port, DPM_REQUEST_SRC_STARTUP); + } else if (!strcasecmp(argv[2], "dev")) { + int max_volt; + + if (argc >= 4) { + max_volt = strtoi(argv[3], &e, 10) * 1000; + if (*e) + return EC_ERROR_PARAM3; + } else { + max_volt = pd_get_max_voltage(); + } + pd_request_source_voltage(port, max_volt); + pe_dpm_request(port, DPM_REQUEST_NEW_POWER_LEVEL); + ccprintf("max req: %dmV\n", max_volt); + } else if (!strcasecmp(argv[2], "disable")) { + pd_comm_enable(port, 0); + ccprintf("Port C%d disable\n", port); + return EC_SUCCESS; + } else if (!strcasecmp(argv[2], "enable")) { + pd_comm_enable(port, 1); + ccprintf("Port C%d enabled\n", port); + return EC_SUCCESS; + } else if (!strcasecmp(argv[2], "hard")) { + pe_dpm_request(port, DPM_REQUEST_HARD_RESET_SEND); + } else if (!strcasecmp(argv[2], "soft")) { + pe_dpm_request(port, DPM_REQUEST_SOFT_RESET_SEND); + } else if (!strcasecmp(argv[2], "swap")) { + if (argc < 4) + return EC_ERROR_PARAM_COUNT; + + if (!strcasecmp(argv[3], "power")) + pe_dpm_request(port, DPM_REQUEST_PR_SWAP); + else if (!strcasecmp(argv[3], "data")) + pe_dpm_request(port, DPM_REQUEST_DR_SWAP); + else if (IS_ENABLED(CONFIG_USBC_VCONN_SWAP) && + !strcasecmp(argv[3], "vconn")) + pe_dpm_request(port, DPM_REQUEST_VCONN_SWAP); + else + return EC_ERROR_PARAM3; + } else if (!strcasecmp(argv[2], "dualrole")) { + if (argc < 4) { + ccprintf("dual-role toggling: "); + switch (pd_get_dual_role(port)) { + case PD_DRP_TOGGLE_ON: + ccprintf("on\n"); + break; + case PD_DRP_TOGGLE_OFF: + ccprintf("off\n"); + break; + case PD_DRP_FREEZE: + ccprintf("freeze\n"); + break; + case PD_DRP_FORCE_SINK: + ccprintf("force sink\n"); + break; + case PD_DRP_FORCE_SOURCE: + ccprintf("force source\n"); + break; + } + } else { + if (!strcasecmp(argv[3], "on")) + pd_set_dual_role(port, + PD_DRP_TOGGLE_ON); + else if (!strcasecmp(argv[3], "off")) + pd_set_dual_role(port, + PD_DRP_TOGGLE_OFF); + else if (!strcasecmp(argv[3], "freeze")) + pd_set_dual_role(port, PD_DRP_FREEZE); + else if (!strcasecmp(argv[3], "sink")) + pd_set_dual_role(port, + PD_DRP_FORCE_SINK); + else if (!strcasecmp(argv[3], "source")) + pd_set_dual_role(port, + PD_DRP_FORCE_SOURCE); + else + return EC_ERROR_PARAM4; + } + return EC_SUCCESS; + } + } + + if (!strcasecmp(argv[2], "state")) { + ccprintf("Port C%d CC%d, %s - Role: %s-%s", + port, pd_get_polarity(port) + 1, + pd_comm_is_enabled(port) ? "Enable" : "Disable", + pd_get_power_role(port) == + PD_ROLE_SOURCE ? "SRC" : "SNK", + pd_get_data_role(port) == PD_ROLE_DFP ? "DFP" : "UFP"); + + if (IS_ENABLED(CONFIG_USBC_VCONN)) + ccprintf("%s ", tc_is_vconn_src(port) ? "-VC" : ""); + + ccprintf("TC State: %s, Flags: 0x%04x\n", + tc_get_current_state(port), + tc_get_flags(port)); + } + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(pd, command_pd, +#ifdef CONFIG_USB_PD_TRY_SRC + "trysrc [0|1|2]" +#endif + "\n\t<port> state" +#ifdef CONFIG_USB_PD_DUAL_ROLE + "|tx|charger|dev" + "\n\t<port> disable|enable|soft|hard" + "\n\t<port> dualrole [on|off|freeze|sink|source]" + "\n\t<port> swap [power|data|vconn]" +#endif /* CONFIG_USB_PD_DUAL_ROLE */ + , + "USB PD"); |