Linux-USB Gadget API

Last Modified: 11 December 2003

The <linux/usb_gadget.h> API makes it easy for peripherals and other devices (such as PDAs) embedding Linux to act in the USB "device" (slave) role. Most Linux users will not be able to use this API, since they have PC-style USB "Host Controller" hardware in a PC, workstation, or server. Smart gadgets like PDAs, printers, cash registers, and network routers will often have this type of "Device Controller" USB link.

This is the first such "USB Gadget" API on Linux to support high speed (USB 2.0) devices and arbitrary numbers of endpoints, sharing core models and data structures with the "host side" USB API. It's designed for flexibility: the API handles simple devices, composite ones, multiple configurations, class (or vendor) specific functionality, and more. It a good base for integrating and re-using this type of driver code.

Getting the Code

The API works on both 2.4 and 2.6 Linux kernels. Get the very latest code using BitKeeper:

     bk://linux.bkbits.net/linux-2.5
     bk://linux.bkbits.net/linux-2.4

     bk://usb-gadget.bkbits.net/gadget-2.6
     bk://usb-gadget.bkbits.net/gadget-2.4

Those first trees are the "official" Linux kernel trees, and they include a basic set of drivers. They're available through kernel.org as (compressed) tarballs, or as patches. The other trees are more experimental, and may have additional gadget drivers, enhancements, or fixes. (There may be other public trees with controller or gadget drivers too.) The "gadget" API is available in 2.6 kernels, as well as 2.4.23 and later.

Parts of the API

The API standardizes a boundary between two software layers, but the software stack usually has several higher layers. From the bottom up, those layers are:

The Linux 2.6 kernel tree includes kerneldoc for this API, including a structural overview as well as API reference.

Drivers

Drivers for several different usb device chips are available. Not all are listed on this page. One driver of particular interest supports the NetChip net2280. The net2280 hardware supports high speed (40+ MByte/sec) and full speed (1.5 MByte/sec) USB traffic through PCI, so it's easy for Linux developers to start with. A controller driver is also available for the full speed USB device controller (UDC) in Intel's PXA 2xx series of XScale ARM-5TE processors, used in products including Linux PDAs. The full speed UDC from several SuperH processors is supported, as is the full speed UDC from the Toshiba TC86c001 (Goku-S).

At this writing there are several public "gadget drivers", implementing USB functions.

Other controller and gadget drivers are in development, but are unreleased or not published here.

Contributing

Yes, please! Bug fixes, gadget drivers (especially "class" drivers), and USB device controller drivers will all be of interest. Discussions, patches, and similar work should be on the linux-usb-devel mailing list for now.

Thanks!

This work has been supported by patches, feedback, bug reports, hardware, and other contributions from many groups and individuals. Of particular note are NetChip Technology Inc, Agilent Technologies, Intel Corporation, Pengutronix, MontaVista Software, handhelds.org, Alan Stern, Al Borchers, Julian Back, and everyone who's contributed a patch or other feedback through the Linux-USB community.