Subject: Re: ArkMicroChips USB-UART
To: None <tech-kern@NetBSD.org>
From: Martin Husemann <martin@duskware.de>
List: tech-kern
Date: 07/06/2006 11:12:46
--BOKacYhQ+x31HxR3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

On Tue, Jun 27, 2006 at 09:23:11PM +0200, Martin Husemann wrote:
> I have a strange serial dongle:

Ok, I was pointed at ugensa.c, which implements a very dumb serial device
over usb. So I hacked the initialization sequence into it and tried - but
it does not work. (Patch below, of course the call of the init function
needs to depend on the matched device, this was just for testing.)

Guess I'll have to read usbcdc11.pdf now and see what I can make of this
device. Should this go into usbgensa then, or become a different driver?

I'll leave this as ugen for now and examine the device from userland a bit
more.

Martin

--BOKacYhQ+x31HxR3
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=patch

Index: ugensa.c
===================================================================
RCS file: /cvsroot/src/sys/dev/usb/ugensa.c,v
retrieving revision 1.7
diff -u -p -r1.7 ugensa.c
--- ugensa.c	28 Jun 2006 18:20:36 -0000	1.7
+++ ugensa.c	6 Jul 2006 08:53:19 -0000
@@ -93,6 +93,7 @@ struct ucom_methods ugensa_methods = {
 static const struct usb_devno ugensa_devs[] = {
 	{ USB_VENDOR_AIRPRIME, USB_PRODUCT_AIRPRIME_PC5220 },
 	{ USB_VENDOR_QUALCOMM_K, USB_PRODUCT_QUALCOMM_K_CDMA_MSM_K },
+	{ USB_VENDOR_ARKMICROCHIPS, USB_PRODUCT_ARKMICROCHIPS_USBSERIAL },
 };
 #define ugensa_lookup(v, p) usb_lookup(ugensa_devs, v, p)
 
@@ -112,6 +113,82 @@ USB_MATCH(ugensa)
 		UMATCH_VENDOR_PRODUCT : UMATCH_NONE);
 }
 
+static usbd_status
+fxusb_snd(usbd_device_handle dev, uint16_t value, uint16_t index)
+{
+	usb_device_request_t req;
+
+	req.bmRequestType = UT_WRITE_VENDOR_DEVICE;
+	req.bRequest = 0xfe;
+	USETW(req.wValue, value);
+	USETW(req.wIndex, index);
+	USETW(req.wLength, 0);
+	return (usbd_do_request(dev, &req, NULL));
+}
+
+static usbd_status
+fxusb_rcv(usbd_device_handle dev, uint16_t index, char *buf)
+{
+	usb_device_request_t req;
+
+	req.bmRequestType = UT_READ_VENDOR_DEVICE;
+	req.bRequest = 0xfe;
+	USETW(req.wValue, 0);
+	USETW(req.wIndex, index);
+	USETW(req.wLength, 1);
+	return (usbd_do_request(dev, &req, buf));
+}
+
+static void
+fxusb_init(usbd_device_handle dev)
+{
+	char buf;
+	usbd_status rst;
+
+	printf("\nfxusb_init:\n");
+	rst = fxusb_rcv(dev, 0x00003, &buf);
+	printf("7 control msg return : %d = %0x\n", rst, buf);
+
+	rst = fxusb_rcv(dev, 0x0004, &buf);
+	printf("12 control msg return : %d = %0x\n", rst, buf);
+
+	rst = fxusb_snd(dev, 0x0001, 0x004);
+	printf("17 control msg return : %d\n", rst);
+
+	rst = fxusb_rcv(dev, 0x0004, &buf);
+	printf("18 control msg return : %d = %0x\n", rst, buf);
+
+	rst = fxusb_snd(dev, 0x0004, 0x0004);
+	printf("19 control msg return : %d\n", rst);
+
+	rst = fxusb_rcv(dev, 0x0006, &buf);
+	printf("20 control msg return : %d = %0x\n", rst, buf);
+
+	rst = fxusb_snd(dev, 0x0082, 0x0003);
+	printf("147 control msg return : %d\n", rst);
+
+	rst = fxusb_snd(dev, 0x000d, 0x0000);
+	printf("148 control msg return : %d\n", rst);
+
+	rst = fxusb_snd(dev, 0x0000, 0x0001);
+	printf("149 control msg return : %d\n", rst);
+
+	rst = fxusb_snd(dev, 0x0002, 0x0003);
+	printf("150 control msg return : %d\n", rst);
+
+	rst = fxusb_rcv(dev, 0x0004, &buf);
+	printf("151 control msg return : %d = %0x\n", rst, buf);
+
+	rst = fxusb_snd(dev, 0x0003, 0x0004);
+	printf("152 control msg return : %d\n", rst);
+
+	rst = fxusb_rcv(dev, 0x0003, &buf);
+	printf("153 control msg return : %d = %0x\n", rst, buf);
+
+	rst = fxusb_snd(dev, 0x0003, 0x0003);
+	printf("154 control msg return : %d\n", rst);
+}
+
 USB_ATTACH(ugensa)
 {
 	USB_ATTACH_START(ugensa, sc, uaa);
@@ -202,6 +279,8 @@ USB_ATTACH(ugensa)
 	sc->sc_subdev = config_found_sm_loc(self, "ucombus", NULL, &uca,
 					    ucomprint, ucomsubmatch);
 
+	fxusb_init(dev);
+
 	USB_ATTACH_SUCCESS_RETURN;
 
 bad:

--BOKacYhQ+x31HxR3--