summaryrefslogtreecommitdiff
path: root/test/usb_pd.c
diff options
context:
space:
mode:
authorSam Hurst <shurst@google.com>2017-01-10 09:55:37 -0800
committerchrome-bot <chrome-bot@chromium.org>2017-01-26 18:43:52 -0800
commit17515de32c7dffc5a9afd7e365a4dd31b3d3074a (patch)
tree5957d718301b4c0377906cc3f4a49a501785b918 /test/usb_pd.c
parent7736c887d786c8ee2374dcc2b7fe4a4fc066c9bb (diff)
downloadchrome-ec-17515de32c7dffc5a9afd7e365a4dd31b3d3074a.tar.gz
pd: support gotoMin and giveBack
In Sink mode, on the receipt of a GotoMin message, reduce the current consumption to some minimum level. BUG=chrome-os-partner:33688 TEST=Manual testing Used a Kevin, with test routine, to test GotoMin feature on another Kevin unit. Test routine: if (!strcasecmp(argv[2], "gm")) { ccprintf("send goto min\n"); send_control(port, PD_CTRL_GOTO_MIN); send_control(port, PD_CTRL_PS_RDY); } Kevin with GotoMin feature: # ectool usbpdpower 0 Port 0: SNK DRP PD 4277mV / 3000mA, max 5000mV / 3000mA / 15000mW Port 1: Disconnected After Test routine is executed: # ectool usbpdpower 0 Port 0: SNK DRP PD 4906mV / 500mA, max 5000mV / 500mA / 2500mW Port 1: Disconnected BRANCH=none Change-Id: Iaac6e19706ceb10ccaff4d602d63fc086c808c8f Reviewed-on: https://chromium-review.googlesource.com/425728 Commit-Ready: Sam Hurst <shurst@google.com> Tested-by: Sam Hurst <shurst@google.com> Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'test/usb_pd.c')
-rw-r--r--test/usb_pd.c74
1 files changed, 73 insertions, 1 deletions
diff --git a/test/usb_pd.c b/test/usb_pd.c
index 233714e3ad..d87a4c3960 100644
--- a/test/usb_pd.c
+++ b/test/usb_pd.c
@@ -27,6 +27,8 @@ struct pd_port_t {
int partner_polarity;
} pd_port[CONFIG_USB_PD_PORT_COUNT];
+static int give_back_called;
+
/* Mock functions */
int pd_adc_read(int port, int cc)
@@ -193,9 +195,37 @@ static void unplug(int port)
usleep(30 * MSEC);
}
+void pd_snk_give_back(int port, uint32_t * const ma, uint32_t * const mv)
+{
+ if (*ma == 3000)
+ give_back_called = 1;
+}
+
+static void simulate_ps_rdy(int port)
+{
+ uint16_t header = PD_HEADER(PD_CTRL_PS_RDY, PD_ROLE_SOURCE,
+ PD_ROLE_DFP, pd_port[port].msg_rx_id,
+ 0);
+
+ simulate_rx_msg(port, header, 0, NULL);
+}
+
+static void simulate_goto_min(int port)
+{
+ uint16_t header = PD_HEADER(PD_CTRL_GOTO_MIN, PD_ROLE_SOURCE,
+ PD_ROLE_DFP, pd_port[port].msg_rx_id, 0);
+
+ simulate_rx_msg(port, header, 0, NULL);
+}
+
static int test_request_with_wait_and_contract(void)
{
+#ifdef CONFIG_USB_PD_GIVE_BACK
+ uint32_t expected_rdo =
+ RDO_FIXED(2, 3000, PD_MIN_CURRENT_MA, RDO_GIVE_BACK);
+#else
uint32_t expected_rdo = RDO_FIXED(2, 3000, 3000, 0);
+#endif
uint8_t port = PORT0;
plug_in_source(port, 0);
@@ -310,6 +340,34 @@ static int test_request_with_wait_and_contract(void)
task_wait_event(30 * MSEC);
TEST_ASSERT(verify_goodcrc(0, PD_ROLE_SINK, pd_port[port].msg_rx_id));
+ task_wake(PD_PORT_TO_TASK_ID(port));
+ task_wait_event(30 * MSEC);
+ inc_rx_id(port);
+
+ /* We're in SNK_TRANSITION. Send ps_rdy */
+ simulate_ps_rdy(port);
+ task_wait_event(30 * MSEC);
+ TEST_ASSERT(verify_goodcrc(0, PD_ROLE_SINK, pd_port[port].msg_rx_id));
+
+ task_wake(PD_PORT_TO_TASK_ID(port));
+ task_wait_event(30 * MSEC);
+ inc_rx_id(port);
+
+ /* We're in SNK_READY. Send goto_min */
+ simulate_goto_min(port);
+ task_wait_event(30 * MSEC);
+ TEST_ASSERT(verify_goodcrc(0, PD_ROLE_SINK, pd_port[port].msg_rx_id));
+
+ task_wake(PD_PORT_TO_TASK_ID(port));
+ task_wait_event(30 * MSEC);
+ inc_rx_id(port);
+
+#ifdef CONFIG_USB_PD_GIVE_BACK
+ TEST_ASSERT(give_back_called);
+#else
+ TEST_ASSERT(!give_back_called);
+#endif
+
/* We're done */
unplug(port);
@@ -318,7 +376,12 @@ static int test_request_with_wait_and_contract(void)
static int test_request_with_wait(void)
{
+#ifdef CONFIG_USB_PD_GIVE_BACK
+ uint32_t expected_rdo = RDO_FIXED(1, 900, PD_MIN_CURRENT_MA,
+ RDO_CAP_MISMATCH | RDO_GIVE_BACK);
+#else
uint32_t expected_rdo = RDO_FIXED(1, 900, 900, RDO_CAP_MISMATCH);
+#endif
uint8_t port = PORT0;
plug_in_source(port, 0);
@@ -401,7 +464,12 @@ static int test_request_with_wait(void)
static int test_request_with_reject(void)
{
+#ifdef CONFIG_USB_PD_GIVE_BACK
+ uint32_t expected_rdo = RDO_FIXED(1, 900, PD_MIN_CURRENT_MA,
+ RDO_CAP_MISMATCH | RDO_GIVE_BACK);
+#else
uint32_t expected_rdo = RDO_FIXED(1, 900, 900, RDO_CAP_MISMATCH);
+#endif
uint8_t port = PORT0;
plug_in_source(port, 0);
@@ -474,7 +542,12 @@ static int test_request_with_reject(void)
static int test_request(void)
{
+#ifdef CONFIG_USB_PD_GIVE_BACK
+ uint32_t expected_rdo = RDO_FIXED(1, 900, PD_MIN_CURRENT_MA,
+ RDO_CAP_MISMATCH | RDO_GIVE_BACK);
+#else
uint32_t expected_rdo = RDO_FIXED(1, 900, 900, RDO_CAP_MISMATCH);
+#endif
uint8_t port = PORT0;
plug_in_source(port, 0);
@@ -562,6 +635,5 @@ void run_test(void)
RUN_TEST(test_request_with_wait);
RUN_TEST(test_request_with_wait_and_contract);
RUN_TEST(test_request_with_reject);
-
test_print_result();
}