usbdcore.h 19 KB

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