From 5c26087ef381fbe8469498eb65ecb10fc62ba349 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Fri, 9 Jan 2015 11:11:56 -0800 Subject: 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 Reviewed-on: https://chromium-review.googlesource.com/239951 Reviewed-by: Vincent Palatin Reviewed-by: Todd Broch --- common/usb_pd_protocol.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index d54c20dcac..8a837be345 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -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 { -- cgit v1.2.1