Skip to contentSkip to conversation

usb: typec: ucsi: Handle connectors already attached at init

PATCH In review William Bright 3 participants 4 messages Aug 13 – Aug 17

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

PATCH 1/1 usb: typec: ucsi: Handle connectors already attached at init

After a cold boot the PPM may already have a partner attached without a pending connector change to report. On a CYPD6125 the CCI register reads back 0 in ucsi_init(), so ucsi_connector_change() is never called and the Type-C mux is left unconfigured for the already-attached port.

Fix this by additionally checking the connector status of every connector and call ucsi_connector_change() for connectors that are already attached. Whilst also continuing to call ucsi_connector_change() for connectors that report a change via the CCI register.

Fixes ce4c8d21054a ("usb: typec: ucsi: Fix connector check on init")
---
 drivers/usb/typec/ucsi/ucsi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +5 -2
index ecbda2a3783c..740ae4a14f7f 100644
@@ -2136,8 +2136,11 @@ static int ucsi_init(struct ucsi *ucsi)
 	mutex_unlock(&ucsi->ppm_lock);
 	if (ret)
 		return ret;
-	if (UCSI_CCI_CONNECTOR(cci))
-		ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci));
+
+	for (i = 0; i < ucsi->cap.num_connectors; i++)
+		if (UCSI_CONSTAT(&connector[i], CONNECTED) ||
+		    UCSI_CCI_CONNECTOR(cci) == i + 1)
+			ucsi_connector_change(ucsi, i + 1);
 
 	return 0;
 

---
base-commit: 55431f6adac42f818a0c76594ce2c6c02fe1034d
change-id: 20260813-ucsi-cold-b35e11991b7c

Best regards,

Signature · 1 line
William Bright <[email protected]>
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 5 lines · William Bright

After a cold boot the PPM may already have a partner attached without a pending connector change to report. On a CYPD6125 the CCI register reads back 0 in ucsi_init(), so ucsi_connector_change() is never called and the Type-C mux is left unconfigured for the already-attached port.

Quoted 7 lines

Fix this by additionally checking the connector status of every connector and call ucsi_connector_change() for connectors that are already attached. Whilst also continuing to call ucsi_connector_change() for connectors that report a change via the CCI register.

Fixes ce4c8d21054a ("usb: typec: ucsi: Fix connector check on init")

You need to CC stable.

Quoted 30 lines
---
 drivers/usb/typec/ucsi/ucsi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +5 -3
index ecbda2a3783c..740ae4a14f7f 100644
@@ -2136,8 +2136,11 @@ static int ucsi_init(struct ucsi *ucsi)
 	mutex_unlock(&ucsi->ppm_lock);
 	if (ret)
 		return ret;
-	if (UCSI_CCI_CONNECTOR(cci))
-		ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci));
+
+	for (i = 0; i < ucsi->cap.num_connectors; i++)
+		if (UCSI_CONSTAT(&connector[i], CONNECTED) ||
+		    UCSI_CCI_CONNECTOR(cci) == i + 1)
+			ucsi_connector_change(ucsi, i + 1);
 
 	return 0;
 
 
---

base-commit: 55431f6adac42f818a0c76594ce2c6c02fe1034d
change-id: 20260813-ucsi-cold-b35e11991b7c

Best regards,

Signature · 1 line
William Bright <[email protected]>
Signature · 1 line
heikki
#2 lore raw
In reply to William Bright

Hi William,

Quoted 9 lines · William Bright

After a cold boot the PPM may already have a partner attached without a pending connector change to report. On a CYPD6125 the CCI register reads back 0 in ucsi_init(), so ucsi_connector_change() is never called and the Type-C mux is left unconfigured for the already-attached port.

Fix this by additionally checking the connector status of every connector and call ucsi_connector_change() for connectors that are already attached. Whilst also continuing to call ucsi_connector_change() for connectors that report a change via the CCI register.

I'm not sure if this is the right thing to do.

First, there is code in ucsi_register_port() that is supposed to handle the case where a connection is already present. I wonder why that does not work for you?

Quoted 11 lines
Fixes ce4c8d21054a ("usb: typec: ucsi: Fix connector check on init")
---
 drivers/usb/typec/ucsi/ucsi.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/usb/typec/ucsi/ucsi.c +0 -0
index ecbda2a3783c..740ae4a14f7f 100644

drivers/usb/typec/ucsi/ucsi.c static int ucsi_init(struct ucsi *ucsi) · line 2143

Quoted 10 lines
drivers/usb/typec/ucsi/ucsi.c +5 -2
@@ -2136,8 +2136,11 @@ static int ucsi_init(struct ucsi *ucsi)
 	mutex_unlock(&ucsi->ppm_lock);
 	if (ret)
 		return ret;
-	if (UCSI_CCI_CONNECTOR(cci))
-		ucsi_connector_change(ucsi, UCSI_CCI_CONNECTOR(cci));
+
+	for (i = 0; i < ucsi->cap.num_connectors; i++)
+		if (UCSI_CONSTAT(&connector[i], CONNECTED) ||
+		    UCSI_CCI_CONNECTOR(cci) == i + 1)
+			ucsi_connector_change(ucsi, i + 1);

ucsi_connector_change() really is supposed to handle an actual event. The second call to the function will be a NOP because EVENT_PENDING is already set. So your fix only works for one established connection.

Additionally, calling ucsi_connector_change() will set EVENT_PENDING which in turn will cause the next ACK to include UCSI_ACK_CONNECTOR_CHANGE which acks a connector change event that never happend. That is, unless such an event did happen in the mean time. In this case you will ACK the event without handling it.

Also, I seem to recall that some backends don't like it when you ACK something that did not happen.

Best regards,
Christian

Quoted 12 lines
drivers/usb/typec/ucsi/ucsi.c +0 -1
 	return 0;
 
 
---

base-commit: 55431f6adac42f818a0c76594ce2c6c02fe1034d
change-id: 20260813-ucsi-cold-b35e11991b7c

Best regards,

Signature · 1 line
William Bright <[email protected]>
#3 lore raw
Quoted 14 lines · Christian A. Ehrhardt

Hi William,

Quoted 9 lines · William Bright

After a cold boot the PPM may already have a partner attached without a pending connector change to report. On a CYPD6125 the CCI register reads back 0 in ucsi_init(), so ucsi_connector_change() is never called and the Type-C mux is left unconfigured for the already-attached port.

Fix this by additionally checking the connector status of every connector and call ucsi_connector_change() for connectors that are already attached. Whilst also continuing to call ucsi_connector_change() for connectors that report a change via the CCI register.

Quoted 6 lines

I'm not sure if this is the right thing to do.

First, there is code in ucsi_register_port() that is supposed to handle the case where a connection is already present. I wonder why that does not work for you?

Hi Christian,

Thanks for your feedback, I had another go this morning at trying to reproduce the issue I was seeing last week where I was just seeing only high-speed on the host instead of superspeed and I am struggling to reproduce it even when doing a load of cold-boots.

Can we drop this patch-series for now? I need to find a more reliable way of reproducing this issue and if I manage to then I will need to come up with a fix that is on the ucsi_register_port() path as you suggested.

Regards

Will