pd: avoid multiple role swaps on connect

Avoid multiple power and data swaps on connect by clearing our
local flag for checking our role when we receive a role swap.
This means if the port partner sends a role swap on connect before
us and we accept, then we will not turn around and ask for another
swap.

BUG=none
BRANCH=samus
TEST=connect samus to samus and make sure only one swap on connect.

Change-Id: I2414b5bd5ffc54701b5758047e5d7e51ca3ff596
Signed-off-by: Alec Berg <alecaberg@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/239951
Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Todd Broch <tbroch@chromium.org>
This commit is contained in:
Alec Berg
2015-01-09 11:11:56 -08:00
parent 8fbb6e8070
commit 5c26087ef3

View File

@@ -1161,6 +1161,11 @@ static void handle_ctrl_request(int port, uint16_t head,
#ifdef CONFIG_USB_PD_DUAL_ROLE
if (pd_check_power_swap(port)) {
send_control(port, PD_CTRL_ACCEPT);
/*
* Clear flag for checking power role to avoid
* immediately requesting another swap.
*/
pd[port].flags &= ~PD_FLAGS_CHECK_PR_ROLE;
if (pd[port].power_role == PD_ROLE_SINK)
set_state(port, PD_STATE_SNK_SWAP_SNK_DISABLE);
else
@@ -1174,7 +1179,12 @@ static void handle_ctrl_request(int port, uint16_t head,
break;
case PD_CTRL_DR_SWAP:
if (pd_check_data_swap(port, pd[port].data_role)) {
/* Accept switch and perform data swap */
/*
* Accept switch and perform data swap. Clear
* flag for checking data role to avoid
* immediately requesting another swap.
*/
pd[port].flags &= ~PD_FLAGS_CHECK_DR_ROLE;
if (send_control(port, PD_CTRL_ACCEPT) >= 0)
pd_dr_swap(port);
} else {