]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
usb: typec: ucsi: Supply the USB capabilities to the ports
authorHeikki Krogerus <heikki.krogerus@linux.intel.com>
Wed, 16 Oct 2024 13:18:33 +0000 (16:18 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 17 Oct 2024 06:41:45 +0000 (08:41 +0200)
The USB capabilities can be extracted from the response to
the Get Connector Capability command. USB2 and USB3 support
can be checked from the Operation Mode field, and USB4
support from the Extended Operation Mode field.

Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Tested-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org> # SM8450-HDK
Link: https://lore.kernel.org/r/20241016131834.898599-4-heikki.krogerus@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/typec/ucsi/ucsi.c
drivers/usb/typec/ucsi/ucsi.h

index e0f3925e401b3d6acf794754a0255c32fe8f01b9..13c739d334c4a680449304b7127537b159f0d593 100644 (file)
@@ -1588,6 +1588,13 @@ static int ucsi_register_port(struct ucsi *ucsi, struct ucsi_connector *con)
        if (con->cap.op_mode & UCSI_CONCAP_OPMODE_DEBUG_ACCESSORY)
                *accessory = TYPEC_ACCESSORY_DEBUG;
 
+       if (UCSI_CONCAP_USB2_SUPPORT(con))
+               cap->usb_capability |= USB_CAPABILITY_USB2;
+       if (UCSI_CONCAP_USB3_SUPPORT(con))
+               cap->usb_capability |= USB_CAPABILITY_USB3;
+       if (UCSI_CONCAP_USB4_SUPPORT(con))
+               cap->usb_capability |= USB_CAPABILITY_USB4;
+
        cap->driver_data = con;
        cap->ops = &ucsi_ops;
 
index bcb904813c63d2ee4197b5d387507607b04c192a..ee7d8bf4c404e9a09cfc630ce19961bbeb8b6f14 100644 (file)
@@ -287,6 +287,14 @@ struct ucsi_connector_capability {
        UCSI_SPEC_REVISION_TO_BCD(UCSI_CONCAP_FLAG_PARTNER_PD_MAJOR_REV(_f_))
 } __packed;
 
+#define UCSI_CONCAP_USB2_SUPPORT(_con_) ((_con_)->cap.op_mode & UCSI_CONCAP_OPMODE_USB2)
+#define UCSI_CONCAP_USB3_SUPPORT(_con_) ((_con_)->cap.op_mode & UCSI_CONCAP_OPMODE_USB3)
+#define UCSI_CONCAP_USB4_SUPPORT(_con_)                                        \
+       ((_con_)->ucsi->version >= UCSI_VERSION_2_0 &&                  \
+        ((_con_)->cap.flags & (UCSI_CONCAP_EX_OP_MODE_USB4_GEN2 |      \
+                               UCSI_CONCAP_EX_OP_MODE_USB4_GEN3 |      \
+                               UCSI_CONCAP_EX_OP_MODE_USB4_GEN4)))
+
 struct ucsi_altmode {
        u16 svid;
        u32 mid;