From 347c7313a03fff7f268d17a84d2d65ddd0699e41 Mon Sep 17 00:00:00 2001 From: Alec Berg Date: Fri, 9 Jan 2015 14:02:53 -0800 Subject: pd: ensure power role matches CC pull resistor after hard reset Make sure the power role and the CC pull resistor match after receiving hard reset command in the middle of a swap. BUG=none BRANCH=samus TEST=on samus connect left and right ports together with C to C cable. note that after some collisions and some hard resets, it eventually stabilizes with one port in SNK_READY, the other in SRC_READY. without this CL, we get stuck executing a power swap and our power role and CC resistor get out of sync, requiring a reboot. Change-Id: Ia1385eb3a1c503052ad5bfd0d1595ecc096cd5f4 Signed-off-by: Alec Berg Reviewed-on: https://chromium-review.googlesource.com/239976 Reviewed-by: Vincent Palatin Reviewed-by: Todd Broch --- common/usb_pd_protocol.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/usb_pd_protocol.c b/common/usb_pd_protocol.c index 8a837be345..cedf027094 100644 --- a/common/usb_pd_protocol.c +++ b/common/usb_pd_protocol.c @@ -813,6 +813,20 @@ static void execute_hard_reset(int port) #endif #ifdef CONFIG_USB_PD_DUAL_ROLE + /* + * If we are swapping to a source and have changed to Rp, restore back + * to Rd to match our power_role. + */ + if (pd[port].task_state == PD_STATE_SNK_SWAP_STANDBY || + pd[port].task_state == PD_STATE_SNK_SWAP_COMPLETE) + pd_set_host_mode(port, 0); + /* + * If we are swapping to a sink and have changed to Rd, change role to + * sink to match the CC pull resistor. + */ + if (pd[port].task_state == PD_STATE_SRC_SWAP_STANDBY) + pd[port].power_role = PD_ROLE_SINK; + if (pd[port].power_role == PD_ROLE_SINK) { /* Clear the input current limit */ pd_set_input_current_limit(port, 0, 0); -- cgit v1.2.1