Skip to contentSkip to conversation

usb: typec: altmodes/displayport: add port data role handling support

PATCH Superseded RD Babiera 2 participants 5 messages Aug 21, 2025 – Sep 3, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

RD Babiera

author
#0 lore raw

cover usb: typec: altmodes/displayport: add port data role handling support

This patchset adds support for Type-C PD altmodes drivers to query the port data role using typec_altmode_get_data_role which requires a new symbol typec_get_data_role. The UFP is not allowed to send the Enter Mode command, so Alt Mode drivers can use this check to prevent driver registration during the probe sequence.

The DisplayPort Alt Mode driver queries for the port data role during the probe sequence and exits if the port is the UFP. If a data role swap were initiated, the driver would be unregistered anyways so it is not necessary to keep it alive.

RD Babiera (2):
usb: typec: class: add typec_get_data_role symbol
usb: typec: altmodes/displayport: do not enter mode if port is the UFP

 drivers/usb/typec/altmodes/displayport.c |  4 +++-
 drivers/usb/typec/class.c                | 13 +++++++++++++
 include/linux/usb/typec.h                |  1 +
 include/linux/usb/typec_altmode.h        | 12 ++++++++++++
 4 files changed, 29 insertions(+), 1 deletion(-)

base-commit: 956606bafb5fc6e5968aadcda86fc0037e1d7548

Signature · 1 line
2.51.0.261.g7ce5a0a67e-goog
author
#1 lore raw

PATCH 1/2 usb: typec: class: add typec_get_data_role symbol

Alt Mode drivers are responsible for sending Enter Mode through the TCPM, but only a DFP is allowed to send Enter Mode. typec_get_data_role gets the port's data role, which can then be used in altmode drivers via typec_altmode_get_data_role to know if Enter Mode should be sent.

---
 drivers/usb/typec/class.c         | 13 +++++++++++++
 include/linux/usb/typec.h         |  1 +
 include/linux/usb/typec_altmode.h | 12 ++++++++++++
 3 files changed, 26 insertions(+)
drivers/usb/typec/class.c +13 -0
index 67a533e35150..9b2647cb199b 100644
@@ -2120,6 +2120,19 @@ void typec_set_data_role(struct typec_port *port, enum typec_data_role role)
 }
 EXPORT_SYMBOL_GPL(typec_set_data_role);
 
+/**
+ * typec_get_data_role - Get port data role
+ * @port: The USB Type-C Port to query
+ *
+ * This routine is used by the altmode drivers to determine if the port is the
+ * DFP before issuing Enter Mode
+ */
+enum typec_data_role typec_get_data_role(struct typec_port *port)
+{
+	return port->data_role;
+}
+EXPORT_SYMBOL_GPL(typec_get_data_role);
+
 /**
  * typec_set_pwr_role - Report power role change
  * @port: The USB Type-C Port where the role was changed
include/linux/usb/typec.h +1 -0
index 252af3f77039..309251572e2e 100644
@@ -337,6 +337,7 @@ struct typec_plug *typec_register_plug(struct typec_cable *cable,
 void typec_unregister_plug(struct typec_plug *plug);
 
 void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
+enum typec_data_role typec_get_data_role(struct typec_port *port);
 void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
 void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
 void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
include/linux/usb/typec_altmode.h +12 -0
index b3c0866ea70f..559cd6865ba1 100644
@@ -172,6 +172,18 @@ typec_altmode_get_svdm_version(struct typec_altmode *altmode)
 	return typec_get_negotiated_svdm_version(typec_altmode2port(altmode));
 }
 
+/**
+ * typec_altmode_get_data_role - Get port data role. Alt Mode drivers should only
+ * issue Enter Mode through the port if they are the DFP.
+ *
+ * @altmode Handle to the alternate mode
+ */
+static inline enum typec_data_role
+typec_altmode_get_data_role(struct typec_altmode *altmode)
+{
+	return typec_get_data_role(typec_altmode2port(altmode));
+}
+
 /**
  * struct typec_altmode_driver - USB Type-C alternate mode device driver
  * @id_table: Null terminated array of SVIDs
Signature · 1 line
2.51.0.261.g7ce5a0a67e-goog
maintainer
#2 lore raw

Re: [PATCH v1 1/2] usb: typec: class: add typec_get_data_role symbol

Quoted 4 lines · RD Babiera

Alt Mode drivers are responsible for sending Enter Mode through the TCPM, but only a DFP is allowed to send Enter Mode. typec_get_data_role gets the port's data role, which can then be used in altmode drivers via typec_altmode_get_data_role to know if Enter Mode should be sent.

The functions are okay by me, but is the above statement correct? Are you mixing power role and data role?

Quoted 48 lines
---
 drivers/usb/typec/class.c         | 13 +++++++++++++
 include/linux/usb/typec.h         |  1 +
 include/linux/usb/typec_altmode.h | 12 ++++++++++++
 3 files changed, 26 insertions(+)
drivers/usb/typec/class.c +13 -0
index 67a533e35150..9b2647cb199b 100644
@@ -2120,6 +2120,19 @@ void typec_set_data_role(struct typec_port *port, enum typec_data_role role)
 }
 EXPORT_SYMBOL_GPL(typec_set_data_role);
 
+/**
+ * typec_get_data_role - Get port data role
+ * @port: The USB Type-C Port to query
+ *
+ * This routine is used by the altmode drivers to determine if the port is the
+ * DFP before issuing Enter Mode
+ */
+enum typec_data_role typec_get_data_role(struct typec_port *port)
+{
+	return port->data_role;
+}
+EXPORT_SYMBOL_GPL(typec_get_data_role);
+
 /**
  * typec_set_pwr_role - Report power role change
  * @port: The USB Type-C Port where the role was changed
include/linux/usb/typec.h +1 -0
index 252af3f77039..309251572e2e 100644
@@ -337,6 +337,7 @@ struct typec_plug *typec_register_plug(struct typec_cable *cable,
 void typec_unregister_plug(struct typec_plug *plug);
 
 void typec_set_data_role(struct typec_port *port, enum typec_data_role role);
+enum typec_data_role typec_get_data_role(struct typec_port *port);
 void typec_set_pwr_role(struct typec_port *port, enum typec_role role);
 void typec_set_vconn_role(struct typec_port *port, enum typec_role role);
 void typec_set_pwr_opmode(struct typec_port *port, enum typec_pwr_opmode mode);
include/linux/usb/typec_altmode.h +0 -0
index b3c0866ea70f..559cd6865ba1 100644

include/linux/usb/typec_altmode.h typec_altmode_get_svdm_version(struct typec_altmode *altmode) · line 177

Quoted 6 lines
include/linux/usb/typec_altmode.h +3 -0
@@ -172,6 +172,18 @@ typec_altmode_get_svdm_version(struct typec_altmode *altmode)
 	return typec_get_negotiated_svdm_version(typec_altmode2port(altmode));
 }
 
+/**
+ * typec_altmode_get_data_role - Get port data role. Alt Mode drivers should only
+ * issue Enter Mode through the port if they are the DFP.

The second sentence should go below. But I'm not sure it's correct.

Quoted 13 lines
include/linux/usb/typec_altmode.h +8 -0
+ * @altmode Handle to the alternate mode
+ */
+static inline enum typec_data_role
+typec_altmode_get_data_role(struct typec_altmode *altmode)
+{
+	return typec_get_data_role(typec_altmode2port(altmode));
+}
+
 /**
  * struct typec_altmode_driver - USB Type-C alternate mode device driver
  * @id_table: Null terminated array of SVIDs
Signature · 1 line
2.51.0.261.g7ce5a0a67e-goog
Signature · 1 line
heikki
author
#3 lore raw

Re: [PATCH v1 1/2] usb: typec: class: add typec_get_data_role symbol

Quoted 6 lines · Heikki Krogerus
Quoted 4 lines

Alt Mode drivers are responsible for sending Enter Mode through the TCPM, but only a DFP is allowed to send Enter Mode. typec_get_data_role gets the port's data role, which can then be used in altmode drivers via typec_altmode_get_data_role to know if Enter Mode should be sent.

The functions are okay by me, but is the above statement correct? Are you mixing power role and data role?

The PD Specification lists the DFP as being the USB host when USB Communication is supported while acting as a DFP; it gives a charger being a DFP and not supporting USB Communication as an example.

Quoted 9 lines

include/linux/usb/typec_altmode.h typec_altmode_get_svdm_version(struct typec_altmode *altmode) · line 177

Quoted 7 lines
include/linux/usb/typec_altmode.h +3 -0
@@ -172,6 +172,18 @@ typec_altmode_get_svdm_version(struct typec_altmode *altmode)
      return typec_get_negotiated_svdm_version(typec_altmode2port(altmode));
 }
 
+/**
+ * typec_altmode_get_data_role - Get port data role. Alt Mode drivers should only
+ * issue Enter Mode through the port if they are the DFP.

The second sentence should go below. But I'm not sure it's correct.

The kernel-doc comment guide agrees with that statement. I'll change it, thanks for the heads up!

---
RD

author
#4 lore raw

PATCH 2/2 usb: typec: altmodes/displayport: do not enter mode if port is the UFP

In reply to RD Babiera

Nothing currently stops the DisplayPort Alt Mode driver from sending Enter Mode if the port is the Data Device. Utilize typec_altmode_get_data_role to prevent mode entry.

---
 drivers/usb/typec/altmodes/displayport.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/usb/typec/altmodes/displayport.c +3 -1
index 1dcb77faf85d..8d111ad3b71b 100644
@@ -758,7 +758,9 @@ int dp_altmode_probe(struct typec_altmode *alt)
 	struct fwnode_handle *fwnode;
 	struct dp_altmode *dp;
 
-	/* FIXME: Port can only be DFP_U. */
+	/* Port can only be DFP_U. */
+	if (typec_altmode_get_data_role(alt) != TYPEC_HOST)
+		return -EPROTO;
 
 	/* Make sure we have compatible pin configurations */
 	if (!(DP_CAP_PIN_ASSIGN_DFP_D(port->vdo) &
Signature · 1 line
2.51.0.261.g7ce5a0a67e-goog