linux/drivers/usb/typec
Sebastian Reichel 5cbf5709aa usb: typec: fusb302: cache PD RX state
[ Upstream commit 1e61f6ab08 ]

This patch fixes a race condition communication error, which ends up in
PD hard resets when losing the race. Some systems, like the Radxa ROCK
5B are powered through USB-C without any backup power source and use a
FUSB302 chip to do the PD negotiation. This means it is quite important
to avoid hard resets, since that effectively kills the system's
power-supply.

I've found the following race condition while debugging unplanned power
loss during booting the board every now and then:

1. lots of TCPM/FUSB302/PD initialization stuff
2. TCPM ends up in SNK_WAIT_CAPABILITIES (tcpm_set_pd_rx is enabled here)
3. the remote PD source does not send anything, so TCPM does a SOFT RESET
4. TCPM ends up in SNK_WAIT_CAPABILITIES for the second time
   (tcpm_set_pd_rx is enabled again, even though it is still on)

At this point I've seen broken CRC good messages being send by the
FUSB302 with a logic analyzer sniffing the CC lines. Also it looks like
messages are being lost and things generally going haywire with one of
the two sides doing a hard reset once a broken CRC good message was send
to the bus.

I think the system is running into a race condition, that the FIFOs are
being cleared and/or the automatic good CRC message generation flag is
being updated while a message is already arriving.

Let's avoid this by caching the PD RX enabled state, as we have already
processed anything in the FIFOs and are in a good state. As a side
effect that this also optimizes I2C bus usage :)

As far as I can tell the problem theoretically also exists when TCPM
enters SNK_WAIT_CAPABILITIES the first time, but I believe this is less
critical for the following reason:

On devices like the ROCK 5B, which are powered through a TCPM backed
USB-C port, the bootloader must have done some prior PD communication
(initial communication must happen within 5 seconds after plugging the
USB-C plug). This means the first time the kernel TCPM state machine
reaches SNK_WAIT_CAPABILITIES, the remote side is not sending messages
actively. On other devices a hard reset simply adds some extra delay and
things should be good afterwards.

Fixes: c034a43e72 ("staging: typec: Fairchild FUSB302 Type-c chip driver")
Cc: stable <stable@kernel.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Link: https://lore.kernel.org/r/20250704-fusb302-race-condition-fix-v1-1-239012c0e27a@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
[ replaced str_on_off(on) with ternary operator ]
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
History 2025-08-28 16:24:31 +02:00
..
altmodes usb: typec: displayport: Fix potential deadlock 2025-07-10 15:57:50 +02:00
mux usb: typec: intel_pmc_mux: Defer probe if SCU IPC isn't present 2025-08-28 16:24:19 +02:00
tcpm usb: typec: fusb302: cache PD RX state 2025-08-28 16:24:31 +02:00
tipd usb: typec: tipd: Fix spurious fwnode_handle_put in error path 2022-12-31 13:14:27 +01:00
ucsi usb: typec: ucsi: Update power_supply on power role change 2025-08-28 16:24:26 +02:00
bus.c usb: typec: bus: verify partner exists in typec_altmode_attention 2023-09-19 12:22:53 +02:00
bus.h usb: typec: Organize the private headers properly 2021-04-05 09:07:41 +02:00
class.c usb: typec: fix unreleased fwnode_handle in typec_port_register_altmodes() 2024-11-08 16:25:54 +01:00
class.h usb: typec: Link all ports during connector registration 2021-04-09 16:00:00 +02:00
hd3ss3220.c usb: typec: hd3ss3220: Use OF graph API to get the connector fwnode 2020-10-02 15:28:18 +02:00
Kconfig usb: typec: STUSB160X should select REGMAP_I2C 2021-11-18 19:16:54 +01:00
Makefile usb: typec: Port mapping utility 2021-04-09 16:00:00 +02:00
mux.c usb: typec: mux: Check dev_set_name() return value 2022-06-14 18:36:05 +02:00
mux.h usb: typec: mux: Use device type instead of device name for matching 2021-05-27 09:23:57 +02:00
port-mapper.c usb: typec: silence a static checker warning 2021-04-14 15:15:40 +02:00
qcom-pmic-typec.c usb: typec: Add QCOM PMIC typec detection driver 2020-10-09 15:14:43 +02:00
stusb160x.c usb: typec: stusb160x: Don't block probing of consumer of "connector" nodes 2021-07-21 09:16:40 +02:00