xref: /netbsd-src/share/man/man4/usb.4 (revision b1c86f5f087524e68db12794ee9c3e3da1ab17a0)
1.\" $NetBSD: usb.4,v 1.92 2010/03/22 18:58:31 joerg Exp $
2.\"
3.\" Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
4.\" All rights reserved.
5.\"
6.\" This code is derived from software contributed to The NetBSD Foundation
7.\" by Lennart Augustsson.
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
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.
17.\"
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.
29.\"
30.Dd March 25, 2008
31.Dt USB 4
32.Os
33.Sh NAME
34.Nm usb
35.Nd Universal Serial Bus driver
36.Sh SYNOPSIS
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"
49.Cd "uhub*   at usb?"
50.Cd "uhub*   at uhub? port ? configuration ? interface ? vendor ? product ? release ?"
51.Cd "XX*     at uhub? port ? configuration ? interface ? vendor ? product ? release ?"
52.Pp
53.Cd options USBVERBOSE
54.Pp
55.In dev/usb/usb.h
56.In dev/usb/usbhid.h
57.Sh DESCRIPTION
58.Nx
59provides machine-independent bus support and drivers for
60.Tn USB
61devices.
62.Pp
63The
64.Nx
65.Nm
66driver has three layers (like
67.Xr scsi 4
68and
69.Xr pcmcia 4 ) :
70the controller, the bus, and the device layer.
71The controller attaches to a physical bus (like
72.Xr pci 4 ) .
73The
74.Tn USB
75bus attaches to the controller and the root hub attaches
76to the bus.
77Further devices, which may include further hubs,
78attach to other hubs.
79The attachment forms the same tree structure as the physical
80.Tn USB
81device tree.
82For each
83.Tn USB
84device there may be additional drivers attached to it.
85.Pp
86The
87.Cm uhub
88device controls
89.Tn USB
90hubs and must always be present since there is at least a root hub in any
91.Tn USB
92system.
93.Pp
94The
95.Va flags
96argument to the
97.Va usb
98device affects the order in which the device detection happens
99during cold boot.
100Normally, only the USB host controller and the
101.Va usb
102device are detected during the autoconfiguration when the
103machine is booted.
104The rest of the devices are detected once
105the system becomes functional and the kernel thread for the
106.Va usb
107device is started.
108Sometimes it is desirable to have a device detected early in the
109boot process, e.g., the console keyboard.
110To achieve this use a
111.Va flags
112value of 1.
113.Pp
114.Nx
115supports the following machine-independent
116.Tn USB
117drivers:
118.Ss Storage devices
119.Bl -tag -width 12n -offset ind -compact
120.It Xr umass 4
121.Tn USB
122Mass Storage Devices, e.g., external disk drives
123.El
124.Ss Wired network interfaces
125.Bl -tag -width 12n -offset ind -compact
126.It Xr aue 4
127ADMtek AN986/ADM8511 Pegasus family 10/100 USB Ethernet device
128.It Xr axe 4
129ASIX Electronics AX88172/AX88178/AX88772 10/100/Gigabit USB Ethernet device
130.It Xr cdce 4
131USB Communication Device Class Ethernet device
132.It Xr cue 4
133CATC USB-EL1201A USB Ethernet device
134.It Xr kue 4
135Kawasaki LSI KL5KUSB101B USB Ethernet device
136.It Xr udav 4
137Davicom DM9601 10/100 USB Ethernet device
138.It Xr url 4
139Realtek RTL8150L 10/100 USB Ethernet device
140.El
141.Ss Wireless network interfaces
142.Bl -tag -width 12n -offset ind -compact
143.It Xr atu 4
144Atmel AT76C50x IEEE 802.11b wireless network device
145.It Xr ral 4
146Ralink Technology USB IEEE 802.11b/g wireless network device
147.It Xr rum 4
148Ralink Technology USB IEEE 802.11a/b/g wireless network device
149.It Xr ubt 4
150USB Bluetooth dongles
151.It Xr zyd 4
152ZyDAS ZD1211/ZD1211B USB IEEE 802.11b/g wireless network device
153.El
154.Ss Serial and parallel interfaces
155.Bl -tag -width 12n -offset ind -compact
156.It Xr ubsa 4
157Belkin USB serial adapter
158.It Xr uchcom 4
159WinChipHead CH341/340 based USB serial adapter
160.It Xr ucom 4
161USB tty support
162.It Xr ucycom 4
163Cypress microcontroller based USB serial adapter
164.It Xr uftdi 4
165FT8U100AX USB serial adapter
166.It Xr ugensa 4
167USB generic serial adapter
168.It Xr uhmodem 4
169USB Huawei 3G wireless modem device
170.It Xr uipaq 4
171iPAQ USB units
172.It Xr ukyopon 4
173USB Kyocera AIR-EDGE PHONE device
174.It Xr ulpt 4
175USB printer support
176.It Xr umct 4
177MCT USB-RS232 USB serial adapter
178.It Xr umodem 4
179USB modem support
180.It Xr uplcom 4
181Prolific PL-2303 USB serial adapter
182.It Xr uslsa 4
183Silicon Laboratories CP2101/CP2102 based USB serial adapter
184.It Xr uvisor 4
185USB Handspring Visor
186.It Xr uvscom 4
187SUNTAC Slipper U VS-10U USB serial adapter
188.El
189.Ss Audio devices
190.Bl -tag -width 12n -offset ind -compact
191.It Xr uaudio 4
192USB audio devices
193.It Xr umidi 4
194USB MIDI devices
195.It Xr urio 4
196Diamond Multimedia Rio MP3 players
197.El
198.Ss Radio receiver devices
199.Bl -tag -width 12n -offset ind -compact
200.It Xr udsbr 4
201D-Link DSB-R100 USB radio device
202.El
203.Ss Human Interface Devices
204.Bl -tag -width 12n -offset ind -compact
205.It Xr uhid 4
206Generic driver for Human Interface Devices
207.It Xr uhidev 4
208Base driver for all Human Interface Devices
209.It Xr ukbd 4
210.Tn USB
211keyboards that follow the boot protocol
212.It Xr ums 4
213.Tn USB
214mouse devices
215.El
216.Ss Miscellaneous devices
217.Bl -tag -width 12n -offset ind -compact
218.It Xr stuirda 4
219Sigmaltel 4116/4220 USB-IrDA bridge
220.It Xr uep 4
221USB eGalax touch-panel
222.It Xr ugen 4
223USB generic devices
224.It Xr uirda 4
225USB IrDA bridges
226.It Xr upl 4
227Prolific based host-to-host adapters
228.It Xr uscanner 4
229USB scanner support
230.It Xr usscanner 4
231SCSI-over-USB scanners
232.It Xr ustir 4
233SigmaTel STIr4200 USB IrDA bridges
234.It Xr utoppy 4
235Topfield TF5000PVR range of digital video recorders
236.It Xr uyap 4
237USB YAP phone firmware loader
238.El
239.Sh INTRODUCTION TO USB
240The
241.Tn USB
2421.x is a 12 Mb/s serial bus with 1.5 Mb/s for low speed devices.
243.Tn USB
2442.x handles 480 Mb/s.
245Each
246.Tn USB
247has a host controller that is the master of the bus;
248all other devices on the bus only speak when spoken to.
249.Pp
250There can be up to 127 devices (apart from the host controller)
251on a bus, each with its own address.
252The addresses are assigned
253dynamically by the host when each device is attached to the bus.
254.Pp
255Within each device there can be up to 16 endpoints.
256Each endpoint
257is individually addressed and the addresses are static.
258Each of these endpoints will communicate in one of four different modes:
259control, isochronous, bulk, or interrupt.
260A device always has at least one endpoint.
261This endpoint has address 0 and is a control
262endpoint and is used to give commands to and extract basic data,
263such as descriptors, from the device.
264Each endpoint, except the control endpoint, is unidirectional.
265.Pp
266The endpoints in a device are grouped into interfaces.
267An interface is a logical unit within a device; e.g.,
268a compound device with both a keyboard and a trackball would present
269one interface for each.
270An interface can sometimes be set into different modes,
271called alternate settings, which affects how it operates.
272Different alternate settings can have different endpoints
273within it.
274.Pp
275A device may operate in different configurations.
276Depending on the
277configuration the device may present different sets of endpoints
278and interfaces.
279.Pp
280Each device located on a hub has several
281.Xr config 1
282locators:
283.Bl -tag -compact -width xxxxxxxxx
284.It Cd port
285this is the number of the port on closest upstream hub.
286.It Cd configuration
287this is the configuration the device must be in for this driver to attach.
288This locator does not set the configuration; it is iterated by the bus
289enumeration.
290.It Cd interface
291this is the interface number within a device that an interface driver
292attaches to.
293.It Cd vendor
294this is the 16 bit vendor id of the device.
295.It Cd product
296this is the 16 bit product id of the device.
297.It Cd release
298this is the 16 bit release (revision) number of the device.
299.El
300The first locator can be used to pin down a particular device
301according to its physical position in the device tree.
302The last three locators can be used to pin down a particular
303device according to what device it actually is.
304.Pp
305The bus enumeration of the
306.Tn USB
307bus proceeds in several steps:
308.Bl -enum
309.It
310Any device specific driver can attach to the device.
311.It
312If none is found, any device class specific driver can attach.
313.It
314If none is found, all configurations are iterated over.
315For each configuration all the interface are iterated over and interface
316drivers can attach.
317If any interface driver attached in a certain
318configuration the iteration over configurations is stopped.
319.It
320If still no drivers have been found, the generic
321.Tn USB
322driver can attach.
323.El
324.Sh USB CONTROLLER INTERFACE
325Use the following to get access to the
326.Tn USB
327specific structures and defines.
328.Bd -literal
329#include \*[Lt]dev/usb/usb.h\*[Gt]
330.Ed
331.Pp
332The
333.Pa /dev/usbN
334can be opened and a few operations can be performed on it.
335The
336.Xr poll 2
337system call will say that I/O is possible on the controller device when a
338.Tn USB
339device has been connected or disconnected to the bus.
340.Pp
341The following
342.Xr ioctl 2
343commands 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"
351This command can be used to retrieve some information about a device
352on the bus.
353The
354.Va addr
355field should be filled before the call and the other fields will
356be filled by information about the device on that address.
357Should no such device exist an error is reported.
358.Bd -literal
359struct usb_device_info {
360	uint8_t	udi_bus;
361	uint8_t	udi_addr;
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];
365	char		udi_release[8];
366	char		udi_serial[USB_MAX_ENCODED_STRING_LEN];
367	uint16_t	udi_productNo;
368	uint16_t	udi_vendorNo;
369	uint16_t	udi_releaseNo;
370	uint8_t	udi_class;
371	uint8_t	udi_subclass;
372	uint8_t	udi_protocol;
373	uint8_t	udi_config;
374	uint8_t	udi_speed;
375#define USB_SPEED_LOW  1
376#define USB_SPEED_FULL 2
377#define USB_SPEED_HIGH 3
378	int		udi_power;
379	int		udi_nports;
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
386};
387.Ed
388.Pp
389The
390.Va product ,
391.Va vendor ,
392.Va release ,
393and
394.Va serial
395fields contain self-explanatory descriptions of the device.
396.Pp
397The
398.Va class
399field contains the device class.
400.Pp
401The
402.Va config
403field shows the current configuration of the device.
404.Pp
405The
406.Va lowspeed
407field
408is set if the device is a
409.Tn USB
410low speed device.
411.Pp
412The
413.Va power
414field shows the power consumption in milli-amps drawn at 5 volts,
415or zero if the device is self powered.
416.Pp
417If the device is a hub the
418.Va nports
419field is non-zero and the
420.Va ports
421field contains the addresses of the connected devices.
422If no device is connected to a port one of the
423.Va USB_PORT_*
424values indicates its status.
425.It Dv USB_DEVICESTATS Fa "struct usb_device_stats"
426This command retrieves statistics about the controller.
427.Bd -literal
428struct usb_device_stats {
429	u_long	uds_requests[4];
430};
431.Ed
432.Pp
433The
434.Va requests
435field is indexed by the transfer kind, i.e.
436.Va UE_* ,
437and indicates how many transfers of each kind have been completed
438by the controller.
439.It Dv USB_REQUEST Fa "struct usb_ctl_request"
440This command can be used to execute arbitrary requests on the control pipe.
441This is
442.Em DANGEROUS
443and should be used with great care since it
444can destroy the bus integrity.
445.El
446.Pp
447The include file
448.In dev/usb/usb.h
449contains definitions for the types used by the various
450.Xr ioctl 2
451calls.
452The naming convention of the fields for the various
453.Tn USB
454descriptors exactly follows the naming in the
455.Tn USB
456specification.
457Byte sized fields can be accessed directly, but word (16 bit)
458sized fields must be access by the
459.Fn UGETW field
460and
461.Fn USETW field value
462macros to handle byte order and alignment properly.
463.Pp
464The include file
465.In dev/usb/usbhid.h
466similarly contains the definitions for
467Human Interface Devices
468.Pq Tn HID .
469.Sh USB EVENT INTERFACE
470All
471.Tn USB
472events are reported via the
473.Pa /dev/usb
474device.
475This devices can be opened for reading and each
476.Xr read 2
477will yield an event record (if something has happened).
478The
479.Xr poll 2
480system call can be used to determine if an event record is available
481for reading.
482.Pp
483The event record has the following definition:
484.Bd -literal
485struct usb_event {
486        int                                 ue_type;
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;
494        union {
495                struct {
496                        int                 ue_bus;
497                } ue_ctrlr;
498                struct usb_device_info      ue_device;
499                struct {
500                        usb_event_cookie_t  ue_cookie;
501                        char                ue_devname[16];
502                } ue_driver;
503        } u;
504};
505.Ed
506.Pp
507The
508.Va ue_type
509field identifies the type of event that is described.
510The possible events are attach/detach of a host controller,
511a device, or a device driver.
512The union contains information
513pertinent to the different types of events.
514.Pp
515The
516.Va ue_bus
517contains the number of the
518.Tn USB
519bus for host controller events.
520.Pp
521The
522.Va ue_device
523record contains information about the device in a device event event.
524.Pp
525The
526.Va ue_cookie
527is an opaque value that uniquely determines which
528device a device driver has been attached to (i.e., it equals
529the cookie value in the device that the driver attached to).
530The
531.Va ue_devname
532contains the name of the device (driver) as seen in, e.g.,
533kernel messages.
534.Pp
535Note that there is a separation between device and device
536driver events.
537A device event is generated when a physical
538USB device is attached or detached.
539A single USB device may
540have zero, one, or many device drivers associated with it.
541.Sh KERNEL THREADS
542For each USB bus, i.e., for each host controller, there is
543a kernel thread that handles attach and detach of devices on
544that bus.
545The thread is named
546.Va usbN
547where
548.Va N
549is the bus number.
550.Pp
551In addition there is a kernel thread,
552.Va usbtask ,
553which handles various minor tasks that are initiated from
554an interrupt context, but need to sleep, e.g., time-out
555abort of transfers.
556.Sh SEE ALSO
557The
558.Tn USB
559specifications can be found at:
560.D1 http://www.usb.org/developers/docs/
561.Pp
562.Xr usbhidaction 1 ,
563.Xr usbhidctl 1 ,
564.Xr cardbus 4 ,
565.Xr ehci 4 ,
566.Xr isa 4 ,
567.Xr ohci 4 ,
568.Xr pci 4 ,
569.Xr pcmcia 4 ,
570.Xr slhci 4 ,
571.Xr uhci 4 ,
572.Xr usbdevs 8
573.Sh HISTORY
574The
575.Nm
576driver
577appeared in
578.Nx 1.4 .
579.Sh BUGS
580There should be a serial number locator, but
581.Nx
582does not have string valued locators.
583