usb.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* USB core: device enumeration, descriptor parsing, hub recursion, bus
  2. scans and the hotplug watcher. Controller-specific work (transfers, root
  3. ports) goes through the usb_hcd_ops vtable (uhci.c / ohci.c). */
  4. #ifndef USB_H
  5. #define USB_H
  6. #include "usb_hcd.h"
  7. /* `lsusb` command: full scan, print the tree. */
  8. void usb_enumerate_and_print(void);
  9. /* Find + bring up a host controller; 0 when one is available. */
  10. int usb_hcd_init(void);
  11. const char *usb_hcd_name(void);
  12. /* Full bus scan: resets every connected root port, re-enumerates and calls
  13. the probe for each interface (probe may be NULL to print instead).
  14. Returns 0, -1 (no controller) or -2 (a scan is already running); every
  15. completed scan bumps the generation counter. */
  16. int usb_scan(usb_probe_fn probe);
  17. /* Cheap periodic watcher: enumerates devices on root ports whose connect
  18. state changed since the last call (internally throttled). Returns the
  19. number of ports with a new device. */
  20. int usb_hotplug_poll(usb_probe_fn probe);
  21. /* Incremented by every scan; consumers re-init when it changes. */
  22. unsigned int usb_generation(void);
  23. /* Root-port query (used to watch the port the mouse hangs off). */
  24. int usb_port_connected(unsigned int ctrl, unsigned int port);
  25. /* Control request helpers. rt is the raw bmRequestType (standard 0x80/0x00,
  26. class 0xA0/0x20, other 0xA3/0x23); the rest is the raw setup fields. */
  27. int usb_control_in(unsigned int ctrl, unsigned int addr, unsigned int mps,
  28. int low_speed, unsigned char rt, unsigned char req,
  29. unsigned short value, unsigned short index,
  30. unsigned char *buf, unsigned int len);
  31. int usb_control_out(unsigned int ctrl, unsigned int addr, unsigned int mps,
  32. int low_speed, unsigned char rt, unsigned char req,
  33. unsigned short value, unsigned short index);
  34. int usb_control_out_data(unsigned int ctrl, unsigned int addr,
  35. unsigned int mps, int low_speed, unsigned char rt,
  36. unsigned char req, unsigned short value,
  37. unsigned short index, const unsigned char *buf,
  38. unsigned int len);
  39. /* Bulk transfers: bulk_in is start-or-poll (see usb_hcd.h). */
  40. int usb_bulk_out(unsigned int ctrl, unsigned int addr, unsigned int ep,
  41. unsigned int mps, const unsigned char *buf,
  42. unsigned int len);
  43. int usb_bulk_in(unsigned int ctrl, unsigned int addr, unsigned int ep,
  44. unsigned int mps, unsigned char *buf, unsigned int len);
  45. /* Device-level probe for drivers that do not use HID interfaces (the
  46. * USB Ethernet driver parses the whole configuration itself). Return 1
  47. * when the device was claimed. Called for every non-hub device during a
  48. * scan, before the per-interface HID probe. */
  49. typedef int (*usb_device_probe_fn)(unsigned int ctrl, unsigned int addr,
  50. unsigned int mps, int low_speed,
  51. unsigned int port, unsigned int vendor,
  52. unsigned int product);
  53. void usb_register_device_probe(usb_device_probe_fn fn);
  54. /* Interrupt-IN endpoints (slots 0..USB_HCD_INT_SLOTS-1; usbhid assigns
  55. one per HID interface it claims). */
  56. int usb_int_in_start(unsigned int ctrl, unsigned int slot, unsigned int addr,
  57. unsigned int ep, unsigned int mps, int low_speed);
  58. int usb_int_in_poll(unsigned int slot, unsigned char *buf, unsigned int len);
  59. void usb_int_in_stop(unsigned int slot);
  60. #endif