xref: /utopia/UTPA2-700.0.x/modules/usb/drv/usb_ecos/usbhost/drvHUB.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 
79 #ifndef _CORE_HUB_H_
80 #define _CORE_HUB_H_
81 #include <MsTypes.h>
82 
83 #include "include/drvList.h"
84 #include "include/drvCompiler.h"
85 #include "include/drvUSB.h"
86 #include "include/drvCPE_AMBA.h"
87 #include "drvUsbHostConfig.h"
88 
89 #define USB_RT_HUB  (USB_TYPE_CLASS | USB_RECIP_DEVICE)
90 #define USB_RT_PORT  (USB_TYPE_CLASS | USB_RECIP_OTHER)
91 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
92 
93 #define HUB_CLEAR_TT_BUFFER  8
94 #define HUB_RESET_TT    9
95 #define HUB_GET_TT_STATE  10
96 #define HUB_STOP_TT    11
97 
98 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
99 #define C_HUB_LOCAL_POWER  0
100 #define C_HUB_OVER_CURRENT  1
101 
102 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
103 #define USB_PORT_FEAT_CONNECTION  0
104 #define USB_PORT_FEAT_ENABLE    1
105 #define USB_PORT_FEAT_SUSPEND    2
106 #define USB_PORT_FEAT_OVER_CURRENT  3
107 #define USB_PORT_FEAT_RESET    4
108 #define USB_PORT_FEAT_POWER    8
109 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
110 #define USB_PORT_FEAT_LOWSPEED    9
111 #define USB_PORT_FEAT_HIGHSPEED    10
112 #define USB_PORT_FEAT_C_CONNECTION  16
113 #define USB_PORT_FEAT_C_ENABLE    17
114 #define USB_PORT_FEAT_C_SUSPEND    18
115 #define USB_PORT_FEAT_C_OVER_CURRENT  19
116 #define USB_PORT_FEAT_C_RESET    20
117 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
118 #define USB_PORT_FEAT_TEST              21 // ??? 11
119 #define USB_PORT_FEAT_INDICATOR         22 // ??? 12
120 
121 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
122 #define USB_PORT_STAT_CONNECTION  0x0001
123 #define USB_PORT_STAT_ENABLE    0x0002
124 #define USB_PORT_STAT_SUSPEND    0x0004
125 #define USB_PORT_STAT_OVERCURRENT  0x0008
126 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
127 #define USB_PORT_STAT_RESET    0x0010
128 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
129 #define USB_PORT_STAT_POWER    0x0100
130 #define USB_PORT_STAT_LOW_SPEED    0x0200
131 #define USB_PORT_STAT_HIGH_SPEED        0x0400
132 #define USB_PORT_STAT_TEST              0x0800
133 #define USB_PORT_STAT_INDICATOR         0x1000
134 
135 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
136 #define USB_PORT_STAT_C_CONNECTION  0x0001
137 #define USB_PORT_STAT_C_ENABLE    0x0002
138 #define USB_PORT_STAT_C_SUSPEND    0x0004
139 #define USB_PORT_STAT_C_OVERCURRENT  0x0008
140 #define USB_PORT_STAT_C_RESET    0x0010
141 
142 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
143 #define HUB_CHAR_LPSM    0x0003
144 #define HUB_CHAR_COMPOUND  0x0004
145 #define HUB_CHAR_OCPM    0x0018
146 #define HUB_CHAR_TTTT           0x0060
147 #define HUB_CHAR_PORTIND        0x0080
148 
149 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
150 struct usb_port_status {
151   U16 wPortStatus;
152   U16 wPortChange;
153 } __attribute__((packed));
154 
155 struct usb_hub_status {
156   U16 wHubStatus;
157   U16 wHubChange;
158 } __attribute__((packed));
159 
160 #define HUB_STATUS_LOCAL_POWER  0x0001
161 #define HUB_STATUS_OVERCURRENT  0x0002
162 #define HUB_CHANGE_LOCAL_POWER  0x0001
163 #define HUB_CHANGE_OVERCURRENT  0x0002
164 
165 
166 #define USB_DT_HUB      (USB_TYPE_CLASS | 0x09)
167 #define USB_DT_HUB_NONVAR_SIZE    7
168 
169 struct usb_hub_descriptor {
170   unsigned char  bDescLength;
171   unsigned char  bDescriptorType;
172   unsigned char  bNbrPorts;
173   U16 wHubCharacteristics;
174   unsigned char  bPwrOn2PwrGood;
175   unsigned char  bHubContrCurrent;
176   unsigned char  DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8 + 1]; // add 1 to prevent warning message
177   unsigned char  PortPwrCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8 + 1];
178 } __attribute__((packed));
179 
180 struct usb_device;
181 
182 struct usb_tt {
183   struct usb_device  *hub;
184   int      multi;
185 
186   spinlock_t    lock;
187   struct list_head  clear_list;
188   //struct work_struct      kevent;
189 };
190 
191 struct usb_tt_clear {
192   struct list_head  clear_list;
193   U32    tt;
194   U16      devinfo;
195 };
196 
197 extern void usb_hub_tt_clear_buffer (struct usb_device *dev, int pipe);
198 
199 struct usb_hub {
200   struct usb_interface  *intf;
201   struct urb    *urb;
202 
203   char      (*buffer)[(USB_MAXCHILDREN + 1 + 7) / 8];
204   dma_addr_t    buffer_dma;
205   union {
206     struct usb_hub_status  hub;
207     struct usb_port_status  port;
208   }status;
209 
210   int      error;
211   int      nerrors;
212 
213   struct list_head  hub_list;
214   struct list_head  event_list;
215 
216   struct usb_hub_descriptor descriptor;
217   //struct semaphore  khubd_sem;
218   struct usb_tt    tt;
219 };
220 
221 extern void hub_poll(void);
222 extern BOOL has_hub_events(U16 *pPortStatus);
223 #define HUB_RESET_TRIES    5
224 #define HUB_PROBE_TRIES    2
225 #define HUB_ROOT_RESET_TIME  50
226 #define HUB_SHORT_RESET_TIME  10
227 #define HUB_LONG_RESET_TIME  200
228 #define HUB_RESET_TIMEOUT  500
229 #define HUB_DEBOUNCE_STEP      25
230 #define HUB_DEBOUNCE_STABLE   4 // # of counts
231 
232 struct s_vPortRange
233 {
234     U32 vPortStart;
235     U32 vPortEnd;
236 };
237 
238 struct s_cpe_dev_info
239 {
240     U32 devid;
241     char devname[24];
242 };
243 
244 struct s_gVar4UsbPort
245 {
246 char name[24];
247 MS_U8 portNum;
248 struct s_vPortRange vPortRange;
249 char bus_name[24];
250 char product_desc[24];
251 struct s_cpe_dev_info cpe_dev_info;
252 #ifndef  MS_NOSAPI
253 MS_U8 *u8pHubStackBuffer;
254 #endif
255 
256 struct cpe_dev cpe_ehci_dev;
257 
258 struct list_head *p_hub_event; // for UsbTask()
259 struct usb_hcd *p_UsbHcd; // for MDrv_UsbDeviceConnect()
260 };
cpe_to_gVar(struct cpe_dev * cpe_ptr)261 static __inline__ struct s_gVar4UsbPort *cpe_to_gVar(struct cpe_dev *cpe_ptr)
262 {
263   const struct cpe_dev *__mptr = (cpe_ptr);
264   return (struct s_gVar4UsbPort *)( (char *)__mptr - (char *)offsetof(struct s_gVar4UsbPort, cpe_ehci_dev) );
265 }
266 
267 struct s_RegMap
268 {
269     MS_U32 iFlag;
270     MS_U32 baseUTMI;
271     MS_U32 baseUHC;
272     MS_U32 baseUSBC;
273     MS_U8 uhcIRQ;
274     MS_U8 usbcIRQ;
275 };
276 
277 struct s_UsbcInfo
278 {
279     MS_U8 portNum;
280     MS_U8 int_pol;
281     MS_U16 intEn;
282     MS_U16 intSts;
283     MS_U8 eventFlag;
284     MS_U8 eventType;
285 };
286 
287 struct s_ChipUsbHostDef
288 {
289     MS_U8 chipID;
290     char name[24];
291     MS_U8 nRootHub;
292     struct s_RegMap reg[NUM_OF_ROOT_HUB];
293     //struct cpe_dev *p_cpe_ehci_dev[NUM_OF_ROOT_HUB];
294     struct s_gVar4UsbPort *p_roothub[NUM_OF_ROOT_HUB];
295     struct s_UsbcInfo usbc_ip[NUM_OF_ROOT_HUB];
296 };
297 
298 
299 #endif /* __LINUX_HUB_H */
300 
301