]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
usb: typec: Connect Type-C port with associated USB4 port
authorAlan Borzeszkowski <alan.borzeszkowski@linux.intel.com>
Mon, 14 Apr 2025 17:55:54 +0000 (19:55 +0200)
committerMika Westerberg <mika.westerberg@linux.intel.com>
Thu, 17 Apr 2025 09:21:45 +0000 (12:21 +0300)
If USB3.x device references USB4 host interface, USB4 port can be
connected with appropriate Type-C port. By using component framework,
and in turn by creating symlinks, userspace can benefit from having
Thunderbolt/USB4 connection to Type-C ports.

Note: This change introduces dependency on Thunderbolt driver as it's
required to properly map USB4 port to Type-C port.

Signed-off-by: Alan Borzeszkowski <alan.borzeszkowski@linux.intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
drivers/usb/typec/port-mapper.c

index d42da5720a251da3dc0700baa2b2103a5c4a20cb..cdbb7c11d714223b684cf43469c6ceb136d13996 100644 (file)
@@ -8,6 +8,7 @@
 
 #include <linux/acpi.h>
 #include <linux/component.h>
+#include <linux/thunderbolt.h>
 #include <linux/usb.h>
 
 #include "class.h"
@@ -36,6 +37,11 @@ struct each_port_arg {
        struct component_match *match;
 };
 
+static int usb4_port_compare(struct device *dev, void *fwnode)
+{
+       return usb4_usb3_port_match(dev, fwnode);
+}
+
 static int typec_port_compare(struct device *dev, void *fwnode)
 {
        return device_match_fwnode(dev, fwnode);
@@ -51,9 +57,22 @@ static int typec_port_match(struct device *dev, void *data)
        if (con_adev == adev)
                return 0;
 
-       if (con_adev->pld_crc == adev->pld_crc)
+       if (con_adev->pld_crc == adev->pld_crc) {
+               struct fwnode_handle *adev_fwnode = acpi_fwnode_handle(adev);
+
                component_match_add(&arg->port->dev, &arg->match, typec_port_compare,
-                                   acpi_fwnode_handle(adev));
+                                   adev_fwnode);
+
+               /*
+                * If dev is USB 3.x port, it may have reference to the
+                * USB4 host interface in which case we can also link the
+                * Type-C port with the USB4 port.
+                */
+               if (fwnode_property_present(adev_fwnode, "usb4-host-interface"))
+                       component_match_add(&arg->port->dev, &arg->match,
+                                           usb4_port_compare, adev_fwnode);
+       }
+
        return 0;
 }