These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / include / ipxe / usbhid.h
1 #ifndef _IPXE_USBHID_H
2 #define _IPXE_USBHID_H
3
4 /** @file
5  *
6  * USB human interface devices (HID)
7  *
8  */
9
10 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11
12 #include <ipxe/usb.h>
13
14 /** Class code for human interface devices */
15 #define USB_CLASS_HID 3
16
17 /** Subclass code for boot devices */
18 #define USB_SUBCLASS_HID_BOOT 1
19
20 /** Set protocol */
21 #define USBHID_SET_PROTOCOL                                             \
22         ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
23           USB_REQUEST_TYPE ( 0x0b ) )
24
25 /** Boot protocol */
26 #define USBHID_PROTOCOL_BOOT 0
27
28 /** Report protocol */
29 #define USBHID_PROTOCOL_REPORT 1
30
31 /** Set idle time */
32 #define USBHID_SET_IDLE                                                 \
33         ( USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE |          \
34           USB_REQUEST_TYPE ( 0x0a ) )
35
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 /**
47  * Initialise USB human interface device
48  *
49  * @v hid               USB human interface device
50  * @v func              USB function
51  * @v in                Interrupt IN endpoint operations
52  * @v out               Interrupt OUT endpoint operations (or NULL)
53  */
54 static inline __attribute__ (( always_inline )) void
55 usbhid_init ( struct usb_hid *hid, struct usb_function *func,
56               struct usb_endpoint_driver_operations *in,
57               struct usb_endpoint_driver_operations *out ) {
58         struct usb_device *usb = func->usb;
59
60         hid->func = func;
61         usb_endpoint_init ( &hid->in, usb, in );
62         if ( out )
63                 usb_endpoint_init ( &hid->out, usb, out );
64 }
65
66 /**
67  * Set protocol
68  *
69  * @v usb               USB device
70  * @v interface         Interface number
71  * @v protocol          HID protocol
72  * @ret rc              Return status code
73  */
74 static inline __attribute__ (( always_inline )) int
75 usbhid_set_protocol ( struct usb_device *usb, unsigned int interface,
76                       unsigned int protocol ) {
77
78         return usb_control ( usb, USBHID_SET_PROTOCOL, protocol, interface,
79                              NULL, 0 );
80 }
81
82 /**
83  * Set idle time
84  *
85  * @v usb               USB device
86  * @v interface         Interface number
87  * @v report            Report ID
88  * @v duration          Duration (in 4ms units)
89  * @ret rc              Return status code
90  */
91 static inline __attribute__ (( always_inline )) int
92 usbhid_set_idle ( struct usb_device *usb, unsigned int interface,
93                   unsigned int report, unsigned int duration ) {
94
95         return usb_control ( usb, USBHID_SET_IDLE,
96                              ( ( duration << 8 ) | report ),
97                              interface, NULL, 0 );
98 }
99
100 extern int usbhid_open ( struct usb_hid *hid );
101 extern void usbhid_close ( struct usb_hid *hid );
102 extern int usbhid_refill ( struct usb_hid *hid );
103 extern int usbhid_describe ( struct usb_hid *hid,
104                              struct usb_configuration_descriptor *config );
105
106 #endif /* _IPXE_USBHID_H */