xref: /utopia/UTPA2-700.0.x/projects/tmplib/include/drvUsbcommon.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 //    Software and any modification/derivatives thereof.
18 //    No right, ownership, or interest to MStar Software and any
19 //    modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 //    supplied together with third party`s software and the use of MStar
23 //    Software may require additional licenses from third parties.
24 //    Therefore, you hereby agree it is your sole responsibility to separately
25 //    obtain any and all third party right and license necessary for your use of
26 //    such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 //    MStar`s confidential information and you agree to keep MStar`s
30 //    confidential information in strictest confidence and not disclose to any
31 //    third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 //    kind. Any warranties are hereby expressly disclaimed by MStar, including
35 //    without limitation, any warranties of merchantability, non-infringement of
36 //    intellectual property rights, fitness for a particular purpose, error free
37 //    and in conformity with any international standard.  You agree to waive any
38 //    claim against MStar for any loss, damage, cost or expense that you may
39 //    incur related to your use of MStar Software.
40 //    In no event shall MStar be liable for any direct, indirect, incidental or
41 //    consequential damages, including without limitation, lost of profit or
42 //    revenues, lost or damage of data, and unauthorized system use.
43 //    You agree that this Section 4 shall still apply without being affected
44 //    even if MStar Software has been modified by MStar in accordance with your
45 //    request or instruction for your use, except otherwise agreed by both
46 //    parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 //    services in relation with MStar Software to you for your use of
50 //    MStar Software in conjunction with your or your customer`s product
51 //    ("Services").
52 //    You understand and agree that, except otherwise agreed by both parties in
53 //    writing, Services are provided on an "AS IS" basis and the warranty
54 //    disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 //    or otherwise:
58 //    (a) conferring any license or right to use MStar name, trademark, service
59 //        mark, symbol or any other identification;
60 //    (b) obligating MStar or any of its affiliates to furnish any person,
61 //        including without limitation, you and your customers, any assistance
62 //        of any kind whatsoever, or any information; or
63 //    (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 //    of Taiwan, R.O.C., excluding its conflict of law rules.
67 //    Any and all dispute arising out hereof or related hereto shall be finally
68 //    settled by arbitration referred to the Chinese Arbitration Association,
69 //    Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 //    Rules of the Association by three (3) arbitrators appointed in accordance
71 //    with the said Rules.
72 //    The place of arbitration shall be in Taipei, Taiwan and the language shall
73 //    be English.
74 //    The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 #ifndef __USBCOMMON_H
79 #define __USBCOMMON_H
80 
81 #include "asmCPU.h" // ASSERT debug
82 
83 typedef void* (*mem_Alloc)(int size);
84 typedef void (*mem_Free)(void* pBuf);
85 typedef MS_U32 (*mem_VA2PA)(MS_U32 addr);
86 typedef MS_U32 (*mem_PA2VA)(MS_U32 addr, int bCached);
87 typedef void* (*mem_Cached2Noncached)(MS_U32 addr);
88 typedef void* (*mem_NonCached2Cached)(MS_U32 addr);
89 
90 
91 extern mem_Alloc    pfnAllocCachedMem, pfnAllocNoncachedMem;
92 extern mem_Free     pfnFreeCachedMem, pfnFreeNoncachedMem;
93 extern mem_VA2PA    pfnVA2PA;
94 extern mem_PA2VA    pfnPA2VA;
95 extern mem_Cached2Noncached     pfnCached2Noncached;
96 extern mem_NonCached2Cached     pfnNoncached2Cached;
97 
98 #if 1 // eCos lib
99 #define Usb_AllocateNonCachedMemory(x)  pfnAllocNoncachedMem(x)
100 #define Usb_FreeNonCachedMemory(x)      pfnFreeNoncachedMem(x)
101 #define Usb_AllocateCachedMemory(x)     pfnAllocCachedMem(x)
102 #define Usb_FreeCachedMemory(x)         pfnFreeCachedMem(x)
103 
104 
105 //extern void* (*kmalloc)(int size, int flag);
106 //extern void  (*kfree)(void* pBuf);
107 #define kmalloc(size, flag)             pfnAllocCachedMem(size)
108 #define kfree(pBuf)                     pfnFreeCachedMem(pBuf)
109 
110 #define USB_VA2PA(addr)                 pfnVA2PA(addr)
111 #else
112 #define Usb_AllocateNonCachedMemory(x)  kmalloc(x, 0)
113 #define Usb_FreeNonCachedMemory(x)      kfree(x)
114 #define Usb_AllocateCachedMemory(x)     kmalloc(x, 0)
115 #define Usb_FreeCachedMemory(x)         kfree(x)
116 #endif
117 
118 #if 1 // eCos lib
119 #define KSEG02KSEG1(addr)       pfnCached2Noncached((MS_U32)addr)  //cached -> unchched, 20111017 for K2
120 #define KSEG12KSEG0(addr)       pfnNoncached2Cached((MS_U32)addr) //unchched -> cached
121 #else
122 #define KSEG02KSEG1(addr)       ((void *)((MS_U32)(addr)|0x20000000))  //cached -> unchched
123 #define KSEG12KSEG0(addr)       ((void *)((MS_U32)(addr)&~0x20000000)) //unchched -> cached
124 #endif
125 
126 #ifndef U32
127 #define U32 MS_U32
128 #endif
129 
130 #ifndef U16
131 #define U16 MS_U16
132 #endif
133 
134 #ifndef U8
135 #define U8 MS_U8
136 #endif
137 
138 #ifndef S32
139 #define S32 MS_S32
140 #endif
141 
142 #ifndef S16
143 #define S16 MS_S16
144 #endif
145 
146 #ifndef S8
147 #define S8 MS_S8
148 #endif
149 
150 #ifndef __u32
151 #define __u32 MS_U32
152 #endif
153 
154 #ifndef __u16
155 #define __u16 MS_U16
156 #endif
157 
158 #ifndef __u8
159 #define __u8 MS_U8
160 #endif
161 
162 #ifndef __s32
163 #define __s32 MS_S32
164 #endif
165 
166 #ifndef __s16
167 #define __s16 MS_S16
168 #endif
169 
170 #ifndef __s8
171 #define __s8 MS_S8
172 #endif
173 
174 #ifndef BOOL
175 #define BOOL MS_BOOL
176 #endif
177 
178 #ifndef BOOLEAN
179 #define BOOLEAN MS_BOOL
180 #endif
181 
182 
183 #ifdef MS_DEBUG
184 #define ASSERT(_bool_)                                                                                      \
185         {                                                                                                   \
186             if ( ! ( _bool_ ) )                                                                             \
187             {                                                                                               \
188                 diag_printf("ASSERT FAIL: %s, %s %s %d\n", #_bool_, __FILE__, __PRETTY_FUNCTION__, __LINE__);\
189                 MAsm_CPU_SwDbgBp();                                                                       \
190             }                                                                                               \
191         }
192 #else
193 #define ASSERT(_bool_) MS_ASSERT(_bool_)
194 #endif
195 
196 
197 
198 //#define MsOS_DiableAllInterrupts() MsOS_DisableAllInterrupts()
199 
200 //externC int  diag_printf( const char *fmt, ... );
201 
202 #ifndef MSTAR_USB_DEBUG
203 #define MSTAR_USB_DEBUG                  0
204 #endif
205 
206 /* Define trace levels. */
207 #define USB_DEBUG_LEVEL_ERROR          (1)    /* Error condition debug messages. */
208 #define USB_DEBUG_LEVEL_WARNING        (2)    /* Warning condition debug messages. */
209 #define USB_DEBUG_LEVEL_DEBUG          (3)    /* Debug messages (high debugging). */
210 #define USB_DEBUG_LEVEL_INFO           (4)    /* Infomation messages. */
211 
212 #define USB_DEBUG_LEVEL                USB_DEBUG_LEVEL_WARNING
213 
214 
215 #if     (MSTAR_USB_DEBUG)
216 #define ehci_printf(fmt, arg...)       diag_printf(fmt, ##arg)
217 #define ehci_debug(dbg_lv, str, ...)                \
218     do {                                            \
219         if (dbg_lv > USB_DEBUG_LEVEL)               \
220             break;                                  \
221         else {                                      \
222             ehci_printf(str, ##__VA_ARGS__);        \
223         }                                           \
224     } while(0)
225 #else  /* MSTAR_USB_DEBUG */
226 #define ehci_printf(...)
227 #define ehci_debug(enable, tag, str, ...) do{} while(0)
228 #endif /* MSTAR_USB_DEBUG */
229 
230 //#define MSTAR_USB_DEBUG_MSG
231 #ifdef MSTAR_USB_DEBUG_MSG
232 #define ms_usbhost_msg(fmt, arg...)    \
233         do {diag_printf(fmt, ##arg);} while(0)
234 #else
235 #define ms_usbhost_msg(...)
236 #endif
237 
238 //#define MSTAR_USB_DEBUG_WARN
239 #ifdef MSTAR_USB_DEBUG_WARN
240 #define ms_usbhost_warn(fmt, arg...)    \
241         do {diag_printf(fmt, ##arg);} while(0)
242 #else
243 #define ms_usbhost_warn(...)
244 #endif
245 
246 //#define MSTAR_USB_DEBUG_DEBUG
247 #ifdef MSTAR_USB_DEBUG_DEBUG
248 #define ms_usbhost_debug(fmt, arg...)    \
249         do {diag_printf(fmt, ##arg);} while(0)
250 #else
251 #define ms_usbhost_debug(...)
252 #endif
253 
254 //Chip ID deifinition
255 #define CHIPID_NEPTUNE     0x2
256 #define CHIPID_ERIS        0x3
257 #define CHIPID_TITANIA     0x4
258 #define CHIPID_PLUTO       0x5
259 #define CHIPID_TRITON      0x6
260 #define CHIPID_TITANIA2    0xB
261 #define CHIPID_TITANIA3    0xF
262 #define CHIPID_EUCLID      0x15
263 #define CHIPID_TITANIA4    0x18
264 #define CHIPID_URANUS4     0x1B
265 #define CHIPID_TITANIA7    0x1C
266 #define CHIPID_JANUS       0x1D
267 #define CHIPID_TITANIA8    0x1F
268 #define CHIPID_TITANIA9    0x23
269 #define CHIPID_KRONUS      0x2F
270 #define CHIPID_KAISERIN      0x41
271 #define CHIPID_KAPPA       0x75
272 #define CHIPID_KELTIC      0x72
273 #define CHIPID_KENYA       0x7C
274 #define CHIPID_KRITI       0x87
275 #define CHIPID_KAISER      0x56
276 #define CHIPID_KERES       0x7E
277 
278 
279 #if defined(CHIP_U4)
280     #define USB_LIB_CHIPID        CHIPID_URANUS4
281 #elif defined(CHIP_K1)
282     #define USB_LIB_CHIPID        CHIPID_KRONUS
283 #elif defined(CHIP_K2)
284     #define USB_LIB_CHIPID        CHIPID_KAISERIN
285 #elif defined(CHIP_KAPPA)
286     #define USB_LIB_CHIPID        CHIPID_KAPPA
287 #elif defined(CHIP_KELTIC)
288     #define USB_LIB_CHIPID        CHIPID_KELTIC
289 #elif defined(CHIP_KENYA)
290     #define USB_LIB_CHIPID        CHIPID_KENYA
291 #elif defined(CHIP_KRITI)
292     #define USB_LIB_CHIPID        CHIPID_KRITI
293 #elif defined(CHIP_KAISER)
294     #define USB_LIB_CHIPID        CHIPID_KAISER
295 #elif defined(CHIP_KERES)
296     #define USB_LIB_CHIPID        CHIPID_KERES
297 #else
298     #error No USB Driver Supported
299 #endif
300 
301 #endif
302 
303