dwc_otg_pcd.c File Reference

This file implements PCD Core. More...

#include "dwc_otg_pcd.h"

Go to the source code of this file.

Functions

static dwc_otg_pcd_ep_tget_ep_from_handle (dwc_otg_pcd_t *pcd, void *handle)
void dwc_otg_request_done (dwc_otg_pcd_ep_t *ep, dwc_otg_pcd_request_t *req, int32_t status)
 This function completes a request.
void dwc_otg_request_nuke (dwc_otg_pcd_ep_t *ep)
 This function terminates all the requsts in the EP request queue.
void dwc_otg_pcd_start (dwc_otg_pcd_t *pcd, const struct dwc_otg_pcd_function_ops *fops)
 Call this to bind the function driver to the PCD Core.
static int32_t dwc_otg_pcd_start_cb (void *p)
 PCD Callback function for initializing the PCD when switching to device mode.
uint8_t * cfiw_ep_alloc_buffer (dwc_otg_pcd_t *pcd, void *pep, dwc_dma_t *addr, size_t buflen, int flags)
 CFI-specific buffer allocation function for EP.
static int32_t dwc_otg_pcd_resume_cb (void *p)
 PCD Callback function for notifying the PCD when resuming from suspend.
static int32_t dwc_otg_pcd_suspend_cb (void *p)
 PCD Callback function for notifying the PCD device is suspended.
static int32_t dwc_otg_pcd_stop_cb (void *p)
 PCD Callback function for stopping the PCD when switching to Host mode.
dwc_otg_dev_dma_desc_tdwc_otg_ep_alloc_desc_chain (uint32_t *dma_desc_addr, uint32_t count)
 This function allocates a DMA Descriptor chain for the Endpoint buffer to be used for a transfer to/from the specified endpoint.
void dwc_otg_ep_free_desc_chain (dwc_otg_dev_dma_desc_t *desc_addr, uint32_t dma_desc_addr, uint32_t count)
 This function frees a DMA Descriptor chain that was allocated by ep_alloc_desc.
void dwc_otg_iso_ep_start_ddma_transfer (dwc_otg_core_if_t *core_if, dwc_ep_t *dwc_ep)
 This function initializes a descriptor chain for Isochronous transfer.
void dwc_otg_iso_ep_start_buf_transfer (dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
 This function initializes a descriptor chain for Isochronous transfer.
static void dwc_otg_iso_ep_start_transfer (dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
 This function does the setup for a data transfer for an EP and starts the transfer.
void dwc_otg_iso_ep_stop_transfer (dwc_otg_core_if_t *core_if, dwc_ep_t *ep)
 This function does the setup for a data transfer for an EP and starts the transfer.
int dwc_otg_pcd_iso_ep_start (dwc_otg_pcd_t *pcd, void *ep_handle, uint8_t *buf0, uint8_t *buf1, dwc_dma_t dma0, dwc_dma_t dma1, int sync_frame, int dp_frame, int data_per_frame, int start_frame, int buf_proc_intrvl, void *req_handle, int atomic_alloc)
 Start isochronous transfers on the endpoint referenced by ep_handle.
int dwc_otg_pcd_iso_ep_stop (dwc_otg_pcd_t *pcd, void *ep_handle, void *req_handle)
 Stop ISOC transfers on endpoint referenced by ep_handle.
void dwc_otg_iso_buffer_done (dwc_otg_pcd_t *pcd, dwc_otg_pcd_ep_t *ep, void *req_handle)
 This function is used for perodical data exchnage between PCD and gadget drivers.
int dwc_otg_pcd_get_iso_packet_count (dwc_otg_pcd_t *pcd, void *ep_handle, void *iso_req_handle)
 Get ISOC packet count.
void dwc_otg_pcd_get_iso_packet_params (dwc_otg_pcd_t *pcd, void *ep_handle, void *iso_req_handle, int packet, int *status, int *actual, int *offset)
 Get ISOC packet status.
static void dwc_otg_pcd_init_ep (dwc_otg_pcd_t *pcd, dwc_otg_pcd_ep_t *pcd_ep, uint32_t is_in, uint32_t ep_num)
static void dwc_otg_pcd_reinit (dwc_otg_pcd_t *pcd)
 Initialise ep's.
static void srp_timeout (void *ptr)
 This function is called when the SRP timer expires.
void start_next_request (dwc_otg_pcd_ep_t *ep)
 Tasklet.
static void start_xfer_tasklet_func (void *data)
dwc_otg_pcd_tdwc_otg_pcd_init (dwc_otg_core_if_t *core_if)
 Call this function to get pointer on dwc_otg_pcd_t, this pointer will be used for all PCD API functions.
void dwc_otg_pcd_remove (dwc_otg_pcd_t *pcd)
 Frees PCD allocated by dwc_otg_pcd_init.
uint32_t dwc_otg_pcd_is_dualspeed (dwc_otg_pcd_t *pcd)
 This function returns whether device is dualspeed.
uint32_t dwc_otg_pcd_is_otg (dwc_otg_pcd_t *pcd)
 This function returns whether device is otg.
static uint32_t assign_tx_fifo (dwc_otg_core_if_t *core_if)
 This function assigns periodic Tx FIFO to an periodic EP in shared Tx FIFO mode.
static uint32_t assign_perio_tx_fifo (dwc_otg_core_if_t *core_if)
 This function assigns periodic Tx FIFO to an periodic EP in shared Tx FIFO mode.
static void release_perio_tx_fifo (dwc_otg_core_if_t *core_if, uint32_t fifo_num)
 This function releases periodic Tx FIFO in shared Tx FIFO mode.
static void release_tx_fifo (dwc_otg_core_if_t *core_if, uint32_t fifo_num)
 This function releases periodic Tx FIFO in shared Tx FIFO mode.
int dwc_otg_pcd_ep_enable (dwc_otg_pcd_t *pcd, const uint8_t *ep_desc, void *usb_ep)
 Enables an endpoint for use.
int dwc_otg_pcd_ep_disable (dwc_otg_pcd_t *pcd, void *ep_handle)
 Disable the endpoint referenced by ep_handle.
int dwc_otg_pcd_ep_queue (dwc_otg_pcd_t *pcd, void *ep_handle, uint8_t *buf, dwc_dma_t dma_buf, uint32_t buflen, int zero, void *req_handle, int atomic_alloc)
 Queue a data transfer request on the endpoint referenced by ep_handle.
int dwc_otg_pcd_ep_dequeue (dwc_otg_pcd_t *pcd, void *ep_handle, void *req_handle)
 De-queue the specified data transfer that has not yet completed.
int dwc_otg_pcd_ep_halt (dwc_otg_pcd_t *pcd, void *ep_handle, int value)
 Halt (STALL) an endpoint or clear it.
void dwc_otg_pcd_rem_wkup_from_suspend (dwc_otg_pcd_t *pcd, int set)
 This function initiates remote wakeup of the host from suspend state.
void dwc_otg_pcd_remote_wakeup (dwc_otg_pcd_t *pcd, int set)
 Starts remote wakeup signaling.
int dwc_otg_pcd_wakeup (dwc_otg_pcd_t *pcd)
 This function starts the SRP Protocol if no session is in progress.
void dwc_otg_pcd_start_srp_timer (dwc_otg_pcd_t *pcd)
 Start the SRP timer to detect when the SRP does not complete within 6 seconds.
void dwc_otg_pcd_initiate_srp (dwc_otg_pcd_t *pcd)
 Initiate SRP.
int dwc_otg_pcd_get_frame_number (dwc_otg_pcd_t *pcd)
 This function returns current frame number.
int dwc_otg_pcd_is_lpm_enabled (dwc_otg_pcd_t *pcd)
 This function returns 1 if LPM support is enabled, and 0 otherwise.
uint32_t get_b_hnp_enable (dwc_otg_pcd_t *pcd)
 These functions allow to get hnp parameters.
uint32_t get_a_hnp_support (dwc_otg_pcd_t *pcd)
uint32_t get_a_alt_hnp_support (dwc_otg_pcd_t *pcd)
int dwc_otg_pcd_get_rmwkup_enable (dwc_otg_pcd_t *pcd)
 This function returns 1 if remote wakeup is allowed and 0, otherwise.

Variables

static dwc_otg_cil_callbacks_t pcd_callbacks
 PCD Callback structure for handling mode switching.


Detailed Description

This file implements PCD Core.

All code in this file is portable and don't use any OS specific functions. PCD Core provides Interface, defined in <dwc_otg_pcd_if.h> header file, which can be used to implement OS specific PCD interface.

An important function of the PCD is managing interrupts generated by the DWC_otg controller. The implementation of the DWC_otg device mode interrupt service routines is in dwc_otg_pcd_intr.c.

Todo:
Add Device Mode test modes (Test J mode, Test K mode, etc).

Does it work when the request size is greater than DEPTSIZ transfer size

Definition in file dwc_otg_pcd.c.


Function Documentation

void dwc_otg_request_done ( dwc_otg_pcd_ep_t ep,
dwc_otg_pcd_request_t req,
int32_t  status 
)

This function completes a request.

It call's the request call back.

Definition at line 78 of file dwc_otg_pcd.c.

void dwc_otg_pcd_start ( dwc_otg_pcd_t pcd,
const struct dwc_otg_pcd_function_ops fops 
)

Call this to bind the function driver to the PCD Core.

Parameters:
pcd Pointer on dwc_otg_pcd_t returned by dwc_otg_pcd_init function.
fops The Function Driver Ops data structure containing pointers to all callbacks.

Definition at line 117 of file dwc_otg_pcd.c.

static int32_t dwc_otg_pcd_start_cb ( void *  p  )  [static]

PCD Callback function for initializing the PCD when switching to device mode.

Parameters:
p void pointer to the dwc_otg_pcd_t

Definition at line 129 of file dwc_otg_pcd.c.

static int32_t dwc_otg_pcd_resume_cb ( void *  p  )  [static]

PCD Callback function for notifying the PCD when resuming from suspend.

Parameters:
p void pointer to the dwc_otg_pcd_t

Definition at line 163 of file dwc_otg_pcd.c.

static int32_t dwc_otg_pcd_suspend_cb ( void *  p  )  [static]

PCD Callback function for notifying the PCD device is suspended.

Parameters:
p void pointer to the dwc_otg_pcd_t

Definition at line 187 of file dwc_otg_pcd.c.

static int32_t dwc_otg_pcd_stop_cb ( void *  p  )  [static]

PCD Callback function for stopping the PCD when switching to Host mode.

Parameters:
p void pointer to the dwc_otg_pcd_t

Definition at line 204 of file dwc_otg_pcd.c.

void dwc_otg_iso_ep_start_ddma_transfer ( dwc_otg_core_if_t core_if,
dwc_ep_t dwc_ep 
)

This function initializes a descriptor chain for Isochronous transfer.

Parameters:
core_if Programming view of DWC_otg controller.
dwc_ep The EP to start the transfer on.

Allocate descriptors for double buffering

ISO OUT EP

Buffer 0 descriptors setup

Buffer 1 descriptors setup

Write dma_ad into DOEPDMA register

ISO IN EP

Buffer 0 descriptors setup

Buffer 1 descriptors setup

Write dma_ad into diepdma register

Enable endpoint, clear nak

Definition at line 254 of file dwc_otg_pcd.c.

void dwc_otg_iso_ep_start_buf_transfer ( dwc_otg_core_if_t core_if,
dwc_ep_t ep 
)

This function initializes a descriptor chain for Isochronous transfer.

Parameters:
core_if Programming view of DWC_otg controller.
ep The EP to start the transfer on.

Enable endpoint, clear nak

Definition at line 517 of file dwc_otg_pcd.c.

static void dwc_otg_iso_ep_start_transfer ( dwc_otg_core_if_t core_if,
dwc_ep_t ep 
) [static]

This function does the setup for a data transfer for an EP and starts the transfer.

For an IN transfer, the packets will be loaded into the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are unloaded from the Rx FIFO in the ISR. the ISR.

Parameters:
core_if Programming view of DWC_otg controller.
ep The EP to start the transfer on.

Definition at line 598 of file dwc_otg_pcd.c.

void dwc_otg_iso_ep_stop_transfer ( dwc_otg_core_if_t core_if,
dwc_ep_t ep 
)

This function does the setup for a data transfer for an EP and starts the transfer.

For an IN transfer, the packets will be loaded into the appropriate Tx FIFO in the ISR. For OUT transfers, the packets are unloaded from the Rx FIFO in the ISR. the ISR.

Parameters:
core_if Programming view of DWC_otg controller.
ep The EP to start the transfer on.

Definition at line 641 of file dwc_otg_pcd.c.

int dwc_otg_pcd_iso_ep_start ( dwc_otg_pcd_t pcd,
void *  ep_handle,
uint8_t *  buf0,
uint8_t *  buf1,
dwc_dma_t  dma0,
dwc_dma_t  dma1,
int  sync_frame,
int  dp_frame,
int  data_per_frame,
int  start_frame,
int  buf_proc_intrvl,
void *  req_handle,
int  atomic_alloc 
)

Start isochronous transfers on the endpoint referenced by ep_handle.

For isochronous transfers duble buffering is used. After processing each of buffers comlete callback will be called with status for each transaction.

Parameters:
pcd The PCD
ep_handle The handle of the endpoint
buf0 The virtual address of first data buffer
buf1 The virtual address of second data buffer
dma0 The DMA address of first data buffer
dma1 The DMA address of second data buffer
sync_frame Data pattern frame number
dp_frame Data size for pattern frame
data_per_frame Data size for regular frame
start_frame Frame number to start transfers, if -1 then start transfers ASAP.
buf_proc_intrvl Interval of ISOC Buffer processing
req_handle Handle of ISOC request
atomic_alloc Specefies whether to perform atomic allocation for internal data structures.
Returns -DWC_E_NO_MEMORY if there is no enough memory. Returns -DWC_E_INVALID if incorrect arguments are passed to the function. Returns -DW_E_SHUTDOWN for any other error. Returns 0 on success

Todo:
  • pattern data support is to be implemented in the future

Definition at line 685 of file dwc_otg_pcd.c.

int dwc_otg_pcd_iso_ep_stop ( dwc_otg_pcd_t pcd,
void *  ep_handle,
void *  req_handle 
)

Stop ISOC transfers on endpoint referenced by ep_handle.

Parameters:
pcd The PCD
ep_handle The handle of the endpoint
req_handle Handle of ISOC request
Returns -DWC_E_INVALID if incorrect arguments are passed to the function Returns 0 on success

Definition at line 794 of file dwc_otg_pcd.c.

void dwc_otg_iso_buffer_done ( dwc_otg_pcd_t pcd,
dwc_otg_pcd_ep_t ep,
void *  req_handle 
)

This function is used for perodical data exchnage between PCD and gadget drivers.

for Isochronous EPs

Definition at line 830 of file dwc_otg_pcd.c.

int dwc_otg_pcd_get_iso_packet_count ( dwc_otg_pcd_t pcd,
void *  ep_handle,
void *  iso_req_handle 
)

Get ISOC packet count.

Parameters:
pcd The PCD
ep_handle The handle of the endpoint
iso_req_handle 

Definition at line 850 of file dwc_otg_pcd.c.

void dwc_otg_pcd_get_iso_packet_params ( dwc_otg_pcd_t pcd,
void *  ep_handle,
void *  iso_req_handle,
int  packet,
int *  status,
int *  actual,
int *  offset 
)

Get ISOC packet status.

Parameters:
pcd The PCD
ep_handle The handle of the endpoint
iso_req_handle Isochronoush request handle
packet Number of packet
status Out parameter for returning status
actual Out parameter for returning actual length
offset Out parameter for returning offset

Definition at line 862 of file dwc_otg_pcd.c.

static void dwc_otg_pcd_reinit ( dwc_otg_pcd_t pcd  )  [static]

Initialise ep's.

Initialize the EP0 structure.

Todo:
NGS: Add direction to EP, based on contents of HWCFG1. Need a copy of HWCFG1 in pcd structure? sprintf(";r

Todo:
NGS: Add direction to EP, based on contents of HWCFG1. Need a copy of HWCFG1 in pcd structure? sprintf(";r

Definition at line 911 of file dwc_otg_pcd.c.

static void srp_timeout ( void *  ptr  )  [static]

This function is called when the SRP timer expires.

The SRP should complete within 6 seconds.

Definition at line 970 of file dwc_otg_pcd.c.

dwc_otg_pcd_t* dwc_otg_pcd_init ( dwc_otg_core_if_t core_if  ) 

Call this function to get pointer on dwc_otg_pcd_t, this pointer will be used for all PCD API functions.

Parameters:
core_if The DWC_OTG Core

Definition at line 1056 of file dwc_otg_pcd.c.

void dwc_otg_pcd_remove ( dwc_otg_pcd_t pcd  ) 

Frees PCD allocated by dwc_otg_pcd_init.

Parameters:
pcd The PCD

Definition at line 1215 of file dwc_otg_pcd.c.

int dwc_otg_pcd_ep_enable ( dwc_otg_pcd_t pcd,
const uint8_t *  ep_desc,
void *  ep_handle 
)

Enables an endpoint for use.

This function enables an endpoint in the PCD. The endpoint is described by the ep_desc which has the same format as a USB ep descriptor. The ep_handle parameter is used to refer to the endpoint from other API functions and in callbacks. Normally this should be called after a SET_CONFIGURATION/SET_INTERFACE to configure the core for that interface.

Returns -DWC_E_INVALID if invalid parameters were passed. Returns -DWC_E_SHUTDOWN if any other error ocurred. Returns 0 on success.

Parameters:
pcd The PCD
ep_desc Endpoint descriptor
ep_handle Handle on endpoint, that will be used to identify endpoint.

Definition at line 1341 of file dwc_otg_pcd.c.

int dwc_otg_pcd_ep_disable ( dwc_otg_pcd_t pcd,
void *  ep_handle 
)

Disable the endpoint referenced by ep_handle.

Returns -DWC_E_INVALID if invalid parameters were passed. Returns -DWC_E_SHUTDOWN if any other error ocurred. Returns 0 on success.

Definition at line 1449 of file dwc_otg_pcd.c.

int dwc_otg_pcd_ep_queue ( dwc_otg_pcd_t pcd,
void *  ep_handle,
uint8_t *  buf,
dwc_dma_t  dma_buf,
uint32_t  buflen,
int  zero,
void *  req_handle,
int  atomic_alloc 
)

Queue a data transfer request on the endpoint referenced by ep_handle.

After the transfer is completes, the complete callback will be called with the request status.

Parameters:
pcd The PCD
ep_handle The handle of the endpoint
buf The buffer for the data
dma_buf The DMA buffer for the data
buflen The length of the data transfer
zero Specifies whether to send zero length last packet.
req_handle Set this handle to any value to use to reference this request in the ep_dequeue function or from the complete callback
atomic_alloc If driver need to perform atomic allocations for internal data structures.
Returns -DWC_E_INVALID if invalid parameters were passed. Returns -DWC_E_SHUTDOWN if any other error ocurred. Returns 0 on success.

Todo:
NGS Create a function for this.

Definition at line 1502 of file dwc_otg_pcd.c.

int dwc_otg_pcd_ep_dequeue ( dwc_otg_pcd_t pcd,
void *  ep_handle,
void *  req_handle 
)

De-queue the specified data transfer that has not yet completed.

Returns -DWC_E_INVALID if invalid parameters were passed. Returns -DWC_E_SHUTDOWN if any other error ocurred. Returns 0 on success.

Definition at line 1694 of file dwc_otg_pcd.c.

int dwc_otg_pcd_ep_halt ( dwc_otg_pcd_t pcd,
void *  ep_handle,
int  value 
)

Halt (STALL) an endpoint or clear it.

Returns -DWC_E_INVALID if invalid parameters were passed. Returns -DWC_E_SHUTDOWN if any other error ocurred. Returns -DWC_E_AGAIN if the STALL cannot be sent and must be tried again later Returns 0 on success.

Definition at line 1733 of file dwc_otg_pcd.c.

int dwc_otg_pcd_wakeup ( dwc_otg_pcd_t pcd  ) 

This function starts the SRP Protocol 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 1896 of file dwc_otg_pcd.c.

void dwc_otg_pcd_start_srp_timer ( dwc_otg_pcd_t pcd  ) 

Start the SRP timer to detect when the SRP does not complete within 6 seconds.

Parameters:
pcd the pcd structure.

Definition at line 1937 of file dwc_otg_pcd.c.


Variable Documentation

dwc_otg_cil_callbacks_t pcd_callbacks [static]

Initial value:

 {
        .start = dwc_otg_pcd_start_cb,
        .stop = dwc_otg_pcd_stop_cb,
        .suspend = dwc_otg_pcd_suspend_cb,
        .resume_wakeup = dwc_otg_pcd_resume_cb,
        .p = 0,                 
}
PCD Callback structure for handling mode switching.

Definition at line 216 of file dwc_otg_pcd.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