freebsd-skq/share/man/man4/usb.4

408 lines
12 KiB
Groff
Raw Normal View History

1999-02-21 16:56:33 +00:00
.\" Copyright (c) 1997, 1998
.\" Nick Hibma <n_hibma@FreeBSD.org>. All rights reserved.
1999-02-21 16:56:33 +00:00
.\"
.\" 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. Neither the name of the author nor the names of any co-contributors
1999-02-21 16:56:33 +00:00
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY NICK HIBMA 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 PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL NICK HIBMA OR THE VOICES IN HIS HEAD
.\" 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.
.\"
1999-08-28 00:22:10 +00:00
.\" $FreeBSD$
1999-02-21 16:56:33 +00:00
.\"
.Dd February 21, 1999
.Dt USB 4
.Os
1999-02-21 16:56:33 +00:00
.Sh NAME
.Nm usb
.Nd Universal Serial Bus
.Sh SYNOPSIS
.Cd "device usb"
2002-01-28 00:48:28 +00:00
.Pp
2002-03-18 14:35:22 +00:00
.In dev/usb/usb.h
.In dev/usb/usbhid.h
1999-02-21 16:56:33 +00:00
.Sh DESCRIPTION
.Fx
1999-02-21 16:56:33 +00:00
provides machine-independent bus support and drivers for
.Tn USB
devices.
.Pp
The
.Nm
driver has three layers: the controller, the bus, and the
device layer.
The controller attaches to a physical bus
1999-02-21 16:56:33 +00:00
(like
2001-01-16 09:32:40 +00:00
.Xr pci 4 ) .
1999-02-21 16:56:33 +00:00
The
.Tn USB
2002-03-18 14:35:22 +00:00
bus attaches to the controller, and the root hub attaches
1999-02-21 16:56:33 +00:00
to the controller.
Any devices attached to the bus will attach to the root hub
2002-03-18 14:35:22 +00:00
or another hub attached to the
.Tn USB
bus.
1999-02-21 16:56:33 +00:00
.Pp
The
.Nm uhub
device will always be present as it is needed for the
root hub.
.Sh INTRODUCTION TO USB
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;
all other devices on the bus only speak when spoken to.
.Pp
There can be up to 127 devices (apart from the host controller)
on a bus, each with its own address.
The addresses are assigned
dynamically by the host when each device is attached to the bus.
.Pp
Within each device there can be up to 16 endpoints.
Each endpoint
is individually addressed and the addresses are static.
Each of these endpoints will communicate in one of four different modes:
2002-03-18 14:35:22 +00:00
.Em control , isochronous , bulk ,
or
.Em interrupt .
1999-02-21 16:56:33 +00:00
A device always has at least one endpoint.
This endpoint has address 0 and is a control
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.
.Pp
The endpoints in a device are grouped into interfaces.
An interface is a logical unit within a device; e.g.\&
1999-02-21 16:56:33 +00:00
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,
called alternate settings, which affects how it operates.
Different alternate settings can have different endpoints
within it.
.Pp
A device may operate in different configurations.
Depending on the
2002-03-18 14:35:22 +00:00
configuration, the device may present different sets of endpoints
1999-02-21 16:56:33 +00:00
and interfaces.
.\" .Pp
.\" Each device located on a hub has several
.\" .Xr config 8
.\" locators:
.\" .Bl -tag -compact -width xxxxxx
.\" .It Cd port
.\" this is the number of the port on the closest upstream hub.
.\" .It Cd configuration
.\" this is the configuration the device must be in for this driver to attach.
.\" This locator does not set the configuration; it is iterated by the bus
.\" enumeration.
.\" .It Cd interface
.\" this is the interface number within a device that an interface driver
.\" attaches to.
.\" .It Cd vendor
.\" this is the 16 bit vendor id of the device.
.\" .It Cd product
.\" this is the 16 bit product id of the device.
.\" .It Cd release
.\" this is the 16 bit release (revision) number of the device.
.\" .El
.\" The first locator can be used to pin down a particular device
.\" according to its physical position in the device tree.
.\" The last three locators can be used to pin down a particular
.\" device according to what device it actually is.
1999-02-21 16:56:33 +00:00
.Pp
The bus enumeration of the
.Tn USB
bus proceeds in several steps:
.Bl -enum
.It
2002-03-18 14:35:22 +00:00
Any device specific driver can attach to the device.
1999-02-21 16:56:33 +00:00
.It
If none is found, any device class specific driver can attach.
.It
If none is found, all configurations are iterated over.
2002-03-18 14:35:22 +00:00
For each configuration, all the interfaces are iterated over, and interface
1999-02-21 16:56:33 +00:00
drivers can attach.
If any interface driver attached in a certain
2002-03-18 14:35:22 +00:00
configuration, the iteration over configurations is stopped.
1999-02-21 16:56:33 +00:00
.It
If still no drivers have been found, the generic
.Tn USB
driver can attach.
.El
.Sh USB CONTROLLER INTERFACE
Use the following to get access to the
.Tn USB
2002-01-21 12:09:13 +00:00
specific structures and defines.
2002-03-18 14:35:22 +00:00
.Pp
.In dev/usb/usb.h
1999-02-21 16:56:33 +00:00
.Pp
The
2002-03-18 14:35:22 +00:00
.Pa /dev/usb Ns Ar N
1999-02-21 16:56:33 +00:00
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
.Tn USB
device has been connected or disconnected to the bus.
.Pp
The following
.Xr ioctl 2
commands are supported on the controller device:
.Bl -tag -width xxxxxx
.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
processed during this command.
This is the only way that new devices are found on the bus.
2002-03-18 14:35:22 +00:00
.It Dv USB_DEVICEINFO Vt "struct usb_device_info"
1999-02-21 16:56:33 +00:00
This command can be used to retrieve some information about a device
on the bus.
The
.Va addr
field should be filled before the call and the other fields will
be filled by information about the device on that address.
2002-03-18 14:35:22 +00:00
Should no such device exist, an error is reported.
1999-02-21 16:56:33 +00:00
.Bd -literal
struct usb_device_info {
u_int8_t bus;
u_int8_t addr;
2002-01-28 00:48:28 +00:00
usb_event_cookie_t cookie;
char product[USB_MAX_STRING_LEN];
char vendor[USB_MAX_STRING_LEN];
char release[8];
u_int16_t productNo;
u_int16_t vendorNo;
u_int16_t releaseNo;
u_int8_t class;
u_int8_t subclass;
u_int8_t protocol;
u_int8_t config;
u_int8_t lowspeed;
int power;
int nports;
2002-01-28 00:48:28 +00:00
char devnames[USB_MAX_DEVNAMES][USB_MAX_DEVNAMELEN];
u_int8_t ports[16];
#define USB_PORT_ENABLED 0xff
#define USB_PORT_SUSPENDED 0xfe
#define USB_PORT_POWERED 0xfd
#define USB_PORT_DISABLED 0xfc
1999-02-21 16:56:33 +00:00
};
.Ed
.Pp
.Va bus
and
.Va addr
contain the topological information for the device.
.Va devnames
contains the device names of the connected drivers.
2002-03-18 14:35:22 +00:00
For example, the
third
.Tn USB
Zip drive connected will be
.Li umass2 .
1999-02-21 16:56:33 +00:00
The
.Va product , vendor
1999-02-21 16:56:33 +00:00
and
.Va release
1999-02-21 16:56:33 +00:00
fields contain self-explanatory descriptions of the device.
.Va productNo , vendorNo , releaseNo , class , subclass
and
.Va protocol
contain the corresponding values from the device descriptors.
1999-02-21 16:56:33 +00:00
The
.Va config
field shows the current configuration of the device.
.Pp
.Va lowspeed
indicates whether the device is a full speed (0) or low speed (1)
device.
The
1999-02-21 16:56:33 +00:00
.Va power
field shows the power consumption in milli-amps drawn at 5 volts,
or zero if the device is self powered.
.Pp
2002-03-18 14:35:22 +00:00
If the device is a hub, the
1999-02-21 16:56:33 +00:00
.Va nports
2002-03-18 14:35:22 +00:00
field is non-zero, and the
1999-02-21 16:56:33 +00:00
.Va ports
field contains the addresses of the connected devices.
2002-03-18 14:35:22 +00:00
If no device is connected to a port, one of the
.Dv USB_PORT_*
1999-02-21 16:56:33 +00:00
values indicates its status.
2002-03-18 14:35:22 +00:00
.It Dv USB_DEVICESTATS Vt "struct usb_device_stats"
1999-02-21 16:56:33 +00:00
This command retrieves statistics about the controller.
.Bd -literal
struct usb_device_stats {
u_long requests[4];
};
.Ed
.Pp
The
.Va requests
field is indexed by the transfer kind, i.e.\&
2002-03-18 14:35:22 +00:00
.Dv UE_* ,
1999-02-21 16:56:33 +00:00
and indicates how many transfers of each kind that has been completed
by the controller.
2002-03-18 14:35:22 +00:00
.It Dv USB_REQUEST Vt "struct usb_ctl_request"
1999-02-21 16:56:33 +00:00
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
can destroy the bus integrity.
.El
.Pp
The include file
.Aq Pa dev/usb/usb.h
contains definitions for the types used by the various
.Xr ioctl 2
calls.
The naming convention of the fields for the various
.Tn USB
descriptors exactly follows the naming in the
.Tn USB
specification.
Byte sized fields can be accessed directly, but word (16 bit)
sized fields must be access by the
.Fn UGETW field
and
.Fn USETW field value
macros to handle byte order and alignment properly.
.Pp
The include file
.Aq Pa dev/usb/usbhid.h
similarly contains the definitions for
Human Interface Devices
.Pq Tn HID .
.Sh USB EVENT INTERFACE
All
.Tn USB
events are reported via the
.Pa /dev/usb
2002-03-18 14:35:22 +00:00
device.
This devices can be opened for reading and each
.Xr read 2
will yield an event record (if something has happened).
The
.Xr poll 2
system call can be used to determine if an event record is available
for reading.
.Pp
The event record has the following definition:
.Bd -literal
struct usb_event {
int ue_type;
#define USB_EVENT_CTRLR_ATTACH 1
#define USB_EVENT_CTRLR_DETACH 2
#define USB_EVENT_DEVICE_ATTACH 3
#define USB_EVENT_DEVICE_DETACH 4
#define USB_EVENT_DRIVER_ATTACH 5
#define USB_EVENT_DRIVER_DETACH 6
struct timespec ue_time;
union {
struct {
int ue_bus;
} ue_ctrlr;
struct usb_device_info ue_device;
struct {
usb_event_cookie_t ue_cookie;
char ue_devname[16];
} ue_driver;
} u;
};
.Ed
The
.Va ue_type
field identifies the type of event that is described.
The possible events are attach/detach of a host controller,
2002-03-18 14:35:22 +00:00
a device, or a device driver.
The union contains information
pertinent to the different types of events.
2002-03-18 14:35:22 +00:00
.Pp
The
.Va ue_bus
contains the number of the
.Tn USB
bus for host controller events.
2002-03-18 14:35:22 +00:00
.Pp
The
.Va ue_device
record contains information about the device in a device event event.
2002-03-18 14:35:22 +00:00
.Pp
The
.Va ue_cookie
is an opaque value that uniquely determines which which
device a device driver has been attached to (i.e., it equals
the cookie value in the device that the driver attached to).
2002-03-18 14:35:22 +00:00
.Pp
The
.Va ue_devname
contains the name of the device (driver) as seen in, e.g.,
kernel messages.
.Pp
2002-03-18 14:35:22 +00:00
Note that there is a separation between device and device
driver events.
A device event is generated when a physical
.Tn USB
device is attached or detached.
A single
.Tn USB
device may
have zero, one, or many device drivers associated with it.
1999-02-21 16:56:33 +00:00
.Sh SEE ALSO
The
.Tn USB
2002-01-28 00:48:28 +00:00
specifications can be found at:
2002-03-18 14:35:22 +00:00
.Pp
.D1 Pa http://www.usb.org/developers/docs.html
1999-02-21 16:56:33 +00:00
.Pp
2002-01-28 00:48:28 +00:00
.Xr aue 4 ,
.Xr cue 4 ,
.Xr kue 4 ,
1999-02-21 16:56:33 +00:00
.Xr ohci 4 ,
.Xr pci 4 ,
.Xr ucom 4 ,
2002-01-28 00:48:28 +00:00
.Xr ugen 4 ,
.Xr uhci 4 ,
1999-02-21 16:56:33 +00:00
.Xr uhid 4 ,
.Xr ukbd 4 ,
.Xr ulpt 4 ,
2002-01-28 00:48:28 +00:00
.Xr umass 4 ,
1999-02-21 16:56:33 +00:00
.Xr ums 4 ,
2002-01-28 00:48:28 +00:00
.Xr urio 4 ,
.Xr uscanner 4 ,
2002-03-18 14:35:22 +00:00
.Xr usbd 8 ,
1999-02-21 16:56:33 +00:00
.Xr usbdevs 8
.Sh HISTORY
The
.Nm
driver first appeared in
.Fx 3.0 .
.Sh AUTHORS
1999-02-21 16:56:33 +00:00
The
.Nm
driver was written by
.An Lennart Augustsson Aq augustss@carlstedt.se
for the
1999-02-21 16:56:33 +00:00
.Nx
project.