dwc_otg_pcd_linux.c File Reference

This file implements the Peripheral Controller Driver. More...

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/errno.h>
#include <linux/list.h>
#include <linux/interrupt.h>
#include <linux/string.h>
#include <linux/dma-mapping.h>
#include <linux/version.h>
#include <asm/io.h>
#include <linux/usb_ch9.h>
#include <linux/usb_gadget.h>
#include "dwc_otg_pcd_if.h"
#include "dwc_otg_driver.h"
#include "dwc_otg_dbg.h"

Go to the source code of this file.

Data Structures

struct  gadget_wrapper

Functions

void dump_msg (const u8 *buf, unsigned int length)
static int ep_enable (struct usb_ep *usb_ep, const struct usb_endpoint_descriptor *ep_desc)
 This function is called by the Gadget Driver for each EP to be configured for the current configuration (SET_CONFIGURATION).
static int ep_disable (struct usb_ep *usb_ep)
 This function is called when an EP is disabled due to disconnect or change in configuration.
static struct usb_request * dwc_otg_pcd_alloc_request (struct usb_ep *ep, gfp_t gfp_flags)
 This function allocates a request object to use with the specified endpoint.
static void dwc_otg_pcd_free_request (struct usb_ep *ep, struct usb_request *req)
 This function frees a request object.
static void * dwc_otg_pcd_alloc_buffer (struct usb_ep *usb_ep, unsigned bytes, dma_addr_t *dma, gfp_t gfp_flags)
 This function allocates an I/O buffer to be used for a transfer to/from the specified endpoint.
static void dwc_otg_pcd_free_buffer (struct usb_ep *usb_ep, void *buf, dma_addr_t dma, unsigned bytes)
 This function frees an I/O buffer that was allocated by alloc_buffer.
static int ep_queue (struct usb_ep *usb_ep, struct usb_request *usb_req, gfp_t gfp_flags)
 This function is used to submit an I/O Request to an EP.
static int ep_dequeue (struct usb_ep *usb_ep, struct usb_request *usb_req)
 This function cancels an I/O request from an EP.
static int ep_halt (struct usb_ep *usb_ep, int value)
 usb_ep_set_halt stalls an endpoint.
static int iso_ep_start (struct usb_ep *usb_ep, struct usb_iso_request *req, gfp_t gfp_flags)
 This function is used to submit an ISOC Transfer Request to an EP.
static int iso_ep_stop (struct usb_ep *usb_ep, struct usb_iso_request *req)
 This function stops ISO EP Periodic Data Transfer.
static struct usb_iso_request * alloc_iso_request (struct usb_ep *ep, int packets, gfp_t gfp_flags)
static void free_iso_request (struct usb_ep *ep, struct usb_iso_request *req)
static int get_frame_number (struct usb_gadget *gadget)
 Gets the USB Frame number of the last SOF.
static int wakeup (struct usb_gadget *gadget)
 Initiates Session Request Protocol (SRP) to wakeup the host if no session is in progress.
static int _setup (dwc_otg_pcd_t *pcd, uint8_t *bytes)
static int _isoc_complete (dwc_otg_pcd_t *pcd, void *ep_handle, void *req_handle, int proc_buf_num)
static int _complete (dwc_otg_pcd_t *pcd, void *ep_handle, void *req_handle, int32_t status, uint32_t actual)
static int _connect (dwc_otg_pcd_t *pcd, int speed)
static int _disconnect (dwc_otg_pcd_t *pcd)
static int _resume (dwc_otg_pcd_t *pcd)
static int _suspend (dwc_otg_pcd_t *pcd)
static int _hnp_changed (dwc_otg_pcd_t *pcd)
 This function updates the otg values in the gadget structure.
static int _reset (dwc_otg_pcd_t *pcd)
static irqreturn_t dwc_otg_pcd_irq (int irq, void *dev)
 This function is the top level PCD interrupt handler.
void gadget_add_eps (struct gadget_wrapper *d)
 This function initialized the usb_ep structures to there default state.
static void dwc_otg_pcd_gadget_release (struct device *dev)
 This function releases the Gadget device.
static struct gadget_wrapperalloc_wrapper ()
static void free_wrapper (struct gadget_wrapper *d)
int pcd_init ()
 This function initialized the PCD portion of the driver.
void pcd_remove ()
 Cleanup the PCD.
int usb_gadget_register_driver (struct usb_gadget_driver *driver)
 This function registers a gadget driver with the PCD.
 EXPORT_SYMBOL (usb_gadget_register_driver)
int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
 This function unregisters a gadget driver.
 EXPORT_SYMBOL (usb_gadget_unregister_driver)

Variables

static struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops
static struct usb_gadget_ops dwc_otg_pcd_ops
static struct dwc_otg_pcd_function_ops fops


Detailed Description

This file implements the Peripheral Controller Driver.

The Peripheral Controller Driver (PCD) is responsible for translating requests from the Function Driver into the appropriate actions on the DWC_otg controller. It isolates the Function Driver from the specifics of the controller by providing an API to the Function Driver.

The Peripheral Controller Driver for Linux will implement the Gadget API, so that the existing Gadget drivers can be used. (Gadget Driver is the Linux terminology for a Function Driver.)

The Linux Gadget API is defined in the header file <linux/usb_gadget.h>. The USB EP operations API is defined in the structure usb_ep_ops and the USB Controller API is defined in the structure usb_gadget_ops.

Definition in file dwc_otg_pcd_linux.c.


Function Documentation

static int ep_enable ( struct usb_ep *  usb_ep,
const struct usb_endpoint_descriptor *  ep_desc 
) [static]

This function is called by the Gadget Driver for each EP to be configured for the current configuration (SET_CONFIGURATION).

This function initializes the dwc_otg_ep_t data structure, and then calls dwc_otg_ep_activate.

Definition at line 121 of file dwc_otg_pcd_linux.c.

static int ep_disable ( struct usb_ep *  usb_ep  )  [static]

This function is called when an EP is disabled due to disconnect or change in configuration.

Any pending requests will terminate with a status of -ESHUTDOWN.

This function modifies the dwc_otg_ep_t data structure for this EP, and then calls dwc_otg_ep_deactivate.

Definition at line 170 of file dwc_otg_pcd_linux.c.

static struct usb_request* dwc_otg_pcd_alloc_request ( struct usb_ep *  ep,
gfp_t  gfp_flags 
) [static]

This function allocates a request object to use with the specified endpoint.

Parameters:
ep The endpoint to be used with with the request
gfp_flags the GFP_* flags to use.

Definition at line 196 of file dwc_otg_pcd_linux.c.

static void dwc_otg_pcd_free_request ( struct usb_ep *  ep,
struct usb_request *  req 
) [static]

This function frees a request object.

Parameters:
ep The endpoint associated with the request
req The request being freed

Definition at line 223 of file dwc_otg_pcd_linux.c.

static void* dwc_otg_pcd_alloc_buffer ( struct usb_ep *  usb_ep,
unsigned  bytes,
dma_addr_t *  dma,
gfp_t  gfp_flags 
) [static]

This function allocates an I/O buffer to be used for a transfer to/from the specified endpoint.

Parameters:
usb_ep The endpoint to be used with with the request
bytes The desired number of bytes for the buffer
dma Pointer to the buffer's DMA address; must be valid
gfp_flags the GFP_* flags to use.
Returns:
address of a new buffer or null is buffer could not be allocated.

Definition at line 246 of file dwc_otg_pcd_linux.c.

static void dwc_otg_pcd_free_buffer ( struct usb_ep *  usb_ep,
void *  buf,
dma_addr_t  dma,
unsigned  bytes 
) [static]

This function frees an I/O buffer that was allocated by alloc_buffer.

Parameters:
usb_ep the endpoint associated with the buffer
buf address of the buffer
dma The buffer's DMA address
bytes The number of bytes of the buffer

Definition at line 282 of file dwc_otg_pcd_linux.c.

static int ep_queue ( struct usb_ep *  usb_ep,
struct usb_request *  usb_req,
gfp_t  gfp_flags 
) [static]

This function is used to submit an I/O Request to an EP.

Definition at line 308 of file dwc_otg_pcd_linux.c.

static int ep_halt ( struct usb_ep *  usb_ep,
int  value 
) [static]

usb_ep_set_halt stalls an endpoint.

usb_ep_clear_halt clears an endpoint halt and resets its data toggle.

Both of these functions are implemented with the same underlying function. The behavior depends on the value argument.

Parameters:
[in] usb_ep the Endpoint to halt or clear halt.
[in] value 
  • 0 means clear_halt.
  • 1 means set_halt,
  • 2 means clear stall lock flag.
  • 3 means set stall lock flag.

Definition at line 391 of file dwc_otg_pcd_linux.c.

static int iso_ep_start ( struct usb_ep *  usb_ep,
struct usb_iso_request *  req,
gfp_t  gfp_flags 
) [static]

This function is used to submit an ISOC Transfer Request to an EP.

Definition at line 422 of file dwc_otg_pcd_linux.c.

static int wakeup ( struct usb_gadget *  gadget  )  [static]

Initiates Session Request Protocol (SRP) to wakeup the host if no session is in progress.

If a session is already in progress, but the device is suspended, remote wakeup signaling is started.

Definition at line 603 of file dwc_otg_pcd_linux.c.

void gadget_add_eps ( struct gadget_wrapper d  ) 

This function initialized the usb_ep structures to there default state.

Parameters:
d Pointer on gadget_wrapper.

Initialize the EP0 structure.

Todo:
NGS: What should the max packet size be set to here? Before EP type is set?

Initialize the EP structures.

Todo:
NGS: What should the max packet size be set to here? Before EP type is set?

Todo:
NGS: What should the max packet size be set to here? Before EP type is set?

Definition at line 824 of file dwc_otg_pcd_linux.c.

static void dwc_otg_pcd_gadget_release ( struct device *  dev  )  [static]

This function releases the Gadget device.

required by device_unregister().

Todo:
Should this do something? Should it free the PCD?

Definition at line 937 of file dwc_otg_pcd_linux.c.

int usb_gadget_register_driver ( struct usb_gadget_driver *  driver  ) 

This function registers a gadget driver with the PCD.

When a driver is successfully registered, it will receive control requests including set_configuration(), which enables non-control requests. then usb traffic follows until a disconnect is reported. then a host may connect again, or the driver might get unbound.

Parameters:
driver The driver being registered

Definition at line 1096 of file dwc_otg_pcd_linux.c.

int usb_gadget_unregister_driver ( struct usb_gadget_driver *  driver  ) 

This function unregisters a gadget driver.

Parameters:
driver The driver being unregistered

Definition at line 1143 of file dwc_otg_pcd_linux.c.


Variable Documentation

struct usb_isoc_ep_ops dwc_otg_pcd_ep_ops [static]

Initial value:

 {
        .ep_ops = {
                   .enable = ep_enable,
                   .disable = ep_disable,

                   .alloc_request = dwc_otg_pcd_alloc_request,
                   .free_request = dwc_otg_pcd_free_request,

                   .alloc_buffer = dwc_otg_pcd_alloc_buffer,
                   .free_buffer = dwc_otg_pcd_free_buffer,

                   .queue = ep_queue,
                   .dequeue = ep_dequeue,

                   .set_halt = ep_halt,
                   .fifo_status = 0,
                   .fifo_flush = 0,
                   },
        .iso_ep_start = iso_ep_start,
        .iso_ep_stop = iso_ep_stop,
        .alloc_iso_request = alloc_iso_request,
        .free_iso_request = free_iso_request,
}

Definition at line 507 of file dwc_otg_pcd_linux.c.

struct usb_gadget_ops dwc_otg_pcd_ops [static]

Initial value:

 {
        .get_frame = get_frame_number,
        .wakeup = wakeup,



        
}

Definition at line 618 of file dwc_otg_pcd_linux.c.

struct dwc_otg_pcd_function_ops fops [static]

Initial value:

 {
        .complete = _complete,

        .isoc_complete = _isoc_complete,

        .setup = _setup,
        .disconnect = _disconnect,
        .connect = _connect,
        .resume = _resume,
        .suspend = _suspend,
        .hnp_changed = _hnp_changed,
        .reset = _reset,



}

Definition at line 786 of file dwc_otg_pcd_linux.c.


Generated on Tue May 5 02:22:49 2009 for DesignWare USB 2.0 OTG Controller (DWC_otg) Device Driver by  doxygen 1.4.7