diff options
author | Daisuke Nojiri <dnojiri@chromium.org> | 2023-02-23 15:04:48 -0800 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2023-04-14 20:26:52 +0000 |
commit | 1366a27d9bfe4ee31899403f5d2aa82eeb81d0bc (patch) | |
tree | 0d70628661bec1e333a977ce64214fe8eae1f3e1 | |
parent | 9b8a17e2e5fe00a84f75b8728ce79b30f6a30729 (diff) | |
download | chrome-ec-1366a27d9bfe4ee31899403f5d2aa82eeb81d0bc.tar.gz |
USB-PD: Update pd console command for EPR
> pd 1 epr enter
EPR enter requested
> [130.434040 C1: PE_SNK_Send_EPR_Mode_Entry]
[130.434852 C1: DPM Waiting]
[130.445641 C1: PE_SNK_EPR_Mode_Entry_Wait_For_Response]
[130.501005 C1: Entered EPR]
[130.501378 C1: PE_SNK_Wait_for_Capabilities]
[130.518489 C1: PE_SNK_Evaluate_Capability]
[130.519076 C1: PE_SNK_Select_Capability]
C1: Req [8] 28000mV 5000mA
> pd 1 state
Port C1 CC1, Enable - Role: SNK-UFP TC State: Attached.SNK, Flags: 0x1000
PE State: PE_SNK_Ready, Flags: 0x41000201 EPR
> pd 1 epr exit
EPR exit requested
[222.511037 C1: Request SPR before EPR exit]
[222.511515 C1: PE_SNK_Select_Capability]
C1: Req [4] 20000mV 5000mA
BUG=b:257320026
BRANCH=None
TEST=Agah. Run make run-usb_pd_console.
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Change-Id: If7566e1dc4de790180e44b49893622e1e71269da
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4296999
Reviewed-by: Keith Short <keithshort@chromium.org>
-rw-r--r-- | common/usbc/usb_pd_console.c | 40 | ||||
-rw-r--r-- | test/test_config.h | 4 | ||||
-rw-r--r-- | test/usb_pd_console.c | 62 |
3 files changed, 101 insertions, 5 deletions
diff --git a/common/usbc/usb_pd_console.c b/common/usbc/usb_pd_console.c index 20ddbff7d8..d1c82bafda 100644 --- a/common/usbc/usb_pd_console.c +++ b/common/usbc/usb_pd_console.c @@ -192,18 +192,47 @@ static ccprintf("TC State: %s, Flags: 0x%04x", tc_get_current_state(port), tc_get_flags(port)); - if (IS_ENABLED(CONFIG_USB_PE_SM)) - ccprintf(" PE State: %s, Flags: 0x%04x\n", + if (IS_ENABLED(CONFIG_USB_PE_SM)) { + ccprintf(" PE State: %s, Flags: 0x%04x", pe_get_current_state(port), pe_get_flags(port)); - else - ccprintf("\n"); + if (pe_is_explicit_contract(port)) { + if (pe_snk_in_epr_mode(port)) + ccprintf(" EPR"); + else + ccprintf(" SPR"); + } + } + ccprintf("\n"); cflush(); } else if (!strcasecmp(argv[2], "srccaps")) { pd_srccaps_dump(port); } else if (!strcasecmp(argv[2], "cc")) { ccprintf("Port C%d CC%d\n", port, pd_get_task_cc_state(port)); +#ifdef CONFIG_USB_PD_EPR + } else if (!strcasecmp(argv[2], "epr")) { + enum pd_dpm_request req; + + if (argc < 4) { + return EC_ERROR_PARAM_COUNT; + } + if (pd_get_power_role(port) != PD_ROLE_SINK) { + ccprintf("EPR is currently supported only for sink\n"); + /* Suppress (long) help message */ + return EC_SUCCESS; + } + if (!strcasecmp(argv[3], "enter")) { + req = DPM_REQUEST_EPR_MODE_ENTRY; + } else if (!strcasecmp(argv[3], "exit")) { + req = DPM_REQUEST_EPR_MODE_EXIT; + } else { + return EC_ERROR_PARAM3; + } + pd_dpm_request(port, req); + ccprintf("EPR %s requested\n", argv[3]); + return EC_SUCCESS; +#endif } if (IS_ENABLED(CONFIG_CMD_PD_TIMER) && !strcasecmp(argv[2], "timer")) { @@ -232,6 +261,9 @@ DECLARE_CONSOLE_COMMAND(pd, command_pd, "\n\t<port> suspend|resume" "\n\t<port> dualrole [on|off|freeze|sink|source]" "\n\t<port> swap [power|data|vconn]" +#ifdef CONFIG_USB_PD_EPR + "\n\t<port> epr [enter|exit]" +#endif #endif /* CONFIG_USB_PD_DUAL_ROLE */ , "USB PD"); diff --git a/test/test_config.h b/test/test_config.h index e87a63453b..8f1c482b71 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -610,6 +610,10 @@ int ncp15wb_calculate_temp(uint16_t adc); #endif #endif /* TEST_USB_PD || TEST_USB_PD_GIVEBACK || TEST_USB_PD_REV30 */ +#ifdef TEST_USB_PD_CONSOLE +#define CONFIG_USB_PD_EPR +#endif + #ifdef TEST_USB_PPC #define CONFIG_USB_PD_PORT_MAX_COUNT 1 #define CONFIG_USB_PD_VBUS_DETECT_PPC diff --git a/test/usb_pd_console.c b/test/usb_pd_console.c index bc647f094e..a835a643f8 100644 --- a/test/usb_pd_console.c +++ b/test/usb_pd_console.c @@ -33,6 +33,8 @@ static bool tc_get_current_state_called; static bool tc_get_flags_called; static bool pe_get_current_state_called; static bool pe_get_flags_called; +static bool pe_is_explicit_contract_called; +static bool pe_snk_in_epr_mode_called; static bool pd_get_dual_role_called; static bool board_get_usb_pd_port_count_called; static bool pd_srccaps_dump_called; @@ -51,6 +53,7 @@ static int vdm_count; static int vdm_vid; static uint32_t vdm_data[10]; static enum pd_dual_role_states dr_state; +static enum pd_power_role pd_get_power_role_return = PD_ROLE_SINK; /* Mock functions */ int tc_is_vconn_src(int port) @@ -62,7 +65,7 @@ int tc_is_vconn_src(int port) enum pd_power_role pd_get_power_role(int port) { pd_get_power_role_called = true; - return 0; + return pd_get_power_role_return; } uint32_t pe_get_flags(int port) @@ -71,6 +74,18 @@ uint32_t pe_get_flags(int port) return 0; } +int pe_is_explicit_contract(int port) +{ + pe_is_explicit_contract_called = true; + return 1; +} + +bool pe_snk_in_epr_mode(int port) +{ + pe_snk_in_epr_mode_called = true; + return true; +} + const char *pe_get_current_state(int port) { pe_get_current_state_called = true; @@ -660,6 +675,8 @@ static int test_command_pd_state(void) tc_get_flags_called = false; pe_get_current_state_called = false; pe_get_flags_called = false; + pe_is_explicit_contract_called = true; + pe_snk_in_epr_mode_called = true; TEST_ASSERT(command_pd(argc, argv) == EC_SUCCESS); TEST_ASSERT(pd_get_polarity_called); @@ -671,6 +688,8 @@ static int test_command_pd_state(void) TEST_ASSERT(tc_get_flags_called); TEST_ASSERT(pe_get_current_state_called); TEST_ASSERT(pe_get_flags_called); + TEST_ASSERT(pe_is_explicit_contract_called); + TEST_ASSERT(pe_snk_in_epr_mode_called); return EC_SUCCESS; } @@ -687,6 +706,46 @@ static int test_command_pd_srccaps(void) return EC_SUCCESS; } +static int test_command_pd_epr(void) +{ + int argc = 4; + const char *argv[] = { "pd", "0", "epr", "enter" }; + + /* Return EC_ERROR_PARAM_COUNT if argc < 3. */ + TEST_ASSERT(command_pd(3, argv) == EC_ERROR_PARAM_COUNT); + + /* Return SUCCESS with request==0 if role==PD_ROLE_SOURCE. */ + request = 0; + pd_get_power_role_called = false; + pd_get_power_role_return = PD_ROLE_SOURCE; + TEST_ASSERT(command_pd(argc, argv) == EC_SUCCESS); + TEST_ASSERT(pd_get_power_role_called); + TEST_ASSERT(request == 0); + + /* Return SUCCESS with request==DPM_REQUEST_EPR_MODE_ENTRY. */ + request = 0; + pd_get_power_role_called = false; + pd_get_power_role_return = PD_ROLE_SINK; + TEST_ASSERT(command_pd(argc, argv) == EC_SUCCESS); + TEST_ASSERT(pd_get_power_role_called); + TEST_ASSERT(request == DPM_REQUEST_EPR_MODE_ENTRY); + + /* Return SUCCESS with request==DPM_REQUEST_EPR_MODE_EXIT. */ + argv[3] = "exit"; + request = 0; + pd_get_power_role_called = false; + pd_get_power_role_return = PD_ROLE_SINK; + TEST_ASSERT(command_pd(argc, argv) == EC_SUCCESS); + TEST_ASSERT(pd_get_power_role_called); + TEST_ASSERT(request == DPM_REQUEST_EPR_MODE_EXIT); + + /* Return EC_ERROR_PARAM3 for invalid sub-command. */ + argv[3] = "start"; + TEST_ASSERT(command_pd(argc, argv) == EC_ERROR_PARAM3); + + return EC_SUCCESS; +} + static int test_command_pd_timer(void) { int argc = 3; @@ -731,6 +790,7 @@ void run_test(int argc, const char **argv) RUN_TEST(test_command_pd_dualrole3); RUN_TEST(test_command_pd_dualrole4); RUN_TEST(test_command_pd_dualrole5); + RUN_TEST(test_command_pd_epr); RUN_TEST(test_command_pd_state); RUN_TEST(test_command_pd_srccaps); RUN_TEST(test_command_pd_timer); |