USB(4) NetBSD Programmer's Manual USB(4)
NAME
usb - Universal Serial Bus driver
SYNOPSIS
ehci* at cardbus? dev ? function ? ehci* at pci? dev ? function ? ohci* at cardbus? dev ? function ? ohci* at pci? dev ? function ? uhci* at pci? dev ? function ? usb* at ehci? flags X usb* at ohci? flags X usb* at uhci? flags X uhub* at usb? uhub* at uhub? port ? configuration ? interface ? vendor ? product ? release ? XX* at uhub? port ? configuration ? interface ? vendor ? product ? release ? #include <dev/usb/usb.h> #include <dev/usb/usbhid.h>
DESCRIPTION
NetBSD provides machine-independent bus support and drivers for USB de- vices. The NetBSD usb driver has three layers (like scsi(4) and pcmcia(4)): the controller, the bus, and the device layer. The controller attaches to a physical bus (like pci(4)). The USB bus attaches to the controller and the root hub attaches to the controller. Further devices, which may in- clude further hubs, attach to other hubs. The attachment forms the same tree structure as the physical USB device tree. For each USB device there may be additional drivers attached to it. The uhub device controls USB hubs and must always be present since there is at least a root hub in any USB system. The flags argument to the usb device affects the order in which the de- vice detection happens during cold boot. Normally, only the USB host controller and the usb device are detected during the autoconfiguration when the machine is booted. The rest of the devices are detected once the system becomes functional and the kernel thread for the usb device is started. Sometimes it is desirable to have a device detected early in the boot process, e.g., the console keyboard. To achieve this use a flags value of 1.
SUPPORTED DEVICES
NetBSD includes machine-independent USB drivers, sorted by driver name: aue driver for ADMtek AN986 Pegasus USB Ethernet. cue driver for CATC USB-EL1201A USB Ethernet. kue driver for Kawasaki LSI KL5KUSB101B USB Ethernet. url driver for Realtek RTL8150L USB Ethernet. uaudio driver for audio devices. udsbr driver for D-Link DSB-R100 USB radio. uftdi driver for FTDI based serial adapters. ugen generic driver for USB devices. uhidev top level HID driver. uhid generic driver for Human Interface Devices. uirda driver for USB-IrDA bridges. ukbd keyboard driver. ulpt printer driver. umass driver for mass storage devices, such as disks. umidi driver for MIDI devices. umodem driver for communication devices that use the Abstract Control Model. ums mouse driver. upl driver for Prolific host-to-host adapter. uplcom driver for Prolific 2303 serial adapter. umct driver for MCT USB-RS232 serial adapter. urio driver for the Diamond Rio 500 MP3 player. uscanner driver for some USB scanners. usscanner driver for some SCSI-over-USB scanners. ustir driver for SigmaTel STIr4200 USB-IrDA bridges. uvisor Handspring Visor driver. uvscom driver for SUNTAC Slipper U VS-10U serial adapter.
INTRODUCTION TO USB
The USB 1.x is a 12 Mb/s serial bus with 1.5 Mb/s for low speed devices. USB 2.x handles 480 Mb/s. Each USB has a host controller that is the master of the bus; all other devices on the bus only speak when spoken to. 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. Within each device there can be up to 16 endpoints. Each endpoint is in- dividually addressed and the addresses are static. Each of these end- points will communicate in one of four different modes: control, isochronous, bulk, or interrupt. A device always has at least one end- point. 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. 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 key- board 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. A device may operate in different configurations. Depending on the con- figuration the device may present different sets of endpoints and inter- faces. Each device located on a hub has several config(8) locators: port this is the number of the port on closest upstream hub. configuration this is the configuration the device must be in for this driv- er to attach. This locator does not set the configuration; it is iterated by the bus enumeration. interface this is the interface number within a device that an interface driver attaches to. vendor this is the 16 bit vendor id of the device. product this is the 16 bit product id of the device. release this is the 16 bit release (revision) number of the device. 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 actu- ally is. The bus enumeration of the USB bus proceeds in several steps: 1. Any device specific driver can to attach to the device. 2. If none is found, any device class specific driver can attach. 3. If none is found, all configurations are iterated over. For each configuration all the interface are iterated over and interface drivers can attach. If any interface driver attached in a certain configuration the iteration over configurations is stopped. 4. If still no drivers have been found, the generic USB driver can at- tach.
USB CONTROLLER INTERFACE
Use the following to get access to the USB specific structures and de- fines. #include <sys/dev/usb.h> The /dev/usbN can be opened and a few operations can be performed on it. The poll(2) system call will say that I/O is possible on the controller device when a USB device has been connected or disconnected to the bus. The following ioctl(2) commands are supported on the controller device: USB_DEVICEINFO struct usb_device_info This command can be used to retrieve some information about a de- vice on the bus. The addr field should be filled before the call and the other fields will be filled by information about the de- vice on that address. Should no such device exist an error is reported. struct usb_device_info { u_int8_t bus; u_int8_t addr; 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; 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 }; The product, vendor, and release fields contain self-explanatory descriptions of the device. The class field contains the device class. The config field shows the current configuration of the device. The lowspeed field is set if the device is a USB low speed de- vice. The power field shows the power consumption in milli-amps drawn at 5 volts, or zero if the device is self powered. If the device is a hub the nports field is non-zero and the ports field contains the addresses of the connected devices. If no de- vice is connected to a port one of the USB_PORT_* values indi- cates its status. USB_DEVICESTATS struct usb_device_stats This command retrieves statistics about the controller. struct usb_device_stats { u_long requests[4]; }; The requests field is indexed by the transfer kind, i.e. UE_*, and indicates how many transfers of each kind that has been com- pleted by the controller. USB_REQUEST struct usb_ctl_request This command can be used to execute arbitrary requests on the control pipe. This is DANGEROUS and should be used with great care since it can destroy the bus integrity. The include file <dev/usb/usb.h> contains definitions for the types used by the various ioctl(2) calls. The naming convention of the fields for the various USB descriptors exactly follows the naming in the USB speci- fication. Byte sized fields can be accessed directly, but word (16 bit) sized fields must be access by the UGETW(field) and USETW(field, value) macros to handle byte order and alignment properly. The include file <dev/usb/usbhid.h> similarly contains the definitions for Human Interface Devices (HID).
USB EVENT INTERFACE
All USB events are reported via the /dev/usb device. This devices can be opened for reading and each read(2) will yield an event record (if some- thing has happened). The poll(2) system call can be used to determine if an event record is available for reading. The event record has the following definition: 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; }; The ue_type field identifies the type of event that is described. The possible events are attach/detach of a host controller, a device, or a device driver. The union contains information pertinent to the different types of events. The ue_bus contains the number of the USB bus for host controller events. The ue_device record contains information about the device in a device event event. The ue_cookie is an opaque value that uniquely determines which which de- vice a device driver has been attached to (i.e., it equals the cookie value in the device that the driver attached to). The ue_devname con- tains the name of the device (driver) as seen in, e.g., kernel messages. Note that that there is a separation between device and device driver events. A device event is generated when a physical USB device is at- tached or detached. A single USB device may have zero, one, or many de- vice drivers associated with it.
SEE ALSO
The USB specifications can be found at: http://www.usb.org/developers/docs.html usb(3), aue(4), cardbus(4), cue(4), ehci(4), kue(4), ohci(4), pci(4), uaudio(4), ucom(4), udsbr(4), ugen(4), uhci(4), uhid(4), uhidev(4), uirda(4), ukbd(4), ulpt(4), umass(4), umidi(4), ums(4), upl(4), url(4), urio(4), uscanner(4), usscanner(4), ustir(4), uvisor(4), usbdevs(8)
HISTORY
The usb driver appeared in NetBSD 1.4.
BUGS
There should be a serial number locator, but NetBSD does not have string valued locators. NetBSD 1.6.1 July 12, 1998 5
Powered by man-cgi (2024-08-26). Maintained for NetBSD by Kimmo Suominen. Based on man-cgi by Panagiotis Christias.