blob: 7037efd33eb0c85dede846b5fd62dc6babf8d708 [file] [log] [blame]
wdenk232c1502004-03-12 00:14:09 +00001/*
2 * (C) Copyright 2003
3 * Gerry Hamel, geh@ti.com, Texas Instruments
4 *
5 * Based on linux/drivers/usbd/usbd.h
6 *
7 * Copyright (c) 2000, 2001, 2002 Lineo
8 * Copyright (c) 2001 Hewlett Packard
9 *
10 * By:
11 * Stuart Lynne <sl@lineo.com>,
12 * Tom Rushworth <tbr@lineo.com>,
13 * Bruce Balden <balden@lineo.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 *
29 */
30
31#ifndef __USBDCORE_H__
32#define __USBDCORE_H__
33
34#include <common.h>
35#include "usbdescriptors.h"
36
37
38#define MAX_URBS_QUEUED 5
39
40
41#if 1
42#define usberr(fmt,args...) serial_printf("ERROR: %s(), %d: "fmt"\n",__FUNCTION__,__LINE__,##args)
43#else
44#define usberr(fmt,args...) do{}while(0)
45#endif
46
47#if 0
48#define usbdbg(fmt,args...) serial_printf("debug: %s(), %d: "fmt"\n",__FUNCTION__,__LINE__,##args)
49#else
50#define usbdbg(fmt,args...) do{}while(0)
51#endif
52
53#if 0
54#define usbinfo(fmt,args...) serial_printf("info: %s(), %d: "fmt"\n",__FUNCTION__,__LINE__,##args)
55#else
56#define usbinfo(fmt,args...) do{}while(0)
57#endif
58
59#ifndef le16_to_cpu
60#define le16_to_cpu(x) (x)
61#endif
62
63#ifndef inb
64#define inb(p) (*(volatile u8*)(p))
65#endif
66
67#ifndef outb
68#define outb(val,p) (*(volatile u8*)(p) = (val))
69#endif
70
71#ifndef inw
72#define inw(p) (*(volatile u16*)(p))
73#endif
74
75#ifndef outw
76#define outw(val,p) (*(volatile u16*)(p) = (val))
77#endif
78
79#ifndef inl
80#define inl(p) (*(volatile u32*)(p))
81#endif
82
83#ifndef outl
84#define outl(val,p) (*(volatile u32*)(p) = (val))
85#endif
86
87#ifndef insw
88#define insw(p,to,len) mmio_insw(p,to,len)
89#endif
90
91#ifndef outsw
92#define outsw(p,from,len) mmio_outsw(p,from,len)
93#endif
94
95#ifndef insb
96#define insb(p,to,len) mmio_insb(p,to,len)
97#endif
98
99#ifndef mmio_insw
100#define mmio_insw(r,b,l) ({ int __i ; \
101 u16 *__b2; \
102 __b2 = (u16 *) b; \
103 for (__i = 0; __i < l; __i++) { \
104 *(__b2 + __i) = inw(r); \
105 }; \
106 })
107#endif
108
109#ifndef mmio_outsw
110#define mmio_outsw(r,b,l) ({ int __i; \
111 u16 *__b2; \
112 __b2 = (u16 *) b; \
113 for (__i = 0; __i < l; __i++) { \
114 outw( *(__b2 + __i), r); \
115 } \
116 })
117#endif
118
119#ifndef mmio_insb
120#define mmio_insb(r,b,l) ({ int __i ; \
121 u8 *__b2; \
122 __b2 = (u8 *) b; \
123 for (__i = 0; __i < l; __i++) { \
124 *(__b2 + __i) = inb(r); \
125 }; \
126 })
127#endif
128
wdenk232c1502004-03-12 00:14:09 +0000129/*
130 * Structure member address manipulation macros.
131 * These are used by client code (code using the urb_link routines), since
132 * the urb_link structure is embedded in the client data structures.
133 *
134 * Note: a macro offsetof equivalent to member_offset is defined in stddef.h
135 * but this is kept here for the sake of portability.
136 *
137 * p2surround returns a pointer to the surrounding structure given
138 * type of the surrounding structure, the name memb of the structure
139 * member pointed at by ptr. For example, if you have:
140 *
141 * struct foo {
142 * int x;
143 * float y;
144 * char z;
145 * } thingy;
146 *
147 * char *cp = &thingy.z;
148 *
149 * then
150 *
151 * &thingy == p2surround(struct foo, z, cp)
152 *
153 * Clear?
154 */
155#define _cv_(ptr) ((char*)(void*)(ptr))
156#define member_offset(type,memb) (_cv_(&(((type*)0)->memb))-(char*)0)
157#define p2surround(type,memb,ptr) ((type*)(void*)(_cv_(ptr)-member_offset(type,memb)))
158
159struct urb;
160
161struct usb_endpoint_instance;
162struct usb_interface_instance;
163struct usb_configuration_instance;
164struct usb_device_instance;
165struct usb_bus_instance;
166
167/*
168 * Device and/or Interface Class codes
169 */
170#define USB_CLASS_PER_INTERFACE 0 /* for DeviceClass */
171#define USB_CLASS_AUDIO 1
172#define USB_CLASS_COMM 2
173#define USB_CLASS_HID 3
174#define USB_CLASS_PHYSICAL 5
175#define USB_CLASS_PRINTER 7
176#define USB_CLASS_MASS_STORAGE 8
177#define USB_CLASS_HUB 9
178#define USB_CLASS_DATA 10
179#define USB_CLASS_APP_SPEC 0xfe
180#define USB_CLASS_VENDOR_SPEC 0xff
181
182/*
183 * USB types
184 */
185#define USB_TYPE_STANDARD (0x00 << 5)
186#define USB_TYPE_CLASS (0x01 << 5)
187#define USB_TYPE_VENDOR (0x02 << 5)
188#define USB_TYPE_RESERVED (0x03 << 5)
189
190/*
191 * USB recipients
192 */
193#define USB_RECIP_DEVICE 0x00
194#define USB_RECIP_INTERFACE 0x01
195#define USB_RECIP_ENDPOINT 0x02
196#define USB_RECIP_OTHER 0x03
197
198/*
199 * USB directions
200 */
201#define USB_DIR_OUT 0
202#define USB_DIR_IN 0x80
203
204/*
205 * Descriptor types
206 */
207#define USB_DT_DEVICE 0x01
208#define USB_DT_CONFIG 0x02
209#define USB_DT_STRING 0x03
210#define USB_DT_INTERFACE 0x04
211#define USB_DT_ENDPOINT 0x05
212
Vipin KUMARf9da0f82012-03-26 15:38:06 +0530213#if defined(CONFIG_USBD_HS)
214#define USB_DT_QUAL 0x06
215#endif
216
wdenk232c1502004-03-12 00:14:09 +0000217#define USB_DT_HID (USB_TYPE_CLASS | 0x01)
218#define USB_DT_REPORT (USB_TYPE_CLASS | 0x02)
219#define USB_DT_PHYSICAL (USB_TYPE_CLASS | 0x03)
220#define USB_DT_HUB (USB_TYPE_CLASS | 0x09)
221
222/*
223 * Descriptor sizes per descriptor type
224 */
225#define USB_DT_DEVICE_SIZE 18
226#define USB_DT_CONFIG_SIZE 9
227#define USB_DT_INTERFACE_SIZE 9
228#define USB_DT_ENDPOINT_SIZE 7
229#define USB_DT_ENDPOINT_AUDIO_SIZE 9 /* Audio extension */
230#define USB_DT_HUB_NONVAR_SIZE 7
231#define USB_DT_HID_SIZE 9
232
233/*
234 * Endpoints
235 */
236#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
237#define USB_ENDPOINT_DIR_MASK 0x80
238
239#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
240#define USB_ENDPOINT_XFER_CONTROL 0
241#define USB_ENDPOINT_XFER_ISOC 1
242#define USB_ENDPOINT_XFER_BULK 2
243#define USB_ENDPOINT_XFER_INT 3
244
245/*
246 * USB Packet IDs (PIDs)
247 */
248#define USB_PID_UNDEF_0 0xf0
249#define USB_PID_OUT 0xe1
250#define USB_PID_ACK 0xd2
251#define USB_PID_DATA0 0xc3
252#define USB_PID_PING 0xb4 /* USB 2.0 */
253#define USB_PID_SOF 0xa5
254#define USB_PID_NYET 0x96 /* USB 2.0 */
255#define USB_PID_DATA2 0x87 /* USB 2.0 */
256#define USB_PID_SPLIT 0x78 /* USB 2.0 */
257#define USB_PID_IN 0x69
258#define USB_PID_NAK 0x5a
259#define USB_PID_DATA1 0x4b
260#define USB_PID_PREAMBLE 0x3c /* Token mode */
261#define USB_PID_ERR 0x3c /* USB 2.0: handshake mode */
262#define USB_PID_SETUP 0x2d
263#define USB_PID_STALL 0x1e
264#define USB_PID_MDATA 0x0f /* USB 2.0 */
265
266/*
267 * Standard requests
268 */
269#define USB_REQ_GET_STATUS 0x00
270#define USB_REQ_CLEAR_FEATURE 0x01
271#define USB_REQ_SET_FEATURE 0x03
272#define USB_REQ_SET_ADDRESS 0x05
273#define USB_REQ_GET_DESCRIPTOR 0x06
274#define USB_REQ_SET_DESCRIPTOR 0x07
275#define USB_REQ_GET_CONFIGURATION 0x08
276#define USB_REQ_SET_CONFIGURATION 0x09
277#define USB_REQ_GET_INTERFACE 0x0A
278#define USB_REQ_SET_INTERFACE 0x0B
279#define USB_REQ_SYNCH_FRAME 0x0C
280
281#define USBD_DEVICE_REQUESTS(x) (((unsigned int)x <= USB_REQ_SYNCH_FRAME) ? usbd_device_requests[x] : "UNKNOWN")
282
283/*
284 * HID requests
285 */
286#define USB_REQ_GET_REPORT 0x01
287#define USB_REQ_GET_IDLE 0x02
288#define USB_REQ_GET_PROTOCOL 0x03
289#define USB_REQ_SET_REPORT 0x09
290#define USB_REQ_SET_IDLE 0x0A
291#define USB_REQ_SET_PROTOCOL 0x0B
292
293
294/*
295 * USB Spec Release number
296 */
297
Vipin KUMARf9da0f82012-03-26 15:38:06 +0530298#if defined(CONFIG_USBD_HS)
299#define USB_BCD_VERSION 0x0200
300#else
wdenk232c1502004-03-12 00:14:09 +0000301#define USB_BCD_VERSION 0x0110
Vipin KUMARf9da0f82012-03-26 15:38:06 +0530302#endif
wdenk232c1502004-03-12 00:14:09 +0000303
304
305/*
306 * Device Requests (c.f Table 9-2)
307 */
308
309#define USB_REQ_DIRECTION_MASK 0x80
310#define USB_REQ_TYPE_MASK 0x60
311#define USB_REQ_RECIPIENT_MASK 0x1f
312
313#define USB_REQ_DEVICE2HOST 0x80
314#define USB_REQ_HOST2DEVICE 0x00
315
316#define USB_REQ_TYPE_STANDARD 0x00
317#define USB_REQ_TYPE_CLASS 0x20
318#define USB_REQ_TYPE_VENDOR 0x40
319
320#define USB_REQ_RECIPIENT_DEVICE 0x00
321#define USB_REQ_RECIPIENT_INTERFACE 0x01
322#define USB_REQ_RECIPIENT_ENDPOINT 0x02
323#define USB_REQ_RECIPIENT_OTHER 0x03
324
325/*
326 * get status bits
327 */
328
329#define USB_STATUS_SELFPOWERED 0x01
330#define USB_STATUS_REMOTEWAKEUP 0x02
331
332#define USB_STATUS_HALT 0x01
333
334/*
335 * descriptor types
336 */
337
338#define USB_DESCRIPTOR_TYPE_DEVICE 0x01
339#define USB_DESCRIPTOR_TYPE_CONFIGURATION 0x02
340#define USB_DESCRIPTOR_TYPE_STRING 0x03
341#define USB_DESCRIPTOR_TYPE_INTERFACE 0x04
342#define USB_DESCRIPTOR_TYPE_ENDPOINT 0x05
343#define USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER 0x06
344#define USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION 0x07
345#define USB_DESCRIPTOR_TYPE_INTERFACE_POWER 0x08
346#define USB_DESCRIPTOR_TYPE_HID 0x21
347#define USB_DESCRIPTOR_TYPE_REPORT 0x22
348
349#define USBD_DEVICE_DESCRIPTORS(x) (((unsigned int)x <= USB_DESCRIPTOR_TYPE_INTERFACE_POWER) ? \
350 usbd_device_descriptors[x] : "UNKNOWN")
351
352/*
353 * standard feature selectors
354 */
355#define USB_ENDPOINT_HALT 0x00
356#define USB_DEVICE_REMOTE_WAKEUP 0x01
357#define USB_TEST_MODE 0x02
358
359
360/* USB Requests
361 *
362 */
363
364struct usb_device_request {
365 u8 bmRequestType;
366 u8 bRequest;
367 u16 wValue;
368 u16 wIndex;
369 u16 wLength;
370} __attribute__ ((packed));
371
372
373/* USB Status
374 *
375 */
376typedef enum urb_send_status {
377 SEND_IN_PROGRESS,
378 SEND_FINISHED_OK,
379 SEND_FINISHED_ERROR,
380 RECV_READY,
381 RECV_OK,
382 RECV_ERROR
383} urb_send_status_t;
384
385/*
386 * Device State (c.f USB Spec 2.0 Figure 9-1)
387 *
388 * What state the usb device is in.
389 *
390 * Note the state does not change if the device is suspended, we simply set a
391 * flag to show that it is suspended.
392 *
393 */
394typedef enum usb_device_state {
395 STATE_INIT, /* just initialized */
396 STATE_CREATED, /* just created */
397 STATE_ATTACHED, /* we are attached */
398 STATE_POWERED, /* we have seen power indication (electrical bus signal) */
399 STATE_DEFAULT, /* we been reset */
400 STATE_ADDRESSED, /* we have been addressed (in default configuration) */
401 STATE_CONFIGURED, /* we have seen a set configuration device command */
402 STATE_UNKNOWN, /* destroyed */
403} usb_device_state_t;
404
405#define USBD_DEVICE_STATE(x) (((unsigned int)x <= STATE_UNKNOWN) ? usbd_device_states[x] : "UNKNOWN")
406
407/*
408 * Device status
409 *
410 * Overall state
411 */
412typedef enum usb_device_status {
413 USBD_OPENING, /* we are currently opening */
414 USBD_OK, /* ok to use */
415 USBD_SUSPENDED, /* we are currently suspended */
416 USBD_CLOSING, /* we are currently closing */
417} usb_device_status_t;
418
419#define USBD_DEVICE_STATUS(x) (((unsigned int)x <= USBD_CLOSING) ? usbd_device_status[x] : "UNKNOWN")
420
421/*
422 * Device Events
423 *
424 * These are defined in the USB Spec (c.f USB Spec 2.0 Figure 9-1).
425 *
426 * There are additional events defined to handle some extra actions we need
427 * to have handled.
428 *
429 */
430typedef enum usb_device_event {
431
432 DEVICE_UNKNOWN, /* bi - unknown event */
433 DEVICE_INIT, /* bi - initialize */
434 DEVICE_CREATE, /* bi - */
435 DEVICE_HUB_CONFIGURED, /* bi - bus has been plugged int */
436 DEVICE_RESET, /* bi - hub has powered our port */
437
438 DEVICE_ADDRESS_ASSIGNED, /* ep0 - set address setup received */
439 DEVICE_CONFIGURED, /* ep0 - set configure setup received */
440 DEVICE_SET_INTERFACE, /* ep0 - set interface setup received */
441
442 DEVICE_SET_FEATURE, /* ep0 - set feature setup received */
443 DEVICE_CLEAR_FEATURE, /* ep0 - clear feature setup received */
444
445 DEVICE_DE_CONFIGURED, /* ep0 - set configure setup received for ?? */
446
447 DEVICE_BUS_INACTIVE, /* bi - bus in inactive (no SOF packets) */
448 DEVICE_BUS_ACTIVITY, /* bi - bus is active again */
449
450 DEVICE_POWER_INTERRUPTION, /* bi - hub has depowered our port */
451 DEVICE_HUB_RESET, /* bi - bus has been unplugged */
452 DEVICE_DESTROY, /* bi - device instance should be destroyed */
453
454 DEVICE_HOTPLUG, /* bi - a hotplug event has occured */
455
456 DEVICE_FUNCTION_PRIVATE, /* function - private */
457
458} usb_device_event_t;
459
460
461typedef struct urb_link {
462 struct urb_link *next;
463 struct urb_link *prev;
464} urb_link;
465
466/* USB Data structure - for passing data around.
467 *
468 * This is used for both sending and receiving data.
469 *
470 * The callback function is used to let the function driver know when
471 * transmitted data has been sent.
472 *
473 * The callback function is set by the alloc_recv function when an urb is
474 * allocated for receiving data for an endpoint and used to call the
475 * function driver to inform it that data has arrived.
476 */
477
Shiraz Hashimb2caefb2012-12-17 14:19:37 +0530478/* in linux we'd malloc this, but in u-boot we prefer static data */
479#define URB_BUF_SIZE 512
480
wdenk232c1502004-03-12 00:14:09 +0000481struct urb {
482
483 struct usb_endpoint_instance *endpoint;
484 struct usb_device_instance *device;
485
486 struct usb_device_request device_request; /* contents of received SETUP packet */
487
488 struct urb_link link; /* embedded struct for circular doubly linked list of urbs */
489
490 u8* buffer;
491 unsigned int buffer_length;
492 unsigned int actual_length;
493
494 urb_send_status_t status;
495 int data;
496
497 u16 buffer_data[URB_BUF_SIZE]; /* data received (OUT) or being sent (IN) */
498};
499
500/* Endpoint configuration
501 *
502 * Per endpoint configuration data. Used to track which function driver owns
503 * an endpoint.
504 *
505 */
506struct usb_endpoint_instance {
507 int endpoint_address; /* logical endpoint address */
508
509 /* control */
510 int status; /* halted */
511 int state; /* available for use by bus interface driver */
512
513 /* receive side */
514 struct urb_link rcv; /* received urbs */
515 struct urb_link rdy; /* empty urbs ready to receive */
516 struct urb *rcv_urb; /* active urb */
517 int rcv_attributes; /* copy of bmAttributes from endpoint descriptor */
518 int rcv_packetSize; /* maximum packet size from endpoint descriptor */
519 int rcv_transferSize; /* maximum transfer size from function driver */
520 int rcv_queue;
521
522 /* transmit side */
523 struct urb_link tx; /* urbs ready to transmit */
524 struct urb_link done; /* transmitted urbs */
525 struct urb *tx_urb; /* active urb */
526 int tx_attributes; /* copy of bmAttributes from endpoint descriptor */
527 int tx_packetSize; /* maximum packet size from endpoint descriptor */
528 int tx_transferSize; /* maximum transfer size from function driver */
529 int tx_queue;
530
531 int sent; /* data already sent */
532 int last; /* data sent in last packet XXX do we need this */
533};
534
535struct usb_alternate_instance {
536 struct usb_interface_descriptor *interface_descriptor;
537
538 int endpoints;
539 int *endpoint_transfersize_array;
540 struct usb_endpoint_descriptor **endpoints_descriptor_array;
541};
542
543struct usb_interface_instance {
544 int alternates;
545 struct usb_alternate_instance *alternates_instance_array;
546};
547
548struct usb_configuration_instance {
549 int interfaces;
550 struct usb_configuration_descriptor *configuration_descriptor;
551 struct usb_interface_instance *interface_instance_array;
552};
553
554
555/* USB Device Instance
556 *
557 * For each physical bus interface we create a logical device structure. This
558 * tracks all of the required state to track the USB HOST's view of the device.
559 *
560 * Keep track of the device configuration for a real physical bus interface,
561 * this includes the bus interface, multiple function drivers, the current
562 * configuration and the current state.
563 *
564 * This will show:
565 * the specific bus interface driver
566 * the default endpoint 0 driver
567 * the configured function driver
568 * device state
569 * device status
570 * endpoint list
571 */
572
573struct usb_device_instance {
574
575 /* generic */
576 char *name;
577 struct usb_device_descriptor *device_descriptor; /* per device descriptor */
Vipin KUMARf9da0f82012-03-26 15:38:06 +0530578#if defined(CONFIG_USBD_HS)
579 struct usb_qualifier_descriptor *qualifier_descriptor;
580#endif
wdenk232c1502004-03-12 00:14:09 +0000581
582 void (*event) (struct usb_device_instance *device, usb_device_event_t event, int data);
583
Wolfgang Denk16c8d5e2006-06-14 17:45:53 +0200584 /* Do cdc device specific control requests */
585 int (*cdc_recv_setup)(struct usb_device_request *request, struct urb *urb);
586
wdenk232c1502004-03-12 00:14:09 +0000587 /* bus interface */
588 struct usb_bus_instance *bus; /* which bus interface driver */
589
590 /* configuration descriptors */
591 int configurations;
592 struct usb_configuration_instance *configuration_instance_array;
593
594 /* device state */
595 usb_device_state_t device_state; /* current USB Device state */
596 usb_device_state_t device_previous_state; /* current USB Device state */
597
598 u8 address; /* current address (zero is default) */
599 u8 configuration; /* current show configuration (zero is default) */
600 u8 interface; /* current interface (zero is default) */
601 u8 alternate; /* alternate flag */
602
603 usb_device_status_t status; /* device status */
604
605 int urbs_queued; /* number of submitted urbs */
606
607 /* Shouldn't need to make this atomic, all we need is a change indicator */
608 unsigned long usbd_rxtx_timestamp;
609 unsigned long usbd_last_rxtx_timestamp;
610
611};
612
613/* Bus Interface configuration structure
614 *
615 * This is allocated for each configured instance of a bus interface driver.
616 *
617 * The privdata pointer may be used by the bus interface driver to store private
618 * per instance state information.
619 */
620struct usb_bus_instance {
621
622 struct usb_device_instance *device;
623 struct usb_endpoint_instance *endpoint_array; /* array of available configured endpoints */
624
625 int max_endpoints; /* maximimum number of rx enpoints */
626 unsigned char maxpacketsize;
627
628 unsigned int serial_number;
629 char *serial_number_str;
630 void *privdata; /* private data for the bus interface */
631
632};
633
634extern char *usbd_device_events[];
635extern char *usbd_device_states[];
636extern char *usbd_device_status[];
637extern char *usbd_device_requests[];
638extern char *usbd_device_descriptors[];
639
640void urb_link_init (urb_link * ul);
641void urb_detach (struct urb *urb);
642urb_link *first_urb_link (urb_link * hd);
643struct urb *first_urb (urb_link * hd);
644struct urb *first_urb_detached (urb_link * hd);
645void urb_append (urb_link * hd, struct urb *urb);
646
647struct urb *usbd_alloc_urb (struct usb_device_instance *device, struct usb_endpoint_instance *endpoint);
648void usbd_dealloc_urb (struct urb *urb);
649
650/*
651 * usbd_device_event is used by bus interface drivers to tell the higher layers that
652 * certain events have taken place.
653 */
654void usbd_device_event_irq (struct usb_device_instance *conf, usb_device_event_t, int);
655void usbd_device_event (struct usb_device_instance *conf, usb_device_event_t, int);
656
657/* descriptors
658 *
659 * Various ways of finding descriptors based on the current device and any
660 * possible configuration / interface / endpoint for it.
661 */
662struct usb_configuration_descriptor *usbd_device_configuration_descriptor (struct usb_device_instance *, int, int);
663struct usb_function_instance *usbd_device_function_instance (struct usb_device_instance *, unsigned int);
664struct usb_interface_instance *usbd_device_interface_instance (struct usb_device_instance *, int, int, int);
665struct usb_alternate_instance *usbd_device_alternate_instance (struct usb_device_instance *, int, int, int, int);
666struct usb_interface_descriptor *usbd_device_interface_descriptor (struct usb_device_instance *, int, int, int, int);
667struct usb_endpoint_descriptor *usbd_device_endpoint_descriptor_index (struct usb_device_instance *, int, int, int, int, int);
668struct usb_class_descriptor *usbd_device_class_descriptor_index (struct usb_device_instance *, int, int, int, int, int);
669struct usb_class_report_descriptor *usbd_device_class_report_descriptor_index( struct usb_device_instance *, int , int , int , int , int );
670struct usb_endpoint_descriptor *usbd_device_endpoint_descriptor (struct usb_device_instance *, int, int, int, int, int);
671int usbd_device_endpoint_transfersize (struct usb_device_instance *, int, int, int, int, int);
672struct usb_string_descriptor *usbd_get_string (u8);
Vipin KUMARf9da0f82012-03-26 15:38:06 +0530673struct usb_device_descriptor *usbd_device_device_descriptor(struct
674 usb_device_instance *, int);
wdenk232c1502004-03-12 00:14:09 +0000675
Vipin KUMARf9da0f82012-03-26 15:38:06 +0530676#if defined(CONFIG_USBD_HS)
677/*
678 * is_usbd_high_speed routine needs to be defined by specific gadget driver
679 * It returns TRUE if device enumerates at High speed
680 * Retuns FALSE otherwise
681 */
682int is_usbd_high_speed(void);
683#endif
wdenk232c1502004-03-12 00:14:09 +0000684int usbd_endpoint_halted (struct usb_device_instance *device, int endpoint);
685void usbd_rcv_complete(struct usb_endpoint_instance *endpoint, int len, int urb_bad);
686void usbd_tx_complete (struct usb_endpoint_instance *endpoint);
687
Tom Rix988365a2009-10-31 12:37:39 -0500688/* These are macros used in debugging */
689#ifdef DEBUG
690static inline void print_urb(struct urb *u)
691{
692 serial_printf("urb %p\n", (u));
693 serial_printf("\tendpoint %p\n", u->endpoint);
694 serial_printf("\tdevice %p\n", u->device);
695 serial_printf("\tbuffer %p\n", u->buffer);
696 serial_printf("\tbuffer_length %d\n", u->buffer_length);
697 serial_printf("\tactual_length %d\n", u->actual_length);
698 serial_printf("\tstatus %d\n", u->status);
699 serial_printf("\tdata %d\n", u->data);
700}
701
702static inline void print_usb_device_request(struct usb_device_request *r)
703{
704 serial_printf("usb request\n");
705 serial_printf("\tbmRequestType 0x%2.2x\n", r->bmRequestType);
706 if ((r->bmRequestType & USB_REQ_DIRECTION_MASK) == 0)
707 serial_printf("\t\tDirection : To device\n");
708 else
709 serial_printf("\t\tDirection : To host\n");
710 if ((r->bmRequestType & USB_TYPE_STANDARD) == USB_TYPE_STANDARD)
711 serial_printf("\t\tType : Standard\n");
712 if ((r->bmRequestType & USB_TYPE_CLASS) == USB_TYPE_CLASS)
713 serial_printf("\t\tType : Standard\n");
714 if ((r->bmRequestType & USB_TYPE_VENDOR) == USB_TYPE_VENDOR)
715 serial_printf("\t\tType : Standard\n");
716 if ((r->bmRequestType & USB_TYPE_RESERVED) == USB_TYPE_RESERVED)
717 serial_printf("\t\tType : Standard\n");
718 if ((r->bmRequestType & USB_REQ_RECIPIENT_MASK) ==
719 USB_REQ_RECIPIENT_DEVICE)
720 serial_printf("\t\tRecipient : Device\n");
721 if ((r->bmRequestType & USB_REQ_RECIPIENT_MASK) ==
722 USB_REQ_RECIPIENT_INTERFACE)
723 serial_printf("\t\tRecipient : Interface\n");
724 if ((r->bmRequestType & USB_REQ_RECIPIENT_MASK) ==
725 USB_REQ_RECIPIENT_ENDPOINT)
726 serial_printf("\t\tRecipient : Endpoint\n");
727 if ((r->bmRequestType & USB_REQ_RECIPIENT_MASK) ==
728 USB_REQ_RECIPIENT_OTHER)
729 serial_printf("\t\tRecipient : Other\n");
730 serial_printf("\tbRequest 0x%2.2x\n", r->bRequest);
731 if (r->bRequest == USB_REQ_GET_STATUS)
732 serial_printf("\t\tGET_STATUS\n");
733 else if (r->bRequest == USB_REQ_SET_ADDRESS)
734 serial_printf("\t\tSET_ADDRESS\n");
735 else if (r->bRequest == USB_REQ_SET_FEATURE)
736 serial_printf("\t\tSET_FEATURE\n");
737 else if (r->bRequest == USB_REQ_GET_DESCRIPTOR)
738 serial_printf("\t\tGET_DESCRIPTOR\n");
739 else if (r->bRequest == USB_REQ_SET_CONFIGURATION)
740 serial_printf("\t\tSET_CONFIGURATION\n");
741 else if (r->bRequest == USB_REQ_SET_INTERFACE)
742 serial_printf("\t\tUSB_REQ_SET_INTERFACE\n");
743 else
744 serial_printf("\tUNKNOWN %d\n", r->bRequest);
745 serial_printf("\twValue 0x%4.4x\n", r->wValue);
746 if (r->bRequest == USB_REQ_GET_DESCRIPTOR) {
747 switch (r->wValue >> 8) {
748 case USB_DESCRIPTOR_TYPE_DEVICE:
749 serial_printf("\tDEVICE\n");
750 break;
751 case USB_DESCRIPTOR_TYPE_CONFIGURATION:
752 serial_printf("\tCONFIGURATION\n");
753 break;
754 case USB_DESCRIPTOR_TYPE_STRING:
755 serial_printf("\tSTRING\n");
756 break;
757 case USB_DESCRIPTOR_TYPE_INTERFACE:
758 serial_printf("\tINTERFACE\n");
759 break;
760 case USB_DESCRIPTOR_TYPE_ENDPOINT:
761 serial_printf("\tENDPOINT\n");
762 break;
763 case USB_DESCRIPTOR_TYPE_DEVICE_QUALIFIER:
764 serial_printf("\tDEVICE_QUALIFIER\n");
765 break;
766 case USB_DESCRIPTOR_TYPE_OTHER_SPEED_CONFIGURATION:
767 serial_printf("\tOTHER_SPEED_CONFIGURATION\n");
768 break;
769 case USB_DESCRIPTOR_TYPE_INTERFACE_POWER:
770 serial_printf("\tINTERFACE_POWER\n");
771 break;
772 case USB_DESCRIPTOR_TYPE_HID:
773 serial_printf("\tHID\n");
774 break;
775 case USB_DESCRIPTOR_TYPE_REPORT:
776 serial_printf("\tREPORT\n");
777 break;
778 default:
779 serial_printf("\tUNKNOWN TYPE\n");
780 break;
781 }
782 }
783 serial_printf("\twIndex 0x%4.4x\n", r->wIndex);
784 serial_printf("\twLength 0x%4.4x\n", r->wLength);
785}
786#else
787/* stubs */
788#define print_urb(u)
789#define print_usb_device_request(r)
790#endif /* DEBUG */
wdenk232c1502004-03-12 00:14:09 +0000791#endif