All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
To: Abhishek Pandit-Subedi <abhishekpandit@chromium.org>
Cc: "Dmitry Baryshkov" <dmitry.baryshkov@linaro.org>,
	"Łukasz Bartosik" <ukaszb@chromium.org>,
	"Benson Leung" <bleung@chromium.org>,
	"Jameson Thies" <jthies@google.com>,
	"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
	linux-usb@vger.kernel.org
Subject: [PATCH v1 4/4] usb: typec: ucsi: Add support for the partner USB Modes
Date: Fri,  4 Oct 2024 17:04:39 +0300	[thread overview]
Message-ID: <20241004140440.1882311-5-heikki.krogerus@linux.intel.com> (raw)
In-Reply-To: <20241004140440.1882311-1-heikki.krogerus@linux.intel.com>

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 | 9 +++++++++
 drivers/usb/typec/ucsi/ucsi.h | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/drivers/usb/typec/ucsi/ucsi.c b/drivers/usb/typec/ucsi/ucsi.c
index 13c739d334c4..b7f0cdc70250 100644
--- a/drivers/usb/typec/ucsi/ucsi.c
+++ b/drivers/usb/typec/ucsi/ucsi.c
@@ -1037,6 +1037,7 @@ static int ucsi_register_partner(struct ucsi_connector *con)
 		desc.accessory = TYPEC_ACCESSORY_AUDIO;
 		break;
 	default:
+		desc.usb_capability = USB_CAPABILITY_USB2;
 		break;
 	}
 
@@ -1057,6 +1058,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 f6a3287cdc06..189e45f37bae 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
-- 
2.45.2


      parent reply	other threads:[~2024-10-04 14:04 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-04 14:04 [PATCH v1 0/3] usb: typec: USB Modes Heikki Krogerus
2024-10-04 14:04 ` [PATCH v1 1/4] usb: typec: Add attribute file showing the supported USB modes of the port Heikki Krogerus
2024-10-06 16:35   ` Dmitry Baryshkov
2024-10-04 14:04 ` [PATCH v1 2/4] usb: typec: Add attribute file showing the USB Modes of the partner Heikki Krogerus
2024-10-05  7:25   ` kernel test robot
2024-10-06 16:22   ` Dmitry Baryshkov
2024-10-09  8:34     ` Heikki Krogerus
2024-10-04 14:04 ` [PATCH v1 3/4] usb: typec: ucsi: Supply the USB capabilities to the ports Heikki Krogerus
2024-10-06 16:36   ` Dmitry Baryshkov
2024-10-04 14:04 ` Heikki Krogerus [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241004140440.1882311-5-heikki.krogerus@linux.intel.com \
    --to=heikki.krogerus@linux.intel.com \
    --cc=abhishekpandit@chromium.org \
    --cc=bleung@chromium.org \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jthies@google.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=ukaszb@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.