Skip to content

Commit f6ec9bb

Browse files
Xu Yanggregkh
authored andcommitted
usb: typec: tcpm: fix debug accessory mode detection for sink ports
The port in debug accessory mode can be either a source or sink. The previous tcpm_port_is_debug() function only checked for source port. Commit 8db73e6 ("usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug") changed the detection logic to support both roles, but left some logic in _tcpm_cc_change() unchanged, This causes the state machine to transition to an incorrect state when operating as a sink in debug accessory mode. Log as below: [ 978.637541] CC1: 0 -> 5, CC2: 0 -> 5 [state TOGGLING, polarity 0, connected] [ 978.637567] state change TOGGLING -> SRC_ATTACH_WAIT [rev1 NONE_AMS] [ 978.637596] pending state change SRC_ATTACH_WAIT -> DEBUG_ACC_ATTACHED @ 180 ms [rev1 NONE_AMS] [ 978.647098] CC1: 5 -> 0, CC2: 5 -> 5 [state SRC_ATTACH_WAIT, polarity 0, connected] [ 978.647115] state change SRC_ATTACH_WAIT -> SRC_ATTACH_WAIT [rev1 NONE_AMS] It should go to SNK_ATTACH_WAIT instead of SRC_ATTACH_WAIT state. To fix this, add tcpm_port_is_debug_source() and tcpm_port_is_debug_sink() helper to explicitly identify the power mode in debug accessory mode. Update the state transition logic in _tcpm_cc_change() to ensure the state machine transitions comply with Type-C specification. Also update the logic in run_state_machine() to keep consistency. Fixes: 8db73e6 ("usb: typec: tcpm: allow sink (ufp) to toggle into accessory mode debug") Cc: stable <stable@kernel.org> Signed-off-by: Xu Yang <xu.yang_2@nxp.com> Acked-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Reviewed-by: Amit Sunil Dhamne <amitsd@google.com> Link: https://patch.msgid.link/20260424074009.2979266-1-xu.yang_2@nxp.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 2909f0d commit f6ec9bb

1 file changed

Lines changed: 16 additions & 9 deletions

File tree

drivers/usb/typec/tcpm/tcpm.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -732,9 +732,14 @@ static const char * const pd_rev[] = {
732732
(tcpm_cc_is_source((port)->cc2) && \
733733
!tcpm_cc_is_source((port)->cc1)))
734734

735+
#define tcpm_port_is_debug_source(port) \
736+
(tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2))
737+
738+
#define tcpm_port_is_debug_sink(port) \
739+
(tcpm_cc_is_sink((port)->cc1) && tcpm_cc_is_sink((port)->cc2))
740+
735741
#define tcpm_port_is_debug(port) \
736-
((tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) || \
737-
(tcpm_cc_is_sink((port)->cc1) && tcpm_cc_is_sink((port)->cc2)))
742+
(tcpm_port_is_debug_source(port) || tcpm_port_is_debug_sink(port))
738743

739744
#define tcpm_port_is_audio(port) \
740745
(tcpm_cc_is_audio((port)->cc1) && tcpm_cc_is_audio((port)->cc2))
@@ -5176,7 +5181,7 @@ static void run_state_machine(struct tcpm_port *port)
51765181
tcpm_set_state(port, SNK_UNATTACHED, PD_T_DRP_SNK);
51775182
break;
51785183
case SRC_ATTACH_WAIT:
5179-
if (tcpm_port_is_debug(port))
5184+
if (tcpm_port_is_debug_source(port))
51805185
tcpm_set_state(port, DEBUG_ACC_ATTACHED,
51815186
port->timings.cc_debounce_time);
51825187
else if (tcpm_port_is_audio(port))
@@ -5434,7 +5439,7 @@ static void run_state_machine(struct tcpm_port *port)
54345439
tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC);
54355440
break;
54365441
case SNK_ATTACH_WAIT:
5437-
if (tcpm_port_is_debug(port))
5442+
if (tcpm_port_is_debug_sink(port))
54385443
tcpm_set_state(port, DEBUG_ACC_ATTACHED,
54395444
PD_T_CC_DEBOUNCE);
54405445
else if (tcpm_port_is_audio(port))
@@ -5454,7 +5459,7 @@ static void run_state_machine(struct tcpm_port *port)
54545459
if (tcpm_port_is_disconnected(port))
54555460
tcpm_set_state(port, SNK_UNATTACHED,
54565461
PD_T_PD_DEBOUNCE);
5457-
else if (tcpm_port_is_debug(port))
5462+
else if (tcpm_port_is_debug_sink(port))
54585463
tcpm_set_state(port, DEBUG_ACC_ATTACHED,
54595464
PD_T_CC_DEBOUNCE);
54605465
else if (tcpm_port_is_audio(port))
@@ -6362,20 +6367,22 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
63626367

63636368
switch (port->state) {
63646369
case TOGGLING:
6365-
if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) ||
6370+
if (tcpm_port_is_debug_source(port) || tcpm_port_is_audio(port) ||
63666371
tcpm_port_is_source(port))
63676372
tcpm_set_state(port, SRC_ATTACH_WAIT, 0);
6368-
else if (tcpm_port_is_sink(port))
6373+
else if (tcpm_port_is_debug_sink(port) || tcpm_port_is_sink(port))
63696374
tcpm_set_state(port, SNK_ATTACH_WAIT, 0);
63706375
break;
63716376
case CHECK_CONTAMINANT:
63726377
/* Wait for Toggling to be resumed */
63736378
break;
63746379
case SRC_UNATTACHED:
63756380
case ACC_UNATTACHED:
6376-
if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) ||
6381+
if (tcpm_port_is_debug_source(port) || tcpm_port_is_audio(port) ||
63776382
tcpm_port_is_source(port))
63786383
tcpm_set_state(port, SRC_ATTACH_WAIT, 0);
6384+
else if (tcpm_port_is_debug_sink(port))
6385+
tcpm_set_state(port, SNK_ATTACH_WAIT, 0);
63796386
break;
63806387
case SRC_ATTACH_WAIT:
63816388
if (tcpm_port_is_disconnected(port) ||
@@ -6397,7 +6404,7 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
63976404
}
63986405
break;
63996406
case SNK_UNATTACHED:
6400-
if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) ||
6407+
if (tcpm_port_is_debug_sink(port) || tcpm_port_is_audio(port) ||
64016408
tcpm_port_is_sink(port))
64026409
tcpm_set_state(port, SNK_ATTACH_WAIT, 0);
64036410
break;

0 commit comments

Comments
 (0)