xref: /freebsd/share/man/man4/usb.4 (revision a31999ca51d72a54f719da540a4d13c5ca72cdd2)
1b2c1f437SNick Hibma.\" Copyright (c) 1997, 1998
2eddc45e7SJeroen Ruigrok van der Werven.\"	Nick Hibma <n_hibma@FreeBSD.org>. All rights reserved.
3b2c1f437SNick Hibma.\"
4b2c1f437SNick Hibma.\" Redistribution and use in source and binary forms, with or without
5b2c1f437SNick Hibma.\" modification, are permitted provided that the following conditions
6b2c1f437SNick Hibma.\" are met:
7b2c1f437SNick Hibma.\" 1. Redistributions of source code must retain the above copyright
8b2c1f437SNick Hibma.\"    notice, this list of conditions and the following disclaimer.
9b2c1f437SNick Hibma.\" 2. Redistributions in binary form must reproduce the above copyright
10b2c1f437SNick Hibma.\"    notice, this list of conditions and the following disclaimer in the
11b2c1f437SNick Hibma.\"    documentation and/or other materials provided with the distribution.
12b2c1f437SNick Hibma.\" 3. All advertising materials mentioning features or use of this software
13b2c1f437SNick Hibma.\"    must display the following acknowledgement:
14b2c1f437SNick Hibma.\"	This product includes software developed by Bill Paul.
15b2c1f437SNick Hibma.\" 4. Neither the name of the author nor the names of any co-contributors
16b2c1f437SNick Hibma.\"    may be used to endorse or promote products derived from this software
17b2c1f437SNick Hibma.\"   without specific prior written permission.
18b2c1f437SNick Hibma.\"
19b2c1f437SNick Hibma.\" THIS SOFTWARE IS PROVIDED BY NICK HIBMA AND CONTRIBUTORS ``AS IS'' AND
20b2c1f437SNick Hibma.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21b2c1f437SNick Hibma.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22b2c1f437SNick Hibma.\" ARE DISCLAIMED.  IN NO EVENT SHALL NICK HIBMA OR THE VOICES IN HIS HEAD
23b2c1f437SNick Hibma.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24b2c1f437SNick Hibma.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25b2c1f437SNick Hibma.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26b2c1f437SNick Hibma.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27b2c1f437SNick Hibma.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28b2c1f437SNick Hibma.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
29b2c1f437SNick Hibma.\" THE POSSIBILITY OF SUCH DAMAGE.
30b2c1f437SNick Hibma.\"
317f3dea24SPeter Wemm.\" $FreeBSD$
32b2c1f437SNick Hibma.\"
33b2c1f437SNick Hibma.Dd February 21, 1999
34474fc32bSAlexey Zelkin.Dt USB 4
353d45e180SRuslan Ermilov.Os
36b2c1f437SNick Hibma.Sh NAME
37b2c1f437SNick Hibma.Nm usb
38b2c1f437SNick Hibma.Nd Universal Serial Bus
39b2c1f437SNick Hibma.Sh SYNOPSIS
40b9781e20SJeroen Ruigrok van der Werven.Cd "device usb"
41a31999caSJosef Karthauser.Pp
42a31999caSJosef Karthauser.Cd "#include <dev/usb/usb.h>"
43a31999caSJosef Karthauser.Cd "#include <dev/usb/usbhid.h>"
44b2c1f437SNick Hibma.Sh DESCRIPTION
45d4be94a1SChris Costello.Fx
46b2c1f437SNick Hibmaprovides machine-independent bus support and drivers for
47b2c1f437SNick Hibma.Tn USB
48b2c1f437SNick Hibmadevices.
49b2c1f437SNick Hibma.Pp
50b2c1f437SNick HibmaThe
51b2c1f437SNick Hibma.Nm
52b2c1f437SNick Hibmadriver has three layers: the controller, the bus, and the
536d249eeeSSheldon Hearndevice layer.
546d249eeeSSheldon HearnThe controller attaches to a physical bus
55b2c1f437SNick Hibma(like
56b2c1f437SNick Hibma.Xr pci 4 ) .
57b2c1f437SNick HibmaThe
58b2c1f437SNick Hibma.Tn USB
59b2c1f437SNick Hibmabus attaches to the controller and the root hub attaches
60b2c1f437SNick Hibmato the controller.
61b2c1f437SNick HibmaAny devices attached to the bus will attach to the root hub
62b2c1f437SNick Hibmaor another hub attached to the USB bus.
63b2c1f437SNick Hibma.Pp
64b2c1f437SNick HibmaThe
65b2c1f437SNick Hibma.Nm uhub
66b2c1f437SNick Hibmadevice will always be present as it is needed for the
67b2c1f437SNick Hibmaroot hub.
68b2c1f437SNick Hibma.Sh INTRODUCTION TO USB
69b2c1f437SNick HibmaThe
70b2c1f437SNick Hibma.Tn USB
71b2c1f437SNick Hibmais a 12 Mb/s serial bus (1.5 Mb/s for low speed devices).
72b2c1f437SNick HibmaEach
73b2c1f437SNick Hibma.Tn USB
74b2c1f437SNick Hibmahas a host controller that is the master of the bus;
75b2c1f437SNick Hibmaall other devices on the bus only speak when spoken to.
76b2c1f437SNick Hibma.Pp
77b2c1f437SNick HibmaThere can be up to 127 devices (apart from the host controller)
78b2c1f437SNick Hibmaon a bus, each with its own address.
79b2c1f437SNick HibmaThe addresses are assigned
80b2c1f437SNick Hibmadynamically by the host when each device is attached to the bus.
81b2c1f437SNick Hibma.Pp
82b2c1f437SNick HibmaWithin each device there can be up to 16 endpoints.
83b2c1f437SNick HibmaEach endpoint
84b2c1f437SNick Hibmais individually addressed and the addresses are static.
85b2c1f437SNick HibmaEach of these endpoints will communicate in one of four different modes:
86b2c1f437SNick Hibmacontrol, isochronous, bulk, or interrupt.
87b2c1f437SNick HibmaA device always has at least one endpoint.
88b2c1f437SNick HibmaThis endpoint has address 0 and is a control
89b2c1f437SNick Hibmaendpoint and is used to give commands to and extract basic data,
90b2c1f437SNick Hibmasuch as descriptors, from the device.
91b2c1f437SNick HibmaEach endpoint, except the control endpoint, is unidirectional.
92b2c1f437SNick Hibma.Pp
93b2c1f437SNick HibmaThe endpoints in a device are grouped into interfaces.
9457e4378bSRuslan ErmilovAn interface is a logical unit within a device; e.g.\&
95b2c1f437SNick Hibmaa compound device with both a keyboard and a trackball would present
96b2c1f437SNick Hibmaone interface for each.
97b2c1f437SNick HibmaAn interface can sometimes be set into different modes,
98b2c1f437SNick Hibmacalled alternate settings, which affects how it operates.
99b2c1f437SNick HibmaDifferent alternate settings can have different endpoints
100b2c1f437SNick Hibmawithin it.
101b2c1f437SNick Hibma.Pp
102b2c1f437SNick HibmaA device may operate in different configurations.
103b2c1f437SNick HibmaDepending on the
104b2c1f437SNick Hibmaconfiguration the device may present different sets of endpoints
105b2c1f437SNick Hibmaand interfaces.
106b2c1f437SNick Hibma.Pp
107b2c1f437SNick HibmaEach device located on a hub has several
108b2c1f437SNick Hibma.Xr config 8
109b2c1f437SNick Hibmalocators:
110b2c1f437SNick Hibma.Bl -tag -compact -width xxxxxx
111b2c1f437SNick Hibma.It Cd port
112b2c1f437SNick Hibmathis is the number of the port on the closest upstream hub.
113b2c1f437SNick Hibma.It Cd configuration
114b2c1f437SNick Hibmathis is the configuration the device must be in for this driver to attach.
115b2c1f437SNick HibmaThis locator does not set the configuration; it is iterated by the bus
116b2c1f437SNick Hibmaenumeration.
117b2c1f437SNick Hibma.It Cd interface
118b2c1f437SNick Hibmathis is the interface number within a device that an interface driver
119b2c1f437SNick Hibmaattaches to.
120a31999caSJosef Karthauser.It Cd vendor
121a31999caSJosef Karthauserthis is the 16 bit vendor id of the device.
122a31999caSJosef Karthauser.It Cd product
123a31999caSJosef Karthauserthis is the 16 bit product id of the device.
124a31999caSJosef Karthauser.It Cd release
125a31999caSJosef Karthauserthis is the 16 bit release (revision) number of the device.
126b2c1f437SNick Hibma.El
127a31999caSJosef KarthauserThe first locator can be used to pin down a particular device
128a31999caSJosef Karthauseraccording to its physical position in the device tree.
129a31999caSJosef KarthauserThe last three locators can be used to pin down a particular
130a31999caSJosef Karthauserdevice according to what device it actually is.
131b2c1f437SNick Hibma.Pp
132b2c1f437SNick HibmaThe bus enumeration of the
133b2c1f437SNick Hibma.Tn USB
134b2c1f437SNick Hibmabus proceeds in several steps:
135b2c1f437SNick Hibma.Bl -enum
136b2c1f437SNick Hibma.It
137b2c1f437SNick HibmaAny device specific driver can to attach to the device.
138b2c1f437SNick Hibma.It
139b2c1f437SNick HibmaIf none is found, any device class specific driver can attach.
140b2c1f437SNick Hibma.It
141b2c1f437SNick HibmaIf none is found, all configurations are iterated over.
142b2c1f437SNick HibmaFor each configuration all the interface are iterated over and interface
143b2c1f437SNick Hibmadrivers can attach.
144b2c1f437SNick HibmaIf any interface driver attached in a certain
145b2c1f437SNick Hibmaconfiguration the iteration over configurations is stopped.
146b2c1f437SNick Hibma.It
147b2c1f437SNick HibmaIf still no drivers have been found, the generic
148b2c1f437SNick Hibma.Tn USB
149b2c1f437SNick Hibmadriver can attach.
150b2c1f437SNick Hibma.El
151b2c1f437SNick Hibma.Sh USB CONTROLLER INTERFACE
152b2c1f437SNick HibmaUse the following to get access to the
153b2c1f437SNick Hibma.Tn USB
154f87717faSMike Pritchardspecific structures and defines.
155b2c1f437SNick Hibma.Bd -literal
156b2c1f437SNick Hibma#include <sys/dev/usb.h>
157b2c1f437SNick Hibma.Ed
158b2c1f437SNick Hibma.Pp
159b2c1f437SNick HibmaThe
160b2c1f437SNick Hibma.Pa /dev/usbN
161b2c1f437SNick Hibmacan be opened and a few operations can be performed on it.
162b2c1f437SNick HibmaThe
163b2c1f437SNick Hibma.Xr poll 2
164b2c1f437SNick Hibmasystem call will say that I/O is possible on the controller device when a
165b2c1f437SNick Hibma.Tn USB
166b2c1f437SNick Hibmadevice has been connected or disconnected to the bus.
167b2c1f437SNick Hibma.Pp
168b2c1f437SNick HibmaThe following
169b2c1f437SNick Hibma.Xr ioctl 2
170b2c1f437SNick Hibmacommands are supported on the controller device:
171b2c1f437SNick Hibma.Bl -tag -width xxxxxx
172b2c1f437SNick Hibma.It Dv USB_DISCOVER
173b2c1f437SNick HibmaThis command will cause a complete bus discovery to be initiated.
174b2c1f437SNick HibmaIf any devices attached or detached from the bus they will be
175b2c1f437SNick Hibmaprocessed during this command.
176b2c1f437SNick HibmaThis is the only way that new devices are found on the bus.
177b2c1f437SNick Hibma.It Dv USB_DEVICEINFO Fa "struct usb_device_info"
178b2c1f437SNick HibmaThis command can be used to retrieve some information about a device
179b2c1f437SNick Hibmaon the bus.
180b2c1f437SNick HibmaThe
181b2c1f437SNick Hibma.Va addr
182b2c1f437SNick Hibmafield should be filled before the call and the other fields will
183b2c1f437SNick Hibmabe filled by information about the device on that address.
184b2c1f437SNick HibmaShould no such device exist an error is reported.
185b2c1f437SNick Hibma.Bd -literal
186b2c1f437SNick Hibmastruct usb_device_info {
1874239682eSNick Hibma        u_int8_t        bus;
1884239682eSNick Hibma        u_int8_t        addr;
189a31999caSJosef Karthauser        usb_event_cookie_t cookie;
190b2c1f437SNick Hibma        char            product[USB_MAX_STRING_LEN];
191b2c1f437SNick Hibma        char            vendor[USB_MAX_STRING_LEN];
1924239682eSNick Hibma        char            release[8];
1934239682eSNick Hibma        u_int16_t       productNo;
1944239682eSNick Hibma        u_int16_t       vendorNo;
1954239682eSNick Hibma        u_int16_t       releaseNo;
1964239682eSNick Hibma        u_int8_t        class;
1974239682eSNick Hibma        u_int8_t        subclass;
1984239682eSNick Hibma        u_int8_t        protocol;
1994239682eSNick Hibma        u_int8_t        config;
2004239682eSNick Hibma        u_int8_t        lowspeed;
201b2c1f437SNick Hibma        int             power;
202b2c1f437SNick Hibma        int             nports;
203a31999caSJosef Karthauser        char            devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
2044239682eSNick Hibma        u_int8_t        ports[16];
205b2c1f437SNick Hibma#define USB_PORT_ENABLED      0xff
206b2c1f437SNick Hibma#define USB_PORT_SUSPENDED    0xfe
207b2c1f437SNick Hibma#define USB_PORT_POWERED      0xfd
208b2c1f437SNick Hibma#define USB_PORT_DISABLED     0xfc
209b2c1f437SNick Hibma};
210b2c1f437SNick Hibma.Ed
211b2c1f437SNick Hibma.Pp
2124239682eSNick Hibma.Va bus
213b2c1f437SNick Hibmaand
2144239682eSNick Hibma.Va addr
2154239682eSNick Hibmacontain the topological information for the device.
2164239682eSNick Hibma.Va devnames
2176d249eeeSSheldon Hearncontains the device names of the connected drivers.
2186d249eeeSSheldon HearnFor example the
2194239682eSNick Hibmathird USB Zip drive connected will be
2204239682eSNick Hibma.Li umass2 .
221b2c1f437SNick HibmaThe
2224239682eSNick Hibma.Va product , vendor
2234239682eSNick Hibmaand
2244239682eSNick Hibma.Va release
2254239682eSNick Hibmafields contain self-explanatory descriptions of the device.
2264239682eSNick Hibma.Va productNo , vendorNo , releaseNo , class , subclass
2274239682eSNick Hibmaand
2284239682eSNick Hibma.Va protocol
2294239682eSNick Hibmacontain the corresponding values from the device descriptors.
230b2c1f437SNick HibmaThe
231b2c1f437SNick Hibma.Va config
232b2c1f437SNick Hibmafield shows the current configuration of the device.
233b2c1f437SNick Hibma.Pp
234b2c1f437SNick Hibma.Va lowspeed
2354239682eSNick Hibmaindicates whether the device is a full speed (0) or low speed (1)
2366d249eeeSSheldon Hearndevice.
2376d249eeeSSheldon HearnThe
238b2c1f437SNick Hibma.Va power
239b2c1f437SNick Hibmafield shows the power consumption in milli-amps drawn at 5 volts,
240b2c1f437SNick Hibmaor zero if the device is self powered.
241b2c1f437SNick Hibma.Pp
242b2c1f437SNick HibmaIf the device is a hub the
243b2c1f437SNick Hibma.Va nports
244b2c1f437SNick Hibmafield is non-zero and the
245b2c1f437SNick Hibma.Va ports
246b2c1f437SNick Hibmafield contains the addresses of the connected devices.
247b2c1f437SNick HibmaIf no device is connected to a port one of the
248b2c1f437SNick Hibma.Va USB_PORT_*
249b2c1f437SNick Hibmavalues indicates its status.
250b2c1f437SNick Hibma.It Dv USB_DEVICESTATS Fa "struct usb_device_stats"
251b2c1f437SNick HibmaThis command retrieves statistics about the controller.
252b2c1f437SNick Hibma.Bd -literal
253b2c1f437SNick Hibmastruct usb_device_stats {
254b2c1f437SNick Hibma        u_long  requests[4];
255b2c1f437SNick Hibma};
256b2c1f437SNick Hibma.Ed
257b2c1f437SNick Hibma.Pp
258b2c1f437SNick HibmaThe
259b2c1f437SNick Hibma.Va requests
26057e4378bSRuslan Ermilovfield is indexed by the transfer kind, i.e.\&
261b2c1f437SNick Hibma.Va UE_* ,
262b2c1f437SNick Hibmaand indicates how many transfers of each kind that has been completed
263b2c1f437SNick Hibmaby the controller.
264b2c1f437SNick Hibma.It Dv USB_REQUEST Fa "struct usb_ctl_request"
265b2c1f437SNick HibmaThis command can be used to execute arbitrary requests on the control pipe.
266b2c1f437SNick HibmaThis is
267b2c1f437SNick Hibma.Em DANGEROUS
268b2c1f437SNick Hibmaand should be used with great care since it
269b2c1f437SNick Hibmacan destroy the bus integrity.
270b2c1f437SNick Hibma.El
271b2c1f437SNick Hibma.Pp
272b2c1f437SNick HibmaThe include file
273b2c1f437SNick Hibma.Aq Pa dev/usb/usb.h
274b2c1f437SNick Hibmacontains definitions for the types used by the various
275b2c1f437SNick Hibma.Xr ioctl 2
276b2c1f437SNick Hibmacalls.
277b2c1f437SNick HibmaThe naming convention of the fields for the various
278b2c1f437SNick Hibma.Tn USB
279b2c1f437SNick Hibmadescriptors exactly follows the naming in the
280b2c1f437SNick Hibma.Tn USB
281b2c1f437SNick Hibmaspecification.
282b2c1f437SNick HibmaByte sized fields can be accessed directly, but word (16 bit)
283b2c1f437SNick Hibmasized fields must be access by the
284b2c1f437SNick Hibma.Fn UGETW field
285b2c1f437SNick Hibmaand
286b2c1f437SNick Hibma.Fn USETW field value
287b2c1f437SNick Hibmamacros to handle byte order and alignment properly.
288b2c1f437SNick Hibma.Pp
289b2c1f437SNick HibmaThe include file
290b2c1f437SNick Hibma.Aq Pa dev/usb/usbhid.h
291b2c1f437SNick Hibmasimilarly contains the definitions for
292b2c1f437SNick HibmaHuman Interface Devices
293b2c1f437SNick Hibma.Pq Tn HID .
294b2c1f437SNick Hibma.Sh SEE ALSO
295b2c1f437SNick HibmaThe
296b2c1f437SNick Hibma.Tn USB
297a31999caSJosef Karthauserspecifications can be found at:
298a31999caSJosef Karthauser.D1 http://www.usb.org/developers/docs.htm .
299b2c1f437SNick Hibma.Pp
300a31999caSJosef Karthauser.Xr usb 3 ,
301a31999caSJosef Karthauser.Xr aue 4 ,
302a31999caSJosef Karthauser.Xr cue 4 ,
303a31999caSJosef Karthauser.Xr kue 4 ,
304b2c1f437SNick Hibma.Xr ohci 4 ,
3055521ff5aSRuslan Ermilov.Xr pci 4 ,
306a31999caSJosef Karthauser.Xr ugen 4 ,
307def37e7cSMike Pritchard.Xr uhci 4 ,
308b2c1f437SNick Hibma.Xr uhid 4 ,
309b2c1f437SNick Hibma.Xr ukbd 4 ,
310a31999caSJosef Karthauser.Xr umass 4 ,
311b2c1f437SNick Hibma.Xr ums 4 ,
312b2c1f437SNick Hibma.Xr usbd 8 ,
313a31999caSJosef Karthauser.Xr urio 4 ,
314a31999caSJosef Karthauser.Xr uscanner 4 ,
315b2c1f437SNick Hibma.Xr usbdevs 8
316b2c1f437SNick Hibma.Sh HISTORY
317b2c1f437SNick HibmaThe
318b2c1f437SNick Hibma.Nm
319b2c1f437SNick Hibmadriver first appeared in
320b2c1f437SNick Hibma.Fx 3.0 .
321def37e7cSMike Pritchard.Sh AUTHORS
322b2c1f437SNick HibmaThe
323b2c1f437SNick Hibma.Nm
324b2c1f437SNick Hibmadriver was written by
325def37e7cSMike Pritchard.An Lennart Augustsson Aq augustss@carlstedt.se
326def37e7cSMike Pritchardfor the
327b2c1f437SNick Hibma.Nx
328b2c1f437SNick Hibmaproject.
329