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