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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. #ifndef _IPXE_USBHID_H
  2. #define _IPXE_USBHID_H
  3. /** @file
  4. *
  5. * USB human interface devices (HID)
  6. *
  7. */
  8. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  9. #include <ipxe/usb.h>
  10. /** Class code for human interface devices */
  11. #define USB_CLASS_HID 3
  12. /** Subclass code for boot devices */
  13. #define USB_SUBCLASS_HID_BOOT 1
  14. /** Set protocol */
  15. #define USBHID_SET_PROTOCOL \
  16. ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  17. USB_REQUEST_TYPE ( 0x0b ) )
  18. /** Boot protocol */
  19. #define USBHID_PROTOCOL_BOOT 0
  20. /** Report protocol */
  21. #define USBHID_PROTOCOL_REPORT 1
  22. /** Set idle time */
  23. #define USBHID_SET_IDLE \
  24. ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  25. USB_REQUEST_TYPE ( 0x0a ) )
  26. /** Set report */
  27. #define USBHID_SET_REPORT \
  28. ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE | \
  29. USB_REQUEST_TYPE ( 0x09 ) )
  30. /** Input report type */
  31. #define USBHID_REPORT_INPUT 0x01
  32. /** Output report type */
  33. #define USBHID_REPORT_OUTPUT 0x02
  34. /** Feature report type */
  35. #define USBHID_REPORT_FEATURE 0x03
  36. /** A USB human interface device */
  37. struct usb_hid {
  38. /** USB function */
  39. struct usb_function *func;
  40. /** Interrupt IN endpoint */
  41. struct usb_endpoint in;
  42. /** Interrupt OUT endpoint (optional) */
  43. struct usb_endpoint out;
  44. };
  45. /**
  46. * Initialise USB human interface device
  47. *
  48. * @v hid USB human interface device
  49. * @v func USB function
  50. * @v in Interrupt IN endpoint operations
  51. * @v out Interrupt OUT endpoint operations (or NULL)
  52. */
  53. static inline __attribute__ (( always_inline )) void
  54. usbhid_init ( struct usb_hid *hid, struct usb_function *func,
  55. struct usb_endpoint_driver_operations *in,
  56. struct usb_endpoint_driver_operations *out ) {
  57. struct usb_device *usb = func->usb;
  58. hid->func = func;
  59. usb_endpoint_init ( &hid->in, usb, in );
  60. if ( out )
  61. usb_endpoint_init ( &hid->out, usb, out );
  62. }
  63. /**
  64. * Set protocol
  65. *
  66. * @v usb USB device
  67. * @v interface Interface number
  68. * @v protocol HID protocol
  69. * @ret rc Return status code
  70. */
  71. static inline __attribute__ (( always_inline )) int
  72. usbhid_set_protocol ( struct usb_device *usb, unsigned int interface,
  73. unsigned int protocol ) {
  74. return usb_control ( usb, USBHID_SET_PROTOCOL, protocol, interface,
  75. NULL, 0 );
  76. }
  77. /**
  78. * Set idle time
  79. *
  80. * @v usb USB device
  81. * @v interface Interface number
  82. * @v report Report ID
  83. * @v duration Duration (in 4ms units)
  84. * @ret rc Return status code
  85. */
  86. static inline __attribute__ (( always_inline )) int
  87. usbhid_set_idle ( struct usb_device *usb, unsigned int interface,
  88. unsigned int report, unsigned int duration ) {
  89. return usb_control ( usb, USBHID_SET_IDLE,
  90. ( ( duration << 8 ) | report ),
  91. interface, NULL, 0 );
  92. }
  93. /**
  94. * Set report
  95. *
  96. * @v usb USB device
  97. * @v interface Interface number
  98. * @v type Report type
  99. * @v report Report ID
  100. * @v data Report data
  101. * @v len Length of report data
  102. * @ret rc Return status code
  103. */
  104. static inline __attribute__ (( always_inline )) int
  105. usbhid_set_report ( struct usb_device *usb, unsigned int interface,
  106. unsigned int type, unsigned int report, void *data,
  107. size_t len ) {
  108. return usb_control ( usb, USBHID_SET_REPORT, ( ( type << 8 ) | report ),
  109. interface, data, len );
  110. }
  111. extern int usbhid_open ( struct usb_hid *hid );
  112. extern void usbhid_close ( struct usb_hid *hid );
  113. extern int usbhid_refill ( struct usb_hid *hid );
  114. extern int usbhid_describe ( struct usb_hid *hid,
  115. struct usb_configuration_descriptor *config );
  116. #endif /* _IPXE_USBHID_H */