Lines Matching +full:autosuspend +full:- +full:delay

1 // SPDX-License-Identifier: GPL-2.0
6 * (C) Copyright Johannes Erdfelt 1999-2001
11 * (C) Copyright David Brownell 2000-2004
14 * (C) Copyright Greg Kroah-Hartman 2002-2003
46 #include <linux/dma-mapping.h>
66 /* Default delay value, in seconds */
68 module_param_named(autosuspend, usb_autosuspend_delay, int, 0644);
69 MODULE_PARM_DESC(autosuspend, "default autosuspend delay");
119 * usb_find_common_endpoints() -- look up common endpoint descriptors
126 * Search the alternate setting's endpoint descriptors for the first bulk-in,
127 * bulk-out, interrupt-in and interrupt-out endpoints and return them in the
133 * Return: Zero if all requested descriptors were found, or -ENXIO otherwise.
153 for (i = 0; i < alt->desc.bNumEndpoints; ++i) { in usb_find_common_endpoints()
154 epd = &alt->endpoint[i].desc; in usb_find_common_endpoints()
160 return -ENXIO; in usb_find_common_endpoints()
165 * usb_find_common_endpoints_reverse() -- look up common endpoint descriptors
172 * Search the alternate setting's endpoint descriptors for the last bulk-in,
173 * bulk-out, interrupt-in and interrupt-out endpoints and return them in the
179 * Return: Zero if all requested descriptors were found, or -ENXIO otherwise.
199 for (i = alt->desc.bNumEndpoints - 1; i >= 0; --i) { in usb_find_common_endpoints_reverse()
200 epd = &alt->endpoint[i].desc; in usb_find_common_endpoints_reverse()
206 return -ENXIO; in usb_find_common_endpoints_reverse()
211 * usb_find_alt_setting() - Given a configuration, find the alternate setting
231 for (i = 0; i < config->desc.bNumInterfaces; i++) { in usb_find_alt_setting()
232 if (config->intf_cache[i]->altsetting[0].desc.bInterfaceNumber in usb_find_alt_setting()
234 intf_cache = config->intf_cache[i]; in usb_find_alt_setting()
240 for (i = 0; i < intf_cache->num_altsetting; i++) in usb_find_alt_setting()
241 if (intf_cache->altsetting[i].desc.bAlternateSetting == alt_num) in usb_find_alt_setting()
242 return &intf_cache->altsetting[i]; in usb_find_alt_setting()
246 config->desc.bConfigurationValue); in usb_find_alt_setting()
252 * usb_ifnum_to_if - get the interface object with a given interface number
275 struct usb_host_config *config = dev->actconfig; in usb_ifnum_to_if()
280 for (i = 0; i < config->desc.bNumInterfaces; i++) in usb_ifnum_to_if()
281 if (config->interface[i]->altsetting[0] in usb_ifnum_to_if()
283 return config->interface[i]; in usb_ifnum_to_if()
290 * usb_altnum_to_altsetting - get the altsetting structure with a given alternate setting number.
314 for (i = 0; i < intf->num_altsetting; i++) { in usb_altnum_to_altsetting()
315 if (intf->altsetting[i].desc.bAlternateSetting == altnum) in usb_altnum_to_altsetting()
316 return &intf->altsetting[i]; in usb_altnum_to_altsetting()
335 if (dev->driver != arg->drv) in __find_interface()
338 return intf->minor == arg->minor; in __find_interface()
342 * usb_find_interface - find usb_interface pointer for driver and device
358 argb.drv = &drv->drvwrap.driver; in usb_find_interface()
382 return arg->fn(to_usb_device(dev), arg->data); in __each_dev()
386 * usb_for_each_dev - iterate over all USB devices in the system
403 * usb_release_dev - free a usb device structure when all users of it are finished.
415 hcd = bus_to_hcd(udev->bus); in usb_release_dev()
419 of_node_put(dev->of_node); in usb_release_dev()
421 kfree(udev->product); in usb_release_dev()
422 kfree(udev->manufacturer); in usb_release_dev()
423 kfree(udev->serial); in usb_release_dev()
433 if (add_uevent_var(env, "BUSNUM=%03d", usb_dev->bus->busnum)) in usb_dev_uevent()
434 return -ENOMEM; in usb_dev_uevent()
436 if (add_uevent_var(env, "DEVNUM=%03d", usb_dev->devnum)) in usb_dev_uevent()
437 return -ENOMEM; in usb_dev_uevent()
444 /* USB device Power-Management thunks.
516 usb_dev->bus->busnum, usb_dev->devnum); in usb_devnode()
534 return hcd->wireless; in usb_bus_is_wusb()
541 if (!dev->parent) in usb_dev_authorized()
544 switch (hcd->dev_policy) { in usb_dev_authorized()
553 hub = usb_hub_to_struct_hub(dev->parent); in usb_dev_authorized()
554 return hub->ports[dev->portnum - 1]->connect_type == in usb_dev_authorized()
560 * usb_alloc_dev - usb device constructor (usbcore-internal)
563 * @port1: one-based index of port; ignored for root hubs
569 * This call may not be used in a non-sleeping context.
591 if (usb_hcd->driver->alloc_dev && parent && in usb_alloc_dev()
592 !usb_hcd->driver->alloc_dev(usb_hcd, dev)) { in usb_alloc_dev()
598 device_initialize(&dev->dev); in usb_alloc_dev()
599 dev->dev.bus = &usb_bus_type; in usb_alloc_dev()
600 dev->dev.type = &usb_device_type; in usb_alloc_dev()
601 dev->dev.groups = usb_device_groups; in usb_alloc_dev()
602 set_dev_node(&dev->dev, dev_to_node(bus->sysdev)); in usb_alloc_dev()
603 dev->state = USB_STATE_ATTACHED; in usb_alloc_dev()
604 dev->lpm_disable_count = 1; in usb_alloc_dev()
605 atomic_set(&dev->urbnum, 0); in usb_alloc_dev()
607 INIT_LIST_HEAD(&dev->ep0.urb_list); in usb_alloc_dev()
608 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; in usb_alloc_dev()
609 dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; in usb_alloc_dev()
611 usb_enable_endpoint(dev, &dev->ep0, false); in usb_alloc_dev()
612 dev->can_submit = 1; in usb_alloc_dev()
617 * dev->devpath will be stable until USB is re-cabled, and hubs in usb_alloc_dev()
619 * as stable: bus->busnum changes easily from modprobe order, in usb_alloc_dev()
623 dev->devpath[0] = '0'; in usb_alloc_dev()
624 dev->route = 0; in usb_alloc_dev()
626 dev->dev.parent = bus->controller; in usb_alloc_dev()
627 device_set_of_node_from_dev(&dev->dev, bus->sysdev); in usb_alloc_dev()
628 dev_set_name(&dev->dev, "usb%d", bus->busnum); in usb_alloc_dev()
631 /* match any labeling on the hubs; it's one-based */ in usb_alloc_dev()
632 if (parent->devpath[0] == '0') { in usb_alloc_dev()
633 snprintf(dev->devpath, sizeof dev->devpath, in usb_alloc_dev()
636 dev->route = 0; in usb_alloc_dev()
638 snprintf(dev->devpath, sizeof dev->devpath, in usb_alloc_dev()
639 "%s.%d", parent->devpath, port1); in usb_alloc_dev()
642 dev->route = parent->route + in usb_alloc_dev()
643 (port1 << ((parent->level - 1)*4)); in usb_alloc_dev()
645 dev->route = parent->route + in usb_alloc_dev()
646 (15 << ((parent->level - 1)*4)); in usb_alloc_dev()
649 dev->dev.parent = &parent->dev; in usb_alloc_dev()
650 dev_set_name(&dev->dev, "%d-%s", bus->busnum, dev->devpath); in usb_alloc_dev()
652 if (!parent->parent) { in usb_alloc_dev()
657 dev->dev.of_node = usb_of_get_device_node(parent, raw_port); in usb_alloc_dev()
662 dev->portnum = port1; in usb_alloc_dev()
663 dev->bus = bus; in usb_alloc_dev()
664 dev->parent = parent; in usb_alloc_dev()
665 INIT_LIST_HEAD(&dev->filelist); in usb_alloc_dev()
668 pm_runtime_set_autosuspend_delay(&dev->dev, in usb_alloc_dev()
670 dev->connect_time = jiffies; in usb_alloc_dev()
671 dev->active_duration = -jiffies; in usb_alloc_dev()
674 dev->authorized = usb_dev_authorized(dev, usb_hcd); in usb_alloc_dev()
676 dev->wusb = usb_bus_is_wusb(bus) ? 1 : 0; in usb_alloc_dev()
683 * usb_get_dev - increments the reference count of the usb device structure
697 get_device(&dev->dev); in usb_get_dev()
703 * usb_put_dev - release a use of the usb device structure
712 put_device(&dev->dev); in usb_put_dev()
717 * usb_get_intf - increments the reference count of the usb interface structure
731 get_device(&intf->dev); in usb_get_intf()
737 * usb_put_intf - release a use of the usb interface structure
747 put_device(&intf->dev); in usb_put_intf()
759 * time. Only hub-aware drivers that are part of usbcore ever have to
768 * usb_lock_device_for_reset - cautiously acquire the lock for a usb device structure
776 * disconnect; in some drivers (such as usb-storage) the disconnect()
786 if (udev->state == USB_STATE_NOTATTACHED) in usb_lock_device_for_reset()
787 return -ENODEV; in usb_lock_device_for_reset()
788 if (udev->state == USB_STATE_SUSPENDED) in usb_lock_device_for_reset()
789 return -EHOSTUNREACH; in usb_lock_device_for_reset()
790 if (iface && (iface->condition == USB_INTERFACE_UNBINDING || in usb_lock_device_for_reset()
791 iface->condition == USB_INTERFACE_UNBOUND)) in usb_lock_device_for_reset()
792 return -EINTR; in usb_lock_device_for_reset()
799 return -EBUSY; in usb_lock_device_for_reset()
802 if (udev->state == USB_STATE_NOTATTACHED) in usb_lock_device_for_reset()
803 return -ENODEV; in usb_lock_device_for_reset()
804 if (udev->state == USB_STATE_SUSPENDED) in usb_lock_device_for_reset()
805 return -EHOSTUNREACH; in usb_lock_device_for_reset()
806 if (iface && (iface->condition == USB_INTERFACE_UNBINDING || in usb_lock_device_for_reset()
807 iface->condition == USB_INTERFACE_UNBOUND)) in usb_lock_device_for_reset()
808 return -EINTR; in usb_lock_device_for_reset()
815 * usb_get_current_frame_number - return current bus frame number
834 /*-------------------------------------------------------------------*/
848 if (header->bLength < 2 || header->bLength > size) { in __usb_get_extra_descriptor()
852 header->bDescriptorType, in __usb_get_extra_descriptor()
853 header->bLength); in __usb_get_extra_descriptor()
854 return -1; in __usb_get_extra_descriptor()
857 if (header->bDescriptorType == type && header->bLength >= minsize) { in __usb_get_extra_descriptor()
862 buffer += header->bLength; in __usb_get_extra_descriptor()
863 size -= header->bLength; in __usb_get_extra_descriptor()
865 return -1; in __usb_get_extra_descriptor()
870 * usb_alloc_coherent - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP
877 * cpu-space pointer to a buffer that may be used to perform DMA to the
878 * specified device. Such cpu-space buffers are returned along with the DMA
882 * These buffers are used with URB_NO_xxx_DMA_MAP set in urb->transfer_flags
887 * architectures where CPU caches are not DMA-coherent. On systems without
888 * bus-snooping caches, these buffers are uncached.
895 if (!dev || !dev->bus) in usb_alloc_coherent()
897 return hcd_buffer_alloc(dev->bus, size, mem_flags, dma); in usb_alloc_coherent()
902 * usb_free_coherent - free memory allocated with usb_alloc_coherent()
915 if (!dev || !dev->bus) in usb_free_coherent()
919 hcd_buffer_free(dev->bus, size, addr, dma); in usb_free_coherent()
933 if (dev->type == &usb_device_type) in usb_bus_notify()
935 else if (dev->type == &usb_if_device_type) in usb_bus_notify()
940 if (dev->type == &usb_device_type) in usb_bus_notify()
942 else if (dev->type == &usb_if_device_type) in usb_bus_notify()