diff mbox series

[v3,4/4] usb: typec: ucsi: Add support for the partner USB Modes

Message ID 20241011124402.3306994-5-heikki.krogerus@linux.intel.com (mailing list archive)
State Superseded
Headers show
Series usb: typec: USB Modes | expand

Commit Message

Heikki Krogerus Oct. 11, 2024, 12:44 p.m. UTC
UCSI does not share the contents of the Enter_USB Message
that was used, so the active mode still has to be always
determined from the enumerated USB device. However, after
UCSI v2.0 it is possible to check separately is USB4 the
active mode.

So with USB2 and USB3 the mode is always determined from the
result of the USB enumeration, and when USB4 USB Mode is
active, UCSI driver can assign the mode directly.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
---
 drivers/usb/typec/ucsi/ucsi.c | 8 ++++++++
 drivers/usb/typec/ucsi/ucsi.h | 2 ++
 2 files changed, 10 insertions(+)

Comments

Greg KH Oct. 11, 2024, 1:11 p.m. UTC | #1
On Fri, Oct 11, 2024 at 03:44:02PM +0300, Heikki Krogerus wrote:
> UCSI does not share the contents of the Enter_USB Message
> that was used, so the active mode still has to be always
> determined from the enumerated USB device. However, after
> UCSI v2.0 it is possible to check separately is USB4 the
> active mode.
> 
> So with USB2 and USB3 the mode is always determined from the
> result of the USB enumeration, and when USB4 USB Mode is
> active, UCSI driver can assign the mode directly.
> 
> Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> ---
>  drivers/usb/typec/ucsi/ucsi.c | 8 ++++++++
>  drivers/usb/typec/ucsi/ucsi.h | 2 ++
>  2 files changed, 10 insertions(+)
> 
> diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> index 13c739d334c4..804f7f9b35ea 100644
> --- a/drivers/usb/typec/ucsi/ucsi.c
> +++ b/drivers/usb/typec/ucsi/ucsi.c
> @@ -1057,6 +1057,14 @@ static int ucsi_register_partner(struct ucsi_connector *con)
>  
>  	con->partner = partner;
>  
> +	if (con->ucsi->version >= UCSI_VERSION_3_0)
> +		if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) &
> +		    UCSI_CONSTAT_PARTNER_FLAG_USB4_GEN4)
> +			typec_partner_set_usb_mode(partner, USB_MODE_USB4);
> +	if (con->ucsi->version >= UCSI_VERSION_2_0)
> +		if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) &
> +		    UCSI_CONSTAT_PARTNER_FLAG_USB4_GEN3)
> +			typec_partner_set_usb_mode(partner, USB_MODE_USB4);

Will this cause multiple set mode uevents to go out if both of these are
true?

thanks,

greg k-h
Heikki Krogerus Oct. 11, 2024, 2:04 p.m. UTC | #2
On Fri, Oct 11, 2024 at 03:11:01PM +0200, Greg Kroah-Hartman wrote:
> On Fri, Oct 11, 2024 at 03:44:02PM +0300, Heikki Krogerus wrote:
> > UCSI does not share the contents of the Enter_USB Message
> > that was used, so the active mode still has to be always
> > determined from the enumerated USB device. However, after
> > UCSI v2.0 it is possible to check separately is USB4 the
> > active mode.
> > 
> > So with USB2 and USB3 the mode is always determined from the
> > result of the USB enumeration, and when USB4 USB Mode is
> > active, UCSI driver can assign the mode directly.
> > 
> > Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
> > ---
> >  drivers/usb/typec/ucsi/ucsi.c | 8 ++++++++
> >  drivers/usb/typec/ucsi/ucsi.h | 2 ++
> >  2 files changed, 10 insertions(+)
> > 
> > diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
> > index 13c739d334c4..804f7f9b35ea 100644
> > --- a/drivers/usb/typec/ucsi/ucsi.c
> > +++ b/drivers/usb/typec/ucsi/ucsi.c
> > @@ -1057,6 +1057,14 @@ static int ucsi_register_partner(struct ucsi_connector *con)
> >  
> >  	con->partner = partner;
> >  
> > +	if (con->ucsi->version >= UCSI_VERSION_3_0)
> > +		if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) &
> > +		    UCSI_CONSTAT_PARTNER_FLAG_USB4_GEN4)
> > +			typec_partner_set_usb_mode(partner, USB_MODE_USB4);
> > +	if (con->ucsi->version >= UCSI_VERSION_2_0)
> > +		if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) &
> > +		    UCSI_CONSTAT_PARTNER_FLAG_USB4_GEN3)
> > +			typec_partner_set_usb_mode(partner, USB_MODE_USB4);
> 
> Will this cause multiple set mode uevents to go out if both of these are
> true?

That should not be possible, but I'll change it to if else.

thanks,
diff mbox series

Patch

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 13c739d334c4..804f7f9b35ea 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1057,6 +1057,14 @@  static int ucsi_register_partner(struct ucsi_connector *con)
 
 	con->partner = partner;
 
+	if (con->ucsi->version >= UCSI_VERSION_3_0)
+		if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) &
+		    UCSI_CONSTAT_PARTNER_FLAG_USB4_GEN4)
+			typec_partner_set_usb_mode(partner, USB_MODE_USB4);
+	if (con->ucsi->version >= UCSI_VERSION_2_0)
+		if (UCSI_CONSTAT_PARTNER_FLAGS(con->status.flags) &
+		    UCSI_CONSTAT_PARTNER_FLAG_USB4_GEN3)
+			typec_partner_set_usb_mode(partner, USB_MODE_USB4);
 	return 0;
 }
 
diff --git a/drivers/usb/typec/ucsi/ucsi.h b/drivers/usb/typec/ucsi/ucsi.h
index a1f4b9b568c8..d850073e8d0a 100644
--- a/drivers/usb/typec/ucsi/ucsi.h
+++ b/drivers/usb/typec/ucsi/ucsi.h
@@ -346,6 +346,8 @@  struct ucsi_connector_status {
 #define UCSI_CONSTAT_PARTNER_FLAGS(_f_)		(((_f_) & GENMASK(12, 5)) >> 5)
 #define   UCSI_CONSTAT_PARTNER_FLAG_USB		1
 #define   UCSI_CONSTAT_PARTNER_FLAG_ALT_MODE	2
+#define   UCSI_CONSTAT_PARTNER_FLAG_USB4_GEN3	4
+#define   UCSI_CONSTAT_PARTNER_FLAG_USB4_GEN4	8
 #define UCSI_CONSTAT_PARTNER_TYPE(_f_)		(((_f_) & GENMASK(15, 13)) >> 13)
 #define   UCSI_CONSTAT_PARTNER_TYPE_DFP		1
 #define   UCSI_CONSTAT_PARTNER_TYPE_UFP		2