Skip to content

Commit 9119500

Browse files
Xu Yanggregkh
authored andcommitted
usb: typec: tcpm: fix debug accessory mode detection for sink ports
commit f6ec9bb upstream. 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> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent f30ccfc commit 9119500

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
@@ -634,9 +634,14 @@ static const char * const pd_rev[] = {
634634
(tcpm_cc_is_source((port)->cc2) && \
635635
!tcpm_cc_is_source((port)->cc1)))
636636

637+
#define tcpm_port_is_debug_source(port) \
638+
(tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2))
639+
640+
#define tcpm_port_is_debug_sink(port) \
641+
(tcpm_cc_is_sink((port)->cc1) && tcpm_cc_is_sink((port)->cc2))
642+
637643
#define tcpm_port_is_debug(port) \
638-
((tcpm_cc_is_source((port)->cc1) && tcpm_cc_is_source((port)->cc2)) || \
639-
(tcpm_cc_is_sink((port)->cc1) && tcpm_cc_is_sink((port)->cc2)))
644+
(tcpm_port_is_debug_source(port) || tcpm_port_is_debug_sink(port))
640645

641646
#define tcpm_port_is_audio(port) \
642647
(tcpm_cc_is_audio((port)->cc1) && tcpm_cc_is_audio((port)->cc2))
@@ -4812,7 +4817,7 @@ static void run_state_machine(struct tcpm_port *port)
48124817
tcpm_set_state(port, SNK_UNATTACHED, PD_T_DRP_SNK);
48134818
break;
48144819
case SRC_ATTACH_WAIT:
4815-
if (tcpm_port_is_debug(port))
4820+
if (tcpm_port_is_debug_source(port))
48164821
tcpm_set_state(port, DEBUG_ACC_ATTACHED,
48174822
port->timings.cc_debounce_time);
48184823
else if (tcpm_port_is_audio(port))
@@ -5070,7 +5075,7 @@ static void run_state_machine(struct tcpm_port *port)
50705075
tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC);
50715076
break;
50725077
case SNK_ATTACH_WAIT:
5073-
if (tcpm_port_is_debug(port))
5078+
if (tcpm_port_is_debug_sink(port))
50745079
tcpm_set_state(port, DEBUG_ACC_ATTACHED,
50755080
PD_T_CC_DEBOUNCE);
50765081
else if (tcpm_port_is_audio(port))
@@ -5090,7 +5095,7 @@ static void run_state_machine(struct tcpm_port *port)
50905095
if (tcpm_port_is_disconnected(port))
50915096
tcpm_set_state(port, SNK_UNATTACHED,
50925097
PD_T_PD_DEBOUNCE);
5093-
else if (tcpm_port_is_debug(port))
5098+
else if (tcpm_port_is_debug_sink(port))
50945099
tcpm_set_state(port, DEBUG_ACC_ATTACHED,
50955100
PD_T_CC_DEBOUNCE);
50965101
else if (tcpm_port_is_audio(port))
@@ -5961,20 +5966,22 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
59615966

59625967
switch (port->state) {
59635968
case TOGGLING:
5964-
if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) ||
5969+
if (tcpm_port_is_debug_source(port) || tcpm_port_is_audio(port) ||
59655970
tcpm_port_is_source(port))
59665971
tcpm_set_state(port, SRC_ATTACH_WAIT, 0);
5967-
else if (tcpm_port_is_sink(port))
5972+
else if (tcpm_port_is_debug_sink(port) || tcpm_port_is_sink(port))
59685973
tcpm_set_state(port, SNK_ATTACH_WAIT, 0);
59695974
break;
59705975
case CHECK_CONTAMINANT:
59715976
/* Wait for Toggling to be resumed */
59725977
break;
59735978
case SRC_UNATTACHED:
59745979
case ACC_UNATTACHED:
5975-
if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) ||
5980+
if (tcpm_port_is_debug_source(port) || tcpm_port_is_audio(port) ||
59765981
tcpm_port_is_source(port))
59775982
tcpm_set_state(port, SRC_ATTACH_WAIT, 0);
5983+
else if (tcpm_port_is_debug_sink(port))
5984+
tcpm_set_state(port, SNK_ATTACH_WAIT, 0);
59785985
break;
59795986
case SRC_ATTACH_WAIT:
59805987
if (tcpm_port_is_disconnected(port) ||
@@ -5996,7 +6003,7 @@ static void _tcpm_cc_change(struct tcpm_port *port, enum typec_cc_status cc1,
59966003
}
59976004
break;
59986005
case SNK_UNATTACHED:
5999-
if (tcpm_port_is_debug(port) || tcpm_port_is_audio(port) ||
6006+
if (tcpm_port_is_debug_sink(port) || tcpm_port_is_audio(port) ||
60006007
tcpm_port_is_sink(port))
60016008
tcpm_set_state(port, SNK_ATTACH_WAIT, 0);
60026009
break;

0 commit comments

Comments
 (0)