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_endpoint() - Given an endpoint address, search for the endpoint's
226 n = intf->cur_altsetting->desc.bNumEndpoints; in usb_find_endpoint()
227 ep = intf->cur_altsetting->endpoint; in usb_find_endpoint()
228 for (; n > 0; (--n, ++ep)) { in usb_find_endpoint()
229 if (ep->desc.bEndpointAddress == ep_addr) in usb_find_endpoint()
236 * usb_check_bulk_endpoints - Check whether an interface's current altsetting
239 * @ep_addrs: 0-terminated array of the endpoint addresses (number and
253 if (!ep || !usb_endpoint_xfer_bulk(&ep->desc)) in usb_check_bulk_endpoints()
261 * usb_check_int_endpoints - Check whether an interface's current altsetting
264 * @ep_addrs: 0-terminated array of the endpoint addresses (number and
279 if (!ep || !usb_endpoint_xfer_int(&ep->desc)) in usb_check_int_endpoints()
287 * usb_find_alt_setting() - Given a configuration, find the alternate setting
307 for (i = 0; i < config->desc.bNumInterfaces; i++) { in usb_find_alt_setting()
308 if (config->intf_cache[i]->altsetting[0].desc.bInterfaceNumber in usb_find_alt_setting()
310 intf_cache = config->intf_cache[i]; in usb_find_alt_setting()
316 for (i = 0; i < intf_cache->num_altsetting; i++) in usb_find_alt_setting()
317 if (intf_cache->altsetting[i].desc.bAlternateSetting == alt_num) in usb_find_alt_setting()
318 return &intf_cache->altsetting[i]; in usb_find_alt_setting()
322 config->desc.bConfigurationValue); in usb_find_alt_setting()
328 * usb_ifnum_to_if - get the interface object with a given interface number
351 struct usb_host_config *config = dev->actconfig; in usb_ifnum_to_if()
356 for (i = 0; i < config->desc.bNumInterfaces; i++) in usb_ifnum_to_if()
357 if (config->interface[i]->altsetting[0] in usb_ifnum_to_if()
359 return config->interface[i]; in usb_ifnum_to_if()
366 * usb_altnum_to_altsetting - get the altsetting structure with a given alternate setting number.
390 for (i = 0; i < intf->num_altsetting; i++) { in usb_altnum_to_altsetting()
391 if (intf->altsetting[i].desc.bAlternateSetting == altnum) in usb_altnum_to_altsetting()
392 return &intf->altsetting[i]; in usb_altnum_to_altsetting()
411 if (dev->driver != arg->drv) in __find_interface()
414 return intf->minor == arg->minor; in __find_interface()
418 * usb_find_interface - find usb_interface pointer for driver and device
434 argb.drv = &drv->driver; in usb_find_interface()
458 return arg->fn(to_usb_device(dev), arg->data); in __each_dev()
462 * usb_for_each_dev - iterate over all USB devices in the system
479 * usb_release_dev - free a usb device structure when all users of it are finished.
491 hcd = bus_to_hcd(udev->bus); in usb_release_dev()
495 of_node_put(dev->of_node); in usb_release_dev()
497 kfree(udev->product); in usb_release_dev()
498 kfree(udev->manufacturer); in usb_release_dev()
499 kfree(udev->serial); in usb_release_dev()
509 if (add_uevent_var(env, "BUSNUM=%03d", usb_dev->bus->busnum)) in usb_dev_uevent()
510 return -ENOMEM; in usb_dev_uevent()
512 if (add_uevent_var(env, "DEVNUM=%03d", usb_dev->devnum)) in usb_dev_uevent()
513 return -ENOMEM; in usb_dev_uevent()
520 /* USB device Power-Management thunks.
592 usb_dev->bus->busnum, usb_dev->devnum); in usb_devnode()
609 if (!dev->parent) in usb_dev_authorized()
612 switch (hcd->dev_policy) { in usb_dev_authorized()
621 hub = usb_hub_to_struct_hub(dev->parent); in usb_dev_authorized()
622 return hub->ports[dev->portnum - 1]->connect_type == in usb_dev_authorized()
628 * usb_alloc_dev - usb device constructor (usbcore-internal)
631 * @port1: one-based index of port; ignored for root hubs
638 * This call may not be used in a non-sleeping context.
659 if (usb_hcd->driver->alloc_dev && parent && in usb_alloc_dev()
660 !usb_hcd->driver->alloc_dev(usb_hcd, dev)) { in usb_alloc_dev()
666 device_initialize(&dev->dev); in usb_alloc_dev()
667 dev->dev.bus = &usb_bus_type; in usb_alloc_dev()
668 dev->dev.type = &usb_device_type; in usb_alloc_dev()
669 dev->dev.groups = usb_device_groups; in usb_alloc_dev()
670 set_dev_node(&dev->dev, dev_to_node(bus->sysdev)); in usb_alloc_dev()
671 dev->state = USB_STATE_ATTACHED; in usb_alloc_dev()
672 dev->lpm_disable_count = 1; in usb_alloc_dev()
673 atomic_set(&dev->urbnum, 0); in usb_alloc_dev()
675 INIT_LIST_HEAD(&dev->ep0.urb_list); in usb_alloc_dev()
676 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE; in usb_alloc_dev()
677 dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT; in usb_alloc_dev()
679 usb_enable_endpoint(dev, &dev->ep0, false); in usb_alloc_dev()
680 dev->can_submit = 1; in usb_alloc_dev()
685 * dev->devpath will be stable until USB is re-cabled, and hubs in usb_alloc_dev()
687 * as stable: bus->busnum changes easily from modprobe order, in usb_alloc_dev()
691 dev->devpath[0] = '0'; in usb_alloc_dev()
692 dev->route = 0; in usb_alloc_dev()
694 dev->dev.parent = bus->controller; in usb_alloc_dev()
695 device_set_of_node_from_dev(&dev->dev, bus->sysdev); in usb_alloc_dev()
696 dev_set_name(&dev->dev, "usb%d", bus->busnum); in usb_alloc_dev()
698 /* match any labeling on the hubs; it's one-based */ in usb_alloc_dev()
699 if (parent->devpath[0] == '0') { in usb_alloc_dev()
700 snprintf(dev->devpath, sizeof dev->devpath, in usb_alloc_dev()
703 dev->route = 0; in usb_alloc_dev()
705 snprintf(dev->devpath, sizeof dev->devpath, in usb_alloc_dev()
706 "%s.%d", parent->devpath, port1); in usb_alloc_dev()
709 dev->route = parent->route + in usb_alloc_dev()
710 (port1 << ((parent->level - 1)*4)); in usb_alloc_dev()
712 dev->route = parent->route + in usb_alloc_dev()
713 (15 << ((parent->level - 1)*4)); in usb_alloc_dev()
716 dev->dev.parent = &parent->dev; in usb_alloc_dev()
717 dev_set_name(&dev->dev, "%d-%s", bus->busnum, dev->devpath); in usb_alloc_dev()
719 if (!parent->parent) { in usb_alloc_dev()
724 dev->dev.of_node = usb_of_get_device_node(parent, raw_port); in usb_alloc_dev()
729 dev->portnum = port1; in usb_alloc_dev()
730 dev->bus = bus; in usb_alloc_dev()
731 dev->parent = parent; in usb_alloc_dev()
732 INIT_LIST_HEAD(&dev->filelist); in usb_alloc_dev()
735 pm_runtime_set_autosuspend_delay(&dev->dev, in usb_alloc_dev()
737 dev->connect_time = jiffies; in usb_alloc_dev()
738 dev->active_duration = -jiffies; in usb_alloc_dev()
741 dev->authorized = usb_dev_authorized(dev, usb_hcd); in usb_alloc_dev()
747 * usb_get_dev - increments the reference count of the usb device structure
765 get_device(&dev->dev); in usb_get_dev()
771 * usb_put_dev - release a use of the usb device structure
780 put_device(&dev->dev); in usb_put_dev()
785 * usb_get_intf - increments the reference count of the usb interface structure
803 get_device(&intf->dev); in usb_get_intf()
809 * usb_put_intf - release a use of the usb interface structure
819 put_device(&intf->dev); in usb_put_intf()
824 * usb_intf_get_dma_device - acquire a reference on the usb interface's DMA endpoint
842 if (!udev->bus) in usb_intf_get_dma_device()
845 dmadev = get_device(udev->bus->sysdev); in usb_intf_get_dma_device()
846 if (!dmadev || !dmadev->dma_mask) { in usb_intf_get_dma_device()
863 * time. Only hub-aware drivers that are part of usbcore ever have to
872 * usb_lock_device_for_reset - cautiously acquire the lock for a usb device structure
880 * disconnect; in some drivers (such as usb-storage) the disconnect()
890 if (udev->state == USB_STATE_NOTATTACHED) in usb_lock_device_for_reset()
891 return -ENODEV; in usb_lock_device_for_reset()
892 if (udev->state == USB_STATE_SUSPENDED) in usb_lock_device_for_reset()
893 return -EHOSTUNREACH; in usb_lock_device_for_reset()
894 if (iface && (iface->condition == USB_INTERFACE_UNBINDING || in usb_lock_device_for_reset()
895 iface->condition == USB_INTERFACE_UNBOUND)) in usb_lock_device_for_reset()
896 return -EINTR; in usb_lock_device_for_reset()
903 return -EBUSY; in usb_lock_device_for_reset()
906 if (udev->state == USB_STATE_NOTATTACHED) in usb_lock_device_for_reset()
907 return -ENODEV; in usb_lock_device_for_reset()
908 if (udev->state == USB_STATE_SUSPENDED) in usb_lock_device_for_reset()
909 return -EHOSTUNREACH; in usb_lock_device_for_reset()
910 if (iface && (iface->condition == USB_INTERFACE_UNBINDING || in usb_lock_device_for_reset()
911 iface->condition == USB_INTERFACE_UNBOUND)) in usb_lock_device_for_reset()
912 return -EINTR; in usb_lock_device_for_reset()
919 * usb_get_current_frame_number - return current bus frame number
938 /*-------------------------------------------------------------------*/
952 if (header->bLength < 2 || header->bLength > size) { in __usb_get_extra_descriptor()
956 header->bDescriptorType, in __usb_get_extra_descriptor()
957 header->bLength); in __usb_get_extra_descriptor()
958 return -1; in __usb_get_extra_descriptor()
961 if (header->bDescriptorType == type && header->bLength >= minsize) { in __usb_get_extra_descriptor()
966 buffer += header->bLength; in __usb_get_extra_descriptor()
967 size -= header->bLength; in __usb_get_extra_descriptor()
969 return -1; in __usb_get_extra_descriptor()
974 * usb_alloc_coherent - allocate dma-consistent buffer for URB_NO_xxx_DMA_MAP
981 * cpu-space pointer to a buffer that may be used to perform DMA to the
982 * specified device. Such cpu-space buffers are returned along with the DMA
986 * These buffers are used with URB_NO_xxx_DMA_MAP set in urb->transfer_flags
991 * architectures where CPU caches are not DMA-coherent. On systems without
992 * bus-snooping caches, these buffers are uncached.
999 if (!dev || !dev->bus) in usb_alloc_coherent()
1001 return hcd_buffer_alloc(dev->bus, size, mem_flags, dma); in usb_alloc_coherent()
1006 * usb_free_coherent - free memory allocated with usb_alloc_coherent()
1019 if (!dev || !dev->bus) in usb_free_coherent()
1023 hcd_buffer_free(dev->bus, size, addr, dma); in usb_free_coherent()
1037 if (dev->type == &usb_device_type) in usb_bus_notify()
1039 else if (dev->type == &usb_if_device_type) in usb_bus_notify()
1044 if (dev->type == &usb_device_type) in usb_bus_notify()
1046 else if (dev->type == &usb_if_device_type) in usb_bus_notify()
1153 MODULE_DESCRIPTION("USB core host-side support");