diff options
author | Peter Marheine <pmarheine@chromium.org> | 2020-08-04 11:24:16 +1000 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-06 07:27:49 +0000 |
commit | 0385893469bad2c00690268d112436086fa69d1a (patch) | |
tree | 80f2a73e6933d8aa3c76b12172659348e42a71bc /test/usb_pe_drp.c | |
parent | ea334082eb7bcf690a54e2773ddaec2905075922 (diff) | |
download | chrome-ec-0385893469bad2c00690268d112436086fa69d1a.tar.gz |
usbc: correctly handle Get_Source_Cap as a sink
USB Power Delivery Specification Revision 3.0, version 2.0 section 6.3.7
states that a dual-role port shall respond to Get_Source_Cap with its
source capabilities, but this was incorrectly handled by responding with
a request for source capabilities.
Per section 8.3.3.18.10, implement the PE_DR_SNK_Give_Source_Cap state to
handle this correctly.
To support the new test, some helper functions for the fake PE are added
and the test code's copy of the PE state enum is updated to be in sync
with the real one.
BUG=b:161400825,b:161331630
TEST=New host test for this state, and verified on Dalboz that requesting a
PRS via the EC console (`pd 1 swap power`) now sends source
capabilities when the partner requests them.
BRANCH=None
Signed-off-by: Peter Marheine <pmarheine@chromium.org>
Change-Id: I87c27d406e0a3f57cf2c25fa583bee51155b6b12
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2336233
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Diffstat (limited to 'test/usb_pe_drp.c')
-rw-r--r-- | test/usb_pe_drp.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/usb_pe_drp.c b/test/usb_pe_drp.c index 6cd1fb2bde..b57f0c09bd 100644 --- a/test/usb_pe_drp.c +++ b/test/usb_pe_drp.c @@ -178,6 +178,32 @@ static int test_pe_frs(void) return EC_SUCCESS; } +static int test_snk_give_source_cap(void) +{ + setup_sink(); + + /* + * Receive a Get_Source_Cap message; respond with Source_Capabilities + * and return to PE_SNK_Ready once sent. + */ + rx_emsg[PORT0].header = + PD_HEADER(PD_CTRL_GET_SOURCE_CAP, 0, 0, 0, 0, 0, 0); + pe_set_flag(PORT0, PE_FLAGS_MSG_RECEIVED); + task_wait_event(10 * MSEC); + + TEST_ASSERT(!pe_chk_flag(PORT0, PE_FLAGS_MSG_RECEIVED)); + TEST_ASSERT(!pe_chk_flag(PORT0, PE_FLAGS_TX_COMPLETE)); + TEST_EQ(fake_prl_get_last_sent_data_msg_type(PORT0), + PD_DATA_SOURCE_CAP, "%d"); + TEST_EQ(get_state_pe(PORT0), PE_DR_SNK_GIVE_SOURCE_CAP, "%d"); + + pe_set_flag(PORT0, PE_FLAGS_TX_COMPLETE); + task_wait_event(10 * MSEC); + TEST_EQ(get_state_pe(PORT0), PE_SNK_READY, "%d"); + + return EC_SUCCESS; +} + static int test_vbus_gpio_discharge(void) { pd_set_vbus_discharge(PORT0, 1); @@ -318,6 +344,7 @@ void run_test(int argc, char **argv) test_reset(); RUN_TEST(test_pe_frs); + RUN_TEST(test_snk_give_source_cap); RUN_TEST(test_vbus_gpio_discharge); #ifndef CONFIG_USB_PD_EXTENDED_MESSAGES RUN_TEST(test_extended_message_not_supported_src); |