switch (port_dev->connect_type) { case USB_PORT_CONNECT_TYPE_HOT_PLUG:
result = "hotplug"; break; case USB_PORT_CONNECT_TYPE_HARD_WIRED:
result = "hardwired"; break; case USB_PORT_NOT_USED:
result = "not used"; break; default:
result = "unknown"; break;
}
if (port_dev->usb3_lpm_u1_permit) { if (port_dev->usb3_lpm_u2_permit)
p = "u1_u2"; else
p = "u1";
} else { if (port_dev->usb3_lpm_u2_permit)
p = "u2"; else
p = "0";
}
/* If device is connected to the port, disable or enable lpm * to make new u1 u2 setting take effect immediately.
*/ if (udev) {
hcd = bus_to_hcd(udev->bus); if (!hcd) return -EINVAL;
usb_lock_device(udev);
mutex_lock(hcd->bandwidth_mutex); if (!usb_disable_lpm(udev))
usb_enable_lpm(udev);
mutex_unlock(hcd->bandwidth_mutex);
usb_unlock_device(udev);
}
if (!hub) return -EINVAL; if (hub->in_reset) {
set_bit(port1, hub->power_bits); return 0;
}
/* * Power on our usb3 peer before this usb2 port to prevent a usb3 * device from degrading to its usb2 connection
*/ if (!port_dev->is_superspeed && peer)
pm_runtime_get_sync(&peer->dev);
retval = usb_autopm_get_interface(intf); if (retval < 0) return retval;
retval = usb_hub_set_port_power(hdev, hub, port1, true);
msleep(hub_power_on_good_delay(hub)); if (udev && !retval) { /* * Our preference is to simply wait for the port to reconnect, * as that is the lowest latency method to restart the port. * However, there are cases where toggling port power results in * the host port and the device port getting out of sync causing * a link training live lock. Upon timeout, flag the port as * needing warm reset recovery (to be performed later by * usb_port_resume() as requested via usb_wakeup_notification())
*/ if (hub_port_debounce_be_connected(hub, port1) < 0) {
dev_dbg(&port_dev->dev, "reconnect timeout\n"); if (hub_is_superspeed(hdev))
set_bit(port1, hub->warm_reset_bits);
}
/* Force the child awake to revalidate after the power loss. */ if (!test_and_set_bit(port1, hub->child_usage_bits)) {
pm_runtime_get_noresume(&port_dev->dev);
pm_request_resume(&udev->dev);
}
}
/* * Our peer usb3 port may now be able to suspend, so * asynchronously queue a suspend request to observe that this * usb2 port is now off.
*/ if (!port_dev->is_superspeed && peer)
pm_runtime_put(&peer->dev);
/* * We need to wake the HiSpeed port to make sure we don't race * setting ->peer with usb_port_runtime_suspend(). Otherwise we * may miss a suspend event for the SuperSpeed port.
*/ if (left->is_superspeed) {
ss_port = left;
WARN_ON(right->is_superspeed);
hs_port = right;
} else {
ss_port = right;
WARN_ON(!right->is_superspeed);
hs_port = left;
}
pm_runtime_get_sync(&hs_port->dev);
left->peer = right;
right->peer = left;
/* * The SuperSpeed reference is dropped when the HiSpeed port in * this relationship suspends, i.e. when it is safe to allow a * SuperSpeed connection to drop since there is no risk of a * device degrading to its powered-off HiSpeed connection. * * Also, drop the HiSpeed ref taken above.
*/
pm_runtime_get_sync(&ss_port->dev);
pm_runtime_put(&hs_port->dev);
return 0;
}
staticvoid link_peers_report(struct usb_port *left, struct usb_port *right)
{ int rc;
rc = link_peers(left, right); if (rc == 0) {
dev_dbg(&left->dev, "peered to %s\n", dev_name(&right->dev));
} else {
dev_dbg(&left->dev, "failed to peer to %s (%d)\n",
dev_name(&right->dev), rc);
pr_warn_once("usb: port power management may be unreliable\n");
usb_port_block_power_off = 1;
}
}
WARN(right->peer != left || left->peer != right, "%s and %s are not peers?\n",
dev_name(&left->dev), dev_name(&right->dev));
/* * We wake the HiSpeed port to make sure we don't race its * usb_port_runtime_resume() event which takes a SuperSpeed ref * when ->peer is !NULL.
*/ if (left->is_superspeed) {
ss_port = left;
hs_port = right;
} else {
ss_port = right;
hs_port = left;
}
/* Drop the SuperSpeed ref held on behalf of the active HiSpeed port */
pm_runtime_put(&ss_port->dev);
/* Drop the ref taken above */
pm_runtime_put(&hs_port->dev);
}
/* * For each usb hub device in the system check to see if it is in the * peer domain of the given port_dev, and if it is check to see if it * has a port that matches the given port by location
*/ staticint match_location(struct usb_device *peer_hdev, void *p)
{ int port1; struct usb_hcd *hcd, *peer_hcd; struct usb_port *port_dev = p, *peer; struct usb_hub *peer_hub = usb_hub_to_struct_hub(peer_hdev); struct usb_device *hdev = to_usb_device(port_dev->dev.parent->parent);
if (!peer_hub || port_dev->connect_type == USB_PORT_NOT_USED) return 0;
hcd = bus_to_hcd(hdev->bus);
peer_hcd = bus_to_hcd(peer_hdev->bus); /* peer_hcd is provisional until we verify it against the known peer */ if (peer_hcd != hcd->shared_hcd) return 0;
/* * Find the peer port either via explicit platform firmware "location" * data, the peer hcd for root hubs, or the upstream peer relationship * for all other hubs.
*/ staticvoid find_and_link_peer(struct usb_hub *hub, int port1)
{ struct usb_port *port_dev = hub->ports[port1 - 1], *peer; struct usb_device *hdev = hub->hdev; struct usb_device *peer_hdev; struct usb_hub *peer_hub;
/* * If location data is available then we can only peer this port * by a location match, not the default peer (lest we create a * situation where we need to go back and undo a default peering * when the port is later peered by location data)
*/ if (port_dev->location) { /* we link the peer in match_location() if found */
usb_for_each_dev(port_dev, match_location); return;
} elseif (!hdev->parent) { struct usb_hcd *hcd = bus_to_hcd(hdev->bus); struct usb_hcd *peer_hcd = hcd->shared_hcd;
upstream = parent_hub->ports[hdev->portnum - 1]; if (!upstream || !upstream->peer) return;
peer_hdev = upstream->peer->child;
}
peer_hub = usb_hub_to_struct_hub(peer_hdev); if (!peer_hub || port1 > peer_hdev->maxchild) return;
/* * we found a valid default peer, last check is to make sure it * does not have location data
*/
peer = peer_hub->ports[port1 - 1]; if (peer && peer->location == 0)
link_peers_report(port_dev, peer);
}
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;
}
port_dev->connector = data;
/* * If there is already USB device connected to the port, letting the * Type-C connector know about it immediately.
*/ if (port_dev->child)
typec_attach(port_dev->connector, &port_dev->child->dev);
port_dev->state_kn = sysfs_get_dirent(port_dev->dev.kobj.sd, "state"); if (!port_dev->state_kn) {
dev_err(&port_dev->dev, "failed to sysfs_get_dirent 'state'\n");
retval = -ENODEV; goto err_unregister;
}
/* Set default policy of port-poweroff disabled. */
retval = dev_pm_qos_add_request(&port_dev->dev, port_dev->req,
DEV_PM_QOS_FLAGS, PM_QOS_FLAG_NO_POWER_OFF); if (retval < 0) { goto err_put_kn;
}
retval = component_add(&port_dev->dev, &connector_ops); if (retval) {
dev_warn(&port_dev->dev, "failed to add component\n"); goto err_put_kn;
}
find_and_link_peer(hub, port1);
/* * Enable runtime pm and hold a refernce that hub_configure() * will drop once the PM_QOS_NO_POWER_OFF flag state has been set * and the hub has been fully registered (hdev->maxchild set).
*/
pm_runtime_set_active(&port_dev->dev);
pm_runtime_get_noresume(&port_dev->dev);
pm_runtime_enable(&port_dev->dev);
device_enable_async_suspend(&port_dev->dev);
/* * Keep hidden the ability to enable port-poweroff if the hub * does not support power switching.
*/ if (!hub_is_port_power_switchable(hub)) return 0;
/* Attempt to let userspace take over the policy. */
retval = dev_pm_qos_expose_flags(&port_dev->dev,
PM_QOS_FLAG_NO_POWER_OFF); if (retval < 0) {
dev_warn(&port_dev->dev, "failed to expose pm_qos_no_poweroff\n"); return 0;
}
/* Userspace owns the policy, drop the kernel 'no_poweroff' request. */
retval = dev_pm_qos_remove_request(port_dev->req); if (retval >= 0) {
kfree(port_dev->req);
port_dev->req = NULL;
} return 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.