linux/drivers/usb/typec
Xu Yang f6ec9bb4ac 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 8db73e6a42 ("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: 8db73e6a42 ("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>
History 2026-04-27 09:56:28 -06:00
..
altmodes usb: typec: thunderbolt: Set enter_vdo during initialization 2026-03-30 17:17:40 +02:00
mux usb: typec: ps883x: Fix Oops at unbind 2026-03-18 16:04:03 +01:00
tcpm usb: typec: tcpm: fix debug accessory mode detection for sink ports 2026-04-27 09:56:28 -06:00
tipd usb: typec: Fix error pointer dereference 2026-03-11 15:38:40 +01:00
ucsi USB / Thunderbolt changes for 7.1-rc1 2026-04-19 08:47:40 -07:00
anx7411.c usb: typec: anx7411: add WQ_PERCPU to alloc_workqueue users 2025-11-21 15:17:36 +01:00
bus.c usb: typec: Export typec bus and typec altmode device type 2025-12-17 14:42:34 +01:00
bus.h usb: typec: Export typec bus and typec altmode device type 2025-12-17 14:42:34 +01:00
class.c usb: typec: Remove alt->adev.dev.class assignment 2026-03-30 17:17:21 +02:00
class.h usb: typec: Implement mode selection 2026-01-23 17:18:01 +01:00
hd3ss3220.c usb: typec: hd3ss3220: Check if regulator needs to be switched 2026-02-06 11:23:50 +01:00
Kconfig usb: typec: qcom: Add Qualcomm PMIC Type-C driver 2023-05-13 19:03:46 +09:00
Makefile usb: typec: Implement mode selection 2026-01-23 17:18:01 +01:00
mode_selection.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
mux.c usb: typec: mux: avoid duplicated mux switches 2026-03-11 15:38:54 +01:00
mux.h usb: typec: mux: Introduce indirection 2022-04-26 13:47:13 +02:00
pd.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
pd.h usb: typec: Separate USB Power Delivery from USB Type-C 2022-06-12 06:49:47 +02:00
port-mapper.c usb: typec: Connect Type-C port with associated USB4 port 2025-04-17 12:21:45 +03:00
retimer.c Convert 'alloc_obj' family to use the new default GFP_KERNEL argument 2026-02-21 17:09:51 -08:00
retimer.h usb: typec: Make bus switch code retimer-aware 2023-01-17 17:29:00 +01:00
rt1719.c power: supply: Change usb_types from an array into a bitmask 2024-09-03 23:20:28 +02:00
stusb160x.c usb: typec: stusb160x: Make use of i2c_get_match_data() 2024-10-04 15:12:15 +02:00
wusb3801.c usb: Switch i2c drivers back to use .probe() 2023-05-29 15:53:11 +01:00