1999-01-14 14:07:44 +03:00
|
|
|
.\" $NetBSD: usb.4,v 1.10 1999/01/14 11:07:44 augustss Exp $
|
1998-07-12 23:51:55 +04:00
|
|
|
.\" Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\" 3. All advertising materials mentioning features or use of this software
|
|
|
|
.\" must display the following acknowledgement:
|
|
|
|
.\" This product includes software developed by the NetBSD
|
|
|
|
.\" Foundation, Inc. and its contributors.
|
|
|
|
.\" 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
.\" contributors may be used to endorse or promote products derived
|
|
|
|
.\" from this software without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
1999-01-14 09:29:18 +03:00
|
|
|
.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
1998-07-12 23:51:55 +04:00
|
|
|
.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
.\" POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.Dd July 12, 1998
|
|
|
|
.Dt USB 4
|
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm usb
|
1999-01-14 09:29:18 +03:00
|
|
|
.Nd Universal Serial Bus driver
|
1998-07-12 23:51:55 +04:00
|
|
|
.Sh SYNOPSIS
|
1998-10-25 22:24:19 +03:00
|
|
|
.Cd "uhci* at pci? function ?"
|
|
|
|
.Cd "ohci* at pci? function ?"
|
1998-07-12 23:51:55 +04:00
|
|
|
.Cd "usb* at uhci?"
|
|
|
|
.Cd "usb* at ohci?"
|
|
|
|
.Cd "uhub* at usb?"
|
1998-12-11 02:43:32 +03:00
|
|
|
.Cd "uhub* at uhub? port ? configuration ? interface ?"
|
1998-12-08 17:21:48 +03:00
|
|
|
.Cd "XX* at uhub? port ? configuration ? interface ?"
|
1998-07-12 23:51:55 +04:00
|
|
|
.Pp
|
1998-12-07 16:11:47 +03:00
|
|
|
.Cd "#include <dev/usb/usb.h>"
|
|
|
|
.Cd "#include <dev/usb/usbhid.h>"
|
1998-07-12 23:51:55 +04:00
|
|
|
.Sh INTRODUCTION
|
|
|
|
.Nx
|
1999-01-14 09:29:18 +03:00
|
|
|
provides machine-independent bus support and drivers for
|
|
|
|
.Tn USB
|
|
|
|
devices.
|
1998-07-12 23:51:55 +04:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Nx
|
1999-01-14 09:29:18 +03:00
|
|
|
.Nm
|
1998-07-12 23:51:55 +04:00
|
|
|
driver has three layers (like
|
|
|
|
.Xr scsi 4
|
|
|
|
and
|
|
|
|
.Xr pcmcia 4 ):
|
|
|
|
the controller, the bus, and the device layer.
|
|
|
|
The controller attaches to a physical bus (like
|
|
|
|
.Xr pci 4 ).
|
1999-01-14 09:29:18 +03:00
|
|
|
The
|
|
|
|
.Tn USB
|
|
|
|
bus attaches to the controller and the root hub attaches
|
|
|
|
to the controller.
|
|
|
|
Further devices, which may include further hubs,
|
|
|
|
attach to other hubs.
|
|
|
|
The attachment forms the same tree structure as the physical
|
|
|
|
.Tn USB
|
|
|
|
device tree.
|
|
|
|
For each
|
|
|
|
.Tn USB
|
|
|
|
device there may be additional drivers attached to it.
|
1998-07-12 23:51:55 +04:00
|
|
|
.Pp
|
|
|
|
The
|
|
|
|
.Cm uhub
|
1999-01-14 09:29:18 +03:00
|
|
|
device controls
|
|
|
|
.Tn USB
|
|
|
|
hubs and must always be present since there is at least a root hub in any
|
|
|
|
.Tn USB
|
|
|
|
system.
|
1998-07-12 23:51:55 +04:00
|
|
|
.Pp
|
|
|
|
.Sh INTRODUCTION TO USB
|
1999-01-14 09:29:18 +03:00
|
|
|
The
|
|
|
|
.Tn USB
|
|
|
|
is a 12 Mb/s serial bus (1.5 Mb/s for low speed devices).
|
|
|
|
Each
|
|
|
|
.Tn USB
|
|
|
|
has a host controller that is the master of the bus;
|
1998-07-12 23:51:55 +04:00
|
|
|
all other devices on the bus only speak when spoken to.
|
|
|
|
.Pp
|
|
|
|
There can be up to 127 devices (apart from the host controller)
|
1999-01-14 09:29:18 +03:00
|
|
|
on a bus, each with its own address.
|
|
|
|
The addresses are assigned
|
1998-10-22 14:42:01 +04:00
|
|
|
dynamically by the host when each device is attached to the bus.
|
1998-07-12 23:51:55 +04:00
|
|
|
.Pp
|
1999-01-14 09:29:18 +03:00
|
|
|
Within each device there can be up to 16 endpoints.
|
|
|
|
Each endpoint
|
1998-07-12 23:51:55 +04:00
|
|
|
is individually addressed and the addresses are static.
|
|
|
|
Each of these endpoints will communicate in one of four different modes:
|
1999-01-14 09:29:18 +03:00
|
|
|
control, isochronous, bulk, or interrupt.
|
|
|
|
A device always has at least one endpoint.
|
|
|
|
This endpoint has address 0 and is a control
|
1998-10-22 14:42:01 +04:00
|
|
|
endpoint and is used to give commands to and extract basic data,
|
|
|
|
such as descriptors, from the device.
|
|
|
|
Each endpoint, except the control endpoint, is unidirectional.
|
1998-07-12 23:51:55 +04:00
|
|
|
.Pp
|
1999-01-14 09:29:18 +03:00
|
|
|
The endpoints in a device are grouped into interfaces.
|
|
|
|
An interface is a logical unit within a device; e.g.
|
|
|
|
a compound device with both a keyboard and a trackball would present
|
|
|
|
one interface for each.
|
|
|
|
An interface can sometimes be set into different modes,
|
1998-07-12 23:51:55 +04:00
|
|
|
called alternate settings, which affects how it operates.
|
|
|
|
Different alternate settings can have different endpoints
|
|
|
|
within it.
|
|
|
|
.Pp
|
1999-01-14 09:29:18 +03:00
|
|
|
A device may operate in different configurations.
|
|
|
|
Depending on the
|
1998-07-12 23:51:55 +04:00
|
|
|
configuration the device may present different sets of endpoints
|
|
|
|
and interfaces.
|
1998-12-08 17:21:48 +03:00
|
|
|
.Pp
|
1999-01-14 09:29:18 +03:00
|
|
|
Each device located on a hub has several
|
|
|
|
.Xr config 8
|
|
|
|
locators:
|
|
|
|
.Bl -tag -compact -width xxxxxx
|
|
|
|
.It Cd port
|
1998-12-08 17:21:48 +03:00
|
|
|
this is the number of the port on closest upstream hub.
|
1999-01-14 09:29:18 +03:00
|
|
|
.It Cd configuration
|
1998-12-08 17:21:48 +03:00
|
|
|
this is the configuration the device must be in for this driver to attach.
|
1999-01-14 09:29:18 +03:00
|
|
|
This locator does not set the configuration; it is iterated by the bus
|
1998-12-08 17:21:48 +03:00
|
|
|
enumeration.
|
1999-01-14 09:29:18 +03:00
|
|
|
.It Cd interface
|
|
|
|
this is the interface number within a device that an interface driver
|
1998-12-08 17:21:48 +03:00
|
|
|
attaches to.
|
|
|
|
.El
|
|
|
|
.Pp
|
1999-01-14 09:29:18 +03:00
|
|
|
The bus enumeration of the
|
|
|
|
.Tn USB
|
|
|
|
bus proceeds in several steps:
|
|
|
|
.Bl -enum
|
|
|
|
.It
|
1998-12-08 17:21:48 +03:00
|
|
|
Any device specific driver can to attach to the device.
|
1999-01-14 09:29:18 +03:00
|
|
|
.It
|
1998-12-08 17:21:48 +03:00
|
|
|
If none is found, any device class specific driver can attach.
|
1999-01-14 09:29:18 +03:00
|
|
|
.It
|
1998-12-08 17:21:48 +03:00
|
|
|
If none is found, all configurations are iterated over.
|
|
|
|
For each configuration all the interface are iterated over and interface
|
1999-01-14 09:29:18 +03:00
|
|
|
drivers can attach.
|
|
|
|
If any interface driver attached in a certain
|
1998-12-08 17:21:48 +03:00
|
|
|
configuration the iteration over configurations is stopped.
|
1999-01-14 09:29:18 +03:00
|
|
|
.It
|
|
|
|
If still no drivers have been found, the generic
|
|
|
|
.Tn USB
|
|
|
|
driver can attach.
|
1998-12-08 17:21:48 +03:00
|
|
|
.El
|
1998-07-27 02:22:26 +04:00
|
|
|
.Sh USB CONTROLLER INTERFACE
|
1999-01-14 09:29:18 +03:00
|
|
|
Use the following to get access to the
|
|
|
|
.Tn USB
|
|
|
|
specific structurs and defines.
|
|
|
|
.Bd -literal
|
1998-07-27 02:22:26 +04:00
|
|
|
#include <sys/dev/usb.h>
|
|
|
|
.Ed
|
1998-07-12 23:51:55 +04:00
|
|
|
.Pp
|
1998-07-27 02:22:26 +04:00
|
|
|
The
|
|
|
|
.Pa /dev/usbN
|
|
|
|
can be opened and a few operations can be performed on it.
|
|
|
|
The
|
|
|
|
.Xr poll 2
|
|
|
|
system call will say that I/O is possible on the controller device when a
|
1999-01-14 09:29:18 +03:00
|
|
|
.Tn USB
|
|
|
|
device has been connected or disconnected to the bus.
|
1998-07-27 02:22:26 +04:00
|
|
|
.Pp
|
|
|
|
The following
|
|
|
|
.Xr ioctl 2
|
|
|
|
commands are supported on the controller device:
|
1999-01-14 09:29:18 +03:00
|
|
|
.Bl -tag -width xxxxxx
|
1998-07-27 02:22:26 +04:00
|
|
|
.It Dv USB_DISCOVER
|
|
|
|
This command will cause a complete bus discovery to be initiated.
|
|
|
|
If any devices attached or detached from the bus they will be
|
1999-01-14 09:29:18 +03:00
|
|
|
processed during this command.
|
|
|
|
This is the only way that new devices are found on the bus.
|
|
|
|
.It Dv USB_DEVICEINFO Fa "struct usb_device_info"
|
1998-07-27 02:22:26 +04:00
|
|
|
This command can be used to retrieve some information about a device
|
1999-01-14 09:29:18 +03:00
|
|
|
on the bus.
|
|
|
|
The
|
1998-07-27 02:22:26 +04:00
|
|
|
.Va addr
|
1999-01-14 09:29:18 +03:00
|
|
|
field should be filled before the call and the other fields will
|
|
|
|
be filled by information about the device on that address.
|
|
|
|
Should no such device exist an error is reported.
|
1998-07-27 02:22:26 +04:00
|
|
|
.Bd -literal
|
|
|
|
struct usb_device_info {
|
|
|
|
uByte addr; /* device address */
|
|
|
|
char product[USB_MAX_STRING_LEN];
|
|
|
|
char vendor[USB_MAX_STRING_LEN];
|
|
|
|
char revision[8];
|
|
|
|
uByte class;
|
|
|
|
uByte config;
|
|
|
|
uByte lowspeed;
|
|
|
|
int power;
|
|
|
|
int nports;
|
|
|
|
uByte ports[16];
|
|
|
|
#define USB_PORT_ENABLED 0xff
|
|
|
|
#define USB_PORT_SUSPENDED 0xfe
|
|
|
|
#define USB_PORT_POWERED 0xfd
|
|
|
|
#define USB_PORT_DISABLED 0xfc
|
|
|
|
};
|
|
|
|
.Ed
|
1999-01-14 09:29:18 +03:00
|
|
|
.Pp
|
1998-07-27 02:22:26 +04:00
|
|
|
The
|
|
|
|
.Va product ,
|
|
|
|
.Va vendor ,
|
|
|
|
and
|
|
|
|
.Va revision
|
1999-01-14 09:29:18 +03:00
|
|
|
fields contain self-explanatory descriptions of the device.
|
|
|
|
.Pp
|
1998-07-27 02:22:26 +04:00
|
|
|
The
|
|
|
|
.Va class
|
1998-10-22 14:42:01 +04:00
|
|
|
field contains the device class.
|
1999-01-14 09:29:18 +03:00
|
|
|
.Pp
|
1998-07-27 02:22:26 +04:00
|
|
|
The
|
|
|
|
.Va config
|
|
|
|
field shows the current configuration of the device.
|
1999-01-14 09:29:18 +03:00
|
|
|
.Pp
|
1998-07-27 02:22:26 +04:00
|
|
|
The
|
|
|
|
.Va lowspeed
|
|
|
|
field
|
1999-01-14 09:29:18 +03:00
|
|
|
is set if the device is a
|
|
|
|
.Tn USB
|
|
|
|
low speed device.
|
|
|
|
.Pp
|
1998-07-27 02:22:26 +04:00
|
|
|
The
|
|
|
|
.Va power
|
1999-01-14 09:29:18 +03:00
|
|
|
field shows the power consumption in milli-amps drawn at 5 volts,
|
|
|
|
or zero if the device is self powered.
|
1998-07-27 02:22:26 +04:00
|
|
|
.Pp
|
|
|
|
If the device is a hub the
|
|
|
|
.Va nports
|
|
|
|
field is non-zero and the
|
|
|
|
.Va ports
|
|
|
|
field contains the addresses of the connected devices.
|
|
|
|
If no device is connected to a port one of the
|
|
|
|
.Va USB_PORT_*
|
|
|
|
values indicates its status.
|
1999-01-14 09:29:18 +03:00
|
|
|
.It Dv USB_DEVICESTATS Fa "struct usb_device_stats"
|
|
|
|
This command retrieves statistics about the controller.
|
1998-07-27 02:22:26 +04:00
|
|
|
.Bd -literal
|
|
|
|
struct usb_device_stats {
|
|
|
|
u_long requests[4];
|
|
|
|
};
|
|
|
|
.Ed
|
1999-01-14 09:29:18 +03:00
|
|
|
.Pp
|
1998-07-27 02:22:26 +04:00
|
|
|
The
|
|
|
|
.Va requests
|
1999-01-14 09:29:18 +03:00
|
|
|
field is indexed by the transfer kind, i.e.
|
1998-07-27 02:22:26 +04:00
|
|
|
.Va UE_* ,
|
|
|
|
and indicates how many transfers of each kind that has been completed
|
1998-10-22 14:42:01 +04:00
|
|
|
by the controller.
|
1999-01-14 09:29:18 +03:00
|
|
|
.It Dv USB_REQUEST Fa "struct usb_ctl_request"
|
|
|
|
This command can be used to execute arbitrary requests on the control pipe.
|
|
|
|
This is
|
|
|
|
.Em DANGEROUS
|
|
|
|
and should be used with great care since it
|
1998-10-22 14:42:01 +04:00
|
|
|
can destroy the bus integrity.
|
1998-07-27 02:22:26 +04:00
|
|
|
.El
|
1998-12-07 16:11:47 +03:00
|
|
|
.Pp
|
|
|
|
The include file
|
1999-01-14 09:29:18 +03:00
|
|
|
.Aq Pa dev/usb/usb.h
|
|
|
|
contains definitions for the types used by the various
|
1998-12-07 16:11:47 +03:00
|
|
|
.Xr ioctl 2
|
1999-01-14 09:29:18 +03:00
|
|
|
calls.
|
|
|
|
The naming convention of the fields for the various
|
|
|
|
.Tn USB
|
|
|
|
descriptors exactly follows the naming in the
|
|
|
|
.Tn USB
|
|
|
|
specification.
|
1998-12-07 16:11:47 +03:00
|
|
|
Byte sized fields can be accessed directly, but word (16 bit)
|
|
|
|
sized fields must be access by the
|
1999-01-14 09:29:18 +03:00
|
|
|
.Fn UGETW field
|
1998-12-07 16:11:47 +03:00
|
|
|
and
|
1999-01-14 09:29:18 +03:00
|
|
|
.Fn USETW field value
|
1998-12-07 16:11:47 +03:00
|
|
|
macros to handle byte order and alignment properly.
|
1999-01-14 09:29:18 +03:00
|
|
|
.Pp
|
1998-12-07 16:11:47 +03:00
|
|
|
The include file
|
1999-01-14 09:29:18 +03:00
|
|
|
.Aq Pa dev/usb/usbhid.h
|
|
|
|
similarly contains the definitions for
|
|
|
|
Human Interface Devices
|
|
|
|
.Pq Tn HID .
|
1998-07-12 23:51:55 +04:00
|
|
|
.Sh SEE ALSO
|
1999-01-14 14:07:44 +03:00
|
|
|
The
|
|
|
|
.Tn USB
|
|
|
|
specifications can be found at
|
|
|
|
.Dv http://www.usb.org/developers/docs.htm .
|
|
|
|
.Pp
|
1998-07-12 23:51:55 +04:00
|
|
|
.Xr pci 4 ,
|
|
|
|
.Xr uaudio 4 ,
|
|
|
|
.Xr ugen 4 ,
|
|
|
|
.Xr uhid 4 ,
|
|
|
|
.Xr ukbd 4 ,
|
|
|
|
.Xr ulpt 4 ,
|
|
|
|
.Xr ums 4 ,
|
1998-07-13 00:56:23 +04:00
|
|
|
.Xr usbd 8 ,
|
|
|
|
.Xr usbdevs 8
|
1998-07-12 23:51:55 +04:00
|
|
|
.Sh HISTORY
|
|
|
|
The
|
|
|
|
.Nm
|
|
|
|
driver
|
|
|
|
appeared in
|
|
|
|
.Nx 1.4 .
|