Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros
gadget.h File Reference
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/list.h>
#include <linux/slab.h>
#include <linux/scatterlist.h>
#include <linux/types.h>
#include <linux/usb/ch9.h>

Go to the source code of this file.

Data Structures

struct  usb_request
 
struct  usb_ep_ops
 
struct  usb_ep
 
struct  usb_dcd_config_params
 
struct  usb_gadget_ops
 
struct  usb_gadget
 
struct  usb_gadget_driver
 
struct  usb_string
 
struct  usb_gadget_strings
 

Macros

#define USB_DEFAULT_U1_DEV_EXIT_LAT   0x01 /* Less then 1 microsec */
 
#define USB_DEFAULT_U2_DEV_EXIT_LAT   0x1F4 /* Less then 500 microsec */
 

: Identifies the controller hardware type. Used in diagnostics

struct usb_gadget - represents a usb slave device : Function pointers used to access hardware-specific operations. : Endpoint zero, used when reading or writing responses to driver setup() requests : List of other endpoints supported by the device. : Speed of current connection to USB host. : Maximal speed the UDC can handle. UDC must support this and all slower speeds. : true if we can handle scatter-gather : True if the USB device port uses a Mini-AB jack, so that the gadget driver must provide a USB OTG descriptor. : False unless is_otg, the "A" end of a USB cable is in the Mini-AB jack, and HNP has been used to switch roles so that the "A" device currently acts as A-Peripheral, not A-Host. : OTG device feature flag, indicating that the A-Host supports HNP at this port. : OTG device feature flag, indicating that the A-Host only supports HNP on a different root port. : OTG device feature flag, indicating that the A-Host enabled HNP support.

and sometimes configuration. : Driver model state for this abstract device. : last used out ep number : last used in ep number

Gadgets have a mostly-portable "gadget driver" implementing device functions, handling all usb configurations and interfaces. Gadget drivers talk to hardware-specific code indirectly, through ops vectors. That insulates the gadget driver from hardware details, and packages the hardware endpoints through generic i/o queues. The "usb_gadget" and "usb_ep" interfaces provide that insulation from the hardware.

Except for the driver data, all fields in this structure are read-only to the gadget driver. That driver data is part of the "driver model" infrastructure in 2.6 (and later) kernels, and for earlier systems is grouped in a similar structure that's not known to the rest of the kernel.

Values of the three OTG device feature flags are updated before the setup() call corresponding to USB_REQ_SET_CONFIGURATION, and before driver suspend() calls. They are valid only when is_otg, and when the device is acting as a B-Peripheral (so is_a_peripheral is false).

#define gadget_for_each_ep(tmp, gadget)   list_for_each_entry(tmp, &(gadget)->ep_list, ep_list)
 
int usb_gadget_probe_driver (struct usb_gadget_driver *driver)
 
int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
 
int usb_add_gadget_udc (struct device *parent, struct usb_gadget *gadget)
 
void usb_del_gadget_udc (struct usb_gadget *gadget)
 
int usb_gadget_get_string (struct usb_gadget_strings *table, int id, u8 *buf)
 
int usb_descriptor_fillbuf (void *, unsigned, const struct usb_descriptor_header **)
 
int usb_gadget_config_buf (const struct usb_config_descriptor *config, void *buf, unsigned buflen, const struct usb_descriptor_header **desc)
 
struct usb_descriptor_header ** usb_copy_descriptors (struct usb_descriptor_header **)
 
int usb_gadget_map_request (struct usb_gadget *gadget, struct usb_request *req, int is_in)
 
void usb_gadget_unmap_request (struct usb_gadget *gadget, struct usb_request *req, int is_in)
 
struct usb_epusb_ep_autoconfig (struct usb_gadget *, struct usb_endpoint_descriptor *)
 
struct usb_epusb_ep_autoconfig_ss (struct usb_gadget *, struct usb_endpoint_descriptor *, struct usb_ss_ep_comp_descriptor *)
 
void usb_ep_autoconfig_reset (struct usb_gadget *)
 

Macro Definition Documentation

#define gadget_for_each_ep (   tmp,
  gadget 
)    list_for_each_entry(tmp, &(gadget)->ep_list, ep_list)

Definition at line 556 of file gadget.h.

#define USB_DEFAULT_U1_DEV_EXIT_LAT   0x01 /* Less then 1 microsec */

Definition at line 448 of file gadget.h.

#define USB_DEFAULT_U2_DEV_EXIT_LAT   0x1F4 /* Less then 500 microsec */

Definition at line 450 of file gadget.h.

Function Documentation

int usb_add_gadget_udc ( struct device parent,
struct usb_gadget gadget 
)

usb_add_gadget_udc - adds a new gadget to the udc class driver list : the parent device to this udc. Usually the controller driver's device. : the gadget to be added to the list

Returns zero on success, negative errno otherwise.

Definition at line 207 of file udc-core.c.

struct usb_descriptor_header** usb_copy_descriptors ( struct usb_descriptor_header **  src)
read

usb_copy_descriptors - copy a vector of USB descriptors : null-terminated vector to copy Context: initialization code, which may sleep

This makes a copy of a vector of USB descriptors. Its primary use is to support usb_function objects which can have multiple copies, each needing different descriptors. Functions may have static tables of descriptors, which are used as templates and customized with identifiers (for interfaces, strings, endpoints, and more) as needed by a given function instance.

Definition at line 123 of file config.c.

void usb_del_gadget_udc ( struct usb_gadget gadget)

usb_del_gadget_udc - deletes from udc_list : the gadget to be removed.

This, will call usb_gadget_unregister_driver() if the is still busy.

Definition at line 284 of file udc-core.c.

int usb_descriptor_fillbuf ( void buf,
unsigned  buflen,
const struct usb_descriptor_header **  src 
)

usb_descriptor_fillbuf - fill buffer with descriptors : Buffer to be filled : Size of buf : Array of descriptor pointers, terminated by null pointer.

Copies descriptors into the buffer, returning the length or a negative error code if they can't all be copied. Useful when assembling descriptors for an associated set of interfaces used as part of configuring a composite device; or in other cases where sets of descriptors need to be marshaled.

Definition at line 36 of file config.c.

struct usb_ep* usb_ep_autoconfig ( struct usb_gadget gadget,
struct usb_endpoint_descriptor desc 
)
read

usb_ep_autoconfig() - choose an endpoint matching the descriptor : The device to which the endpoint must belong. : Endpoint descriptor, with endpoint direction and transfer mode initialized. For periodic transfers, the maximum packet size must also be initialized. This is modified on success.

By choosing an endpoint to use with the specified descriptor, this routine simplifies writing gadget drivers that work with multiple USB device controllers. The endpoint would be passed later to usb_ep_enable(), along with some descriptor.

That second descriptor won't always be the same as the first one. For example, isochronous endpoints can be autoconfigured for high bandwidth, and then used in several lower bandwidth altsettings. Also, high and full speed descriptors will be different.

Be sure to examine and test the results of autoconfiguration on your hardware. This code may not make the best choices about how to use the USB controller, and it can't know all the restrictions that may apply. Some combinations of driver and hardware won't be able to autoconfigure.

On success, this returns an un-claimed usb_ep, and modifies the endpoint descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value is initialized as if the endpoint were used at full speed. To prevent the endpoint from being returned by a later autoconfig call, claim it by assigning ep->driver_data to some non-null value.

On failure, this returns a null endpoint descriptor.

Definition at line 363 of file epautoconf.c.

void usb_ep_autoconfig_reset ( struct usb_gadget gadget)

usb_ep_autoconfig_reset - reset endpoint autoconfig state : device for which autoconfig state will be reset

Use this for devices where one configuration may need to assign endpoint resources very differently from the next one. It clears state such as ep->driver_data and the record of assigned endpoints used by usb_ep_autoconfig().

Definition at line 381 of file epautoconf.c.

struct usb_ep* usb_ep_autoconfig_ss ( struct usb_gadget gadget,
struct usb_endpoint_descriptor desc,
struct usb_ss_ep_comp_descriptor ep_comp 
)
read

usb_ep_autoconfig_ss() - choose an endpoint matching the ep descriptor and ep companion descriptor : The device to which the endpoint must belong. : Endpoint descriptor, with endpoint direction and transfer mode initialized. For periodic transfers, the maximum packet size must also be initialized. This is modified on success. : Endpoint companion descriptor, with the required number of streams. Will be modified when the chosen EP supports a different number of streams.

This routine replaces the usb_ep_autoconfig when needed superspeed enhancments. If such enhancemnets are required, the FD should call usb_ep_autoconfig_ss directly and provide the additional ep_comp parameter.

By choosing an endpoint to use with the specified descriptor, this routine simplifies writing gadget drivers that work with multiple USB device controllers. The endpoint would be passed later to usb_ep_enable(), along with some descriptor.

That second descriptor won't always be the same as the first one. For example, isochronous endpoints can be autoconfigured for high bandwidth, and then used in several lower bandwidth altsettings. Also, high and full speed descriptors will be different.

Be sure to examine and test the results of autoconfiguration on your hardware. This code may not make the best choices about how to use the USB controller, and it can't know all the restrictions that may apply. Some combinations of driver and hardware won't be able to autoconfigure.

On success, this returns an un-claimed usb_ep, and modifies the endpoint descriptor bEndpointAddress. For bulk endpoints, the wMaxPacket value is initialized as if the endpoint were used at full speed and the bmAttribute field in the ep companion descriptor is updated with the assigned number of streams if it is different from the original value. To prevent the endpoint from being returned by a later autoconfig call, claim it by assigning ep->driver_data to some non-null value.

On failure, this returns a null endpoint descriptor.

Definition at line 260 of file epautoconf.c.

int usb_gadget_config_buf ( const struct usb_config_descriptor config,
void buf,
unsigned  length,
const struct usb_descriptor_header **  desc 
)

usb_gadget_config_buf - builts a complete configuration descriptor : Header for the descriptor, including characteristics such as power requirements and number of interfaces. : Null-terminated vector of pointers to the descriptors (interface, endpoint, etc) defining all functions in this device configuration. : Buffer for the resulting configuration descriptor. : Length of buffer. If this is not big enough to hold the entire configuration descriptor, an error code will be returned.

This copies descriptors into the response buffer, building a descriptor for that configuration. It returns the buffer length or a negative status code. The config.wTotalLength field is set to match the length of the result, but other descriptor fields (including power usage and interface count) must be set by the caller.

Gadget drivers could use this when constructing a config descriptor in response to USB_REQ_GET_DESCRIPTOR. They will need to patch the resulting bDescriptorType value if USB_DT_OTHER_SPEED_CONFIG is needed.

Definition at line 78 of file config.c.

int usb_gadget_get_string ( struct usb_gadget_strings table,
int  id,
u8 buf 
)

usb_gadget_get_string - fill out a string descriptor : of c strings encoded using UTF-8 : string id, from low byte of wValue in get string descriptor : at least 256 bytes, must be 16-bit aligned

Finds the UTF-8 string matching the ID, and converts it into a string descriptor in utf16-le. Returns length of descriptor (always even) or negative errno

If your driver needs stings in multiple languages, you'll probably "switch (wIndex) { ... }" in your ep0 string descriptor logic, using this routine after choosing which set of UTF-8 strings to use. Note that US-ASCII is a strict subset of UTF-8; any string bytes with the eighth bit set will be multibyte UTF-8 characters, not ISO-8859/1 characters (which are also widely used in C strings).

Definition at line 40 of file usbstring.c.

int usb_gadget_map_request ( struct usb_gadget gadget,
struct usb_request req,
int  is_in 
)

Definition at line 53 of file udc-core.c.

int usb_gadget_probe_driver ( struct usb_gadget_driver driver)

usb_gadget_probe_driver - probe a gadget driver : the driver being registered Context: can sleep

Call this in your gadget driver's module initialization function, to tell the underlying usb controller driver about your driver. The () function will be called to bind it to a gadget before this registration call returns. It's expected that the () function will be in init sections.

Definition at line 314 of file udc-core.c.

void usb_gadget_unmap_request ( struct usb_gadget gadget,
struct usb_request req,
int  is_in 
)

Definition at line 84 of file udc-core.c.

int usb_gadget_unregister_driver ( struct usb_gadget_driver driver)

usb_gadget_unregister_driver - unregister a gadget driver :the driver being unregistered Context: can sleep

Call this in your gadget driver's module cleanup function, to tell the underlying usb controller that your driver is going away. If the controller is connected to a USB host, it will first disconnect(). The driver is also requested to unbind() and clean up any device state, before this procedure finally returns. It's expected that the unbind() functions will in in exit sections, so may not be linked in some kernels.

Definition at line 372 of file udc-core.c.