usbdevice.h 22 KB

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