1.\" $OpenBSD: usb.4,v 1.107 2009/03/23 21:58:35 deraadt Exp $ 2.\" $NetBSD: usb.4,v 1.15 1999/07/29 14:20:32 augustss Exp $ 3.\" 4.\" Copyright (c) 1999 The NetBSD Foundation, Inc. 5.\" All rights reserved. 6.\" 7.\" This code is derived from software contributed to The NetBSD Foundation 8.\" by Lennart Augustsson. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 19.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29.\" POSSIBILITY OF SUCH DAMAGE. 30.\" 31.Dd $Mdocdate: March 23 2009 $ 32.Dt USB 4 33.Os 34.Sh NAME 35.Nm usb 36.Nd introduction to Universal Serial Bus support 37.Sh SYNOPSIS 38.Cd "# zaurus specific" 39.Cd "ohci0 at pxaip?" 40.Cd "# all architectures" 41.Cd "ehci* at cardbus?" 42.Cd "uhci* at cardbus?" 43.Cd "ohci* at cardbus?" 44.Cd "ehci* at pci?" 45.Cd "uhci* at pci?" 46.Cd "ohci* at pci?" 47.Cd "usb* at ehci? flags 0x00" 48.Cd "usb* at uhci? flags 0x00" 49.Cd "usb* at ohci? flags 0x00" 50.Cd "uhub* at usb?" 51.Cd "uhub* at uhub?" 52.Pp 53.Cd option USBVERBOSE 54.Pp 55.Fd "#include <dev/usb/usb.h>" 56.Fd "#include <dev/usb/usbhid.h>" 57.Sh DESCRIPTION 58.Ox 59provides machine-independent bus support and drivers for Universal Serial Bus 60.Pq Tn USB 61devices. 62.Pp 63The 64.Ox 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 73or 74.Xr cardbus 4 ) . 75The 76.Tn USB 77bus attaches to the controller and the root hub attaches 78to the controller. 79Devices, which may include further hubs, attach to the root hub. 80The attachment forms the same tree structure as the physical 81.Tn USB 82device tree. 83For each 84.Tn USB 85device there may be additional drivers attached to it. 86.Pp 87The 88.Cm uhub 89driver controls 90.Tn USB 91hubs and must always be present since there is at least one root hub in any 92.Tn USB 93system. 94.Pp 95The 96.Cm flags 97are used to specify if the devices on the 98.Tn USB 99bus should be probed 100early in the boot process. 101If the 102.Cm flags 103are specified with a value of 1, the 104.Tn USB 105bus will be probed when the 106.Tn USB 107host device is attached instead of waiting 108until kernel processes start running. 109.Pp 110.Ox 111provides support for the following devices. 112Note that not all architectures support all devices. 113.Ss Storage devices 114.Bl -tag -width 12n -offset ind -compact 115.It Xr umass 4 116.Tn USB 117Mass Storage Devices, e.g., external disk drives 118.El 119.Ss Wired network interfaces 120.Bl -tag -width 12n -offset ind -compact 121.It Xr aue 4 122ADMtek AN986/ADM8511 Pegasus family 10/100 USB Ethernet device 123.It Xr axe 4 124ASIX Electronics AX88172/AX88178/AX88772 10/100/Gigabit USB Ethernet device 125.It Xr cdce 4 126USB Communication Device Class Ethernet device 127.It Xr cue 4 128CATC USB-EL1201A USB Ethernet device 129.It Xr kue 4 130Kawasaki LSI KL5KUSB101B USB Ethernet device 131.It Xr mos 4 132MOSCHIP MCS7730/7830 10/100 USB 2.0 Ethernet device 133.It Xr udav 4 134Davicom DM9601 10/100 USB Ethernet device 135.It Xr ueagle 4 136Analog Devices Eagle ADSL modems 137.It Xr url 4 138Realtek RTL8150L 10/100 USB Ethernet device 139.El 140.Ss Wireless network interfaces 141.Bl -tag -width 12n -offset ind -compact 142.It Xr atu 4 143Atmel AT76C50x IEEE 802.11b wireless network device 144.It Xr otus 4 145Atheros USB IEEE 802.11a/b/g/Draft-N wireless network device 146.It Xr rum 4 147Ralink Technology USB IEEE 802.11a/b/g wireless network device 148.It Xr run 4 149Ralink Technology USB IEEE 802.11a/b/g/Draft-N wireless network device 150.It Xr uath 4 151Atheros USB IEEE 802.11a/b/g wireless network device 152.It Xr ubt 4 153Bluetooth adapters 154.It Xr upgt 4 155Conexant/Intersil PrismGT SoftMAC USB IEEE 802.11b/g wireless network device 156.It Xr ural 4 157Ralink Technology USB IEEE 802.11b/g wireless network device 158.It Xr urtw 4 159Realtek RTL8187L USB IEEE 802.11b/g wireless network device 160.It Xr wi 4 161Intersil PRISM 2-3 IEEE 802.11b wireless network device 162.It Xr zyd 4 163ZyDAS ZD1211/ZD1211B USB IEEE 802.11b/g wireless network device 164.El 165.Ss Serial and parallel interfaces 166.Bl -tag -width 12n -offset ind -compact 167.It Xr moscom 4 168MosChip Semiconductor MCS7703 based USB serial adapter 169.It Xr uark 4 170Arkmicro Technologies ARK3116 based USB serial adapter 171.It Xr ubsa 4 172Belkin USB serial adapter 173.It Xr uchcom 4 174WinChipHead CH341/340 based USB serial adapter 175.It Xr ucom 4 176USB tty support 177.It Xr ucycom 4 178Cypress microcontroller based USB serial adapter 179.It Xr uftdi 4 180FT8U100AX USB serial adapter 181.It Xr uipaq 4 182iPAQ USB units 183.It Xr ulpt 4 184USB printer support 185.It Xr umct 4 186MCT USB-RS232 USB serial adapter 187.It Xr umodem 4 188USB modem support 189.It Xr umsm 4 190Qualcomm MSM modem device 191.It Xr uplcom 4 192Prolific PL-2303 USB serial adapter 193.It Xr uslcom 4 194Silicon Laboratories CP2101/CP2102 based USB serial adapter 195.It Xr uticom 4 196Texas Instruments TUSB3410 USB serial adapter 197.It Xr uvisor 4 198USB Handspring Visor 199.It Xr uvscom 4 200SUNTAC Slipper U VS-10U USB serial adapter 201.El 202.Ss Audio devices 203.Bl -tag -width 12n -offset ind -compact 204.It Xr uaudio 4 205USB audio devices 206.It Xr umidi 4 207USB MIDI devices 208.It Xr urio 4 209Diamond Multimedia Rio MP3 players 210.El 211.Ss Time receiver devices 212.Bl -tag -width 12n -offset ind -compact 213.It Xr udcf 4 214Gude ADS Expert mouseCLOCK USB timedelta sensor 215.It Xr umbg 4 216Meinberg Funkuhren USB5131 timedelta sensor 217.El 218.Ss Radio receiver devices 219.Bl -tag -width 12n -offset ind -compact 220.It Xr udsbr 4 221D-Link DSB-R100 USB radio device 222.El 223.Ss Human Interface Devices 224.Bl -tag -width 12n -offset ind -compact 225.It Xr tpms 4 226Apple touchpad mouse 227.It Xr uhid 4 228Generic driver for Human Interface Devices 229.It Xr uhidev 4 230Base driver for all Human Interface Devices 231.It Xr ukbd 4 232.Tn USB 233keyboards that follow the boot protocol 234.It Xr ums 4 235.Tn USB 236mouse devices 237.El 238.Ss Miscellaneous devices 239.Bl -tag -width 12n -offset ind -compact 240.It Xr uberry 4 241Research In Motion Blackberry 242.It Xr ugen 4 243USB generic device support 244.It Xr uow 4 245Maxim/Dallas DS2490 USB 1-Wire adapter 246.It Xr upl 4 247Prolific based host-to-host adapters 248.It Xr uscanner 4 249USB scanner support 250.It Xr usscanner 4 251SCSI-over-USB scanners 252.It Xr uts 4 253USB touchscreen support 254.It Xr uyap 4 255USB YAP phone firmware loader 256.El 257.Sh INTRODUCTION TO USB 258There are different versions of the 259.Tn USB 260which provide different speeds. 261.Tn USB 2622 operates at 480Mb/s, while 263.Tn USB 264versions 1 and 1.1 operate at 12 Mb/s and 1.5 Mb/s for low speed devices. 265Each 266.Tn USB 267has a host controller that is the master of the bus; 268all other devices on the bus only speak when spoken to. 269.Pp 270There can be up to 127 devices (apart from the host controller) 271on a bus, each with its own address. 272The addresses are assigned 273dynamically by the host when each device is attached to the bus. 274.Pp 275Within each device there can be up to 16 endpoints. 276Each endpoint 277is individually addressed and the addresses are static. 278Each of these endpoints will communicate in one of four different modes: 279control, isochronous, bulk, or interrupt. 280A device always has at least one endpoint. 281This is a control endpoint at address 0 282and is used to give commands to the device and extract basic data, 283such as descriptors, from the device. 284Each endpoint, except the control endpoint, is unidirectional. 285.Pp 286The endpoints in a device are grouped into interfaces. 287An interface is a logical unit within a device; e.g., 288a compound device with both a keyboard and a trackball would present 289one interface for each. 290An interface can sometimes be set into different modes, 291called alternate settings, which affects how it operates. 292Different alternate settings can have different endpoints 293within it. 294.Pp 295A device may operate in different configurations. 296Depending on the 297configuration the device may present different sets of endpoints 298and interfaces. 299.Pp 300Each device located on a hub has several 301.Xr config 8 302locators: 303.Pp 304.Bl -tag -width configuration -compact 305.It Cd port 306Number of the port on closest upstream hub. 307.It Cd configuration 308Configuration the device must be in for this driver to attach. 309This locator does not set the configuration; it is iterated by the bus 310enumeration. 311.It Cd interface 312Interface number within a device that an interface driver attaches to. 313.It Cd vendor 31416-bit vendor ID of the device. 315.It Cd product 31616-bit product ID of the device. 317.It Cd release 31816-bit release (revision) number of the device. 319.El 320.Pp 321The first locator can be used to pin down a particular device 322according to its physical position in the device tree. 323The last three locators can be used to pin down a particular 324device according to what device it actually is. 325.Pp 326The bus enumeration of the 327.Tn USB 328bus proceeds in several steps: 329.Bl -enum 330.It 331Any device-specific driver can attach to the device. 332.It 333If none is found, any device class specific driver can attach. 334.It 335If none is found, all configurations are iterated over. 336For each configuration all the interfaces are iterated over and interface 337drivers can attach. 338If any interface driver attached in a certain 339configuration, the iteration over configurations is stopped. 340.It 341If still no drivers have been found, the generic 342.Tn USB 343driver can attach. 344.El 345.Sh USB CONTROLLER INTERFACE 346Use the following to get access to the 347.Tn USB 348specific structures and defines: 349.Bd -literal 350.Fd #include <dev/usb/usb.h> 351.Ed 352.Pp 353The 354.Pa /dev/usbN 355device can be opened and a few operations can be performed on it. 356The 357.Xr poll 2 358system call will say that I/O is possible on the controller device when a 359.Tn USB 360device has been connected or disconnected to the bus. 361.Pp 362The following 363.Xr ioctl 2 364commands are supported on the controller device: 365.Bl -tag -width xxxxxx 366.\" .It Dv USB_DISCOVER 367.\" This command will cause a complete bus discovery to be initiated. 368.\" If any devices attached or detached from the bus they will be 369.\" processed during this command. 370.\" This is the only way that new devices are found on the bus. 371.It Dv USB_DEVICEINFO Fa "struct usb_device_info *" 372This command can be used to retrieve some information about a device 373on the bus. 374The 375.Va udi_addr 376field should be filled before the call and the other fields will 377be filled by information about the device on that address. 378Should no such device exist, an error is reported. 379.Bd -literal 380#define USB_MAX_DEVNAMES 4 381#define USB_MAX_DEVNAMELEN 16 382struct usb_device_info { 383 u_int8_t udi_bus; 384 u_int8_t udi_addr; /* device address */ 385 usb_event_cookie_t udi_cookie; 386 char udi_product[USB_MAX_STRING_LEN]; 387 char udi_vendor[USB_MAX_STRING_LEN]; 388 char udi_release[8]; 389 u_int16_t udi_productNo; 390 u_int16_t udi_vendorNo; 391 u_int16_t udi_releaseNo; 392 u_int8_t udi_class; 393 u_int8_t udi_subclass; 394 u_int8_t udi_protocol; 395 u_int8_t udi_config; 396 u_int8_t udi_speed; 397#define USB_SPEED_LOW 1 398#define USB_SPEED_FULL 2 399#define USB_SPEED_HIGH 3 400 int udi_power; /* power consumption */ 401 int udi_nports; 402 char udi_devnames[USB_MAX_DEVNAMES] 403 [USB_MAX_DEVNAMELEN]; 404 u_int8_t udi_ports[16]; /* hub only */ 405#define USB_PORT_ENABLED 0xff 406#define USB_PORT_SUSPENDED 0xfe 407#define USB_PORT_POWERED 0xfd 408#define USB_PORT_DISABLED 0xfc 409}; 410.Ed 411.Pp 412The 413.Va udi_bus 414field contains the device unit number of the device. 415.Pp 416The 417.Va udi_product , 418.Va udi_vendor , 419and 420.Va udi_release 421fields contain self-explanatory descriptions of the device. 422The 423.Va udi_productNo , 424.Va udi_vendorNo , 425and 426.Va udi_releaseNo 427fields contain numeric identifiers for the device. 428.Pp 429The 430.Va udi_class 431and 432.Va udi_subclass 433fields contain the device class and subclass. 434.Pp 435The 436.Va udi_config 437field shows the current configuration of the device. 438.Pp 439The 440.Va udi_protocol 441field contains the device protocol as given from the device. 442.Pp 443The 444.Va udi_speed 445field 446contains the speed of the device. 447.Pp 448The 449.Va udi_power 450field shows the power consumption in milli-amps drawn at 5 volts 451or is zero if the device is self powered. 452.Pp 453The 454.Va udi_devnames 455field contains the names and instance numbers of the device drivers 456for the devices attached to this device. 457.Pp 458If the device is a hub, the 459.Va udi_nports 460field is non-zero and the 461.Va udi_ports 462field contains the addresses of the connected devices. 463If no device is connected to a port, one of the 464.Dv USB_PORT_* 465values indicates its status. 466.It Dv USB_DEVICESTATS Fa "struct usb_device_stats *" 467This command retrieves statistics about the controller. 468.Bd -unfilled 469struct usb_device_stats { 470 u_long uds_requests[4]; 471}; 472.Ed 473.Pp 474The 475.Va uds_requests 476field is indexed by the transfer kind, i.e.\& 477.Dv UE_* , 478and indicates how many transfers of each kind have been completed 479by the controller. 480.It Dv USB_REQUEST Fa "struct usb_ctl_request *" 481This command can be used to execute arbitrary requests on the control pipe. 482This is 483.Em DANGEROUS 484and should be used with great care since it 485can destroy the bus integrity. 486.Pp 487The 488.Vt usb_ctl_request 489structure has the following definition: 490.Bd -literal 491typedef struct { 492 uByte bmRequestType; 493 uByte bRequest; 494 uWord wValue; 495 uWord wIndex; 496 uWord wLength; 497} __packed usb_device_request_t; 498 499struct usb_ctl_request { 500 int ucr_addr; 501 usb_device_request_t ucr_request; 502 void *ucr_data; 503 int ucr_flags; 504#define USBD_SHORT_XFER_OK 0x04 /* allow short reads */ 505 int ucr_actlen; /* actual length transferred */ 506}; 507.Ed 508.Pp 509The 510.Va ucr_addr 511field identifies the device on which to perform the request. 512The 513.Va ucr_request 514field identifies parameters of the request, such as length and type. 515The 516.Va ucr_data 517field contains the location where data will be read from or written to. 518The 519.Va ucr_flags 520field specifies options for the request, and the 521.Va ucr_actlen 522field contains the actual length transferred as the result of the request. 523.El 524.Pp 525The include file 526.Aq Pa dev/usb/usb.h 527contains definitions for the types used by the various 528.Xr ioctl 2 529calls. 530The naming convention of the fields for the various 531.Tn USB 532descriptors exactly follows the naming in the 533.Tn USB 534specification. 535Byte sized fields can be accessed directly, but word (16-bit) 536sized fields must be accessed by the 537.Fn UGETW field 538and 539.Fn USETW field value 540macros and double word (32-bit) sized fields must be accessed by the 541.Fn UGETDW field 542and 543.Fn USETDW field value 544macros to handle byte order and alignment properly. 545.Pp 546The include file 547.Aq Pa dev/usb/usbhid.h 548similarly contains the definitions for 549Human Interface Devices 550.Pq Tn HID . 551.Sh SEE ALSO 552.Xr usbhidaction 1 , 553.Xr usbhidctl 1 , 554.Xr ioctl 2 , 555.Xr ehci 4 , 556.Xr ohci 4 , 557.Xr uhci 4 , 558.Xr config 8 , 559.Xr usbdevs 8 560.Pp 561The 562.Tn USB 563specifications can be found at: 564.Pp 565.Dl http://www.usb.org/developers/docs/ 566.Sh HISTORY 567The 568.Nm 569driver 570appeared in 571.Ox 2.6 . 572