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
80 #ifndef __LINUX_USB_H
81 #define __LINUX_USB_H
82
83 #define USB_MAJOR 180
84
85 #include "drvDevice.h"
86 #include "drvList.h"
87
88 #include "drvConfig.h"
89 #include "drvCompiler.h"
90 //#include "drvErrno.h"
91 #include "drvPorts.h"
92 #include "drvPCIMEM.h"
93
94 #include "drvUSB_CH9.h"
95 #include "drvTimer.h"
96 #include "drvCompletion.h"
97 #include "MsCommon.h"
98 #include "../drvUsbcommon.h"
99
100 struct usb_device;
101
102
103 struct usb_host_endpoint {
104 struct usb_endpoint_descriptor desc;
105
106 unsigned char *extra;
107 S32 extralen;
108 };
109
110 struct usb_host_interface {
111 struct usb_interface_descriptor desc;
112
113 struct usb_host_endpoint *endpoint;
114
115 unsigned char *extra;
116 S32 extralen;
117 };
118
119 struct usb_interface {
120 struct usb_host_interface *altsetting;
121
122 S32 act_altsetting;
123 S32 num_altsetting;
124 S32 max_altsetting;
125
126 struct usb_driver *driver;
127 S32 minor;
128 struct device_s dev;
129 };
130
usb_get_intfdata(struct usb_interface * intf)131 static __inline__ void *usb_get_intfdata (struct usb_interface *intf)
132 {
133 return dev_get_drvdata (&intf->dev);
134 }
135
usb_set_intfdata(struct usb_interface * intf,void * data)136 static __inline__ void usb_set_intfdata (struct usb_interface *intf, void *data)
137 {
138 dev_set_drvdata(&intf->dev, data);
139 }
140
141 #define USB_MAXINTERFACES 32
142
143 struct usb_host_config {
144 struct usb_config_descriptor desc;
145
146 struct usb_interface *interface[USB_MAXINTERFACES];
147
148 unsigned char *extra;
149 S32 extralen;
150 };
151
152 extern struct usb_endpoint_descriptor *
153 usb_epnum_to_ep_desc(struct usb_device *dev, U32 epnum);
154
155 int __usb_get_extra_descriptor(char *buffer, U32 size,
156 U8 type, void **ptr);
157
158 #define usb_get_extra_descriptor(ifpoint,type,ptr)\
159 __usb_get_extra_descriptor((ifpoint)->extra,(ifpoint)->extralen,\
160 type,(void**)ptr)
161
162 /* -------------------------------------------------------------------------- */
163
164 struct usb_operations;
165
166 struct usb_devmap {
167 U32 devicemap[128 / (8*sizeof(U32))];
168 };
169
170 struct usb_bus {
171 struct device_s *controller;
172 MS_S32 busnum;
173 char *bus_name;
174
175 S32 devnum_next;
176
177 struct usb_devmap devmap;
178 struct usb_operations *op;
179 struct usb_device *root_hub;
180 struct list_head bus_list;
181 void *hcpriv;
182 void *otgpriv;
183
184 S32 bandwidth_allocated;
185 S32 bandwidth_int_reqs;
186 S32 bandwidth_isoc_reqs;
187
188 void (*release)(struct usb_bus *bus);
189 };
190
191 //#define to_usb_bus(d) container_of(d, struct usb_bus, class_dev)
192
193 /*
194 static __inline struct usb_bus *to_usb_bus(struct class_device *d)
195 {
196 const struct usb_bus *__mptr = (d);
197 return (char *)__mptr - offsetof(struct usb_bus,dev);
198 }
199 */
200
201
202 #define USB_MAXCHILDREN (16)
203
204 struct usb_tt;
205
206 struct usb_device {
207 S32 devnum;
208 char devpath [16];
209 enum usb_device_state state;
210 enum usb_device_speed speed;
211
212 struct usb_tt *tt;
213 S32 ttport;
214
215 U32 toggle[2];
216 U32 halted[2];
217
218 S32 epmaxpacketin[16];
219 S32 epmaxpacketout[16];
220
221 struct usb_device *parent;
222 struct usb_bus *bus;
223
224 struct device_s dev;
225
226 struct usb_device_descriptor descriptor;
227 struct usb_host_config *config;
228 struct usb_host_config *actconfig;
229
230 char **rawdescriptors;
231
232 S32 have_langid;
233 S32 string_langid;
234
235 void *hcpriv;
236
237 struct list_head filelist;
238
239 char *product;
240 char *manufacturer;
241 char *serial;
242
243
244 S32 maxchild;
245 struct usb_device *children[USB_MAXCHILDREN];
246 };
247
248 //#define to_usb_device(d) container_of(d, struct usb_device, dev)
to_usb_device(struct device_s * d)249 static __inline__ struct usb_device *to_usb_device(struct device_s *d)
250 {
251 const struct usb_interface *__mptr = (struct usb_interface *)(d);
252 return (struct usb_device *)( (char *)__mptr - (char *)offsetof(struct usb_device,dev));
253
254 }
255 //#define to_usb_interface(d) container_of(d, struct usb_interface, dev)
to_usb_interface(struct device_s * d)256 static __inline__ struct usb_interface *to_usb_interface(struct device_s *d)
257 {
258 const struct usb_interface *__mptr = (struct usb_interface *)(d);
259 return (struct usb_interface *)((char *)__mptr - (char *)offsetof(struct usb_interface,dev));
260 }
261
interface_to_usbdev(struct usb_interface * ptr)262 static __inline__ struct usb_device *interface_to_usbdev(struct usb_interface *ptr)
263 {
264 const struct usb_device *__mptr = (struct usb_device *)(ptr->dev.parent);
265 return (struct usb_device *)((char *)__mptr - (char *)offsetof( struct usb_device, dev));
266 }
267
268 extern struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus);
269 extern struct usb_device *usb_get_dev(struct usb_device *dev);
270 extern void usb_put_dev(struct usb_device *dev);
271
272 extern int usb_reset_device(struct usb_device *dev);
273
274 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
275 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
276 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
277 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
278 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
279 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
280 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
281 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
282 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
283 extern struct usb_device *usb_find_device(U16 vendor_id, U16 product_id);
284
285 extern int usb_get_current_frame_number (struct usb_device *usb_dev);
286
287 extern S32 usb_driver_claim_interface(struct usb_driver *driver,
288 struct usb_interface *iface, void* priv);
289 extern S32 usb_interface_claimed(struct usb_interface *iface);
290 extern void usb_driver_release_interface(struct usb_driver *driver,
291 struct usb_interface *iface);
292 const struct usb_device_id *usb_match_id(struct usb_interface *interface,
293 const struct usb_device_id *id);
294
295 extern struct usb_interface *usb_find_interface(struct usb_driver *drv, int minor);
296 extern struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, int ifnum);
297 #if 0
298 static __inline__ S32 usb_make_path (struct usb_device *dev,char *buf, size_t size)
299 {
300 S32 actual;
301 actual = LIB_StringPrintFormatN(buf, size, "usb-%s-%s", dev->bus->bus_name, dev->devpath);
302 return ((size_t) actual >= size) ? -1 : actual;
303 }
304 #endif
305
306 /*-------------------------------------------------------------------------*/
307
308 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
309 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
310 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
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 #define USB_DEVICE_ID_MATCH_DEVICE (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
318 #define USB_DEVICE_ID_MATCH_DEV_RANGE (USB_DEVICE_ID_MATCH_DEV_LO | USB_DEVICE_ID_MATCH_DEV_HI)
319 #define USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION (USB_DEVICE_ID_MATCH_DEVICE | USB_DEVICE_ID_MATCH_DEV_RANGE)
320 #define USB_DEVICE_ID_MATCH_DEV_INFO \
321 (USB_DEVICE_ID_MATCH_DEV_CLASS | USB_DEVICE_ID_MATCH_DEV_SUBCLASS | USB_DEVICE_ID_MATCH_DEV_PROTOCOL)
322 #define USB_DEVICE_ID_MATCH_INT_INFO \
323 (USB_DEVICE_ID_MATCH_INT_CLASS | USB_DEVICE_ID_MATCH_INT_SUBCLASS | USB_DEVICE_ID_MATCH_INT_PROTOCOL)
324
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
335 #define USB_DEVICE(vend,prod) \
336 USB_DEVICE_ID_MATCH_DEVICE, vend, prod
337
338 #define USB_DEVICE_VER(vend,prod,lo,hi) \
339 .match_flags = USB_DEVICE_ID_MATCH_DEVICE_AND_VERSION, .idVendor = (vend), .idProduct = (prod), .bcdDevice_lo = (lo), .bcdDevice_hi = (hi)
340
341 #define USB_DEVICE_INFO(cl,sc,pr) \
342 USB_DEVICE_ID_MATCH_DEV_INFO,0,0,0,0,cl,sc,pr,0,0,0,0
343
344 #define USB_INTERFACE_INFO(cl,sc,pr) \
345 USB_DEVICE_ID_MATCH_INT_INFO,0,0,0,0,0,0,0,cl,sc,pr,0
346
347 struct usb_driver {
348 //struct module *owner;
349 void *module;
350
351 //const char *name;
352 char name[16];
353
354 int (*probe) (struct usb_interface *intf,
355 const struct usb_device_id *id);
356
357 void (*disconnect) (struct usb_interface *intf);
358
359 int (*ioctl) (struct usb_interface *intf, U32 code, void *buf);
360
361 const struct usb_device_id *id_table;
362
363 struct device_driver driver;
364
365 //struct file_operations *fops;
366 unsigned int minor_base;
367
368 //struct semaphore serialize;
369 };
370
371 //#define to_usb_driver(d) container_of(d, struct usb_driver, driver)
372
to_usb_driver(struct device_driver * dev_ptr)373 static __inline__ struct usb_driver *to_usb_driver(struct device_driver *dev_ptr)
374 {
375 const struct device_driver *__mptr = (dev_ptr);
376 return (struct usb_driver *)( (char *)__mptr - (char *)offsetof(struct usb_driver,driver) );
377 }
378
379 extern struct bus_type usb_bus_type;
380
381 struct usb_class_driver {
382 char name[BUS_ID_SIZE];
383 struct file_operations *fops;
384 //mode_t mode;
385 S32 minor_base;
386 };
387
388 extern int usb_register(struct usb_driver *);
389 extern void usb_deregister(struct usb_driver *);
390
391 extern S32 usb_register_dev(struct usb_interface *intf,
392 struct usb_class_driver *class_driver);
393 extern void usb_deregister_dev(struct usb_interface *intf,
394 struct usb_class_driver *class_driver);
395
396
397 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
398 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
399 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
400 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
401 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
402 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
403 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
404 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
405 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
406
407
408 extern MS_S32 usb_disabled(void);
409
410 #define URB_SHORT_NOT_OK 0x0001 /* report short reads as errors */
411 #define URB_ISO_ASAP 0x0002 /* iso-only, urb->start_frame ignored */
412 #define URB_NO_TRANSFER_DMA_MAP 0x0004 /* urb->transfer_dma valid on submit */
413 #define URB_NO_SETUP_DMA_MAP 0x0008 /* urb->setup_dma valid on submit */
414 #define URB_ASYNC_UNLINK 0x0010 /* usb_unlink_urb() returns asap */
415 #define URB_NO_FSBR 0x0020 /* UHCI-specific */
416 #define URB_ZERO_PACKET 0x0040 /* Finish bulk OUTs with short packet */
417 #define URB_NO_INTERRUPT 0x0080 /* HINT: no non-error interrupt needed */
418
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 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
433 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
434 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
435 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
436 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
437 struct usb_iso_packet_descriptor {
438 U32 offset;
439 U32 length; /* expected length */
440 U32 actual_length;
441 U32 status;
442 };
443
444 struct urb;
445 struct pt_regs;
446
447 typedef void (*usb_complete_t)(struct urb *, struct pt_regs *);
448
449 struct urb
450 {
451 spinlock_t lock;
452 atomic_t count;
453 void *hcpriv;
454 struct list_head urb_list;
455 S32 bandwidth;
456
457 struct usb_device *dev;
458 U32 pipe;
459 S32 status;
460 U32 transfer_flags;
461 void *transfer_buffer;
462 dma_addr_t transfer_dma;
463 S32 transfer_buffer_length;
464 S32 actual_length;
465 unsigned char *setup_packet;
466 dma_addr_t setup_dma;
467 S32 start_frame;
468 S32 number_of_packets;
469 S32 interval;
470 S32 error_count;
471 S32 timeout;
472 void *context;
473 usb_complete_t complete;
474 //__Test
475 void *SetDMABuf; //Note, for DMA
476 S32 SetDMALen;
477 void *TxDMABuf;
478 S32 TxDMALen;
479 struct list_head qtd_list; // Store qtds belong to this urb
480 struct completion urb_done; // completion for urb
481 struct timer_list to_timer; // timeout value for urb
482 //__Test
483 struct usb_iso_packet_descriptor iso_frame_desc[0]; /* (in) ISO ONLY */
484
485 S32 WaitFlag_storage; //added by jonas
486
487 };
488
usb_fill_control_urb(struct urb * urb,struct usb_device * dev,U32 pipe,unsigned char * setup_packet,void * transfer_buffer,S32 buffer_length,usb_complete_t complete,void * context)489 static __inline__ void usb_fill_control_urb (struct urb *urb,
490 struct usb_device *dev,
491 U32 pipe,
492 unsigned char *setup_packet,
493 void *transfer_buffer,
494 S32 buffer_length,
495 usb_complete_t complete,
496 void *context)
497 {
498 spin_lock_init(&urb->lock);
499 urb->dev = dev;
500 urb->pipe = pipe;
501 urb->setup_packet = setup_packet;
502 urb->transfer_buffer = transfer_buffer;
503 urb->transfer_buffer_length = buffer_length;
504 urb->complete = complete;
505 urb->context = context;
506 urb->SetDMABuf = NULL;
507 urb->SetDMALen = 0;
508 urb->TxDMABuf = NULL;
509 urb->TxDMALen = 0;
510 }
511
usb_fill_bulk_urb(struct urb * urb,struct usb_device * dev,U32 pipe,void * transfer_buffer,S32 buffer_length,usb_complete_t complete,void * context)512 static __inline__ void usb_fill_bulk_urb (struct urb *urb,
513 struct usb_device *dev,
514 U32 pipe,
515 void *transfer_buffer,
516 S32 buffer_length,
517 usb_complete_t complete,
518 void *context)
519 {
520 spin_lock_init(&urb->lock);
521 urb->dev = dev;
522 urb->pipe = pipe;
523 urb->transfer_buffer = transfer_buffer;
524 urb->transfer_buffer_length = buffer_length;
525 urb->complete = complete;
526 urb->context = context;
527 urb->SetDMABuf = NULL;
528 urb->SetDMALen = 0;
529 urb->TxDMABuf = NULL;
530 urb->TxDMALen = 0;
531 }
532
usb_fill_int_urb(struct urb * urb,struct usb_device * dev,U32 pipe,void * transfer_buffer,S32 buffer_length,usb_complete_t complete,void * context,S32 interval)533 static __inline__ void usb_fill_int_urb (struct urb *urb,
534 struct usb_device *dev,
535 U32 pipe,
536 void *transfer_buffer,
537 S32 buffer_length,
538 usb_complete_t complete,
539 void *context,
540 S32 interval)
541 {
542 spin_lock_init(&urb->lock);
543 urb->dev = dev;
544 urb->pipe = pipe;
545 urb->transfer_buffer = transfer_buffer;
546 urb->transfer_buffer_length = buffer_length;
547 urb->complete = complete;
548 urb->context = context;
549 if (dev->speed == USB_SPEED_HIGH)
550 urb->interval = 1 << (interval - 1);
551 else
552 urb->interval = interval;
553 urb->start_frame = -1;
554 urb->SetDMABuf = NULL;
555 urb->SetDMALen = 0;
556 urb->TxDMABuf = NULL;
557 urb->TxDMALen = 0;
558 }
559
560 extern void usb_init_urb(struct urb *urb);
561 extern struct urb *usb_alloc_urb(int iso_packets, int mem_flags);
562 extern void usb_free_urb(struct urb *urb);
563 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
564 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
565 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
566 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
567 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
568 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
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 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
579 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
580 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
581
582 #define usb_put_urb usb_free_urb
583 extern struct urb *usb_get_urb(struct urb *urb);
584 extern int usb_submit_urb(struct urb *urb, int mem_flags);
585 extern int usb_unlink_urb(struct urb *urb);
586
587 #define HAVE_USB_BUFFERS
588 void *usb_buffer_alloc (struct usb_device *dev, size_t size,
589 int mem_flags, dma_addr_t *dma);
590 void usb_buffer_free (struct usb_device *dev, size_t size,
591 void *addr, dma_addr_t dma);
592
593 struct urb *usb_buffer_map (struct urb *urb);
594 void usb_buffer_dmasync (struct urb *urb);
595 void usb_buffer_unmap (struct urb *urb);
596
597 struct scatterlist;
598 S32 usb_buffer_map_sg (struct usb_device *dev, U32 pipe,
599 struct scatterlist *sg, S32 nents);
600 void usb_buffer_dmasync_sg (struct usb_device *dev, U32 pipe,
601 struct scatterlist *sg, S32 n_hw_ents);
602 void usb_buffer_unmap_sg (struct usb_device *dev, U32 pipe,
603 struct scatterlist *sg, S32 n_hw_ents);
604
605
606 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
607 unsigned char request, unsigned char requesttype, unsigned short value, unsigned short index,
608 void *data, unsigned short size, int timeout);
609 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
610 void *data, int len, int *actual_length,
611 int timeout);
612
613
614 #define USB_CTRL_GET_TIMEOUT 5
615 #define USB_CTRL_SET_TIMEOUT 5
616
617 #define PIPE_ISOCHRONOUS 0
618 #define PIPE_INTERRUPT 1
619 #define PIPE_CONTROL 2
620 #define PIPE_BULK 3
621
622 #define usb_maxpacket(dev, pipe, out) (out \
623 ? (dev)->epmaxpacketout[usb_pipeendpoint(pipe)] \
624 : (dev)->epmaxpacketin [usb_pipeendpoint(pipe)] )
625
626 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
627 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
628 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
629 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
630 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
631 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
632 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
633 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
634 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
635 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
636 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
637 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
638 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
639 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
640 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
641 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
642 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
643 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
644 #define usb_pipein(pipe) ((pipe) & USB_DIR_IN)
645 #define usb_pipeout(pipe) (!usb_pipein(pipe))
646 #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
647 #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
648 #define usb_pipetype(pipe) (((pipe) >> 30) & 3)
649 #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
650 #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
651 #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
652 #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
653
654 #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
655 #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
656
657
__create_pipe(struct usb_device * dev,U32 endpoint)658 static __inline__ U32 __create_pipe(struct usb_device *dev, U32 endpoint)
659 {
660 return (dev->devnum << 8) | (endpoint << 15);
661 }
662
663 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
664 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
665 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
666 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
667 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
668 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
669 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
670 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
671 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
672 #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> (ep)) & 1)
673 #define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << (ep)))
674 #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = ((dev)->toggle[out] & ~(1 << (ep))) | ((bit) << (ep)))
675
676 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
677 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
678 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
679 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
680 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
681 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
682 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
683 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
684 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
685 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
686 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
687 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
688 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
689 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
690 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
691 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
692 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
693 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
694 #define usb_sndctrlpipe(dev,endpoint) (((U32)PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))
695 #define usb_rcvctrlpipe(dev,endpoint) (((U32)PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
696 #define usb_sndisocpipe(dev,endpoint) (((U32)PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))
697 #define usb_rcvisocpipe(dev,endpoint) (((U32)PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
698 #define usb_sndbulkpipe(dev,endpoint) (((U32)PIPE_BULK << 30) | __create_pipe(dev,endpoint))
699 #define usb_rcvbulkpipe(dev,endpoint) (((U32)PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
700 #define usb_sndintpipe(dev,endpoint) (((U32)PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))
701 #define usb_rcvintpipe(dev,endpoint) (((U32)PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)
702
703 extern int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,
704 unsigned char descindex, void *buf, int size);
705 extern int usb_get_device_descriptor(struct usb_device *dev);
706 extern int usb_get_status(struct usb_device *dev,
707 int type, int target, void *data);
708 extern int usb_get_string(struct usb_device *dev,
709 unsigned short langid, unsigned char index, void *buf, int size);
710 extern int usb_string(struct usb_device *dev, int index,
711 char *buf, size_t size);
712
713 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
714 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
715 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
716 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
717 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
718 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
719 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
720 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
721 /*USB HOST USB HOST USB HOST USB HOST USB HOST USB HOST*/
722 extern int usb_clear_halt(struct usb_device *dev, int pipe);
723 extern int usb_reset_configuration(struct usb_device *dev);
724 extern int usb_set_configuration(struct usb_device *dev, int configuration);
725 extern int usb_set_interface(struct usb_device *dev, int ifnum, int alternate);
726
727 void usb_show_device_descriptor(struct usb_device_descriptor *);
728 void usb_show_config_descriptor(struct usb_config_descriptor *);
729 void usb_show_interface_descriptor(struct usb_interface_descriptor *);
730 void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *);
731 void usb_show_device(struct usb_device *);
732 void usb_show_string(struct usb_device *dev, char *id, int index);
733
734 #ifdef DBG
735 #define dbg printk
736 #else
737 #define dbg(format, ...) do {} while (0)
738 #endif
739
740 #ifdef SHOW_MSG
741 #define usb_msg printk
742 #else
743 #define usb_msg(format,...) do {} while (0)
744 #endif
745
746
747 #ifdef VERBOSE_DEBUG
748 #define vdbg dbg
749 #else
750 #define vdbg(format, ...) do {} while (0)
751 #endif
752
753 #ifdef KERNEL_DEBUG
754 #define kdbg dbg
755 #else
756 #define kdbg(format, ...) do {} while (0)
757 #endif
758
759
760
761 #define usb_err(format, ...) printk(format, __VA_ARGS__)
762 #define usb_info(format, ...) printk(format, __VA_ARGS__)
763 #define usb_warn(format, ...) printk(format, __VA_ARGS__)
764
765
766 struct usb_otg_ap_operations {
767 void (*gadget_init)(void *);
768 S32 (*gadget_bh_init)(void);
769 S32 (*host_init)(void *,U32);
770 S32 (*host_bh_init)(void *);
771 S32 (*gadget_main) (void *,U8 ,U8 );
772 void (*host_main) (void);
773 S32 (*gadget_exit) (void *);
774 S32 (*gadget_bh_exit) (void);
775 S32 (*host_exit) (void *);
776 S32 (*host_bh_exit) (void *);
777 };
778
779 // Added by Peter Liao, 2003/09/08
780 extern int USB_core_lock;
781 extern int Timer_task_lock;
782
783 #ifdef CONFIG_OTG
784 extern BOOL gOPT_Device_attached;
Is_OPT_Dev_Attach()785 static __inline__ BOOL Is_OPT_Dev_Attach()
786 {
787 return gOPT_Device_attached;
788 }
789
Set_OPT_Dev_Attach()790 static __inline__ void Set_OPT_Dev_Attach()
791 {
792 gOPT_Device_attached = TRUE;
793 }
794
Set_OPT_Dev_Unattach()795 static __inline__ void Set_OPT_Dev_Unattach()
796 {
797 gOPT_Device_attached = FALSE;
798 }
799
800 #endif
801
802 #define USB_HOST_ROLE 0
803 #define USB_DEVICE_ROLE 1
804 //Used by power management related funciton (ex. suspend, wake up, etc.)
805 #define USB_PWM_SUSPEND 0
806 #define USB_OTG_SUSPEND 1
807
808 #define USB_STOR_STRING_LEN 32
809
810 extern S32 usb_role_change(void);
811 extern S32 usb_get_cur_role(void);
812 extern S32 usb_get_role_ID(void);
813 extern void usb_drop_Vbus(void);
814 extern void usb_drive_Vbus(void);
815 extern S32 usb_srp_section(void);
816 extern S32 usb_hnp_section(void);
817 #endif
818
819