blob: e96bf8663ffcd0eef052e334a0ecca8b430f628a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * USB ConnectTech WhiteHEAT driver
3 *
4 * Copyright (C) 2002
5 * Connect Tech Inc.
6 *
7 * Copyright (C) 1999 - 2001
8 * Greg Kroah-Hartman (greg@kroah.com)
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * See Documentation/usb/usb-serial.txt for more information on using this driver
16 *
17 * (10/09/2002) Stuart MacDonald (stuartm@connecttech.com)
18 * Upgrade to full working driver
19 *
20 * (05/30/2001) gkh
21 * switched from using spinlock to a semaphore, which fixes lots of problems.
22 *
23 * (04/08/2001) gb
24 * Identify version on module load.
25 *
26 * 2001_Mar_19 gkh
27 * Fixed MOD_INC and MOD_DEC logic, the ability to open a port more
28 * than once, and the got the proper usb_device_id table entries so
29 * the driver works again.
30 *
31 * (11/01/2000) Adam J. Richter
32 * usb_device_id table support
33 *
34 * (10/05/2000) gkh
35 * Fixed bug with urb->dev not being set properly, now that the usb
36 * core needs it.
37 *
38 * (10/03/2000) smd
39 * firmware is improved to guard against crap sent to device
40 * firmware now replies CMD_FAILURE on bad things
41 * read_callback fix you provided for private info struct
42 * command_finished now indicates success or fail
43 * setup_port struct now packed to avoid gcc padding
44 * firmware uses 1 based port numbering, driver now handles that
45 *
46 * (09/11/2000) gkh
47 * Removed DEBUG #ifdefs with call to usb_serial_debug_data
48 *
49 * (07/19/2000) gkh
50 * Added module_init and module_exit functions to handle the fact that this
51 * driver is a loadable module now.
52 * Fixed bug with port->minor that was found by Al Borchers
53 *
54 * (07/04/2000) gkh
55 * Added support for port settings. Baud rate can now be changed. Line signals
56 * are not transferred to and from the tty layer yet, but things seem to be
57 * working well now.
58 *
59 * (05/04/2000) gkh
60 * First cut at open and close commands. Data can flow through the ports at
61 * default speeds now.
62 *
63 * (03/26/2000) gkh
64 * Split driver up into device specific pieces.
65 *
66 */
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068#include <linux/kernel.h>
69#include <linux/errno.h>
70#include <linux/init.h>
71#include <linux/slab.h>
72#include <linux/tty.h>
73#include <linux/tty_driver.h>
74#include <linux/tty_flip.h>
75#include <linux/module.h>
76#include <linux/spinlock.h>
Oliver Neukum08a2b3b2007-05-24 13:52:51 +020077#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070078#include <asm/uaccess.h>
79#include <asm/termbits.h>
80#include <linux/usb.h>
81#include <linux/serial_reg.h>
82#include <linux/serial.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070083#include <linux/usb/serial.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070084#include "whiteheat_fw.h" /* firmware for the ConnectTech WhiteHEAT device */
85#include "whiteheat.h" /* WhiteHEAT specific commands */
86
87static int debug;
88
89#ifndef CMSPAR
90#define CMSPAR 0
91#endif
92
93/*
94 * Version Information
95 */
96#define DRIVER_VERSION "v2.0"
97#define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>"
98#define DRIVER_DESC "USB ConnectTech WhiteHEAT driver"
99
100#define CONNECT_TECH_VENDOR_ID 0x0710
101#define CONNECT_TECH_FAKE_WHITE_HEAT_ID 0x0001
102#define CONNECT_TECH_WHITE_HEAT_ID 0x8001
103
104/*
105 ID tables for whiteheat are unusual, because we want to different
106 things for different versions of the device. Eventually, this
107 will be doable from a single table. But, for now, we define two
108 separate ID tables, and then a third table that combines them
109 just for the purpose of exporting the autoloading information.
110*/
111static struct usb_device_id id_table_std [] = {
112 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
113 { } /* Terminating entry */
114};
115
116static struct usb_device_id id_table_prerenumeration [] = {
117 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
118 { } /* Terminating entry */
119};
120
121static struct usb_device_id id_table_combined [] = {
122 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_WHITE_HEAT_ID) },
123 { USB_DEVICE(CONNECT_TECH_VENDOR_ID, CONNECT_TECH_FAKE_WHITE_HEAT_ID) },
124 { } /* Terminating entry */
125};
126
127MODULE_DEVICE_TABLE (usb, id_table_combined);
128
129static struct usb_driver whiteheat_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 .name = "whiteheat",
131 .probe = usb_serial_probe,
132 .disconnect = usb_serial_disconnect,
133 .id_table = id_table_combined,
Greg Kroah-Hartmanba9dc652005-11-16 13:41:28 -0800134 .no_dynamic_id = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135};
136
137/* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
138static int whiteheat_firmware_download (struct usb_serial *serial, const struct usb_device_id *id);
139static int whiteheat_firmware_attach (struct usb_serial *serial);
140
141/* function prototypes for the Connect Tech WhiteHEAT serial converter */
142static int whiteheat_attach (struct usb_serial *serial);
143static void whiteheat_shutdown (struct usb_serial *serial);
144static int whiteheat_open (struct usb_serial_port *port, struct file *filp);
145static void whiteheat_close (struct usb_serial_port *port, struct file *filp);
146static int whiteheat_write (struct usb_serial_port *port, const unsigned char *buf, int count);
147static int whiteheat_write_room (struct usb_serial_port *port);
148static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
Alan Cox606d0992006-12-08 02:38:45 -0800149static void whiteheat_set_termios (struct usb_serial_port *port, struct ktermios * old);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file);
151static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file, unsigned int set, unsigned int clear);
152static void whiteheat_break_ctl (struct usb_serial_port *port, int break_state);
153static int whiteheat_chars_in_buffer (struct usb_serial_port *port);
154static void whiteheat_throttle (struct usb_serial_port *port);
155static void whiteheat_unthrottle (struct usb_serial_port *port);
David Howells7d12e782006-10-05 14:55:46 +0100156static void whiteheat_read_callback (struct urb *urb);
157static void whiteheat_write_callback (struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -0700159static struct usb_serial_driver whiteheat_fake_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700160 .driver = {
161 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700162 .name = "whiteheatnofirm",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700163 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700164 .description = "Connect Tech - WhiteHEAT - (prerenumeration)",
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100165 .usb_driver = &whiteheat_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 .id_table = id_table_prerenumeration,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 .num_ports = 1,
168 .probe = whiteheat_firmware_download,
169 .attach = whiteheat_firmware_attach,
170};
171
Greg Kroah-Hartmanea653702005-06-20 21:15:16 -0700172static struct usb_serial_driver whiteheat_device = {
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700173 .driver = {
174 .owner = THIS_MODULE,
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700175 .name = "whiteheat",
Greg Kroah-Hartman18fcac32005-06-20 21:15:16 -0700176 },
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700177 .description = "Connect Tech - WhiteHEAT",
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100178 .usb_driver = &whiteheat_driver,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 .id_table = id_table_std,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 .num_ports = 4,
181 .attach = whiteheat_attach,
182 .shutdown = whiteheat_shutdown,
183 .open = whiteheat_open,
184 .close = whiteheat_close,
185 .write = whiteheat_write,
186 .write_room = whiteheat_write_room,
187 .ioctl = whiteheat_ioctl,
188 .set_termios = whiteheat_set_termios,
189 .break_ctl = whiteheat_break_ctl,
190 .tiocmget = whiteheat_tiocmget,
191 .tiocmset = whiteheat_tiocmset,
192 .chars_in_buffer = whiteheat_chars_in_buffer,
193 .throttle = whiteheat_throttle,
194 .unthrottle = whiteheat_unthrottle,
195 .read_bulk_callback = whiteheat_read_callback,
196 .write_bulk_callback = whiteheat_write_callback,
197};
198
199
200struct whiteheat_command_private {
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200201 struct mutex mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 __u8 port_running;
203 __u8 command_finished;
204 wait_queue_head_t wait_command; /* for handling sleeping while waiting for a command to finish */
205 __u8 result_buffer[64];
206};
207
208
209#define THROTTLED 0x01
210#define ACTUALLY_THROTTLED 0x02
211
212static int urb_pool_size = 8;
213
214struct whiteheat_urb_wrap {
215 struct list_head list;
216 struct urb *urb;
217};
218
219struct whiteheat_private {
220 spinlock_t lock;
221 __u8 flags;
Alan Coxa5b6f602008-04-08 17:16:06 +0100222 __u8 mcr; /* FIXME: no locking on mcr */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 struct list_head rx_urbs_free;
224 struct list_head rx_urbs_submitted;
225 struct list_head rx_urb_q;
226 struct work_struct rx_work;
David Howellsc4028952006-11-22 14:57:56 +0000227 struct usb_serial_port *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 struct list_head tx_urbs_free;
229 struct list_head tx_urbs_submitted;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200230 struct mutex deathwarrant;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231};
232
233
234/* local function prototypes */
235static int start_command_port(struct usb_serial *serial);
236static void stop_command_port(struct usb_serial *serial);
David Howells7d12e782006-10-05 14:55:46 +0100237static void command_port_write_callback(struct urb *urb);
238static void command_port_read_callback(struct urb *urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240static int start_port_read(struct usb_serial_port *port);
241static struct whiteheat_urb_wrap *urb_to_wrap(struct urb *urb, struct list_head *head);
242static struct list_head *list_first(struct list_head *head);
David Howellsc4028952006-11-22 14:57:56 +0000243static void rx_data_softint(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
245static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *data, __u8 datasize);
246static int firm_open(struct usb_serial_port *port);
247static int firm_close(struct usb_serial_port *port);
248static int firm_setup_port(struct usb_serial_port *port);
249static int firm_set_rts(struct usb_serial_port *port, __u8 onoff);
250static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff);
251static int firm_set_break(struct usb_serial_port *port, __u8 onoff);
252static int firm_purge(struct usb_serial_port *port, __u8 rxtx);
253static int firm_get_dtr_rts(struct usb_serial_port *port);
254static int firm_report_tx_done(struct usb_serial_port *port);
255
256
257#define COMMAND_PORT 4
258#define COMMAND_TIMEOUT (2*HZ) /* 2 second timeout for a command */
259#define COMMAND_TIMEOUT_MS 2000
260#define CLOSING_DELAY (30 * HZ)
261
262
263/*****************************************************************************
264 * Connect Tech's White Heat prerenumeration driver functions
265 *****************************************************************************/
266
267/* steps to download the firmware to the WhiteHEAT device:
268 - hold the reset (by writing to the reset bit of the CPUCS register)
269 - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD
270 - release the reset (by writing to the CPUCS register)
271 - download the WH.HEX file for all addresses greater than 0x1b3f using
272 VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD
273 - hold the reset
274 - download the WH.HEX file for all addresses less than 0x1b40 using
275 VENDOR_REQUEST_ANCHOR_LOAD
276 - release the reset
277 - device renumerated itself and comes up as new device id with all
278 firmware download completed.
279*/
280static int whiteheat_firmware_download (struct usb_serial *serial, const struct usb_device_id *id)
281{
282 int response;
283 const struct whiteheat_hex_record *record;
284
Harvey Harrison441b62c2008-03-03 16:08:34 -0800285 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 response = ezusb_set_reset (serial, 1);
288
289 record = &whiteheat_loader[0];
290 while (record->address != 0xffff) {
291 response = ezusb_writememory (serial, record->address,
292 (unsigned char *)record->data, record->data_size, 0xa0);
293 if (response < 0) {
294 err("%s - ezusb_writememory failed for loader (%d %04X %p %d)",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800295 __func__, response, record->address, record->data, record->data_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 break;
297 }
298 ++record;
299 }
300
301 response = ezusb_set_reset (serial, 0);
302
303 record = &whiteheat_firmware[0];
304 while (record->address < 0x1b40) {
305 ++record;
306 }
307 while (record->address != 0xffff) {
308 response = ezusb_writememory (serial, record->address,
309 (unsigned char *)record->data, record->data_size, 0xa3);
310 if (response < 0) {
311 err("%s - ezusb_writememory failed for first firmware step (%d %04X %p %d)",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800312 __func__, response, record->address, record->data, record->data_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 break;
314 }
315 ++record;
316 }
317
318 response = ezusb_set_reset (serial, 1);
319
320 record = &whiteheat_firmware[0];
321 while (record->address < 0x1b40) {
322 response = ezusb_writememory (serial, record->address,
323 (unsigned char *)record->data, record->data_size, 0xa0);
324 if (response < 0) {
325 err("%s - ezusb_writememory failed for second firmware step (%d %04X %p %d)",
Harvey Harrison441b62c2008-03-03 16:08:34 -0800326 __func__, response, record->address, record->data, record->data_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 break;
328 }
329 ++record;
330 }
331
332 response = ezusb_set_reset (serial, 0);
333
334 return 0;
335}
336
337
338static int whiteheat_firmware_attach (struct usb_serial *serial)
339{
340 /* We want this device to fail to have a driver assigned to it */
341 return 1;
342}
343
344
345/*****************************************************************************
346 * Connect Tech's White Heat serial driver functions
347 *****************************************************************************/
348static int whiteheat_attach (struct usb_serial *serial)
349{
350 struct usb_serial_port *command_port;
351 struct whiteheat_command_private *command_info;
352 struct usb_serial_port *port;
353 struct whiteheat_private *info;
354 struct whiteheat_hw_info *hw_info;
355 int pipe;
356 int ret;
357 int alen;
358 __u8 *command;
359 __u8 *result;
360 int i;
361 int j;
362 struct urb *urb;
363 int buf_size;
364 struct whiteheat_urb_wrap *wrap;
365 struct list_head *tmp;
366
367 command_port = serial->port[COMMAND_PORT];
368
369 pipe = usb_sndbulkpipe (serial->dev, command_port->bulk_out_endpointAddress);
370 command = kmalloc(2, GFP_KERNEL);
371 if (!command)
372 goto no_command_buffer;
373 command[0] = WHITEHEAT_GET_HW_INFO;
374 command[1] = 0;
375
376 result = kmalloc(sizeof(*hw_info) + 1, GFP_KERNEL);
377 if (!result)
378 goto no_result_buffer;
379 /*
380 * When the module is reloaded the firmware is still there and
381 * the endpoints are still in the usb core unchanged. This is the
382 * unlinking bug in disguise. Same for the call below.
383 */
384 usb_clear_halt(serial->dev, pipe);
385 ret = usb_bulk_msg (serial->dev, pipe, command, 2, &alen, COMMAND_TIMEOUT_MS);
386 if (ret) {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700387 err("%s: Couldn't send command [%d]", serial->type->description, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388 goto no_firmware;
Stuart MacDonald09fd6bc2006-05-31 13:28:40 -0400389 } else if (alen != 2) {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700390 err("%s: Send command incomplete [%d]", serial->type->description, alen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 goto no_firmware;
392 }
393
394 pipe = usb_rcvbulkpipe (serial->dev, command_port->bulk_in_endpointAddress);
395 /* See the comment on the usb_clear_halt() above */
396 usb_clear_halt(serial->dev, pipe);
397 ret = usb_bulk_msg (serial->dev, pipe, result, sizeof(*hw_info) + 1, &alen, COMMAND_TIMEOUT_MS);
398 if (ret) {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700399 err("%s: Couldn't get results [%d]", serial->type->description, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 goto no_firmware;
Stuart MacDonald09fd6bc2006-05-31 13:28:40 -0400401 } else if (alen != sizeof(*hw_info) + 1) {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700402 err("%s: Get results incomplete [%d]", serial->type->description, alen);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 goto no_firmware;
404 } else if (result[0] != command[0]) {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700405 err("%s: Command failed [%d]", serial->type->description, result[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 goto no_firmware;
407 }
408
409 hw_info = (struct whiteheat_hw_info *)&result[1];
410
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700411 info("%s: Driver %s: Firmware v%d.%02d", serial->type->description,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 DRIVER_VERSION, hw_info->sw_major_rev, hw_info->sw_minor_rev);
413
414 for (i = 0; i < serial->num_ports; i++) {
415 port = serial->port[i];
416
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800417 info = kmalloc(sizeof(struct whiteheat_private), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 if (info == NULL) {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700419 err("%s: Out of memory for port structures\n", serial->type->description);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 goto no_private;
421 }
422
423 spin_lock_init(&info->lock);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200424 mutex_init(&info->deathwarrant);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 info->flags = 0;
426 info->mcr = 0;
David Howellsc4028952006-11-22 14:57:56 +0000427 INIT_WORK(&info->rx_work, rx_data_softint);
428 info->port = port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430 INIT_LIST_HEAD(&info->rx_urbs_free);
431 INIT_LIST_HEAD(&info->rx_urbs_submitted);
432 INIT_LIST_HEAD(&info->rx_urb_q);
433 INIT_LIST_HEAD(&info->tx_urbs_free);
434 INIT_LIST_HEAD(&info->tx_urbs_submitted);
435
436 for (j = 0; j < urb_pool_size; j++) {
437 urb = usb_alloc_urb(0, GFP_KERNEL);
438 if (!urb) {
439 err("No free urbs available");
440 goto no_rx_urb;
441 }
442 buf_size = port->read_urb->transfer_buffer_length;
443 urb->transfer_buffer = kmalloc(buf_size, GFP_KERNEL);
444 if (!urb->transfer_buffer) {
445 err("Couldn't allocate urb buffer");
446 goto no_rx_buf;
447 }
448 wrap = kmalloc(sizeof(*wrap), GFP_KERNEL);
449 if (!wrap) {
450 err("Couldn't allocate urb wrapper");
451 goto no_rx_wrap;
452 }
453 usb_fill_bulk_urb(urb, serial->dev,
454 usb_rcvbulkpipe(serial->dev,
455 port->bulk_in_endpointAddress),
456 urb->transfer_buffer, buf_size,
457 whiteheat_read_callback, port);
458 wrap->urb = urb;
459 list_add(&wrap->list, &info->rx_urbs_free);
460
461 urb = usb_alloc_urb(0, GFP_KERNEL);
462 if (!urb) {
463 err("No free urbs available");
464 goto no_tx_urb;
465 }
466 buf_size = port->write_urb->transfer_buffer_length;
467 urb->transfer_buffer = kmalloc(buf_size, GFP_KERNEL);
468 if (!urb->transfer_buffer) {
469 err("Couldn't allocate urb buffer");
470 goto no_tx_buf;
471 }
472 wrap = kmalloc(sizeof(*wrap), GFP_KERNEL);
473 if (!wrap) {
474 err("Couldn't allocate urb wrapper");
475 goto no_tx_wrap;
476 }
477 usb_fill_bulk_urb(urb, serial->dev,
478 usb_sndbulkpipe(serial->dev,
479 port->bulk_out_endpointAddress),
480 urb->transfer_buffer, buf_size,
481 whiteheat_write_callback, port);
482 wrap->urb = urb;
483 list_add(&wrap->list, &info->tx_urbs_free);
484 }
485
486 usb_set_serial_port_data(port, info);
487 }
488
Robert P. J. Day5cbded52006-12-13 00:35:56 -0800489 command_info = kmalloc(sizeof(struct whiteheat_command_private), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 if (command_info == NULL) {
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700491 err("%s: Out of memory for port structures\n", serial->type->description);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 goto no_command_private;
493 }
494
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200495 mutex_init(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 command_info->port_running = 0;
497 init_waitqueue_head(&command_info->wait_command);
498 usb_set_serial_port_data(command_port, command_info);
499 command_port->write_urb->complete = command_port_write_callback;
500 command_port->read_urb->complete = command_port_read_callback;
501 kfree(result);
502 kfree(command);
503
504 return 0;
505
506no_firmware:
507 /* Firmware likely not running */
Greg Kroah-Hartman269bda12005-06-20 21:15:16 -0700508 err("%s: Unable to retrieve firmware version, try replugging\n", serial->type->description);
509 err("%s: If the firmware is not running (status led not blinking)\n", serial->type->description);
510 err("%s: please contact support@connecttech.com\n", serial->type->description);
Jesper Juhl67ca0282006-04-23 19:59:23 +0200511 kfree(result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 return -ENODEV;
513
514no_command_private:
515 for (i = serial->num_ports - 1; i >= 0; i--) {
516 port = serial->port[i];
517 info = usb_get_serial_port_data(port);
518 for (j = urb_pool_size - 1; j >= 0; j--) {
519 tmp = list_first(&info->tx_urbs_free);
520 list_del(tmp);
521 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
522 urb = wrap->urb;
523 kfree(wrap);
524no_tx_wrap:
525 kfree(urb->transfer_buffer);
526no_tx_buf:
527 usb_free_urb(urb);
528no_tx_urb:
529 tmp = list_first(&info->rx_urbs_free);
530 list_del(tmp);
531 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
532 urb = wrap->urb;
533 kfree(wrap);
534no_rx_wrap:
535 kfree(urb->transfer_buffer);
536no_rx_buf:
537 usb_free_urb(urb);
538no_rx_urb:
539 ;
540 }
541 kfree(info);
542no_private:
543 ;
544 }
545 kfree(result);
546no_result_buffer:
547 kfree(command);
548no_command_buffer:
549 return -ENOMEM;
550}
551
552
553static void whiteheat_shutdown (struct usb_serial *serial)
554{
555 struct usb_serial_port *command_port;
556 struct usb_serial_port *port;
557 struct whiteheat_private *info;
558 struct whiteheat_urb_wrap *wrap;
559 struct urb *urb;
560 struct list_head *tmp;
561 struct list_head *tmp2;
562 int i;
563
Harvey Harrison441b62c2008-03-03 16:08:34 -0800564 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
566 /* free up our private data for our command port */
567 command_port = serial->port[COMMAND_PORT];
568 kfree (usb_get_serial_port_data(command_port));
569
570 for (i = 0; i < serial->num_ports; i++) {
571 port = serial->port[i];
572 info = usb_get_serial_port_data(port);
573 list_for_each_safe(tmp, tmp2, &info->rx_urbs_free) {
574 list_del(tmp);
575 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
576 urb = wrap->urb;
577 kfree(wrap);
578 kfree(urb->transfer_buffer);
579 usb_free_urb(urb);
580 }
581 list_for_each_safe(tmp, tmp2, &info->tx_urbs_free) {
582 list_del(tmp);
583 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
584 urb = wrap->urb;
585 kfree(wrap);
586 kfree(urb->transfer_buffer);
587 usb_free_urb(urb);
588 }
589 kfree(info);
590 }
591
592 return;
593}
594
595
596static int whiteheat_open (struct usb_serial_port *port, struct file *filp)
597{
598 int retval = 0;
Alan Cox606d0992006-12-08 02:38:45 -0800599 struct ktermios old_term;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Harvey Harrison441b62c2008-03-03 16:08:34 -0800601 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
603 retval = start_command_port(port->serial);
604 if (retval)
605 goto exit;
606
Oliver Neukume58679802007-12-20 12:23:03 +0100607 port->tty->low_latency = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 /* send an open port command */
610 retval = firm_open(port);
611 if (retval) {
612 stop_command_port(port->serial);
613 goto exit;
614 }
615
616 retval = firm_purge(port, WHITEHEAT_PURGE_RX | WHITEHEAT_PURGE_TX);
617 if (retval) {
618 firm_close(port);
619 stop_command_port(port->serial);
620 goto exit;
621 }
622
623 old_term.c_cflag = ~port->tty->termios->c_cflag;
624 old_term.c_iflag = ~port->tty->termios->c_iflag;
625 whiteheat_set_termios(port, &old_term);
626
627 /* Work around HCD bugs */
628 usb_clear_halt(port->serial->dev, port->read_urb->pipe);
629 usb_clear_halt(port->serial->dev, port->write_urb->pipe);
630
631 /* Start reading from the device */
632 retval = start_port_read(port);
633 if (retval) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800634 err("%s - failed submitting read urb, error %d", __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 firm_close(port);
636 stop_command_port(port->serial);
637 goto exit;
638 }
639
640exit:
Harvey Harrison441b62c2008-03-03 16:08:34 -0800641 dbg("%s - exit, retval = %d", __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 return retval;
643}
644
645
646static void whiteheat_close(struct usb_serial_port *port, struct file * filp)
647{
648 struct whiteheat_private *info = usb_get_serial_port_data(port);
649 struct whiteheat_urb_wrap *wrap;
650 struct urb *urb;
651 struct list_head *tmp;
652 struct list_head *tmp2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Harvey Harrison441b62c2008-03-03 16:08:34 -0800654 dbg("%s - port %d", __func__, port->number);
Oliver Neukume33fe4d2008-01-21 17:44:10 +0100655
656 mutex_lock(&port->serial->disc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 /* filp is NULL when called from usb_serial_disconnect */
Oliver Neukume33fe4d2008-01-21 17:44:10 +0100658 if ((filp && (tty_hung_up_p(filp))) || port->serial->disconnected) {
659 mutex_unlock(&port->serial->disc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660 return;
661 }
Oliver Neukume33fe4d2008-01-21 17:44:10 +0100662 mutex_unlock(&port->serial->disc_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 port->tty->closing = 1;
665
666/*
667 * Not currently in use; tty_wait_until_sent() calls
668 * serial_chars_in_buffer() which deadlocks on the second semaphore
669 * acquisition. This should be fixed at some point. Greg's been
670 * notified.
671 if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) {
672 tty_wait_until_sent(port->tty, CLOSING_DELAY);
673 }
674*/
675
676 if (port->tty->driver->flush_buffer)
677 port->tty->driver->flush_buffer(port->tty);
678 tty_ldisc_flush(port->tty);
679
680 firm_report_tx_done(port);
681
682 firm_close(port);
683
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200684printk(KERN_ERR"Before processing rx_urbs_submitted.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 /* shutdown our bulk reads and writes */
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200686 mutex_lock(&info->deathwarrant);
687 spin_lock_irq(&info->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688 list_for_each_safe(tmp, tmp2, &info->rx_urbs_submitted) {
689 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
690 urb = wrap->urb;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200691 list_del(tmp);
692 spin_unlock_irq(&info->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 usb_kill_urb(urb);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200694 spin_lock_irq(&info->lock);
695 list_add(tmp, &info->rx_urbs_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 }
Akinobu Mita179e0912006-06-26 00:24:41 -0700697 list_for_each_safe(tmp, tmp2, &info->rx_urb_q)
698 list_move(tmp, &info->rx_urbs_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 list_for_each_safe(tmp, tmp2, &info->tx_urbs_submitted) {
700 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
701 urb = wrap->urb;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200702 list_del(tmp);
703 spin_unlock_irq(&info->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 usb_kill_urb(urb);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200705 spin_lock_irq(&info->lock);
706 list_add(tmp, &info->tx_urbs_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 }
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200708 spin_unlock_irq(&info->lock);
709 mutex_unlock(&info->deathwarrant);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710
711 stop_command_port(port->serial);
712
713 port->tty->closing = 0;
714}
715
716
717static int whiteheat_write(struct usb_serial_port *port, const unsigned char *buf, int count)
718{
719 struct usb_serial *serial = port->serial;
720 struct whiteheat_private *info = usb_get_serial_port_data(port);
721 struct whiteheat_urb_wrap *wrap;
722 struct urb *urb;
723 int result;
724 int bytes;
725 int sent = 0;
726 unsigned long flags;
727 struct list_head *tmp;
728
Harvey Harrison441b62c2008-03-03 16:08:34 -0800729 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730
731 if (count == 0) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800732 dbg("%s - write request of 0 bytes", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 return (0);
734 }
735
736 while (count) {
737 spin_lock_irqsave(&info->lock, flags);
738 if (list_empty(&info->tx_urbs_free)) {
739 spin_unlock_irqrestore(&info->lock, flags);
740 break;
741 }
742 tmp = list_first(&info->tx_urbs_free);
743 list_del(tmp);
744 spin_unlock_irqrestore(&info->lock, flags);
745
746 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
747 urb = wrap->urb;
748 bytes = (count > port->bulk_out_size) ? port->bulk_out_size : count;
749 memcpy (urb->transfer_buffer, buf + sent, bytes);
750
Harvey Harrison441b62c2008-03-03 16:08:34 -0800751 usb_serial_debug_data(debug, &port->dev, __func__, bytes, urb->transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
753 urb->dev = serial->dev;
754 urb->transfer_buffer_length = bytes;
755 result = usb_submit_urb(urb, GFP_ATOMIC);
756 if (result) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800757 err("%s - failed submitting write urb, error %d", __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 sent = result;
759 spin_lock_irqsave(&info->lock, flags);
760 list_add(tmp, &info->tx_urbs_free);
761 spin_unlock_irqrestore(&info->lock, flags);
762 break;
763 } else {
764 sent += bytes;
765 count -= bytes;
766 spin_lock_irqsave(&info->lock, flags);
767 list_add(tmp, &info->tx_urbs_submitted);
768 spin_unlock_irqrestore(&info->lock, flags);
769 }
770 }
771
772 return sent;
773}
774
775
776static int whiteheat_write_room(struct usb_serial_port *port)
777{
778 struct whiteheat_private *info = usb_get_serial_port_data(port);
779 struct list_head *tmp;
780 int room = 0;
781 unsigned long flags;
782
Harvey Harrison441b62c2008-03-03 16:08:34 -0800783 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 spin_lock_irqsave(&info->lock, flags);
786 list_for_each(tmp, &info->tx_urbs_free)
787 room++;
788 spin_unlock_irqrestore(&info->lock, flags);
789 room *= port->bulk_out_size;
790
Harvey Harrison441b62c2008-03-03 16:08:34 -0800791 dbg("%s - returns %d", __func__, room);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 return (room);
793}
794
795
796static int whiteheat_tiocmget (struct usb_serial_port *port, struct file *file)
797{
798 struct whiteheat_private *info = usb_get_serial_port_data(port);
799 unsigned int modem_signals = 0;
800
Harvey Harrison441b62c2008-03-03 16:08:34 -0800801 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
803 firm_get_dtr_rts(port);
804 if (info->mcr & UART_MCR_DTR)
805 modem_signals |= TIOCM_DTR;
806 if (info->mcr & UART_MCR_RTS)
807 modem_signals |= TIOCM_RTS;
808
809 return modem_signals;
810}
811
812
813static int whiteheat_tiocmset (struct usb_serial_port *port, struct file *file,
814 unsigned int set, unsigned int clear)
815{
816 struct whiteheat_private *info = usb_get_serial_port_data(port);
817
Harvey Harrison441b62c2008-03-03 16:08:34 -0800818 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 if (set & TIOCM_RTS)
821 info->mcr |= UART_MCR_RTS;
822 if (set & TIOCM_DTR)
823 info->mcr |= UART_MCR_DTR;
824
825 if (clear & TIOCM_RTS)
826 info->mcr &= ~UART_MCR_RTS;
827 if (clear & TIOCM_DTR)
828 info->mcr &= ~UART_MCR_DTR;
829
830 firm_set_dtr(port, info->mcr & UART_MCR_DTR);
831 firm_set_rts(port, info->mcr & UART_MCR_RTS);
832 return 0;
833}
834
835
836static int whiteheat_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
837{
838 struct serial_struct serstruct;
839 void __user *user_arg = (void __user *)arg;
840
Harvey Harrison441b62c2008-03-03 16:08:34 -0800841 dbg("%s - port %d, cmd 0x%.4x", __func__, port->number, cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 switch (cmd) {
844 case TIOCGSERIAL:
845 memset(&serstruct, 0, sizeof(serstruct));
846 serstruct.type = PORT_16654;
847 serstruct.line = port->serial->minor;
848 serstruct.port = port->number;
849 serstruct.flags = ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ;
850 serstruct.xmit_fifo_size = port->bulk_out_size;
851 serstruct.custom_divisor = 0;
852 serstruct.baud_base = 460800;
853 serstruct.close_delay = CLOSING_DELAY;
854 serstruct.closing_wait = CLOSING_DELAY;
855
856 if (copy_to_user(user_arg, &serstruct, sizeof(serstruct)))
857 return -EFAULT;
858
859 break;
860
861 case TIOCSSERIAL:
862 if (copy_from_user(&serstruct, user_arg, sizeof(serstruct)))
863 return -EFAULT;
864
865 /*
866 * For now this is ignored. dip sets the ASYNC_[V]HI flags
867 * but this isn't used by us at all. Maybe someone somewhere
868 * will need the custom_divisor setting.
869 */
870
871 break;
872
873 default:
874 break;
875 }
876
877 return -ENOIOCTLCMD;
878}
879
880
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200881static void whiteheat_set_termios(struct usb_serial_port *port, struct ktermios *old_termios)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882{
Harvey Harrison441b62c2008-03-03 16:08:34 -0800883 dbg("%s -port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 firm_setup_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885}
886
887
888static void whiteheat_break_ctl(struct usb_serial_port *port, int break_state) {
889 firm_set_break(port, break_state);
890}
891
892
893static int whiteheat_chars_in_buffer(struct usb_serial_port *port)
894{
895 struct whiteheat_private *info = usb_get_serial_port_data(port);
896 struct list_head *tmp;
897 struct whiteheat_urb_wrap *wrap;
898 int chars = 0;
899 unsigned long flags;
900
Harvey Harrison441b62c2008-03-03 16:08:34 -0800901 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
903 spin_lock_irqsave(&info->lock, flags);
904 list_for_each(tmp, &info->tx_urbs_submitted) {
905 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
906 chars += wrap->urb->transfer_buffer_length;
907 }
908 spin_unlock_irqrestore(&info->lock, flags);
909
Harvey Harrison441b62c2008-03-03 16:08:34 -0800910 dbg ("%s - returns %d", __func__, chars);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200911 return chars;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912}
913
914
915static void whiteheat_throttle (struct usb_serial_port *port)
916{
917 struct whiteheat_private *info = usb_get_serial_port_data(port);
918 unsigned long flags;
919
Harvey Harrison441b62c2008-03-03 16:08:34 -0800920 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
922 spin_lock_irqsave(&info->lock, flags);
923 info->flags |= THROTTLED;
924 spin_unlock_irqrestore(&info->lock, flags);
925
926 return;
927}
928
929
930static void whiteheat_unthrottle (struct usb_serial_port *port)
931{
932 struct whiteheat_private *info = usb_get_serial_port_data(port);
933 int actually_throttled;
934 unsigned long flags;
935
Harvey Harrison441b62c2008-03-03 16:08:34 -0800936 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 spin_lock_irqsave(&info->lock, flags);
939 actually_throttled = info->flags & ACTUALLY_THROTTLED;
940 info->flags &= ~(THROTTLED | ACTUALLY_THROTTLED);
941 spin_unlock_irqrestore(&info->lock, flags);
942
943 if (actually_throttled)
David Howellsc4028952006-11-22 14:57:56 +0000944 rx_data_softint(&info->rx_work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 return;
947}
948
949
950/*****************************************************************************
951 * Connect Tech's White Heat callback routines
952 *****************************************************************************/
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200953static void command_port_write_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954{
Greg Kroah-Hartman05400012007-06-15 15:44:13 -0700955 int status = urb->status;
956
Harvey Harrison441b62c2008-03-03 16:08:34 -0800957 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Greg Kroah-Hartman05400012007-06-15 15:44:13 -0700959 if (status) {
960 dbg("nonzero urb status: %d", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 return;
962 }
963}
964
965
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200966static void command_port_read_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967{
Ming Leicdc97792008-02-24 18:41:47 +0800968 struct usb_serial_port *command_port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 struct whiteheat_command_private *command_info;
Greg Kroah-Hartman05400012007-06-15 15:44:13 -0700970 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 unsigned char *data = urb->transfer_buffer;
972 int result;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Harvey Harrison441b62c2008-03-03 16:08:34 -0800974 dbg("%s", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 command_info = usb_get_serial_port_data(command_port);
977 if (!command_info) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800978 dbg ("%s - command_info is NULL, exiting.", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 return;
980 }
Greg Kroah-Hartman05400012007-06-15 15:44:13 -0700981 if (status) {
Harvey Harrison441b62c2008-03-03 16:08:34 -0800982 dbg("%s - nonzero urb status: %d", __func__, status);
Greg Kroah-Hartman05400012007-06-15 15:44:13 -0700983 if (status != -ENOENT)
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200984 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
985 wake_up(&command_info->wait_command);
986 return;
987 }
988
Harvey Harrison441b62c2008-03-03 16:08:34 -0800989 usb_serial_debug_data(debug, &command_port->dev, __func__, urb->actual_length, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
991 if (data[0] == WHITEHEAT_CMD_COMPLETE) {
992 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200993 wake_up(&command_info->wait_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 } else if (data[0] == WHITEHEAT_CMD_FAILURE) {
995 command_info->command_finished = WHITEHEAT_CMD_FAILURE;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +0200996 wake_up(&command_info->wait_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 } else if (data[0] == WHITEHEAT_EVENT) {
998 /* These are unsolicited reports from the firmware, hence no waiting command to wakeup */
Harvey Harrison441b62c2008-03-03 16:08:34 -0800999 dbg("%s - event received", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 } else if (data[0] == WHITEHEAT_GET_DTR_RTS) {
1001 memcpy(command_info->result_buffer, &data[1], urb->actual_length - 1);
1002 command_info->command_finished = WHITEHEAT_CMD_COMPLETE;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001003 wake_up(&command_info->wait_command);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 } else {
Harvey Harrison441b62c2008-03-03 16:08:34 -08001005 dbg("%s - bad reply from firmware", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 }
1007
1008 /* Continue trying to always read */
1009 command_port->read_urb->dev = command_port->serial->dev;
1010 result = usb_submit_urb(command_port->read_urb, GFP_ATOMIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 if (result)
Harvey Harrison441b62c2008-03-03 16:08:34 -08001012 dbg("%s - failed resubmitting read urb, error %d", __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013}
1014
1015
David Howells7d12e782006-10-05 14:55:46 +01001016static void whiteheat_read_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017{
Ming Leicdc97792008-02-24 18:41:47 +08001018 struct usb_serial_port *port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 struct whiteheat_urb_wrap *wrap;
1020 unsigned char *data = urb->transfer_buffer;
1021 struct whiteheat_private *info = usb_get_serial_port_data(port);
Greg Kroah-Hartman05400012007-06-15 15:44:13 -07001022 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Harvey Harrison441b62c2008-03-03 16:08:34 -08001024 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025
1026 spin_lock(&info->lock);
1027 wrap = urb_to_wrap(urb, &info->rx_urbs_submitted);
1028 if (!wrap) {
1029 spin_unlock(&info->lock);
Harvey Harrison441b62c2008-03-03 16:08:34 -08001030 err("%s - Not my urb!", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 return;
1032 }
1033 list_del(&wrap->list);
1034 spin_unlock(&info->lock);
1035
Greg Kroah-Hartman05400012007-06-15 15:44:13 -07001036 if (status) {
1037 dbg("%s - nonzero read bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001038 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 spin_lock(&info->lock);
1040 list_add(&wrap->list, &info->rx_urbs_free);
1041 spin_unlock(&info->lock);
1042 return;
1043 }
1044
Harvey Harrison441b62c2008-03-03 16:08:34 -08001045 usb_serial_debug_data(debug, &port->dev, __func__, urb->actual_length, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047 spin_lock(&info->lock);
1048 list_add_tail(&wrap->list, &info->rx_urb_q);
1049 if (info->flags & THROTTLED) {
1050 info->flags |= ACTUALLY_THROTTLED;
1051 spin_unlock(&info->lock);
1052 return;
1053 }
1054 spin_unlock(&info->lock);
1055
1056 schedule_work(&info->rx_work);
1057}
1058
1059
David Howells7d12e782006-10-05 14:55:46 +01001060static void whiteheat_write_callback(struct urb *urb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
Ming Leicdc97792008-02-24 18:41:47 +08001062 struct usb_serial_port *port = urb->context;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063 struct whiteheat_private *info = usb_get_serial_port_data(port);
1064 struct whiteheat_urb_wrap *wrap;
Greg Kroah-Hartman05400012007-06-15 15:44:13 -07001065 int status = urb->status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066
Harvey Harrison441b62c2008-03-03 16:08:34 -08001067 dbg("%s - port %d", __func__, port->number);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068
1069 spin_lock(&info->lock);
1070 wrap = urb_to_wrap(urb, &info->tx_urbs_submitted);
1071 if (!wrap) {
1072 spin_unlock(&info->lock);
Harvey Harrison441b62c2008-03-03 16:08:34 -08001073 err("%s - Not my urb!", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 return;
1075 }
Akinobu Mita179e0912006-06-26 00:24:41 -07001076 list_move(&wrap->list, &info->tx_urbs_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 spin_unlock(&info->lock);
1078
Greg Kroah-Hartman05400012007-06-15 15:44:13 -07001079 if (status) {
1080 dbg("%s - nonzero write bulk status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -08001081 __func__, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 return;
1083 }
1084
Pete Zaitcevcf2c7482006-05-22 21:58:49 -07001085 usb_serial_port_softint(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086}
1087
1088
1089/*****************************************************************************
1090 * Connect Tech's White Heat firmware interface
1091 *****************************************************************************/
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001092static int firm_send_command(struct usb_serial_port *port, __u8 command, __u8 *data, __u8 datasize)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093{
1094 struct usb_serial_port *command_port;
1095 struct whiteheat_command_private *command_info;
1096 struct whiteheat_private *info;
1097 __u8 *transfer_buffer;
1098 int retval = 0;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001099 int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Harvey Harrison441b62c2008-03-03 16:08:34 -08001101 dbg("%s - command %d", __func__, command);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102
1103 command_port = port->serial->port[COMMAND_PORT];
1104 command_info = usb_get_serial_port_data(command_port);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001105 mutex_lock(&command_info->mutex);
Richard Knutsson38c3cb52007-03-26 22:00:28 -08001106 command_info->command_finished = false;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
1108 transfer_buffer = (__u8 *)command_port->write_urb->transfer_buffer;
1109 transfer_buffer[0] = command;
1110 memcpy (&transfer_buffer[1], data, datasize);
1111 command_port->write_urb->transfer_buffer_length = datasize + 1;
1112 command_port->write_urb->dev = port->serial->dev;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001113 retval = usb_submit_urb (command_port->write_urb, GFP_NOIO);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 if (retval) {
Harvey Harrison441b62c2008-03-03 16:08:34 -08001115 dbg("%s - submit urb failed", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 goto exit;
1117 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001118
1119 /* wait for the command to complete */
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001120 t = wait_event_timeout(command_info->wait_command,
Richard Knutsson38c3cb52007-03-26 22:00:28 -08001121 (bool)command_info->command_finished, COMMAND_TIMEOUT);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001122 if (!t)
1123 usb_kill_urb(command_port->write_urb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Richard Knutsson38c3cb52007-03-26 22:00:28 -08001125 if (command_info->command_finished == false) {
Harvey Harrison441b62c2008-03-03 16:08:34 -08001126 dbg("%s - command timed out.", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 retval = -ETIMEDOUT;
1128 goto exit;
1129 }
1130
1131 if (command_info->command_finished == WHITEHEAT_CMD_FAILURE) {
Harvey Harrison441b62c2008-03-03 16:08:34 -08001132 dbg("%s - command failed.", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133 retval = -EIO;
1134 goto exit;
1135 }
1136
1137 if (command_info->command_finished == WHITEHEAT_CMD_COMPLETE) {
Harvey Harrison441b62c2008-03-03 16:08:34 -08001138 dbg("%s - command completed.", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 switch (command) {
1140 case WHITEHEAT_GET_DTR_RTS:
1141 info = usb_get_serial_port_data(port);
1142 memcpy(&info->mcr, command_info->result_buffer, sizeof(struct whiteheat_dr_info));
1143 break;
1144 }
1145 }
1146
1147exit:
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001148 mutex_unlock(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 return retval;
1150}
1151
1152
1153static int firm_open(struct usb_serial_port *port) {
1154 struct whiteheat_simple open_command;
1155
1156 open_command.port = port->number - port->serial->minor + 1;
1157 return firm_send_command(port, WHITEHEAT_OPEN, (__u8 *)&open_command, sizeof(open_command));
1158}
1159
1160
1161static int firm_close(struct usb_serial_port *port) {
1162 struct whiteheat_simple close_command;
1163
1164 close_command.port = port->number - port->serial->minor + 1;
1165 return firm_send_command(port, WHITEHEAT_CLOSE, (__u8 *)&close_command, sizeof(close_command));
1166}
1167
1168
1169static int firm_setup_port(struct usb_serial_port *port) {
1170 struct whiteheat_port_settings port_settings;
1171 unsigned int cflag = port->tty->termios->c_cflag;
1172
1173 port_settings.port = port->number + 1;
1174
1175 /* get the byte size */
1176 switch (cflag & CSIZE) {
1177 case CS5: port_settings.bits = 5; break;
1178 case CS6: port_settings.bits = 6; break;
1179 case CS7: port_settings.bits = 7; break;
1180 default:
1181 case CS8: port_settings.bits = 8; break;
1182 }
Harvey Harrison441b62c2008-03-03 16:08:34 -08001183 dbg("%s - data bits = %d", __func__, port_settings.bits);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001184
1185 /* determine the parity */
1186 if (cflag & PARENB)
1187 if (cflag & CMSPAR)
1188 if (cflag & PARODD)
1189 port_settings.parity = WHITEHEAT_PAR_MARK;
1190 else
1191 port_settings.parity = WHITEHEAT_PAR_SPACE;
1192 else
1193 if (cflag & PARODD)
1194 port_settings.parity = WHITEHEAT_PAR_ODD;
1195 else
1196 port_settings.parity = WHITEHEAT_PAR_EVEN;
1197 else
1198 port_settings.parity = WHITEHEAT_PAR_NONE;
Harvey Harrison441b62c2008-03-03 16:08:34 -08001199 dbg("%s - parity = %c", __func__, port_settings.parity);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
1201 /* figure out the stop bits requested */
1202 if (cflag & CSTOPB)
1203 port_settings.stop = 2;
1204 else
1205 port_settings.stop = 1;
Harvey Harrison441b62c2008-03-03 16:08:34 -08001206 dbg("%s - stop bits = %d", __func__, port_settings.stop);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
1208 /* figure out the flow control settings */
1209 if (cflag & CRTSCTS)
1210 port_settings.hflow = (WHITEHEAT_HFLOW_CTS | WHITEHEAT_HFLOW_RTS);
1211 else
1212 port_settings.hflow = WHITEHEAT_HFLOW_NONE;
Harvey Harrison441b62c2008-03-03 16:08:34 -08001213 dbg("%s - hardware flow control = %s %s %s %s", __func__,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 (port_settings.hflow & WHITEHEAT_HFLOW_CTS) ? "CTS" : "",
1215 (port_settings.hflow & WHITEHEAT_HFLOW_RTS) ? "RTS" : "",
1216 (port_settings.hflow & WHITEHEAT_HFLOW_DSR) ? "DSR" : "",
1217 (port_settings.hflow & WHITEHEAT_HFLOW_DTR) ? "DTR" : "");
1218
1219 /* determine software flow control */
1220 if (I_IXOFF(port->tty))
1221 port_settings.sflow = WHITEHEAT_SFLOW_RXTX;
1222 else
1223 port_settings.sflow = WHITEHEAT_SFLOW_NONE;
Harvey Harrison441b62c2008-03-03 16:08:34 -08001224 dbg("%s - software flow control = %c", __func__, port_settings.sflow);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001225
1226 port_settings.xon = START_CHAR(port->tty);
1227 port_settings.xoff = STOP_CHAR(port->tty);
Harvey Harrison441b62c2008-03-03 16:08:34 -08001228 dbg("%s - XON = %2x, XOFF = %2x", __func__, port_settings.xon, port_settings.xoff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 /* get the baud rate wanted */
1231 port_settings.baud = tty_get_baud_rate(port->tty);
Harvey Harrison441b62c2008-03-03 16:08:34 -08001232 dbg("%s - baud rate = %d", __func__, port_settings.baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
Alan Cox01d1df22007-10-18 01:24:23 -07001234 /* fixme: should set validated settings */
1235 tty_encode_baud_rate(port->tty, port_settings.baud, port_settings.baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 /* handle any settings that aren't specified in the tty structure */
1237 port_settings.lloop = 0;
1238
1239 /* now send the message to the device */
1240 return firm_send_command(port, WHITEHEAT_SETUP_PORT, (__u8 *)&port_settings, sizeof(port_settings));
1241}
1242
1243
1244static int firm_set_rts(struct usb_serial_port *port, __u8 onoff) {
1245 struct whiteheat_set_rdb rts_command;
1246
1247 rts_command.port = port->number - port->serial->minor + 1;
1248 rts_command.state = onoff;
1249 return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&rts_command, sizeof(rts_command));
1250}
1251
1252
1253static int firm_set_dtr(struct usb_serial_port *port, __u8 onoff) {
1254 struct whiteheat_set_rdb dtr_command;
1255
1256 dtr_command.port = port->number - port->serial->minor + 1;
1257 dtr_command.state = onoff;
1258 return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&dtr_command, sizeof(dtr_command));
1259}
1260
1261
1262static int firm_set_break(struct usb_serial_port *port, __u8 onoff) {
1263 struct whiteheat_set_rdb break_command;
1264
1265 break_command.port = port->number - port->serial->minor + 1;
1266 break_command.state = onoff;
1267 return firm_send_command(port, WHITEHEAT_SET_RTS, (__u8 *)&break_command, sizeof(break_command));
1268}
1269
1270
1271static int firm_purge(struct usb_serial_port *port, __u8 rxtx) {
1272 struct whiteheat_purge purge_command;
1273
1274 purge_command.port = port->number - port->serial->minor + 1;
1275 purge_command.what = rxtx;
1276 return firm_send_command(port, WHITEHEAT_PURGE, (__u8 *)&purge_command, sizeof(purge_command));
1277}
1278
1279
1280static int firm_get_dtr_rts(struct usb_serial_port *port) {
1281 struct whiteheat_simple get_dr_command;
1282
1283 get_dr_command.port = port->number - port->serial->minor + 1;
1284 return firm_send_command(port, WHITEHEAT_GET_DTR_RTS, (__u8 *)&get_dr_command, sizeof(get_dr_command));
1285}
1286
1287
1288static int firm_report_tx_done(struct usb_serial_port *port) {
1289 struct whiteheat_simple close_command;
1290
1291 close_command.port = port->number - port->serial->minor + 1;
1292 return firm_send_command(port, WHITEHEAT_REPORT_TX_DONE, (__u8 *)&close_command, sizeof(close_command));
1293}
1294
1295
1296/*****************************************************************************
1297 * Connect Tech's White Heat utility functions
1298 *****************************************************************************/
1299static int start_command_port(struct usb_serial *serial)
1300{
1301 struct usb_serial_port *command_port;
1302 struct whiteheat_command_private *command_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 int retval = 0;
1304
1305 command_port = serial->port[COMMAND_PORT];
1306 command_info = usb_get_serial_port_data(command_port);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001307 mutex_lock(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 if (!command_info->port_running) {
1309 /* Work around HCD bugs */
1310 usb_clear_halt(serial->dev, command_port->read_urb->pipe);
1311
1312 command_port->read_urb->dev = serial->dev;
1313 retval = usb_submit_urb(command_port->read_urb, GFP_KERNEL);
1314 if (retval) {
Harvey Harrison441b62c2008-03-03 16:08:34 -08001315 err("%s - failed submitting read urb, error %d", __func__, retval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 goto exit;
1317 }
1318 }
1319 command_info->port_running++;
1320
1321exit:
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001322 mutex_unlock(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 return retval;
1324}
1325
1326
1327static void stop_command_port(struct usb_serial *serial)
1328{
1329 struct usb_serial_port *command_port;
1330 struct whiteheat_command_private *command_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331
1332 command_port = serial->port[COMMAND_PORT];
1333 command_info = usb_get_serial_port_data(command_port);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001334 mutex_lock(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 command_info->port_running--;
1336 if (!command_info->port_running)
1337 usb_kill_urb(command_port->read_urb);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001338 mutex_unlock(&command_info->mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339}
1340
1341
1342static int start_port_read(struct usb_serial_port *port)
1343{
1344 struct whiteheat_private *info = usb_get_serial_port_data(port);
1345 struct whiteheat_urb_wrap *wrap;
1346 struct urb *urb;
1347 int retval = 0;
1348 unsigned long flags;
1349 struct list_head *tmp;
1350 struct list_head *tmp2;
1351
1352 spin_lock_irqsave(&info->lock, flags);
1353
1354 list_for_each_safe(tmp, tmp2, &info->rx_urbs_free) {
1355 list_del(tmp);
1356 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
1357 urb = wrap->urb;
1358 urb->dev = port->serial->dev;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001359 spin_unlock_irqrestore(&info->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 retval = usb_submit_urb(urb, GFP_KERNEL);
1361 if (retval) {
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001362 spin_lock_irqsave(&info->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 list_add(tmp, &info->rx_urbs_free);
1364 list_for_each_safe(tmp, tmp2, &info->rx_urbs_submitted) {
1365 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
1366 urb = wrap->urb;
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001367 list_del(tmp);
1368 spin_unlock_irqrestore(&info->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 usb_kill_urb(urb);
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001370 spin_lock_irqsave(&info->lock, flags);
1371 list_add(tmp, &info->rx_urbs_free);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 }
1373 break;
1374 }
Oliver Neukum08a2b3b2007-05-24 13:52:51 +02001375 spin_lock_irqsave(&info->lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 list_add(tmp, &info->rx_urbs_submitted);
1377 }
1378
1379 spin_unlock_irqrestore(&info->lock, flags);
1380
1381 return retval;
1382}
1383
1384
1385static struct whiteheat_urb_wrap *urb_to_wrap(struct urb* urb, struct list_head *head)
1386{
1387 struct whiteheat_urb_wrap *wrap;
1388 struct list_head *tmp;
1389
1390 list_for_each(tmp, head) {
1391 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
1392 if (wrap->urb == urb)
1393 return wrap;
1394 }
1395
1396 return NULL;
1397}
1398
1399
1400static struct list_head *list_first(struct list_head *head)
1401{
1402 return head->next;
1403}
1404
1405
David Howellsc4028952006-11-22 14:57:56 +00001406static void rx_data_softint(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407{
David Howellsc4028952006-11-22 14:57:56 +00001408 struct whiteheat_private *info =
1409 container_of(work, struct whiteheat_private, rx_work);
1410 struct usb_serial_port *port = info->port;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411 struct tty_struct *tty = port->tty;
1412 struct whiteheat_urb_wrap *wrap;
1413 struct urb *urb;
1414 unsigned long flags;
1415 struct list_head *tmp;
1416 struct list_head *tmp2;
1417 int result;
1418 int sent = 0;
1419
1420 spin_lock_irqsave(&info->lock, flags);
1421 if (info->flags & THROTTLED) {
1422 spin_unlock_irqrestore(&info->lock, flags);
1423 return;
1424 }
1425
1426 list_for_each_safe(tmp, tmp2, &info->rx_urb_q) {
1427 list_del(tmp);
1428 spin_unlock_irqrestore(&info->lock, flags);
1429
1430 wrap = list_entry(tmp, struct whiteheat_urb_wrap, list);
1431 urb = wrap->urb;
1432
1433 if (tty && urb->actual_length) {
Alan Cox33f0f882006-01-09 20:54:13 -08001434 int len = tty_buffer_request_room(tty, urb->actual_length);
1435 /* This stuff can go away now I suspect */
1436 if (unlikely(len < urb->actual_length)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 spin_lock_irqsave(&info->lock, flags);
1438 list_add(tmp, &info->rx_urb_q);
1439 spin_unlock_irqrestore(&info->lock, flags);
1440 tty_flip_buffer_push(tty);
1441 schedule_work(&info->rx_work);
1442 return;
1443 }
Alan Cox33f0f882006-01-09 20:54:13 -08001444 tty_insert_flip_string(tty, urb->transfer_buffer, len);
1445 sent += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 }
1447
1448 urb->dev = port->serial->dev;
1449 result = usb_submit_urb(urb, GFP_ATOMIC);
1450 if (result) {
Harvey Harrison441b62c2008-03-03 16:08:34 -08001451 err("%s - failed resubmitting read urb, error %d", __func__, result);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 spin_lock_irqsave(&info->lock, flags);
1453 list_add(tmp, &info->rx_urbs_free);
1454 continue;
1455 }
1456
1457 spin_lock_irqsave(&info->lock, flags);
1458 list_add(tmp, &info->rx_urbs_submitted);
1459 }
1460 spin_unlock_irqrestore(&info->lock, flags);
1461
1462 if (sent)
1463 tty_flip_buffer_push(tty);
1464}
1465
1466
1467/*****************************************************************************
1468 * Connect Tech's White Heat module functions
1469 *****************************************************************************/
1470static int __init whiteheat_init (void)
1471{
1472 int retval;
1473 retval = usb_serial_register(&whiteheat_fake_device);
1474 if (retval)
1475 goto failed_fake_register;
1476 retval = usb_serial_register(&whiteheat_device);
1477 if (retval)
1478 goto failed_device_register;
1479 retval = usb_register(&whiteheat_driver);
1480 if (retval)
1481 goto failed_usb_register;
1482 info(DRIVER_DESC " " DRIVER_VERSION);
1483 return 0;
1484failed_usb_register:
1485 usb_serial_deregister(&whiteheat_device);
1486failed_device_register:
1487 usb_serial_deregister(&whiteheat_fake_device);
1488failed_fake_register:
1489 return retval;
1490}
1491
1492
1493static void __exit whiteheat_exit (void)
1494{
1495 usb_deregister (&whiteheat_driver);
1496 usb_serial_deregister (&whiteheat_fake_device);
1497 usb_serial_deregister (&whiteheat_device);
1498}
1499
1500
1501module_init(whiteheat_init);
1502module_exit(whiteheat_exit);
1503
1504MODULE_AUTHOR( DRIVER_AUTHOR );
1505MODULE_DESCRIPTION( DRIVER_DESC );
1506MODULE_LICENSE("GPL");
1507
1508module_param(urb_pool_size, int, 0);
1509MODULE_PARM_DESC(urb_pool_size, "Number of urbs to use for buffering");
1510
1511module_param(debug, bool, S_IRUGO | S_IWUSR);
1512MODULE_PARM_DESC(debug, "Debug enabled or not");