xref: /utopia/UTPA2-700.0.x/modules/usb/drv/usb_ecos/newhost/drvUsbd.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_HCD_H_
80 #define _CORE_HCD_H_
81 
82 #include <MsCommon.h>
83 #include "include/drvUSBHost.h"
84 #include "drvHub.h"
85 
86 #define  HCD_FS   0x0010
87 #define  HCD_HS   0x0020
88 #define HCD_MEM_POOLS  5
89 
90 struct st_saved_ehci_state
91 {
92     int iPsc;
93     U32 reset_done;
94     U32 usbcmd;
95 };
96 
97 struct usb_hcd {
98 
99   struct usb_bus    self;
100   int  hcd_flags;
101   char    product_desc[24];  /* product/vendor string */
102 
103   struct timer_list  roothub_timer;
104   struct urb		*hcd_status_urb;
105   struct list_head  hcd_dev_list;
106 
107   int  (*ms_urb_enqueue) (struct usb_hcd *hcd, struct urb *urb, int mem_flags);
108   int  (*ms_urb_dequeue) (struct usb_hcd *hcd, struct urb *urb);
109 
110   // Check root hub registered
111   unsigned        roothub_registered:1;
112   // for the new root-hub polling mechanism.
113   unsigned        hcd_poll_pending:1;
114   unsigned        rh_disconn:1;
115 
116   int      ehci_irq;
117   U32      *uhc_regs;
118   struct device_s    *controller;
119   struct ms_mem_pool    *pool [HCD_MEM_POOLS];
120 
121   int      state;
122 
123     // new to collect hcd related variables
124     U32 host_id;
125     //U32 pre_sts; // preserve the previous state (ehci_hub_status_data)
126     //U32 pre_temp; // preserve the previous state (ehci_hub_control_EX)
127     S32 USBWaitFlg; // OS wait flag
128     U32 badDeviceCnt; // for Philips mp3 device
129     BOOL isBadDevice; // backward compatible
130     BOOL isBadDeviceRH; // bad device on the root hub
131     BOOL isRootHubPortReset; // backward compatible, may be omitted
132     BOOL isFSmode;
133     struct list_head *phub_event;
134     struct list_head tt_clear_list;
135     struct st_saved_ehci_state saved_ehci_state;
136 };
137 
138 // define usb_hcd.state
139 #define  __ACTIVE    0x01
140 #define  __SLEEPY    0x02
141 #define  __SUSPEND    0x04
142 #define  __TRANSIENT    0x80
143 
144 #define  HCD_STATE_HALT    0
145 #define  HCD_STATE_RUNNING  (__ACTIVE)
146 #define  HCD_STATE_READY    (__ACTIVE|__SLEEPY)
147 #define  HCD_STATE_QUIESCING  (__SUSPEND|__TRANSIENT|__ACTIVE)
148 #define  HCD_STATE_RESUMING  (__SUSPEND|__TRANSIENT)
149 #define  HCD_STATE_SUSPENDED  (__SUSPEND)
150 
151 #define  HCD_IS_RUNNING(state) ((state) & __ACTIVE)
152 #define  HCD_IS_SUSPENDED(state) ((state) & __SUSPEND)
153 
154 struct stPtRegs;
155 
156 struct s_hcd_dev {
157   struct list_head  dev_list;
158   struct list_head  urb_list;
159 
160   void      *ep[32];
161 };
162 
163 /*
164 //struct ms_usb_bus_ops {
165 //  int (*ms_alloc_hcd_dev)(struct usb_device *);
166 //  int (*ms_deallo_hcd_dev)(struct usb_device *);
167 //  int (*ms_hcd_submit_urb) (struct urb *urb, int mem_flags);
168 //  int (*ms_hcd_unlink_urb) (struct urb *urb);
169 //  void *(*ms_alloc_hcd_buffer)(struct usb_bus *bus, size_t size,
170 //      int mem_flags,
171 //      dma_addr_t *dma);
172 //  void (*ms_free_hcd_buffer)(struct usb_bus *bus, size_t size,
173 //      void *addr, dma_addr_t dma);
174 //  void (*ms_disable_ep)(struct usb_device *udev, int bEndpointAddress);
175 //};
176 */
177 extern int ms_hcd_submit_urb (struct urb *, int);
178 extern int ms_hcd_unlink_urb (struct urb *, int);
179 extern int ms_hcd_free_dev (struct usb_device *);
180 extern int ms_hcd_alloc_dev (struct usb_device *);
181 extern void ms_usb_hcd_flush_endpoint(struct usb_device *, int);
182 extern void ms_hcd_endpoint_disable (struct usb_device *, int);
183 extern void ms_hcd_check_dev_urb (struct usb_device *, int); // debug only
184 
185 extern int ms_unlink1(struct usb_hcd *, struct urb *);
186 
187 extern void ms_usb_hcd_giveback_urb (struct urb *urb, struct stPtRegs *regs);
188 extern void ms_usb_bus_init (struct usb_bus *bus);
189 extern void ms_rh_status_dequeue (struct usb_hcd *pHcd, struct urb *pUrb);
190 
191 int ms_hcd_buffer_create (struct usb_hcd *hcd);
192 void ms_hcd_buffer_destroy (struct usb_hcd *hcd);
193 
194 void *ms_hcd_buffer_alloc (struct usb_bus *bus, size_t size,
195   int mem_flags, dma_addr_t *dma);
196 void ms_hcd_buffer_free (struct usb_bus *bus, size_t size,
197   void *addr, dma_addr_t dma);
198 
199 //extern struct ms_usb_bus_ops ms_usb_hcd_operations;
200 
201 extern int ms_usb_new_device(struct usb_device *dev, struct device_s *parent);
202 extern void ms_usb_choose_address(struct usb_device *dev);
203 extern void ms_usb_disconnect(struct usb_device **);
204 
205 extern int ms_usb_get_config(struct usb_device *dev);
206 extern void ms_usb_destroy_config(struct usb_device *dev);
207 extern int ms_usb_set_address(struct usb_device *dev);
208 
209 #define usb_snddefctrl(dev)    (((U32)EP_CONTROL << 30))
210 #define usb_rcvdefctrl(dev)    (((U32)EP_CONTROL << 30) | USB_DIR_IN)
211 
212 /*-------------------------------------------------------------------------*/
213 
214 #define ms_CalcBitTime(bytes)  (7 * 8 * bytes / 6)  /* with ��� truncation */
215 
216 #define NS_2_US(ns)  ((ns + 500L) / 1000L)
217 
218 #define USB2_EHCI_DELAY  5       // (ns)
219 #define EHCI_BW_DELAY    1000L   // (ns)
220 #define HUB_BW_LS_SETUP  333L    // (ns)
221 
222 // revised base on linux code
223 #define HIGHSPEED_NS(bytes)  ( ((55 * 8 * 2083) \
224   + (2083UL * (3 + ms_CalcBitTime (bytes))))/1000 \
225   + USB2_EHCI_DELAY)
226 
227 #define HIGHSPEED_NS_ISO(bytes)  ( ((38 * 8 * 2083) \
228   + (2083UL * (3 + ms_CalcBitTime (bytes))))/1000 \
229   + USB2_EHCI_DELAY)
230 
231 #define HIGHSPEED_US(bytes) NS_2_US(HIGHSPEED_NS(bytes))
232 #define HIGHSPEED_US_ISO(bytes) NS_2_US(HIGHSPEED_NS_ISO(bytes))
233 
234 extern int ms_usb_calc_bus_time (int speed, int is_input, int bytes);
235 
236 /*-------------------------------------------------------------------------*/
237 
238 #define Req_SetHubFeature     (0x2000 | USB_REQ_SET_FEATURE)
239 #define Req_SetPortFeature    (0x2300 | USB_REQ_SET_FEATURE)
240 #define Req_GetHubDescriptor  (0xa000 | USB_REQ_GET_DESCRIPTOR)
241 #define Req_GetHubStatus      (0xa000 | USB_REQ_GET_STATUS)
242 #define Req_GetPortStatus     (0xa300 | USB_REQ_GET_STATUS)
243 #define Req_ClearHubFeature   (0x2000 | USB_REQ_CLEAR_FEATURE)
244 #define Req_ClearPortFeature  (0x2300 | USB_REQ_CLEAR_FEATURE)
245 
246 #define ReqType_Device \
247   ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
248 #define ReqType_DeviceOut \
249   ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
250 
251 #define ReqType_Interface \
252   ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
253 
254 #define ReqType_Endpoint \
255   ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
256 #define ReqType_EndpointOut \
257   ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
258 
259 /*-------------------------------------------------------------------------*/
260 extern int ms_usb_register_bus (struct usb_bus *);
261 extern void ms_usb_deregister_bus (struct usb_bus *);
262 extern int ms_register_root_hub (struct usb_hcd *hcd);
263 
264 extern struct list_head usb_bus_list;
265 
266 //#define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
267 
268 #define usb_endpoint_dir(ep_dir)  (!((ep_dir) & USB_DIR_IN))
269 
270 //#define bitmap   DeviceRemovable
271 
272 #endif
273