Skip to contentSkip to conversation

usb: typec: tcpm: Use configured PD revision for negotiation

PATCH Superseded Cosmo Chou 2 participants 2 messages May 8, 2025 – May 12, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Cosmo Chou

author
#0 lore raw

PATCH 1/1 usb: typec: tcpm: Use configured PD revision for negotiation

Initialize negotiated_rev and negotiated_rev_prime based on the port's configured PD revision (rev_major) rather than always defaulting to PD_MAX_REV. This ensures ports start PD communication using their appropriate revision level.

This allows proper communication with devices that require specific PD revision levels, especially for the hardware designed for PD 1.0 or 2.0 specifications.

---
 drivers/usb/typec/tcpm/tcpm.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +14 -4
index a99db4e025cd..5a58c21c4d14 100644
@@ -4782,8 +4782,13 @@ static void run_state_machine(struct tcpm_port *port)
 		typec_set_pwr_opmode(port->typec_port, opmode);
 		port->pwr_opmode = TYPEC_PWR_MODE_USB;
 		port->caps_count = 0;
-		port->negotiated_rev = PD_MAX_REV;
-		port->negotiated_rev_prime = PD_MAX_REV;
+		if (port->pd_rev.rev_major > 0 && port->pd_rev.rev_major <= PD_MAX_REV + 1) {
+			port->negotiated_rev = port->pd_rev.rev_major - 1;
+			port->negotiated_rev_prime = port->pd_rev.rev_major - 1;
+		} else {
+			port->negotiated_rev = PD_MAX_REV;
+			port->negotiated_rev_prime = PD_MAX_REV;
+		}
 		port->message_id = 0;
 		port->message_id_prime = 0;
 		port->rx_msgid = -1;
@@ -5048,8 +5053,13 @@ static void run_state_machine(struct tcpm_port *port)
 					      port->cc2 : port->cc1);
 		typec_set_pwr_opmode(port->typec_port, opmode);
 		port->pwr_opmode = TYPEC_PWR_MODE_USB;
-		port->negotiated_rev = PD_MAX_REV;
-		port->negotiated_rev_prime = PD_MAX_REV;
+		if (port->pd_rev.rev_major > 0 && port->pd_rev.rev_major <= PD_MAX_REV + 1) {
+			port->negotiated_rev = port->pd_rev.rev_major - 1;
+			port->negotiated_rev_prime = port->pd_rev.rev_major - 1;
+		} else {
+			port->negotiated_rev = PD_MAX_REV;
+			port->negotiated_rev_prime = PD_MAX_REV;
+		}
 		port->message_id = 0;
 		port->message_id_prime = 0;
 		port->rx_msgid = -1;
Signature · 1 line
2.43.0
#1 lore raw

Hi Cosmo,

Thanks for the patch!

Quoted 7 lines · Cosmo Chou

Initialize negotiated_rev and negotiated_rev_prime based on the port's configured PD revision (rev_major) rather than always defaulting to PD_MAX_REV. This ensures ports start PD communication using their appropriate revision level.

This allows proper communication with devices that require specific PD revision levels, especially for the hardware designed for PD 1.0

I didn't know PD1.0 is still used.

Quoted 12 lines

or 2.0 specifications.

---
  drivers/usb/typec/tcpm/tcpm.c | 18 ++++++++++++++----
  1 file changed, 14 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +0 -0
index a99db4e025cd..5a58c21c4d14 100644

drivers/usb/typec/tcpm/tcpm.c static void run_state_machine(struct tcpm_port *port) · line 4785

Quoted 6 lines
drivers/usb/typec/tcpm/tcpm.c +1 -2
@@ -4782,8 +4782,13 @@ static void run_state_machine(struct tcpm_port *port)
  		typec_set_pwr_opmode(port->typec_port, opmode);
  		port->pwr_opmode = TYPEC_PWR_MODE_USB;
  		port->caps_count = 0;
-		port->negotiated_rev = PD_MAX_REV;
-		port->negotiated_rev_prime = PD_MAX_REV;
+		if (port->pd_rev.rev_major > 0 && port->pd_rev.rev_major <= PD_MAX_REV + 1) {

For better readability, I'd prefer you use macros for the numerical values and implement this logic as a switch case. This would make the value difference between PD specification revision in PD Message header vs PD max revision AMS transparent to the reader.

Thanks,

Amit

Quoted 25 lines
drivers/usb/typec/tcpm/tcpm.c +13 -2
+			port->negotiated_rev = port->pd_rev.rev_major - 1;
+			port->negotiated_rev_prime = port->pd_rev.rev_major - 1;
+		} else {
+			port->negotiated_rev = PD_MAX_REV;
+			port->negotiated_rev_prime = PD_MAX_REV;
+		}
  		port->message_id = 0;
  		port->message_id_prime = 0;
  		port->rx_msgid = -1;
@@ -5048,8 +5053,13 @@ static void run_state_machine(struct tcpm_port *port)
  					      port->cc2 : port->cc1);
  		typec_set_pwr_opmode(port->typec_port, opmode);
  		port->pwr_opmode = TYPEC_PWR_MODE_USB;
-		port->negotiated_rev = PD_MAX_REV;
-		port->negotiated_rev_prime = PD_MAX_REV;
+		if (port->pd_rev.rev_major > 0 && port->pd_rev.rev_major <= PD_MAX_REV + 1) {
+			port->negotiated_rev = port->pd_rev.rev_major - 1;
+			port->negotiated_rev_prime = port->pd_rev.rev_major - 1;
+		} else {
+			port->negotiated_rev = PD_MAX_REV;
+			port->negotiated_rev_prime = PD_MAX_REV;
+		}
  		port->message_id = 0;
  		port->message_id_prime = 0;
  		port->rx_msgid = -1;