| #ifndef __USB2_MAIN_H__ |
| #define __USB2_MAIN_H__ |
| /****************************************************************************** |
| * |
| * (C)Copyright 2013 Marvell. All Rights Reserved. |
| * |
| * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MARVELL. |
| * The copyright notice above does not evidence any actual or intended |
| * publication of such source code. |
| * This Module contains Proprietary Information of Marvell and should be |
| * treated as Confidential. |
| * The information in this file is provided for the exclusive use of the |
| * licensees of Marvell. |
| * Such users have the right to use, modify, and incorporate this code into |
| * products for purposes authorized by the license agreement provided they |
| * include this notice and the associated copyright notice with any such |
| * product. |
| * The information in this file is provided "AS IS" without warranty. |
| * |
| ******************************************************************************/ |
| |
| #include "Typedef.h" |
| #include "usbdefs.h" |
| |
| #define USB2D_CTRL_RESET_TIME_MS 0x20 |
| #define USB2D_SHUTDOWN_TIME_MS 0x20 |
| #define MAX_USB2_dTD_XFER_SIZE_B (16*1024) |
| |
| #define FOUR_KB_DTD_LIMIT (0x1000) |
| #define FOUR_KB_DTD_MASK (0xFFF) |
| |
| #define EP0_OUT_BUFF_SIZE (512) |
| #define EP0_IN_BUFF_SIZE (512) |
| #define EP1_OUT_BUFF_SIZE (1024) |
| #define EP1_IN_BUFF_SIZE (512) |
| |
| #define EP0_DATA_RCD_NUM (32) |
| #define EP1IN_DATA_RCD_NUM (16) |
| #define EP1OUT_DATA_RCD_NUM (16) |
| #define EP1OUT_NCOPM_DATA_RCD_NUM (16) |
| #define USB_INT_REG_RCD_NUM (16) |
| |
| #ifndef MIN |
| #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
| #endif |
| |
| // Enumerate USB Endpoints |
| typedef enum USB_SPEED_MODE |
| { |
| USB_MODE_LS = 0, |
| USB_MODE_FS, |
| USB_MODE_HS, |
| } USB_SPEED_MODE_T; |
| |
| enum USB_DEVICE_STATE { |
| /* NOTATTACHED isn't in the USB spec, and this state acts |
| * the same as ATTACHED ... but it's clearer this way. |
| */ |
| USB_STATE_NOTATTACHED = 0, |
| |
| /* chapter 9 and authentication (wireless) device states */ |
| USB_STATE_ATTACHED, |
| USB_STATE_POWERED, /* wired */ |
| USB_STATE_RECONNECTING, /* auth */ |
| USB_STATE_UNAUTHENTICATED, /* auth */ |
| USB_STATE_DEFAULT, /* limited function */ |
| USB_STATE_ADDRESS, |
| USB_STATE_CONFIGURED, /* most functions */ |
| |
| USB_STATE_SUSPENDED |
| |
| /* NOTE: there are actually four different SUSPENDED |
| * states, returning to POWERED, DEFAULT, ADDRESS, or |
| * CONFIGURED respectively when SOF tokens flow again. |
| * At this level there's no difference between L1 and L2 |
| * suspend states. (L2 being original USB 1.1 suspend.) |
| */ |
| }; |
| |
| // Interrupt / Status Register Masks |
| //Endpoint Queue Head Structure (must be padded to 64 Bytes) |
| #pragma pack (4) |
| typedef struct |
| { |
| UINT_T tot_size; //not used by USB driver, used by software to xfer info |
| UINT_T buffer; //not used by USB driver, used by software to xfer info |
| } dQH_T, *P_dQH_T; |
| #pragma pack () |
| |
| //Device 'Object' |
| #pragma pack (4) |
| typedef struct |
| { |
| P_dQH_T pdQHHead; //pointer to the first Queue Head (EP0 In) for this device |
| UINT_T InterruptNum; //interrupt number for this device |
| |
| UINT_T SendBuffer[EP1_IN_BUFF_SIZE / sizeof(UINT_T)]; |
| UINT_T ep0_out_buffer[EP0_OUT_BUFF_SIZE / sizeof(UINT_T)]; //space for ep0_out |
| UINT_T BufferSpace[EP1_OUT_BUFF_SIZE / sizeof(UINT_T)]; //space for initial EP2 priming (before getting to Protocol manager): for preamble |
| UINT_T ep0_in_buffer[EP0_IN_BUFF_SIZE / sizeof(UINT_T)]; //space for ep0_in |
| UCHAR *ep0_out_buff_ptr; |
| UCHAR *ep0_in_buff_ptr; |
| UCHAR *data_in_buff_ptr; |
| UCHAR *data_out_buff_ptr; |
| |
| UCHAR ep0rx_data_len_array[EP0_DATA_RCD_NUM]; |
| UINT_T ep0rx_rcd_idx; |
| UCHAR ep0_data_len_array[EP0_DATA_RCD_NUM]; |
| UINT_T ep0_rcd_idx; |
| UINT16_T ep1in_data_len_array[EP1IN_DATA_RCD_NUM]; |
| UINT_T ep1in_rcd_idx; |
| UINT16_T ep1out_data_len_array[EP1OUT_DATA_RCD_NUM]; |
| UINT_T ep1out_rcd_idx; |
| UINT16_T ep1rx_data_len_array[EP1OUT_DATA_RCD_NUM]; |
| UINT_T ep1rx_rcd_idx; |
| UINT_T ep1rx_ncomp_reg_array[EP1OUT_NCOPM_DATA_RCD_NUM]; |
| UINT_T ep1rx_ncomp_rcd_idx; |
| UINT_T usb_int_reg_array[EP1OUT_NCOPM_DATA_RCD_NUM]; |
| UINT_T usb_int_rcd_idx; |
| |
| UCHAR usb_speed_mode; |
| UCHAR nr_ep0_stall; |
| UCHAR dev_state; |
| UINT_T stop_timeout1; |
| UINT_T stop_timeout2; |
| UINT_T stop_timeout3; |
| UINT_T stop_timeout4; |
| UINT_T stop_timeout5; |
| UINT_T stop_timeout6; |
| UINT_T dev_addr; |
| UINT_T dwc_usb2_err_status; |
| UINT_T dwc_crst_tout; |
| UINT_T dwc_ahbidle_tout; |
| } DC_Properties_T, *P_DC_Properties_T; |
| #pragma pack () |
| |
| //Prototypes |
| UINT_T USB2D_Initialize(UINT_T base_address, UINT_T int_number, int usb_speed_mode); |
| void USB2D_Shutdown(UINT intnum); |
| void USB2D_ISR(UINT_T intnum); |
| void USB2D_Controller_Setup(P_DC_Properties_T pDCProps, int usb_speed_mode); |
| void USB2D_Endpoint_Setup(P_DC_Properties_T pDCProps, XLLP_USB_ENDPOINT_ID_T ep_num, XLLP_USB_EP_DIR_T direction, XLLP_USB_EP_TYPE_T type); |
| void USB2D_Reset_Int(P_DC_Properties_T pDCProps); |
| void USB2D_Setup_Int(P_DC_Properties_T pDCProps); |
| void USB2D_PM_Call(P_DC_Properties_T pDCProps); |
| void USB2D_Endpoint0Transmit(P_DC_Properties_T pDCProps, XLLP_USB_ENDPOINT_ID_T ep_num, XLLP_USB_EP_DIR_T direction, UINT_T buffer, UINT_T size); |
| void USB2D_EndpointTransmit(P_DC_Properties_T pDCProps, XLLP_USB_ENDPOINT_ID_T ep_num, XLLP_USB_EP_DIR_T direction, UINT_T buffer, UINT_T size); |
| void USB2D_SendWrapper(UINT_T *buffer, UINT_T size, void * pUSBAPI); |
| void USB2D_RecieveWrapper(UINT_T *buffer, UINT_T size, void * pUSBAPI); |
| void USB2D_EP0_STALL_AND_RESTART(P_DC_Properties_T pDCProps); |
| void USB2D_Set_Addr(UINT16_T Addr); |
| |
| #define PRINT_DBG_LOG 0 |
| #define DEFAULT_USB_SPEED_MODE (USB_MODE_HS) |
| |
| #ifdef PRINT_DBG_LOG |
| //extern int bbu_printf(const char *format, ...); |
| #define bbu_printf(format,...) do {} while(0) |
| #else |
| #define bbu_printf(format,...) do {} while(0) |
| #endif |
| |
| /* #define CONFIG_FPGA_USB_TEST 1 */ |
| |
| #endif |