diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2009-10-26 15:56:47 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-10-30 08:39:31 -0500 |
commit | 2b0efdc3e116753e349bc3d1888a8520f57e8315 (patch) | |
tree | a17fdd90789af0fb69283a80737608f2cd68e5a1 | |
parent | fa7c70c35a24f2c5b115004c51f3b726cc630e6d (diff) |
usb-serial and braille: use qdev for -usbdevice
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
-rw-r--r-- | hw/baum.c | 6 | ||||
-rw-r--r-- | hw/baum.h | 3 | ||||
-rw-r--r-- | hw/usb-serial.c | 85 | ||||
-rw-r--r-- | hw/usb.h | 3 | ||||
-rw-r--r-- | vl.c | 6 |
5 files changed, 65 insertions, 38 deletions
@@ -627,9 +627,3 @@ fail_handle: free(baum); return NULL; } - -USBDevice *usb_baum_init(void) -{ - /* USB Product ID of Super Vario 40 */ - return usb_serial_init("productid=FE72:braille"); -} @@ -22,8 +22,5 @@ * THE SOFTWARE. */ -/* usb device */ -USBDevice *usb_baum_init(void); - /* char device */ CharDriverState *chr_baum_init(QemuOpts *opts); diff --git a/hw/usb-serial.c b/hw/usb-serial.c index d02f6b2867..223d4c3859 100644 --- a/hw/usb-serial.c +++ b/hw/usb-serial.c @@ -90,8 +90,8 @@ do { printf("usb-serial: " fmt , ## __VA_ARGS__); } while (0) typedef struct { USBDevice dev; - uint16_t vendorid; - uint16_t productid; + uint32_t vendorid; + uint32_t productid; uint8_t recv_buf[RECV_BUF]; uint16_t recv_ptr; uint16_t recv_used; @@ -527,15 +527,18 @@ static int usb_serial_initfn(USBDevice *dev) { USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev); s->dev.speed = USB_SPEED_FULL; + + qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read, + usb_serial_event, s); + usb_serial_handle_reset(dev); return 0; } -USBDevice *usb_serial_init(const char *filename) +static USBDevice *usb_serial_init(const char *filename) { USBDevice *dev; - USBSerialState *s; CharDriverState *cdrv; - unsigned short vendorid = 0x0403, productid = 0x6001; + uint32_t vendorid = 0, productid = 0; char label[32]; static int index; @@ -545,26 +548,26 @@ USBDevice *usb_serial_init(const char *filename) if (strstart(filename, "vendorid=", &p)) { vendorid = strtol(p, &e, 16); if (e == p || (*e && *e != ',' && *e != ':')) { - printf("bogus vendor ID %s\n", p); + qemu_error("bogus vendor ID %s\n", p); return NULL; } filename = e; } else if (strstart(filename, "productid=", &p)) { productid = strtol(p, &e, 16); if (e == p || (*e && *e != ',' && *e != ':')) { - printf("bogus product ID %s\n", p); + qemu_error("bogus product ID %s\n", p); return NULL; } filename = e; } else { - printf("unrecognized serial USB option %s\n", filename); + qemu_error("unrecognized serial USB option %s\n", filename); return NULL; } while(*filename == ',') filename++; } if (!*filename) { - printf("character device specification needed\n"); + qemu_error("character device specification needed\n"); return NULL; } filename++; @@ -574,23 +577,56 @@ USBDevice *usb_serial_init(const char *filename) if (!cdrv) return NULL; - dev = usb_create_simple(NULL /* FIXME */, "QEMU USB Serial"); - s = DO_UPCAST(USBSerialState, dev, dev); - s->cs = cdrv; - s->vendorid = vendorid; - s->productid = productid; - snprintf(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Serial(%.16s)", - filename); + dev = usb_create(NULL /* FIXME */, "QEMU USB Serial"); + qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); + if (vendorid) + qdev_prop_set_uint16(&dev->qdev, "vendorid", vendorid); + if (productid) + qdev_prop_set_uint16(&dev->qdev, "productid", productid); + qdev_init(&dev->qdev); - qemu_chr_add_handlers(cdrv, usb_serial_can_read, usb_serial_read, - usb_serial_event, s); + return dev; +} + +static USBDevice *usb_braille_init(const char *unused) +{ + USBDevice *dev; + CharDriverState *cdrv; + + cdrv = qemu_chr_open("braille", "braille", NULL); + if (!cdrv) + return NULL; - usb_serial_handle_reset((USBDevice *)s); - return (USBDevice *)s; + dev = usb_create(NULL /* FIXME */, "QEMU USB Braille"); + qdev_prop_set_chr(&dev->qdev, "chardev", cdrv); + qdev_init(&dev->qdev); + + return dev; } static struct USBDeviceInfo serial_info = { .qdev.name = "QEMU USB Serial", + .qdev.alias = "usb-serial", + .qdev.size = sizeof(USBSerialState), + .init = usb_serial_initfn, + .handle_packet = usb_generic_handle_packet, + .handle_reset = usb_serial_handle_reset, + .handle_control = usb_serial_handle_control, + .handle_data = usb_serial_handle_data, + .handle_destroy = usb_serial_handle_destroy, + .usbdevice_name = "serial", + .usbdevice_init = usb_serial_init, + .qdev.props = (Property[]) { + DEFINE_PROP_CHR("chardev", USBSerialState, cs), + DEFINE_PROP_HEX32("vendorid", USBSerialState, vendorid, 0x0403), + DEFINE_PROP_HEX32("productid", USBSerialState, productid, 0x6001), + DEFINE_PROP_END_OF_LIST(), + }, +}; + +static struct USBDeviceInfo braille_info = { + .qdev.name = "QEMU USB Braille", + .qdev.alias = "usb-braille", .qdev.size = sizeof(USBSerialState), .init = usb_serial_initfn, .handle_packet = usb_generic_handle_packet, @@ -598,10 +634,19 @@ static struct USBDeviceInfo serial_info = { .handle_control = usb_serial_handle_control, .handle_data = usb_serial_handle_data, .handle_destroy = usb_serial_handle_destroy, + .usbdevice_name = "braille", + .usbdevice_init = usb_braille_init, + .qdev.props = (Property[]) { + DEFINE_PROP_CHR("chardev", USBSerialState, cs), + DEFINE_PROP_HEX32("vendorid", USBSerialState, vendorid, 0x0403), + DEFINE_PROP_HEX32("productid", USBSerialState, productid, 0xfe72), + DEFINE_PROP_END_OF_LIST(), + }, }; static void usb_serial_register_devices(void) { usb_qdev_register(&serial_info); + usb_qdev_register(&braille_info); } device_init(usb_serial_register_devices) @@ -265,9 +265,6 @@ USBDevice *usb_net_init(NICInfo *nd); /* usb-bt.c */ USBDevice *usb_bt_init(HCIInfo *hci); -/* usb-serial.c */ -USBDevice *usb_serial_init(const char *filename); - /* usb ports of the VM */ #define VM_USB_HUB_SIZE 8 @@ -2558,12 +2558,6 @@ static int usb_device_add(const char *devname, int is_hotplug) return 0; } } - } else if (strstart(devname, "serial:", &p)) { - dev = usb_serial_init(p); -#ifdef CONFIG_BRLAPI - } else if (!strcmp(devname, "braille")) { - dev = usb_baum_init(); -#endif } else if (strstart(devname, "net:", &p)) { QemuOpts *opts; int idx; |