4 * Copyright (c) 2005 Fabrice Bellard
5 * Copyright (c) 2007 OpenMoko, Inc. (andrew@openedhand.com)
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
26 #include "ui/console.h"
28 #include "hw/usb/desc.h"
29 #include "qemu/timer.h"
30 #include "hw/input/hid.h"
32 /* HID interface requests */
33 #define GET_REPORT 0xa101
34 #define GET_IDLE 0xa102
35 #define GET_PROTOCOL 0xa103
36 #define SET_REPORT 0x2109
37 #define SET_IDLE 0x210a
38 #define SET_PROTOCOL 0x210b
40 /* HID descriptor types */
41 #define USB_DT_HID 0x21
42 #define USB_DT_REPORT 0x22
43 #define USB_DT_PHY 0x23
45 typedef struct USBHIDState
{
65 static const USBDescStrings desc_strings
= {
66 [STR_MANUFACTURER
] = "QEMU",
67 [STR_PRODUCT_MOUSE
] = "QEMU USB Mouse",
68 [STR_PRODUCT_TABLET
] = "QEMU USB Tablet",
69 [STR_PRODUCT_KEYBOARD
] = "QEMU USB Keyboard",
70 [STR_SERIALNUMBER
] = "42", /* == remote wakeup works */
71 [STR_CONFIG_MOUSE
] = "HID Mouse",
72 [STR_CONFIG_TABLET
] = "HID Tablet",
73 [STR_CONFIG_KEYBOARD
] = "HID Keyboard",
76 static const USBDescIface desc_iface_mouse
= {
77 .bInterfaceNumber
= 0,
79 .bInterfaceClass
= USB_CLASS_HID
,
80 .bInterfaceSubClass
= 0x01, /* boot */
81 .bInterfaceProtocol
= 0x02,
83 .descs
= (USBDescOther
[]) {
87 0x09, /* u8 bLength */
88 USB_DT_HID
, /* u8 bDescriptorType */
89 0x01, 0x00, /* u16 HID_class */
90 0x00, /* u8 country_code */
91 0x01, /* u8 num_descriptors */
92 USB_DT_REPORT
, /* u8 type: Report */
97 .eps
= (USBDescEndpoint
[]) {
99 .bEndpointAddress
= USB_DIR_IN
| 0x01,
100 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
107 static const USBDescIface desc_iface_tablet
= {
108 .bInterfaceNumber
= 0,
110 .bInterfaceClass
= USB_CLASS_HID
,
111 .bInterfaceProtocol
= 0x02,
113 .descs
= (USBDescOther
[]) {
116 .data
= (uint8_t[]) {
117 0x09, /* u8 bLength */
118 USB_DT_HID
, /* u8 bDescriptorType */
119 0x01, 0x00, /* u16 HID_class */
120 0x00, /* u8 country_code */
121 0x01, /* u8 num_descriptors */
122 USB_DT_REPORT
, /* u8 type: Report */
127 .eps
= (USBDescEndpoint
[]) {
129 .bEndpointAddress
= USB_DIR_IN
| 0x01,
130 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
137 static const USBDescIface desc_iface_tablet2
= {
138 .bInterfaceNumber
= 0,
140 .bInterfaceClass
= USB_CLASS_HID
,
141 .bInterfaceProtocol
= 0x02,
143 .descs
= (USBDescOther
[]) {
146 .data
= (uint8_t[]) {
147 0x09, /* u8 bLength */
148 USB_DT_HID
, /* u8 bDescriptorType */
149 0x01, 0x00, /* u16 HID_class */
150 0x00, /* u8 country_code */
151 0x01, /* u8 num_descriptors */
152 USB_DT_REPORT
, /* u8 type: Report */
157 .eps
= (USBDescEndpoint
[]) {
159 .bEndpointAddress
= USB_DIR_IN
| 0x01,
160 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
162 .bInterval
= 4, /* 2 ^ (4-1) * 125 usecs = 1 ms */
167 static const USBDescIface desc_iface_keyboard
= {
168 .bInterfaceNumber
= 0,
170 .bInterfaceClass
= USB_CLASS_HID
,
171 .bInterfaceSubClass
= 0x01, /* boot */
172 .bInterfaceProtocol
= 0x01, /* keyboard */
174 .descs
= (USBDescOther
[]) {
177 .data
= (uint8_t[]) {
178 0x09, /* u8 bLength */
179 USB_DT_HID
, /* u8 bDescriptorType */
180 0x11, 0x01, /* u16 HID_class */
181 0x00, /* u8 country_code */
182 0x01, /* u8 num_descriptors */
183 USB_DT_REPORT
, /* u8 type: Report */
184 0x3f, 0, /* u16 len */
188 .eps
= (USBDescEndpoint
[]) {
190 .bEndpointAddress
= USB_DIR_IN
| 0x01,
191 .bmAttributes
= USB_ENDPOINT_XFER_INT
,
198 static const USBDescDevice desc_device_mouse
= {
200 .bMaxPacketSize0
= 8,
201 .bNumConfigurations
= 1,
202 .confs
= (USBDescConfig
[]) {
205 .bConfigurationValue
= 1,
206 .iConfiguration
= STR_CONFIG_MOUSE
,
207 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
210 .ifs
= &desc_iface_mouse
,
215 static const USBDescDevice desc_device_tablet
= {
217 .bMaxPacketSize0
= 8,
218 .bNumConfigurations
= 1,
219 .confs
= (USBDescConfig
[]) {
222 .bConfigurationValue
= 1,
223 .iConfiguration
= STR_CONFIG_TABLET
,
224 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
227 .ifs
= &desc_iface_tablet
,
232 static const USBDescDevice desc_device_tablet2
= {
234 .bMaxPacketSize0
= 64,
235 .bNumConfigurations
= 1,
236 .confs
= (USBDescConfig
[]) {
239 .bConfigurationValue
= 1,
240 .iConfiguration
= STR_CONFIG_TABLET
,
241 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
244 .ifs
= &desc_iface_tablet2
,
249 static const USBDescDevice desc_device_keyboard
= {
251 .bMaxPacketSize0
= 8,
252 .bNumConfigurations
= 1,
253 .confs
= (USBDescConfig
[]) {
256 .bConfigurationValue
= 1,
257 .iConfiguration
= STR_CONFIG_KEYBOARD
,
258 .bmAttributes
= USB_CFG_ATT_ONE
| USB_CFG_ATT_WAKEUP
,
261 .ifs
= &desc_iface_keyboard
,
266 static const USBDescMSOS desc_msos_suspend
= {
267 .SelectiveSuspendEnabled
= true,
270 static const USBDesc desc_mouse
= {
275 .iManufacturer
= STR_MANUFACTURER
,
276 .iProduct
= STR_PRODUCT_MOUSE
,
277 .iSerialNumber
= STR_SERIALNUMBER
,
279 .full
= &desc_device_mouse
,
281 .msos
= &desc_msos_suspend
,
284 static const USBDesc desc_tablet
= {
289 .iManufacturer
= STR_MANUFACTURER
,
290 .iProduct
= STR_PRODUCT_TABLET
,
291 .iSerialNumber
= STR_SERIALNUMBER
,
293 .full
= &desc_device_tablet
,
295 .msos
= &desc_msos_suspend
,
298 static const USBDesc desc_tablet2
= {
303 .iManufacturer
= STR_MANUFACTURER
,
304 .iProduct
= STR_PRODUCT_TABLET
,
305 .iSerialNumber
= STR_SERIALNUMBER
,
307 .full
= &desc_device_tablet
,
308 .high
= &desc_device_tablet2
,
310 .msos
= &desc_msos_suspend
,
313 static const USBDesc desc_keyboard
= {
318 .iManufacturer
= STR_MANUFACTURER
,
319 .iProduct
= STR_PRODUCT_KEYBOARD
,
320 .iSerialNumber
= STR_SERIALNUMBER
,
322 .full
= &desc_device_keyboard
,
324 .msos
= &desc_msos_suspend
,
327 static const uint8_t qemu_mouse_hid_report_descriptor
[] = {
328 0x05, 0x01, /* Usage Page (Generic Desktop) */
329 0x09, 0x02, /* Usage (Mouse) */
330 0xa1, 0x01, /* Collection (Application) */
331 0x09, 0x01, /* Usage (Pointer) */
332 0xa1, 0x00, /* Collection (Physical) */
333 0x05, 0x09, /* Usage Page (Button) */
334 0x19, 0x01, /* Usage Minimum (1) */
335 0x29, 0x03, /* Usage Maximum (3) */
336 0x15, 0x00, /* Logical Minimum (0) */
337 0x25, 0x01, /* Logical Maximum (1) */
338 0x95, 0x03, /* Report Count (3) */
339 0x75, 0x01, /* Report Size (1) */
340 0x81, 0x02, /* Input (Data, Variable, Absolute) */
341 0x95, 0x01, /* Report Count (1) */
342 0x75, 0x05, /* Report Size (5) */
343 0x81, 0x01, /* Input (Constant) */
344 0x05, 0x01, /* Usage Page (Generic Desktop) */
345 0x09, 0x30, /* Usage (X) */
346 0x09, 0x31, /* Usage (Y) */
347 0x09, 0x38, /* Usage (Wheel) */
348 0x15, 0x81, /* Logical Minimum (-0x7f) */
349 0x25, 0x7f, /* Logical Maximum (0x7f) */
350 0x75, 0x08, /* Report Size (8) */
351 0x95, 0x03, /* Report Count (3) */
352 0x81, 0x06, /* Input (Data, Variable, Relative) */
353 0xc0, /* End Collection */
354 0xc0, /* End Collection */
357 static const uint8_t qemu_tablet_hid_report_descriptor
[] = {
358 0x05, 0x01, /* Usage Page (Generic Desktop) */
359 0x09, 0x01, /* Usage (Pointer) */
360 0xa1, 0x01, /* Collection (Application) */
361 0x09, 0x01, /* Usage (Pointer) */
362 0xa1, 0x00, /* Collection (Physical) */
363 0x05, 0x09, /* Usage Page (Button) */
364 0x19, 0x01, /* Usage Minimum (1) */
365 0x29, 0x03, /* Usage Maximum (3) */
366 0x15, 0x00, /* Logical Minimum (0) */
367 0x25, 0x01, /* Logical Maximum (1) */
368 0x95, 0x03, /* Report Count (3) */
369 0x75, 0x01, /* Report Size (1) */
370 0x81, 0x02, /* Input (Data, Variable, Absolute) */
371 0x95, 0x01, /* Report Count (1) */
372 0x75, 0x05, /* Report Size (5) */
373 0x81, 0x01, /* Input (Constant) */
374 0x05, 0x01, /* Usage Page (Generic Desktop) */
375 0x09, 0x30, /* Usage (X) */
376 0x09, 0x31, /* Usage (Y) */
377 0x15, 0x00, /* Logical Minimum (0) */
378 0x26, 0xff, 0x7f, /* Logical Maximum (0x7fff) */
379 0x35, 0x00, /* Physical Minimum (0) */
380 0x46, 0xff, 0x7f, /* Physical Maximum (0x7fff) */
381 0x75, 0x10, /* Report Size (16) */
382 0x95, 0x02, /* Report Count (2) */
383 0x81, 0x02, /* Input (Data, Variable, Absolute) */
384 0x05, 0x01, /* Usage Page (Generic Desktop) */
385 0x09, 0x38, /* Usage (Wheel) */
386 0x15, 0x81, /* Logical Minimum (-0x7f) */
387 0x25, 0x7f, /* Logical Maximum (0x7f) */
388 0x35, 0x00, /* Physical Minimum (same as logical) */
389 0x45, 0x00, /* Physical Maximum (same as logical) */
390 0x75, 0x08, /* Report Size (8) */
391 0x95, 0x01, /* Report Count (1) */
392 0x81, 0x06, /* Input (Data, Variable, Relative) */
393 0xc0, /* End Collection */
394 0xc0, /* End Collection */
397 static const uint8_t qemu_keyboard_hid_report_descriptor
[] = {
398 0x05, 0x01, /* Usage Page (Generic Desktop) */
399 0x09, 0x06, /* Usage (Keyboard) */
400 0xa1, 0x01, /* Collection (Application) */
401 0x75, 0x01, /* Report Size (1) */
402 0x95, 0x08, /* Report Count (8) */
403 0x05, 0x07, /* Usage Page (Key Codes) */
404 0x19, 0xe0, /* Usage Minimum (224) */
405 0x29, 0xe7, /* Usage Maximum (231) */
406 0x15, 0x00, /* Logical Minimum (0) */
407 0x25, 0x01, /* Logical Maximum (1) */
408 0x81, 0x02, /* Input (Data, Variable, Absolute) */
409 0x95, 0x01, /* Report Count (1) */
410 0x75, 0x08, /* Report Size (8) */
411 0x81, 0x01, /* Input (Constant) */
412 0x95, 0x05, /* Report Count (5) */
413 0x75, 0x01, /* Report Size (1) */
414 0x05, 0x08, /* Usage Page (LEDs) */
415 0x19, 0x01, /* Usage Minimum (1) */
416 0x29, 0x05, /* Usage Maximum (5) */
417 0x91, 0x02, /* Output (Data, Variable, Absolute) */
418 0x95, 0x01, /* Report Count (1) */
419 0x75, 0x03, /* Report Size (3) */
420 0x91, 0x01, /* Output (Constant) */
421 0x95, 0x06, /* Report Count (6) */
422 0x75, 0x08, /* Report Size (8) */
423 0x15, 0x00, /* Logical Minimum (0) */
424 0x25, 0xff, /* Logical Maximum (255) */
425 0x05, 0x07, /* Usage Page (Key Codes) */
426 0x19, 0x00, /* Usage Minimum (0) */
427 0x29, 0xff, /* Usage Maximum (255) */
428 0x81, 0x00, /* Input (Data, Array) */
429 0xc0, /* End Collection */
432 static void usb_hid_changed(HIDState
*hs
)
434 USBHIDState
*us
= container_of(hs
, USBHIDState
, hid
);
436 usb_wakeup(us
->intr
, 0);
439 static void usb_hid_handle_reset(USBDevice
*dev
)
441 USBHIDState
*us
= DO_UPCAST(USBHIDState
, dev
, dev
);
446 static void usb_hid_handle_control(USBDevice
*dev
, USBPacket
*p
,
447 int request
, int value
, int index
, int length
, uint8_t *data
)
449 USBHIDState
*us
= DO_UPCAST(USBHIDState
, dev
, dev
);
450 HIDState
*hs
= &us
->hid
;
453 ret
= usb_desc_handle_control(dev
, p
, request
, value
, index
, length
, data
);
459 /* hid specific requests */
460 case InterfaceRequest
| USB_REQ_GET_DESCRIPTOR
:
461 switch (value
>> 8) {
463 if (hs
->kind
== HID_MOUSE
) {
464 memcpy(data
, qemu_mouse_hid_report_descriptor
,
465 sizeof(qemu_mouse_hid_report_descriptor
));
466 p
->actual_length
= sizeof(qemu_mouse_hid_report_descriptor
);
467 } else if (hs
->kind
== HID_TABLET
) {
468 memcpy(data
, qemu_tablet_hid_report_descriptor
,
469 sizeof(qemu_tablet_hid_report_descriptor
));
470 p
->actual_length
= sizeof(qemu_tablet_hid_report_descriptor
);
471 } else if (hs
->kind
== HID_KEYBOARD
) {
472 memcpy(data
, qemu_keyboard_hid_report_descriptor
,
473 sizeof(qemu_keyboard_hid_report_descriptor
));
474 p
->actual_length
= sizeof(qemu_keyboard_hid_report_descriptor
);
482 if (hs
->kind
== HID_MOUSE
|| hs
->kind
== HID_TABLET
) {
483 p
->actual_length
= hid_pointer_poll(hs
, data
, length
);
484 } else if (hs
->kind
== HID_KEYBOARD
) {
485 p
->actual_length
= hid_keyboard_poll(hs
, data
, length
);
489 if (hs
->kind
== HID_KEYBOARD
) {
490 p
->actual_length
= hid_keyboard_write(hs
, data
, length
);
496 if (hs
->kind
!= HID_KEYBOARD
&& hs
->kind
!= HID_MOUSE
) {
499 data
[0] = hs
->protocol
;
500 p
->actual_length
= 1;
503 if (hs
->kind
!= HID_KEYBOARD
&& hs
->kind
!= HID_MOUSE
) {
506 hs
->protocol
= value
;
510 p
->actual_length
= 1;
513 hs
->idle
= (uint8_t) (value
>> 8);
514 hid_set_next_idle(hs
);
515 if (hs
->kind
== HID_MOUSE
|| hs
->kind
== HID_TABLET
) {
516 hid_pointer_activate(hs
);
521 p
->status
= USB_RET_STALL
;
526 static void usb_hid_handle_data(USBDevice
*dev
, USBPacket
*p
)
528 USBHIDState
*us
= DO_UPCAST(USBHIDState
, dev
, dev
);
529 HIDState
*hs
= &us
->hid
;
530 uint8_t buf
[p
->iov
.size
];
535 if (p
->ep
->nr
== 1) {
536 if (hs
->kind
== HID_MOUSE
|| hs
->kind
== HID_TABLET
) {
537 hid_pointer_activate(hs
);
539 if (!hid_has_events(hs
)) {
540 p
->status
= USB_RET_NAK
;
543 hid_set_next_idle(hs
);
544 if (hs
->kind
== HID_MOUSE
|| hs
->kind
== HID_TABLET
) {
545 len
= hid_pointer_poll(hs
, buf
, p
->iov
.size
);
546 } else if (hs
->kind
== HID_KEYBOARD
) {
547 len
= hid_keyboard_poll(hs
, buf
, p
->iov
.size
);
549 usb_packet_copy(p
, buf
, len
);
557 p
->status
= USB_RET_STALL
;
562 static void usb_hid_handle_destroy(USBDevice
*dev
)
564 USBHIDState
*us
= DO_UPCAST(USBHIDState
, dev
, dev
);
569 static void usb_hid_initfn(USBDevice
*dev
, int kind
)
571 USBHIDState
*us
= DO_UPCAST(USBHIDState
, dev
, dev
);
574 usb_desc_set_string(dev
, STR_SERIALNUMBER
, dev
->serial
);
577 us
->intr
= usb_ep_get(dev
, USB_TOKEN_IN
, 1);
578 hid_init(&us
->hid
, kind
, usb_hid_changed
);
579 if (us
->display
&& us
->hid
.s
) {
580 qemu_input_handler_bind(us
->hid
.s
, us
->display
, us
->head
, NULL
);
584 static void usb_tablet_realize(USBDevice
*dev
, Error
**errp
)
586 USBHIDState
*us
= DO_UPCAST(USBHIDState
, dev
, dev
);
588 switch (us
->usb_version
) {
590 dev
->usb_desc
= &desc_tablet
;
593 dev
->usb_desc
= &desc_tablet2
;
596 error_setg(errp
, "Invalid usb version %d for usb-tablet "
597 "(must be 1 or 2)", us
->usb_version
);
601 usb_hid_initfn(dev
, HID_TABLET
);
604 static void usb_mouse_realize(USBDevice
*dev
, Error
**errp
)
606 usb_hid_initfn(dev
, HID_MOUSE
);
609 static void usb_keyboard_realize(USBDevice
*dev
, Error
**errp
)
611 usb_hid_initfn(dev
, HID_KEYBOARD
);
614 static int usb_ptr_post_load(void *opaque
, int version_id
)
616 USBHIDState
*s
= opaque
;
618 if (s
->dev
.remote_wakeup
) {
619 hid_pointer_activate(&s
->hid
);
624 static const VMStateDescription vmstate_usb_ptr
= {
627 .minimum_version_id
= 1,
628 .post_load
= usb_ptr_post_load
,
629 .fields
= (VMStateField
[]) {
630 VMSTATE_USB_DEVICE(dev
, USBHIDState
),
631 VMSTATE_HID_POINTER_DEVICE(hid
, USBHIDState
),
632 VMSTATE_END_OF_LIST()
636 static const VMStateDescription vmstate_usb_kbd
= {
639 .minimum_version_id
= 1,
640 .fields
= (VMStateField
[]) {
641 VMSTATE_USB_DEVICE(dev
, USBHIDState
),
642 VMSTATE_HID_KEYBOARD_DEVICE(hid
, USBHIDState
),
643 VMSTATE_END_OF_LIST()
647 static void usb_hid_class_initfn(ObjectClass
*klass
, void *data
)
649 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
651 uc
->handle_reset
= usb_hid_handle_reset
;
652 uc
->handle_control
= usb_hid_handle_control
;
653 uc
->handle_data
= usb_hid_handle_data
;
654 uc
->handle_destroy
= usb_hid_handle_destroy
;
655 uc
->handle_attach
= usb_desc_attach
;
658 static Property usb_tablet_properties
[] = {
659 DEFINE_PROP_UINT32("usb_version", USBHIDState
, usb_version
, 2),
660 DEFINE_PROP_STRING("display", USBHIDState
, display
),
661 DEFINE_PROP_UINT32("head", USBHIDState
, head
, 0),
662 DEFINE_PROP_END_OF_LIST(),
665 static void usb_tablet_class_initfn(ObjectClass
*klass
, void *data
)
667 DeviceClass
*dc
= DEVICE_CLASS(klass
);
668 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
670 usb_hid_class_initfn(klass
, data
);
671 uc
->realize
= usb_tablet_realize
;
672 uc
->product_desc
= "QEMU USB Tablet";
673 dc
->vmsd
= &vmstate_usb_ptr
;
674 dc
->props
= usb_tablet_properties
;
675 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
678 static const TypeInfo usb_tablet_info
= {
679 .name
= "usb-tablet",
680 .parent
= TYPE_USB_DEVICE
,
681 .instance_size
= sizeof(USBHIDState
),
682 .class_init
= usb_tablet_class_initfn
,
685 static void usb_mouse_class_initfn(ObjectClass
*klass
, void *data
)
687 DeviceClass
*dc
= DEVICE_CLASS(klass
);
688 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
690 usb_hid_class_initfn(klass
, data
);
691 uc
->realize
= usb_mouse_realize
;
692 uc
->product_desc
= "QEMU USB Mouse";
693 uc
->usb_desc
= &desc_mouse
;
694 dc
->vmsd
= &vmstate_usb_ptr
;
695 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
698 static const TypeInfo usb_mouse_info
= {
700 .parent
= TYPE_USB_DEVICE
,
701 .instance_size
= sizeof(USBHIDState
),
702 .class_init
= usb_mouse_class_initfn
,
705 static Property usb_keyboard_properties
[] = {
706 DEFINE_PROP_STRING("display", USBHIDState
, display
),
707 DEFINE_PROP_END_OF_LIST(),
710 static void usb_keyboard_class_initfn(ObjectClass
*klass
, void *data
)
712 DeviceClass
*dc
= DEVICE_CLASS(klass
);
713 USBDeviceClass
*uc
= USB_DEVICE_CLASS(klass
);
715 usb_hid_class_initfn(klass
, data
);
716 uc
->realize
= usb_keyboard_realize
;
717 uc
->product_desc
= "QEMU USB Keyboard";
718 uc
->usb_desc
= &desc_keyboard
;
719 dc
->vmsd
= &vmstate_usb_kbd
;
720 dc
->props
= usb_keyboard_properties
;
721 set_bit(DEVICE_CATEGORY_INPUT
, dc
->categories
);
724 static const TypeInfo usb_keyboard_info
= {
726 .parent
= TYPE_USB_DEVICE
,
727 .instance_size
= sizeof(USBHIDState
),
728 .class_init
= usb_keyboard_class_initfn
,
731 static void usb_hid_register_types(void)
733 type_register_static(&usb_tablet_info
);
734 usb_legacy_register("usb-tablet", "tablet", NULL
);
735 type_register_static(&usb_mouse_info
);
736 usb_legacy_register("usb-mouse", "mouse", NULL
);
737 type_register_static(&usb_keyboard_info
);
738 usb_legacy_register("usb-kbd", "keyboard", NULL
);
741 type_init(usb_hid_register_types
)