Firmware for MNT ZZ9000 graphics and ARM coprocessor card for Amiga computers.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

usb.h 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * (C) Copyright 2001
  4. * Denis Peter, MPL AG Switzerland
  5. *
  6. * Adapted for U-Boot driver model
  7. * (C) Copyright 2015 Google, Inc
  8. * Note: Part of this code has been derived from linux
  9. *
  10. */
  11. #ifndef _USB_H_
  12. #define _USB_H_
  13. // cache line = 32 bytes
  14. #define ARCH_DMA_MINALIGN 32
  15. #include "../platform.h"
  16. #include <xil_types.h>
  17. #include <stdbool.h>
  18. //#include <fdtdec.h>
  19. #include "usb_defs.h"
  20. #include <linux/usb/ch9.h>
  21. //#include <part.h>
  22. /*
  23. * The EHCI spec says that we must align to at least 32 bytes. However,
  24. * some platforms require larger alignment.
  25. */
  26. #if ARCH_DMA_MINALIGN > 32
  27. #define USB_DMA_MINALIGN ARCH_DMA_MINALIGN
  28. #else
  29. #define USB_DMA_MINALIGN 32
  30. #endif
  31. /* Everything is aribtrary */
  32. #define USB_ALTSETTINGALLOC 4
  33. #define USB_MAXALTSETTING 128 /* Hard limit */
  34. #define USB_MAX_DEVICE 32
  35. #define USB_MAXCONFIG 8
  36. #define USB_MAXINTERFACES 8
  37. #define USB_MAXENDPOINTS 16
  38. #define USB_MAXCHILDREN 8 /* This is arbitrary */
  39. #define USB_MAX_HUB 16
  40. #define USB_CNTL_TIMEOUT 100 /* 100ms timeout */
  41. /*
  42. * This is the timeout to allow for submitting an urb in ms. We allow more
  43. * time for a BULK device to react - some are slow.
  44. */
  45. #define USB_TIMEOUT_MS(pipe) (usb_pipebulk(pipe) ? 20000 : 4000) // FIXME quadrupled
  46. /* device request (setup) */
  47. struct devrequest {
  48. __u8 requesttype;
  49. __u8 request;
  50. __le16 value;
  51. __le16 index;
  52. __le16 length;
  53. } __attribute__ ((packed));
  54. /* Interface */
  55. struct usb_interface {
  56. struct usb_interface_descriptor desc;
  57. __u8 no_of_ep;
  58. __u8 num_altsetting;
  59. __u8 act_altsetting;
  60. struct usb_endpoint_descriptor ep_desc[USB_MAXENDPOINTS];
  61. /*
  62. * Super Speed Device will have Super Speed Endpoint
  63. * Companion Descriptor (section 9.6.7 of usb 3.0 spec)
  64. * Revision 1.0 June 6th 2011
  65. */
  66. struct usb_ss_ep_comp_descriptor ss_ep_comp_desc[USB_MAXENDPOINTS];
  67. } __attribute__ ((packed));
  68. /* Configuration information.. */
  69. struct usb_config {
  70. struct usb_config_descriptor desc;
  71. __u8 no_of_if; /* number of interfaces */
  72. struct usb_interface if_desc[USB_MAXINTERFACES];
  73. } __attribute__ ((packed));
  74. enum {
  75. /* Maximum packet size; encoded as 0,1,2,3 = 8,16,32,64 */
  76. PACKET_SIZE_8 = 0,
  77. PACKET_SIZE_16 = 1,
  78. PACKET_SIZE_32 = 2,
  79. PACKET_SIZE_64 = 3,
  80. };
  81. /**
  82. * struct usb_device - information about a USB device
  83. *
  84. * With driver model both UCLASS_USB (the USB controllers) and UCLASS_USB_HUB
  85. * (the hubs) have this as parent data. Hubs are children of controllers or
  86. * other hubs and there is always a single root hub for each controller.
  87. * Therefore struct usb_device can always be accessed with
  88. * dev_get_parent_priv(dev), where dev is a USB device.
  89. *
  90. * Pointers exist for obtaining both the device (could be any uclass) and
  91. * controller (UCLASS_USB) from this structure. The controller does not have
  92. * a struct usb_device since it is not a device.
  93. */
  94. struct usb_device {
  95. int devnum; /* Device number on USB bus */
  96. int speed; /* full/low/high */
  97. char mf[32]; /* manufacturer */
  98. char prod[32]; /* product */
  99. char serial[32]; /* serial number */
  100. /* Maximum packet size; one of: PACKET_SIZE_* */
  101. int maxpacketsize;
  102. /* one bit for each endpoint ([0] = IN, [1] = OUT) */
  103. unsigned int toggle[2];
  104. /* endpoint halts; one bit per endpoint # & direction;
  105. * [0] = IN, [1] = OUT
  106. */
  107. unsigned int halted[2];
  108. int epmaxpacketin[16]; /* INput endpoint specific maximums */
  109. int epmaxpacketout[16]; /* OUTput endpoint specific maximums */
  110. int configno; /* selected config number */
  111. /* Device Descriptor */
  112. struct usb_device_descriptor descriptor
  113. __attribute__((aligned(ARCH_DMA_MINALIGN)));
  114. struct usb_config config; /* config descriptor */
  115. int have_langid; /* whether string_langid is valid yet */
  116. int string_langid; /* language ID for strings */
  117. int (*irq_handle)(struct usb_device *dev);
  118. unsigned long irq_status;
  119. int irq_act_len; /* transferred bytes */
  120. void *privptr;
  121. /*
  122. * Child devices - if this is a hub device
  123. * Each instance needs its own set of data structures.
  124. */
  125. unsigned long status;
  126. unsigned long int_pending; /* 1 bit per ep, used by int_queue */
  127. int act_len; /* transferred bytes */
  128. int maxchild; /* Number of ports if hub */
  129. int portnr; /* Port number, 1=first */
  130. /* parent hub, or NULL if this is the root hub */
  131. struct usb_device *parent;
  132. struct usb_device *children[USB_MAXCHILDREN];
  133. void *controller; /* hardware controller private data */
  134. /* slot_id - for xHCI enabled devices */
  135. unsigned int slot_id;
  136. };
  137. struct int_queue;
  138. /*
  139. * You can initialize platform's USB host or device
  140. * ports by passing this enum as an argument to
  141. * board_usb_init().
  142. */
  143. enum usb_init_type {
  144. USB_INIT_HOST,
  145. USB_INIT_DEVICE
  146. };
  147. /**********************************************************************
  148. * this is how the lowlevel part communicate with the outer world
  149. */
  150. int usb_lowlevel_init(int index, enum usb_init_type init, void **controller);
  151. int usb_lowlevel_stop(int index);
  152. //int usb_reset_root_port(struct usb_device *dev);
  153. #define usb_reset_root_port(dev)
  154. int submit_bulk_msg(struct usb_device *dev, unsigned long pipe,
  155. void *buffer, int transfer_len);
  156. int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  157. int transfer_len, struct devrequest *setup);
  158. int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
  159. int transfer_len, int interval);
  160. #if defined CONFIG_USB_EHCI_HCD || defined CONFIG_USB_MUSB_HOST
  161. struct int_queue *create_int_queue(struct usb_device *dev, unsigned long pipe,
  162. int queuesize, int elementsize, void *buffer, int interval);
  163. int destroy_int_queue(struct usb_device *dev, struct int_queue *queue);
  164. void *poll_int_queue(struct usb_device *dev, struct int_queue *queue);
  165. #endif
  166. /* Defines */
  167. #define USB_UHCI_VEND_ID 0x8086
  168. #define USB_UHCI_DEV_ID 0x7112
  169. /*
  170. * PXA25x can only act as USB device. There are drivers
  171. * which works with USB CDC gadgets implementations.
  172. * Some of them have common routines which can be used
  173. * in boards init functions e.g. udc_disconnect() used for
  174. * forced device disconnection from host.
  175. */
  176. extern void udc_disconnect(void);
  177. /*
  178. * board-specific hardware initialization, called by
  179. * usb drivers and u-boot commands
  180. *
  181. * @param index USB controller number
  182. * @param init initializes controller as USB host or device
  183. */
  184. int board_usb_init(int index, enum usb_init_type init);
  185. /*
  186. * can be used to clean up after failed USB initialization attempt
  187. * vide: board_usb_init()
  188. *
  189. * @param index USB controller number for selective cleanup
  190. * @param init usb_init_type passed to board_usb_init()
  191. */
  192. int board_usb_cleanup(int index, enum usb_init_type init);
  193. #define USB_MAX_STOR_DEV 1
  194. int usb_stor_scan(int mode);
  195. int usb_stor_info(void);
  196. unsigned long usb_stor_read_direct(int dev_index, unsigned long blknr, unsigned long blkcnt, void *buffer);
  197. unsigned long usb_stor_write_direct(int dev_index, unsigned long blknr, unsigned long blkcnt, void *buffer);
  198. unsigned long usb_stor_get_capacity(int dev_index);
  199. #ifdef CONFIG_USB_HOST_ETHER
  200. #define USB_MAX_ETH_DEV 5
  201. int usb_host_eth_scan(int mode);
  202. #endif
  203. #ifdef CONFIG_USB_KEYBOARD
  204. int drv_usb_kbd_init(void);
  205. int usb_kbd_deregister(int force);
  206. #endif
  207. /* routines */
  208. int usb_init(void); /* initialize the USB Controller */
  209. int usb_stop(void); /* stop the USB Controller */
  210. int usb_detect_change(void); /* detect if a USB device has been (un)plugged */
  211. int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);
  212. int usb_set_idle(struct usb_device *dev, int ifnum, int duration,
  213. int report_id);
  214. int usb_control_msg(struct usb_device *dev, unsigned int pipe,
  215. unsigned char request, unsigned char requesttype,
  216. unsigned short value, unsigned short index,
  217. void *data, unsigned short size, int timeout);
  218. int usb_bulk_msg(struct usb_device *dev, unsigned int pipe,
  219. void *data, int len, int *actual_length, int timeout);
  220. int usb_int_msg(struct usb_device *dev, unsigned long pipe,
  221. void *buffer, int transfer_len, int interval);
  222. int usb_disable_asynch(int disable);
  223. int usb_maxpacket(struct usb_device *dev, unsigned long pipe);
  224. int usb_get_configuration_no(struct usb_device *dev, int cfgno,
  225. unsigned char *buffer, int length);
  226. int usb_get_configuration_len(struct usb_device *dev, int cfgno);
  227. int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,
  228. unsigned char id, void *buf, int size);
  229. int usb_get_class_descriptor(struct usb_device *dev, int ifnum,
  230. unsigned char type, unsigned char id, void *buf,
  231. int size);
  232. int usb_clear_halt(struct usb_device *dev, int pipe);
  233. int usb_string(struct usb_device *dev, int index, char *buf, size_t size);
  234. int usb_set_interface(struct usb_device *dev, int interface, int alternate);
  235. int usb_get_port_status(struct usb_device *dev, int port, void *data);
  236. /* big endian -> little endian conversion */
  237. /* some CPUs are already little endian e.g. the ARM920T */
  238. #define __swap_16(x) \
  239. ({ unsigned short x_ = (unsigned short)x; \
  240. (unsigned short)( \
  241. ((x_ & 0x00FFU) << 8) | ((x_ & 0xFF00U) >> 8)); \
  242. })
  243. #define __swap_32(x) \
  244. ({ unsigned long x_ = (unsigned long)x; \
  245. (unsigned long)( \
  246. ((x_ & 0x000000FFUL) << 24) | \
  247. ((x_ & 0x0000FF00UL) << 8) | \
  248. ((x_ & 0x00FF0000UL) >> 8) | \
  249. ((x_ & 0xFF000000UL) >> 24)); \
  250. })
  251. #ifdef __LITTLE_ENDIAN
  252. # define swap_16(x) (x)
  253. # define swap_32(x) (x)
  254. #else
  255. # define swap_16(x) __swap_16(x)
  256. # define swap_32(x) __swap_32(x)
  257. #endif
  258. /*
  259. * Calling this entity a "pipe" is glorifying it. A USB pipe
  260. * is something embarrassingly simple: it basically consists
  261. * of the following information:
  262. * - device number (7 bits)
  263. * - endpoint number (4 bits)
  264. * - current Data0/1 state (1 bit)
  265. * - direction (1 bit)
  266. * - speed (2 bits)
  267. * - max packet size (2 bits: 8, 16, 32 or 64)
  268. * - pipe type (2 bits: control, interrupt, bulk, isochronous)
  269. *
  270. * That's 18 bits. Really. Nothing more. And the USB people have
  271. * documented these eighteen bits as some kind of glorious
  272. * virtual data structure.
  273. *
  274. * Let's not fall in that trap. We'll just encode it as a simple
  275. * unsigned int. The encoding is:
  276. *
  277. * - max size: bits 0-1 (00 = 8, 01 = 16, 10 = 32, 11 = 64)
  278. * - direction: bit 7 (0 = Host-to-Device [Out],
  279. * (1 = Device-to-Host [In])
  280. * - device: bits 8-14
  281. * - endpoint: bits 15-18
  282. * - Data0/1: bit 19
  283. * - pipe type: bits 30-31 (00 = isochronous, 01 = interrupt,
  284. * 10 = control, 11 = bulk)
  285. *
  286. * Why? Because it's arbitrary, and whatever encoding we select is really
  287. * up to us. This one happens to share a lot of bit positions with the UHCI
  288. * specification, so that much of the uhci driver can just mask the bits
  289. * appropriately.
  290. */
  291. /* Create various pipes... */
  292. #define create_pipe(dev,endpoint) \
  293. (((dev)->devnum << 8) | ((endpoint) << 15) | \
  294. (dev)->maxpacketsize)
  295. #define default_pipe(dev) ((dev)->speed << 26)
  296. #define usb_sndctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \
  297. create_pipe(dev, endpoint))
  298. #define usb_rcvctrlpipe(dev, endpoint) ((PIPE_CONTROL << 30) | \
  299. create_pipe(dev, endpoint) | \
  300. USB_DIR_IN)
  301. #define usb_sndisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \
  302. create_pipe(dev, endpoint))
  303. #define usb_rcvisocpipe(dev, endpoint) ((PIPE_ISOCHRONOUS << 30) | \
  304. create_pipe(dev, endpoint) | \
  305. USB_DIR_IN)
  306. #define usb_sndbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \
  307. create_pipe(dev, endpoint))
  308. #define usb_rcvbulkpipe(dev, endpoint) ((PIPE_BULK << 30) | \
  309. create_pipe(dev, endpoint) | \
  310. USB_DIR_IN)
  311. #define usb_sndintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \
  312. create_pipe(dev, endpoint))
  313. #define usb_rcvintpipe(dev, endpoint) ((PIPE_INTERRUPT << 30) | \
  314. create_pipe(dev, endpoint) | \
  315. USB_DIR_IN)
  316. #define usb_snddefctrl(dev) ((PIPE_CONTROL << 30) | \
  317. default_pipe(dev))
  318. #define usb_rcvdefctrl(dev) ((PIPE_CONTROL << 30) | \
  319. default_pipe(dev) | \
  320. USB_DIR_IN)
  321. /* The D0/D1 toggle bits */
  322. #define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> ep) & 1)
  323. #define usb_dotoggle(dev, ep, out) ((dev)->toggle[out] ^= (1 << ep))
  324. #define usb_settoggle(dev, ep, out, bit) ((dev)->toggle[out] = \
  325. ((dev)->toggle[out] & \
  326. ~(1 << ep)) | ((bit) << ep))
  327. /* Endpoint halt control/status */
  328. #define usb_endpoint_out(ep_dir) (((ep_dir >> 7) & 1) ^ 1)
  329. #define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))
  330. #define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))
  331. #define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))
  332. #define usb_packetid(pipe) (((pipe) & USB_DIR_IN) ? USB_PID_IN : \
  333. USB_PID_OUT)
  334. #define usb_pipeout(pipe) ((((pipe) >> 7) & 1) ^ 1)
  335. #define usb_pipein(pipe) (((pipe) >> 7) & 1)
  336. #define usb_pipedevice(pipe) (((pipe) >> 8) & 0x7f)
  337. #define usb_pipe_endpdev(pipe) (((pipe) >> 8) & 0x7ff)
  338. #define usb_pipeendpoint(pipe) (((pipe) >> 15) & 0xf)
  339. #define usb_pipedata(pipe) (((pipe) >> 19) & 1)
  340. #define usb_pipetype(pipe) (((pipe) >> 30) & 3)
  341. #define usb_pipeisoc(pipe) (usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)
  342. #define usb_pipeint(pipe) (usb_pipetype((pipe)) == PIPE_INTERRUPT)
  343. #define usb_pipecontrol(pipe) (usb_pipetype((pipe)) == PIPE_CONTROL)
  344. #define usb_pipebulk(pipe) (usb_pipetype((pipe)) == PIPE_BULK)
  345. #define usb_pipe_ep_index(pipe) \
  346. usb_pipecontrol(pipe) ? (usb_pipeendpoint(pipe) * 2) : \
  347. ((usb_pipeendpoint(pipe) * 2) - \
  348. (usb_pipein(pipe) ? 0 : 1))
  349. /**
  350. * struct usb_device_id - identifies USB devices for probing and hotplugging
  351. * @match_flags: Bit mask controlling which of the other fields are used to
  352. * match against new devices. Any field except for driver_info may be
  353. * used, although some only make sense in conjunction with other fields.
  354. * This is usually set by a USB_DEVICE_*() macro, which sets all
  355. * other fields in this structure except for driver_info.
  356. * @idVendor: USB vendor ID for a device; numbers are assigned
  357. * by the USB forum to its members.
  358. * @idProduct: Vendor-assigned product ID.
  359. * @bcdDevice_lo: Low end of range of vendor-assigned product version numbers.
  360. * This is also used to identify individual product versions, for
  361. * a range consisting of a single device.
  362. * @bcdDevice_hi: High end of version number range. The range of product
  363. * versions is inclusive.
  364. * @bDeviceClass: Class of device; numbers are assigned
  365. * by the USB forum. Products may choose to implement classes,
  366. * or be vendor-specific. Device classes specify behavior of all
  367. * the interfaces on a device.
  368. * @bDeviceSubClass: Subclass of device; associated with bDeviceClass.
  369. * @bDeviceProtocol: Protocol of device; associated with bDeviceClass.
  370. * @bInterfaceClass: Class of interface; numbers are assigned
  371. * by the USB forum. Products may choose to implement classes,
  372. * or be vendor-specific. Interface classes specify behavior only
  373. * of a given interface; other interfaces may support other classes.
  374. * @bInterfaceSubClass: Subclass of interface; associated with bInterfaceClass.
  375. * @bInterfaceProtocol: Protocol of interface; associated with bInterfaceClass.
  376. * @bInterfaceNumber: Number of interface; composite devices may use
  377. * fixed interface numbers to differentiate between vendor-specific
  378. * interfaces.
  379. * @driver_info: Holds information used by the driver. Usually it holds
  380. * a pointer to a descriptor understood by the driver, or perhaps
  381. * device flags.
  382. *
  383. * In most cases, drivers will create a table of device IDs by using
  384. * USB_DEVICE(), or similar macros designed for that purpose.
  385. * They will then export it to userspace using MODULE_DEVICE_TABLE(),
  386. * and provide it to the USB core through their usb_driver structure.
  387. *
  388. * See the usb_match_id() function for information about how matches are
  389. * performed. Briefly, you will normally use one of several macros to help
  390. * construct these entries. Each entry you provide will either identify
  391. * one or more specific products, or will identify a class of products
  392. * which have agreed to behave the same. You should put the more specific
  393. * matches towards the beginning of your table, so that driver_info can
  394. * record quirks of specific products.
  395. */
  396. struct usb_device_id {
  397. /* which fields to match against? */
  398. u16 match_flags;
  399. /* Used for product specific matches; range is inclusive */
  400. u16 idVendor;
  401. u16 idProduct;
  402. u16 bcdDevice_lo;
  403. u16 bcdDevice_hi;
  404. /* Used for device class matches */
  405. u8 bDeviceClass;
  406. u8 bDeviceSubClass;
  407. u8 bDeviceProtocol;
  408. /* Used for interface class matches */
  409. u8 bInterfaceClass;
  410. u8 bInterfaceSubClass;
  411. u8 bInterfaceProtocol;
  412. /* Used for vendor-specific interface matches */
  413. u8 bInterfaceNumber;
  414. /* not matched against */
  415. unsigned long driver_info;
  416. };
  417. /* Some useful macros to use to create struct usb_device_id */
  418. #define USB_DEVICE_ID_MATCH_VENDOR 0x0001
  419. #define USB_DEVICE_ID_MATCH_PRODUCT 0x0002
  420. #define USB_DEVICE_ID_MATCH_DEV_LO 0x0004
  421. #define USB_DEVICE_ID_MATCH_DEV_HI 0x0008
  422. #define USB_DEVICE_ID_MATCH_DEV_CLASS 0x0010
  423. #define USB_DEVICE_ID_MATCH_DEV_SUBCLASS 0x0020
  424. #define USB_DEVICE_ID_MATCH_DEV_PROTOCOL 0x0040
  425. #define USB_DEVICE_ID_MATCH_INT_CLASS 0x0080
  426. #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
  427. #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
  428. #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
  429. /* Match anything, indicates this is a valid entry even if everything is 0 */
  430. #define USB_DEVICE_ID_MATCH_NONE 0x0800
  431. #define USB_DEVICE_ID_MATCH_ALL 0x07ff
  432. /**
  433. * struct usb_driver_entry - Matches a driver to its usb_device_ids
  434. * @driver: Driver to use
  435. * @match: List of match records for this driver, terminated by {}
  436. */
  437. struct usb_driver_entry {
  438. struct driver *driver;
  439. const struct usb_device_id *match;
  440. };
  441. #define USB_DEVICE_ID_MATCH_DEVICE \
  442. (USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT)
  443. /**
  444. * USB_DEVICE - macro used to describe a specific usb device
  445. * @vend: the 16 bit USB Vendor ID
  446. * @prod: the 16 bit USB Product ID
  447. *
  448. * This macro is used to create a struct usb_device_id that matches a
  449. * specific device.
  450. */
  451. #define USB_DEVICE(vend, prod) \
  452. .match_flags = USB_DEVICE_ID_MATCH_DEVICE, \
  453. .idVendor = (vend), \
  454. .idProduct = (prod)
  455. #define U_BOOT_USB_DEVICE(__name, __match) \
  456. ll_entry_declare(struct usb_driver_entry, __name, usb_driver_entry) = {\
  457. .driver = llsym(struct driver, __name, driver), \
  458. .match = __match, \
  459. }
  460. /*************************************************************************
  461. * Hub Stuff
  462. */
  463. struct usb_port_status {
  464. unsigned short wPortStatus;
  465. unsigned short wPortChange;
  466. } __attribute__ ((packed));
  467. struct usb_hub_status {
  468. unsigned short wHubStatus;
  469. unsigned short wHubChange;
  470. } __attribute__ ((packed));
  471. /*
  472. * Hub Device descriptor
  473. * USB Hub class device protocols
  474. */
  475. #define USB_HUB_PR_FS 0 /* Full speed hub */
  476. #define USB_HUB_PR_HS_NO_TT 0 /* Hi-speed hub without TT */
  477. #define USB_HUB_PR_HS_SINGLE_TT 1 /* Hi-speed hub with single TT */
  478. #define USB_HUB_PR_HS_MULTI_TT 2 /* Hi-speed hub with multiple TT */
  479. #define USB_HUB_PR_SS 3 /* Super speed hub */
  480. /* Transaction Translator Think Times, in bits */
  481. #define HUB_TTTT_8_BITS 0x00
  482. #define HUB_TTTT_16_BITS 0x20
  483. #define HUB_TTTT_24_BITS 0x40
  484. #define HUB_TTTT_32_BITS 0x60
  485. /* Hub descriptor */
  486. struct usb_hub_descriptor {
  487. unsigned char bLength;
  488. unsigned char bDescriptorType;
  489. unsigned char bNbrPorts;
  490. unsigned short wHubCharacteristics;
  491. unsigned char bPwrOn2PwrGood;
  492. unsigned char bHubContrCurrent;
  493. /* 2.0 and 3.0 hubs differ here */
  494. union {
  495. struct {
  496. /* add 1 bit for hub status change; round to bytes */
  497. __u8 DeviceRemovable[(USB_MAXCHILDREN + 1 + 7) / 8];
  498. __u8 PortPowerCtrlMask[(USB_MAXCHILDREN + 1 + 7) / 8];
  499. } __attribute__ ((packed)) hs;
  500. struct {
  501. __u8 bHubHdrDecLat;
  502. __le16 wHubDelay;
  503. __le16 DeviceRemovable;
  504. } __attribute__ ((packed)) ss;
  505. } u;
  506. } __attribute__ ((packed));
  507. struct usb_hub_device {
  508. struct usb_device *pusb_dev;
  509. struct usb_hub_descriptor desc;
  510. unsigned long connect_timeout; /* Device connection timeout in ms */
  511. unsigned long query_delay; /* Device query delay in ms */
  512. int overcurrent_count[USB_MAXCHILDREN]; /* Over-current counter */
  513. int hub_depth; /* USB 3.0 hub depth */
  514. struct usb_tt tt; /* Transaction Translator */
  515. };
  516. struct usb_device *usb_get_dev_index(int index);
  517. bool usb_device_has_child_on_port(struct usb_device *parent, int port);
  518. int usb_hub_probe(struct usb_device *dev, int ifnum);
  519. void usb_hub_reset(void);
  520. /*
  521. * usb_find_usb2_hub_address_port() - Get hub address and port for TT setting
  522. *
  523. * Searches for the first HS hub above the given device. If a
  524. * HS hub is found, the hub address and the port the device is
  525. * connected to is return, as required for SPLIT transactions
  526. *
  527. * @param: udev full speed or low speed device
  528. */
  529. void usb_find_usb2_hub_address_port(struct usb_device *udev,
  530. uint8_t *hub_address, uint8_t *hub_port);
  531. /**
  532. * usb_alloc_new_device() - Allocate a new device
  533. *
  534. * @devp: returns a pointer of a new device structure. With driver model this
  535. * is a device pointer, but with legacy USB this pointer is
  536. * driver-specific.
  537. * @return 0 if OK, -ENOSPC if we have found out of room for new devices
  538. */
  539. int usb_alloc_new_device(void *controller, struct usb_device **devp);
  540. /**
  541. * usb_free_device() - Free a partially-inited device
  542. *
  543. * This is an internal function. It is used to reverse the action of
  544. * usb_alloc_new_device() when we hit a problem during init.
  545. */
  546. void usb_free_device(void *controller);
  547. int usb_new_device(struct usb_device *dev);
  548. int usb_alloc_device(struct usb_device *dev);
  549. /**
  550. * usb_update_hub_device() - Update HCD's internal representation of hub
  551. *
  552. * After a hub descriptor is fetched, notify HCD so that its internal
  553. * representation of this hub can be updated.
  554. *
  555. * @dev: Hub device
  556. * @return 0 if OK, -ve on error
  557. */
  558. int usb_update_hub_device(struct usb_device *dev);
  559. /**
  560. * usb_get_max_xfer_size() - Get HCD's maximum transfer bytes
  561. *
  562. * The HCD may have limitation on the maximum bytes to be transferred
  563. * in a USB transfer. USB class driver needs to be aware of this.
  564. *
  565. * @dev: USB device
  566. * @size: maximum transfer bytes
  567. * @return 0 if OK, -ve on error
  568. */
  569. int usb_get_max_xfer_size(struct usb_device *dev, size_t *size);
  570. /**
  571. * usb_emul_setup_device() - Set up a new USB device emulation
  572. *
  573. * This is normally called when a new emulation device is bound. It tells
  574. * the USB emulation uclass about the features of the emulator.
  575. *
  576. * @dev: Emulation device
  577. * @strings: List of USB string descriptors, terminated by a NULL
  578. * entry
  579. * @desc_list: List of points or USB descriptors, terminated by NULL.
  580. * The first entry must be struct usb_device_descriptor,
  581. * and others follow on after that.
  582. * @return 0 if OK, -ENOSYS if not implemented, other -ve on error
  583. */
  584. //int usb_emul_setup_device(struct udevice *dev, struct usb_string *strings,
  585. // void **desc_list);
  586. /**
  587. * usb_emul_control() - Send a control packet to an emulator
  588. *
  589. * @emul: Emulator device
  590. * @udev: USB device (which the emulator is causing to appear)
  591. * See struct dm_usb_ops for details on other parameters
  592. * @return 0 if OK, -ve on error
  593. */
  594. //int usb_emul_control(struct udevice *emul, struct usb_device *udev,
  595. // unsigned long pipe, void *buffer, int length,
  596. // struct devrequest *setup);
  597. /**
  598. * usb_emul_bulk() - Send a bulk packet to an emulator
  599. *
  600. * @emul: Emulator device
  601. * @udev: USB device (which the emulator is causing to appear)
  602. * See struct dm_usb_ops for details on other parameters
  603. * @return 0 if OK, -ve on error
  604. */
  605. //int usb_emul_bulk(struct udevice *emul, struct usb_device *udev,
  606. // unsigned long pipe, void *buffer, int length);
  607. /**
  608. * usb_emul_int() - Send an interrupt packet to an emulator
  609. *
  610. * @emul: Emulator device
  611. * @udev: USB device (which the emulator is causing to appear)
  612. * See struct dm_usb_ops for details on other parameters
  613. * @return 0 if OK, -ve on error
  614. */
  615. //int usb_emul_int(struct udevice *emul, struct usb_device *udev,
  616. // unsigned long pipe, void *buffer, int length, int interval);
  617. /**
  618. * usb_emul_find() - Find an emulator for a particular device
  619. *
  620. * Check @pipe and @port1 to find a device number on bus @bus and return it.
  621. *
  622. * @bus: USB bus (controller)
  623. * @pipe: Describes pipe being used, and includes the device number
  624. * @port1: Describes port number on the parent hub
  625. * @emulp: Returns pointer to emulator, or NULL if not found
  626. * @return 0 if found, -ve on error
  627. */
  628. //int usb_emul_find(struct udevice *bus, unsigned long pipe, int port1,
  629. // struct udevice **emulp);
  630. /**
  631. * usb_emul_find_for_dev() - Find an emulator for a particular device
  632. *
  633. * @dev: USB device to check
  634. * @emulp: Returns pointer to emulator, or NULL if not found
  635. * @return 0 if found, -ve on error
  636. */
  637. //int usb_emul_find_for_dev(struct udevice *dev, struct udevice **emulp);
  638. /**
  639. * usb_emul_find_descriptor() - Find a USB descriptor of a particular device
  640. *
  641. * @ptr: a pointer to a list of USB descriptor pointers
  642. * @type: type of USB descriptor to find
  643. * @index: if @type is USB_DT_CONFIG, this is the configuration value
  644. * @return a pointer to the USB descriptor found, NULL if not found
  645. */
  646. struct usb_generic_descriptor **usb_emul_find_descriptor(
  647. struct usb_generic_descriptor **ptr, int type, int index);
  648. /**
  649. * usb_show_tree() - show the USB device tree
  650. *
  651. * This shows a list of active USB devices along with basic information about
  652. * each.
  653. */
  654. void usb_show_tree(void);
  655. struct usb_platdata {
  656. enum usb_init_type init_type;
  657. };
  658. #endif /*_USB_H_ */