diff mbox series

usb: typec: tcpm: reset counter when enter into unattached state after try role

Message ID 20230820151518.1403006-1-xu.yang_2@nxp.com
State New
Headers show
Series usb: typec: tcpm: reset counter when enter into unattached state after try role | expand

Commit Message

Xu Yang Aug. 20, 2023, 3:15 p.m. UTC
The try_src_count and try_snk_count may still be 1 after enter into
unattached state. This may be caused by below case:
 - SNK_TRY->SNK_TRY_WAIT->SRC_TRYWAIT->SNK_UNATTACHED
 - SRC_TRY->SRC_TRY_WAIT->SNK_TRYWAIT->SNK_UNATTACHED

The port->attached is not true at the end and tcpm_reset_port() will not
be called. This will reset counter into for these cases, otherwise the tcpm
won't try role when new cable attached.

Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
---
 drivers/usb/typec/tcpm/tcpm.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Heikki Krogerus Aug. 23, 2023, 6:52 a.m. UTC | #1
On Sun, Aug 20, 2023 at 11:15:18PM +0800, Xu Yang wrote:
> The try_src_count and try_snk_count may still be 1 after enter into
> unattached state. This may be caused by below case:
>  - SNK_TRY->SNK_TRY_WAIT->SRC_TRYWAIT->SNK_UNATTACHED
>  - SRC_TRY->SRC_TRY_WAIT->SNK_TRYWAIT->SNK_UNATTACHED
> 
> The port->attached is not true at the end and tcpm_reset_port() will not
> be called. This will reset counter into for these cases, otherwise the tcpm
> won't try role when new cable attached.
> 
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 5639b9a1e0bf..c9a186a8c58c 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -3719,6 +3719,9 @@ static void tcpm_detach(struct tcpm_port *port)
>  	if (tcpm_port_is_disconnected(port))
>  		port->hard_reset_count = 0;
>  
> +	port->try_src_count = 0;
> +	port->try_snk_count = 0;
> +
>  	if (!port->attached)
>  		return;
>  
> -- 
> 2.34.1
Guenter Roeck Aug. 23, 2023, 1:25 p.m. UTC | #2
On Sun, Aug 20, 2023 at 11:15:18PM +0800, Xu Yang wrote:
> The try_src_count and try_snk_count may still be 1 after enter into
> unattached state. This may be caused by below case:
>  - SNK_TRY->SNK_TRY_WAIT->SRC_TRYWAIT->SNK_UNATTACHED
>  - SRC_TRY->SRC_TRY_WAIT->SNK_TRYWAIT->SNK_UNATTACHED
> 
> The port->attached is not true at the end and tcpm_reset_port() will not
> be called. This will reset counter into for these cases, otherwise the tcpm
> won't try role when new cable attached.
> 
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>

Reviewed-by: Guenter Roeck <linux@roeck-us.net>

> ---
>  drivers/usb/typec/tcpm/tcpm.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 5639b9a1e0bf..c9a186a8c58c 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -3719,6 +3719,9 @@ static void tcpm_detach(struct tcpm_port *port)
>  	if (tcpm_port_is_disconnected(port))
>  		port->hard_reset_count = 0;
>  
> +	port->try_src_count = 0;
> +	port->try_snk_count = 0;
> +
>  	if (!port->attached)
>  		return;
>  
> -- 
> 2.34.1
>
Ondřej Jirman Feb. 10, 2024, 5:28 p.m. UTC | #3
Hi,

On Sun, Aug 20, 2023 at 11:15:18PM +0800, Xu Yang wrote:
> The try_src_count and try_snk_count may still be 1 after enter into
> unattached state. This may be caused by below case:
>  - SNK_TRY->SNK_TRY_WAIT->SRC_TRYWAIT->SNK_UNATTACHED
>  - SRC_TRY->SRC_TRY_WAIT->SNK_TRYWAIT->SNK_UNATTACHED
> 
> The port->attached is not true at the end and tcpm_reset_port() will not
> be called. This will reset counter into for these cases, otherwise the tcpm
> won't try role when new cable attached.
> 
> Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> ---
>  drivers/usb/typec/tcpm/tcpm.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> index 5639b9a1e0bf..c9a186a8c58c 100644
> --- a/drivers/usb/typec/tcpm/tcpm.c
> +++ b/drivers/usb/typec/tcpm/tcpm.c
> @@ -3719,6 +3719,9 @@ static void tcpm_detach(struct tcpm_port *port)
>  	if (tcpm_port_is_disconnected(port))
>  		port->hard_reset_count = 0;
>  
> +	port->try_src_count = 0;
> +	port->try_snk_count = 0;

This patch breaks partner detection for USB type-c hubs and USB type-c docks.

Connecting an unpowered USB-C 4-port HUB:

Before reverting this patch: (endless loop)

[    0.657246] Setting usb_comm capable false
[    0.661870] Setting voltage/current limit 0 mV 0 mA
[    0.661880] polarity 0
[    0.661883] Requesting mux state 0, usb-role 0, orientation 0
[    0.663879] state change INVALID_STATE -> SNK_UNATTACHED [rev1 NONE_AMS]
[    0.663891] CC1: 0 -> 0, CC2: 0 -> 0 [state SNK_UNATTACHED, polarity 0, disconnected]
[    0.663897] 4-0022: registered
[    0.663962] Setting usb_comm capable false
[    0.669903] Setting voltage/current limit 0 mV 0 mA
[    0.669914] polarity 0
[    0.669917] Requesting mux state 0, usb-role 0, orientation 0
[    0.672166] cc:=2
[    0.679360] pending state change PORT_RESET -> PORT_RESET_WAIT_OFF @ 100 ms [rev1 NONE_AMS]
[    0.779554] state change PORT_RESET -> PORT_RESET_WAIT_OFF [delayed 100 ms]
[    0.779570] state change PORT_RESET_WAIT_OFF -> SNK_UNATTACHED [rev1 NONE_AMS]
[    0.779576] Start toggling
[   12.957711] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
[   12.957720] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   12.957729] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   13.157924] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   13.157939] cc:=2
[   13.167339] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   13.267545] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   13.267561] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   13.267566] cc:=3
[   13.278148] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   13.378347] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   13.378364] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   13.378373] Start toggling
[   13.387019] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   13.462597] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   13.462606] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   13.462613] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   13.662808] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   13.662827] cc:=2
[   13.672351] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   13.772550] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   13.772581] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   13.772586] cc:=3
[   13.781883] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   13.882095] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   13.882112] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   13.882118] Start toggling
[   13.890365] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   13.967377] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   13.967386] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   13.967393] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   14.167587] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   14.167602] cc:=2
[   14.177398] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   14.277605] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   14.277621] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   14.277626] cc:=3
[   14.287822] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   14.388028] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   14.388045] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   14.388051] Start toggling
[   14.397965] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   14.472959] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   14.472968] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   14.472975] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   14.673163] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   14.673179] cc:=2
[   14.683570] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   14.783777] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   14.783793] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   14.783798] cc:=3
[   14.793352] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   14.893469] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   14.893485] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   14.893492] Start toggling
[   14.903601] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   14.983779] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   14.983788] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   14.983796] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   15.183991] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   15.184005] cc:=2
[   15.193756] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   15.293963] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   15.293980] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   15.293985] cc:=3
[   15.304408] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   15.404606] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   15.404623] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   15.404629] Start toggling
[   15.414219] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   15.492054] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   15.492063] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   15.492071] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   15.692264] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   15.692279] cc:=2
[   15.701387] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   15.801593] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   15.801609] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   15.801615] cc:=3
[   15.811570] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   15.911786] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   15.911803] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   15.911809] Start toggling
[   15.920856] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   15.999246] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   15.999255] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   15.999263] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   16.199458] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   16.199474] cc:=2
[   16.208903] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   16.309105] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   16.309122] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   16.309127] cc:=3
[   16.319633] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   16.419838] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   16.419854] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   16.419861] Start toggling
[   16.428888] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   16.505691] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   16.505699] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   16.505706] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   16.705894] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   16.705910] cc:=2
[   16.715312] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   16.815518] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   16.815534] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   16.815539] cc:=3
[   16.825341] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   16.925553] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   16.925571] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   16.925577] Start toggling
[   16.934430] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   17.008462] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   17.008471] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   17.008478] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   17.208666] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   17.208683] cc:=2
[   17.218657] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   17.318863] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   17.318879] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   17.318884] cc:=3
[   17.328497] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   17.428704] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   17.428720] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   17.428727] Start toggling
[   17.437989] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   17.517195] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   17.517204] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   17.517213] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   17.717406] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   17.717422] cc:=2
[   17.727337] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   17.827542] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   17.827559] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   17.827563] cc:=3
[   17.837921] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   17.938133] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   17.938149] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   17.938156] Start toggling
[   17.946970] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   18.020575] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   18.020584] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   18.020591] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   18.220785] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   18.220801] cc:=2
[   18.231043] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   18.331250] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   18.331266] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   18.331271] cc:=3
[   18.341883] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   18.442081] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   18.442098] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   18.442104] Start toggling
[   18.450845] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   18.529250] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   18.529259] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   18.529267] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   18.729453] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   18.729469] cc:=2
[   18.739051] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   18.839250] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   18.839267] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   18.839271] cc:=3
[   18.847079] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   18.947289] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   18.947305] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   18.947312] Start toggling
[   18.955648] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   19.031557] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   19.031568] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   19.031576] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   19.231629] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   19.231644] cc:=2
[   19.241224] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   19.341424] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   19.341443] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   19.341449] cc:=3
[   19.351743] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   19.451963] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   19.451979] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   19.451986] Start toggling
[   19.460899] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   19.536487] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   19.536496] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   19.536503] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   19.736697] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   19.736712] cc:=2
[   19.746524] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   19.846714] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   19.846774] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   19.846779] cc:=3
[   19.856380] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   19.956584] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   19.956601] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   19.956607] Start toggling
[   19.964946] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   20.040030] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   20.040039] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   20.040046] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   20.240232] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   20.240248] cc:=2
[   20.248133] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   20.348339] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   20.348355] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   20.348361] cc:=3
[   20.357423] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   20.457475] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   20.457492] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   20.457498] Start toggling
[   20.467656] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   20.547175] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   20.547184] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   20.547193] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   20.747388] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   20.747403] cc:=2
[   20.756392] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   20.856458] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   20.856474] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   20.856479] cc:=3
[   20.863358] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   20.963403] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   20.963419] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   20.963425] Start toggling
[   20.969938] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   21.044949] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   21.044958] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   21.044966] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   21.245077] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   21.245090] cc:=2
[   21.251435] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   21.351484] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   21.351499] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   21.351508] cc:=3
[   21.357834] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   21.457897] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   21.457913] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   21.457920] Start toggling
[   21.464455] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   21.536293] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   21.536301] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   21.536312] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   21.736475] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   21.736488] cc:=2
[   21.745580] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   21.845679] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   21.845695] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   21.845700] cc:=3
[   21.852380] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   21.952434] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   21.952450] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   21.952457] Start toggling
[   21.958032] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   22.031084] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   22.031094] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   22.031101] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   22.231203] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   22.231218] cc:=2
[   22.237238] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   22.337281] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   22.337298] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   22.337304] cc:=3
[   22.343114] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   22.443221] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   22.443237] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   22.443244] Start toggling
[   22.449085] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   22.527011] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   22.527020] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   22.527028] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   22.727222] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   22.727238] cc:=2
[   22.736834] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   22.837041] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   22.837057] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   22.837062] cc:=3
[   22.847286] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   22.947351] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   22.947367] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   22.947373] Start toggling
[   22.955370] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   23.029294] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   23.029303] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   23.029310] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   23.229503] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   23.229518] cc:=2
[   23.239083] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   23.339294] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   23.339310] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   23.339315] cc:=3
[   23.347947] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   23.447989] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   23.448005] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   23.448011] Start toggling
[   23.457261] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   23.536826] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   23.536835] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   23.536843] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   23.736961] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   23.736977] cc:=2
[   23.746763] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   23.846952] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   23.846969] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   23.846974] cc:=3
[   23.855442] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   23.955490] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[   23.955505] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[   23.955511] Start toggling
[   23.964647] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[   24.037445] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   24.037454] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   24.037462] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   24.237649] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   24.237665] cc:=2
[   24.246526] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   24.346634] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   24.346649] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   24.346654] cc:=3
[   24.357490] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]

After reverting the patch:

[    0.665952] Setting usb_comm capable false
[    0.670577] Setting voltage/current limit 0 mV 0 mA
[    0.670584] polarity 0
[    0.670629] Requesting mux state 0, usb-role 0, orientation 0
[    0.672656] state change INVALID_STATE -> SNK_UNATTACHED [rev1 NONE_AMS]
[    0.672668] CC1: 0 -> 0, CC2: 0 -> 0 [state SNK_UNATTACHED, polarity 0, disconnected]
[    0.672674] 4-0022: registered
[    0.672734] Setting usb_comm capable false
[    0.678431] Setting voltage/current limit 0 mV 0 mA
[    0.678444] polarity 0
[    0.678447] Requesting mux state 0, usb-role 0, orientation 0
[    0.680532] cc:=2
[    0.686272] pending state change PORT_RESET -> PORT_RESET_WAIT_OFF @ 100 ms [rev1 NONE_AMS]
[    0.786469] state change PORT_RESET -> PORT_RESET_WAIT_OFF [delayed 100 ms]
[    0.786486] state change PORT_RESET_WAIT_OFF -> SNK_UNATTACHED [rev1 NONE_AMS]
[    0.786492] Start toggling
[    6.839620] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
[    6.839629] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[    6.839639] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[    7.039829] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[    7.039846] cc:=2
[    7.049047] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[    7.149249] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[    7.149266] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[    7.149270] cc:=3
[    7.158701] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[    7.258897] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
[    7.258915] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
[    7.258921] Start toggling
[    7.266951] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
[    7.341707] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[    7.341716] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[    7.341723] pending state change SRC_ATTACH_WAIT -> SRC_ATTACHED @ 200 ms [rev1 NONE_AMS]
[    7.541918] state change SRC_ATTACH_WAIT -> SRC_ATTACHED [delayed 200 ms]
[    7.541934] polarity 1
[    7.541939] Requesting mux state 1, usb-role 1, orientation 2
[    7.574501] vbus:=1 charge=0
[    7.574903] pending state change SRC_ATTACHED -> SRC_UNATTACHED @ 480 ms [rev1 NONE_AMS]
[    7.580492] VBUS on
[    7.580497] state change SRC_ATTACHED -> SRC_STARTUP [rev1 NONE_AMS]
[    7.580505] AMS POWER_NEGOTIATION start
[    7.580508] cc:=4
[    7.586492] state change SRC_STARTUP -> AMS_START [rev3 POWER_NEGOTIATION]
[    7.586498] state change AMS_START -> SRC_SEND_CAPABILITIES [rev3 POWER_NEGOTIATION]
[    7.586504] PD TX, header: 0x11a1
[    7.600290] PD TX complete, status: 2
[    7.600355] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    7.769110] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    7.769132] PD TX, header: 0x11a1
[    7.786930] PD TX complete, status: 2
[    7.788211] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    7.938343] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    7.938359] PD TX, header: 0x11a1
[    7.953177] PD TX complete, status: 2
[    7.953273] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    8.103472] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    8.103489] PD TX, header: 0x11a1
[    8.120014] PD TX complete, status: 2
[    8.120111] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    8.270231] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    8.270248] PD TX, header: 0x11a1
[    8.285528] PD TX complete, status: 2
[    8.285624] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    8.435766] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    8.435788] PD TX, header: 0x11a1
[    8.450077] PD TX complete, status: 2
[    8.450228] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    8.600425] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    8.600443] PD TX, header: 0x11a1
[    8.615200] PD TX complete, status: 2
[    8.615293] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    8.765492] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    8.765512] PD TX, header: 0x11a1
[    8.782628] PD TX complete, status: 2
[    8.782732] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    8.932917] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    8.932935] PD TX, header: 0x11a1
[    8.949602] PD TX complete, status: 2
[    8.949707] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    9.099911] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    9.099929] PD TX, header: 0x11a1
[    9.116041] PD TX complete, status: 2
[    9.116142] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    9.266308] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    9.266326] PD TX, header: 0x11a1
[    9.282962] PD TX complete, status: 2
[    9.283063] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    9.433223] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    9.433244] PD TX, header: 0x11a1
[    9.449758] PD TX complete, status: 2
[    9.449855] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    9.600047] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    9.600065] PD TX, header: 0x11a1
[    9.616269] PD TX complete, status: 2
[    9.616310] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    9.766453] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    9.766470] PD TX, header: 0x11a1
[    9.782042] PD TX complete, status: 2
[    9.782148] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[    9.932341] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[    9.932359] PD TX, header: 0x11a1
[    9.948928] PD TX complete, status: 2
[    9.949031] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   10.099231] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   10.099248] PD TX, header: 0x11a1
[   10.115496] PD TX complete, status: 2
[   10.115589] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   10.265782] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   10.265800] PD TX, header: 0x11a1
[   10.282709] PD TX complete, status: 2
[   10.282810] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   10.433011] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   10.433029] PD TX, header: 0x11a1
[   10.449594] PD TX complete, status: 2
[   10.449702] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   10.599852] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   10.599870] PD TX, header: 0x11a1
[   10.616542] PD TX complete, status: 2
[   10.616647] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   10.766844] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   10.766935] PD TX, header: 0x11a1
[   10.784152] PD TX complete, status: 2
[   10.784253] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   10.934369] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   10.934386] PD TX, header: 0x11a1
[   10.949643] PD TX complete, status: 2
[   10.949749] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   11.099930] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   11.099949] PD TX, header: 0x11a1
[   11.117254] PD TX complete, status: 2
[   11.117360] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   11.267418] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   11.267435] PD TX, header: 0x11a1
[   11.284007] PD TX complete, status: 2
[   11.284116] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   11.434308] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   11.434325] PD TX, header: 0x11a1
[   11.450561] PD TX complete, status: 2
[   11.450663] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   11.600855] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   11.600872] PD TX, header: 0x11a1
[   11.618078] PD TX complete, status: 2
[   11.618184] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   11.768378] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   11.768396] PD TX, header: 0x11a1
[   11.785107] PD TX complete, status: 2
[   11.785227] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   11.935431] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   11.935448] PD TX, header: 0x11a1
[   11.951955] PD TX complete, status: 2
[   11.952069] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   12.102261] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   12.102278] PD TX, header: 0x11a1
[   12.118553] PD TX complete, status: 2
[   12.118654] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   12.268854] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   12.268871] PD TX, header: 0x11a1
[   12.286119] PD TX complete, status: 2
[   12.286223] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   12.436417] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   12.436436] PD TX, header: 0x11a1
[   12.453586] PD TX complete, status: 2
[   12.453692] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   12.603893] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   12.603924] PD TX, header: 0x11a1
[   12.620706] PD TX complete, status: 2
[   12.620812] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   12.770935] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   12.770953] PD TX, header: 0x11a1
[   12.786119] PD TX complete, status: 2
[   12.786214] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   12.936405] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   12.936422] PD TX, header: 0x11a1
[   12.953263] PD TX complete, status: 2
[   12.953367] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   13.103568] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]
[   13.103585] state change SRC_SEND_CAPABILITIES -> SRC_READY [rev3 POWER_NEGOTIATION]
[   13.103759] AMS POWER_NEGOTIATION finished
[   13.103763] cc:=3

A diff:

--- work        2024-02-10 18:05:56.240978440 +0100
+++ nonwork     2024-02-10 18:06:27.800653295 +0100
@@ -1,55 +1,67 @@
 Setting usb_comm capable false
 Setting voltage/current limit 0 mV 0 mA
 polarity 0
 Requesting mux state 0, usb-role 0, orientation 0
 state change INVALID_STATE -> SNK_UNATTACHED [rev1 NONE_AMS]
 CC1: 0 -> 0, CC2: 0 -> 0 [state SNK_UNATTACHED, polarity 0, disconnected]
 4-0022: registered
 Setting usb_comm capable false
 Setting voltage/current limit 0 mV 0 mA
 polarity 0
 Requesting mux state 0, usb-role 0, orientation 0
-cc:=2 
+cc:=2
 pending state change PORT_RESET -> PORT_RESET_WAIT_OFF @ 100 ms [rev1 NONE_AMS]
 state change PORT_RESET -> PORT_RESET_WAIT_OFF [delayed 100 ms]
 state change PORT_RESET_WAIT_OFF -> SNK_UNATTACHED [rev1 NONE_AMS]
 Start toggling
 CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
 state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
 pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
 state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
 cc:=2
 pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
 state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
 state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
 cc:=3
 pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
 state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
 state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
 Start toggling
 state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
 CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
 state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
-pending state change SRC_ATTACH_WAIT -> SRC_ATTACHED @ 200 ms [rev1 NONE_AMS]
-state change SRC_ATTACH_WAIT -> SRC_ATTACHED [delayed 200 ms]
-polarity 1
+pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
+state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
+cc:=2

So it looks like the trouble start right after the first transition to
SNK_UNATTACHED which is when this new code from this patch runs.

I'm not that deep into the TCPM state machine code, but my thinking is that
give that this patch resets both try counters during transition to either
SNK_UNATTACHED or SRC_UNATTACHED and looking at the failing log, it somehow
breaks transition to SRC_ATTACHED state, when TOGGLING.

It only always goes from SRC_ATTACH_WAIT -> SNK_TRY with this patch.
Without this patch, it goes to SRC_ATTACHED after initially trying SNK_TRY
earlier.

So only use cases where the type-c port is in power sink mode, work and
use cases with type-c port being in source mode are broken.

Unless someone has a better idea, I'd like to send a revert for this patch,
which will make partner detection work again with the docks/ hubs I have. I'd be
happy to test a better fix for the original problem, that doesn't break the
power source mode when toggling on dual power role ports.

kind regards,
	o.

> +
>  	if (!port->attached)
>  		return;
>  
> -- 
> 2.34.1
>
Ondřej Jirman Feb. 24, 2024, 3:42 a.m. UTC | #4
Hi Xu,

On Mon, Feb 19, 2024 at 08:36:50AM +0000, Xu Yang wrote:
> Hi Ondřej,
> 
> > 
> > Hi,
> > 
> > On Sun, Aug 20, 2023 at 11:15:18PM +0800, Xu Yang wrote:
> > > The try_src_count and try_snk_count may still be 1 after enter into
> > > unattached state. This may be caused by below case:
> > >  - SNK_TRY->SNK_TRY_WAIT->SRC_TRYWAIT->SNK_UNATTACHED
> > >  - SRC_TRY->SRC_TRY_WAIT->SNK_TRYWAIT->SNK_UNATTACHED
> > >
> > > The port->attached is not true at the end and tcpm_reset_port() will not
> > > be called. This will reset counter into for these cases, otherwise the tcpm
> > > won't try role when new cable attached.
> > >
> > > Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> > > ---
> > >  drivers/usb/typec/tcpm/tcpm.c | 3 +++
> > >  1 file changed, 3 insertions(+)
> > >
> > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> > > index 5639b9a1e0bf..c9a186a8c58c 100644
> > > --- a/drivers/usb/typec/tcpm/tcpm.c
> > > +++ b/drivers/usb/typec/tcpm/tcpm.c
> > > @@ -3719,6 +3719,9 @@ static void tcpm_detach(struct tcpm_port *port)
> > >       if (tcpm_port_is_disconnected(port))
> > >               port->hard_reset_count = 0;
> > >
> > > +     port->try_src_count = 0;
> > > +     port->try_snk_count = 0;
> > 
> > This patch breaks partner detection for USB type-c hubs and USB type-c docks.
> 
> I guess the type-c port of hub is sink-only and the type-c port of dock
> is DRP, right?

The hub is sink-only, yes.

> > 
> > Connecting an unpowered USB-C 4-port HUB:
> > 
> > Before reverting this patch: (endless loop)
> > 
> > [   12.957711] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
> > [   12.957720] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> > [   12.957729] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> > [   13.157924] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> > [   13.157939] cc:=2
> > [   13.167339] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
> > [   13.267545] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
> > [   13.267561] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
> > [   13.267566] cc:=3
> > [   13.278148] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
> 
> Based on my assumption, the DRP port is presenting Rp-default termination on CC line again,
> then tcpc should report CC change due to a connection is established in 100 ms. However, this
> CC change is not reported here. This leads to state from SRC_TRYWAIT to SRC_TRYWAIT_UNATTACHED
> rather SRC_TRYWAIT_DEBOUNCE.
> 
> Below log is a normal case.
> 
> ---
> [  149.954434] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
> [  149.954447] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> [  149.954452] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> [  150.154543] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> [  150.154554] cc:=2
> [  150.154859] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
> [  150.254881] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
> [  150.254893] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
> [  150.254896] cc:=3
> [  150.255200] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
> [  150.257288] CC1: 0 -> 0, CC2: 2 -> 2 [state SRC_TRYWAIT, polarity 0, connected]
> [  150.257295] state change SRC_TRYWAIT -> SRC_TRYWAIT_DEBOUNCE [rev1 NONE_AMS]
> [  150.257300] pending state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED @ 200 ms [rev1 NONE_AMS]
> [  150.457319] state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED [delayed 200 ms]
> [  150.457329] cc:=3
> [  150.457606] polarity 1
> [  150.458314] Requesting mux state 1, usb-role 1, orientation 2
> [  150.460722] vbus:=1 charge=0
> ---
> 
> So the issue may be why that CC change is not reported?

But there is no change. Your log has:

  CC1: 0 -> 0, CC2: 2 -> 2 [state SRC_TRYWAIT, polarity 0, connected]

How to interpret this? This is with fusb302 driver. The driver has bunch of
gates to not report cc status when it doesn't change:

https://elixir.bootlin.com/linux/latest/source/drivers/usb/typec/tcpm/fusb302.c#L1215

in several places where tcpm_cc_change is called. Not sure what is the
expectation of TCPM state machine, whether it always expects tcpm_cc_change()
call after it calls set_cc callback, or what exactly.

kind regards,
	o.

> Please refer to USB Type-C Specification
> Figure 4-17 Connection State Diagram: DRP with Accessory and Try.SNK Support
> 
> Thanks,
> Xu Yang
> 
> > [   13.378347] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
> > [   13.378364] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
> > [   13.378373] Start toggling
> > [   13.387019] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
> > [   13.462597] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
> > [   13.462606] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> > [   13.462613] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> > [   13.662808] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> > [   13.662827] cc:=2
>
Xu Yang Feb. 26, 2024, 2:44 a.m. UTC | #5
Hi Ondřej,

>
> Hi Xu,
>
> On Mon, Feb 19, 2024 at 08:36:50AM +0000, Xu Yang wrote:
> > Hi Ondřej,
> >
> > >
> > > Hi,
> > >
> > > On Sun, Aug 20, 2023 at 11:15:18PM +0800, Xu Yang wrote:
> > > > The try_src_count and try_snk_count may still be 1 after enter into
> > > > unattached state. This may be caused by below case:
> > > >  - SNK_TRY->SNK_TRY_WAIT->SRC_TRYWAIT->SNK_UNATTACHED
> > > >  - SRC_TRY->SRC_TRY_WAIT->SNK_TRYWAIT->SNK_UNATTACHED
> > > >
> > > > The port->attached is not true at the end and tcpm_reset_port() will not
> > > > be called. This will reset counter into for these cases, otherwise the tcpm
> > > > won't try role when new cable attached.
> > > >
> > > > Signed-off-by: Xu Yang <xu.yang_2@nxp.com>
> > > > ---
> > > >  drivers/usb/typec/tcpm/tcpm.c | 3 +++
> > > >  1 file changed, 3 insertions(+)
> > > >
> > > > diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
> > > > index 5639b9a1e0bf..c9a186a8c58c 100644
> > > > --- a/drivers/usb/typec/tcpm/tcpm.c
> > > > +++ b/drivers/usb/typec/tcpm/tcpm.c
> > > > @@ -3719,6 +3719,9 @@ static void tcpm_detach(struct tcpm_port *port)
> > > >       if (tcpm_port_is_disconnected(port))
> > > >               port->hard_reset_count = 0;
> > > >
> > > > +     port->try_src_count = 0;
> > > > +     port->try_snk_count = 0;
> > >
> > > This patch breaks partner detection for USB type-c hubs and USB type-c docks.
> >
> > I guess the type-c port of hub is sink-only and the type-c port of dock
> > is DRP, right?
>
> The hub is sink-only, yes.
>
> > >
> > > Connecting an unpowered USB-C 4-port HUB:
> > >
> > > Before reverting this patch: (endless loop)
> > >
> > > [   12.957711] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
> > > [   12.957720] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> > > [   12.957729] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> > > [   13.157924] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> > > [   13.157939] cc:=2
> > > [   13.167339] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
> > > [   13.267545] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
> > > [   13.267561] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
> > > [   13.267566] cc:=3
> > > [   13.278148] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
> >
> > Based on my assumption, the DRP port is presenting Rp-default termination on CC line again,
> > then tcpc should report CC change due to a connection is established in 100 ms. However, this
> > CC change is not reported here. This leads to state from SRC_TRYWAIT to SRC_TRYWAIT_UNATTACHED
> > rather SRC_TRYWAIT_DEBOUNCE.
> >
> > Below log is a normal case.
> >
> > ---
> > [  149.954434] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
> > [  149.954447] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> > [  149.954452] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> > [  150.154543] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> > [  150.154554] cc:=2
> > [  150.154859] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
> > [  150.254881] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
> > [  150.254893] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
> > [  150.254896] cc:=3
> > [  150.255200] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
> > [  150.257288] CC1: 0 -> 0, CC2: 2 -> 2 [state SRC_TRYWAIT, polarity 0, connected]
> > [  150.257295] state change SRC_TRYWAIT -> SRC_TRYWAIT_DEBOUNCE [rev1 NONE_AMS]
> > [  150.257300] pending state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED @ 200 ms [rev1 NONE_AMS]
> > [  150.457319] state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED [delayed 200 ms]
> > [  150.457329] cc:=3
> > [  150.457606] polarity 1
> > [  150.458314] Requesting mux state 1, usb-role 1, orientation 2
> > [  150.460722] vbus:=1 charge=0
> > ---
> >
> > So the issue may be why that CC change is not reported?
>
> But there is no change. Your log has:
>
>   CC1: 0 -> 0, CC2: 2 -> 2 [state SRC_TRYWAIT, polarity 0, connected]
>
> How to interpret this? This is with fusb302 driver. The driver has bunch of

When try sink fails (note: cc:=2 in this period), the tcpm will change to SRC_TRYWAIT
state and it will pull up CC to Rp-default (cc:=3). Since the partner is a sink-only port,
I think the type-c chip will sense a connection is established. Therefore, a CC change
event is reported by type-c chip. I'm not sure the behaviors of fusb302 chip when set
cc:=3. If it does not generate interrupt for this change, then tcpm may think the partner
has been disconnected and move the state to SRC_TRYWAIT_UNATTACHED. Maybe it's a
real hw issue or the event is masked by sw.

Is this dock also failed to connect other sink-only devices?

> gates to not report cc status when it doesn't change:
>
> https://elixir.bootlin.com/linux/latest/source/
> drivers%2Fusb%2Ftypec%2Ftcpm%2Ffusb302.c%23L1215&data=05%7C02%7Cxu.yang_2%40nxp.com%7C836aa20d8f9549e9
> 636008dc34ea9e0f%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638443429472475922%7CUnknown%7CTWFpbGZ
> sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=bCXr5obX2B
> hKh5ZZt7CZHQ6OLhJ7JFgSPkW7f49NKfs%3D&reserved=0
>
> in several places where tcpm_cc_change is called. Not sure what is the
> expectation of TCPM state machine, whether it always expects tcpm_cc_change()
> call after it calls set_cc callback, or what exactly.

I think the tcpm_cc_change() will be called only when a real CC change happens
on the CC line. It's irrelevant to whether tcpm_set_cc() is called or not.

Thanks,
Xu Yang

>
> kind regards,
>         o.
>
> > Please refer to USB Type-C Specification
> > Figure 4-17 Connection State Diagram: DRP with Accessory and Try.SNK Support
> >
> > Thanks,
> > Xu Yang
> >
> > > [   13.378347] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
> > > [   13.378364] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
> > > [   13.378373] Start toggling
> > > [   13.387019] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
> > > [   13.462597] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
> > > [   13.462606] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> > > [   13.462613] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> > > [   13.662808] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> > > [   13.662827] cc:=2
> >
Ondřej Jirman Feb. 26, 2024, 10 a.m. UTC | #6
On Mon, Feb 26, 2024 at 02:44:21AM +0000, Xu Yang wrote:
> [...]
>
> >
> > But there is no change. Your log has:
> >
> >   CC1: 0 -> 0, CC2: 2 -> 2 [state SRC_TRYWAIT, polarity 0, connected]
> >
> > How to interpret this? This is with fusb302 driver. The driver has bunch of
> 
> When try sink fails (note: cc:=2 in this period), the tcpm will change to SRC_TRYWAIT
> state and it will pull up CC to Rp-default (cc:=3). Since the partner is a sink-only port,
> I think the type-c chip will sense a connection is established. Therefore, a CC change
> event is reported by type-c chip. I'm not sure the behaviors of fusb302 chip when set
> cc:=3. If it does not generate interrupt for this change, then tcpm may think the partner
> has been disconnected and move the state to SRC_TRYWAIT_UNATTACHED. Maybe it's a
> real hw issue or the event is masked by sw.
> 
> Is this dock also failed to connect other sink-only devices?

The hub is sink-only. It is connected to a DRP phone Type-C port (which is using
fusb302), which is where my log is from.

I also have a board with husb311 Type-C chip and DRP port, which I can use for
comparison (with/without your patch), I guess. It's TCPCI based (husb311), so
that should eliminate bug in fusb302 driver as a possibility, I think.

Kind regards,
	o.

> > gates to not report cc status when it doesn't change:
> >
> > https://elixir.bootlin.com/linux/latest/source/
> > drivers%2Fusb%2Ftypec%2Ftcpm%2Ffusb302.c%23L1215&data=05%7C02%7Cxu.yang_2%40nxp.com%7C836aa20d8f9549e9
> > 636008dc34ea9e0f%7C686ea1d3bc2b4c6fa92cd99c5c301635%7C0%7C0%7C638443429472475922%7CUnknown%7CTWFpbGZ
> > sb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=bCXr5obX2B
> > hKh5ZZt7CZHQ6OLhJ7JFgSPkW7f49NKfs%3D&reserved=0
> >
> > in several places where tcpm_cc_change is called. Not sure what is the
> > expectation of TCPM state machine, whether it always expects tcpm_cc_change()
> > call after it calls set_cc callback, or what exactly.
> 
> I think the tcpm_cc_change() will be called only when a real CC change happens
> on the CC line. It's irrelevant to whether tcpm_set_cc() is called or not.
> 
> Thanks,
> Xu Yang
> 
> >
> > kind regards,
> >         o.
> >
> > > Please refer to USB Type-C Specification
> > > Figure 4-17 Connection State Diagram: DRP with Accessory and Try.SNK Support
> > >
> > > Thanks,
> > > Xu Yang
> > >
> > > > [   13.378347] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
> > > > [   13.378364] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
> > > > [   13.378373] Start toggling
> > > > [   13.387019] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
> > > > [   13.462597] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
> > > > [   13.462606] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> > > > [   13.462613] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> > > > [   13.662808] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> > > > [   13.662827] cc:=2
> > >
Xu Yang Feb. 26, 2024, 10:32 a.m. UTC | #7
> -----Original Message-----
> From: Ondřej Jirman <megi@xff.cz>
> 
> On Mon, Feb 26, 2024 at 02:44:21AM +0000, Xu Yang wrote:
> > [...]
> >
> > >
> > > But there is no change. Your log has:
> > >
> > >   CC1: 0 -> 0, CC2: 2 -> 2 [state SRC_TRYWAIT, polarity 0, connected]
> > >
> > > How to interpret this? This is with fusb302 driver. The driver has bunch of
> >
> > When try sink fails (note: cc:=2 in this period), the tcpm will change to SRC_TRYWAIT
> > state and it will pull up CC to Rp-default (cc:=3). Since the partner is a sink-only port,
> > I think the type-c chip will sense a connection is established. Therefore, a CC change
> > event is reported by type-c chip. I'm not sure the behaviors of fusb302 chip when set
> > cc:=3. If it does not generate interrupt for this change, then tcpm may think the partner
> > has been disconnected and move the state to SRC_TRYWAIT_UNATTACHED. Maybe it's a
> > real hw issue or the event is masked by sw.
> >
> > Is this dock also failed to connect other sink-only devices?
> 
> The hub is sink-only. It is connected to a DRP phone Type-C port (which is using
> fusb302), which is where my log is from.
> 
> I also have a board with husb311 Type-C chip and DRP port, which I can use for
> comparison (with/without your patch), I guess. It's TCPCI based (husb311), so
> that should eliminate bug in fusb302 driver as a possibility, I think.

Yeah, it's a good idea. Looking forward to your results.

Thanks,
Xu Yang

> 
> Kind regards,
>         o.
>
Ondřej Jirman March 1, 2024, 5:25 p.m. UTC | #8
Hi Xu,

On Mon, Feb 19, 2024 at 08:36:50AM +0000, Xu Yang wrote:
> > Connecting an unpowered USB-C 4-port HUB:
> > 
> > Before reverting this patch: (endless loop)
> > 
> > [    0.657246] Setting usb_comm capable false
> > [    0.661870] Setting voltage/current limit 0 mV 0 mA
> > [    0.661880] polarity 0
> > [    0.661883] Requesting mux state 0, usb-role 0, orientation 0
> > [    0.663879] state change INVALID_STATE -> SNK_UNATTACHED [rev1 NONE_AMS]
> > [    0.663891] CC1: 0 -> 0, CC2: 0 -> 0 [state SNK_UNATTACHED, polarity 0, disconnected]
> > [    0.663897] 4-0022: registered
> > [    0.663962] Setting usb_comm capable false
> > [    0.669903] Setting voltage/current limit 0 mV 0 mA
> > [    0.669914] polarity 0
> > [    0.669917] Requesting mux state 0, usb-role 0, orientation 0
> > [    0.672166] cc:=2
> > [    0.679360] pending state change PORT_RESET -> PORT_RESET_WAIT_OFF @ 100 ms [rev1 NONE_AMS]
> > [    0.779554] state change PORT_RESET -> PORT_RESET_WAIT_OFF [delayed 100 ms]
> > [    0.779570] state change PORT_RESET_WAIT_OFF -> SNK_UNATTACHED [rev1 NONE_AMS]
> > [    0.779576] Start toggling
> > [   12.957711] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
> > [   12.957720] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> > [   12.957729] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> > [   13.157924] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> > [   13.157939] cc:=2
> > [   13.167339] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
> > [   13.267545] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
> > [   13.267561] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
> > [   13.267566] cc:=3
> > [   13.278148] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
> 
> Based on my assumption, the DRP port is presenting Rp-default termination on CC line again,
> then tcpc should report CC change due to a connection is established in 100 ms. However, this
> CC change is not reported here. This leads to state from SRC_TRYWAIT to SRC_TRYWAIT_UNATTACHED
> rather SRC_TRYWAIT_DEBOUNCE.
> 
> Below log is a normal case.
> 
> ---
> [  149.954434] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
> [  149.954447] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> [  149.954452] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> [  150.154543] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> [  150.154554] cc:=2
> [  150.154859] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
> [  150.254881] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
> [  150.254893] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
> [  150.254896] cc:=3
> [  150.255200] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
> [  150.257288] CC1: 0 -> 0, CC2: 2 -> 2 [state SRC_TRYWAIT, polarity 0, connected]
> [  150.257295] state change SRC_TRYWAIT -> SRC_TRYWAIT_DEBOUNCE [rev1 NONE_AMS]
> [  150.257300] pending state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED @ 200 ms [rev1 NONE_AMS]
> [  150.457319] state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED [delayed 200 ms]
> [  150.457329] cc:=3
> [  150.457606] polarity 1
> [  150.458314] Requesting mux state 1, usb-role 1, orientation 2
> [  150.460722] vbus:=1 charge=0
> ---

So I tried with tcpci based system and it works with your patch:

[    2.644265] Setting usb_comm capable false
[    2.645756] Setting voltage/current limit 0 mV 0 mA
[    2.645762] polarity 0
[    2.647884] Requesting mux state 0, usb-role 0, orientation 0
[    2.649661] state change INVALID_STATE -> SNK_UNATTACHED [rev1 NONE_AMS]
[    2.650611] CC1: 0 -> 0, CC2: 0 -> 0 [state SNK_UNATTACHED, polarity 0, disconnected]
[    2.650617] 2-004e: registered
[    2.650619] Setting usb_comm capable false
[    2.652276] Setting voltage/current limit 0 mV 0 mA
[    2.652282] polarity 0
[    2.654410] Requesting mux state 0, usb-role 0, orientation 0
[    2.655799] cc:=2
[    2.656612] pending state change PORT_RESET -> PORT_RESET_WAIT_OFF @ 100 ms [rev1 NONE_AMS]
[    2.656615] state change PORT_RESET -> PORT_RESET_WAIT_OFF [delayed 100 ms]
[    2.656616] state change PORT_RESET_WAIT_OFF -> SNK_UNATTACHED [rev1 NONE_AMS]
[    2.656617] Start toggling

[   24.268594] CC1: 0 -> 2, CC2: 0 -> 0 [state TOGGLING, polarity 0, connected]
[   24.268599] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
[   24.268602] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
[   24.468659] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
[   24.468664] cc:=2
[   24.469899] pending state change SNK_TRY -> SNK_TRY_WAIT @ 100 ms [rev1 NONE_AMS]
[   24.473708] CC1: 2 -> 0, CC2: 0 -> 0 [state SNK_TRY, polarity 0, disconnected]

               ^^^^ this is extra

[   24.569964] state change SNK_TRY -> SNK_TRY_WAIT [delayed 100 ms]
[   24.569968] state change SNK_TRY_WAIT -> SRC_TRYWAIT [rev1 NONE_AMS]
[   24.569970] cc:=5
[   24.571089] pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms [rev1 NONE_AMS]
[   24.574996] CC1: 0 -> 2, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, connected]

               ^^^ this is different from your log due to prior change to 0/0
	       and here the fusb302 backed tcpm would fail/diverge, due to lack of this
	       line

[   24.575001] state change SRC_TRYWAIT -> SRC_TRYWAIT_DEBOUNCE [rev1 NONE_AMS]
[   24.575004] pending state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED @ 200 ms [rev1 NONE_AMS]
[   24.775066] state change SRC_TRYWAIT_DEBOUNCE -> SRC_ATTACHED [delayed 200 ms]

               .... lack of cc:=5? after => SRC_ATTACHED

[   24.775070] polarity 0
[   24.778209] Requesting mux state 1, usb-role 1, orientation 1
[   24.779236] vbus:=1 charge=0
[   24.780234] pending state change SRC_ATTACHED -> SRC_UNATTACHED @ 480 ms [rev1 NONE_AMS]
[   24.782755] VBUS on
[   24.782758] state change SRC_ATTACHED -> SRC_STARTUP [rev1 NONE_AMS]
[   24.782773] AMS POWER_NEGOTIATION start
[   24.782774] cc:=4
[   24.783540] pending state change SRC_STARTUP -> AMS_START @ 16 ms [rev3 POWER_NEGOTIATION]
[   24.799554] state change SRC_STARTUP -> AMS_START [delayed 16 ms]
[   24.799558] state change AMS_START -> SRC_SEND_CAPABILITIES [rev3 POWER_NEGOTIATION]
[   24.799559] PD TX, header: 0x11a1
[   24.807710] PD TX complete, status: 2
[   24.807765] pending state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES @ 150 ms [rev3 POWER_NEGOTIATION]
[   24.957845] state change SRC_SEND_CAPABILITIES -> SRC_SEND_CAPABILITIES [delayed 150 ms]

So it looks slightly different from your log, but ends up working because
there's an CC change event after "pending state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED @ 100 ms".

So I think your patch changes some assumptions about the need for the CC change
event in this state, which breaks the state machine. If I strip the logs to just
cc events:

Your normal case:

[  149.954434] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
[  150.154554] cc:=2
[  150.254896] cc:=3
[  150.257288] CC1: 0 -> 0, CC2: 2 -> 2 [state SRC_TRYWAIT, polarity 0, connected]
[  150.457329] cc:=3

My husb311 working case:

[   24.268594] CC1: 0 -> 2, CC2: 0 -> 0 [state TOGGLING, polarity 0, connected]
[   24.468664] cc:=2
[   24.473708] CC1: 2 -> 0, CC2: 0 -> 0 [state SNK_TRY, polarity 0, disconnected]
[   24.569970] cc:=5
[   24.574996] CC1: 0 -> 2, CC2: 0 -> 0 [state SRC_TRYWAIT, polarity 0, connected]

My non-working fusb302 case:

[   12.957711] CC1: 0 -> 0, CC2: 0 -> 2 [state TOGGLING, polarity 0, connected]
[   13.157939] cc:=2
[   13.267566] cc:=3
[   13.462597] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
[   13.662827] cc:=2

kind regards,
	o.

> So the issue may be why that CC change is not reported?
> 
> Please refer to USB Type-C Specification
> Figure 4-17 Connection State Diagram: DRP with Accessory and Try.SNK Support
> 
> Thanks,
> Xu Yang
> 
> > [   13.378347] state change SRC_TRYWAIT -> SRC_TRYWAIT_UNATTACHED [delayed 100 ms]
> > [   13.378364] state change SRC_TRYWAIT_UNATTACHED -> SNK_UNATTACHED [rev1 NONE_AMS]
> > [   13.378373] Start toggling
> > [   13.387019] state change SNK_UNATTACHED -> TOGGLING [rev1 NONE_AMS]
> > [   13.462597] CC1: 0 -> 0, CC2: 2 -> 2 [state TOGGLING, polarity 0, connected]
> > [   13.462606] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS]
> > [   13.462613] pending state change SRC_ATTACH_WAIT -> SNK_TRY @ 200 ms [rev1 NONE_AMS]
> > [   13.662808] state change SRC_ATTACH_WAIT -> SNK_TRY [delayed 200 ms]
> > [   13.662827] cc:=2
>
diff mbox series

Patch

diff --git a/drivers/usb/typec/tcpm/tcpm.c b/drivers/usb/typec/tcpm/tcpm.c
index 5639b9a1e0bf..c9a186a8c58c 100644
--- a/drivers/usb/typec/tcpm/tcpm.c
+++ b/drivers/usb/typec/tcpm/tcpm.c
@@ -3719,6 +3719,9 @@  static void tcpm_detach(struct tcpm_port *port)
 	if (tcpm_port_is_disconnected(port))
 		port->hard_reset_count = 0;
 
+	port->try_src_count = 0;
+	port->try_snk_count = 0;
+
 	if (!port->attached)
 		return;