From e477345da07a552148b6e45d3f109fa459b45bb6 Mon Sep 17 00:00:00 2001 From: Diana Z Date: Wed, 11 Aug 2021 13:45:04 -0600 Subject: TCPMv2: Fix ordering of Vbus application in Attached.SRC entry Per the TCPCI spec figures, we should be setting the CC lines and enabling Auto Discharge Disconnect before attempting to source Vbus. Doing these things out of order may cause Vbus sourcing to appear to fail when a TCPC is waiting for ADD to set before enabling Vbus. BRANCH=None BUG=b:195966013 TEST=on guybrush, verify both C0 and C1 successfully detect that they are sourcing Vbus with an unpowered Apple 3-in-1 dongle Signed-off-by: Diana Z Change-Id: Icb0bd221a7d8eb069b74327c27894e5d92e95329 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3088003 Reviewed-by: Edward Hill Reviewed-by: Denis Brockus Commit-Queue: Edward Hill --- common/usbc/usb_tc_drp_acc_trysrc_sm.c | 36 ++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/common/usbc/usb_tc_drp_acc_trysrc_sm.c b/common/usbc/usb_tc_drp_acc_trysrc_sm.c index c56bcd2b81..1049326e42 100644 --- a/common/usbc/usb_tc_drp_acc_trysrc_sm.c +++ b/common/usbc/usb_tc_drp_acc_trysrc_sm.c @@ -2979,11 +2979,23 @@ static void tc_attached_src_entry(const int port) * completed and tc_pr_swap_complete is called. */ } else { + /* + * Set up CC's, Vconn, and ADD before Vbus, as per + * Figure 4-24. DRP Initialization and Connection + * Detection in TCPCI r2 v1.2 specification. + */ + /* Get connector orientation */ tcpm_get_cc(port, &cc1, &cc2); tc[port].polarity = get_src_polarity(cc1, cc2); pd_set_polarity(port, tc[port].polarity); + /* Attached.SRC - enable AutoDischargeDisconnect */ + tcpm_enable_auto_discharge_disconnect(port, 1); + + /* Apply Rp */ + typec_update_cc(port); + /* * Initial data role for sink is DFP * This also sets the usb mux @@ -3013,23 +3025,29 @@ static void tc_attached_src_entry(const int port) tc[port].polarity); } - /* Attached.SRC - enable AutoDischargeDisconnect */ - tcpm_enable_auto_discharge_disconnect(port, 1); - - /* Apply Rp */ - typec_update_cc(port); - tc_enable_pd(port, 0); pd_timer_enable(port, TC_TIMER_TIMEOUT, MAX(PD_POWER_SUPPLY_TURN_ON_DELAY, PD_T_VCONN_STABLE)); } } else { + /* + * Set up CC's, Vconn, and ADD before Vbus, as per + * Figure 4-24. DRP Initialization and Connection + * Detection in TCPCI r2 v1.2 specification. + */ + /* Get connector orientation */ tcpm_get_cc(port, &cc1, &cc2); tc[port].polarity = get_src_polarity(cc1, cc2); pd_set_polarity(port, tc[port].polarity); + /* Attached.SRC - enable AutoDischargeDisconnect */ + tcpm_enable_auto_discharge_disconnect(port, 1); + + /* Apply Rp */ + typec_update_cc(port); + /* * Initial data role for sink is DFP * This also sets the usb mux @@ -3056,12 +3074,6 @@ static void tc_attached_src_entry(const int port) usb_mux_set(port, USB_PD_MUX_NONE, USB_SWITCH_DISCONNECT, tc[port].polarity); } - - /* Attached.SRC - enable AutoDischargeDisconnect */ - tcpm_enable_auto_discharge_disconnect(port, 1); - - /* Apply Rp */ - typec_update_cc(port); } /* Inform PPC and OCP module that a sink is connected. */ -- cgit v1.2.1