aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Walle <michael@walle.cc>2011-08-09 23:54:55 +0200
committerGerd Hoffmann <kraxel@redhat.com>2011-08-10 14:14:00 +0200
commit4c15ba9cc96349ce1cd5396dd243cdc16ff5f016 (patch)
treeb36db5cbf94f38fefa00b2639b262b085491fdbf
parent1f42d22233b4f3d1a2933ff30e8d6a6d9ee2d08f (diff)
milkymist-softusb: use hid code directly
Remove the dummy USB device and use the HID code directly. Use the HID code for the mouse support, too. Signed-off-by: Michael Walle <michael@walle.cc> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
-rw-r--r--hw/milkymist-softusb.c122
1 files changed, 38 insertions, 84 deletions
diff --git a/hw/milkymist-softusb.c b/hw/milkymist-softusb.c
index 75c85aeb6f..fe4eedb2cb 100644
--- a/hw/milkymist-softusb.c
+++ b/hw/milkymist-softusb.c
@@ -25,7 +25,7 @@
#include "sysbus.h"
#include "trace.h"
#include "console.h"
-#include "usb.h"
+#include "hid.h"
#include "qemu-error.h"
enum {
@@ -46,9 +46,8 @@ enum {
struct MilkymistSoftUsbState {
SysBusDevice busdev;
- USBBus usbbus;
- USBPort usbport[2];
- USBDevice *usbdev;
+ HIDState hid_kbd;
+ HIDState hid_mouse;
qemu_irq irq;
@@ -62,13 +61,10 @@ struct MilkymistSoftUsbState {
uint32_t regs[R_MAX];
/* mouse state */
- int mouse_dx;
- int mouse_dy;
- int mouse_dz;
- uint8_t mouse_buttons_state;
+ uint8_t mouse_hid_buffer[4];
/* keyboard state */
- uint8_t kbd_usb_buffer[8];
+ uint8_t kbd_hid_buffer[8];
};
typedef struct MilkymistSoftUsbState MilkymistSoftUsbState;
@@ -177,16 +173,10 @@ static inline void softusb_write_pmem(MilkymistSoftUsbState *s,
static void softusb_mouse_changed(MilkymistSoftUsbState *s)
{
uint8_t m;
- uint8_t buf[4];
-
- buf[0] = s->mouse_buttons_state;
- buf[1] = s->mouse_dx;
- buf[2] = s->mouse_dy;
- buf[3] = s->mouse_dz;
softusb_read_dmem(s, COMLOC_MEVT_PRODUCE, &m, 1);
trace_milkymist_softusb_mevt(m);
- softusb_write_dmem(s, COMLOC_MEVT_BASE + 4 * m, buf, 4);
+ softusb_write_dmem(s, COMLOC_MEVT_BASE + 4 * m, s->mouse_hid_buffer, 4);
m = (m + 1) & 0xf;
softusb_write_dmem(s, COMLOC_MEVT_PRODUCE, &m, 1);
@@ -200,7 +190,7 @@ static void softusb_kbd_changed(MilkymistSoftUsbState *s)
softusb_read_dmem(s, COMLOC_KEVT_PRODUCE, &m, 1);
trace_milkymist_softusb_kevt(m);
- softusb_write_dmem(s, COMLOC_KEVT_BASE + 8 * m, s->kbd_usb_buffer, 8);
+ softusb_write_dmem(s, COMLOC_KEVT_BASE + 8 * m, s->kbd_hid_buffer, 8);
m = (m + 1) & 0x7;
softusb_write_dmem(s, COMLOC_KEVT_PRODUCE, &m, 1);
@@ -208,62 +198,42 @@ static void softusb_kbd_changed(MilkymistSoftUsbState *s)
qemu_irq_pulse(s->irq);
}
-static void softusb_mouse_event(void *opaque,
- int dx, int dy, int dz, int buttons_state)
+static void softusb_kbd_hid_datain(HIDState *hs)
{
- MilkymistSoftUsbState *s = opaque;
+ MilkymistSoftUsbState *s = container_of(hs, MilkymistSoftUsbState, hid_kbd);
+ int len;
/* if device is in reset, do nothing */
if (s->regs[R_CTRL] & CTRL_RESET) {
return;
}
- trace_milkymist_softusb_mouse_event(dx, dy, dz, buttons_state);
+ len = hid_keyboard_poll(hs, s->kbd_hid_buffer, sizeof(s->kbd_hid_buffer));
- s->mouse_dx = dx;
- s->mouse_dy = dy;
- s->mouse_dz = dz;
- s->mouse_buttons_state = buttons_state;
-
- softusb_mouse_changed(s);
+ if (len == 8) {
+ softusb_kbd_changed(s);
+ }
}
-static void softusb_usbdev_datain(void *opaque)
+static void softusb_mouse_hid_datain(HIDState *hs)
{
- MilkymistSoftUsbState *s = opaque;
-
- USBPacket p;
-
- usb_packet_init(&p);
- usb_packet_setup(&p, USB_TOKEN_IN, 0, 1);
- usb_packet_addbuf(&p, s->kbd_usb_buffer, sizeof(s->kbd_usb_buffer));
- s->usbdev->info->handle_data(s->usbdev, &p);
- usb_packet_cleanup(&p);
-
- softusb_kbd_changed(s);
-}
+ MilkymistSoftUsbState *s =
+ container_of(hs, MilkymistSoftUsbState, hid_mouse);
+ int len;
-static void softusb_attach(USBPort *port)
-{
-}
+ /* if device is in reset, do nothing */
+ if (s->regs[R_CTRL] & CTRL_RESET) {
+ return;
+ }
-static void softusb_detach(USBPort *port)
-{
-}
+ len = hid_pointer_poll(hs, s->mouse_hid_buffer,
+ sizeof(s->mouse_hid_buffer));
-static void softusb_child_detach(USBPort *port, USBDevice *child)
-{
+ if (len == 4) {
+ softusb_mouse_changed(s);
+ }
}
-static USBPortOps softusb_ops = {
- .attach = softusb_attach,
- .detach = softusb_detach,
- .child_detach = softusb_child_detach,
-};
-
-static USBBusOps softusb_bus_ops = {
-};
-
static void milkymist_softusb_reset(DeviceState *d)
{
MilkymistSoftUsbState *s =
@@ -273,11 +243,11 @@ static void milkymist_softusb_reset(DeviceState *d)
for (i = 0; i < R_MAX; i++) {
s->regs[i] = 0;
}
- s->mouse_dx = 0;
- s->mouse_dy = 0;
- s->mouse_dz = 0;
- s->mouse_buttons_state = 0;
- memset(s->kbd_usb_buffer, 0, sizeof(s->kbd_usb_buffer));
+ memset(s->kbd_hid_buffer, 0, sizeof(s->kbd_hid_buffer));
+ memset(s->mouse_hid_buffer, 0, sizeof(s->mouse_hid_buffer));
+
+ hid_reset(&s->hid_kbd);
+ hid_reset(&s->hid_mouse);
/* defaults */
s->regs[R_CTRL] = CTRL_RESET;
@@ -304,23 +274,8 @@ static int milkymist_softusb_init(SysBusDevice *dev)
cpu_register_physical_memory(s->dmem_base, s->dmem_size,
dmem_ram | IO_MEM_RAM);
- qemu_add_mouse_event_handler(softusb_mouse_event, s, 0, "Milkymist Mouse");
-
- /* create our usb bus */
- usb_bus_new(&s->usbbus, &softusb_bus_ops, NULL);
-
- /* our two ports */
- /* FIXME: claim to support full speed devices. qemu mouse and keyboard
- * report themselves as full speed devices. */
- usb_register_port(&s->usbbus, &s->usbport[0], NULL, 0, &softusb_ops,
- USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
- usb_register_port(&s->usbbus, &s->usbport[1], NULL, 1, &softusb_ops,
- USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
-
- /* and finally create an usb keyboard */
- s->usbdev = usb_create_simple(&s->usbbus, "usb-kbd");
- usb_hid_datain_cb(s->usbdev, s, softusb_usbdev_datain);
- s->usbdev->info->handle_reset(s->usbdev);
+ hid_init(&s->hid_kbd, HID_KEYBOARD, softusb_kbd_hid_datain);
+ hid_init(&s->hid_mouse, HID_MOUSE, softusb_mouse_hid_datain);
return 0;
}
@@ -332,11 +287,10 @@ static const VMStateDescription vmstate_milkymist_softusb = {
.minimum_version_id_old = 1,
.fields = (VMStateField[]) {
VMSTATE_UINT32_ARRAY(regs, MilkymistSoftUsbState, R_MAX),
- VMSTATE_INT32(mouse_dx, MilkymistSoftUsbState),
- VMSTATE_INT32(mouse_dy, MilkymistSoftUsbState),
- VMSTATE_INT32(mouse_dz, MilkymistSoftUsbState),
- VMSTATE_UINT8(mouse_buttons_state, MilkymistSoftUsbState),
- VMSTATE_BUFFER(kbd_usb_buffer, MilkymistSoftUsbState),
+ VMSTATE_HID_KEYBOARD_DEVICE(hid_kbd, MilkymistSoftUsbState),
+ VMSTATE_HID_POINTER_DEVICE(hid_mouse, MilkymistSoftUsbState),
+ VMSTATE_BUFFER(kbd_hid_buffer, MilkymistSoftUsbState),
+ VMSTATE_BUFFER(mouse_hid_buffer, MilkymistSoftUsbState),
VMSTATE_END_OF_LIST()
}
};