summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/usbc/usb_pd_console.c40
-rw-r--r--test/test_config.h4
-rw-r--r--test/usb_pd_console.c62
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);