linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [RFC] ark3116: add IrDA support (for Gembird UIR-22)
@ 2009-07-26 12:19 Ondrej Zary
  2009-07-27 10:15 ` Alan Cox
  0 siblings, 1 reply; 3+ messages in thread
From: Ondrej Zary @ 2009-07-26 12:19 UTC (permalink / raw)
  To: gregkh; +Cc: linux-usb, linux-kernel

Hello,
I got a Gembird UIR-22 USB to IrDA adapter (vendor ID 0x18ec, device ID 0x3118)
that did not work in Linux at all. So I opened it and found ARK3116T chip and
IrDA transceiver inside. Adding the IDs to ark3116 driver was not enough -
irdadump did not show any received data.

The next step was usbsnoop to find what windows driver does with the device.
The result is the patch below. Now the device works after plugging and running
"irattach /dev/ttyUSB0 -s".

But how to make it appear as a real IrDA device by itself? Another problem is
mixing IrDA with USB serial driver. Is a separate driver (something like
ark3116-irda) needed?


Signed-off-by: Ondrej Zary <linux@rainbow-software.org>

--- linux-2.6.30-orig/drivers/usb/serial/ark3116.c	2009-07-19 19:21:54.000000000 +0200
+++ linux/drivers/usb/serial/ark3116.c	2009-07-26 13:58:04.000000000 +0200
@@ -31,6 +31,7 @@
 
 static struct usb_device_id id_table [] = {
 	{ USB_DEVICE(0x6547, 0x0232) },
+	{ USB_DEVICE(0x18ec, 0x3118) },		/* USB to IrDA adapter */
 	{ },
 };
 MODULE_DEVICE_TABLE(usb, id_table);
@@ -83,7 +84,7 @@
 {
 	char *buf;
 	struct ark3116_private *priv;
-	int i;
+	int i, irda;
 
 	for (i = 0; i < serial->num_ports; ++i) {
 		priv = kzalloc(sizeof(struct ark3116_private), GFP_KERNEL);
@@ -100,11 +101,21 @@
 		goto cleanup;
 	}
 
+	irda = le16_to_cpu(serial->dev->descriptor.idProduct) == 0x3118;
+	if (irda)
+		dbg("IrDA mode");
+
 	/* 3 */
 	ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002);
 	ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001);
 	ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008);
-	ARK3116_SND(serial, 6, 0xFE, 0x40, 0x0000, 0x000B);
+	ARK3116_SND(serial, 6, 0xFE, 0x40, irda ? 0x0001 : 0x0000, 0x000B);
+
+	if (irda) {
+		ARK3116_SND(serial, 1001, 0xFE, 0x40, 0x0000, 0x000C);
+		ARK3116_SND(serial, 1002, 0xFE, 0x40, 0x0041, 0x000D);
+		ARK3116_SND(serial, 1003, 0xFE, 0x40, 0x0001, 0x000A);
+	}
 
 	/* <-- seq7 */
 	ARK3116_RCV(serial,  7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
@@ -141,6 +152,8 @@
 	ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
 	ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000);
 	ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001);
+	if (irda)
+		ARK3116_SND(serial, 1004, 0xFE, 0x40, 0x0000, 0x0009);
 	ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
 	ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
 	ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);

-- 
Ondrej Zary

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [RFC] ark3116: add IrDA support (for Gembird UIR-22)
  2009-07-26 12:19 [PATCH] [RFC] ark3116: add IrDA support (for Gembird UIR-22) Ondrej Zary
@ 2009-07-27 10:15 ` Alan Cox
  2009-08-01 20:36   ` Ondrej Zary
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Cox @ 2009-07-27 10:15 UTC (permalink / raw)
  To: Ondrej Zary; +Cc: gregkh, linux-usb, linux-kernel

> The next step was usbsnoop to find what windows driver does with the device.
> The result is the patch below. Now the device works after plugging and running
> "irattach /dev/ttyUSB0 -s".
> 
> But how to make it appear as a real IrDA device by itself? Another problem is
> mixing IrDA with USB serial driver. Is a separate driver (something like
> ark3116-irda) needed?

For standard devices using serial/tty then irattach is the right way to
do it. Nothing else should be needed.

> +	irda = le16_to_cpu(serial->dev->descriptor.idProduct) == 0x3118;
> +	if (irda)
> +		dbg("IrDA mode");
> +

I would split this out into

static int is_irda(serial) { }

just so that anyone who needs to add more irda adapters can find it
easily and do so neatly.

Alan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] [RFC] ark3116: add IrDA support (for Gembird UIR-22)
  2009-07-27 10:15 ` Alan Cox
@ 2009-08-01 20:36   ` Ondrej Zary
  0 siblings, 0 replies; 3+ messages in thread
From: Ondrej Zary @ 2009-08-01 20:36 UTC (permalink / raw)
  To: Alan Cox; +Cc: gregkh, linux-usb, linux-kernel

On Monday 27 July 2009 12:15:15 Alan Cox wrote:
> > The next step was usbsnoop to find what windows driver does with the
> > device. The result is the patch below. Now the device works after
> > plugging and running "irattach /dev/ttyUSB0 -s".
> >
> > But how to make it appear as a real IrDA device by itself? Another
> > problem is mixing IrDA with USB serial driver. Is a separate driver
> > (something like ark3116-irda) needed?
>
> For standard devices using serial/tty then irattach is the right way to
> do it. Nothing else should be needed.
>
> > +	irda = le16_to_cpu(serial->dev->descriptor.idProduct) == 0x3118;
> > +	if (irda)
> > +		dbg("IrDA mode");
> > +
>
> I would split this out into
>
> static int is_irda(serial) { }
>
> just so that anyone who needs to add more irda adapters can find it
> easily and do so neatly.

Something like this?



Add IrDA support to ark3116 driver. This makes Gembird UIR-22 USB to
IrDA adapter work (vendor ID 0x18ec, device ID 0x3118). This adapter
contains ARK3116T USB serial chip and an IrDA transceiver, thus
a command like "irattach /dev/ttyUSB0 -s" is needed.

All magic numbers were captured using usbsnoop from windows driver
that came with the device.


Signed-off-by: Ondrej Zary <linux@rainbow-software.org>

--- linux-2.6.30-orig/drivers/usb/serial/ark3116.c	2009-07-19 19:21:54.000000000 +0200
+++ linux/drivers/usb/serial/ark3116.c	2009-08-01 22:04:48.000000000 +0200
@@ -31,10 +31,20 @@
 
 static struct usb_device_id id_table [] = {
 	{ USB_DEVICE(0x6547, 0x0232) },
+	{ USB_DEVICE(0x18ec, 0x3118) },		/* USB to IrDA adapter */
 	{ },
 };
 MODULE_DEVICE_TABLE(usb, id_table);
 
+static int is_irda(struct usb_serial *serial)
+{
+	struct usb_device *dev = serial->dev;
+	if (le16_to_cpu(dev->descriptor.idVendor) == 0x18ec &&
+			le16_to_cpu(dev->descriptor.idProduct) == 0x3118)
+		return 1;
+	return 0;
+}
+
 struct ark3116_private {
 	spinlock_t lock;
 	u8 termios_initialized;
@@ -100,11 +110,21 @@
 		goto cleanup;
 	}
 
+	if (is_irda(serial))
+		dbg("IrDA mode");
+
 	/* 3 */
 	ARK3116_SND(serial, 3, 0xFE, 0x40, 0x0008, 0x0002);
 	ARK3116_SND(serial, 4, 0xFE, 0x40, 0x0008, 0x0001);
 	ARK3116_SND(serial, 5, 0xFE, 0x40, 0x0000, 0x0008);
-	ARK3116_SND(serial, 6, 0xFE, 0x40, 0x0000, 0x000B);
+	ARK3116_SND(serial, 6, 0xFE, 0x40, is_irda(serial) ? 0x0001 : 0x0000,
+		    0x000B);
+
+	if (is_irda(serial)) {
+		ARK3116_SND(serial, 1001, 0xFE, 0x40, 0x0000, 0x000C);
+		ARK3116_SND(serial, 1002, 0xFE, 0x40, 0x0041, 0x000D);
+		ARK3116_SND(serial, 1003, 0xFE, 0x40, 0x0001, 0x000A);
+	}
 
 	/* <-- seq7 */
 	ARK3116_RCV(serial,  7, 0xFE, 0xC0, 0x0000, 0x0003, 0x00, buf);
@@ -141,6 +161,8 @@
 	ARK3116_SND(serial, 147, 0xFE, 0x40, 0x0083, 0x0003);
 	ARK3116_SND(serial, 148, 0xFE, 0x40, 0x0038, 0x0000);
 	ARK3116_SND(serial, 149, 0xFE, 0x40, 0x0001, 0x0001);
+	if (is_irda(serial))
+		ARK3116_SND(serial, 1004, 0xFE, 0x40, 0x0000, 0x0009);
 	ARK3116_SND(serial, 150, 0xFE, 0x40, 0x0003, 0x0003);
 	ARK3116_RCV(serial, 151, 0xFE, 0xC0, 0x0000, 0x0004, 0x03, buf);
 	ARK3116_SND(serial, 152, 0xFE, 0x40, 0x0000, 0x0003);



-- 
Ondrej Zary

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-08-01 20:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-26 12:19 [PATCH] [RFC] ark3116: add IrDA support (for Gembird UIR-22) Ondrej Zary
2009-07-27 10:15 ` Alan Cox
2009-08-01 20:36   ` Ondrej Zary

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).