diff options
author | Scott Collyer <scollyer@google.com> | 2021-06-01 10:35:34 -0700 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-06-06 04:02:27 +0000 |
commit | e3d0d94a559dff751a4b4dc28617170be4f05ac8 (patch) | |
tree | b1485f1f314dcb6c7e7c60bc53f6c2a7bc753508 /baseboard/honeybuns | |
parent | f2f46e879f5cc9a3197caefb1616918baa5ece21 (diff) | |
download | chrome-ec-e3d0d94a559dff751a4b4dc28617170be4f05ac8.tar.gz |
honeybuns: Limit data role swap request attempts
This CL modifies honeybuns data role swap policy in 2 ways. First, the
dependence on dr_swap_flag is removed. Second, a new variable is added
to track data role swap attempts per each usbc attach. Previosly,
dr_swap_flag was used as a means to limit the number of data role swap
attempts, but the flag that is passed in is set in PE code that is
specific to a typical chromebook port policy.
The new policy is to always try to be the desired data role, but limit
the attempts for situations where the port partner rejects the
request. This case happens for example with compliance testing.
HOOK_USB_PD_CONNECT is used to clear the max attempt counter as this
should apply once per each usbc attach event.
BUG=b:188756664
BRANCH=quiche
TEST=Verifed that the host port will request a data role swap when
testing against the iPad. Against the ipad, host port always attaches
as a source, and would remain a DFP.
Signed-off-by: Scott Collyer <scollyer@google.com>
Change-Id: Ib913f8bbba76d2bd12dccb6a6a49ef4249d428ed
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2934358
Tested-by: Scott Collyer <scollyer@chromium.org>
Reviewed-by: Diana Z <dzigterman@chromium.org>
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
Commit-Queue: Scott Collyer <scollyer@chromium.org>
Diffstat (limited to 'baseboard/honeybuns')
-rw-r--r-- | baseboard/honeybuns/usb_pd_policy.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/baseboard/honeybuns/usb_pd_policy.c b/baseboard/honeybuns/usb_pd_policy.c index 96739c2356..869f334bcd 100644 --- a/baseboard/honeybuns/usb_pd_policy.c +++ b/baseboard/honeybuns/usb_pd_policy.c @@ -58,6 +58,9 @@ const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); static int src_host_pdo_cnt_override; +#define PD_DR_SWAP_ATTEMPT_MAX 3 +static int pd_dr_swap_attempt_count[CONFIG_USB_PD_PORT_MAX_COUNT]; + static int command_hostpdo(int argc, char **argv) { char *e; @@ -120,9 +123,13 @@ __override bool port_discovery_dr_swap_policy(int port, /* * Request data role swap if not in the port's desired data role and if - * flag to check for data role in PE is set. + * the attempt count is less than the max allowed. This function is + * called for each PE run once in a PD contract. If the port partner + * rejects data role swap requests (eg compliance tester), want to limit + * how many DR swap requests are attempted. */ - if (dr == role_test && dr_swap_flag) + if (dr == role_test && (pd_dr_swap_attempt_count[port]++ < + PD_DR_SWAP_ATTEMPT_MAX)) return true; /* Do not perform a DR swap */ @@ -320,24 +327,31 @@ int pd_check_power_swap(int port) static void usb_tc_connect(void) { + int port = TASK_ID_TO_PD_PORT(task_get_current()); + /* * The EC needs to indicate to the USB hub when the host port is * attached so that the USB-EP can be properly enumerated. GPIO_BPWR_DET * is used for this purpose. */ - if (pd_is_connected(USB_PD_PORT_HOST)) { + if (port == USB_PD_PORT_HOST) { gpio_set_level(GPIO_BPWR_DET, 1); #ifdef GPIO_UFP_PLUG_DET gpio_set_level(GPIO_UFP_PLUG_DET, 1); #endif } + + /* Clear data role swap attempt counter at each usbc attach */ + pd_dr_swap_attempt_count[port] = 0; } DECLARE_HOOK(HOOK_USB_PD_CONNECT, usb_tc_connect, HOOK_PRIO_DEFAULT); static void usb_tc_disconnect(void) { + int port = TASK_ID_TO_PD_PORT(task_get_current()); + /* Only the host port disconnect is relevant */ - if (!pd_is_connected(USB_PD_PORT_HOST)) { + if (port == USB_PD_PORT_HOST) { gpio_set_level(GPIO_BPWR_DET, 0); #ifdef GPIO_UFP_PLUG_DET gpio_set_level(GPIO_UFP_PLUG_DET, 0); |