| /****************************************************************************** |
| * |
| * (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 "general.h" |
| #include "Errors.h" |
| #include "misc.h" |
| #include "ProtocolManager.h" |
| #include "platform_interrupts.h" |
| #include "PlatformConfig.h" |
| #include "usb2_main.h" |
| #include "USB_controller.h" |
| #include "usbapi.h" |
| #if USB3_DEV |
| #include "usb3_xfr.h" |
| #include "usb3.h" |
| #endif |
| |
| USBAPI_T USBAPI_ARRAY[MAX_USB_DEVICES]; |
| static int usb_speed_mode = DEFAULT_USB_SPEED_MODE; |
| static int usb_phy_mode = 0x0; |
| int usb_port_num = 0; |
| |
| int get_usb_speed_mode(void) |
| { |
| if (usb_speed_mode > USB_MODE_HS || usb_speed_mode < USB_MODE_FS) |
| return USB_MODE_FS; |
| |
| return usb_speed_mode; |
| } |
| |
| int get_usb_phy_mode(void) |
| { |
| return usb_phy_mode; |
| } |
| |
| void set_usb_speed_and_phy_mode(void) |
| { |
| |
| usb_speed_mode = USB_MODE_HS; |
| //0: parallel, 1: serial |
| usb_phy_mode = 0x0; |
| } |
| |
| int get_usb_port_num(void) |
| { |
| return usb_port_num; |
| } |
| |
| void set_usb_port_num(int port_num) |
| { |
| usb_port_num = port_num; |
| } |
| |
| UINT USBAPI_InitializeDevice(UINT DeviceType) |
| { |
| P_USBAPI_T pUSBAPI; |
| |
| //Check ARRAY for already initialized device |
| pUSBAPI = GetUSBAPIhandle_BootNum(DeviceType); |
| if (pUSBAPI != NULL) |
| return NoError; |
| |
| //Allocated new entry in ARRAY |
| pUSBAPI = CreateUSBAPIhandle(DeviceType); |
| if (pUSBAPI == NULL) |
| return NULLPointer; |
| if (usb_port_num) |
| pUSBAPI->interruptNum = USB31_INT; |
| else |
| pUSBAPI->interruptNum = USB30_INT; |
| pUSBAPI->USB_Receive = &USB2D_RecieveWrapper; |
| pUSBAPI->USB_Send = &USB2D_SendWrapper; |
| pUSBAPI->USB_ISR = &USB2D_ISR; |
| Platform_USB2_ON_USB2_PHY_Init(); |
| USB2D_Initialize(USB_BASE, pUSBAPI->interruptNum, 0); |
| |
| //Fill out the rest of the handle entry |
| pUSBAPI->bootNum = DeviceType; |
| pUSBAPI->valid = TRUE; |
| |
| //Enable Interrupt at core |
| EnablePeripheralIRQInterrupt(pUSBAPI->interruptNum); |
| |
| return NoError; |
| } |
| |
| void USBAPI_ISR(UINT IntNum) |
| { |
| P_USBAPI_T pDevice = GetUSBAPIhandle_InterruptNum(IntNum); |
| if(pDevice != NULL) |
| pDevice->USB_ISR(IntNum); |
| |
| return; |
| } |
| |
| void USBAPI_ShutdownAll() |
| { |
| UINT i; |
| |
| for(i = 0; i < MAX_USB_DEVICES; i++) |
| { //check for enabled (valid) devices |
| if(USBAPI_ARRAY[i].valid == TRUE) |
| { //if there is a valid shutdown routine, call it |
| if(USBAPI_ARRAY[i].USB_Shutdown != NULL) |
| USBAPI_ARRAY[i].USB_Shutdown(USBAPI_ARRAY[i].interruptNum); |
| |
| //now, no more USB interrupts: |
| DisablePeripheralIRQInterrupt(USBAPI_ARRAY[i].interruptNum); |
| |
| //then clear out the entry |
| memset(&USBAPI_ARRAY[i], 0, sizeof(USBAPI_T)); |
| } |
| } |
| } |
| |
| P_USBAPI_T GetUSBAPIhandle_InterruptNum(UINT InterruptNum) |
| { |
| UINT i; |
| |
| for(i = 0; i < MAX_USB_DEVICES; i++) |
| if( (USBAPI_ARRAY[i].valid == TRUE) && USBAPI_ARRAY[i].interruptNum == InterruptNum) |
| return &USBAPI_ARRAY[i]; |
| |
| return NULL; |
| } |
| |
| P_USBAPI_T GetUSBAPIhandle_BootNum(UINT BootNum) |
| { |
| UINT i; |
| |
| for(i = 0; i < MAX_USB_DEVICES; i++) |
| if( (USBAPI_ARRAY[i].valid == TRUE) && USBAPI_ARRAY[i].bootNum == BootNum) |
| return &USBAPI_ARRAY[i]; |
| |
| return NULL; |
| } |
| |
| |
| P_USBAPI_T CreateUSBAPIhandle(UINT DeviceType) |
| { |
| UINT i; |
| P_USBAPI_T pUSBAPI; |
| |
| pUSBAPI = GetUSBAPIhandle_BootNum(DeviceType); |
| if(pUSBAPI != NULL) |
| return pUSBAPI; |
| |
| for(i = 0; i < MAX_USB_DEVICES; i++) |
| if(USBAPI_ARRAY[i].valid == FALSE) |
| { |
| pUSBAPI = &USBAPI_ARRAY[i]; |
| break; |
| } |
| |
| //make sure the entry starts clean |
| if(pUSBAPI != NULL) |
| memset(pUSBAPI, 0, sizeof(USBAPI_T)); |
| |
| return pUSBAPI; |
| } |
| |