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/drvUSB.h"
84
85 #define USB_PID_UNDEF_0 0xf0
86 #define USB_PID_OUT 0xe1
87 #define USB_PID_ACK 0xd2
88 #define USB_PID_DATA0 0xc3
89 #define USB_PID_PING 0xb4
90 #define USB_PID_SOF 0xa5
91 #define USB_PID_NYET 0x96
92 #define USB_PID_DATA2 0x87
93 #define USB_PID_SPLIT 0x78
94 #define USB_PID_IN 0x69
95 #define USB_PID_NAK 0x5a
96 #define USB_PID_DATA1 0x4b
97 #define USB_PID_PREAMBLE 0x3c
98 #define USB_PID_ERR 0x3c
99 #define USB_PID_SETUP 0x2d
100 #define USB_PID_STALL 0x1e
101 #define USB_PID_MDATA 0x0f
102
103 struct usb_hcd {
104
105 struct usb_bus self;
106
107 //const char *product_desc; /* product/vendor string */
108 char product_desc[24]; /* product/vendor string */
109 //const char *description; /* "ehci-hcd" etc */
110 char description[24]; /* "ehci-hcd" etc */
111
112 struct timer_list rh_timer;
113 struct urb *status_urb;
114 struct list_head dev_list;
115
116 struct hc_driver *driver;
117
118 #if 1 //def ROOTHUB_INTERRUPT_MODE
119 unsigned rh_registered:1;/* is root hub registered? */
120
121 /* The next flag is a stopgap, to be removed when all the HCDs
122 * support the new root-hub polling mechanism. */
123 unsigned uses_new_polling:1;
124 unsigned poll_rh:1; /* poll for rh status? */
125 unsigned poll_pending:1; /* status has changed? */
126 unsigned wireless:1; /* Wireless USB HCD */
127 unsigned authorized_default:1;
128 unsigned has_tt:1; /* Integrated TT in root hub */
129 #endif
130
131 int irq;
132 U32 *regs;
133 struct device_s *controller;
134
135 struct pci_dev *pdev;
136
137 #ifdef CONFIG_PCI
138 int region;
139 U32 pci_state [16];
140 atomic_t resume_count;
141 #endif
142
143 #define HCD_BUFFER_POOLS 5
144 struct pci_pool *pool [HCD_BUFFER_POOLS];
145
146 int state;
147 #define __ACTIVE 0x01
148 #define __SLEEPY 0x02
149 #define __SUSPEND 0x04
150 #define __TRANSIENT 0x80
151
152 #define USB_STATE_HALT 0
153 #define USB_STATE_RUNNING (__ACTIVE)
154 #define USB_STATE_READY (__ACTIVE|__SLEEPY)
155 #define USB_STATE_QUIESCING (__SUSPEND|__TRANSIENT|__ACTIVE)
156 #define USB_STATE_RESUMING (__SUSPEND|__TRANSIENT)
157 #define USB_STATE_SUSPENDED (__SUSPEND)
158
159 #define HCD_IS_RUNNING(state) ((state) & __ACTIVE)
160 #define HCD_IS_SUSPENDED(state) ((state) & __SUSPEND)
161
162 #if 1 // new to collect hcd related variables
163 U32 host_id;
164 U32 pre_sts; // preserve the previous state (ehci_hub_status_data)
165 U32 pre_temp; // preserve the previous state (ehci_hub_control_EX)
166 S32 USBWaitFlg; // OS wait flag
167 U32 badDeviceCnt; // for Philips mp3 device
168 BOOL isBadDevice; // backward compatible
169 BOOL isRootHubPortReset; // backward compatible, may be omitted
170 struct list_head *phub_event;
171 struct s_gVar4UsbPort *pgVar; // link to global variable struct, JF
172 #endif
173 };
174
175 struct usb_otgd {
176
177 struct usb_bus *bus;
178
179 //const char *product_desc; /* product/vendor string */
180 char product_desc[24]; /* product/vendor string */
181 //const char *description; /* "FOTG100_DRIVER" etc */
182 char description[24]; /* "FOTG100_DRIVER" etc */
183
184 struct otg_driver *driver;
185 int irq;
186 U32 *regs;
187 struct device *controller;
188 struct usb_otg_ap_operations ap_op;
189 struct usb_otg_descriptor desc;
190 };
191
hcd_to_bus(struct usb_hcd * hcd)192 static __inline__ struct usb_bus *hcd_to_bus (struct usb_hcd *hcd)
193 {
194 return &hcd->self;
195 }
196
197
198 struct hcd_dev {
199 struct list_head dev_list;
200 struct list_head urb_list;
201
202 void *ep[32];
203 };
204
205
206 struct hcd_timeout {
207 struct list_head timeout_list;
208 struct timer_list timer;
209 };
210
211 struct usb_operations {
212 int (*allocate)(struct usb_device *);
213 int (*deallocate)(struct usb_device *);
214 int (*get_frame_number) (struct usb_device *usb_dev);
215 int (*submit_urb) (struct urb *urb, int mem_flags);
216 int (*unlink_urb) (struct urb *urb);
217
218 void *(*buffer_alloc)(struct usb_bus *bus, size_t size,
219 int mem_flags,
220 dma_addr_t *dma);
221 void (*buffer_free)(struct usb_bus *bus, size_t size,
222 void *addr, dma_addr_t dma);
223
224 void (*disable)(struct usb_device *udev, int bEndpointAddress);
225 };
226
227
228 struct pt_regs;
229
230 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
231 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
232 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
233 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
234 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
235 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
236 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
237 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
238 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
239 struct hc_driver {
240 char description[24];
241
242 void (*irq) (struct usb_hcd *hcd, struct pt_regs *regs);
243 int flags;
244 #define HCD_MEMORY 0x0001
245 #define HCD_USB11 0x0010
246 #define HCD_USB2 0x0020
247
248 int (*reset) (struct usb_hcd *hcd);
249 int (*start) (struct usb_hcd *hcd);
250 int (*restart) (struct usb_hcd *hcd);
251
252 int (*suspend) (struct usb_hcd *hcd, U32 state);
253
254 int (*resume) (struct usb_hcd *hcd);
255
256 void (*stop) (struct usb_hcd *hcd);
257
258 int (*get_frame_number) (struct usb_hcd *hcd);
259
260 struct usb_hcd *(*hcd_alloc) (void);
261
262 void (*hcd_free) (struct usb_hcd *hcd);
263
264 int (*urb_enqueue) (struct usb_hcd *hcd, struct urb *urb,
265 int mem_flags);
266 int (*urb_dequeue) (struct usb_hcd *hcd, struct urb *urb);
267
268 void (*endpoint_disable)(struct usb_hcd *hcd,
269 struct hcd_dev *dev, int bEndpointAddress);
270
271 int (*hub_status_data) (struct usb_hcd *hcd, char *buf);
272 int (*hub_control) (struct usb_hcd *hcd,
273 U16 typeReq, U16 wValue, U16 wIndex,
274 char *buf, U16 wLength);
275 };
276
277 struct otg_driver {
278 char description[24]; /* "FOTG100_DRIVER" etc */
279
280 void (*irq) (struct usb_otgd *otgd, struct pt_regs *regs);
281
282 int flags;
283
284 int (*get_role_ID) (struct usb_otgd *otgd);
285 int (*get_cur_role) (struct usb_otgd *otgd);
286 void (*drop_Vbus) (struct usb_otgd *otgd);
287 void (*drive_Vbus) (struct usb_otgd *otgd);
288 int (*role_change) (struct usb_otgd *otgd);
289 int (*srp_section) (struct usb_otgd *otgd);
290 int (*hnp_section) (struct usb_otgd *otgd);
291
292 void (*start) (struct usb_otgd *otgd);
293
294 void (*stop) (struct usb_otgd *otgd);
295
296 struct usb_otgd *(*otgd_alloc) (void);
297 void (*otgd_free) (struct usb_otgd *otgd);
298 };
299
300 extern void usb_hcd_giveback_urb (struct usb_hcd *hcd, struct urb *urb, struct pt_regs *regs);
301 extern void usb_bus_init (struct usb_bus *bus);
302 extern void usb_rh_status_dequeue (struct usb_hcd *hcd, struct urb *urb);
303
304 #ifdef CONFIG_PCI
305 struct pci_dev;
306 struct pci_device_id;
307 extern int usb_hcd_pci_probe (struct pci_dev *dev,
308 const struct pci_device_id *id);
309 extern void usb_hcd_pci_remove (struct pci_dev *dev);
310
311 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
312 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
313 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
314 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
315 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
316 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
317 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
318 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
319 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
320 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
321 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
322 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
323 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
324 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
325 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
326 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
327 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
328 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
329 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
330 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
331 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
332 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
333 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
334 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
335 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
336 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
337 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
338 #ifdef CONFIG_PM
339 extern int usb_hcd_pci_suspend (struct pci_dev *dev, U32 state);
340 extern int usb_hcd_pci_resume (struct pci_dev *dev);
341 #endif /* CONFIG_PM */
342
343 #endif /* CONFIG_PCI */
344
345 int hcd_buffer_create (struct usb_hcd *hcd);
346 void hcd_buffer_destroy (struct usb_hcd *hcd);
347
348 void *hcd_buffer_alloc (struct usb_bus *bus, size_t size,
349 int mem_flags, dma_addr_t *dma);
350 void hcd_buffer_free (struct usb_bus *bus, size_t size,
351 void *addr, dma_addr_t dma);
352
353 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
354 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
355 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
356 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
357 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
358 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
359 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
360 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
361 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
362 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
363 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
364 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
365 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
366 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
367 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
368 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
369 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
370 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
371 extern struct usb_operations usb_hcd_operations;
372 extern irqreturn_t usb_hcd_irq (int irq, void *__hcd, struct pt_regs *r);
373 extern void usb_hc_died (struct usb_hcd *hcd);
374
375 extern int usb_new_device(struct usb_device *dev, struct device_s *parent);
376 extern void usb_choose_address(struct usb_device *dev);
377 extern void usb_disconnect(struct usb_device **);
378
379 extern int usb_get_configuration(struct usb_device *dev);
380 extern void usb_destroy_configuration(struct usb_device *dev);
381 extern int usb_set_address(struct usb_device *dev);
382 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
383 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
384 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
385 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
386 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
387 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
388 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
389 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
390 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
391
392 #define usb_snddefctrl(dev) (((U32)PIPE_CONTROL << 30))
393 #define usb_rcvdefctrl(dev) (((U32)PIPE_CONTROL << 30) | USB_DIR_IN)
394
395 #include "drvHUB.h"
396
397 #define DeviceRequest \
398 ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
399 #define DeviceOutRequest \
400 ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
401
402 #define InterfaceRequest \
403 ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
404
405 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
406 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
407 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
408 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
409 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
410 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
411 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
412 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
413 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
414 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
415 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
416 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
417 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
418 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
419 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
420 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
421 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
422 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
423 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
424 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
425 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
426 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
427 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
428 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
429 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
430 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
431 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
432 #define EndpointRequest \
433 ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
434 #define EndpointOutRequest \
435 ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
436
437 #define DEVICE_REMOTE_WAKEUP 1
438 #define ENDPOINT_HALT 0
439
440 #define ClearHubFeature (0x2000 | USB_REQ_CLEAR_FEATURE)
441 #define ClearPortFeature (0x2300 | USB_REQ_CLEAR_FEATURE)
442 #define GetHubDescriptor (0xa000 | USB_REQ_GET_DESCRIPTOR)
443 #define GetHubStatus (0xa000 | USB_REQ_GET_STATUS)
444 #define GetPortStatus (0xa300 | USB_REQ_GET_STATUS)
445 #define SetHubFeature (0x2000 | USB_REQ_SET_FEATURE)
446 #define SetPortFeature (0x2300 | USB_REQ_SET_FEATURE)
447 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
448 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
449 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
450 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
451 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
452 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
453 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
454 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
455 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
456 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
457 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
458 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
459 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
460 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
461 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
462 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
463 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
464 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
465
466
467 #define FRAME_TIME_USECS 1000L
468 #define BitTime(bytecount) (7 * 8 * bytecount / 6) /* with integer truncation */
469
470 #define NS_TO_US(ns) ((ns + 500L) / 1000L)
471
472 extern void usb_claim_bandwidth (struct usb_device *dev, struct urb *urb,
473 int bustime, int isoc);
474 extern void usb_release_bandwidth (struct usb_device *dev, struct urb *urb,
475 int isoc);
476
477 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
478 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
479 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
480 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
481 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
482 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
483 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
484 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
485 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
486 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
487 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
488 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
489 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
490 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
491 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
492 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
493 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
494 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
495 #define BW_HOST_DELAY 1000L /* nanoseconds */
496 #define BW_HUB_LS_SETUP 333L /* nanoseconds */
497
498 #define FRAME_TIME_BITS 12000L /* frame = 1 millisecond */
499 #define FRAME_TIME_MAX_BITS_ALLOC (90L * FRAME_TIME_BITS / 100L)
500 #define FRAME_TIME_MAX_USECS_ALLOC (90L * FRAME_TIME_USECS / 100L)
501
502 extern int usb_check_bandwidth (struct usb_device *dev, struct urb *urb);
503
504 #define USB2_HOST_DELAY 5 /* nsec, guess */
505 #define HS_USECS(bytes) NS_TO_US ( ((55 * 8 * 2083)/1000) \
506 + ((2083UL * (3167 + BitTime (bytes)))/1000) \
507 + USB2_HOST_DELAY)
508 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
509 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
510 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
511 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
512 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
513 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
514 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
515 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
516 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
517 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
518 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
519 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
520 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
521 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
522 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
523 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
524 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
525 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
526 #define HS_USECS_ISO(bytes) NS_TO_US ( ((long)(38 * 8 * 2.083)) \
527 + ((2083UL * (3167 + BitTime (bytes)))/1000) \
528 + USB2_HOST_DELAY)
529
530 extern int usb_calc_bus_time (int speed, int is_input,
531 int isoc, int bytecount);
532
533 /*-------------------------------------------------------------------------*/
534
535 extern struct usb_bus *usb_alloc_bus (struct usb_operations *);
536
537 extern int usb_register_bus (struct usb_bus *);
538 extern void usb_deregister_bus (struct usb_bus *);
539
540 extern int usb_register_root_hub (struct usb_device *usb_dev,
541 struct device_s *parent_dev);
542 extern int register_root_hub (struct usb_hcd *hcd);
543
544 extern int usb_register_otg_to_bus(struct usb_otgd *otgd, struct device *hc);
545 extern int usb_unregister_otg_from_bus(struct usb_otgd *otgd);
546
hcd_register_root(struct usb_hcd * hcd)547 static __inline__ int hcd_register_root (struct usb_hcd *hcd)
548 {
549 #ifdef ROOTHUB_INTERRUPT_MODE
550 return register_root_hub(hcd);
551 #else
552 return usb_register_root_hub (
553 hcd_to_bus (hcd)->root_hub, hcd->controller);
554 #endif
555 }
556
557 extern struct list_head usb_bus_list;
558
559 extern struct usb_bus *usb_bus_get (struct usb_bus *bus);
560 extern void usb_bus_put (struct usb_bus *bus);
561
562 extern int usb_find_interface_driver (struct usb_device *dev,
563 struct usb_interface *interface);
564
565 #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
566
567 #define usb_endpoint_out(ep_dir) (!((ep_dir) & USB_DIR_IN))
568
569 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
570 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
571 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
572 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
573 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
574 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
575 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
576 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
577 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
578 #ifdef CONFIG_USB_DEVICEFS
579
580 extern void usbfs_add_bus(struct usb_bus *bus);
581 extern void usbfs_remove_bus(struct usb_bus *bus);
582 extern void usbfs_add_device(struct usb_device *dev);
583 extern void usbfs_remove_device(struct usb_device *dev);
584 extern void usbfs_update_special (void);
585
586 extern int usbfs_init(void);
587 extern void usbfs_cleanup(void);
588
589 #else /* CONFIG_USB_DEVICEFS */
590
usbfs_add_bus(struct usb_bus * bus)591 static __inline__ void usbfs_add_bus(struct usb_bus *bus) {}
usbfs_remove_bus(struct usb_bus * bus)592 static __inline__ void usbfs_remove_bus(struct usb_bus *bus) {}
usbfs_add_device(struct usb_device * dev)593 static __inline__ void usbfs_add_device(struct usb_device *dev) {}
usbfs_remove_device(struct usb_device * dev)594 static __inline__ void usbfs_remove_device(struct usb_device *dev) {}
usbfs_update_special(void)595 static __inline__ void usbfs_update_special (void) {}
596
usbfs_init(void)597 static __inline__ int usbfs_init(void) { return 0; }
usbfs_cleanup(void)598 static __inline__ void usbfs_cleanup(void) { }
599
600 #endif /* CONFIG_USB_DEVICEFS */
601
602 #define bitmap DeviceRemovable
603
604
605 #define RUN_CONTEXT (in_irq () ? "in_irq" \
606 : (in_interrupt () ? "in_interrupt" : "can sleep"))
607
608
609 #endif
610