xref: /netbsd-src/share/man/man4/usb.4 (revision 1ffa7b76c40339c17a0fb2a09fac93f287cfc046)
1.\" $NetBSD: usb.4,v 1.61 2003/03/30 17:26:51 wiz Exp $
2.\"
3.\" Copyright (c) 1999, 2000, 2001, 2002 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.\" 3. All advertising materials mentioning features or use of this software
18.\"    must display the following acknowledgement:
19.\"        This product includes software developed by the NetBSD
20.\"        Foundation, Inc. and its contributors.
21.\" 4. Neither the name of The NetBSD Foundation nor the names of its
22.\"    contributors may be used to endorse or promote products derived
23.\"    from this software without specific prior written permission.
24.\"
25.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
26.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
29.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35.\" POSSIBILITY OF SUCH DAMAGE.
36.\"
37.Dd September 27, 2002
38.Dt USB 4
39.Os
40.Sh NAME
41.Nm usb
42.Nd Universal Serial Bus driver
43.Sh SYNOPSIS
44.Cd "ehci*   at cardbus? dev ? function ?"
45.Cd "ehci*   at pci? dev ? function ?"
46.Cd "ohci*   at cardbus? dev ? function ?"
47.Cd "ohci*   at pci? dev ? function ?"
48.Cd "slhci*  at isa? port ? irq ?"
49.Cd "uhci*   at pci? dev ? function ?"
50.Cd "usb*    at ehci? flags X"
51.Cd "usb*    at ohci? flags X"
52.Cd "usb*    at uhci? flags X"
53.Cd "usb*    at slhci? flags X"
54.Cd "uhub*   at usb?"
55.Cd "uhub*   at uhub? port ? configuration ? interface ? vendor ? product ? release ?"
56.Cd "XX*     at uhub? port ? configuration ? interface ? vendor ? product ? release ?"
57.Pp
58.Cd options USBVERBOSE
59.Pp
60.Cd "#include \*[Lt]dev/usb/usb.h\*[Gt]"
61.Cd "#include \*[Lt]dev/usb/usbhid.h\*[Gt]"
62.Sh DESCRIPTION
63.Nx
64provides machine-independent bus support and drivers for
65.Tn USB
66devices.
67.Pp
68The
69.Nx
70.Nm
71driver has three layers (like
72.Xr scsi 4
73and
74.Xr pcmcia 4 ) :
75the controller, the bus, and the device layer.
76The controller attaches to a physical bus (like
77.Xr pci 4 ) .
78The
79.Tn USB
80bus attaches to the controller and the root hub attaches
81to the bus.
82Further devices, which may include further hubs,
83attach to other hubs.
84The attachment forms the same tree structure as the physical
85.Tn USB
86device tree.
87For each
88.Tn USB
89device there may be additional drivers attached to it.
90.Pp
91The
92.Cm uhub
93device controls
94.Tn USB
95hubs and must always be present since there is at least a root hub in any
96.Tn USB
97system.
98.Pp
99The
100.Va flags
101argument to the
102.Va usb
103device affects the order in which the device detection happens
104during cold boot.
105Normally, only the USB host controller and the
106.Va usb
107device are detected during the autoconfiguration when the
108machine is booted.  The rest of the devices are detected once
109the system becomes functional and the kernel thread for the
110.Va usb
111device is started.
112Sometimes it is desirable to have a device detected early in the
113boot process, e.g., the console keyboard.  To achieve this use
114a
115.Va flags
116value of 1.
117.Sh SUPPORTED DEVICES
118.Nx
119includes machine-independent
120.Tn USB
121drivers, sorted by driver name:
122.Bl -tag -width usscanner -offset indent
123.It aue
124driver for ADMtek AN986 Pegasus USB Ethernet.
125.It cue
126driver for CATC USB-EL1201A USB Ethernet.
127.It kue
128driver for Kawasaki LSI KL5KUSB101B USB Ethernet.
129.It uaudio
130driver for audio devices.
131.It uax
132driver for ASIX AX88172 USB Ethernet.
133.It ubsa
134driver for Belkin serial adapters.
135.It udsbr
136driver for D-Link DSB-R100 USB radio.
137.It uftdi
138driver for FTDI based serial adapters.
139.It ugen
140generic driver for
141.Tn USB
142devices.
143.It uhid
144generic driver for Human Interface Devices.
145.It uhidev
146top level HID driver.
147.It uirda
148driver for USB-IrDA bridges.
149.It ukbd
150keyboard driver.
151.It ulpt
152printer driver.
153.It umass
154driver for mass storage devices, such as disks.
155.It umct
156driver for MCT USB RS-232 serial adapter.
157.It umidi
158driver for MIDI devices.
159.It umodem
160driver for communication devices that use the Abstract Control Model.
161.It ums
162mouse driver.
163.It upl
164driver for
165.Tn Prolific
166host-to-host adapter.
167.It uplcom
168driver for Prolific 2303 serial adapter.
169.It urio
170driver for the
171.Tn Diamond
172Rio 500 MP3 player.
173.It url
174driver for Realtek RTL8150L USB Ethernet.
175.It uscanner
176driver for some USB scanners.
177.It usscanner
178driver for some SCSI-over-USB scanners.
179.It ustir
180driver for SigmaTel STIr4200 USB-IrDA bridges.
181.It uvisor
182Handspring Visor driver.
183.It uvscom
184driver for SUNTAC Slipper U VS-10U serial adapter.
185.El
186.Sh INTRODUCTION TO USB
187The
188.Tn USB
1891.x is a 12 Mb/s serial bus with 1.5 Mb/s for low speed devices.
190.Tn USB
1912.x handles 480 Mb/s.
192Each
193.Tn USB
194has a host controller that is the master of the bus;
195all other devices on the bus only speak when spoken to.
196.Pp
197There can be up to 127 devices (apart from the host controller)
198on a bus, each with its own address.
199The addresses are assigned
200dynamically by the host when each device is attached to the bus.
201.Pp
202Within each device there can be up to 16 endpoints.
203Each endpoint
204is individually addressed and the addresses are static.
205Each of these endpoints will communicate in one of four different modes:
206control, isochronous, bulk, or interrupt.
207A device always has at least one endpoint.
208This endpoint has address 0 and is a control
209endpoint and is used to give commands to and extract basic data,
210such as descriptors, from the device.
211Each endpoint, except the control endpoint, is unidirectional.
212.Pp
213The endpoints in a device are grouped into interfaces.
214An interface is a logical unit within a device; e.g.,
215a compound device with both a keyboard and a trackball would present
216one interface for each.
217An interface can sometimes be set into different modes,
218called alternate settings, which affects how it operates.
219Different alternate settings can have different endpoints
220within it.
221.Pp
222A device may operate in different configurations.
223Depending on the
224configuration the device may present different sets of endpoints
225and interfaces.
226.Pp
227Each device located on a hub has several
228.Xr config 8
229locators:
230.Bl -tag -compact -width xxxxxxxxx
231.It Cd port
232this is the number of the port on closest upstream hub.
233.It Cd configuration
234this is the configuration the device must be in for this driver to attach.
235This locator does not set the configuration; it is iterated by the bus
236enumeration.
237.It Cd interface
238this is the interface number within a device that an interface driver
239attaches to.
240.It Cd vendor
241this is the 16 bit vendor id of the device.
242.It Cd product
243this is the 16 bit product id of the device.
244.It Cd release
245this is the 16 bit release (revision) number of the device.
246.El
247The first locator can be used to pin down a particular device
248according to its physical position in the device tree.
249The last three locators can be used to pin down a particular
250device according to what device it actually is.
251.Pp
252The bus enumeration of the
253.Tn USB
254bus proceeds in several steps:
255.Bl -enum
256.It
257Any device specific driver can to attach to the device.
258.It
259If none is found, any device class specific driver can attach.
260.It
261If none is found, all configurations are iterated over.
262For each configuration all the interface are iterated over and interface
263drivers can attach.
264If any interface driver attached in a certain
265configuration the iteration over configurations is stopped.
266.It
267If still no drivers have been found, the generic
268.Tn USB
269driver can attach.
270.El
271.Sh USB CONTROLLER INTERFACE
272Use the following to get access to the
273.Tn USB
274specific structures and defines.
275.Bd -literal
276#include \*[Lt]sys/dev/usb.h\*[Gt]
277.Ed
278.Pp
279The
280.Pa /dev/usbN
281can be opened and a few operations can be performed on it.
282The
283.Xr poll 2
284system call will say that I/O is possible on the controller device when a
285.Tn USB
286device has been connected or disconnected to the bus.
287.Pp
288The following
289.Xr ioctl 2
290commands are supported on the controller device:
291.Bl -tag -width xxxxxx
292.\" .It Dv USB_DISCOVER
293.\" This command will cause a complete bus discovery to be initiated.
294.\" If any devices attached or detached from the bus they will be
295.\" processed during this command.
296.\" This is the only way that new devices are found on the bus.
297.It Dv USB_DEVICEINFO Fa "struct usb_device_info"
298This command can be used to retrieve some information about a device
299on the bus.
300The
301.Va addr
302field should be filled before the call and the other fields will
303be filled by information about the device on that address.
304Should no such device exist an error is reported.
305.Bd -literal
306struct usb_device_info {
307	u_int8_t	bus;
308	u_int8_t	addr;
309	usb_event_cookie_t cookie;
310	char		product[USB_MAX_STRING_LEN];
311	char		vendor[USB_MAX_STRING_LEN];
312	char		release[8];
313	u_int16_t	productNo;
314	u_int16_t	vendorNo;
315	u_int16_t	releaseNo;
316	u_int8_t	class;
317	u_int8_t	subclass;
318	u_int8_t	protocol;
319	u_int8_t	config;
320	u_int8_t	lowspeed;
321	int		power;
322	int		nports;
323	char		devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
324	u_int8_t	ports[16];
325#define USB_PORT_ENABLED 0xff
326#define USB_PORT_SUSPENDED 0xfe
327#define USB_PORT_POWERED 0xfd
328#define USB_PORT_DISABLED 0xfc
329};
330.Ed
331.Pp
332The
333.Va product ,
334.Va vendor ,
335and
336.Va release
337fields contain self-explanatory descriptions of the device.
338.Pp
339The
340.Va class
341field contains the device class.
342.Pp
343The
344.Va config
345field shows the current configuration of the device.
346.Pp
347The
348.Va lowspeed
349field
350is set if the device is a
351.Tn USB
352low speed device.
353.Pp
354The
355.Va power
356field shows the power consumption in milli-amps drawn at 5 volts,
357or zero if the device is self powered.
358.Pp
359If the device is a hub the
360.Va nports
361field is non-zero and the
362.Va ports
363field contains the addresses of the connected devices.
364If no device is connected to a port one of the
365.Va USB_PORT_*
366values indicates its status.
367.It Dv USB_DEVICESTATS Fa "struct usb_device_stats"
368This command retrieves statistics about the controller.
369.Bd -literal
370struct usb_device_stats {
371	u_long	requests[4];
372};
373.Ed
374.Pp
375The
376.Va requests
377field is indexed by the transfer kind, i.e.
378.Va UE_* ,
379and indicates how many transfers of each kind that has been completed
380by the controller.
381.It Dv USB_REQUEST Fa "struct usb_ctl_request"
382This command can be used to execute arbitrary requests on the control pipe.
383This is
384.Em DANGEROUS
385and should be used with great care since it
386can destroy the bus integrity.
387.El
388.Pp
389The include file
390.Aq Pa dev/usb/usb.h
391contains definitions for the types used by the various
392.Xr ioctl 2
393calls.
394The naming convention of the fields for the various
395.Tn USB
396descriptors exactly follows the naming in the
397.Tn USB
398specification.
399Byte sized fields can be accessed directly, but word (16 bit)
400sized fields must be access by the
401.Fn UGETW field
402and
403.Fn USETW field value
404macros to handle byte order and alignment properly.
405.Pp
406The include file
407.Aq Pa dev/usb/usbhid.h
408similarly contains the definitions for
409Human Interface Devices
410.Pq Tn HID .
411.Sh USB EVENT INTERFACE
412All
413.Tn USB
414events are reported via the
415.Pa /dev/usb
416device.  This devices can be opened for reading and each
417.Xr read 2
418will yield an event record (if something has happened).
419The
420.Xr poll 2
421system call can be used to determine if an event record is available
422for reading.
423.Pp
424The event record has the following definition:
425.Bd -literal
426struct usb_event {
427        int                                 ue_type;
428#define USB_EVENT_CTRLR_ATTACH 1
429#define USB_EVENT_CTRLR_DETACH 2
430#define USB_EVENT_DEVICE_ATTACH 3
431#define USB_EVENT_DEVICE_DETACH 4
432#define USB_EVENT_DRIVER_ATTACH 5
433#define USB_EVENT_DRIVER_DETACH 6
434        struct timespec                     ue_time;
435        union {
436                struct {
437                        int                 ue_bus;
438                } ue_ctrlr;
439                struct usb_device_info      ue_device;
440                struct {
441                        usb_event_cookie_t  ue_cookie;
442                        char                ue_devname[16];
443                } ue_driver;
444        } u;
445};
446.Ed
447The
448.Va ue_type
449field identifies the type of event that is described.
450The possible events are attach/detach of a host controller,
451a device, or a device driver.  The union contains information
452pertinent to the different types of events.
453.br
454The
455.Va ue_bus
456contains the number of the
457.Tn USB
458bus for host controller events.
459.br
460The
461.Va ue_device
462record contains information about the device in a device event event.
463.br
464The
465.Va ue_cookie
466is an opaque value that uniquely determines which which
467device a device driver has been attached to (i.e., it equals
468the cookie value in the device that the driver attached to).
469The
470.Va ue_devname
471contains the name of the device (driver) as seen in, e.g.,
472kernel messages.
473.Pp
474Note that that there is a separation between device and device
475driver events.  A device event is generated when a physical
476USB device is attached or detached.  A single USB device may
477have zero, one, or many device drivers associated with it.
478.Sh SEE ALSO
479The
480.Tn USB
481specifications can be found at:
482.D1 http://www.usb.org/developers/docs.html
483.Pp
484.Xr aue 4 ,
485.Xr cardbus 4 ,
486.Xr cue 4 ,
487.Xr ehci 4 ,
488.Xr isa 4 ,
489.Xr kue 4 ,
490.Xr ohci 4 ,
491.Xr pci 4 ,
492.Xr slhci 4 ,
493.Xr uaudio 4 ,
494.Xr uax 4 ,
495.Xr ubsa 4 ,
496.Xr ucom 4 ,
497.Xr udsbr 4 ,
498.Xr ugen 4 ,
499.Xr uhci 4 ,
500.Xr uhid 4 ,
501.Xr uhidev 4 ,
502.Xr uirda 4 ,
503.Xr ukbd 4 ,
504.Xr ulpt 4 ,
505.Xr umass 4 ,
506.Xr umct 4 ,
507.Xr umidi 4 ,
508.Xr ums 4 ,
509.Xr upl 4 ,
510.Xr urio 4 ,
511.Xr url 4 ,
512.Xr uscanner 4 ,
513.Xr usscanner 4 ,
514.Xr ustir 4 ,
515.Xr uvisor 4 ,
516.Xr usbdevs 8
517.Sh HISTORY
518The
519.Nm
520driver
521appeared in
522.Nx 1.4 .
523.Sh BUGS
524There should be a serial number locator, but
525.Nx
526does not have string valued locators.
527