]> Git Repo - linux.git/commitdiff
usb: Link the ports to the connectors they are attached to
authorHeikki Krogerus <[email protected]>
Thu, 23 Dec 2021 08:23:49 +0000 (11:23 +0300)
committerGreg Kroah-Hartman <[email protected]>
Thu, 30 Dec 2021 11:13:04 +0000 (12:13 +0100)
Creating link to the USB Type-C connector for every new port
that is added when possible.

Reviewed-by: Andy Shevchenko <[email protected]>
Acked-by: Rafael J. Wysocki <[email protected]>
Signed-off-by: Heikki Krogerus <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Greg Kroah-Hartman <[email protected]>
Documentation/ABI/testing/sysfs-bus-usb
drivers/usb/core/port.c

index 2ebe5708b4bc019dfe723a3829466d778590d0b5..7efe31ed3a25c7ee85ee13d84e43d774604b494f 100644 (file)
@@ -244,6 +244,15 @@ Description:
                is permitted, "u2" if only u2 is permitted, "u1_u2" if both u1 and
                u2 are permitted.
 
+What:          /sys/bus/usb/devices/.../<hub_interface>/port<X>/connector
+Date:          December 2021
+Contact:       Heikki Krogerus <[email protected]>
+Description:
+               Link to the USB Type-C connector when available. This link is
+               only created when USB Type-C Connector Class is enabled, and
+               only if the system firmware is capable of describing the
+               connection between a port and its connector.
+
 What:          /sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout
 Date:          May 2013
 Contact:       Mathias Nyman <[email protected]>
index dfcca9c876c7367dce5a1c06f00bc498e0b0f026..c2bbf97a79bec1ad7458024e9b8da6b844732b72 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <linux/slab.h>
 #include <linux/pm_qos.h>
+#include <linux/component.h>
 
 #include "hub.h"
 
@@ -528,6 +529,32 @@ static void find_and_link_peer(struct usb_hub *hub, int port1)
                link_peers_report(port_dev, peer);
 }
 
+static int connector_bind(struct device *dev, struct device *connector, void *data)
+{
+       int ret;
+
+       ret = sysfs_create_link(&dev->kobj, &connector->kobj, "connector");
+       if (ret)
+               return ret;
+
+       ret = sysfs_create_link(&connector->kobj, &dev->kobj, dev_name(dev));
+       if (ret)
+               sysfs_remove_link(&dev->kobj, "connector");
+
+       return ret;
+}
+
+static void connector_unbind(struct device *dev, struct device *connector, void *data)
+{
+       sysfs_remove_link(&connector->kobj, dev_name(dev));
+       sysfs_remove_link(&dev->kobj, "connector");
+}
+
+static const struct component_ops connector_ops = {
+       .bind = connector_bind,
+       .unbind = connector_unbind,
+};
+
 int usb_hub_create_port_device(struct usb_hub *hub, int port1)
 {
        struct usb_port *port_dev;
@@ -577,6 +604,10 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
 
        find_and_link_peer(hub, port1);
 
+       retval = component_add(&port_dev->dev, &connector_ops);
+       if (retval)
+               dev_warn(&port_dev->dev, "failed to add component\n");
+
        /*
         * Enable runtime pm and hold a refernce that hub_configure()
         * will drop once the PM_QOS_NO_POWER_OFF flag state has been set
@@ -619,5 +650,6 @@ void usb_hub_remove_port_device(struct usb_hub *hub, int port1)
        peer = port_dev->peer;
        if (peer)
                unlink_peers(port_dev, peer);
+       component_del(&port_dev->dev, &connector_ops);
        device_unregister(&port_dev->dev);
 }
This page took 0.07052 seconds and 4 git commands to generate.