blob: 496009cff3a8133e84992c8c0b51bc3a4b0bd546 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * USB IR Dongle driver
3 *
4 * Copyright (C) 2001-2002 Greg Kroah-Hartman (greg@kroah.com)
5 * Copyright (C) 2002 Gary Brubaker (xavyer@ix.netcom.com)
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This driver allows a USB IrDA device to be used as a "dumb" serial device.
13 * This can be useful if you do not have access to a full IrDA stack on the
14 * other side of the connection. If you do have an IrDA stack on both devices,
15 * please use the usb-irda driver, as it contains the proper error checking and
16 * other goodness of a full IrDA stack.
17 *
18 * Portions of this driver were taken from drivers/net/irda/irda-usb.c, which
19 * was written by Roman Weissgaerber <weissg@vienna.at>, Dag Brattli
20 * <dag@brattli.net>, and Jean Tourrilhes <jt@hpl.hp.com>
21 *
22 * See Documentation/usb/usb-serial.txt for more information on using this driver
23 *
Alan Coxa6ea4382007-06-22 14:44:54 +010024 * 2007_Jun_21 Alan Cox <alan@redhat.com>
25 * Minimal cleanups for some of the driver problens and tty layer abuse.
26 * Still needs fixing to allow multiple dongles.
27 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * 2002_Mar_07 greg kh
29 * moved some needed structures and #define values from the
30 * net/irda/irda-usb.h file into our file, as we don't want to depend on
31 * that codebase compiling correctly :)
32 *
33 * 2002_Jan_14 gb
34 * Added module parameter to force specific number of XBOFs.
35 * Added ir_xbof_change().
36 * Reorganized read_bulk_callback error handling.
37 * Switched from FILL_BULK_URB() to usb_fill_bulk_urb().
38 *
39 * 2001_Nov_08 greg kh
40 * Changed the irda_usb_find_class_desc() function based on comments and
41 * code from Martin Diehl.
42 *
43 * 2001_Nov_01 greg kh
44 * Added support for more IrDA USB devices.
45 * Added support for zero packet. Added buffer override paramater, so
46 * users can transfer larger packets at once if they wish. Both patches
47 * came from Dag Brattli <dag@obexcode.com>.
48 *
49 * 2001_Oct_07 greg kh
50 * initial version released.
51 */
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <linux/kernel.h>
54#include <linux/errno.h>
55#include <linux/init.h>
56#include <linux/slab.h>
57#include <linux/tty.h>
58#include <linux/tty_driver.h>
59#include <linux/tty_flip.h>
60#include <linux/module.h>
61#include <linux/spinlock.h>
62#include <asm/uaccess.h>
63#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070064#include <linux/usb/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070065
66/*
67 * Version Information
68 */
69#define DRIVER_VERSION "v0.4"
70#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>"
71#define DRIVER_DESC "USB IR Dongle driver"
72
73/* USB IrDA class spec information */
74#define USB_CLASS_IRDA 0x02
75#define USB_DT_IRDA 0x21
76#define IU_REQ_GET_CLASS_DESC 0x06
77#define SPEED_2400 0x01
78#define SPEED_9600 0x02
79#define SPEED_19200 0x03
80#define SPEED_38400 0x04
81#define SPEED_57600 0x05
82#define SPEED_115200 0x06
83#define SPEED_576000 0x07
84#define SPEED_1152000 0x08
85#define SPEED_4000000 0x09
86
87struct irda_class_desc {
88 u8 bLength;
89 u8 bDescriptorType;
90 u16 bcdSpecRevision;
91 u8 bmDataSize;
92 u8 bmWindowSize;
93 u8 bmMinTurnaroundTime;
94 u16 wBaudRate;
95 u8 bmAdditionalBOFs;
96 u8 bIrdaRateSniff;
97 u8 bMaxUnicastList;
98} __attribute__ ((packed));
99
100static int debug;
101
102/* if overridden by the user, then use their value for the size of the read and
103 * write urbs */
104static int buffer_size;
105/* if overridden by the user, then use the specified number of XBOFs */
106static int xbof = -1;
107
108static int ir_startup (struct usb_serial *serial);
109static int ir_open (struct usb_serial_port *port, struct file *filep);
110static void ir_close (struct usb_serial_port *port, struct file *filep);
111static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int count);
David Howells7d12e782006-10-05 14:55:46 +0100112static void ir_write_bulk_callback (struct urb *urb);
113static void ir_read_bulk_callback (struct urb *urb);
Alan Cox606d0992006-12-08 02:38:45 -0800114static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Alan Coxa6ea4382007-06-22 14:44:54 +0100116/* Not that this lot means you can only have one per system */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117static u8 ir_baud = 0;
118static u8 ir_xbof = 0;
119static u8 ir_add_bof = 0;
120
121static struct usb_device_id id_table [] = {
122 { USB_DEVICE(0x050f, 0x0180) }, /* KC Technology, KC-180 */
123 { USB_DEVICE(0x08e9, 0x0100) }, /* XTNDAccess */
124 { USB_DEVICE(0x09c4, 0x0011) }, /* ACTiSys ACT-IR2000U */
125 { USB_INTERFACE_INFO (USB_CLASS_APP_SPEC, USB_CLASS_IRDA, 0) },
126 { } /* Terminating entry */
127};
128
129MODULE_DEVICE_TABLE (usb, id_table);
130
131static struct usb_driver ir_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 .name = "ir-usb",
133 .probe = usb_serial_probe,
134 .disconnect = usb_serial_disconnect,
135 .id_table = id_table,
Greg Kroah-Hartmanba9dc652005-11-16 13:41:28 -0800136 .no_dynamic_id = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137};
138
139
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -0700140static struct usb_serial_driver ir_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700141 .driver = {
142 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700143 .name = "ir-usb",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700144 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700145 .description = "IR Dongle",
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100146 .usb_driver = &ir_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 .id_table = id_table,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 .num_ports = 1,
149 .set_termios = ir_set_termios,
150 .attach = ir_startup,
151 .open = ir_open,
152 .close = ir_close,
153 .write = ir_write,
154 .write_bulk_callback = ir_write_bulk_callback,
155 .read_bulk_callback = ir_read_bulk_callback,
156};
157
158static inline void irda_usb_dump_class_desc(struct irda_class_desc *desc)
159{
160 dbg("bLength=%x", desc->bLength);
161 dbg("bDescriptorType=%x", desc->bDescriptorType);
162 dbg("bcdSpecRevision=%x", desc->bcdSpecRevision);
163 dbg("bmDataSize=%x", desc->bmDataSize);
164 dbg("bmWindowSize=%x", desc->bmWindowSize);
165 dbg("bmMinTurnaroundTime=%d", desc->bmMinTurnaroundTime);
166 dbg("wBaudRate=%x", desc->wBaudRate);
167 dbg("bmAdditionalBOFs=%x", desc->bmAdditionalBOFs);
168 dbg("bIrdaRateSniff=%x", desc->bIrdaRateSniff);
169 dbg("bMaxUnicastList=%x", desc->bMaxUnicastList);
170}
171
172/*------------------------------------------------------------------*/
173/*
174 * Function irda_usb_find_class_desc(dev, ifnum)
175 *
176 * Returns instance of IrDA class descriptor, or NULL if not found
177 *
178 * The class descriptor is some extra info that IrDA USB devices will
179 * offer to us, describing their IrDA characteristics. We will use that in
180 * irda_usb_init_qos()
181 *
182 * Based on the same function in drivers/net/irda/irda-usb.c
183 */
184static struct irda_class_desc *irda_usb_find_class_desc(struct usb_device *dev, unsigned int ifnum)
185{
186 struct irda_class_desc *desc;
187 int ret;
188
Eric Sesterhenn80b6ca42006-02-27 21:29:43 +0100189 desc = kzalloc(sizeof (struct irda_class_desc), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 if (desc == NULL)
191 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193 ret = usb_control_msg(dev, usb_rcvctrlpipe(dev,0),
194 IU_REQ_GET_CLASS_DESC,
195 USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
196 0, ifnum, desc, sizeof(*desc), 1000);
197
Harvey Harrison441b62c2008-03-03 16:08:34 -0800198 dbg("%s - ret=%d", __func__, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 if (ret < sizeof(*desc)) {
200 dbg("%s - class descriptor read %s (%d)",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800201 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 (ret<0) ? "failed" : "too short",
203 ret);
204 goto error;
205 }
206 if (desc->bDescriptorType != USB_DT_IRDA) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800207 dbg("%s - bad class descriptor type", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 goto error;
209 }
210
211 irda_usb_dump_class_desc(desc);
212 return desc;
213error:
214 kfree(desc);
215 return NULL;
216}
217
218
219static u8 ir_xbof_change(u8 xbof)
220{
221 u8 result;
222 /* reference irda-usb.c */
223 switch(xbof) {
224 case 48: result = 0x10; break;
225 case 28:
226 case 24: result = 0x20; break;
227 default:
228 case 12: result = 0x30; break;
229 case 5:
230 case 6: result = 0x40; break;
231 case 3: result = 0x50; break;
232 case 2: result = 0x60; break;
233 case 1: result = 0x70; break;
234 case 0: result = 0x80; break;
235 }
236 return(result);
237}
238
239
240static int ir_startup (struct usb_serial *serial)
241{
242 struct irda_class_desc *irda_desc;
243
244 irda_desc = irda_usb_find_class_desc (serial->dev, 0);
245 if (irda_desc == NULL) {
246 dev_err (&serial->dev->dev, "IRDA class descriptor not found, device not bound\n");
247 return -ENODEV;
248 }
249
250 dbg ("%s - Baud rates supported:%s%s%s%s%s%s%s%s%s",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800251 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 (irda_desc->wBaudRate & 0x0001) ? " 2400" : "",
253 (irda_desc->wBaudRate & 0x0002) ? " 9600" : "",
254 (irda_desc->wBaudRate & 0x0004) ? " 19200" : "",
255 (irda_desc->wBaudRate & 0x0008) ? " 38400" : "",
256 (irda_desc->wBaudRate & 0x0010) ? " 57600" : "",
257 (irda_desc->wBaudRate & 0x0020) ? " 115200" : "",
258 (irda_desc->wBaudRate & 0x0040) ? " 576000" : "",
259 (irda_desc->wBaudRate & 0x0080) ? " 1152000" : "",
260 (irda_desc->wBaudRate & 0x0100) ? " 4000000" : "");
261
262 switch( irda_desc->bmAdditionalBOFs ) {
263 case 0x01: ir_add_bof = 48; break;
264 case 0x02: ir_add_bof = 24; break;
265 case 0x04: ir_add_bof = 12; break;
266 case 0x08: ir_add_bof = 6; break;
267 case 0x10: ir_add_bof = 3; break;
268 case 0x20: ir_add_bof = 2; break;
269 case 0x40: ir_add_bof = 1; break;
270 case 0x80: ir_add_bof = 0; break;
271 default:;
272 }
273
274 kfree (irda_desc);
275
276 return 0;
277}
278
279static int ir_open (struct usb_serial_port *port, struct file *filp)
280{
281 char *buffer;
282 int result = 0;
283
Harvey Harrison441b62c2008-03-03 16:08:34 -0800284 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285
286 if (buffer_size) {
287 /* override the default buffer sizes */
288 buffer = kmalloc (buffer_size, GFP_KERNEL);
289 if (!buffer) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800290 dev_err (&port->dev, "%s - out of memory.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 return -ENOMEM;
292 }
293 kfree (port->read_urb->transfer_buffer);
294 port->read_urb->transfer_buffer = buffer;
295 port->read_urb->transfer_buffer_length = buffer_size;
296
297 buffer = kmalloc (buffer_size, GFP_KERNEL);
298 if (!buffer) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800299 dev_err (&port->dev, "%s - out of memory.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 return -ENOMEM;
301 }
302 kfree (port->write_urb->transfer_buffer);
303 port->write_urb->transfer_buffer = buffer;
304 port->write_urb->transfer_buffer_length = buffer_size;
305 port->bulk_out_size = buffer_size;
306 }
307
308 /* Start reading from the device */
309 usb_fill_bulk_urb (
310 port->read_urb,
311 port->serial->dev,
312 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress),
313 port->read_urb->transfer_buffer,
314 port->read_urb->transfer_buffer_length,
315 ir_read_bulk_callback,
316 port);
317 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
318 if (result)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800319 dev_err(&port->dev, "%s - failed submitting read urb, error %d\n", __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
321 return result;
322}
323
324static void ir_close (struct usb_serial_port *port, struct file * filp)
325{
Harvey Harrison441b62c2008-03-03 16:08:34 -0800326 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 /* shutdown our bulk read */
329 usb_kill_urb(port->read_urb);
330}
331
332static int ir_write (struct usb_serial_port *port, const unsigned char *buf, int count)
333{
334 unsigned char *transfer_buffer;
335 int result;
336 int transfer_size;
337
Harvey Harrison441b62c2008-03-03 16:08:34 -0800338 dbg("%s - port = %d, count = %d", __func__, port->number, count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 if (!port->tty) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800341 dev_err (&port->dev, "%s - no tty???\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 return 0;
343 }
344
345 if (count == 0)
346 return 0;
347
Peter Zijlstrae81ee632006-09-25 12:51:41 +0200348 spin_lock_bh(&port->lock);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700349 if (port->write_urb_busy) {
Peter Zijlstrae81ee632006-09-25 12:51:41 +0200350 spin_unlock_bh(&port->lock);
Harvey Harrison441b62c2008-03-03 16:08:34 -0800351 dbg("%s - already writing", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 return 0;
353 }
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700354 port->write_urb_busy = 1;
Peter Zijlstrae81ee632006-09-25 12:51:41 +0200355 spin_unlock_bh(&port->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
357 transfer_buffer = port->write_urb->transfer_buffer;
358 transfer_size = min(count, port->bulk_out_size - 1);
359
360 /*
361 * The first byte of the packet we send to the device contains an
362 * inband header which indicates an additional number of BOFs and
363 * a baud rate change.
364 *
365 * See section 5.4.2.2 of the USB IrDA spec.
366 */
367 *transfer_buffer = ir_xbof | ir_baud;
368 ++transfer_buffer;
369
370 memcpy (transfer_buffer, buf, transfer_size);
371
372 usb_fill_bulk_urb (
373 port->write_urb,
374 port->serial->dev,
375 usb_sndbulkpipe(port->serial->dev,
376 port->bulk_out_endpointAddress),
377 port->write_urb->transfer_buffer,
378 transfer_size + 1,
379 ir_write_bulk_callback,
380 port);
381
382 port->write_urb->transfer_flags = URB_ZERO_PACKET;
383
384 result = usb_submit_urb (port->write_urb, GFP_ATOMIC);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700385 if (result) {
386 port->write_urb_busy = 0;
Harvey Harrison441b62c2008-03-03 16:08:34 -0800387 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700388 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 result = transfer_size;
390
391 return result;
392}
393
David Howells7d12e782006-10-05 14:55:46 +0100394static void ir_write_bulk_callback (struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
396 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
Greg Kroah-Hartman3152b742007-06-15 15:44:13 -0700397 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Harvey Harrison441b62c2008-03-03 16:08:34 -0800399 dbg("%s - port %d", __func__, port->number);
Greg Kroah-Hartman507ca9b2005-04-23 12:49:16 -0700400
401 port->write_urb_busy = 0;
Greg Kroah-Hartman3152b742007-06-15 15:44:13 -0700402 if (status) {
403 dbg("%s - nonzero write bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800404 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return;
406 }
407
408 usb_serial_debug_data (
409 debug,
410 &port->dev,
Harvey Harrison441b62c2008-03-03 16:08:34 -0800411 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 urb->actual_length,
413 urb->transfer_buffer);
414
Pete Zaitcevcf2c7482006-05-22 21:58:49 -0700415 usb_serial_port_softint(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416}
417
David Howells7d12e782006-10-05 14:55:46 +0100418static void ir_read_bulk_callback (struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419{
420 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
421 struct tty_struct *tty;
422 unsigned char *data = urb->transfer_buffer;
423 int result;
Greg Kroah-Hartman3152b742007-06-15 15:44:13 -0700424 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Harvey Harrison441b62c2008-03-03 16:08:34 -0800426 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
428 if (!port->open_count) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800429 dbg("%s - port closed.", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 return;
431 }
432
Greg Kroah-Hartman3152b742007-06-15 15:44:13 -0700433 switch (status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 case 0: /* Successful */
435
436 /*
437 * The first byte of the packet we get from the device
438 * contains a busy indicator and baud rate change.
439 * See section 5.4.1.2 of the USB IrDA spec.
440 */
441 if ((*data & 0x0f) > 0)
442 ir_baud = *data & 0x0f;
443
444 usb_serial_debug_data (
445 debug,
446 &port->dev,
Harvey Harrison441b62c2008-03-03 16:08:34 -0800447 __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 urb->actual_length,
449 data);
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 tty = port->tty;
452
Alan Coxa6ea4382007-06-22 14:44:54 +0100453 if (tty_buffer_request_room(tty, urb->actual_length - 1)) {
454 tty_insert_flip_string(tty, data+1, urb->actual_length - 1);
455 tty_flip_buffer_push(tty);
456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
458 /*
459 * No break here.
460 * We want to resubmit the urb so we can read
461 * again.
462 */
463
464 case -EPROTO: /* taking inspiration from pl2303.c */
465
466 /* Continue trying to always read */
467 usb_fill_bulk_urb (
468 port->read_urb,
469 port->serial->dev,
470 usb_rcvbulkpipe(port->serial->dev,
471 port->bulk_in_endpointAddress),
472 port->read_urb->transfer_buffer,
473 port->read_urb->transfer_buffer_length,
474 ir_read_bulk_callback,
475 port);
476
477 result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
478 if (result)
479 dev_err(&port->dev, "%s - failed resubmitting read urb, error %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800480 __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482 break ;
483
484 default:
485 dbg("%s - nonzero read bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800486 __func__,
Greg Kroah-Hartman3152b742007-06-15 15:44:13 -0700487 status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 break ;
489
490 }
491
492 return;
493}
494
Alan Cox606d0992006-12-08 02:38:45 -0800495static void ir_set_termios (struct usb_serial_port *port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
497 unsigned char *transfer_buffer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 int result;
Alan Coxa6ea4382007-06-22 14:44:54 +0100499 speed_t baud;
500 int ir_baud;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501
Harvey Harrison441b62c2008-03-03 16:08:34 -0800502 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Alan Coxa6ea4382007-06-22 14:44:54 +0100504 baud = tty_get_baud_rate(port->tty);
505
506 /*
507 * FIXME, we should compare the baud request against the
508 * capability stated in the IR header that we got in the
509 * startup function.
510 */
511
512 switch (baud) {
513 case 2400: ir_baud = SPEED_2400; break;
514 case 9600: ir_baud = SPEED_9600; break;
515 case 19200: ir_baud = SPEED_19200; break;
516 case 38400: ir_baud = SPEED_38400; break;
517 case 57600: ir_baud = SPEED_57600; break;
518 case 115200: ir_baud = SPEED_115200; break;
519 case 576000: ir_baud = SPEED_576000; break;
520 case 1152000: ir_baud = SPEED_1152000; break;
521 case 4000000: ir_baud = SPEED_4000000; break;
522 break;
523 default:
524 ir_baud = SPEED_9600;
525 baud = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 }
527
Alan Coxa6ea4382007-06-22 14:44:54 +0100528 if (xbof == -1)
529 ir_xbof = ir_xbof_change(ir_add_bof);
530 else
531 ir_xbof = ir_xbof_change(xbof) ;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Alan Coxa6ea4382007-06-22 14:44:54 +0100533 /* FIXME need to check to see if our write urb is busy right
534 * now, or use a urb pool.
535 *
536 * send the baud change out on an "empty" data packet
537 */
538 transfer_buffer = port->write_urb->transfer_buffer;
539 *transfer_buffer = ir_xbof | ir_baud;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
Alan Coxa6ea4382007-06-22 14:44:54 +0100541 usb_fill_bulk_urb (
542 port->write_urb,
543 port->serial->dev,
544 usb_sndbulkpipe(port->serial->dev, port->bulk_out_endpointAddress),
545 port->write_urb->transfer_buffer,
546 1,
547 ir_write_bulk_callback,
548 port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Alan Coxa6ea4382007-06-22 14:44:54 +0100550 port->write_urb->transfer_flags = URB_ZERO_PACKET;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Alan Coxa6ea4382007-06-22 14:44:54 +0100552 result = usb_submit_urb (port->write_urb, GFP_KERNEL);
553 if (result)
Harvey Harrison441b62c2008-03-03 16:08:34 -0800554 dev_err(&port->dev, "%s - failed submitting write urb, error %d\n", __func__, result);
Alan Cox560aac22007-10-18 01:24:20 -0700555
556 /* Only speed changes are supported */
557 tty_termios_copy_hw(port->tty->termios, old_termios);
558 tty_encode_baud_rate(port->tty, baud, baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559}
560
561
562static int __init ir_init (void)
563{
564 int retval;
565 retval = usb_serial_register(&ir_device);
566 if (retval)
567 goto failed_usb_serial_register;
568 retval = usb_register(&ir_driver);
569 if (retval)
570 goto failed_usb_register;
571 info(DRIVER_DESC " " DRIVER_VERSION);
572 return 0;
573failed_usb_register:
574 usb_serial_deregister(&ir_device);
575failed_usb_serial_register:
576 return retval;
577}
578
579
580static void __exit ir_exit (void)
581{
582 usb_deregister (&ir_driver);
583 usb_serial_deregister (&ir_device);
584}
585
586
587module_init(ir_init);
588module_exit(ir_exit);
589
590MODULE_AUTHOR(DRIVER_AUTHOR);
591MODULE_DESCRIPTION(DRIVER_DESC);
592MODULE_LICENSE("GPL");
593
594module_param(debug, bool, S_IRUGO | S_IWUSR);
595MODULE_PARM_DESC(debug, "Debug enabled or not");
596module_param(xbof, int, 0);
597MODULE_PARM_DESC(xbof, "Force specific number of XBOFs");
598module_param(buffer_size, int, 0);
599MODULE_PARM_DESC(buffer_size, "Size of the transfer buffers");
600