blob: fc133eaddaf99ad414ced026aac966aece1f6998 [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001/******************************************************************************
2 *
3 * (C)Copyright 2013 Marvell. All Rights Reserved.
4 *
5 * THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF MARVELL.
6 * The copyright notice above does not evidence any actual or intended
7 * publication of such source code.
8 * This Module contains Proprietary Information of Marvell and should be
9 * treated as Confidential.
10 * The information in this file is provided for the exclusive use of the
11 * licensees of Marvell.
12 * Such users have the right to use, modify, and incorporate this code into
13 * products for purposes authorized by the license agreement provided they
14 * include this notice and the associated copyright notice with any such
15 * product.
16 * The information in this file is provided "AS IS" without warranty.
17 *
18 ******************************************************************************/
19
20#include "Typedef.h"
21#include "general.h"
22#include "Errors.h"
23#include "misc.h"
24#include "ProtocolManager.h"
25#include "platform_interrupts.h"
26#include "PlatformConfig.h"
27#include "usb2_main.h"
28#include "USB_controller.h"
29#include "usbapi.h"
30
31
32USBAPI_T USBAPI_ARRAY[MAX_USB_DEVICES];
33static int usb_speed_mode = DEFAULT_USB_SPEED_MODE;
34static int usb_phy_mode = 0x0;
35
36int get_usb_speed_mode(void)
37{
38 if (usb_speed_mode > USB_MODE_HS || usb_speed_mode < USB_MODE_FS)
39 return USB_MODE_FS;
40
41 return usb_speed_mode;
42}
43
44int get_usb_phy_mode(void)
45{
46 return usb_phy_mode;
47}
48
49void set_usb_speed_and_phy_mode(void)
50{
51
52 usb_speed_mode = USB_MODE_HS;
53 //0: parallel, 1: serial
54 usb_phy_mode = 0x0;
55}
56
57UINT USBAPI_InitializeDevice(UINT DeviceType)
58{
59 P_USBAPI_T pUSBAPI;
60
61 //Check ARRAY for already initialized device
62 pUSBAPI = GetUSBAPIhandle_BootNum(DeviceType);
63 if (pUSBAPI != NULL)
64 return NoError;
65
66 //Allocated new entry in ARRAY
67 pUSBAPI = CreateUSBAPIhandle(DeviceType);
68 if (pUSBAPI == NULL)
69 return NULLPointer;
70 pUSBAPI->interruptNum = USB0_OTG_INT;
71 pUSBAPI->USB_Receive = &USB2D_RecieveWrapper;
72 pUSBAPI->USB_Send = &USB2D_SendWrapper;
73 pUSBAPI->USB_ISR = &USB2D_ISR;
74 Platform_USB2_ON_USB2_PHY_Init();
75 USB2D_Initialize(USB_BASE, USB0_OTG_INT, 0);
76
77 //Fill out the rest of the handle entry
78 pUSBAPI->bootNum = DeviceType;
79 pUSBAPI->valid = TRUE;
80
81 //Enable Interrupt at core
82 EnablePeripheralIRQInterrupt(pUSBAPI->interruptNum);
83
84 return NoError;
85}
86
87void USBAPI_ISR(UINT IntNum)
88{
89 P_USBAPI_T pDevice = GetUSBAPIhandle_InterruptNum(IntNum);
90 if(pDevice != NULL)
91 pDevice->USB_ISR(IntNum);
92
93 return;
94}
95
96void USBAPI_ShutdownAll()
97{
98 UINT i;
99
100 for(i = 0; i < MAX_USB_DEVICES; i++)
101 { //check for enabled (valid) devices
102 if(USBAPI_ARRAY[i].valid == TRUE)
103 { //if there is a valid shutdown routine, call it
104 if(USBAPI_ARRAY[i].USB_Shutdown != NULL)
105 USBAPI_ARRAY[i].USB_Shutdown(USBAPI_ARRAY[i].interruptNum);
106
107 //now, no more USB interrupts:
108 DisablePeripheralIRQInterrupt(USBAPI_ARRAY[i].interruptNum);
109
110 //then clear out the entry
111 memset(&USBAPI_ARRAY[i], 0, sizeof(USBAPI_T));
112 }
113 }
114}
115
116P_USBAPI_T GetUSBAPIhandle_InterruptNum(UINT InterruptNum)
117{
118 UINT i;
119
120 for(i = 0; i < MAX_USB_DEVICES; i++)
121 if( (USBAPI_ARRAY[i].valid == TRUE) && USBAPI_ARRAY[i].interruptNum == InterruptNum)
122 return &USBAPI_ARRAY[i];
123
124 return NULL;
125}
126
127P_USBAPI_T GetUSBAPIhandle_BootNum(UINT BootNum)
128{
129 UINT i;
130
131 for(i = 0; i < MAX_USB_DEVICES; i++)
132 if( (USBAPI_ARRAY[i].valid == TRUE) && USBAPI_ARRAY[i].bootNum == BootNum)
133 return &USBAPI_ARRAY[i];
134
135 return NULL;
136}
137
138
139P_USBAPI_T CreateUSBAPIhandle(UINT DeviceType)
140{
141 UINT i;
142 P_USBAPI_T pUSBAPI;
143
144 pUSBAPI = GetUSBAPIhandle_BootNum(DeviceType);
145 if(pUSBAPI != NULL)
146 return pUSBAPI;
147
148 for(i = 0; i < MAX_USB_DEVICES; i++)
149 if(USBAPI_ARRAY[i].valid == FALSE)
150 {
151 pUSBAPI = &USBAPI_ARRAY[i];
152 break;
153 }
154
155 //make sure the entry starts clean
156 if(pUSBAPI != NULL)
157 memset(pUSBAPI, 0, sizeof(USBAPI_T));
158
159 return pUSBAPI;
160}
161