USB Gadget API for Linux

David Brownell

This documentation is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

For more details see the file COPYING in the source distribution of Linux.


Table of Contents
1. Introduction
2. Structure of Gadget Drivers
3. Kernel Mode Gadget API
3.1. Driver Life Cycle
3.2. USB 2.0 Chapter 9 Types and Constants
struct usb_ctrlrequest --  SETUP data for a USB device control request
3.3. Core Objects and Methods
struct usb_request --  describes one i/o request
struct usb_ep --  device side representation of USB endpoint
usb_ep_enable --  configure endpoint, making it usable
usb_ep_disable --  endpoint is no longer usable
usb_ep_alloc_request --  allocate a request object to use with this endpoint
usb_ep_free_request --  frees a request object
usb_ep_alloc_buffer --  allocate an I/O buffer
usb_ep_free_buffer --  frees an i/o buffer
usb_ep_queue --  queues (submits) an I/O request to an endpoint.
usb_ep_dequeue --  dequeues (cancels, unlinks) an I/O request from an endpoint
usb_ep_set_halt --  sets the endpoint halt feature.
usb_ep_clear_halt --  clears endpoint halt, and resets toggle
usb_ep_fifo_status --  returns number of bytes in fifo, or error
usb_ep_fifo_flush --  flushes contents of a fifo
struct usb_gadget --  represents a usb slave device
usb_gadget_frame_number --  returns the current frame number
usb_gadget_wakeup --  tries to wake up the host connected to this gadget
usb_gadget_set_selfpowered --  sets the device selfpowered feature.
usb_gadget_clear_selfpowered --  clear the device selfpowered feature.
usb_gadget_vbus_connect --  Notify controller that VBUS is powered
usb_gadget_vbus_draw --  constrain controller's VBUS power usage
usb_gadget_vbus_disconnect --  notify controller about VBUS session end
usb_gadget_connect --  software-controlled connect to USB host
usb_gadget_disconnect --  software-controlled disconnect from USB host
struct usb_gadget_driver --  driver for usb 'slave' devices
usb_gadget_register_driver --  register a gadget driver
usb_gadget_unregister_driver --  unregister a gadget driver
struct usb_string --  wraps a C string and its USB id
struct usb_gadget_strings --  a set of USB strings in a given language
3.4. Optional Utilities
usb_gadget_get_string --  fill out a string descriptor
usb_descriptor_fillbuf --  fill buffer with descriptors
usb_gadget_config_buf --  builts a complete configuration descriptor
4. Peripheral Controller Drivers
5. Gadget Drivers
6. USB On-The-GO (OTG)