AM261x MCU+ SDK  11.00.00
cil.c File Reference

Introduction

The Core Interface Layer provides basic services for accessing and managing the DWC_usb3 hardware. These services are used by both the Peripheral Controller Driver and the On The Go Driver.

The CIL manages the memory map for the core so that the PCD and OTG drivers don't have to do this separately. The CIL also performs basic services that are not specific to either the Device or OTG modes of operation. These services include all functionality that requires specific knowledge of the CSR layout or the DMA descriptor (TRB) layout. Also included are services for invoking each of the commands provided by the DGCMD and DEPCMD registers (see the "Control and Status Registers" chapter of the USB3 controller databook for details).

The Core Interface Layer has the following requirements:

  • Provides basic controller operations.
  • Minimal use of OS services.
  • The OS services used will be abstracted by using inline functions or macros.

Functions

static int _handshake (volatile dwc_usb3_device_t *dev, volatile u32 __iomem *ptr, u32 mask, u32 done)
 
static int calc_num_in_eps (volatile dwc_usb3_device_t *dev)
 
static int calc_num_out_eps (volatile dwc_usb3_device_t *dev)
 
void dwc_usb3_fill_desc (dwc_usb3_dma_desc_t *desc, dwc_dma_t dma_addr, u32 dma_len, u32 stream, u32 type, u32 ctrlbits, int own)
 
void dwc_usb3_start_desc_chain (dwc_usb3_dma_desc_t *desc)
 
void dwc_usb3_end_desc_chain (dwc_usb3_dma_desc_t *desc)
 
void dwc_usb3_enable_desc (dwc_usb3_dma_desc_t *desc)
 
void dwc_usb3_disable_desc (dwc_usb3_dma_desc_t *desc)
 
int dwc_usb3_xmit_fn_remote_wake (volatile dwc_usb3_pcd_t *pcd, u32 intf)
 
int dwc_usb3_xmit_ltm (volatile dwc_usb3_pcd_t *pcd, u32 value)
 
int dwc_usb3_set_scratchpad_buf_array (volatile dwc_usb3_pcd_t *pcd, dwc_dma_t dma_addr)
 
int dwc_usb3_flush_fifo (volatile dwc_usb3_pcd_t *pcd, u32 fifo_sel)
 
int dwc_usb3_dep_cfg (volatile dwc_usb3_pcd_t *pcd, dwc_usb3_dev_ep_regs_t __iomem *ep_reg, u32 depcfg0, u32 depcfg1, u32 depcfg2)
 
int dwc_usb3_dep_xfercfg (volatile dwc_usb3_pcd_t *pcd, dwc_usb3_dev_ep_regs_t __iomem *ep_reg, u32 depstrmcfg)
 
u32 dwc_usb3_dep_getepstate (volatile dwc_usb3_pcd_t *pcd, dwc_usb3_dev_ep_regs_t __iomem *ep_reg)
 
int dwc_usb3_dep_sstall (volatile dwc_usb3_pcd_t *pcd, dwc_usb3_dev_ep_regs_t __iomem *ep_reg)
 
int dwc_usb3_dep_cstall (volatile dwc_usb3_pcd_t *pcd, dwc_usb3_dev_ep_regs_t __iomem *ep_reg, int clr_pend)
 
int dwc_usb3_dep_startxfer (volatile dwc_usb3_pcd_t *pcd, dwc_usb3_dev_ep_regs_t __iomem *ep_reg, dwc_dma_t dma_addr, u32 stream_or_uf)
 
int dwc_usb3_dep_updatexfer (volatile dwc_usb3_pcd_t *pcd, dwc_usb3_dev_ep_regs_t __iomem *ep_reg, u32 tri)
 
int dwc_usb3_dep_endxfer (volatile dwc_usb3_pcd_t *pcd, dwc_usb3_dev_ep_regs_t __iomem *ep_reg, u32 tri, u32 flags, void *condition)
 
int dwc_usb3_dep_startnewcfg (volatile dwc_usb3_pcd_t *pcd, dwc_usb3_dev_ep_regs_t __iomem *ep_reg, u32 rsrcidx)
 
int dwc_usb3_enable_ep (volatile dwc_usb3_pcd_t *pcd, volatile dwc_usb3_pcd_ep_t *ep)
 
int dwc_usb3_disable_ep (volatile dwc_usb3_pcd_t *pcd, volatile dwc_usb3_pcd_ep_t *ep)
 
int dwc_usb3_get_device_speed (volatile dwc_usb3_pcd_t *pcd)
 
int dwc_usb3_get_frame (volatile dwc_usb3_pcd_t *pcd)
 
u32 dwc_usb3_pcd_get_link_state (volatile dwc_usb3_pcd_t *pcd)
 This function retrieves the current link state. More...
 
void dwc_usb3_pcd_set_link_state (volatile dwc_usb3_pcd_t *pcd, u32 state)
 This function sets state of USB link. More...
 
void dwc_usb3_pcd_remote_wake (volatile dwc_usb3_pcd_t *pcd, int function)
 This function sends a Remote Wakeup to the host. More...
 
void dwc_usb3_set_address (volatile dwc_usb3_pcd_t *pcd, int addr)
 This function sets the Device Address. More...
 
void dwc_usb3_ena_usb2_phy_suspend (volatile dwc_usb3_pcd_t *pcd)
 This function enables USB2 Phy suspend. More...
 
void dwc_usb3_dis_usb2_phy_suspend (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_ena_usb3_phy_suspend (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_dis_usb3_phy_suspend (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_accept_u1 (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_accept_u2 (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_enable_u1 (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_enable_u2 (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_disable_u1 (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_disable_u2 (volatile dwc_usb3_pcd_t *pcd)
 
int dwc_usb3_u1_enabled (volatile dwc_usb3_pcd_t *pcd)
 
int dwc_usb3_u2_enabled (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_clr_eps_enabled (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_pcd_do_test_mode (unsigned long data)
 This routine is called when the SET_FEATURE TEST_MODE Setup packet is sent from the host. The Device Control register is written with the Test Mode bits set to the specified Test Mode. This is done as a tasklet so that the "Status" phase of the control transfer completes before transmitting the TEST packets. More...
 
int dwc_usb3_pcd_common_init (volatile dwc_usb3_device_t *dev, volatile u8 __iomem *base, const dwc_usb3_core_params_t *core_params)
 This routine is called to initialize the DWC_usb3 CSR data structures. The register addresses in the device structures are initialized from the base address supplied by the caller. The calling routine must make the OS calls to get the base address of the DWC_usb3 controller registers. The core_params argument holds the parameters that specify how the core should be configured. More...
 
void dwc_usb3_pcd_common_remove (volatile dwc_usb3_device_t *dev)
 
int dwc_usb3_pcd_check_snpsid (volatile dwc_usb3_device_t *dev, u32 addr_ofs)
 This routine ensures the device is really a DWC_usb3 controller, by reading and verifying the SNPSID register contents. The value should be 0x5533XXXX, which corresponds to "U3", as in "USB3 version X.XXX". More...
 
void dwc_usb3_dump_dbgregs (volatile dwc_usb3_device_t *dev)
 
void dwc_usb3_dump_global_registers (volatile dwc_usb3_device_t *dev)
 
void dwc_usb3_dump_dev_registers (volatile dwc_usb3_pcd_t *pcd)
 
void dwc_usb3_set_tx_fifo_size (volatile dwc_usb3_device_t *dev, int *sz)
 
void dwc_usb3_set_rx_fifo_size (volatile dwc_usb3_device_t *dev, u32 size)
 
void dwc_usb3_pcd_device_init (volatile dwc_usb3_device_t *dev, int soft_reset, int restore)
 This routine initializes the DWC_usb3 controller registers. More...
 
void dwc_usb3_pcd_device_remove (volatile dwc_usb3_device_t *dev)
 This routine deinitializes the DWC_usb3 controller registers. More...
 

Function Documentation

◆ _handshake()

static int _handshake ( volatile dwc_usb3_device_t dev,
volatile u32 __iomem ptr,
u32  mask,
u32  done 
)
static

Spin on register bit until handshake completes or times out.

Parameters
devProgramming view of DWC_usb3 controller.
ptrAddress of register to read.
maskBit to look at in result of read.
doneValue of the bit when handshake succeeds.
Returns
1 when the mask bit has the specified value (handshake done), 0 when timeout has passed (handshake failed).

◆ calc_num_in_eps()

static int calc_num_in_eps ( volatile dwc_usb3_device_t dev)
static

This routine calculates the number of IN EPs (excluding EP0) using GHWPARAMS3 register values

Parameters
devProgramming view of DWC_usb3 controller.

◆ calc_num_out_eps()

static int calc_num_out_eps ( volatile dwc_usb3_device_t dev)
static

This routine calculates the number of OUT EPs (excluding EP0) using GHWPARAMS3 register values

Parameters
devProgramming view of DWC_usb3 controller.

◆ dwc_usb3_fill_desc()

void dwc_usb3_fill_desc ( dwc_usb3_dma_desc_t desc,
dwc_dma_t  dma_addr,
u32  dma_len,
u32  stream,
u32  type,
u32  ctrlbits,
int  own 
)

Fill in the four dwords of a DMA descriptor (aka a TRB).

◆ dwc_usb3_start_desc_chain()

void dwc_usb3_start_desc_chain ( dwc_usb3_dma_desc_t desc)

Make a DMA descriptor the start of a chain by setting its CHN bit and clearing its IOC bit.

Parameters
descThe DMA descriptor (TRB) to operate on.

◆ dwc_usb3_end_desc_chain()

void dwc_usb3_end_desc_chain ( dwc_usb3_dma_desc_t desc)

Make a DMA descriptor the end of a chain by clearing its CHN bit and setting its IOC bit.

Parameters
descThe DMA descriptor (TRB) to operate on.

◆ dwc_usb3_enable_desc()

void dwc_usb3_enable_desc ( dwc_usb3_dma_desc_t desc)

Enable a DMA descriptor by setting its HWO bit.

Parameters
descThe DMA descriptor (TRB) to operate on.

◆ dwc_usb3_disable_desc()

void dwc_usb3_disable_desc ( dwc_usb3_dma_desc_t desc)

Disable a DMA descriptor by clearing its HWO bit.

NOTE: This must only be called if it is known that the hardware has finished with the DMA descriptor, but for some reason the hardware has not cleared the HWO bit.

Parameters
descThe DMA descriptor (TRB) to operate on.

◆ dwc_usb3_xmit_fn_remote_wake()

int dwc_usb3_xmit_fn_remote_wake ( volatile dwc_usb3_pcd_t pcd,
u32  intf 
)

Send TRANSMIT FUNCTION WAKE DEVICE NOTIFICATION command to Device

◆ dwc_usb3_xmit_ltm()

int dwc_usb3_xmit_ltm ( volatile dwc_usb3_pcd_t pcd,
u32  value 
)

Send LATENCY TOLERANCE MESSAGE DEVICE NOTIFICATION command to Device

◆ dwc_usb3_set_scratchpad_buf_array()

int dwc_usb3_set_scratchpad_buf_array ( volatile dwc_usb3_pcd_t pcd,
dwc_dma_t  dma_addr 
)

Send SET SCRATCHPAD BUFFER ARRAY command to Device

◆ dwc_usb3_flush_fifo()

int dwc_usb3_flush_fifo ( volatile dwc_usb3_pcd_t pcd,
u32  fifo_sel 
)

Send SELECTED FIFO FLUSH command to Device

◆ dwc_usb3_dep_cfg()

int dwc_usb3_dep_cfg ( volatile dwc_usb3_pcd_t pcd,
dwc_usb3_dev_ep_regs_t __iomem ep_reg,
u32  depcfg0,
u32  depcfg1,
u32  depcfg2 
)

Send DEPCFG command to EP

◆ dwc_usb3_dep_xfercfg()

int dwc_usb3_dep_xfercfg ( volatile dwc_usb3_pcd_t pcd,
dwc_usb3_dev_ep_regs_t __iomem ep_reg,
u32  depstrmcfg 
)

Send DEPXFERCFG command to EP

◆ dwc_usb3_dep_getepstate()

u32 dwc_usb3_dep_getepstate ( volatile dwc_usb3_pcd_t pcd,
dwc_usb3_dev_ep_regs_t __iomem ep_reg 
)

Send DEPGETEPSTATE command to EP

◆ dwc_usb3_dep_sstall()

int dwc_usb3_dep_sstall ( volatile dwc_usb3_pcd_t pcd,
dwc_usb3_dev_ep_regs_t __iomem ep_reg 
)

Send DEPSSTALL command to EP

◆ dwc_usb3_dep_cstall()

int dwc_usb3_dep_cstall ( volatile dwc_usb3_pcd_t pcd,
dwc_usb3_dev_ep_regs_t __iomem ep_reg,
int  clr_pend 
)

Send DEPCSTALL command to EP

◆ dwc_usb3_dep_startxfer()

int dwc_usb3_dep_startxfer ( volatile dwc_usb3_pcd_t pcd,
dwc_usb3_dev_ep_regs_t __iomem ep_reg,
dwc_dma_t  dma_addr,
u32  stream_or_uf 
)

Send DEPSTRTXFER command to EP

◆ dwc_usb3_dep_updatexfer()

int dwc_usb3_dep_updatexfer ( volatile dwc_usb3_pcd_t pcd,
dwc_usb3_dev_ep_regs_t __iomem ep_reg,
u32  tri 
)

Send DEPUPDTXFER command to EP

◆ dwc_usb3_dep_endxfer()

int dwc_usb3_dep_endxfer ( volatile dwc_usb3_pcd_t pcd,
dwc_usb3_dev_ep_regs_t __iomem ep_reg,
u32  tri,
u32  flags,
void *  condition 
)

Send DEPENDXFER command to EP

◆ dwc_usb3_dep_startnewcfg()

int dwc_usb3_dep_startnewcfg ( volatile dwc_usb3_pcd_t pcd,
dwc_usb3_dev_ep_regs_t __iomem ep_reg,
u32  rsrcidx 
)

Send DEPSTRTNEWCFG command to EP

◆ dwc_usb3_enable_ep()

int dwc_usb3_enable_ep ( volatile dwc_usb3_pcd_t pcd,
volatile dwc_usb3_pcd_ep_t ep 
)

Enable an EP in the DALEPENA register.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.
epThe EP to enable.
Returns
0 if succesful, -DWC_E_BUSY if already enabled.

◆ dwc_usb3_disable_ep()

int dwc_usb3_disable_ep ( volatile dwc_usb3_pcd_t pcd,
volatile dwc_usb3_pcd_ep_t ep 
)

Disable an EP in the DALEPENA register.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.
epThe EP to disable.
Returns
0 if succesful, -DWC_E_INVALID if already disabled.

◆ dwc_usb3_get_device_speed()

int dwc_usb3_get_device_speed ( volatile dwc_usb3_pcd_t pcd)

Get the device speed from the device status register and convert it to USB speed constant.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.
Returns
The device speed.

◆ dwc_usb3_get_frame()

int dwc_usb3_get_frame ( volatile dwc_usb3_pcd_t pcd)

Get the current microframe number.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.
Returns
The current microframe number.

◆ dwc_usb3_set_address()

void dwc_usb3_set_address ( volatile dwc_usb3_pcd_t pcd,
int  addr 
)

This function sets the Device Address.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.
addrThe address to set.

◆ dwc_usb3_ena_usb2_phy_suspend()

void dwc_usb3_ena_usb2_phy_suspend ( volatile dwc_usb3_pcd_t pcd)

This function enables USB2 Phy suspend.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_dis_usb2_phy_suspend()

void dwc_usb3_dis_usb2_phy_suspend ( volatile dwc_usb3_pcd_t pcd)

Disable USB2 Phy suspend.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_ena_usb3_phy_suspend()

void dwc_usb3_ena_usb3_phy_suspend ( volatile dwc_usb3_pcd_t pcd)

Enable USB3 Phy suspend.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_dis_usb3_phy_suspend()

void dwc_usb3_dis_usb3_phy_suspend ( volatile dwc_usb3_pcd_t pcd)

Disable USB3 Phy suspend.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_accept_u1()

void dwc_usb3_accept_u1 ( volatile dwc_usb3_pcd_t pcd)

Enable the Device to accept U1 control commands from the Host.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_accept_u2()

void dwc_usb3_accept_u2 ( volatile dwc_usb3_pcd_t pcd)

Enable the Device to accept U2 control commands from the Host.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_enable_u1()

void dwc_usb3_enable_u1 ( volatile dwc_usb3_pcd_t pcd)

Enable U1 sleep.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_enable_u2()

void dwc_usb3_enable_u2 ( volatile dwc_usb3_pcd_t pcd)

Enable U2 sleep.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_disable_u1()

void dwc_usb3_disable_u1 ( volatile dwc_usb3_pcd_t pcd)

Disable U1 sleep.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_disable_u2()

void dwc_usb3_disable_u2 ( volatile dwc_usb3_pcd_t pcd)

Disable U2 sleep.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_u1_enabled()

int dwc_usb3_u1_enabled ( volatile dwc_usb3_pcd_t pcd)

Test whether U1 sleep is enabled.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.
Returns
1 if enabled, 0 if not.

◆ dwc_usb3_u2_enabled()

int dwc_usb3_u2_enabled ( volatile dwc_usb3_pcd_t pcd)

Test whether U2 sleep is enabled.

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.
Returns
1 if enabled, 0 if not.

◆ dwc_usb3_clr_eps_enabled()

void dwc_usb3_clr_eps_enabled ( volatile dwc_usb3_pcd_t pcd)

Clear 'eps_enabled' flag and 'ena_once' flags for all EPs, so EPs will get completely reconfigured by SetConfig and SetInterface.

◆ dwc_usb3_dump_dbgregs()

void dwc_usb3_dump_dbgregs ( volatile dwc_usb3_device_t dev)

This routine dumps the core's internal debug registers

Parameters
devProgramming view of DWC_usb3 controller.

◆ dwc_usb3_dump_global_registers()

void dwc_usb3_dump_global_registers ( volatile dwc_usb3_device_t dev)

This routine reads the core global registers and prints them

Parameters
devProgramming view of DWC_usb3 controller.

◆ dwc_usb3_dump_dev_registers()

void dwc_usb3_dump_dev_registers ( volatile dwc_usb3_pcd_t pcd)

This routine reads the device registers and prints them

Parameters
pcdProgramming view of DWC_usb3 peripheral controller.

◆ dwc_usb3_set_tx_fifo_size()

void dwc_usb3_set_tx_fifo_size ( volatile dwc_usb3_device_t dev,
int *  sz 
)

Set the size of the Tx FIFOs

NOTE: The following code for setting the FIFO sizes only works for cores configured with the 3 RAM option. Setting FIFO sizes for the 2 RAM option is not implemented.

Parameters
devProgramming view of DWC_usb3 controller.
szNew sizes for the FIFOs.

◆ dwc_usb3_set_rx_fifo_size()

void dwc_usb3_set_rx_fifo_size ( volatile dwc_usb3_device_t dev,
u32  size 
)

Set the size of the Rx FIFO

NOTE: The following code for setting the FIFO sizes only works for cores configured with the 3 RAM option. Setting FIFO sizes for the 2 RAM option is not implemented.

Parameters
devProgramming view of DWC_usb3 controller.
sizeNew size for the FIFO.