24 #include <linux/module.h>
26 #include <linux/string.h>
27 #include <linux/bitops.h>
28 #include <linux/slab.h>
33 #include <linux/errno.h>
52 #ifdef CONFIG_USB_SUSPEND
59 #define usb_autosuspend_delay 0
73 struct usb_host_config *
config,
77 struct usb_interface_cache *intf_cache =
NULL;
80 for (i = 0; i < config->desc.bNumInterfaces; i++) {
81 if (config->intf_cache[i]->altsetting[0].desc.bInterfaceNumber
83 intf_cache = config->intf_cache[
i];
89 for (i = 0; i < intf_cache->num_altsetting; i++)
90 if (intf_cache->altsetting[i].desc.bAlternateSetting == alt_num)
91 return &intf_cache->altsetting[
i];
94 "config %u\n", alt_num, iface_num,
95 config->desc.bConfigurationValue);
122 struct usb_host_config *
config = dev->actconfig;
127 for (i = 0; i < config->desc.bNumInterfaces; i++)
128 if (config->interface[i]->altsetting[0]
129 .desc.bInterfaceNumber == ifnum)
130 return config->interface[
i];
159 for (i = 0; i < intf->num_altsetting; i++) {
160 if (intf->altsetting[i].desc.bAlternateSetting == altnum)
161 return &intf->altsetting[
i];
177 if (!is_usb_interface(dev))
182 intf = to_usb_interface(dev);
183 return intf->minor == arg->
minor;
201 argb.
drv = &drv->drvwrap.driver;
208 return dev ? to_usb_interface(dev) :
NULL;
219 static void usb_release_dev(
struct device *
dev)
221 struct usb_device *
udev;
224 udev = to_usb_device(dev);
225 hcd = bus_to_hcd(udev->bus);
230 kfree(udev->product);
231 kfree(udev->manufacturer);
236 #ifdef CONFIG_HOTPLUG
239 struct usb_device *usb_dev;
241 usb_dev = to_usb_device(dev);
269 static int usb_dev_prepare(
struct device *dev)
274 static void usb_dev_complete(
struct device *dev)
277 usb_resume_complete(dev);
280 static int usb_dev_suspend(
struct device *dev)
285 static int usb_dev_resume(
struct device *dev)
290 static int usb_dev_freeze(
struct device *dev)
295 static int usb_dev_thaw(
struct device *dev)
300 static int usb_dev_poweroff(
struct device *dev)
305 static int usb_dev_restore(
struct device *dev)
310 static const struct dev_pm_ops usb_device_pm_ops = {
312 .complete = usb_dev_complete,
313 .suspend = usb_dev_suspend,
314 .resume = usb_dev_resume,
315 .freeze = usb_dev_freeze,
316 .thaw = usb_dev_thaw,
317 .poweroff = usb_dev_poweroff,
318 .restore = usb_dev_restore,
319 #ifdef CONFIG_USB_SUSPEND
320 .runtime_suspend = usb_runtime_suspend,
321 .runtime_resume = usb_runtime_resume,
322 .runtime_idle = usb_runtime_idle,
331 struct usb_device *usb_dev;
333 usb_dev = to_usb_device(dev);
335 usb_dev->bus->busnum, usb_dev->devnum);
339 .name =
"usb_device",
340 .release = usb_release_dev,
341 .uevent = usb_dev_uevent,
342 .devnode = usb_devnode,
344 .pm = &usb_device_pm_ops,
350 static unsigned usb_bus_is_wusb(
struct usb_bus *
bus)
352 struct usb_hcd *hcd =
container_of(bus,
struct usb_hcd,
self);
353 return hcd->wireless;
370 struct usb_bus *
bus,
unsigned port1)
372 struct usb_device *
dev;
373 struct usb_hcd *usb_hcd =
container_of(bus,
struct usb_hcd,
self);
374 unsigned root_hub = 0;
385 if (usb_hcd->driver->alloc_dev && parent &&
386 !usb_hcd->driver->alloc_dev(usb_hcd, dev)) {
396 dev->dev.dma_mask = bus->controller->dma_mask;
397 set_dev_node(&dev->dev, dev_to_node(bus->controller));
399 dev->lpm_disable_count = 1;
402 INIT_LIST_HEAD(&dev->ep0.urb_list);
418 dev->devpath[0] =
'0';
421 dev->dev.parent = bus->controller;
426 if (parent->devpath[0] ==
'0') {
427 snprintf(dev->devpath,
sizeof dev->devpath,
432 snprintf(dev->devpath,
sizeof dev->devpath,
433 "%s.%d", parent->devpath, port1);
436 dev->route = parent->route +
437 (port1 << ((parent->level - 1)*4));
439 dev->route = parent->route +
440 (15 << ((parent->level - 1)*4));
443 dev->dev.parent = &parent->dev;
444 dev_set_name(&dev->dev,
"%d-%s", bus->busnum, dev->devpath);
449 dev->portnum = port1;
451 dev->parent = parent;
452 INIT_LIST_HEAD(&dev->filelist);
458 dev->active_duration = -
jiffies;
463 dev->authorized = usb_hcd->authorized_default;
464 dev->wusb = usb_bus_is_wusb(bus)? 1 : 0;
572 unsigned long jiffies_expire =
jiffies +
HZ;
578 if (iface && (iface->condition == USB_INTERFACE_UNBINDING ||
579 iface->condition == USB_INTERFACE_UNBOUND))
582 while (!usb_trylock_device(udev)) {
594 if (iface && (iface->condition == USB_INTERFACE_UNBINDING ||
595 iface->condition == USB_INTERFACE_UNBOUND))
628 unsigned char type,
void **
ptr)
637 "%s: bogus descriptor, type %d length %d\n",
681 if (!dev || !dev->bus)
701 if (!dev || !dev->bus)
726 struct urb *usb_buffer_map(
struct urb *
urb)
733 || !(bus = urb->dev->bus)
734 || !(controller = bus->controller))
739 urb->transfer_buffer, urb->transfer_buffer_length,
740 usb_pipein(urb->pipe)
745 urb->transfer_dma = ~0;
746 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
763 void usb_buffer_dmasync(
struct urb *urb)
769 || !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
771 || !(bus = urb->dev->bus)
772 || !(controller = bus->controller))
777 urb->transfer_dma, urb->transfer_buffer_length,
778 usb_pipein(urb->pipe)
780 if (usb_pipecontrol(urb->pipe))
797 void usb_buffer_unmap(
struct urb *urb)
803 || !(urb->transfer_flags & URB_NO_TRANSFER_DMA_MAP)
805 || !(bus = urb->dev->bus)
806 || !(controller = bus->controller))
811 urb->transfer_dma, urb->transfer_buffer_length,
812 usb_pipein(urb->pipe)
815 urb->transfer_flags &= ~URB_NO_TRANSFER_DMA_MAP;
847 int usb_buffer_map_sg(
const struct usb_device *dev,
int is_in,
855 || !(controller = bus->controller)
883 void usb_buffer_dmasync_sg(
const struct usb_device *dev,
int is_in,
891 || !(controller = bus->controller)
911 void usb_buffer_unmap_sg(
const struct usb_device *dev,
int is_in,
919 || !(controller = bus->controller)
955 if (dev->
type == &usb_device_type)
962 if (dev->
type == &usb_device_type)
972 .notifier_call = usb_bus_notify,
978 static struct dentry *usb_debug_devices;
980 static int usb_debugfs_init(
void)
987 usb_debug_root,
NULL,
989 if (!usb_debug_devices) {
991 usb_debug_root =
NULL;
998 static void usb_debugfs_cleanup(
void)
1007 static int __init usb_init(
void)
1015 retval = usb_debugfs_init();
1022 goto bus_register_failed;
1025 goto bus_notifier_failed;
1028 goto major_init_failed;
1031 goto driver_register_failed;
1034 goto usb_devio_init_failed;
1037 goto hub_init_failed;
1045 usb_devio_init_failed:
1047 driver_register_failed:
1051 bus_notifier_failed:
1053 bus_register_failed:
1055 usb_debugfs_cleanup();
1063 static void __exit usb_exit(
void)
1077 usb_debugfs_cleanup();