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 35b2c1f437SNick Hibma.Os FreeBSD 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" 41b2c1f437SNick Hibma.Sh DESCRIPTION 42d4be94a1SChris Costello.Fx 43b2c1f437SNick Hibmaprovides machine-independent bus support and drivers for 44b2c1f437SNick Hibma.Tn USB 45b2c1f437SNick Hibmadevices. 46b2c1f437SNick Hibma.Pp 47b2c1f437SNick HibmaThe 48b2c1f437SNick Hibma.Nm 49b2c1f437SNick Hibmadriver has three layers: the controller, the bus, and the 506d249eeeSSheldon Hearndevice layer. 516d249eeeSSheldon HearnThe controller attaches to a physical bus 52b2c1f437SNick Hibma(like 53b2c1f437SNick Hibma.Xr pci 4 ) . 54b2c1f437SNick HibmaThe 55b2c1f437SNick Hibma.Tn USB 56b2c1f437SNick Hibmabus attaches to the controller and the root hub attaches 57b2c1f437SNick Hibmato the controller. 58b2c1f437SNick HibmaAny devices attached to the bus will attach to the root hub 59b2c1f437SNick Hibmaor another hub attached to the USB bus. 60b2c1f437SNick Hibma.Pp 61b2c1f437SNick HibmaThe 62b2c1f437SNick Hibma.Nm uhub 63b2c1f437SNick Hibmadevice will always be present as it is needed for the 64b2c1f437SNick Hibmaroot hub. 65b2c1f437SNick Hibma.Pp 66b2c1f437SNick Hibma.Sh INTRODUCTION TO USB 67b2c1f437SNick HibmaThe 68b2c1f437SNick Hibma.Tn USB 69b2c1f437SNick Hibmais a 12 Mb/s serial bus (1.5 Mb/s for low speed devices). 70b2c1f437SNick HibmaEach 71b2c1f437SNick Hibma.Tn USB 72b2c1f437SNick Hibmahas a host controller that is the master of the bus; 73b2c1f437SNick Hibmaall other devices on the bus only speak when spoken to. 74b2c1f437SNick Hibma.Pp 75b2c1f437SNick HibmaThere can be up to 127 devices (apart from the host controller) 76b2c1f437SNick Hibmaon a bus, each with its own address. 77b2c1f437SNick HibmaThe addresses are assigned 78b2c1f437SNick Hibmadynamically by the host when each device is attached to the bus. 79b2c1f437SNick Hibma.Pp 80b2c1f437SNick HibmaWithin each device there can be up to 16 endpoints. 81b2c1f437SNick HibmaEach endpoint 82b2c1f437SNick Hibmais individually addressed and the addresses are static. 83b2c1f437SNick HibmaEach of these endpoints will communicate in one of four different modes: 84b2c1f437SNick Hibmacontrol, isochronous, bulk, or interrupt. 85b2c1f437SNick HibmaA device always has at least one endpoint. 86b2c1f437SNick HibmaThis endpoint has address 0 and is a control 87b2c1f437SNick Hibmaendpoint and is used to give commands to and extract basic data, 88b2c1f437SNick Hibmasuch as descriptors, from the device. 89b2c1f437SNick HibmaEach endpoint, except the control endpoint, is unidirectional. 90b2c1f437SNick Hibma.Pp 91b2c1f437SNick HibmaThe endpoints in a device are grouped into interfaces. 92b2c1f437SNick HibmaAn interface is a logical unit within a device; e.g. 93b2c1f437SNick Hibmaa compound device with both a keyboard and a trackball would present 94b2c1f437SNick Hibmaone interface for each. 95b2c1f437SNick HibmaAn interface can sometimes be set into different modes, 96b2c1f437SNick Hibmacalled alternate settings, which affects how it operates. 97b2c1f437SNick HibmaDifferent alternate settings can have different endpoints 98b2c1f437SNick Hibmawithin it. 99b2c1f437SNick Hibma.Pp 100b2c1f437SNick HibmaA device may operate in different configurations. 101b2c1f437SNick HibmaDepending on the 102b2c1f437SNick Hibmaconfiguration the device may present different sets of endpoints 103b2c1f437SNick Hibmaand interfaces. 104b2c1f437SNick Hibma.Pp 105b2c1f437SNick HibmaEach device located on a hub has several 106b2c1f437SNick Hibma.Xr config 8 107b2c1f437SNick Hibmalocators: 108b2c1f437SNick Hibma.Bl -tag -compact -width xxxxxx 109b2c1f437SNick Hibma.It Cd port 110b2c1f437SNick Hibmathis is the number of the port on the closest upstream hub. 111b2c1f437SNick Hibma.It Cd configuration 112b2c1f437SNick Hibmathis is the configuration the device must be in for this driver to attach. 113b2c1f437SNick HibmaThis locator does not set the configuration; it is iterated by the bus 114b2c1f437SNick Hibmaenumeration. 115b2c1f437SNick Hibma.It Cd interface 116b2c1f437SNick Hibmathis is the interface number within a device that an interface driver 117b2c1f437SNick Hibmaattaches to. 118b2c1f437SNick Hibma.El 119b2c1f437SNick Hibma.Pp 120b2c1f437SNick HibmaThe bus enumeration of the 121b2c1f437SNick Hibma.Tn USB 122b2c1f437SNick Hibmabus proceeds in several steps: 123b2c1f437SNick Hibma.Bl -enum 124b2c1f437SNick Hibma.It 125b2c1f437SNick HibmaAny device specific driver can to attach to the device. 126b2c1f437SNick Hibma.It 127b2c1f437SNick HibmaIf none is found, any device class specific driver can attach. 128b2c1f437SNick Hibma.It 129b2c1f437SNick HibmaIf none is found, all configurations are iterated over. 130b2c1f437SNick HibmaFor each configuration all the interface are iterated over and interface 131b2c1f437SNick Hibmadrivers can attach. 132b2c1f437SNick HibmaIf any interface driver attached in a certain 133b2c1f437SNick Hibmaconfiguration the iteration over configurations is stopped. 134b2c1f437SNick Hibma.It 135b2c1f437SNick HibmaIf still no drivers have been found, the generic 136b2c1f437SNick Hibma.Tn USB 137b2c1f437SNick Hibmadriver can attach. 138b2c1f437SNick Hibma.El 139b2c1f437SNick Hibma.Sh USB CONTROLLER INTERFACE 140b2c1f437SNick HibmaUse the following to get access to the 141b2c1f437SNick Hibma.Tn USB 142b2c1f437SNick Hibmaspecific structurs and defines. 143b2c1f437SNick Hibma.Bd -literal 144b2c1f437SNick Hibma#include <sys/dev/usb.h> 145b2c1f437SNick Hibma.Ed 146b2c1f437SNick Hibma.Pp 147b2c1f437SNick HibmaThe 148b2c1f437SNick Hibma.Pa /dev/usbN 149b2c1f437SNick Hibmacan be opened and a few operations can be performed on it. 150b2c1f437SNick HibmaThe 151b2c1f437SNick Hibma.Xr poll 2 152b2c1f437SNick Hibmasystem call will say that I/O is possible on the controller device when a 153b2c1f437SNick Hibma.Tn USB 154b2c1f437SNick Hibmadevice has been connected or disconnected to the bus. 155b2c1f437SNick Hibma.Pp 156b2c1f437SNick HibmaThe following 157b2c1f437SNick Hibma.Xr ioctl 2 158b2c1f437SNick Hibmacommands are supported on the controller device: 159b2c1f437SNick Hibma.Bl -tag -width xxxxxx 160b2c1f437SNick Hibma.It Dv USB_DISCOVER 161b2c1f437SNick HibmaThis command will cause a complete bus discovery to be initiated. 162b2c1f437SNick HibmaIf any devices attached or detached from the bus they will be 163b2c1f437SNick Hibmaprocessed during this command. 164b2c1f437SNick HibmaThis is the only way that new devices are found on the bus. 165b2c1f437SNick Hibma.It Dv USB_DEVICEINFO Fa "struct usb_device_info" 166b2c1f437SNick HibmaThis command can be used to retrieve some information about a device 167b2c1f437SNick Hibmaon the bus. 168b2c1f437SNick HibmaThe 169b2c1f437SNick Hibma.Va addr 170b2c1f437SNick Hibmafield should be filled before the call and the other fields will 171b2c1f437SNick Hibmabe filled by information about the device on that address. 172b2c1f437SNick HibmaShould no such device exist an error is reported. 173b2c1f437SNick Hibma.Bd -literal 174b2c1f437SNick Hibmastruct usb_device_info { 1754239682eSNick Hibma u_int8_t bus; 1764239682eSNick Hibma u_int8_t addr; 1774239682eSNick Hibma# define USBDEVNAME_NR 4 1784239682eSNick Hibma# define USBDEVNAME_LEN 10 1794239682eSNick Hibma char devnames[USBDEVNAME_NR][USBDEVNAME_LEN]; 180b2c1f437SNick Hibma char product[USB_MAX_STRING_LEN]; 181b2c1f437SNick Hibma char vendor[USB_MAX_STRING_LEN]; 1824239682eSNick Hibma char release[8]; 1834239682eSNick Hibma u_int16_t productNo; 1844239682eSNick Hibma u_int16_t vendorNo; 1854239682eSNick Hibma u_int16_t releaseNo; 1864239682eSNick Hibma u_int8_t class; 1874239682eSNick Hibma u_int8_t subclass; 1884239682eSNick Hibma u_int8_t protocol; 1894239682eSNick Hibma u_int8_t config; 1904239682eSNick Hibma u_int8_t lowspeed; 191b2c1f437SNick Hibma int power; 192b2c1f437SNick Hibma int nports; 1934239682eSNick Hibma u_int8_t ports[16]; 194b2c1f437SNick Hibma#define USB_PORT_ENABLED 0xff 195b2c1f437SNick Hibma#define USB_PORT_SUSPENDED 0xfe 196b2c1f437SNick Hibma#define USB_PORT_POWERED 0xfd 197b2c1f437SNick Hibma#define USB_PORT_DISABLED 0xfc 198b2c1f437SNick Hibma}; 199b2c1f437SNick Hibma.Ed 200b2c1f437SNick Hibma.Pp 2014239682eSNick Hibma.Va bus 202b2c1f437SNick Hibmaand 2034239682eSNick Hibma.Va addr 2044239682eSNick Hibmacontain the topological information for the device. 2054239682eSNick Hibma.Va devnames 2066d249eeeSSheldon Hearncontains the device names of the connected drivers. 2076d249eeeSSheldon HearnFor example the 2084239682eSNick Hibmathird USB Zip drive connected will be 2094239682eSNick Hibma.Li umass2 . 210b2c1f437SNick HibmaThe 2114239682eSNick Hibma.Va product , vendor 2124239682eSNick Hibmaand 2134239682eSNick Hibma.Va release 2144239682eSNick Hibmafields contain self-explanatory descriptions of the device. 2154239682eSNick Hibma.Va productNo , vendorNo , releaseNo , class , subclass 2164239682eSNick Hibmaand 2174239682eSNick Hibma.Va protocol 2184239682eSNick Hibmacontain the corresponding values from the device descriptors. 219b2c1f437SNick HibmaThe 220b2c1f437SNick Hibma.Va config 221b2c1f437SNick Hibmafield shows the current configuration of the device. 222b2c1f437SNick Hibma.Pp 223b2c1f437SNick Hibma.Va lowspeed 2244239682eSNick Hibmaindicates whether the device is a full speed (0) or low speed (1) 2256d249eeeSSheldon Hearndevice. 2266d249eeeSSheldon HearnThe 227b2c1f437SNick Hibma.Va power 228b2c1f437SNick Hibmafield shows the power consumption in milli-amps drawn at 5 volts, 229b2c1f437SNick Hibmaor zero if the device is self powered. 230b2c1f437SNick Hibma.Pp 231b2c1f437SNick HibmaIf the device is a hub the 232b2c1f437SNick Hibma.Va nports 233b2c1f437SNick Hibmafield is non-zero and the 234b2c1f437SNick Hibma.Va ports 235b2c1f437SNick Hibmafield contains the addresses of the connected devices. 236b2c1f437SNick HibmaIf no device is connected to a port one of the 237b2c1f437SNick Hibma.Va USB_PORT_* 238b2c1f437SNick Hibmavalues indicates its status. 239b2c1f437SNick Hibma.It Dv USB_DEVICESTATS Fa "struct usb_device_stats" 240b2c1f437SNick HibmaThis command retrieves statistics about the controller. 241b2c1f437SNick Hibma.Bd -literal 242b2c1f437SNick Hibmastruct usb_device_stats { 243b2c1f437SNick Hibma u_long requests[4]; 244b2c1f437SNick Hibma}; 245b2c1f437SNick Hibma.Ed 246b2c1f437SNick Hibma.Pp 247b2c1f437SNick HibmaThe 248b2c1f437SNick Hibma.Va requests 249b2c1f437SNick Hibmafield is indexed by the transfer kind, i.e. 250b2c1f437SNick Hibma.Va UE_* , 251b2c1f437SNick Hibmaand indicates how many transfers of each kind that has been completed 252b2c1f437SNick Hibmaby the controller. 253b2c1f437SNick Hibma.It Dv USB_REQUEST Fa "struct usb_ctl_request" 254b2c1f437SNick HibmaThis command can be used to execute arbitrary requests on the control pipe. 255b2c1f437SNick HibmaThis is 256b2c1f437SNick Hibma.Em DANGEROUS 257b2c1f437SNick Hibmaand should be used with great care since it 258b2c1f437SNick Hibmacan destroy the bus integrity. 259b2c1f437SNick Hibma.El 260b2c1f437SNick Hibma.Pp 261b2c1f437SNick HibmaThe include file 262b2c1f437SNick Hibma.Aq Pa dev/usb/usb.h 263b2c1f437SNick Hibmacontains definitions for the types used by the various 264b2c1f437SNick Hibma.Xr ioctl 2 265b2c1f437SNick Hibmacalls. 266b2c1f437SNick HibmaThe naming convention of the fields for the various 267b2c1f437SNick Hibma.Tn USB 268b2c1f437SNick Hibmadescriptors exactly follows the naming in the 269b2c1f437SNick Hibma.Tn USB 270b2c1f437SNick Hibmaspecification. 271b2c1f437SNick HibmaByte sized fields can be accessed directly, but word (16 bit) 272b2c1f437SNick Hibmasized fields must be access by the 273b2c1f437SNick Hibma.Fn UGETW field 274b2c1f437SNick Hibmaand 275b2c1f437SNick Hibma.Fn USETW field value 276b2c1f437SNick Hibmamacros to handle byte order and alignment properly. 277b2c1f437SNick Hibma.Pp 278b2c1f437SNick HibmaThe include file 279b2c1f437SNick Hibma.Aq Pa dev/usb/usbhid.h 280b2c1f437SNick Hibmasimilarly contains the definitions for 281b2c1f437SNick HibmaHuman Interface Devices 282b2c1f437SNick Hibma.Pq Tn HID . 283b2c1f437SNick Hibma.Sh SEE ALSO 284b2c1f437SNick HibmaThe 285b2c1f437SNick Hibma.Tn USB 286b2c1f437SNick Hibmaspecifications can be found at 287b2c1f437SNick Hibma.Dv http://www.usb.org/developers/docs.htm . 288b2c1f437SNick Hibma.Pp 289b2c1f437SNick Hibma.Xr ohci 4 , 2905521ff5aSRuslan Ermilov.Xr pci 4 , 291def37e7cSMike Pritchard.Xr uhci 4 , 292b2c1f437SNick Hibma.Xr uhid 4 , 293b2c1f437SNick Hibma.Xr ukbd 4 , 294b2c1f437SNick Hibma.Xr ums 4 , 295b2c1f437SNick Hibma.Xr usbd 8 , 296b2c1f437SNick Hibma.Xr usbdevs 8 297b2c1f437SNick Hibma.Sh HISTORY 298b2c1f437SNick HibmaThe 299b2c1f437SNick Hibma.Nm 300b2c1f437SNick Hibmadriver first appeared in 301b2c1f437SNick Hibma.Fx 3.0 . 302def37e7cSMike Pritchard.Sh AUTHORS 303b2c1f437SNick HibmaThe 304b2c1f437SNick Hibma.Nm 305b2c1f437SNick Hibmadriver was written by 306def37e7cSMike Pritchard.An Lennart Augustsson Aq augustss@carlstedt.se 307def37e7cSMike Pritchardfor the 308b2c1f437SNick Hibma.Nx 309b2c1f437SNick Hibmaproject. 310