* [PATCH v1 0/2] usb: typec: altmodes/displayport: add port data role handling support
@ 2025-08-21 20:38 RD Babiera
2025-08-21 20:38 ` [PATCH v1 1/2] usb: typec: class: add typec_get_data_role symbol RD Babiera
2025-08-21 20:38 ` [PATCH v1 2/2] usb: typec: altmodes/displayport: do not enter mode if port is the UFP RD Babiera
0 siblings, 2 replies; 5+ messages in thread
From: RD Babiera @ 2025-08-21 20:38 UTC (permalink / raw)
Cc: heikki.krogerus, gregkh, badhri, linux-usb, linux-kernel,
RD Babiera
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
--
2.51.0.261.g7ce5a0a67e-goog
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 1/2] usb: typec: class: add typec_get_data_role symbol
2025-08-21 20:38 [PATCH v1 0/2] usb: typec: altmodes/displayport: add port data role handling support RD Babiera
@ 2025-08-21 20:38 ` RD Babiera
2025-08-28 9:43 ` Heikki Krogerus
2025-08-21 20:38 ` [PATCH v1 2/2] usb: typec: altmodes/displayport: do not enter mode if port is the UFP RD Babiera
1 sibling, 1 reply; 5+ messages in thread
From: RD Babiera @ 2025-08-21 20:38 UTC (permalink / raw)
Cc: heikki.krogerus, gregkh, badhri, linux-usb, linux-kernel,
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.
Signed-off-by: RD Babiera <rdbabiera@google.com>
---
drivers/usb/typec/class.c | 13 +++++++++++++
include/linux/usb/typec.h | 1 +
include/linux/usb/typec_altmode.h | 12 ++++++++++++
3 files changed, 26 insertions(+)
diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
index 67a533e35150..9b2647cb199b 100644
--- a/drivers/usb/typec/class.c
+++ b/drivers/usb/typec/class.c
@@ -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
diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
index 252af3f77039..309251572e2e 100644
--- a/include/linux/usb/typec.h
+++ b/include/linux/usb/typec.h
@@ -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);
diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_altmode.h
index b3c0866ea70f..559cd6865ba1 100644
--- a/include/linux/usb/typec_altmode.h
+++ b/include/linux/usb/typec_altmode.h
@@ -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
--
2.51.0.261.g7ce5a0a67e-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v1 2/2] usb: typec: altmodes/displayport: do not enter mode if port is the UFP
2025-08-21 20:38 [PATCH v1 0/2] usb: typec: altmodes/displayport: add port data role handling support RD Babiera
2025-08-21 20:38 ` [PATCH v1 1/2] usb: typec: class: add typec_get_data_role symbol RD Babiera
@ 2025-08-21 20:38 ` RD Babiera
1 sibling, 0 replies; 5+ messages in thread
From: RD Babiera @ 2025-08-21 20:38 UTC (permalink / raw)
Cc: heikki.krogerus, gregkh, badhri, linux-usb, linux-kernel,
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.
Signed-off-by: RD Babiera <rdbabiera@google.com>
---
drivers/usb/typec/altmodes/displayport.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/typec/altmodes/displayport.c b/drivers/usb/typec/altmodes/displayport.c
index 1dcb77faf85d..8d111ad3b71b 100644
--- a/drivers/usb/typec/altmodes/displayport.c
+++ b/drivers/usb/typec/altmodes/displayport.c
@@ -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) &
--
2.51.0.261.g7ce5a0a67e-goog
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/2] usb: typec: class: add typec_get_data_role symbol
2025-08-21 20:38 ` [PATCH v1 1/2] usb: typec: class: add typec_get_data_role symbol RD Babiera
@ 2025-08-28 9:43 ` Heikki Krogerus
2025-09-03 16:47 ` RD Babiera
0 siblings, 1 reply; 5+ messages in thread
From: Heikki Krogerus @ 2025-08-28 9:43 UTC (permalink / raw)
To: RD Babiera; +Cc: gregkh, badhri, linux-usb, linux-kernel
On Thu, Aug 21, 2025 at 08:38:34PM +0000, RD Babiera wrote:
> 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?
> Signed-off-by: RD Babiera <rdbabiera@google.com>
> ---
> drivers/usb/typec/class.c | 13 +++++++++++++
> include/linux/usb/typec.h | 1 +
> include/linux/usb/typec_altmode.h | 12 ++++++++++++
> 3 files changed, 26 insertions(+)
>
> diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c
> index 67a533e35150..9b2647cb199b 100644
> --- a/drivers/usb/typec/class.c
> +++ b/drivers/usb/typec/class.c
> @@ -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
> diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h
> index 252af3f77039..309251572e2e 100644
> --- a/include/linux/usb/typec.h
> +++ b/include/linux/usb/typec.h
> @@ -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);
> diff --git a/include/linux/usb/typec_altmode.h b/include/linux/usb/typec_altmode.h
> index b3c0866ea70f..559cd6865ba1 100644
> --- a/include/linux/usb/typec_altmode.h
> +++ b/include/linux/usb/typec_altmode.h
> @@ -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.
> + * @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
> --
> 2.51.0.261.g7ce5a0a67e-goog
--
heikki
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 1/2] usb: typec: class: add typec_get_data_role symbol
2025-08-28 9:43 ` Heikki Krogerus
@ 2025-09-03 16:47 ` RD Babiera
0 siblings, 0 replies; 5+ messages in thread
From: RD Babiera @ 2025-09-03 16:47 UTC (permalink / raw)
To: Heikki Krogerus; +Cc: gregkh, badhri, linux-usb, linux-kernel
On Thu, Aug 28, 2025 at 5:44 AM Heikki Krogerus
<heikki.krogerus@linux.intel.com> wrote:
> > 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.
> > @@ -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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-09-03 16:47 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-21 20:38 [PATCH v1 0/2] usb: typec: altmodes/displayport: add port data role handling support RD Babiera
2025-08-21 20:38 ` [PATCH v1 1/2] usb: typec: class: add typec_get_data_role symbol RD Babiera
2025-08-28 9:43 ` Heikki Krogerus
2025-09-03 16:47 ` RD Babiera
2025-08-21 20:38 ` [PATCH v1 2/2] usb: typec: altmodes/displayport: do not enter mode if port is the UFP RD Babiera
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).