1 .\" $NetBSD: usb.4,v 1.90 2009/05/04 20:42:34 wiz Exp $
3 .\" Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
7 .\" by Lennart Augustsson.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
35 .Nd Universal Serial Bus driver
37 .Cd "ehci* at cardbus? function ?"
38 .Cd "ehci* at pci? dev ? function ?"
39 .Cd "ohci* at cardbus? function ?"
40 .Cd "ohci* at pci? dev ? function ?"
41 .Cd "slhci* at isa? port ? irq ?"
42 .Cd "slhci* at pcmcia? function ?"
43 .Cd "uhci* at cardbus? function ?"
44 .Cd "uhci* at pci? dev ? function ?"
45 .Cd "usb* at ehci? flags X"
46 .Cd "usb* at ohci? flags X"
47 .Cd "usb* at uhci? flags X"
48 .Cd "usb* at slhci? flags X"
50 .Cd "uhub* at uhub? port ? configuration ? interface ? vendor ? product ? release ?"
51 .Cd "XX* at uhub? port ? configuration ? interface ? vendor ? product ? release ?"
53 .Cd options USBVERBOSE
59 provides machine-independent bus support and drivers for
66 driver has three layers (like
70 the controller, the bus, and the device layer.
71 The controller attaches to a physical bus (like
75 bus attaches to the controller and the root hub attaches
77 Further devices, which may include further hubs,
79 The attachment forms the same tree structure as the physical
84 device there may be additional drivers attached to it.
90 hubs and must always be present since there is at least a root hub in any
98 device affects the order in which the device detection happens
100 Normally, only the USB host controller and the
102 device are detected during the autoconfiguration when the
104 The rest of the devices are detected once
105 the system becomes functional and the kernel thread for the
108 Sometimes it is desirable to have a device detected early in the
109 boot process, e.g., the console keyboard.
110 To achieve this use a
115 supports the following machine-independent
119 .Bl -tag -width 12n -offset ind -compact
122 Mass Storage Devices, e.g., external disk drives
124 .Ss Wired network interfaces
125 .Bl -tag -width 12n -offset ind -compact
127 ADMtek AN986/ADM8511 Pegasus family 10/100 USB Ethernet device
129 ASIX Electronics AX88172/AX88178/AX88772 10/100/Gigabit USB Ethernet device
131 USB Communication Device Class Ethernet device
133 CATC USB-EL1201A USB Ethernet device
135 Kawasaki LSI KL5KUSB101B USB Ethernet device
137 Davicom DM9601 10/100 USB Ethernet device
139 Realtek RTL8150L 10/100 USB Ethernet device
141 .Ss Wireless network interfaces
142 .Bl -tag -width 12n -offset ind -compact
144 Atmel AT76C50x IEEE 802.11b wireless network device
146 Ralink Technology USB IEEE 802.11b/g wireless network device
148 Ralink Technology USB IEEE 802.11a/b/g wireless network device
150 USB Bluetooth dongles
152 ZyDAS ZD1211/ZD1211B USB IEEE 802.11b/g wireless network device
154 .Ss Serial and parallel interfaces
155 .Bl -tag -width 12n -offset ind -compact
157 Belkin USB serial adapter
159 WinChipHead CH341/340 based USB serial adapter
163 Cypress microcontroller based USB serial adapter
165 FT8U100AX USB serial adapter
167 USB generic serial adapter
169 USB Huawei 3G wireless modem device
173 USB Kyocera AIR-EDGE PHONE device
177 MCT USB-RS232 USB serial adapter
181 Prolific PL-2303 USB serial adapter
183 Silicon Laboratories CP2101/CP2102 based USB serial adapter
187 SUNTAC Slipper U VS-10U USB serial adapter
190 .Bl -tag -width 12n -offset ind -compact
196 Diamond Multimedia Rio MP3 players
198 .Ss Radio receiver devices
199 .Bl -tag -width 12n -offset ind -compact
201 D-Link DSB-R100 USB radio device
203 .Ss Human Interface Devices
204 .Bl -tag -width 12n -offset ind -compact
206 Generic driver for Human Interface Devices
208 Base driver for all Human Interface Devices
211 keyboards that follow the boot protocol
216 .Ss Miscellaneous devices
217 .Bl -tag -width 12n -offset ind -compact
219 Sigmaltel 4116/4220 USB-IrDA bridge
221 USB eGalax touch-panel
227 Prolific based host-to-host adapters
231 SCSI-over-USB scanners
233 SigmaTel STIr4200 USB IrDA bridges
235 Topfield TF5000PVR range of digital video recorders
237 USB YAP phone firmware loader
239 .Sh INTRODUCTION TO USB
242 1.x is a 12 Mb/s serial bus with 1.5 Mb/s for low speed devices.
244 2.x handles 480 Mb/s.
247 has a host controller that is the master of the bus;
248 all other devices on the bus only speak when spoken to.
250 There can be up to 127 devices (apart from the host controller)
251 on a bus, each with its own address.
252 The addresses are assigned
253 dynamically by the host when each device is attached to the bus.
255 Within each device there can be up to 16 endpoints.
257 is individually addressed and the addresses are static.
258 Each of these endpoints will communicate in one of four different modes:
259 control, isochronous, bulk, or interrupt.
260 A device always has at least one endpoint.
261 This endpoint has address 0 and is a control
262 endpoint and is used to give commands to and extract basic data,
263 such as descriptors, from the device.
264 Each endpoint, except the control endpoint, is unidirectional.
266 The endpoints in a device are grouped into interfaces.
267 An interface is a logical unit within a device; e.g.,
268 a compound device with both a keyboard and a trackball would present
269 one interface for each.
270 An interface can sometimes be set into different modes,
271 called alternate settings, which affects how it operates.
272 Different alternate settings can have different endpoints
275 A device may operate in different configurations.
277 configuration the device may present different sets of endpoints
280 Each device located on a hub has several
283 .Bl -tag -compact -width xxxxxxxxx
285 this is the number of the port on closest upstream hub.
287 this is the configuration the device must be in for this driver to attach.
288 This locator does not set the configuration; it is iterated by the bus
291 this is the interface number within a device that an interface driver
294 this is the 16 bit vendor id of the device.
296 this is the 16 bit product id of the device.
298 this is the 16 bit release (revision) number of the device.
300 The first locator can be used to pin down a particular device
301 according to its physical position in the device tree.
302 The last three locators can be used to pin down a particular
303 device according to what device it actually is.
305 The bus enumeration of the
307 bus proceeds in several steps:
310 Any device specific driver can attach to the device.
312 If none is found, any device class specific driver can attach.
314 If none is found, all configurations are iterated over.
315 For each configuration all the interface are iterated over and interface
317 If any interface driver attached in a certain
318 configuration the iteration over configurations is stopped.
320 If still no drivers have been found, the generic
324 .Sh USB CONTROLLER INTERFACE
325 Use the following to get access to the
327 specific structures and defines.
329 #include \*[Lt]dev/usb/usb.h\*[Gt]
334 can be opened and a few operations can be performed on it.
337 system call will say that I/O is possible on the controller device when a
339 device has been connected or disconnected to the bus.
343 commands are supported on the controller device:
344 .Bl -tag -width xxxxxx
345 .\" .It Dv USB_DISCOVER
346 .\" This command will cause a complete bus discovery to be initiated.
347 .\" If any devices attached or detached from the bus they will be
348 .\" processed during this command.
349 .\" This is the only way that new devices are found on the bus.
350 .It Dv USB_DEVICEINFO Fa "struct usb_device_info"
351 This command can be used to retrieve some information about a device
355 field should be filled before the call and the other fields will
356 be filled by information about the device on that address.
357 Should no such device exist an error is reported.
359 struct usb_device_info {
362 usb_event_cookie_t udi_cookie;
363 char udi_product[USB_MAX_ENCODED_STRING_LEN];
364 char udi_vendor[USB_MAX_ENCODED_STRING_LEN];
366 char udi_serial[USB_MAX_ENCODED_STRING_LEN];
367 uint16_t udi_productNo;
368 uint16_t udi_vendorNo;
369 uint16_t udi_releaseNo;
371 uint8_t udi_subclass;
372 uint8_t udi_protocol;
375 #define USB_SPEED_LOW 1
376 #define USB_SPEED_FULL 2
377 #define USB_SPEED_HIGH 3
380 char udi_devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
381 uint8_t udi_ports[16];
382 #define USB_PORT_ENABLED 0xff
383 #define USB_PORT_SUSPENDED 0xfe
384 #define USB_PORT_POWERED 0xfd
385 #define USB_PORT_DISABLED 0xfc
395 fields contain self-explanatory descriptions of the device.
399 field contains the device class.
403 field shows the current configuration of the device.
408 is set if the device is a
414 field shows the power consumption in milli-amps drawn at 5 volts,
415 or zero if the device is self powered.
417 If the device is a hub the
419 field is non-zero and the
421 field contains the addresses of the connected devices.
422 If no device is connected to a port one of the
424 values indicates its status.
425 .It Dv USB_DEVICESTATS Fa "struct usb_device_stats"
426 This command retrieves statistics about the controller.
428 struct usb_device_stats {
429 u_long uds_requests[4];
435 field is indexed by the transfer kind, i.e.
437 and indicates how many transfers of each kind have been completed
439 .It Dv USB_REQUEST Fa "struct usb_ctl_request"
440 This command can be used to execute arbitrary requests on the control pipe.
443 and should be used with great care since it
444 can destroy the bus integrity.
449 contains definitions for the types used by the various
452 The naming convention of the fields for the various
454 descriptors exactly follows the naming in the
457 Byte sized fields can be accessed directly, but word (16 bit)
458 sized fields must be access by the
461 .Fn USETW field value
462 macros to handle byte order and alignment properly.
465 .Aq Pa dev/usb/usbhid.h
466 similarly contains the definitions for
467 Human Interface Devices
469 .Sh USB EVENT INTERFACE
472 events are reported via the
475 This devices can be opened for reading and each
477 will yield an event record (if something has happened).
480 system call can be used to determine if an event record is available
483 The event record has the following definition:
487 #define USB_EVENT_CTRLR_ATTACH 1
488 #define USB_EVENT_CTRLR_DETACH 2
489 #define USB_EVENT_DEVICE_ATTACH 3
490 #define USB_EVENT_DEVICE_DETACH 4
491 #define USB_EVENT_DRIVER_ATTACH 5
492 #define USB_EVENT_DRIVER_DETACH 6
493 struct timespec ue_time;
498 struct usb_device_info ue_device;
500 usb_event_cookie_t ue_cookie;
509 field identifies the type of event that is described.
510 The possible events are attach/detach of a host controller,
511 a device, or a device driver.
512 The union contains information
513 pertinent to the different types of events.
517 contains the number of the
519 bus for host controller events.
523 record contains information about the device in a device event event.
527 is an opaque value that uniquely determines which
528 device a device driver has been attached to (i.e., it equals
529 the cookie value in the device that the driver attached to).
532 contains the name of the device (driver) as seen in, e.g.,
535 Note that there is a separation between device and device
537 A device event is generated when a physical
538 USB device is attached or detached.
539 A single USB device may
540 have zero, one, or many device drivers associated with it.
542 For each USB bus, i.e., for each host controller, there is
543 a kernel thread that handles attach and detach of devices on
551 In addition there is a kernel thread,
553 which handles various minor tasks that are initiated from
554 an interrupt context, but need to sleep, e.g., time-out
559 specifications can be found at:
560 .D1 http://www.usb.org/developers/docs/
580 There should be a serial number locator, but
582 does not have string valued locators.