USB serial device
Hello,
I would like to implement support for braille devices, and for this I'd need to first implement a USB serial device (FTDI chip). Has anybody worked on that already?
Samuel
PATCH 1/1 USB serial device
Hello,
Quoted 3 lines · Samuel Thibault, le Fri 11 Jan 2008 00:23:12 +0000, a écrit :
I would like to implement support for braille devices, and for this I'd need to first implement a USB serial device (FTDI chip). Has anybody worked on that already?
Ok, was easier than expected, Here is a patch. The serial support is incomplete however because qemu still lacks support for flow control and modem lines.
You will notice in tty_serial_init that I made the baud values more relaxed. This is because with divisor/baud conversions, things never get exact, so we need to be laxist with the value. For instance here with FTDI, the base divisor is 48000000/2, so for 57600 bps the guest needs to choose between divisors 416 and 417, which bring to either 57692bps or 57553bps but not exactly 57600bps. It happens that Linux chooses divisor 416, hence 57692bps. Of course, the higher the speed, the worse things get. The 1.1 factor is the smallest factor I could find between usual bps values, notably B110, B134 and B150.
Samuel
Index: Makefile
===================================================================
RCS file: /sources/qemu/qemu/Makefile,v
retrieving revision 1.140
Makefile +1 -1
@@ -57,7 +57,7 @@ OBJS+=i2c.o smbus.o smbus_eeprom.o max73 OBJS+=ssd0303.o ssd0323.o ads7846.o stellaris_input.o OBJS+=scsi-disk.o cdrom.o OBJS+=scsi-generic.o -OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o +OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o usb-serial.o OBJS+=sd.o ssi-sd.o ifdef CONFIG_WIN32
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.395
vl.c +17 -27
68 lines not on this page · raw message
Index: hw/usb-serial.c
===================================================================
RCS file: hw/usb-serial.c
usb-serial.c new file +514 -0
514 lines not on this page · raw message
Index: hw/usb.h
===================================================================
RCS file: /sources/qemu/qemu/hw/usb.h,v
retrieving revision 1.19
usb.h +3 -0
@@ -217,6 +217,9 @@ USBDevice *usb_msd_init(const char *file/* usb-wacom.c */ USBDevice *usb_wacom_init (void ); +/* usb-serial.c */ +USBDevice *usb_serial_init (const char *filename); +/* usb ports of the VM */ void qemu_register_usb_port(USBPort *port, void *opaque, int index,
Hello,
Quoted 9 lines · Samuel Thibault, le Fri 11 Jan 2008 11:09:23 +0000, a écrit :
Quoted 3 lines · Samuel Thibault, le Fri 11 Jan 2008 00:23:12 +0000, a écrit :
I would like to implement support for braille devices, and for this I'd need to first implement a USB serial device (FTDI chip). Has anybody worked on that already?
Ok, was easier than expected, Here is a patch. The serial support is incomplete however because qemu still lacks support for flow control and modem lines.
Quoted 9 lines
You will notice in
tty_serial_initthat I made the baud values more relaxed. This is because with divisor/baud conversions, things never get exact, so we need to be laxist with the value. For instance here with FTDI, the base divisor is 48000000/2, so for 57600 bps the guest needs to choose between divisors 416 and 417, which bring to either 57692bps or 57553bps but not exactly 57600bps. It happens that Linux chooses divisor 416, hence 57692bps. Of course, the higher the speed, the worse things get. The 1.1 factor is the smallest factor I could find between usual bps values, notably B110, B134 and B150.
Here is an updated version, that takes parameters, so as to be able to notably provide the product ID.
Samuel
? .vl.c.swp
? stvJqKpr
Index: Makefile
===================================================================
RCS file: /sources/qemu/qemu/Makefile,v
retrieving revision 1.140
Makefile +1 -1
@@ -57,7 +57,7 @@ OBJS+=i2c.o smbus.o smbus_eeprom.o max73 OBJS+=ssd0303.o ssd0323.o ads7846.o stellaris_input.o OBJS+=scsi-disk.o cdrom.o OBJS+=scsi-generic.o -OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o +OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o usb-serial.o OBJS+=sd.o ssi-sd.o ifdef CONFIG_WIN32
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.395
vl.c +17 -27
68 lines not on this page · raw message
Index: hw/usb-serial.c
===================================================================
RCS file: hw/usb-serial.c
usb-serial.c new file +549 -0
549 lines not on this page · raw message
Index: hw/usb.h
===================================================================
RCS file: /sources/qemu/qemu/hw/usb.h,v
retrieving revision 1.19
usb.h +3 -0
@@ -217,6 +217,9 @@ USBDevice *usb_msd_init(const char *file/* usb-wacom.c */ USBDevice *usb_wacom_init (void ); +/* usb-serial.c */ +USBDevice *usb_serial_init (const char *filename); +/* usb ports of the VM */ void qemu_register_usb_port(USBPort *port, void *opaque, int index,
Hello,
Quoted 20 lines · Samuel Thibault, le Sun 13 Jan 2008 01:55:56 +0000, a écrit :
Quoted 9 lines · Samuel Thibault, le Fri 11 Jan 2008 11:09:23 +0000, a écrit :
Quoted 3 lines · Samuel Thibault, le Fri 11 Jan 2008 00:23:12 +0000, a écrit :
I would like to implement support for braille devices, and for this I'd need to first implement a USB serial device (FTDI chip). Has anybody worked on that already?
Ok, was easier than expected, Here is a patch. The serial support is incomplete however because qemu still lacks support for flow control and modem lines.
Quoted 9 lines
You will notice in
tty_serial_initthat I made the baud values more relaxed. This is because with divisor/baud conversions, things never get exact, so we need to be laxist with the value. For instance here with FTDI, the base divisor is 48000000/2, so for 57600 bps the guest needs to choose between divisors 416 and 417, which bring to either 57692bps or 57553bps but not exactly 57600bps. It happens that Linux chooses divisor 416, hence 57692bps. Of course, the higher the speed, the worse things get. The 1.1 factor is the smallest factor I could find between usual bps values, notably B110, B134 and B150.
Quoted 2 lines
Here is an updated version, that takes parameters, so as to be able to notably provide the product ID.
There was a small bug, here is a fixed version.
I also have a braille device emulation patch which now works, but it probably needs a bit more polishing.
Samuel
Index: Makefile
===================================================================
RCS file: /sources/qemu/qemu/Makefile,v
retrieving revision 1.140
Makefile +1 -1
@@ -57,7 +57,7 @@ OBJS+=i2c.o smbus.o smbus_eeprom.o max73 OBJS+=ssd0303.o ssd0323.o ads7846.o stellaris_input.o OBJS+=scsi-disk.o cdrom.o OBJS+=scsi-generic.o -OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o +OBJS+=usb.o usb-hub.o usb-linux.o usb-hid.o usb-msd.o usb-wacom.o usb-serial.o OBJS+=sd.o ssi-sd.o ifdef CONFIG_WIN32
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.395
vl.c +17 -27
68 lines not on this page · raw message
Index: hw/usb-serial.c
===================================================================
RCS file: hw/usb-serial.c
usb-serial.c new file +549 -0
549 lines not on this page · raw message
Index: hw/usb.h
===================================================================
RCS file: /sources/qemu/qemu/hw/usb.h,v
retrieving revision 1.19
usb.h +3 -0
@@ -217,6 +217,9 @@ USBDevice *usb_msd_init(const char *file/* usb-wacom.c */ USBDevice *usb_wacom_init (void ); +/* usb-serial.c */ +USBDevice *usb_serial_init (const char *filename); +/* usb ports of the VM */ void qemu_register_usb_port(USBPort *port, void *opaque, int index,
Quoted 3 lines · Samuel Thibault
Quoted 2 lines · Samuel Thibault, le Sun 13 Jan 2008 01:55:56 +0000, a écrit :
Here is an updated version, that takes parameters, so as to be able to notably provide the product ID.
Can you provide a patch to the .texi docs some time, to document these parameters and an example usb_add line to get the dongle detected under linux?
These parameters probably don't need to be specific to this device but evidently nobody needed them yet with the other USB devices so it's ok.
Quoted 4 lines
There was a small bug, here is a fixed version.
I also have a braille device emulation patch which now works, but it probably needs a bit more polishing.
Regards
Quoted 8 lines · andrzej zaborowski, le Thu 17 Jan 2008 15:09:54 +0100, a écrit :
Quoted 3 lines · Samuel Thibault
Quoted 2 lines · Samuel Thibault, le Sun 13 Jan 2008 01:55:56 +0000, a écrit :
Here is an updated version, that takes parameters, so as to be able to notably provide the product ID.
Can you provide a patch to the .texi docs some time, to document these parameters and an example
usb_addline to get the dongle detected under linux?
Sure, here it is.
Samuel
Index: qemu-doc.texi
===================================================================
RCS file: /sources/qemu/qemu/qemu-doc.texi,v
retrieving revision 1.179
qemu-doc.texi +15 -1
@@ -525,6 +525,10 @@ Pass through the host device identified @item host:vendor_id:product_id Pass through the host device identified by vendor_id:product_id (Linux only). +@item serial:[vendorid=@var{vendor_id}][,productid=@var{product_id}]:@var{dev} +Serial converter to host character device @var{dev}, see @code{-serial} for the +available devices. + @end table @end table
@@ -1562,7 +1566,7 @@ as necessary to connect multiple USB dev USB devices can be connected with the @option{-usbdevice} commandline option or the @code{usb_add} monitor command. Available devices are: -@table @var +@table @code @item @code{mouse} Virtual Mouse. This will override the PS/2 mouse emulation when activated. @item @code{tablet}
@@ -1583,6 +1587,16 @@ above but it can be used with the tslib coordinates it reports touch pressure. @item @code{keyboard} Standard USB keyboard. Will override the PS/2 keyboard (if present). +@item @code{serial}:[vendorid=@var{vendor_id}][,product_id=@var{product_id}]:@var{dev} +Serial converter. This emulates an FTDI FT232BM chip connected to host character +device @var{dev}. The available character devices are the same as for the +@code{-serial} option. The @code{vendorid} and @code{productid} options can be +used to override the default 0403:FF00. For instance, +@example +usb_add serial:productid=FA00:tcp:192.168.0.2:4444 +@end example +will connect to tcp port 4444 of ip 192.168.0.2, and plug that to the virtual +serial converter, faking a Matrix Orbital LCD Display (USB ID 0403:FA00). @end table @node host_usb_devices
Quoted 11 lines · Samuel Thibault
Quoted 8 lines · andrzej zaborowski, le Thu 17 Jan 2008 15:09:54 +0100, a écrit :
Quoted 3 lines · Samuel Thibault
Quoted 2 lines · Samuel Thibault, le Sun 13 Jan 2008 01:55:56 +0000, a écrit :
Here is an updated version, that takes parameters, so as to be able to notably provide the product ID.
Can you provide a patch to the .texi docs some time, to document these parameters and an example
usb_addline to get the dongle detected under linux?Sure, here it is.
Thanks, committed although I hoped for something that lets easily test that the adapter works, e.g. so that after a usb_add serial:...:stdio you can do cat /dev/ttyXXXN in the guest and see what's being typed on qemu's stdin. I got the device detected without problems but Linux didn't create any new serial ports.
Regards
Quoted 5 lines · andrzej zaborowski, le Thu 17 Jan 2008 23:25:04 +0100, a écrit :
Thanks, committed although I hoped for something that lets easily test that the adapter works, e.g. so that after a
usb_addserial:...:stdio you can do cat/dev/ttyXXXNin the guest and see what's being typed on qemu's stdin. I got the device detected without problems but Linux didn't create any new serial ports.
Oh? That's odd, I've no problem here, /dev/ttyUSB0 appears like a charm and cat & echo work fine. We should probably use another product ID by default, which would be more widely automatically recognized. Here is a patch.
Samuel
Index: hw/usb-serial.c
===================================================================
RCS file: /sources/qemu/qemu/hw/usb-serial.c,v
retrieving revision 1.1
usb-serial.c +1 -1
@@ -486,7 +486,7 @@ USBDevice *usb_serial_init(const char *f {USBSerialState *s;CharDriverState *cdrv; -unsigned short vendorid =0x0403 , productid =0xFF00 ; +unsigned short vendorid =0x0403 , productid =0x6001 ;while (*filename && *filename !=':' ) {const char *p;
Index: qemu-doc.texi
===================================================================
RCS file: /sources/qemu/qemu/qemu-doc.texi,v
retrieving revision 1.181
qemu-doc.texi +1 -1
@@ -1594,7 +1594,7 @@ Standard USB keyboard. Will override th Serial converter. This emulates an FTDI FT232BM chip connected to host character device @var{dev}. The available character devices are the same as for the @code{-serial} option. The @code{vendorid} and @code{productid} options can be -used to override the default 0403:FF00. For instance, +used to override the default 0403:6001. For instance, @example usb_add serial:productid=FA00:tcp:192.168.0.2:4444 @end example
Hi,
Quoted 6 lines · Samuel Thibault
Quoted 5 lines · andrzej zaborowski, le Thu 17 Jan 2008 23:25:04 +0100, a écrit :
Thanks, committed although I hoped for something that lets easily test that the adapter works, e.g. so that after a
usb_addserial:...:stdio you can do cat/dev/ttyXXXNin the guest and see what's being typed on qemu's stdin. I got the device detected without problems but Linux didn't create any new serial ports.
Sorry, that was a user error (mine), I had been using the generic usb-serial.ko driver instead of the FTDI specific one. Now it indeed works like a charm.
Quoted 5 lines
Oh? That's odd, I've no problem here,
/dev/ttyUSB0appears like a charm and cat & echo work fine. We should probably use another product ID by default, which would be more widely automatically recognized. Here is a patch.
Thanks, I applied the patch even though the old values worked ok too. If they were better for some reason please tell. I also added a chr_close callback for -serial stdio so that I can do usb_add serial::stdio, then usb_del and usb_add serial::stdio again without getting an error on opening "stdio".
Cheers
Quoted 1 line · andrzej zaborowski, le Sat 19 Jan 2008 14:05:20 +0100, a écrit :
I applied the patch even though the old values worked ok too.
The old values weren't in linux 2.6.12 for instance, and it looks like the new ones are the default ones for the FTDI builderr, so it should be fine now.
Quoted 3 lines
I also added a
chr_closecallback for -serial stdio so that I can dousb_addserial::stdio, thenusb_delandusb_addserial::stdioagain without getting an error on opening "stdio".
Good, thanks!
Samuel