usb_gadgetfs.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include <asm/types.h>
  2. #include <asm/ioctl.h>
  3. #include <linux/usb/ch9.h>
  4. /*
  5. * Filesystem based user-mode API to USB Gadget controller hardware
  6. *
  7. * Almost everything can be done with only read and write operations,
  8. * on endpoint files found in one directory. They are configured by
  9. * writing descriptors, and then may be used for normal stream style
  10. * i/o requests. When ep0 is configured, the device can enumerate;
  11. * when it's closed, the device disconnects from usb.
  12. *
  13. * Configuration and device descriptors get written to /dev/gadget/$CHIP,
  14. * which may then be used to read usb_gadgetfs_event structs. The driver
  15. * may activate endpoints as it handles SET_CONFIGURATION setup events,
  16. * or earlier; writing endpoint descriptors to /dev/gadget/$ENDPOINT
  17. * then performing data transfers by reading or writing.
  18. */
  19. /*
  20. * Events are delivered on the ep0 file descriptor, if the user mode driver
  21. * reads from this file descriptor after writing the descriptors. Don't
  22. * stop polling this descriptor, if you write that kind of driver.
  23. */
  24. enum usb_gadgetfs_event_type {
  25. GADGETFS_NOP = 0,
  26. GADGETFS_CONNECT,
  27. GADGETFS_DISCONNECT,
  28. GADGETFS_SETUP,
  29. GADGETFS_SUSPEND,
  30. // and likely more !
  31. };
  32. struct usb_gadgetfs_event {
  33. enum usb_gadgetfs_event_type type;
  34. union {
  35. // NOP, DISCONNECT, SUSPEND: nothing
  36. // ... some hardware can't report disconnection
  37. // CONNECT: just the speed
  38. enum usb_device_speed speed;
  39. // SETUP: packet; DATA phase i/o precedes next event
  40. // (setup.bmRequestType & USB_DIR_IN) flags direction
  41. // ... includes SET_CONFIGURATION, SET_INTERFACE
  42. struct usb_ctrlrequest setup;
  43. } u;
  44. };
  45. /* endpoint ioctls */
  46. /* IN transfers may be reported to the gadget driver as complete
  47. * when the fifo is loaded, before the host reads the data;
  48. * OUT transfers may be reported to the host's "client" driver as
  49. * complete when they're sitting in the FIFO unread.
  50. * THIS returns how many bytes are "unclaimed" in the endpoint fifo
  51. * (needed for precise fault handling, when the hardware allows it)
  52. */
  53. #define GADGETFS_FIFO_STATUS _IO('g',1)
  54. /* discards any unclaimed data in the fifo. */
  55. #define GADGETFS_FIFO_FLUSH _IO('g',2)
  56. /* resets endpoint halt+toggle; used to implement set_interface.
  57. * some hardware (like pxa2xx) can't support this.
  58. */
  59. #define GADGETFS_CLEAR_HALT _IO('g',3)