Skip to contentSkip to conversation

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

PATCH In review Cosmo Chou 4 participants 7 messages May 13, 2025 – May 16, 2025

Subsystems (3)
lore
Share & tools
lore

Cosmo Chou

author
#0 lore raw

PATCH v2 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.

---
Change log:

v2:
- Add PD_CAP_REVXX macros and use switch-case for better readability.

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +25 -4
index 8adf6f954633..48e9cfc2b49a 100644
@@ -313,6 +313,10 @@ struct pd_data {
 	unsigned int operating_snk_mw;
 };
 
+#define PD_CAP_REV10	0x1
+#define PD_CAP_REV20	0x2
+#define PD_CAP_REV30	0x3
+
 struct pd_revision_info {
 	u8 rev_major;
 	u8 rev_minor;
@@ -4665,6 +4669,25 @@ static void tcpm_set_initial_svdm_version(struct tcpm_port *port)
 	}
 }
 
+static void tcpm_set_initial_negotiated_rev(struct tcpm_port *port)
+{
+	switch (port->pd_rev.rev_major) {
+	case PD_CAP_REV10:
+		port->negotiated_rev = PD_REV10;
+		break;
+	case PD_CAP_REV20:
+		port->negotiated_rev = PD_REV20;
+		break;
+	case PD_CAP_REV30:
+		port->negotiated_rev = PD_REV30;
+		break;
+	default:
+		port->negotiated_rev = PD_MAX_REV;
+		break;
+	}
+	port->negotiated_rev_prime = port->negotiated_rev;
+}
+
 static void run_state_machine(struct tcpm_port *port)
 {
 	int ret;
@@ -4782,8 +4805,7 @@ 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;
+		tcpm_set_initial_negotiated_rev(port);
 		port->message_id = 0;
 		port->message_id_prime = 0;
 		port->rx_msgid = -1;
@@ -5048,8 +5070,7 @@ 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;
+		tcpm_set_initial_negotiated_rev(port);
 		port->message_id = 0;
 		port->message_id_prime = 0;
 		port->rx_msgid = -1;
Signature · 1 line
2.43.0
maintainer
#1 lore raw
Quoted 47 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 or 2.0 specifications.

---
Change log:

v2:
- Add PD_CAP_REVXX macros and use switch-case for better readability.

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +12 -0
index 8adf6f954633..48e9cfc2b49a 100644
@@ -313,6 +313,10 @@ struct pd_data {
 	unsigned int operating_snk_mw;
 };
 
+#define PD_CAP_REV10	0x1
+#define PD_CAP_REV20	0x2
+#define PD_CAP_REV30	0x3
+
 struct pd_revision_info {
 	u8 rev_major;
 	u8 rev_minor;
@@ -4665,6 +4669,25 @@ static void tcpm_set_initial_svdm_version(struct tcpm_port *port)
 	}
 }
 
+static void tcpm_set_initial_negotiated_rev(struct tcpm_port *port)
+{
+	switch (port->pd_rev.rev_major) {
+	case PD_CAP_REV10:
+		port->negotiated_rev = PD_REV10;
+		break;
+	case PD_CAP_REV20:
+		port->negotiated_rev = PD_REV20;

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

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +10 -0
+		break;
+	case PD_CAP_REV30:
+		port->negotiated_rev = PD_REV30;
+		break;
+	default:
+		port->negotiated_rev = PD_MAX_REV;
+		break;
+	}
+	port->negotiated_rev_prime = port->negotiated_rev;
+}

Do we need this? Couldn't you just add one to rev_major?

        port->negotiated_rev = port->pd_rev.rev_major + 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major + 1;

Or am I missing something?

thanks,

Quoted 25 lines
drivers/usb/typec/tcpm/tcpm.c +2 -4
 static void run_state_machine(struct tcpm_port *port)
 {
 	int ret;
@@ -4782,8 +4805,7 @@ 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;
+		tcpm_set_initial_negotiated_rev(port);
 		port->message_id = 0;
 		port->message_id_prime = 0;
 		port->rx_msgid = -1;
@@ -5048,8 +5070,7 @@ 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;
+		tcpm_set_initial_negotiated_rev(port);
 		port->message_id = 0;
 		port->message_id_prime = 0;
 		port->rx_msgid = -1;
Signature · 1 line
2.43.0
Signature · 1 line
heikki
maintainer
#2 lore raw
Quoted 61 lines · Heikki Krogerus
Quoted 47 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 or 2.0 specifications.

---
Change log:

v2:
- Add PD_CAP_REVXX macros and use switch-case for better readability.

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +12 -0
index 8adf6f954633..48e9cfc2b49a 100644
@@ -313,6 +313,10 @@ struct pd_data {
 	unsigned int operating_snk_mw;
 };
 
+#define PD_CAP_REV10	0x1
+#define PD_CAP_REV20	0x2
+#define PD_CAP_REV30	0x3
+
 struct pd_revision_info {
 	u8 rev_major;
 	u8 rev_minor;
@@ -4665,6 +4669,25 @@ static void tcpm_set_initial_svdm_version(struct tcpm_port *port)
 	}
 }
 
+static void tcpm_set_initial_negotiated_rev(struct tcpm_port *port)
+{
+	switch (port->pd_rev.rev_major) {
+	case PD_CAP_REV10:
+		port->negotiated_rev = PD_REV10;
+		break;
+	case PD_CAP_REV20:
+		port->negotiated_rev = PD_REV20;

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

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +10 -0
+		break;
+	case PD_CAP_REV30:
+		port->negotiated_rev = PD_REV30;
+		break;
+	default:
+		port->negotiated_rev = PD_MAX_REV;
+		break;
+	}
+	port->negotiated_rev_prime = port->negotiated_rev;
+}

Do we need this? Couldn't you just add one to rev_major?

Quoted 4 lines
        port->negotiated_rev = port->pd_rev.rev_major + 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major + 1;

Or am I missing something?

Sorry, I mean minus one :-)

        port->negotiated_rev = port->pd_rev.rev_major - 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major - 1;
Signature · 1 line
heikki
author
#3 lore raw
Quoted 68 lines · Heikki Krogerus
Quoted 61 lines · Heikki Krogerus
Quoted 47 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 or 2.0 specifications.

---
Change log:

v2:
- Add PD_CAP_REVXX macros and use switch-case for better readability.

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +12 -0
index 8adf6f954633..48e9cfc2b49a 100644
@@ -313,6 +313,10 @@ struct pd_data {
    unsigned int operating_snk_mw;
 };
 
+#define PD_CAP_REV10       0x1
+#define PD_CAP_REV20       0x2
+#define PD_CAP_REV30       0x3
+
 struct pd_revision_info {
    u8 rev_major;
    u8 rev_minor;
@@ -4665,6 +4669,25 @@ static void tcpm_set_initial_svdm_version(struct tcpm_port *port)
    }
 }
 
+static void tcpm_set_initial_negotiated_rev(struct tcpm_port *port)
+{
+   switch (port->pd_rev.rev_major) {
+   case PD_CAP_REV10:
+           port->negotiated_rev = PD_REV10;
+           break;
+   case PD_CAP_REV20:
+           port->negotiated_rev = PD_REV20;

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

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +10 -0
+           break;
+   case PD_CAP_REV30:
+           port->negotiated_rev = PD_REV30;
+           break;
+   default:
+           port->negotiated_rev = PD_MAX_REV;
+           break;
+   }
+   port->negotiated_rev_prime = port->negotiated_rev;
+}

Do we need this? Couldn't you just add one to rev_major?

Quoted 4 lines
        port->negotiated_rev = port->pd_rev.rev_major + 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major + 1;

Or am I missing something?

Quoted 7 lines

Sorry, I mean minus one :-)

        port->negotiated_rev = port->pd_rev.rev_major - 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major - 1;

--
heikki

It seems to be the PATCH v1:
https://lore.kernel.org/all/[email protected]/

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;
}

--
Thanks
Cosmo

maintainer Reviewed-by
#4 lore raw
Quoted 80 lines · Cosmo Chou
Quoted 68 lines · Heikki Krogerus
Quoted 61 lines · Heikki Krogerus
Quoted 47 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 or 2.0 specifications.

---
Change log:

v2:
- Add PD_CAP_REVXX macros and use switch-case for better readability.

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +12 -0
index 8adf6f954633..48e9cfc2b49a 100644
@@ -313,6 +313,10 @@ struct pd_data {
    unsigned int operating_snk_mw;
 };
 
+#define PD_CAP_REV10       0x1
+#define PD_CAP_REV20       0x2
+#define PD_CAP_REV30       0x3
+
 struct pd_revision_info {
    u8 rev_major;
    u8 rev_minor;
@@ -4665,6 +4669,25 @@ static void tcpm_set_initial_svdm_version(struct tcpm_port *port)
    }
 }
 
+static void tcpm_set_initial_negotiated_rev(struct tcpm_port *port)
+{
+   switch (port->pd_rev.rev_major) {
+   case PD_CAP_REV10:
+           port->negotiated_rev = PD_REV10;
+           break;
+   case PD_CAP_REV20:
+           port->negotiated_rev = PD_REV20;

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

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +10 -0
+           break;
+   case PD_CAP_REV30:
+           port->negotiated_rev = PD_REV30;
+           break;
+   default:
+           port->negotiated_rev = PD_MAX_REV;
+           break;
+   }
+   port->negotiated_rev_prime = port->negotiated_rev;
+}

Do we need this? Couldn't you just add one to rev_major?

Quoted 4 lines
        port->negotiated_rev = port->pd_rev.rev_major + 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major + 1;

Or am I missing something?

Quoted 7 lines

Sorry, I mean minus one :-)

        port->negotiated_rev = port->pd_rev.rev_major - 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major - 1;

--
heikki

It seems to be the PATCH v1:
https://lore.kernel.org/all/[email protected]/

Quoted 7 lines
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;
}

Okay, sorry I missed that. I still don't like the extra definitions, but I don't have any better idea (I guess macro is not an option?).

thanks,

Signature · 1 line
heikki
#5 lore raw

Hi Heikki,

Quoted 63 lines · Heikki Krogerus
Quoted 62 lines · Cosmo Chou
Quoted 61 lines · Heikki Krogerus
Quoted 60 lines · Heikki Krogerus
Quoted 47 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 or 2.0 specifications.

---
Change log:

v2:
- Add PD_CAP_REVXX macros and use switch-case for better readability.

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +12 -0
index 8adf6f954633..48e9cfc2b49a 100644
@@ -313,6 +313,10 @@ struct pd_data {
    unsigned int operating_snk_mw;
 };
 
+#define PD_CAP_REV10       0x1
+#define PD_CAP_REV20       0x2
+#define PD_CAP_REV30       0x3
+
 struct pd_revision_info {
    u8 rev_major;
    u8 rev_minor;
@@ -4665,6 +4669,25 @@ static void tcpm_set_initial_svdm_version(struct tcpm_port *port)
    }
 }
 
+static void tcpm_set_initial_negotiated_rev(struct tcpm_port *port)
+{
+   switch (port->pd_rev.rev_major) {
+   case PD_CAP_REV10:
+           port->negotiated_rev = PD_REV10;
+           break;
+   case PD_CAP_REV20:
+           port->negotiated_rev = PD_REV20;

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

Quoted 10 lines
drivers/usb/typec/tcpm/tcpm.c +10 -0
+           break;
+   case PD_CAP_REV30:
+           port->negotiated_rev = PD_REV30;
+           break;
+   default:
+           port->negotiated_rev = PD_MAX_REV;
+           break;
+   }
+   port->negotiated_rev_prime = port->negotiated_rev;
+}

Do we need this? Couldn't you just add one to rev_major?

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 4 lines
        port->negotiated_rev = port->pd_rev.rev_major + 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major + 1;

Or am I missing something?

Sorry, I mean minus one :-)

        port->negotiated_rev = port->pd_rev.rev_major - 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major - 1;

The only reason I asked for macros is that in the case of Spec Revision for header, the value for PD 3.0 is 0x2, PD 2.0 is 0x1 & so on. While for PD max revisions, it's the exact values. Having a clear distinction may be easier to follow. If you want to go with the +/- approach you can add a comment stating the above.

I don't have a hard opinion on either approach :).

Thanks,

Amit

Quoted 19 lines
Quoted 6 lines
Quoted 3 lines

--
heikki

It seems to be the PATCH v1:
https://lore.kernel.org/all/[email protected]/

Quoted 7 lines
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;
}

Okay, sorry I missed that. I still don't like the extra definitions, but I don't have any better idea (I guess macro is not an option?).

thanks,

maintainer Reviewed-by
#6 lore raw
Quoted 18 lines · Amit Sunil Dhamne

Hi Heikki,

Quoted 14 lines · Heikki Krogerus
Quoted 13 lines · Cosmo Chou
Quoted 12 lines · Heikki Krogerus
Quoted 11 lines · Heikki Krogerus
Quoted 10 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 or 2.0 specifications.

Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines
Quoted 39 lines

---
Change log:

v2:
- Add PD_CAP_REVXX macros and use switch-case for better readability.

---
 drivers/usb/typec/tcpm/tcpm.c | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +14 -0
index 8adf6f954633..48e9cfc2b49a 100644
@@ -313,6 +313,10 @@ struct pd_data {
    unsigned int operating_snk_mw;
 };
 
+#define PD_CAP_REV10       0x1
+#define PD_CAP_REV20       0x2
+#define PD_CAP_REV30       0x3
+
 struct pd_revision_info {
    u8 rev_major;
    u8 rev_minor;
@@ -4665,6 +4669,25 @@ static void tcpm_set_initial_svdm_version(struct tcpm_port *port)
    }
 }
 
+static void tcpm_set_initial_negotiated_rev(struct tcpm_port *port)
+{
+   switch (port->pd_rev.rev_major) {
+   case PD_CAP_REV10:
+           port->negotiated_rev = PD_REV10;
+           break;
+   case PD_CAP_REV20:
+           port->negotiated_rev = PD_REV20;
+           break;
+   case PD_CAP_REV30:
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

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

Quoted 8 lines
drivers/usb/typec/tcpm/tcpm.c +8 -0
+           port->negotiated_rev = PD_REV30;
+           break;
+   default:
+           port->negotiated_rev = PD_MAX_REV;
+           break;
+   }
+   port->negotiated_rev_prime = port->negotiated_rev;
+}

IMHO this looks better in terms of readability although V1 is more concise.

Thanks,
Badhri

Quoted 42 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 6 lines

Do we need this? Couldn't you just add one to rev_major?

        port->negotiated_rev = port->pd_rev.rev_major + 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major + 1;

Or am I missing something?

Sorry, I mean minus one :-)

        port->negotiated_rev = port->pd_rev.rev_major - 1;
        port->negotiated_rev_prime = port->pd_rev.rev_major - 1;

The only reason I asked for macros is that in the case of Spec Revision for header, the value for PD 3.0 is 0x2, PD 2.0 is 0x1 & so on. While for PD max revisions, it's the exact values. Having a clear distinction may be easier to follow. If you want to go with the +/- approach you can add a comment stating the above.

I don't have a hard opinion on either approach :).

Thanks,

Amit

Quoted 19 lines
Quoted 6 lines
Quoted 3 lines

--
heikki

It seems to be the PATCH v1:
https://lore.kernel.org/all/[email protected]/

Quoted 7 lines
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;
}

Okay, sorry I missed that. I still don't like the extra definitions, but I don't have any better idea (I guess macro is not an option?).

thanks,