gadgetfs.h 2.5 KB

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