Skip to contentSkip to conversation

usb: typec: tcpm: Add support for parsing pd-revision DT property

PATCH Superseded Cosmo Chou 2 participants 2 messages May 13, 2025 – May 16, 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: Add support for parsing pd-revision DT property

From: Amit Sunil Dhamne <[email protected]>

Add support for parsing "pd-revision" DT property in TCPM and store PD revision and version supported by the Type-C connnector.

It should be noted that the PD revision is the maximum possible revision supported by the port. This is different from the 2 bit revision set in PD msg headers. The purpose of the 2 bit revision value is to negotiate between Rev 2.X & 3.X spec rev as part of contract negotiation, while this is used for Get_Revision AMS after a contract is in place.

---
 drivers/usb/typec/tcpm/tcpm.c | 46 +++++++++++++++++++++++++++++++++--
 1 file changed, 44 insertions(+), 2 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +44 -2
index 6021eeb903fe..59621cfaee3d 100644
@@ -310,6 +310,13 @@ struct pd_data {
 	unsigned int operating_snk_mw;
 };
 
+struct pd_revision_info {
+	u8 rev_major;
+	u8 rev_minor;
+	u8 ver_major;
+	u8 ver_minor;
+};
+
 /*
  * @sink_wait_cap_time: Deadline (in ms) for tTypeCSinkWaitCap timer
  * @ps_src_wait_off_time: Deadline (in ms) for tPSSourceOff timer
@@ -567,6 +574,9 @@ struct tcpm_port {
 
 	/* Timer deadline values configured at runtime */
 	struct pd_timings timings;
+
+	/* Indicates maximum (revision, version) supported */
+	struct pd_revision_info pd_rev;
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *dentry;
 	struct mutex logbuffer_lock;	/* log buffer access lock */
@@ -7036,7 +7046,9 @@ static void tcpm_port_unregister_pd(struct tcpm_port *port)
 
 static int tcpm_port_register_pd(struct tcpm_port *port)
 {
-	struct usb_power_delivery_desc desc = { port->typec_caps.pd_revision };
+	u16 pd_revision = port->typec_caps.pd_revision;
+	u16 pd_version = port->pd_rev.ver_major << 8 | port->pd_rev.ver_minor;
+	struct usb_power_delivery_desc desc = { pd_revision, pd_version };
 	struct usb_power_delivery_capabilities *cap;
 	int ret, i;
 
@@ -7331,6 +7343,29 @@ static int tcpm_fw_get_snk_vdos(struct tcpm_port *port, struct fwnode_handle *fw
 	return 0;
 }
 
+static void tcpm_fw_get_pd_revision(struct tcpm_port *port, struct fwnode_handle *fwnode)
+{
+	int ret;
+	u8 val[4];
+
+	ret = fwnode_property_count_u8(fwnode, "pd-revision");
+	if (!ret || ret != 4) {
+		tcpm_log(port, "Unable to find pd-revision property or incorrect array size");
+		return;
+	}
+
+	ret = fwnode_property_read_u8_array(fwnode, "pd-revision", val, 4);
+	if (ret) {
+		tcpm_log(port, "Failed to parse pd-revision, ret:(%d)", ret);
+		return;
+	}
+
+	port->pd_rev.rev_major = val[0];
+	port->pd_rev.rev_minor = val[1];
+	port->pd_rev.ver_major = val[2];
+	port->pd_rev.ver_minor = val[3];
+}
+
 /* Power Supply access to expose source power information */
 enum tcpm_psy_online_states {
 	TCPM_PSY_OFFLINE = 0,
@@ -7669,11 +7704,18 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
 		goto out_destroy_wq;
 
 	tcpm_fw_get_timings(port, tcpc->fwnode);
+	tcpm_fw_get_pd_revision(port, tcpc->fwnode);
 
 	port->try_role = port->typec_caps.prefer_role;
 
 	port->typec_caps.revision = 0x0120;	/* Type-C spec release 1.2 */
-	port->typec_caps.pd_revision = 0x0300;	/* USB-PD spec release 3.0 */
+
+	if (port->pd_rev.rev_major)
+		port->typec_caps.pd_revision = port->pd_rev.rev_major << 8 |
+					       port->pd_rev.rev_minor;
+	else
+		port->typec_caps.pd_revision = 0x0300;	/* USB-PD spec release 3.0 */
+
 	port->typec_caps.svdm_version = SVDM_VER_2_0;
 	port->typec_caps.driver_data = port;
 	port->typec_caps.ops = &tcpm_ops;
Signature · 1 line
2.43.0
#1 lore raw

Hi Cosmo,

Quoted 11 lines · Cosmo Chou

From: Amit Sunil Dhamne <[email protected]>

Add support for parsing "pd-revision" DT property in TCPM and store PD revision and version supported by the Type-C connnector.

It should be noted that the PD revision is the maximum possible revision supported by the port. This is different from the 2 bit revision set in PD msg headers. The purpose of the 2 bit revision value is to negotiate between Rev 2.X & 3.X spec rev as part of contract negotiation, while this is used for Get_Revision AMS after a contract is in place.

Quoted 7 lines

---
 drivers/usb/typec/tcpm/tcpm.c | 46 +++++++++++++++++++++++++++++++++--

 1 file changed, 44 insertions(+), 2 deletions(-)

I briefly looked at directly backporting this to dev-6.6 from upstream (8ecf60c3b3d4), but doing so generated conflicts. Did you find the same? If so, please add a short note about what you fixed to the trailer as well as your S-o-b tag, e.g.

...

[Cosmo: Changed <fix summary> to resolve merge conflcts]
Signed-off-by <Your contact details>

Patch reports fuzz when I apply this to the tip of dev-6.6, which is currently 5a4c98323b01 ("Merge tag 'v6.6.90' into for/openbmc/dev- 6.6"). Can you address that and re-send?

Cheers,

Andrew