Skip to contentSkip to conversation

usb: typec: Find a Type-C partner after a warm reboot on the Orange Pi 5

PATCH New Arun Iyengar 2 participants 4 messages Nov 26

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover usb: typec: Find a Type-C partner after a warm reboot on the Orange Pi 5

After a warm reboot, an Orange Pi 5 (FUSB302) often did not find a USB-C to DisplayPort cable that stayed plugged in; only a replug brought DisplayPort back. Two causes:

1. tcpm: a re-queue at port registration cut the 100 ms ErrorRecovery after PORT_RESET to 6 us.
2. fusb302: the chip never found this cable while toggling with

     Rp 3.0A.

Tested on an Orange Pi 5 with a USB-C DisplayPort monitor: DP alt mode on 16/16 warm reboots. Not tested: other TCPCs, ports without PD.

Developed with Claude (Anthropic), which wrote the code and the commit messages. I reviewed every change.

---
Changes in v3:
- Patch 2: Cc stable (Heikki Krogerus)
- Code comments dropped, shorter messages, no functional change
- Link to v2: https://patch.msgid.link/[email protected]

---
Arun Iyengar (2):
usb: typec: tcpm: Don't cut a pending state delay short on a re-queue
usb: typec: fusb302: Toggle with the default Rp current

 drivers/usb/typec/tcpm/fusb302.c | 12 ++++++++++--
 drivers/usb/typec/tcpm/tcpm.c    |  5 +++++
 2 files changed, 15 insertions(+), 2 deletions(-)

---
base-commit: 90d6263e867be7089b3d3323bef8d2accd327c77
change-id: 20261110-tcpm-attach-reboot-d93d5f36403b

Best regards,

Signature · 1 line
Arun Iyengar <[email protected]>
#1 lore raw

PATCH v3 1/2 usb: typec: tcpm: Don't cut a pending state delay short on a re-queue

A re-queue while the work runs applies a pending delayed state at once (the 100 ms ErrorRecovery took 6 us). Re-arm the timer for the time left.

Fixes 3ed8e1c2ac99 ("usb: typec: tcpm: Migrate workqueue to RT priority for processing events")
---
 drivers/usb/typec/tcpm/tcpm.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/usb/typec/tcpm/tcpm.c +5 -0
index 51e5c72799f2..565073b4ca93 100644
@@ -6572,6 +6572,11 @@ static void tcpm_state_machine_work(struct kthread_work *work)
 
 	/* If we were queued due to a delayed state change, update it now */
 	if (port->delayed_state) {
+		if (ktime_after(port->delayed_runtime, ktime_get())) {
+			hrtimer_start(&port->state_machine_timer,
+				      port->delayed_runtime, HRTIMER_MODE_ABS);
+			goto done;
+		}
 		tcpm_log(port, "state change %s -> %s [delayed %ld ms]",
 			 tcpm_states[port->state],
 			 tcpm_states[port->delayed_state], port->delay_ms);
Signature · 1 line
2.55.0
#2 lore raw

PATCH v3 2/2 usb: typec: fusb302: Toggle with the default Rp current

In reply to Arun Iyengar

The FUSB302 does not detect some sinks while toggling with Rp 3.0A. Toggle with the default current and set the requested one on attach.

Fixes c034a43e72dd ("staging: typec: Fairchild FUSB302 Type-c chip driver")
---
 drivers/usb/typec/tcpm/fusb302.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/fusb302.c +10 -2
index 83bd287dadc7..64d02cc0ecae 100644
@@ -97,6 +97,7 @@ struct fusb302_chip {
 	/* chip status */
 	enum toggling_mode toggling_mode;
 	enum src_current_status src_current_status;
+	enum src_current_status toggling_src_current;
 	bool intr_togdone;
 	bool intr_bc_lvl;
 	bool intr_comp_chng;
@@ -942,10 +943,11 @@ static int tcpm_start_toggling(struct tcpc_dev *dev,
 	}
 
 	mutex_lock(&chip->lock);
-	ret = fusb302_set_src_current(chip, cc_src_current[cc]);
+	chip->toggling_src_current = cc_src_current[cc];
+	ret = fusb302_set_src_current(chip, SRC_CURRENT_DEFAULT);
 	if (ret < 0) {
 		fusb302_log(chip, "unable to set src current %s, ret=%d",
-			    typec_cc_status_name[cc], ret);
+			    typec_cc_status_name[TYPEC_CC_RP_DEF], ret);
 		goto done;
 	}
 	ret = fusb302_set_toggling(chip, mode);
@@ -1357,6 +1359,12 @@ static int fusb302_handle_togdone_src(struct fusb302_chip *chip,
 			    typec_cc_status_name[cc2]);
 		return fusb302_set_toggling(chip, toggling_mode);
 	}
+	ret = fusb302_set_src_current(chip, chip->toggling_src_current);
+	if (ret < 0) {
+		fusb302_log(chip, "cannot set src current, ret=%d", ret);
+		return ret;
+	}
+	rd_mda = rd_mda_value[chip->src_current_status];
 	/* set polarity and pull_up, pull_down */
 	ret = fusb302_set_cc_polarity_and_pull(chip, cc_polarity, true, false);
 	if (ret < 0) {
Signature · 1 line
2.55.0