/* called from driver core with dev locked */ staticint usb_probe_device(struct device *dev)
{ struct usb_device_driver *udriver = to_usb_device_driver(dev->driver); struct usb_device *udev = to_usb_device(dev); int error = 0;
dev_dbg(dev, "%s\n", __func__);
/* TODO: Add real matching code */
/* The device should always appear to be in use *unlessthedriversupportsautosuspend.
*/ if (!udriver->supports_autosuspend)
error = usb_autoresume_device(udev); if (error) return error;
if (udriver->generic_subclass)
error = usb_generic_driver_probe(udev); if (error) return error;
/* Probe the USB device with the driver in hand, but only *defertoagenericdriverincasethecurrentUSB *devicedriverhasanid_tableoramatchfunction;i.e., *whenthedevicedriverwasexplicitlymatchedagainst *adevice. * *Ifthedevicedriverdoesnothaveeitherofthese, *thenweassumethatitcanbindtoanydeviceandis *nottrulyamorespecialized/non-genericdriver,soa *returnvalueof-ENODEVshouldnotforcethedevice *tobehandledbythegenericUSBdriver,asthere *canstillbeanother,morespecialized,devicedriver. * *Thisaccommodatestheusbipdriver. * *TODO:Whatif,inthefuture,therearemultiple *specializedUSBdevicedriversforaparticulardevice? *Insuchcases,thereisaneedtotryallmatching *specialiseddevicedriverspriortosettingthe *use_generic_driverbit.
*/ if (udriver->probe)
error = udriver->probe(udev); elseif (!udriver->generic_subclass)
error = -EINVAL; if (error == -ENODEV && udriver != &usb_generic_driver &&
(udriver->id_table || udriver->match)) {
udev->use_generic_driver = 1; return -EPROBE_DEFER;
} return error;
}
/* called from driver core with dev locked */ staticint usb_unbind_device(struct device *dev)
{ struct usb_device *udev = to_usb_device(dev); struct usb_device_driver *udriver = to_usb_device_driver(dev->driver);
if (udriver->disconnect)
udriver->disconnect(udev); if (udriver->generic_subclass)
usb_generic_driver_disconnect(udev); if (!udriver->supports_autosuspend)
usb_autosuspend_device(udev); return0;
}
/* called from driver core with dev locked */ staticint usb_probe_interface(struct device *dev)
{ struct usb_driver *driver = to_usb_driver(dev->driver); struct usb_interface *intf = to_usb_interface(dev); struct usb_device *udev = interface_to_usbdev(intf); conststruct usb_device_id *id; int error = -ENODEV; int lpm_disable_error = -ENODEV;
dev_dbg(dev, "%s\n", __func__);
intf->needs_binding = 0;
if (usb_device_is_owned(udev)) return error;
if (udev->authorized == 0) {
dev_err(&intf->dev, "Device is not authorized for usage\n"); return error;
} elseif (intf->authorized == 0) {
dev_err(&intf->dev, "Interface %d is not authorized for usage\n",
intf->altsetting->desc.bInterfaceNumber); return error;
}
id = usb_match_dynamic_id(intf, driver); if (!id)
id = usb_match_id(intf, driver->id_table); if (!id) return error;
dev_dbg(dev, "%s - got id\n", __func__);
error = usb_autoresume_device(udev); if (error) return error;
intf->condition = USB_INTERFACE_BINDING;
/* Probed interfaces are initially active. They are *runtime-PM-enabledonlyifthedriverhasautosuspendsupport. *Theyaresensitivetotheirchildren'spowerstates.
*/
pm_runtime_set_active(dev);
pm_suspend_ignore_children(dev, false); if (driver->supports_autosuspend)
pm_runtime_enable(dev);
/* If the new driver doesn't allow hub-initiated LPM, and we can't *disablehub-initiatedLPM,thenfailtheprobe. * *Otherwise,leavingLPMenabledshouldbeharmless,becausethe *endpointintervalsshouldremainthesame,andtheU1/U2timeouts *shouldremainthesame. * *Ifweneedtoinstallaltsetting0beforeprobe,oranotheralt *settingduringprobe,thatshouldalsobefine.usb_set_interface() *willattempttodisableLPM,andfailifitcan'tdisableit.
*/ if (driver->disable_hub_initiated_lpm) {
lpm_disable_error = usb_unlocked_disable_lpm(udev); if (lpm_disable_error) {
dev_err(&intf->dev, "%s Failed to disable LPM for driver %s\n",
__func__, driver->name);
error = lpm_disable_error; goto err;
}
}
/* Carry out a deferred switch to altsetting 0 */ if (intf->needs_altsetting0) {
error = usb_set_interface(udev, intf->altsetting[0].
desc.bInterfaceNumber, 0); if (error < 0) goto err;
intf->needs_altsetting0 = 0;
}
error = driver->probe(intf, id); if (error) goto err;
intf->condition = USB_INTERFACE_BOUND;
/* If the LPM disable succeeded, balance the ref counts. */ if (!lpm_disable_error)
usb_unlocked_enable_lpm(udev);
/* If the LPM disable succeeded, balance the ref counts. */ if (!lpm_disable_error)
usb_unlocked_enable_lpm(udev);
/* Unbound interfaces are always runtime-PM-disabled and -suspended */ if (driver->supports_autosuspend)
pm_runtime_disable(dev);
pm_runtime_set_suspended(dev);
usb_autosuspend_device(udev); return error;
}
/* called from driver core with dev locked */ staticint usb_unbind_interface(struct device *dev)
{ struct usb_driver *driver = to_usb_driver(dev->driver); struct usb_interface *intf = to_usb_interface(dev); struct usb_host_endpoint *ep, **eps = NULL; struct usb_device *udev; int i, j, error, r; int lpm_disable_error = -ENODEV;
/* If hub-initiated LPM policy may change, attempt to disable LPM until *thedriverisunbound.IfLPMisn'tdisabled,that'sfinebecauseit *wouldn'tbeenabledunlessalltheboundinterfacessupported *hub-initiatedLPM.
*/ if (driver->disable_hub_initiated_lpm)
lpm_disable_error = usb_unlocked_disable_lpm(udev);
/* Attempt to re-enable USB3 LPM, if the disable succeeded. */ if (!lpm_disable_error)
usb_unlocked_enable_lpm(udev);
/* Unbound interfaces are always runtime-PM-disabled and -suspended */ if (driver->supports_autosuspend)
pm_runtime_disable(dev);
pm_runtime_set_suspended(dev);
/* Claimed interfaces are initially inactive (suspended) and *runtime-PM-enabled,butonlyifthedriverhasautosuspend *support.Otherwisetheyaremarkedactive,topreventthe *devicefrombeingautosuspended,butleftdisabled.Ineither *casetheyaresensitivetotheirchildren'spowerstates.
*/
pm_suspend_ignore_children(dev, false); if (driver->supports_autosuspend)
pm_runtime_enable(dev); else
pm_runtime_set_active(dev);
/* if interface was already added, bind now; else let *thefuturedevice_add()bindit,bypassingprobe()
*/ if (device_is_registered(dev))
retval = device_bind_driver(dev);
/* this should never happen, don't release something that's not ours */ if (!dev->driver || dev->driver != &driver->driver) return;
/* don't release from within disconnect() */ if (iface->condition != USB_INTERFACE_BOUND) return;
iface->condition = USB_INTERFACE_UNBINDING;
/* Release via the driver core only if the interface *hasalreadybeenregistered
*/ if (device_is_registered(dev)) {
device_release_driver(dev);
} else {
device_lock(dev);
usb_unbind_interface(dev);
dev->driver = NULL;
device_unlock(dev);
}
}
EXPORT_SYMBOL_GPL(usb_driver_release_interface);
/* returns 0 if no match, 1 if match */ int usb_match_device(struct usb_device *dev, conststruct usb_device_id *id)
{ if ((id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
id->idVendor != le16_to_cpu(dev->descriptor.idVendor)) return0;
if ((id->match_flags & USB_DEVICE_ID_MATCH_PRODUCT) &&
id->idProduct != le16_to_cpu(dev->descriptor.idProduct)) return0;
/* No need to test id->bcdDevice_lo != 0, since 0 is never
greater than any unsigned number. */ if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO) &&
(id->bcdDevice_lo > le16_to_cpu(dev->descriptor.bcdDevice))) return0;
if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI) &&
(id->bcdDevice_hi < le16_to_cpu(dev->descriptor.bcdDevice))) return0;
if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_CLASS) &&
(id->bDeviceClass != dev->descriptor.bDeviceClass)) return0;
if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_SUBCLASS) &&
(id->bDeviceSubClass != dev->descriptor.bDeviceSubClass)) return0;
if ((id->match_flags & USB_DEVICE_ID_MATCH_DEV_PROTOCOL) &&
(id->bDeviceProtocol != dev->descriptor.bDeviceProtocol)) return0;
return1;
}
/* returns 0 if no match, 1 if match */ int usb_match_one_id_intf(struct usb_device *dev, struct usb_host_interface *intf, conststruct usb_device_id *id)
{ /* The interface class, subclass, protocol and number should never be *checkedforamatchifthedeviceclassisVendorSpecific,
* unless the match record specifies the Vendor ID. */ if (dev->descriptor.bDeviceClass == USB_CLASS_VENDOR_SPEC &&
!(id->match_flags & USB_DEVICE_ID_MATCH_VENDOR) &&
(id->match_flags & (USB_DEVICE_ID_MATCH_INT_CLASS |
USB_DEVICE_ID_MATCH_INT_SUBCLASS |
USB_DEVICE_ID_MATCH_INT_PROTOCOL |
USB_DEVICE_ID_MATCH_INT_NUMBER))) return0;
if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_CLASS) &&
(id->bInterfaceClass != intf->desc.bInterfaceClass)) return0;
if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_SUBCLASS) &&
(id->bInterfaceSubClass != intf->desc.bInterfaceSubClass)) return0;
if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_PROTOCOL) &&
(id->bInterfaceProtocol != intf->desc.bInterfaceProtocol)) return0;
if ((id->match_flags & USB_DEVICE_ID_MATCH_INT_NUMBER) &&
(id->bInterfaceNumber != intf->desc.bInterfaceNumber)) return0;
return1;
}
/* returns 0 if no match, 1 if match */ int usb_match_one_id(struct usb_interface *interface, conststruct usb_device_id *id)
{ struct usb_host_interface *intf; struct usb_device *dev;
/* proc_connectinfo in devio.c may call us with id == NULL. */ if (id == NULL) return0;
intf = interface->cur_altsetting;
dev = interface_to_usbdev(interface);
/* It is important to check that id->driver_info is nonzero, sinceanentrythatisallzeroesexceptforanonzero id->driver_infoisthewaytocreateanentrythat indicatesthatthedriverwanttoexamineevery
device and interface. */ for (; id->idVendor || id->idProduct || id->bDeviceClass ||
id->bInterfaceClass || id->driver_info; id++) { if (usb_match_one_id(interface, id)) return id;
}
/* If the device driver under consideration does not have a *id_tableoramatchfunction,thenletthedriver'sprobe *functiondecide.
*/ if (!udrv->id_table && !udrv->match) return1;
if (usb_dev->devnum < 0) { /* driver is often null here; dev_dbg() would oops */
pr_debug("usb %s: already deleted?\n", dev_name(dev)); return -ENODEV;
} if (!usb_dev->bus) {
pr_debug("usb %s: bus removed?\n", dev_name(dev)); return -ENODEV;
}
/* per-device configurations are common */ if (add_uevent_var(env, "PRODUCT=%x/%x/%x",
le16_to_cpu(usb_dev->descriptor.idVendor),
le16_to_cpu(usb_dev->descriptor.idProduct),
le16_to_cpu(usb_dev->descriptor.bcdDevice))) return -ENOMEM;
/* Forced unbinding of a USB interface driver, either because *itdoesn'tsupportpre_reset/post_reset/reset_resumeor *becauseitdoesn'tsupportsuspend/resume. * *Thecallermusthold@intf'sdevice'slock,butnot@intf'slock.
*/ void usb_forced_unbind_intf(struct usb_interface *intf)
{ struct usb_driver *driver = to_usb_driver(intf->dev.driver);
config = udev->actconfig; if (config) { for (i = 0; i < config->desc.bNumInterfaces; ++i) {
intf = config->interface[i]; if (intf->dev.driver && intf->needs_binding)
usb_forced_unbind_intf(intf);
}
}
}
/* Delayed forced unbinding of a USB interface driver and scan *forrebinding. * *Thecallermusthold@intf'sdevice'slock,butnot@intf'slock. * *Note:Rebindswillbeskippedifasystemsleeptransitionisin *progressandthePM"complete"callbackhasn'toccurredyet.
*/ staticvoid usb_rebind_intf(struct usb_interface *intf)
{ int rc;
/* Delayed unbind of an existing driver */ if (intf->dev.driver)
usb_forced_unbind_intf(intf);
/* Try to rebind the interface */ if (!intf->dev.power.is_prepared) {
intf->needs_binding = 0;
rc = device_attach(&intf->dev); if (rc < 0 && rc != -EPROBE_DEFER)
dev_warn(&intf->dev, "rebind failed: %d\n", rc);
}
}
config = udev->actconfig; if (config) { for (i = 0; i < config->desc.bNumInterfaces; ++i) {
intf = config->interface[i]; if (intf->needs_binding)
usb_rebind_intf(intf);
}
}
}
/* Unbind drivers for @udev's interfaces that don't support suspend/resume *Thereisnocheckforreset_resumeherebecauseitcanbedetermined *onlyduringresumewhetherreset_resumeisneeded. * *Thecallermusthold@udev'sdevicelock.
*/ staticvoid unbind_no_pm_drivers_interfaces(struct usb_device *udev)
{ struct usb_host_config *config; int i; struct usb_interface *intf; struct usb_driver *drv;
config = udev->actconfig; if (config) { for (i = 0; i < config->desc.bNumInterfaces; ++i) {
intf = config->interface[i];
if (intf->dev.driver) {
drv = to_usb_driver(intf->dev.driver); if (!drv->suspend || !drv->resume)
usb_forced_unbind_intf(intf);
}
}
}
}
staticint usb_suspend_device(struct usb_device *udev, pm_message_t msg)
{ struct usb_device_driver *udriver; int status = 0;
if (udev->state == USB_STATE_NOTATTACHED ||
udev->state == USB_STATE_SUSPENDED) goto done;
/* For devices that don't have a driver, we do a generic suspend. */ if (udev->dev.driver)
udriver = to_usb_device_driver(udev->dev.driver); else {
udev->do_remote_wakeup = 0;
udriver = &usb_generic_driver;
} if (udriver->suspend)
status = udriver->suspend(udev, msg); if (status == 0 && udriver->generic_subclass)
status = usb_generic_driver_suspend(udev, msg);
done:
dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); return status;
}
staticint usb_resume_device(struct usb_device *udev, pm_message_t msg)
{ struct usb_device_driver *udriver; int status = 0;
if (udev->state == USB_STATE_NOTATTACHED) goto done;
/* Can't resume it if it doesn't have a driver. */ if (udev->dev.driver == NULL) {
status = -ENOTCONN; goto done;
}
/* Non-root devices on a full/low-speed bus must wait for their *companionhigh-speedroothub,incaseahandoffisneeded.
*/ if (!PMSG_IS_AUTO(msg) && udev->parent && udev->bus->hs_companion)
device_pm_wait_for_dev(&udev->dev,
&udev->bus->hs_companion->root_hub->dev);
if (udev->quirks & USB_QUIRK_RESET_RESUME)
udev->reset_resume = 1;
udriver = to_usb_device_driver(udev->dev.driver); if (udriver->generic_subclass)
status = usb_generic_driver_resume(udev, msg); if (status == 0 && udriver->resume)
status = udriver->resume(udev, msg);
done:
dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); return status;
}
staticint usb_suspend_interface(struct usb_device *udev, struct usb_interface *intf, pm_message_t msg)
{ struct usb_driver *driver; int status = 0;
/* at this time we know the driver supports suspend */
status = driver->suspend(intf, msg); if (status && !PMSG_IS_AUTO(msg))
dev_err(&intf->dev, "suspend error %d\n", status);
done:
dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status); return status;
}
staticint usb_resume_interface(struct usb_device *udev, struct usb_interface *intf, pm_message_t msg, int reset_resume)
{ struct usb_driver *driver; int status = 0;
if (udev->state == USB_STATE_NOTATTACHED) goto done;
/* Don't let autoresume interfere with unbinding */ if (intf->condition == USB_INTERFACE_UNBINDING) goto done;
/* Can't resume it if it doesn't have a driver. */ if (intf->condition == USB_INTERFACE_UNBOUND) {
/* Carry out a deferred switch to altsetting 0 */ if (intf->needs_altsetting0 && !intf->dev.power.is_prepared) {
usb_set_interface(udev, intf->altsetting[0].
desc.bInterfaceNumber, 0);
intf->needs_altsetting0 = 0;
} goto done;
}
/* Don't resume if the interface is marked for rebinding */ if (intf->needs_binding) goto done;
driver = to_usb_driver(intf->dev.driver);
if (reset_resume) { if (driver->reset_resume) {
status = driver->reset_resume(intf); if (status)
dev_err(&intf->dev, "%s error %d\n", "reset_resume", status);
} else {
intf->needs_binding = 1;
dev_dbg(&intf->dev, "no reset_resume for driver %s?\n",
driver->name);
}
} else {
status = driver->resume(intf); if (status)
dev_err(&intf->dev, "resume error %d\n", status);
}
done:
dev_vdbg(&intf->dev, "%s: status %d\n", __func__, status);
/* Later we will unbind the driver and/or reprobe, if necessary */ return status;
}
/** *usb_suspend_both-suspendaUSBdeviceanditsinterfaces *@udev:theusb_devicetosuspend *@msg:PowerManagementmessagedescribingthisstatetransition * *ThisisthecentralroutineforsuspendingUSBdevices.Itcallsthe *suspendmethodsforalltheinterfacedriversin@udevandthencalls *thesuspendmethodfor@udevitself.Whentheroutineiscalledin *autosuspend,ifanerroroccursatanystage,alltheinterfaces *whichweresuspendedareresumedsothattheyremaininthesame *stateasthedevice,butwhencalledfromsystemsleep,allerror *fromsuspendmethodsofinterfacesandthenon-root-hubdeviceitself *aresimplyignored,soallsuspendedinterfacesareonlyresumed *tothedevice'sstatewhen@udevisroot-hubanditssuspendmethod *returnsfailure. * *Autosuspendrequestsoriginatingfromachilddeviceoraninterface *drivermaybemadewithouttheprotectionof@udev'sdevicelock,but *allothersuspendcallswillholdthelock.Usbcorewillinsurethat *methodcallsdonotarriveduringbind,unbind,orresetoperations. *Howeverdriversmustbepreparedtohandlesuspendcallsarrivingat *unpredictabletimes. * *Thisroutinecanrunonlyinprocesscontext. * *Return:0ifthesuspendsucceeded.
*/ staticint usb_suspend_both(struct usb_device *udev, pm_message_t msg)
{ int status = 0; int i = 0, n = 0; struct usb_interface *intf;
if (udev->state == USB_STATE_NOTATTACHED ||
udev->state == USB_STATE_SUSPENDED) goto done;
/* Suspend all the interfaces and then udev itself */ if (udev->actconfig) {
n = udev->actconfig->desc.bNumInterfaces; for (i = n - 1; i >= 0; --i) {
intf = udev->actconfig->interface[i];
status = usb_suspend_interface(udev, intf, msg);
/* Ignore errors during system sleep transitions */ if (!PMSG_IS_AUTO(msg))
status = 0; if (status != 0) break;
}
} if (status == 0) {
status = usb_suspend_device(udev, msg);
/* *Ignoreerrorsfromnon-root-hubdevicesduring *systemsleeptransitions.Forthemostpart, *thesedevicesshouldgotolowpoweranywaywhen *theentirebusissuspended.
*/ if (udev->parent && !PMSG_IS_AUTO(msg))
status = 0;
/* *Ifthedeviceisinaccessible,don'ttrytoresume *suspendedinterfacesandjustreturntheerror.
*/ if (status && status != -EBUSY) { int err;
u16 devstat;
/* If the suspend failed, resume interfaces that did get suspended */ if (status != 0) { if (udev->actconfig) {
msg.event ^= (PM_EVENT_SUSPEND | PM_EVENT_RESUME); while (++i < n) {
intf = udev->actconfig->interface[i];
usb_resume_interface(udev, intf, msg, 0);
}
}
/* If the suspend succeeded then prevent any more URB submissions *andflushanyoutstandingURBs.
*/
} else {
udev->can_submit = 0; for (i = 0; i < 16; ++i) {
usb_hcd_flush_endpoint(udev, udev->ep_out[i]);
usb_hcd_flush_endpoint(udev, udev->ep_in[i]);
}
}
done:
dev_vdbg(&udev->dev, "%s: status %d\n", __func__, status); return status;
}
/* *Ifthedeviceisautosuspendedwiththewrongwakeupsetting, *autoresumenowsothesettingcanbechanged.
*/ if (udev->state == USB_STATE_SUSPENDED && w != udev->do_remote_wakeup)
pm_runtime_resume(&udev->dev);
udev->do_remote_wakeup = w;
}
/* The device lock is held by the PM core */ int usb_suspend(struct device *dev, pm_message_t msg)
{ struct usb_device *udev = to_usb_device(dev); int r;
unbind_no_pm_drivers_interfaces(udev);
/* From now on we are sure all drivers support suspend/resume *butnotnecessarilyreset_resume() *sowemaystillneedtounbindandrebinduponresume
*/
choose_wakeup(udev, msg);
r = usb_suspend_both(udev, msg); if (r) return r;
if (udev->quirks & USB_QUIRK_DISCONNECT_SUSPEND)
usb_port_disable(udev);
return0;
}
/* The device lock is held by the PM core */ int usb_resume_complete(struct device *dev)
{ struct usb_device *udev = to_usb_device(dev);
/* For PM complete calls, all we do is rebind interfaces *whoseneeds_bindingflagisset
*/ if (udev->state != USB_STATE_NOTATTACHED)
rebind_marked_interfaces(udev); return0;
}
/* The device lock is held by the PM core */ int usb_resume(struct device *dev, pm_message_t msg)
{ struct usb_device *udev = to_usb_device(dev); int status;
/* For all calls, take the device back to full power and *tellthePMcoreincaseitwasautosuspendedpreviously. *Unbindtheinterfacesthatwillneedrebindinglater, *becausetheyfailtosupportreset_resume. *(Thiscan'tbedoneinusb_resume_interface() *abovebecauseitdoesn'towntherightsetoflocks.)
*/
status = usb_resume_both(udev, msg); if (status == 0) {
pm_runtime_disable(dev);
pm_runtime_set_active(dev);
pm_runtime_enable(dev);
unbind_marked_interfaces(udev);
}
/* Avoid PM error messages for devices disconnected while suspended *aswe'lldisplayregulardisconnectmessagesjustabitlater.
*/ if (status == -ENODEV || status == -ESHUTDOWN)
status = 0; return status;
}
/* Internal routine to check whether we may autosuspend a device. */ staticint autosuspend_check(struct usb_device *udev)
{ int w, i; struct usb_interface *intf;
if (udev->state == USB_STATE_NOTATTACHED) return -ENODEV;
/* Fail if autosuspend is disabled, or any interfaces are in use, or *anyinterfacedriversrequireremotewakeupbutitisn'tavailable.
*/
w = 0; if (udev->actconfig) { for (i = 0; i < udev->actconfig->desc.bNumInterfaces; i++) {
intf = udev->actconfig->interface[i];
/* We don't need to check interfaces that are *disabledforruntimePM.Eithertheyareunbound *orelsetheirdriversdon'tsupportautosuspend *andsotheyarepermanentlyactive.
*/ if (intf->dev.power.disable_depth) continue; if (atomic_read(&intf->dev.power.usage_count) > 0) return -EBUSY;
w |= intf->needs_remote_wakeup;
/* Don't allow autosuspend if the device will need *areset-resumeandanyofitsinterfacedrivers *doesn'tincludesupportorneedsremotewakeup.
*/ if (udev->quirks & USB_QUIRK_RESET_RESUME) { struct usb_driver *driver;
driver = to_usb_driver(intf->dev.driver); if (!driver->reset_resume ||
intf->needs_remote_wakeup) return -EOPNOTSUPP;
}
}
} if (w && !device_can_wakeup(&udev->dev)) {
dev_dbg(&udev->dev, "remote wakeup needed for autosuspend\n"); return -EOPNOTSUPP;
}
int usb_runtime_suspend(struct device *dev)
{ struct usb_device *udev = to_usb_device(dev); int status;
/* A USB device can be suspended if it passes the various autosuspend *checks.RuntimesuspendforaUSBdevicemeanssuspendingallthe *interfacesandthenthedeviceitself.
*/ if (autosuspend_check(udev) != 0) return -EAGAIN;
status = usb_suspend_both(udev, PMSG_AUTO_SUSPEND);
/* Allow a retry if autosuspend failed temporarily */ if (status == -EAGAIN || status == -EBUSY)
usb_mark_last_busy(udev);
int usb_runtime_resume(struct device *dev)
{ struct usb_device *udev = to_usb_device(dev); int status;
/* Runtime resume for a USB device means resuming both the device *andallitsinterfaces.
*/
status = usb_resume_both(udev, PMSG_AUTO_RESUME); return status;
}
int usb_runtime_idle(struct device *dev)
{ struct usb_device *udev = to_usb_device(dev);
/* An idle USB device can be suspended if it passes the various *autosuspendchecks.
*/ if (autosuspend_check(udev) == 0)
pm_runtime_autosuspend(dev); /* Tell the core not to suspend it, though. */ return -EBUSY;
}
staticint usb_set_usb2_hardware_lpm(struct usb_device *udev, int enable)
{ struct usb_hcd *hcd = bus_to_hcd(udev->bus); int ret = -EPERM;
if (hcd->driver->set_usb2_hw_lpm) {
ret = hcd->driver->set_usb2_hw_lpm(hcd, udev, enable); if (!ret)
udev->usb2_hw_lpm_enabled = enable;
}
return ret;
}
int usb_enable_usb2_hardware_lpm(struct usb_device *udev)
{ if (!udev->usb2_hw_lpm_capable ||
!udev->usb2_hw_lpm_allowed ||
udev->usb2_hw_lpm_enabled) return0;
return usb_set_usb2_hardware_lpm(udev, 1);
}
int usb_disable_usb2_hardware_lpm(struct usb_device *udev)
{ if (!udev->usb2_hw_lpm_enabled) return0;
¤ 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.0.69Bemerkung:
(vorverarbeitet am 2026-09-28)
¤
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.