From 9b4324744dc8ce02d076edb60c7d7b787c57bc71 Mon Sep 17 00:00:00 2001 From: Diana Z Date: Wed, 24 Mar 2021 15:58:20 -0600 Subject: TCPMv2: Call debug detach on toggle changes When our power state changes partway through a debug connection starting, we may end up transitioning straight from a source to a sink role without calling the debug detach routine. Ensure that dual role changes call the debug detach when forcing state changes between source and sink, where we were not previously Attached. BRANCH=None BUG=b:183619502 TEST=on galith, firmware_UserRequestRecovery can pass Signed-off-by: Diana Z Change-Id: Id2214487be9be4209dbd9bece94492bc4ac9c05e Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2786068 Reviewed-by: Henry Sun Commit-Queue: Henry Sun Tested-by: Henry Sun Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2795064 Tested-by: Abe Levkoy Reviewed-by: Abe Levkoy Commit-Queue: Abe Levkoy --- common/usbc/usb_tc_drp_acc_trysrc_sm.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c index 8daf8704e2..269ded1159 100644 --- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c +++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c @@ -1810,7 +1810,12 @@ static void pd_update_dual_role_config(int port) * Change to sink if port is currently a source AND (new DRP * state is force sink OR new DRP state is toggle off and we are * in the source disconnected state). + * + * Force a debug detach in case there was an incomplete debug + * connection in progress. */ + if (get_state_tc(port) != TC_ATTACHED_SRC) + tcpm_debug_detach(port); set_state_tc(port, TC_UNATTACHED_SNK); } else if (tc[port].power_role == PD_ROLE_SINK && drp_state[port] == PD_DRP_FORCE_SOURCE) { @@ -1818,6 +1823,8 @@ static void pd_update_dual_role_config(int port) * Change to source if port is currently a sink and the * new DRP state is force source. */ + if (get_state_tc(port) != TC_ATTACHED_SNK) + tcpm_debug_detach(port); set_state_tc(port, TC_UNATTACHED_SRC); } } -- cgit v1.2.1