|
9 | 9 |
|
10 | 10 | #include <linux/slab.h> |
11 | 11 | #include <linux/pm_qos.h> |
| 12 | +#include <linux/component.h> |
12 | 13 |
|
13 | 14 | #include "hub.h" |
14 | 15 |
|
@@ -528,6 +529,32 @@ static void find_and_link_peer(struct usb_hub *hub, int port1) |
528 | 529 | link_peers_report(port_dev, peer); |
529 | 530 | } |
530 | 531 |
|
| 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 | + |
531 | 558 | int usb_hub_create_port_device(struct usb_hub *hub, int port1) |
532 | 559 | { |
533 | 560 | struct usb_port *port_dev; |
@@ -577,6 +604,10 @@ int usb_hub_create_port_device(struct usb_hub *hub, int port1) |
577 | 604 |
|
578 | 605 | find_and_link_peer(hub, port1); |
579 | 606 |
|
| 607 | + retval = component_add(&port_dev->dev, &connector_ops); |
| 608 | + if (retval) |
| 609 | + dev_warn(&port_dev->dev, "failed to add component\n"); |
| 610 | + |
580 | 611 | /* |
581 | 612 | * Enable runtime pm and hold a refernce that hub_configure() |
582 | 613 | * 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) |
619 | 650 | peer = port_dev->peer; |
620 | 651 | if (peer) |
621 | 652 | unlink_peers(port_dev, peer); |
| 653 | + component_del(&port_dev->dev, &connector_ops); |
622 | 654 | device_unregister(&port_dev->dev); |
623 | 655 | } |
0 commit comments