[WIP] uhidcom(4) driver for USB HID based UART

2014-12-17 Thread SASANO Takayoshi
Hi,

I am trying to write a driver for Silicon Labs CP2110 USB HID based UART.
Here is work-in-progress code, and it seems to set uca.uhidev properly.
(I wrote code/tested on 5.6-release and ported to -current.)

Exar's XR21B1421 uses similar protocol so I named the driver uhidcom(4),
but currently it is not supported --- too expensive to buy evaluation board.

-- 
SASANO Takayoshi u...@mx5.nisiq.net

Index: arch/i386/conf/GENERIC
===
RCS file: /cvs/src/sys/arch/i386/conf/GENERIC,v
retrieving revision 1.792
diff -u -p -u -p -r1.792 GENERIC
--- arch/i386/conf/GENERIC  11 Dec 2014 19:44:17 -  1.792
+++ arch/i386/conf/GENERIC  17 Dec 2014 09:57:54 -
@@ -274,6 +274,8 @@ ukbd*   at uhidev?  # USB keyboard
 wskbd* at ukbd? mux 1
 ucycom*at uhidev?  # Cypress serial
 ucom*  at ucycom?
+uhidcom* at uhidev?# Silicon Labs CP2110 USB HID UART
+ucom*  at uhidcom?
 uticom* at uhub?   # TI serial
 ucom*  at uticom?
 uhid*  at uhidev?  # USB generic HID support
Index: dev/usb/files.usb
===
RCS file: /cvs/src/sys/dev/usb/files.usb,v
retrieving revision 1.120
diff -u -p -u -p -r1.120 files.usb
--- dev/usb/files.usb   11 Dec 2014 19:44:17 -  1.120
+++ dev/usb/files.usb   17 Dec 2014 09:58:00 -
@@ -110,6 +110,11 @@ device ucycom: hid, ucombus
 attach ucycom at uhidbus
 file   dev/usb/ucycom.cucycom  needs-flag
 
+# Silicon Labs USB HID based UART controller
+device uhidcom: hid, ucombus
+attach uhidcom at uhidbus
+file   dev/usb/uhidcom.c   uhidcom needs-flag
+
 # Printers
 device ulpt: firmload
 attach ulpt at uhub
Index: dev/usb/uhidcom.c
===
RCS file: dev/usb/uhidcom.c
diff -N dev/usb/uhidcom.c
--- /dev/null   1 Jan 1970 00:00:00 -
+++ dev/usb/uhidcom.c   17 Dec 2014 09:58:01 -
@@ -0,0 +1,489 @@
+/* $OpenBSD: */
+
+/*
+ * Copyright (c) 2014 SASANO Takayoshi u...@uaa.org.uk
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Device driver for Silicon Labs CP2110 USB HID-UART bridge.
+ */
+
+#include sys/param.h
+#include sys/systm.h
+#include sys/kernel.h
+#include sys/malloc.h
+#include sys/conf.h
+#include sys/tty.h
+#include sys/device.h
+
+#include dev/usb/usb.h
+#include dev/usb/usbdi.h
+#include dev/usb/usbdi_util.h
+#include dev/usb/usbdevs.h
+
+#include dev/usb/hid.h
+#include dev/usb/usbhid.h
+#include dev/usb/uhidev.h
+
+#include dev/usb/ucomvar.h
+#include dev/usb/uhidcomreg.h
+
+#define UHIDCOM_DEBUG
+#ifdef UHIDCOM_DEBUG
+#defineDPRINTFN(n, x)  do { if(uhidcomdebug  (n)) printf x; } while 
(0)
+intuhidcomdebug = 10;
+#else
+#defineDPRINTFN(n, x)
+#endif
+#defineDPRINTF(x) DPRINTFN(0, x)
+
+struct uhidcom_softc {
+   struct uhidevsc_hdev;
+   struct usbd_device  *sc_udev;
+
+   u_char  *sc_ibuf;
+   u_intsc_icnt;
+
+   u_char   sc_lsr;
+   u_char   sc_msr;
+
+   struct device   *sc_subdev;
+};
+
+void   uhidcom_get_status(void *, int, u_char *, u_char *);
+void   uhidcom_set(void *, int, int, int);
+intuhidcom_param(void *, int, struct termios *);
+intuhidcom_open(void *, int);
+void   uhidcom_close(void *, int);
+void   uhidcom_write(void *, int, u_char *, u_char *, u_int32_t *);
+void   uhidcom_read(void *, int, u_char **, u_int32_t *);
+void   uhidcom_intr(struct uhidev *, void *, u_int);
+
+intuhidcom_match(struct device *, void *, void *);
+void   uhidcom_attach(struct device *, struct device *, void *);
+intuhidcom_detach(struct device *, int);
+
+usbd_statusuhidcom_uart_endis(struct uhidcom_softc *, int);
+usbd_statusuhidcom_clear_fifo(struct uhidcom_softc *, int);
+usbd_statusuhidcom_get_version(struct uhidcom_softc *, struct 
uhidcom_version_info *);
+usbd_statusuhidcom_get_uart_status(struct uhidcom_softc *, struct 
uhidcom_uart_status *);
+usbd_statusuhidcom_set_break(struct 

Re: [WIP] uhidcom(4) driver for USB HID based UART

2014-12-17 Thread Jonathan Gray
On Wed, Dec 17, 2014 at 07:49:59PM +0900, SASANO Takayoshi wrote:
 Hi,
 
 I am trying to write a driver for Silicon Labs CP2110 USB HID based UART.
 Here is work-in-progress code, and it seems to set uca.uhidev properly.
 (I wrote code/tested on 5.6-release and ported to -current.)
 
 Exar's XR21B1421 uses similar protocol so I named the driver uhidcom(4),
 but currently it is not supported --- too expensive to buy evaluation board.

Isn't that name a bit too generic?  We already have a USB HID based UART
driver in the tree with ucycom(4), which apparently uses a different protocol?



Re: [WIP] uhidcom(4) driver for USB HID based UART

2014-12-17 Thread SASANO Takayoshi
At Wed, 17 Dec 2014 22:43:40 +1100,
Jonathan Gray wrote:
 
 On Wed, Dec 17, 2014 at 07:49:59PM +0900, SASANO Takayoshi wrote:
  Hi,
  
  I am trying to write a driver for Silicon Labs CP2110 USB HID based UART.
  Here is work-in-progress code, and it seems to set uca.uhidev properly.
  (I wrote code/tested on 5.6-release and ported to -current.)
  
  Exar's XR21B1421 uses similar protocol so I named the driver uhidcom(4),
  but currently it is not supported --- too expensive to buy evaluation board.
 
 Isn't that name a bit too generic?  We already have a USB HID based UART
 driver in the tree with ucycom(4), which apparently uses a different protocol?
 

uslcom(4) is already used by CP210x, how about uslhcom(4)?
slh means Silicon Lab's Hid protocol.

Otherwise, uxrcom(4).

Regards,
-- 
SASANO Takayoshi u...@mx5.nisiq.net