Skip to content

Commit 8c67d06

Browse files
Heikki Krogerusgregkh
authored andcommitted
usb: Link the ports to the connectors they are attached to
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]>
1 parent 882c982 commit 8c67d06

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

Documentation/ABI/testing/sysfs-bus-usb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,15 @@ Description:
244244
is permitted, "u2" if only u2 is permitted, "u1_u2" if both u1 and
245245
u2 are permitted.
246246

247+
What: /sys/bus/usb/devices/.../<hub_interface>/port<X>/connector
248+
Date: December 2021
249+
Contact: Heikki Krogerus <[email protected]>
250+
Description:
251+
Link to the USB Type-C connector when available. This link is
252+
only created when USB Type-C Connector Class is enabled, and
253+
only if the system firmware is capable of describing the
254+
connection between a port and its connector.
255+
247256
What: /sys/bus/usb/devices/.../power/usb2_lpm_l1_timeout
248257
Date: May 2013
249258
Contact: Mathias Nyman <[email protected]>

drivers/usb/core/port.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/slab.h>
1111
#include <linux/pm_qos.h>
12+
#include <linux/component.h>
1213

1314
#include "hub.h"
1415

@@ -528,6 +529,32 @@ static void find_and_link_peer(struct usb_hub *hub, int port1)
528529
link_peers_report(port_dev, peer);
529530
}
530531

532+
static int connector_bind(struct device *dev, struct device *connector, void *data)
533+
{
534+
int ret;
535+
536+
ret = sysfs_create_link(&dev->kobj, &connector->kobj, "connector");
537+
if (ret)
538+
return ret;
539+
540+
ret = sysfs_create_link(&connector->kobj, &dev->kobj, dev_name(dev));
541+
if (ret)
542+
sysfs_remove_link(&dev->kobj, "connector");
543+
544+
return ret;
545+
}
546+
547+
static void connector_unbind(struct device *dev, struct device *connector, void *data)
548+
{
549+
sysfs_remove_link(&connector->kobj, dev_name(dev));
550+
sysfs_remove_link(&dev->kobj, "connector");
551+
}
552+
553+
static const struct component_ops connector_ops = {
554+
.bind = connector_bind,
555+
.unbind = connector_unbind,
556+
};
557+
531558
int usb_hub_create_port_device(struct usb_hub *hub, int port1)
532559
{
533560
struct usb_port *port_dev;
@@ -577,6 +604,10 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1)
577604

578605
find_and_link_peer(hub, port1);
579606

607+
retval = component_add(&port_dev->dev, &connector_ops);
608+
if (retval)
609+
dev_warn(&port_dev->dev, "failed to add component\n");
610+
580611
/*
581612
* Enable runtime pm and hold a refernce that hub_configure()
582613
* 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)
619650
peer = port_dev->peer;
620651
if (peer)
621652
unlink_peers(port_dev, peer);
653+
component_del(&port_dev->dev, &connector_ops);
622654
device_unregister(&port_dev->dev);
623655
}

0 commit comments

Comments
 (0)