4 * (C) Copyright Linus Torvalds 1999
5 * (C) Copyright Johannes Erdfelt 1999-2001
6 * (C) Copyright Andreas Gal 1999
7 * (C) Copyright Gregory P. Smith 1999
8 * (C) Copyright Deti Fliegl 1999 (new USB architecture)
9 * (C) Copyright Randy Dunlap 2000
10 * (C) Copyright David Brownell 2000-2001 (kernel hotplug, usb_device_id,
12 * (C) Copyright Yggdrasil Computing, Inc. 2000
13 * (usb_device_id matching changes by Adam J. Richter)
14 * (C) Copyright Greg Kroah-Hartman 2002-2003
16 * NOTE! This is not actually a driver at all, rather this is
17 * just a collection of helper routines that implement the
18 * generic USB things that the real drivers can use..
20 * Think of this as a "USB library" rather than anything else.
21 * It should be considered a slave, with no callbacks. Callbacks
26 #include <linux/config.h>
28 #ifdef CONFIG_USB_DEBUG
34 #include <linux/module.h>
35 #include <linux/string.h>
36 #include <linux/bitops.h>
37 #include <linux/slab.h>
38 #include <linux/interrupt.h> /* for in_interrupt() */
39 #include <linux/kmod.h>
40 #include <linux/init.h>
41 #include <linux/spinlock.h>
42 #include <linux/errno.h>
43 #include <linux/smp_lock.h>
44 #include <linux/usb.h>
47 #include <asm/scatterlist.h>
49 #include <linux/dma-mapping.h>
53 #include "../usb_wrapper.h"
57 extern int usb_hub_init(void);
58 extern void usb_hub_cleanup(void);
59 extern int usb_major_init(void);
60 extern void usb_major_cleanup(void);
63 int nousb
; /* Disable USB when built into kernel image */
64 /* Not honored on modular build */
67 static int generic_probe (struct device
*dev
)
71 static int generic_remove (struct device
*dev
)
76 static struct device_driver usb_generic_driver
= {
79 .probe
= generic_probe
,
80 .remove
= generic_remove
,
83 static int usb_generic_driver_data
;
85 /* needs to be called with BKL held */
86 int usb_device_probe(struct device
*dev
)
88 struct usb_interface
* intf
= to_usb_interface(dev
);
89 struct usb_driver
* driver
= to_usb_driver(dev
->driver
);
90 const struct usb_device_id
*id
;
93 dev_dbg(dev
, "%s\n", __FUNCTION__
);
97 /* driver claim() doesn't yet affect dev->driver... */
101 id
= usb_match_id (intf
, driver
->id_table
);
103 dev_dbg (dev
, "%s - got id\n", __FUNCTION__
);
104 down (&driver
->serialize
);
105 error
= driver
->probe (intf
, id
);
106 up (&driver
->serialize
);
109 intf
->driver
= driver
;
114 int usb_device_remove(struct device
*dev
)
116 struct usb_interface
*intf
;
117 struct usb_driver
*driver
;
119 intf
= list_entry(dev
,struct usb_interface
,dev
);
120 driver
= to_usb_driver(dev
->driver
);
122 down(&driver
->serialize
);
124 if (intf
->driver
&& intf
->driver
->disconnect
)
125 intf
->driver
->disconnect(intf
);
127 /* if driver->disconnect didn't release the interface */
129 usb_driver_release_interface(driver
, intf
);
131 up(&driver
->serialize
);
137 * usb_register - register a USB driver
138 * @new_driver: USB operations for the driver
140 * Registers a USB driver with the USB core. The list of unattached
141 * interfaces will be rescanned whenever a new driver is added, allowing
142 * the new driver to attach to any recognized devices.
143 * Returns a negative error code on failure and 0 on success.
145 * NOTE: if you want your driver to use the USB major number, you must call
146 * usb_register_dev() to enable that functionality. This function no longer
147 * takes care of that.
149 int usb_register(struct usb_driver
*new_driver
)
156 new_driver
->driver
.name
= (char *)new_driver
->name
;
157 new_driver
->driver
.bus
= &usb_bus_type
;
158 new_driver
->driver
.probe
= usb_device_probe
;
159 new_driver
->driver
.remove
= usb_device_remove
;
161 init_MUTEX(&new_driver
->serialize
);
163 retval
= driver_register(&new_driver
->driver
);
166 info("registered new driver %s", new_driver
->name
);
167 usbfs_update_special();
169 err("problem %d when registering driver %s",
170 retval
, new_driver
->name
);
177 * usb_deregister - unregister a USB driver
178 * @driver: USB operations of the driver to unregister
179 * Context: !in_interrupt (), must be called with BKL held
181 * Unlinks the specified driver from the internal USB driver list.
183 * NOTE: If you called usb_register_dev(), you still need to call
184 * usb_deregister_dev() to clean up your driver's allocated minor numbers,
185 * this * call will no longer do it for you.
187 void usb_deregister(struct usb_driver
*driver
)
189 info("deregistering driver %s", driver
->name
);
191 driver_unregister (&driver
->driver
);
193 usbfs_update_special();
197 * usb_ifnum_to_if - get the interface object with a given interface number (usbcore-internal)
198 * @dev: the device whose current configuration is considered
199 * @ifnum: the desired interface
201 * This walks the device descriptor for the currently active configuration
202 * and returns a pointer to the interface with that particular interface
205 * Note that configuration descriptors are not required to assign interface
206 * numbers sequentially, so that it would be incorrect to assume that
207 * the first interface in that descriptor corresponds to interface zero.
208 * This routine helps device drivers avoid such mistakes.
209 * However, you should make sure that you do the right thing with any
210 * alternate settings available for this interfaces.
212 struct usb_interface
*usb_ifnum_to_if(struct usb_device
*dev
, unsigned ifnum
)
216 for (i
= 0; i
< dev
->actconfig
->desc
.bNumInterfaces
; i
++)
217 if (dev
->actconfig
->interface
[i
].altsetting
[0]
218 .desc
.bInterfaceNumber
== ifnum
)
219 return &dev
->actconfig
->interface
[i
];
225 * usb_epnum_to_ep_desc - get the endpoint object with a given endpoint number
226 * @dev: the device whose current configuration is considered
227 * @epnum: the desired endpoint
229 * This walks the device descriptor for the currently active configuration,
230 * and returns a pointer to the endpoint with that particular endpoint
233 * Note that interface descriptors are not required to assign endpont
234 * numbers sequentially, so that it would be incorrect to assume that
235 * the first endpoint in that descriptor corresponds to interface zero.
236 * This routine helps device drivers avoid such mistakes.
238 struct usb_endpoint_descriptor
*
239 usb_epnum_to_ep_desc(struct usb_device
*dev
, unsigned epnum
)
243 for (i
= 0; i
< dev
->actconfig
->desc
.bNumInterfaces
; i
++)
244 for (j
= 0; j
< dev
->actconfig
->interface
[i
].num_altsetting
; j
++)
245 for (k
= 0; k
< dev
->actconfig
->interface
[i
]
246 .altsetting
[j
].desc
.bNumEndpoints
; k
++)
247 if (epnum
== dev
->actconfig
->interface
[i
]
248 .altsetting
[j
].endpoint
[k
]
249 .desc
.bEndpointAddress
)
250 return &dev
->actconfig
->interface
[i
]
251 .altsetting
[j
].endpoint
[k
]
258 * usb_driver_claim_interface - bind a driver to an interface
259 * @driver: the driver to be bound
260 * @iface: the interface to which it will be bound
261 * @priv: driver data associated with that interface
263 * This is used by usb device drivers that need to claim more than one
264 * interface on a device when probing (audio and acm are current examples).
265 * No device driver should directly modify internal usb_interface or
266 * usb_device structure members.
268 * Few drivers should need to use this routine, since the most natural
269 * way to bind to an interface is to return the private data from
270 * the driver's probe() method. Any driver that does use this must
271 * first be sure that no other driver has claimed the interface, by
272 * checking with usb_interface_claimed().
274 void usb_driver_claim_interface(struct usb_driver
*driver
, struct usb_interface
*iface
, void* priv
)
276 if (!iface
|| !driver
)
279 // FIXME change API to report an error in this case
281 err ("%s driver booted %s off interface %p",
282 driver
->name
, iface
->driver
->name
, iface
);
285 dbg("%s driver claimed interface %p", driver
->name
, iface
);
287 iface
->driver
= driver
;
288 usb_set_intfdata(iface
, priv
);
292 * usb_interface_claimed - returns true iff an interface is claimed
293 * @iface: the interface being checked
295 * This should be used by drivers to check other interfaces to see if
296 * they are available or not. If another driver has claimed the interface,
297 * they may not claim it. Otherwise it's OK to claim it using
298 * usb_driver_claim_interface().
300 * Returns true (nonzero) iff the interface is claimed, else false (zero).
302 int usb_interface_claimed(struct usb_interface
*iface
)
307 return (iface
->driver
!= NULL
);
308 } /* usb_interface_claimed() */
311 * usb_driver_release_interface - unbind a driver from an interface
312 * @driver: the driver to be unbound
313 * @iface: the interface from which it will be unbound
315 * This should be used by drivers to release their claimed interfaces.
316 * It is normally called in their disconnect() methods, and only for
317 * drivers that bound to more than one interface in their probe().
319 * When the USB subsystem disconnect()s a driver from some interface,
320 * it automatically invokes this method for that interface. That
321 * means that even drivers that used usb_driver_claim_interface()
322 * usually won't need to call this.
324 void usb_driver_release_interface(struct usb_driver
*driver
, struct usb_interface
*iface
)
326 /* this should never happen, don't release something that's not ours */
327 if (!iface
|| iface
->driver
!= driver
)
330 iface
->driver
= NULL
;
331 usb_set_intfdata(iface
, NULL
);
335 * usb_match_id - find first usb_device_id matching device or interface
336 * @interface: the interface of interest
337 * @id: array of usb_device_id structures, terminated by zero entry
339 * usb_match_id searches an array of usb_device_id's and returns
340 * the first one matching the device or interface, or null.
341 * This is used when binding (or rebinding) a driver to an interface.
342 * Most USB device drivers will use this indirectly, through the usb core,
343 * but some layered driver frameworks use it directly.
344 * These device tables are exported with MODULE_DEVICE_TABLE, through
345 * modutils and "modules.usbmap", to support the driver loading
346 * functionality of USB hotplugging.
350 * The "match_flags" element in a usb_device_id controls which
351 * members are used. If the corresponding bit is set, the
352 * value in the device_id must match its corresponding member
353 * in the device or interface descriptor, or else the device_id
356 * "driver_info" is normally used only by device drivers,
357 * but you can create a wildcard "matches anything" usb_device_id
358 * as a driver's "modules.usbmap" entry if you provide an id with
359 * only a nonzero "driver_info" field. If you do this, the USB device
360 * driver's probe() routine should use additional intelligence to
361 * decide whether to bind to the specified interface.
363 * What Makes Good usb_device_id Tables:
365 * The match algorithm is very simple, so that intelligence in
366 * driver selection must come from smart driver id records.
367 * Unless you have good reasons to use another selection policy,
368 * provide match elements only in related groups, and order match
369 * specifiers from specific to general. Use the macros provided
370 * for that purpose if you can.
372 * The most specific match specifiers use device descriptor
373 * data. These are commonly used with product-specific matches;
374 * the USB_DEVICE macro lets you provide vendor and product IDs,
375 * and you can also match against ranges of product revisions.
376 * These are widely used for devices with application or vendor
377 * specific bDeviceClass values.
379 * Matches based on device class/subclass/protocol specifications
380 * are slightly more general; use the USB_DEVICE_INFO macro, or
381 * its siblings. These are used with single-function devices
382 * where bDeviceClass doesn't specify that each interface has
385 * Matches based on interface class/subclass/protocol are the
386 * most general; they let drivers bind to any interface on a
387 * multiple-function device. Use the USB_INTERFACE_INFO
388 * macro, or its siblings, to match class-per-interface style
389 * devices (as recorded in bDeviceClass).
391 * Within those groups, remember that not all combinations are
392 * meaningful. For example, don't give a product version range
393 * without vendor and product IDs; or specify a protocol without
394 * its associated class and subclass.
396 const struct usb_device_id
*
397 usb_match_id(struct usb_interface
*interface
, const struct usb_device_id
*id
)
399 struct usb_host_interface
*intf
;
400 struct usb_device
*dev
;
401 struct usb_device_id
*save_id
;
406 save_id
= (struct usb_device_id
*)id
;
408 id
= (struct usb_device_id
*)save_id
;
410 /* proc_connectinfo in devio.c may call us with id == NULL. */
414 intf
= &interface
->altsetting
[interface
->act_altsetting
];
415 dev
= interface_to_usbdev(interface
);
417 /* It is important to check that id->driver_info is nonzero,
418 since an entry that is all zeroes except for a nonzero
419 id->driver_info is the way to create an entry that
420 indicates that the driver want to examine every
421 device and interface. */
422 for (; id
->idVendor
|| id
->bDeviceClass
|| id
->bInterfaceClass
||
423 id
->driver_info
; id
++) {
425 if ((id
->match_flags
& USB_DEVICE_ID_MATCH_VENDOR
) &&
426 id
->idVendor
!= dev
->descriptor
.idVendor
)
429 if ((id
->match_flags
& USB_DEVICE_ID_MATCH_PRODUCT
) &&
430 id
->idProduct
!= dev
->descriptor
.idProduct
)
433 /* No need to test id->bcdDevice_lo != 0, since 0 is never
434 greater than any unsigned number. */
435 if ((id
->match_flags
& USB_DEVICE_ID_MATCH_DEV_LO
) &&
436 (id
->bcdDevice_lo
> dev
->descriptor
.bcdDevice
))
439 if ((id
->match_flags
& USB_DEVICE_ID_MATCH_DEV_HI
) &&
440 (id
->bcdDevice_hi
< dev
->descriptor
.bcdDevice
))
443 if ((id
->match_flags
& USB_DEVICE_ID_MATCH_DEV_CLASS
) &&
444 (id
->bDeviceClass
!= dev
->descriptor
.bDeviceClass
))
447 if ((id
->match_flags
& USB_DEVICE_ID_MATCH_DEV_SUBCLASS
) &&
448 (id
->bDeviceSubClass
!= dev
->descriptor
.bDeviceSubClass
))
451 if ((id
->match_flags
& USB_DEVICE_ID_MATCH_DEV_PROTOCOL
) &&
452 (id
->bDeviceProtocol
!= dev
->descriptor
.bDeviceProtocol
))
455 if ((id
->match_flags
& USB_DEVICE_ID_MATCH_INT_CLASS
) &&
456 (id
->bInterfaceClass
!= intf
->desc
.bInterfaceClass
))
459 if ((id
->match_flags
& USB_DEVICE_ID_MATCH_INT_SUBCLASS
) &&
460 (id
->bInterfaceSubClass
!= intf
->desc
.bInterfaceSubClass
))
463 if ((id
->match_flags
& USB_DEVICE_ID_MATCH_INT_PROTOCOL
) &&
464 (id
->bInterfaceProtocol
!= intf
->desc
.bInterfaceProtocol
))
474 * usb_find_interface - find usb_interface pointer for driver and device
475 * @drv: the driver whose current configuration is considered
476 * @minor: the minor number of the desired device
478 * This walks the driver device list and returns a pointer to the interface
479 * with the matching minor. Note, this only works for devices that share the
482 struct usb_interface
*usb_find_interface(struct usb_driver
*drv
, int minor
)
484 struct list_head
*entry
;
486 struct usb_interface
*intf
;
488 list_for_each(entry
, &drv
->driver
.devices
) {
489 dev
= container_of(entry
, struct device
, driver_list
);
491 /* can't look at usb devices, only interfaces */
492 if (dev
->driver
== &usb_generic_driver
)
495 intf
= to_usb_interface(dev
);
496 if (intf
->minor
== -1)
498 if (intf
->minor
== minor
)
502 /* no device found that matches */
506 static int usb_device_match (struct device
*dev
, struct device_driver
*drv
)
508 struct usb_interface
*intf
;
509 struct usb_driver
*usb_drv
;
510 const struct usb_device_id
*id
;
512 /* check for generic driver, which we don't match any device with */
513 if (drv
== &usb_generic_driver
)
516 intf
= to_usb_interface(dev
);
518 usb_drv
= to_usb_driver(drv
);
519 id
= usb_drv
->id_table
;
521 id
= usb_match_id (intf
, usb_drv
->id_table
);
529 #ifdef CONFIG_HOTPLUG
532 * USB hotplugging invokes what /proc/sys/kernel/hotplug says
533 * (normally /sbin/hotplug) when USB devices get added or removed.
535 * This invokes a user mode policy agent, typically helping to load driver
536 * or other modules, configure the device, and more. Drivers can provide
537 * a MODULE_DEVICE_TABLE to help with module loading subtasks.
539 * We're called either from khubd (the typical case) or from root hub
540 * (init, kapmd, modprobe, rmmod, etc), but the agents need to handle
541 * delays in event delivery. Use sysfs (and DEVPATH) to make sure the
542 * device (and this configuration!) are still present.
544 static int usb_hotplug (struct device
*dev
, char **envp
, int num_envp
,
545 char *buffer
, int buffer_size
)
547 struct usb_interface
*intf
;
548 struct usb_device
*usb_dev
;
553 dbg ("%s", __FUNCTION__
);
558 /* Must check driver_data here, as on remove driver is always NULL */
559 if ((dev
->driver
== &usb_generic_driver
) ||
560 (dev
->driver_data
== &usb_generic_driver_data
))
563 intf
= to_usb_interface(dev
);
564 usb_dev
= interface_to_usbdev (intf
);
566 if (usb_dev
->devnum
< 0) {
567 dbg ("device already deleted ??");
571 dbg ("bus already removed?");
577 #ifdef CONFIG_USB_DEVICEFS
578 /* If this is available, userspace programs can directly read
579 * all the device descriptors we don't tell them about. Or
580 * even act as usermode drivers.
582 * FIXME reduce hardwired intelligence here
584 envp
[i
++] = scratch
;
585 length
+= snprintf (scratch
, buffer_size
- length
,
586 "DEVICE=/proc/bus/usb/%03d/%03d",
587 usb_dev
->bus
->busnum
, usb_dev
->devnum
);
588 if ((buffer_size
- length
<= 0) || (i
>= num_envp
))
594 /* per-device configurations are common */
595 envp
[i
++] = scratch
;
596 length
+= snprintf (scratch
, buffer_size
- length
, "PRODUCT=%x/%x/%x",
597 usb_dev
->descriptor
.idVendor
,
598 usb_dev
->descriptor
.idProduct
,
599 usb_dev
->descriptor
.bcdDevice
);
600 if ((buffer_size
- length
<= 0) || (i
>= num_envp
))
605 /* class-based driver binding models */
606 envp
[i
++] = scratch
;
607 length
+= snprintf (scratch
, buffer_size
- length
, "TYPE=%d/%d/%d",
608 usb_dev
->descriptor
.bDeviceClass
,
609 usb_dev
->descriptor
.bDeviceSubClass
,
610 usb_dev
->descriptor
.bDeviceProtocol
);
611 if ((buffer_size
- length
<= 0) || (i
>= num_envp
))
616 if (usb_dev
->descriptor
.bDeviceClass
== 0) {
617 int alt
= intf
->act_altsetting
;
619 /* 2.4 only exposed interface zero. in 2.5, hotplug
620 * agents are called for all interfaces, and can use
621 * $DEVPATH/bInterfaceNumber if necessary.
623 envp
[i
++] = scratch
;
624 length
+= snprintf (scratch
, buffer_size
- length
,
625 "INTERFACE=%d/%d/%d",
626 intf
->altsetting
[alt
].desc
.bInterfaceClass
,
627 intf
->altsetting
[alt
].desc
.bInterfaceSubClass
,
628 intf
->altsetting
[alt
].desc
.bInterfaceProtocol
);
629 if ((buffer_size
- length
<= 0) || (i
>= num_envp
))
642 static int usb_hotplug (struct device
*dev
, char **envp
,
643 int num_envp
, char *buffer
, int buffer_size
)
648 #endif /* CONFIG_HOTPLUG */
651 * usb_alloc_dev - allocate a usb device structure (usbcore-internal)
652 * @parent: hub to which device is connected
653 * @bus: bus used to access the device
654 * Context: !in_interrupt ()
656 * Only hub drivers (including virtual root hub drivers for host
657 * controllers) should ever call this.
659 * This call is synchronous, and may not be used in an interrupt context.
661 struct usb_device STDCALL
*usb_alloc_dev(struct usb_device
*parent
, struct usb_bus
*bus
)
663 struct usb_device
*dev
;
665 dev
= kmalloc(sizeof(*dev
), GFP_KERNEL
);
669 memset(dev
, 0, sizeof(*dev
));
671 device_initialize(&dev
->dev
);
672 dev
->state
= USB_STATE_ATTACHED
;
677 dev
->devpath
[0] = '0';
679 dev
->parent
= parent
;
680 INIT_LIST_HEAD(&dev
->filelist
);
682 init_MUTEX(&dev
->serialize
);
684 if (dev
->bus
->op
->allocate
)
685 dev
->bus
->op
->allocate(dev
);
691 * usb_get_dev - increments the reference count of the usb device structure
692 * @dev: the device being referenced
694 * Each live reference to a device should be refcounted.
696 * Drivers for USB interfaces should normally record such references in
697 * their probe() methods, when they bind to an interface, and release
698 * them by calling usb_put_dev(), in their disconnect() methods.
700 * A pointer to the device with the incremented reference counter is returned.
702 struct usb_device STDCALL
*usb_get_dev (struct usb_device
*dev
)
709 tmp
= get_device(&dev
->dev
);
711 return to_usb_device(tmp
);
717 * usb_put_dev - release a use of the usb device structure
718 * @dev: device that's been disconnected
720 * Must be called when a user of a device is finished with it. When the last
721 * user of the device calls this function, the memory of the device is freed.
723 void STDCALL
usb_put_dev(struct usb_device
*dev
)
726 put_device(&dev
->dev
);
730 * usb_release_dev - free a usb device structure when all users of it are finished.
731 * @dev: device that's been disconnected
733 * Will be called only by the device core when all users of this usb device are
736 static void usb_release_dev(struct device
*dev
)
738 struct usb_device
*udev
;
740 udev
= to_usb_device(dev
);
742 if (udev
->bus
&& udev
->bus
->op
&& udev
->bus
->op
->deallocate
)
743 udev
->bus
->op
->deallocate(udev
);
744 usb_destroy_configuration (udev
);
745 usb_bus_put (udev
->bus
);
750 static struct usb_device
*match_device(struct usb_device
*dev
,
751 u16 vendor_id
, u16 product_id
)
753 struct usb_device
*ret_dev
= NULL
;
756 dbg("looking at vendor %d, product %d",
757 dev
->descriptor
.idVendor
,
758 dev
->descriptor
.idProduct
);
760 /* see if this device matches */
761 if ((dev
->descriptor
.idVendor
== vendor_id
) &&
762 (dev
->descriptor
.idProduct
== product_id
)) {
763 dbg ("found the device!");
764 ret_dev
= usb_get_dev(dev
);
768 /* look through all of the children of this device */
769 for (child
= 0; child
< dev
->maxchild
; ++child
) {
770 if (dev
->children
[child
]) {
771 ret_dev
= match_device(dev
->children
[child
],
772 vendor_id
, product_id
);
782 * usb_find_device - find a specific usb device in the system
783 * @vendor_id: the vendor id of the device to find
784 * @product_id: the product id of the device to find
786 * Returns a pointer to a struct usb_device if such a specified usb
787 * device is present in the system currently. The usage count of the
788 * device will be incremented if a device is found. Make sure to call
789 * usb_put_dev() when the caller is finished with the device.
791 * If a device with the specified vendor and product id is not found,
794 struct usb_device
*usb_find_device(u16 vendor_id
, u16 product_id
)
796 struct list_head
*buslist
;
798 struct usb_device
*dev
= NULL
;
800 down(&usb_bus_list_lock
);
801 for (buslist
= usb_bus_list
.next
;
802 buslist
!= &usb_bus_list
;
803 buslist
= buslist
->next
) {
804 bus
= container_of(buslist
, struct usb_bus
, bus_list
);
805 dev
= match_device(bus
->root_hub
, vendor_id
, product_id
);
810 up(&usb_bus_list_lock
);
815 * usb_get_current_frame_number - return current bus frame number
816 * @dev: the device whose bus is being queried
818 * Returns the current frame number for the USB host controller
819 * used with the given USB device. This can be used when scheduling
820 * isochronous requests.
822 * Note that different kinds of host controller have different
823 * "scheduling horizons". While one type might support scheduling only
824 * 32 frames into the future, others could support scheduling up to
825 * 1024 frames into the future.
827 int usb_get_current_frame_number(struct usb_device
*dev
)
829 return dev
->bus
->op
->get_frame_number (dev
);
832 /*-------------------------------------------------------------------*/
834 * __usb_get_extra_descriptor() finds a descriptor of specific type in the
835 * extra field of the interface and endpoint descriptor structs.
838 int __usb_get_extra_descriptor(char *buffer
, unsigned size
, unsigned char type
, void **ptr
)
840 struct usb_descriptor_header
*header
;
842 while (size
>= sizeof(struct usb_descriptor_header
)) {
843 header
= (struct usb_descriptor_header
*)buffer
;
845 if (header
->bLength
< 2) {
846 err("invalid descriptor length of %d", header
->bLength
);
850 if (header
->bDescriptorType
== type
) {
855 buffer
+= header
->bLength
;
856 size
-= header
->bLength
;
862 * usb_disconnect - disconnect a device (usbcore-internal)
863 * @pdev: pointer to device being disconnected
864 * Context: !in_interrupt ()
866 * Something got disconnected. Get rid of it, and all of its children.
868 * Only hub drivers (including virtual root hub drivers for host
869 * controllers) should ever call this.
871 * This call is synchronous, and may not be used in an interrupt context.
873 void usb_disconnect(struct usb_device
**pdev
)
875 struct usb_device
*dev
= *pdev
;
877 struct usb_operations
*ops
;
883 // pr_debug ("%s nodev\n", __FUNCTION__);
884 DPRINT ("%s nodev\n", __FUNCTION__
);
889 // pr_debug ("%s nobus\n", __FUNCTION__);
890 DPRINT ("%s nobus\n", __FUNCTION__
);
897 /* mark the device as inactive, so any further urb submissions for
898 * this device will fail.
900 dev
->state
= USB_STATE_NOTATTACHED
;
902 dev_info (&dev
->dev
, "USB disconnect, address %d\n", dev
->devnum
);
904 /* Free up all the children before we remove this device */
905 for (i
= 0; i
< USB_MAXCHILDREN
; i
++) {
906 struct usb_device
**child
= dev
->children
+ i
;
908 usb_disconnect(child
);
911 /* disconnect() drivers from interfaces (a key side effect) */
912 dev_dbg (&dev
->dev
, "unregistering interfaces\n");
913 if (dev
->actconfig
) {
914 for (i
= 0; i
< dev
->actconfig
->desc
.bNumInterfaces
; i
++) {
915 struct usb_interface
*interface
;
917 /* remove this interface */
918 interface
= &dev
->actconfig
->interface
[i
];
919 device_unregister(&interface
->dev
);
923 /* deallocate hcd/hardware state */
925 void (*disable
)(struct usb_device
*, int) = ops
->disable
;
927 for (i
= 0; i
< 15; i
++) {
929 disable (dev
, USB_DIR_IN
| i
);
933 dev_dbg (&dev
->dev
, "unregistering device\n");
934 /* Free the device number and remove the /proc/bus/usb entry */
935 if (dev
->devnum
> 0) {
936 clear_bit(dev
->devnum
, dev
->bus
->devmap
.devicemap
);
937 usbfs_remove_device(dev
);
939 device_unregister(&dev
->dev
);
941 /* Decrement the reference count, it'll auto free everything when */
942 /* it hits 0 which could very well be now */
947 * usb_connect - pick device address (usbcore-internal)
948 * @dev: newly detected device (in DEFAULT state)
950 * Picks a device address. It's up to the hub (or root hub) driver
951 * to handle and manage enumeration, starting from the DEFAULT state.
952 * Only hub drivers (including virtual root hub drivers for host
953 * controllers) should ever call this.
955 void STDCALL
usb_connect(struct usb_device
*dev
)
958 // FIXME needs locking for SMP!!
959 /* why? this is called only from the hub thread,
960 * which hopefully doesn't run on multiple CPU's simultaneously 8-)
961 * ... it's also called from modprobe/rmmod/apmd threads as part
962 * of virtual root hub init/reinit. In the init case, the hub code
963 * won't have seen this, but not so for reinit ...
965 dev
->descriptor
.bMaxPacketSize0
= 8; /* Start off at 8 bytes */
967 /* Try to allocate the next devnum beginning at bus->devnum_next. */
968 devnum
= find_next_zero_bit(dev
->bus
->devmap
.devicemap
, 128, dev
->bus
->devnum_next
);
970 devnum
= find_next_zero_bit(dev
->bus
->devmap
.devicemap
, 128, 1);
972 dev
->bus
->devnum_next
= ( devnum
>= 127 ? 1 : devnum
+ 1);
975 set_bit(devnum
, dev
->bus
->devmap
.devicemap
);
976 dev
->devnum
= devnum
;
981 * usb_choose_address - pick device address (usbcore-internal)
982 * @dev: newly detected device (in DEFAULT state)
984 * Picks a device address. It's up to the hub (or root hub) driver
985 * to handle and manage enumeration, starting from the DEFAULT state.
986 * Only hub drivers (but not virtual root hub drivers for host
987 * controllers) should ever call this.
989 void usb_choose_address(struct usb_device
*dev
)
992 // FIXME needs locking for SMP!!
993 /* why? this is called only from the hub thread,
994 * which hopefully doesn't run on multiple CPU's simultaneously 8-)
997 /* Try to allocate the next devnum beginning at bus->devnum_next. */
998 devnum
= find_next_zero_bit(dev
->bus
->devmap
.devicemap
, 128, dev
->bus
->devnum_next
);
1000 devnum
= find_next_zero_bit(dev
->bus
->devmap
.devicemap
, 128, 1);
1002 dev
->bus
->devnum_next
= ( devnum
>= 127 ? 1 : devnum
+ 1);
1005 set_bit(devnum
, dev
->bus
->devmap
.devicemap
);
1006 dev
->devnum
= devnum
;
1010 // hub-only!! ... and only exported for reset/reinit path.
1011 // otherwise used internally, for usb_new_device()
1012 int usb_set_address(struct usb_device
*dev
)
1016 if (dev
->devnum
== 0)
1018 if (dev
->state
!= USB_STATE_DEFAULT
&& dev
->state
!= USB_STATE_ADDRESS
)
1020 retval
= usb_control_msg(dev
, usb_snddefctrl(dev
), USB_REQ_SET_ADDRESS
,
1021 0, dev
->devnum
, 0, NULL
, 0, HZ
* USB_CTRL_SET_TIMEOUT
);
1023 dev
->state
= USB_STATE_ADDRESS
;
1028 /* improve on the default device description, if we can ... and
1029 * while we're at it, maybe show the vendor and product strings.
1031 static void set_device_description (struct usb_device
*dev
)
1034 int mfgr
= dev
->descriptor
.iManufacturer
;
1035 int prod
= dev
->descriptor
.iProduct
;
1036 int vendor_id
= dev
->descriptor
.idVendor
;
1037 int product_id
= dev
->descriptor
.idProduct
;
1038 char *mfgr_str
, *prod_str
;
1040 /* set default; keep it if there are no strings, or kmalloc fails */
1041 sprintf (dev
->dev
.name
, "USB device %04x:%04x",
1042 vendor_id
, product_id
);
1044 if (!(buf
= kmalloc(256 * 2, GFP_KERNEL
)))
1047 prod_str
= (char *) buf
;
1048 mfgr_str
= (char *) buf
+ 256;
1050 if (prod
&& usb_string (dev
, prod
, prod_str
, 256) > 0) {
1052 dev_printk (KERN_INFO
, &dev
->dev
, "Product: %s\n", prod_str
);
1058 if (mfgr
&& usb_string (dev
, mfgr
, mfgr_str
, 256) > 0) {
1060 dev_printk (KERN_INFO
, &dev
->dev
, "Manufacturer: %s\n", mfgr_str
);
1066 /* much like pci ... describe as either:
1067 * - both strings: 'product descr (vendor descr)'
1068 * - product only: 'product descr (USB device vvvv:pppp)'
1069 * - vendor only: 'USB device vvvv:pppp (vendor descr)'
1070 * - neither string: 'USB device vvvv:pppp'
1073 if (prod_str
&& mfgr_str
) {
1075 snprintf(dev
->dev
.name
, sizeof dev
->dev
.name
,
1076 "%s (%s)", prod_str
, mfgr_str
);
1077 } else if (prod_str
) {
1078 snprintf(dev
->dev
.name
, sizeof dev
->dev
.name
,
1079 "%s (USB device %04x:%04x)",
1080 prod_str
, vendor_id
, product_id
);
1082 } else if (mfgr_str
) {
1083 snprintf(dev
->dev
.name
, sizeof dev
->dev
.name
,
1084 "USB device %04x:%04x (%s)",
1085 vendor_id
, product_id
, mfgr_str
);
1087 usbprintk("USB connected: %s\n",dev
->dev
.name
);
1092 * By the time we get here, we chose a new device address
1093 * and is in the default state. We need to identify the thing and
1094 * get the ball rolling..
1096 * Returns 0 for success, != 0 for error.
1098 * This call is synchronous, and may not be used in an interrupt context.
1100 * Only hub drivers (including virtual root hub drivers for host
1101 * controllers) should ever call this.
1103 #define NEW_DEVICE_RETRYS 2
1104 #define SET_ADDRESS_RETRYS 20
1105 int usb_new_device(struct usb_device
*dev
, struct device
*parent
)
1112 * Set the driver for the usb device to point to the "generic" driver.
1113 * This prevents the main usb device from being sent to the usb bus
1114 * probe function. Yes, it's a hack, but a nice one :)
1116 * Do it asap, so more driver model stuff (like the device.h message
1117 * utilities) can be used in hcd submit/unlink code paths.
1119 usb_generic_driver
.bus
= &usb_bus_type
;
1120 dev
->dev
.parent
= parent
;
1121 dev
->dev
.driver
= &usb_generic_driver
;
1122 dev
->dev
.bus
= &usb_bus_type
;
1123 dev
->dev
.release
= usb_release_dev
;
1124 dev
->dev
.driver_data
= &usb_generic_driver_data
;
1126 if (dev
->dev
.bus_id
[0] == 0)
1127 sprintf (&dev
->dev
.bus_id
[0], "%d-%s",
1128 dev
->bus
->busnum
, dev
->devpath
);
1130 /* dma masks come from the controller; readonly, except to hcd */
1131 dev
->dev
.dma_mask
= parent
->dma_mask
;
1133 /* USB 2.0 section 5.5.3 talks about ep0 maxpacket ...
1134 * it's fixed size except for full speed devices.
1136 switch (dev
->speed
) {
1137 case USB_SPEED_HIGH
: /* fixed at 64 */
1140 case USB_SPEED_FULL
: /* 8, 16, 32, or 64 */
1141 /* to determine the ep0 maxpacket size, read the first 8
1142 * bytes from the device descriptor to get bMaxPacketSize0;
1143 * then correct our initial (small) guess.
1146 case USB_SPEED_LOW
: /* fixed at 8 */
1152 dev
->epmaxpacketin
[0] = i
;
1153 dev
->epmaxpacketout
[0] = i
;
1155 for (i
= 0; i
< NEW_DEVICE_RETRYS
; ++i
) {
1157 for (j
= 0; j
< SET_ADDRESS_RETRYS
; ++j
) {
1158 err
= usb_set_address(dev
);
1164 dev_err(&dev
->dev
, "USB device not accepting new address=%d (error=%d)\n",
1169 wait_ms(10); /* Let the SET_ADDRESS settle */
1171 /* high and low speed devices don't need this... */
1172 err
= usb_get_descriptor(dev
, USB_DT_DEVICE
, 0, &dev
->descriptor
, 8);
1179 dev_err(&dev
->dev
, "device descriptor read/8, error %d\n", err
);
1182 if (dev
->speed
== USB_SPEED_FULL
) {
1183 //usb_disable_endpoint(dev, 0);
1184 usb_endpoint_running(dev
, 0, 1);
1185 usb_endpoint_running(dev
, 0, 0);
1186 dev
->epmaxpacketin
[0] = dev
->descriptor
.bMaxPacketSize0
;
1187 dev
->epmaxpacketout
[0] = dev
->descriptor
.bMaxPacketSize0
;
1190 /* USB device state == addressed ... still not usable */
1192 err
= usb_get_device_descriptor(dev
);
1193 if (err
< (signed)sizeof(dev
->descriptor
)) {
1194 dev_err(&dev
->dev
, "device descriptor read/all, error %d\n", err
);
1198 err
= usb_get_configuration(dev
);
1200 dev_err(&dev
->dev
, "can't read configurations, error %d\n",
1205 /* we set the default configuration here */
1206 err
= usb_set_configuration(dev
, dev
->config
[0].desc
.bConfigurationValue
);
1208 dev_err(&dev
->dev
, "failed to set device %d default configuration (error=%d)\n",
1213 /* USB device state == configured ... tell the world! */
1215 dev_dbg(&dev
->dev
, "new device strings: Mfr=%d, Product=%d, SerialNumber=%d\n",
1216 dev
->descriptor
.iManufacturer
, dev
->descriptor
.iProduct
, dev
->descriptor
.iSerialNumber
);
1217 set_device_description (dev
);
1220 if (dev
->descriptor
.iSerialNumber
)
1221 usb_show_string(dev
, "SerialNumber", dev
->descriptor
.iSerialNumber
);
1223 /* put into sysfs, with device and config specific files */
1224 err
= device_add (&dev
->dev
);
1227 usb_create_driverfs_dev_files (dev
);
1229 /* Register all of the interfaces for this device with the driver core.
1230 * Remember, interfaces get bound to drivers, not devices. */
1231 for (i
= 0; i
< dev
->actconfig
->desc
.bNumInterfaces
; i
++) {
1232 struct usb_interface
*interface
= &dev
->actconfig
->interface
[i
];
1233 struct usb_interface_descriptor
*desc
;
1235 desc
= &interface
->altsetting
[interface
->act_altsetting
].desc
;
1236 interface
->dev
.parent
= &dev
->dev
;
1237 interface
->dev
.driver
= NULL
;
1238 interface
->dev
.bus
= &usb_bus_type
;
1239 interface
->dev
.dma_mask
= parent
->dma_mask
;
1240 sprintf (&interface
->dev
.bus_id
[0], "%d-%s:%d",
1241 dev
->bus
->busnum
, dev
->devpath
,
1242 desc
->bInterfaceNumber
);
1243 if (!desc
->iInterface
1244 || usb_string (dev
, desc
->iInterface
,
1245 interface
->dev
.name
,
1246 sizeof interface
->dev
.name
) <= 0) {
1247 /* typically devices won't bother with interface
1248 * descriptions; this is the normal case. an
1249 * interface's driver might describe it better.
1250 * (also: iInterface is per-altsetting ...)
1252 sprintf (&interface
->dev
.name
[0],
1253 "usb-%s-%s interface %d",
1254 dev
->bus
->bus_name
, dev
->devpath
,
1255 desc
->bInterfaceNumber
);
1256 DPRINT1(".........................usb_new_device: %s\n", interface
->dev
.name
);
1258 dev_dbg (&dev
->dev
, "%s - registering interface %s\n", __FUNCTION__
, interface
->dev
.bus_id
);
1259 device_add (&interface
->dev
);
1260 usb_create_driverfs_intf_files (interface
);
1262 /* add a /proc/bus/usb entry */
1263 usbfs_add_device(dev
);
1267 dev
->state
= USB_STATE_DEFAULT
;
1268 clear_bit(dev
->devnum
, dev
->bus
->devmap
.devicemap
);
1274 * usb_buffer_alloc - allocate dma-consistent buffer for URB_NO_DMA_MAP
1275 * @dev: device the buffer will be used with
1276 * @size: requested buffer size
1277 * @mem_flags: affect whether allocation may block
1278 * @dma: used to return DMA address of buffer
1280 * Return value is either null (indicating no buffer could be allocated), or
1281 * the cpu-space pointer to a buffer that may be used to perform DMA to the
1282 * specified device. Such cpu-space buffers are returned along with the DMA
1283 * address (through the pointer provided).
1285 * These buffers are used with URB_NO_DMA_MAP set in urb->transfer_flags to
1286 * avoid behaviors like using "DMA bounce buffers", or tying down I/O mapping
1287 * hardware for long idle periods. The implementation varies between
1288 * platforms, depending on details of how DMA will work to this device.
1289 * Using these buffers also helps prevent cacheline sharing problems on
1290 * architectures where CPU caches are not DMA-coherent.
1292 * When the buffer is no longer used, free it with usb_buffer_free().
1294 void *usb_buffer_alloc (
1295 struct usb_device
*dev
,
1301 if (!dev
|| !dev
->bus
|| !dev
->bus
->op
|| !dev
->bus
->op
->buffer_alloc
)
1303 return dev
->bus
->op
->buffer_alloc (dev
->bus
, size
, mem_flags
, dma
);
1307 * usb_buffer_free - free memory allocated with usb_buffer_alloc()
1308 * @dev: device the buffer was used with
1309 * @size: requested buffer size
1310 * @addr: CPU address of buffer
1311 * @dma: DMA address of buffer
1313 * This reclaims an I/O buffer, letting it be reused. The memory must have
1314 * been allocated using usb_buffer_alloc(), and the parameters must match
1315 * those provided in that allocation request.
1317 void usb_buffer_free (
1318 struct usb_device
*dev
,
1324 if (!dev
|| !dev
->bus
|| !dev
->bus
->op
|| !dev
->bus
->op
->buffer_free
)
1326 dev
->bus
->op
->buffer_free (dev
->bus
, size
, addr
, dma
);
1330 * usb_buffer_map - create DMA mapping(s) for an urb
1331 * @urb: urb whose transfer_buffer will be mapped
1333 * Return value is either null (indicating no buffer could be mapped), or
1334 * the parameter. URB_NO_DMA_MAP is added to urb->transfer_flags if the
1335 * operation succeeds. If the device is connected to this system through
1336 * a non-DMA controller, this operation always succeeds.
1338 * This call would normally be used for an urb which is reused, perhaps
1339 * as the target of a large periodic transfer, with usb_buffer_dmasync()
1340 * calls to synchronize memory and dma state. It may not be used for
1343 * Reverse the effect of this call with usb_buffer_unmap().
1345 struct urb
*usb_buffer_map (struct urb
*urb
)
1347 struct usb_bus
*bus
;
1348 struct device
*controller
;
1351 || usb_pipecontrol (urb
->pipe
)
1353 || !(bus
= urb
->dev
->bus
)
1354 || !(controller
= bus
->controller
))
1357 if (controller
->dma_mask
) {
1358 urb
->transfer_dma
= dma_map_single (controller
,
1359 urb
->transfer_buffer
, urb
->transfer_buffer_length
,
1360 usb_pipein (urb
->pipe
)
1361 ? DMA_FROM_DEVICE
: DMA_TO_DEVICE
);
1362 // FIXME generic api broken like pci, can't report errors
1363 // if (urb->transfer_dma == DMA_ADDR_INVALID) return 0;
1365 urb
->transfer_dma
= ~0;
1366 urb
->transfer_flags
|= URB_NO_DMA_MAP
;
1371 * usb_buffer_dmasync - synchronize DMA and CPU view of buffer(s)
1372 * @urb: urb whose transfer_buffer will be synchronized
1374 void usb_buffer_dmasync (struct urb
*urb
)
1376 struct usb_bus
*bus
;
1377 struct device
*controller
;
1380 || !(urb
->transfer_flags
& URB_NO_DMA_MAP
)
1382 || !(bus
= urb
->dev
->bus
)
1383 || !(controller
= bus
->controller
))
1386 if (controller
->dma_mask
)
1387 dma_sync_single (controller
,
1388 urb
->transfer_dma
, urb
->transfer_buffer_length
,
1389 usb_pipein (urb
->pipe
)
1390 ? DMA_FROM_DEVICE
: DMA_TO_DEVICE
);
1394 * usb_buffer_unmap - free DMA mapping(s) for an urb
1395 * @urb: urb whose transfer_buffer will be unmapped
1397 * Reverses the effect of usb_buffer_map().
1399 void usb_buffer_unmap (struct urb
*urb
)
1401 struct usb_bus
*bus
;
1402 struct device
*controller
;
1405 || !(urb
->transfer_flags
& URB_NO_DMA_MAP
)
1407 || !(bus
= urb
->dev
->bus
)
1408 || !(controller
= bus
->controller
))
1411 if (controller
->dma_mask
)
1412 dma_unmap_single (controller
,
1413 urb
->transfer_dma
, urb
->transfer_buffer_length
,
1414 usb_pipein (urb
->pipe
)
1415 ? DMA_FROM_DEVICE
: DMA_TO_DEVICE
);
1416 urb
->transfer_flags
&= ~URB_NO_DMA_MAP
;
1420 * usb_buffer_map_sg - create scatterlist DMA mapping(s) for an endpoint
1421 * @dev: device to which the scatterlist will be mapped
1422 * @pipe: endpoint defining the mapping direction
1423 * @sg: the scatterlist to map
1424 * @nents: the number of entries in the scatterlist
1426 * Return value is either < 0 (indicating no buffers could be mapped), or
1427 * the number of DMA mapping array entries in the scatterlist.
1429 * The caller is responsible for placing the resulting DMA addresses from
1430 * the scatterlist into URB transfer buffer pointers, and for setting the
1431 * URB_NO_DMA_MAP transfer flag in each of those URBs.
1433 * Top I/O rates come from queuing URBs, instead of waiting for each one
1434 * to complete before starting the next I/O. This is particularly easy
1435 * to do with scatterlists. Just allocate and submit one URB for each DMA
1436 * mapping entry returned, stopping on the first error or when all succeed.
1437 * Better yet, use the usb_sg_*() calls, which do that (and more) for you.
1439 * This call would normally be used when translating scatterlist requests,
1440 * rather than usb_buffer_map(), since on some hardware (with IOMMUs) it
1441 * may be able to coalesce mappings for improved I/O efficiency.
1443 * Reverse the effect of this call with usb_buffer_unmap_sg().
1445 int usb_buffer_map_sg (struct usb_device
*dev
, unsigned pipe
,
1446 struct scatterlist
*sg
, int nents
)
1448 struct usb_bus
*bus
;
1449 struct device
*controller
;
1452 || usb_pipecontrol (pipe
)
1453 || !(bus
= dev
->bus
)
1454 || !(controller
= bus
->controller
)
1455 || !controller
->dma_mask
)
1458 // FIXME generic api broken like pci, can't report errors
1459 return dma_map_sg (controller
, sg
, nents
,
1460 usb_pipein (pipe
) ? DMA_FROM_DEVICE
: DMA_TO_DEVICE
);
1464 * usb_buffer_dmasync_sg - synchronize DMA and CPU view of scatterlist buffer(s)
1465 * @dev: device to which the scatterlist will be mapped
1466 * @pipe: endpoint defining the mapping direction
1467 * @sg: the scatterlist to synchronize
1468 * @n_hw_ents: the positive return value from usb_buffer_map_sg
1470 * Use this when you are re-using a scatterlist's data buffers for
1471 * another USB request.
1473 void usb_buffer_dmasync_sg (struct usb_device
*dev
, unsigned pipe
,
1474 struct scatterlist
*sg
, int n_hw_ents
)
1476 struct usb_bus
*bus
;
1477 struct device
*controller
;
1480 || !(bus
= dev
->bus
)
1481 || !(controller
= bus
->controller
)
1482 || !controller
->dma_mask
)
1485 dma_sync_sg (controller
, sg
, n_hw_ents
,
1486 usb_pipein (pipe
) ? DMA_FROM_DEVICE
: DMA_TO_DEVICE
);
1490 * usb_buffer_unmap_sg - free DMA mapping(s) for a scatterlist
1491 * @dev: device to which the scatterlist will be mapped
1492 * @pipe: endpoint defining the mapping direction
1493 * @sg: the scatterlist to unmap
1494 * @n_hw_ents: the positive return value from usb_buffer_map_sg
1496 * Reverses the effect of usb_buffer_map_sg().
1498 void usb_buffer_unmap_sg (struct usb_device
*dev
, unsigned pipe
,
1499 struct scatterlist
*sg
, int n_hw_ents
)
1501 struct usb_bus
*bus
;
1502 struct device
*controller
;
1505 || !(bus
= dev
->bus
)
1506 || !(controller
= bus
->controller
)
1507 || !controller
->dma_mask
)
1510 dma_unmap_sg (controller
, sg
, n_hw_ents
,
1511 usb_pipein (pipe
) ? DMA_FROM_DEVICE
: DMA_TO_DEVICE
);
1515 struct bus_type usb_bus_type
= {
1517 .match
= usb_device_match
,
1518 .hotplug
= usb_hotplug
,
1523 static int __init
usb_setup_disable(char *str
)
1529 /* format to disable USB on kernel command line is: nousb */
1530 __setup("nousb", usb_setup_disable
);
1535 * for external read access to <nousb>
1537 int STDCALL
usb_disabled(void)
1545 int STDCALL __init
usb_init(void)
1548 info("USB support disabled\n");
1552 bus_register(&usb_bus_type
);
1557 driver_register(&usb_generic_driver
);
1565 void STDCALL __exit
usb_exit(void)
1567 /* This will matter if shutdown/reboot does exitcalls. */
1571 driver_unregister(&usb_generic_driver
);
1572 usb_major_cleanup();
1575 bus_unregister(&usb_bus_type
);
1578 subsys_initcall(usb_init
);
1579 module_exit(usb_exit
);
1582 * USB may be built into the kernel or be built as modules.
1583 * These symbols are exported for device (or host controller)
1584 * driver modules to use.
1586 EXPORT_SYMBOL(usb_epnum_to_ep_desc
);
1588 EXPORT_SYMBOL(usb_register
);
1589 EXPORT_SYMBOL(usb_deregister
);
1590 EXPORT_SYMBOL(usb_disabled
);
1592 EXPORT_SYMBOL(usb_device_probe
);
1593 EXPORT_SYMBOL(usb_device_remove
);
1595 EXPORT_SYMBOL(usb_alloc_dev
);
1596 EXPORT_SYMBOL(usb_put_dev
);
1597 EXPORT_SYMBOL(usb_get_dev
);
1598 EXPORT_SYMBOL(usb_hub_tt_clear_buffer
);
1600 EXPORT_SYMBOL(usb_driver_claim_interface
);
1601 EXPORT_SYMBOL(usb_interface_claimed
);
1602 EXPORT_SYMBOL(usb_driver_release_interface
);
1603 EXPORT_SYMBOL(usb_match_id
);
1604 EXPORT_SYMBOL(usb_find_interface
);
1605 EXPORT_SYMBOL(usb_ifnum_to_if
);
1607 EXPORT_SYMBOL(usb_new_device
);
1608 EXPORT_SYMBOL(usb_reset_device
);
1609 EXPORT_SYMBOL(usb_connect
);
1610 EXPORT_SYMBOL(usb_disconnect
);
1612 EXPORT_SYMBOL(__usb_get_extra_descriptor
);
1614 EXPORT_SYMBOL(usb_find_device
);
1615 EXPORT_SYMBOL(usb_get_current_frame_number
);
1617 EXPORT_SYMBOL (usb_buffer_alloc
);
1618 EXPORT_SYMBOL (usb_buffer_free
);
1620 EXPORT_SYMBOL (usb_buffer_map
);
1621 EXPORT_SYMBOL (usb_buffer_dmasync
);
1622 EXPORT_SYMBOL (usb_buffer_unmap
);
1624 EXPORT_SYMBOL (usb_buffer_map_sg
);
1625 EXPORT_SYMBOL (usb_buffer_dmasync_sg
);
1626 EXPORT_SYMBOL (usb_buffer_unmap_sg
);
1628 MODULE_LICENSE("GPL");