2 * USB ConnectTech WhiteHEAT driver
7 * Copyright (C) 1999 - 2001
8 * Greg Kroah-Hartman (greg@kroah.com)
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.
15 * See Documentation/usb/usb-serial.txt for more information on using this driver
17 * (10/09/2002) Stuart MacDonald (stuartm@connecttech.com)
18 * Upgrade to full working driver
21 * switched from using spinlock to a semaphore, which fixes lots of problems.
24 * Identify version on module load.
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.
31 * (11/01/2000) Adam J. Richter
32 * usb_device_id table support
35 * Fixed bug with urb->dev not being set properly, now that the usb
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
47 * Removed DEBUG #ifdefs with call to usb_serial_debug_data
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
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
60 * First cut at open and close commands. Data can flow through the ports at
64 * Split driver up into device specific pieces.
68 #include <linux/config.h>
69 #include <linux/kernel.h>
70 #include <linux/errno.h>
71 #include <linux/init.h>
72 #include <linux/slab.h>
73 #include <linux/tty.h>
74 #include <linux/tty_driver.h>
75 #include <linux/tty_flip.h>
76 #include <linux/module.h>
77 #include <linux/spinlock.h>
78 #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>
83 #include "usb-serial.h"
84 #include "whiteheat_fw.h" /* firmware for the ConnectTech WhiteHEAT device */
85 #include "whiteheat.h" /* WhiteHEAT specific commands */
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"
100 #define CONNECT_TECH_VENDOR_ID 0x0710
101 #define CONNECT_TECH_FAKE_WHITE_HEAT_ID 0x0001
102 #define CONNECT_TECH_WHITE_HEAT_ID 0x8001
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.
111 static struct usb_device_id id_table_std
[] = {
112 { USB_DEVICE(CONNECT_TECH_VENDOR_ID
, CONNECT_TECH_WHITE_HEAT_ID
) },
113 { } /* Terminating entry */
116 static struct usb_device_id id_table_prerenumeration
[] = {
117 { USB_DEVICE(CONNECT_TECH_VENDOR_ID
, CONNECT_TECH_FAKE_WHITE_HEAT_ID
) },
118 { } /* Terminating entry */
121 static 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 */
127 MODULE_DEVICE_TABLE (usb
, id_table_combined
);
129 static struct usb_driver whiteheat_driver
= {
130 .owner
= THIS_MODULE
,
132 .probe
= usb_serial_probe
,
133 .disconnect
= usb_serial_disconnect
,
134 .id_table
= id_table_combined
,
137 /* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
138 static int whiteheat_firmware_download (struct usb_serial
*serial
, const struct usb_device_id
*id
);
139 static int whiteheat_firmware_attach (struct usb_serial
*serial
);
141 /* function prototypes for the Connect Tech WhiteHEAT serial converter */
142 static int whiteheat_attach (struct usb_serial
*serial
);
143 static void whiteheat_shutdown (struct usb_serial
*serial
);
144 static int whiteheat_open (struct usb_serial_port
*port
, struct file
*filp
);
145 static void whiteheat_close (struct usb_serial_port
*port
, struct file
*filp
);
146 static int whiteheat_write (struct usb_serial_port
*port
, int from_user
, const unsigned char *buf
, int count
);
147 static int whiteheat_write_room (struct usb_serial_port
*port
);
148 static int whiteheat_ioctl (struct usb_serial_port
*port
, struct file
* file
, unsigned int cmd
, unsigned long arg
);
149 static void whiteheat_set_termios (struct usb_serial_port
*port
, struct termios
* old
);
150 static int whiteheat_tiocmget (struct usb_serial_port
*port
, struct file
*file
);
151 static int whiteheat_tiocmset (struct usb_serial_port
*port
, struct file
*file
, unsigned int set
, unsigned int clear
);
152 static void whiteheat_break_ctl (struct usb_serial_port
*port
, int break_state
);
153 static int whiteheat_chars_in_buffer (struct usb_serial_port
*port
);
154 static void whiteheat_throttle (struct usb_serial_port
*port
);
155 static void whiteheat_unthrottle (struct usb_serial_port
*port
);
156 static void whiteheat_read_callback (struct urb
*urb
, struct pt_regs
*regs
);
157 static void whiteheat_write_callback (struct urb
*urb
, struct pt_regs
*regs
);
159 static struct usb_serial_device_type whiteheat_fake_device
= {
160 .owner
= THIS_MODULE
,
161 .name
= "Connect Tech - WhiteHEAT - (prerenumeration)",
162 .short_name
= "whiteheatnofirm",
163 .id_table
= id_table_prerenumeration
,
164 .num_interrupt_in
= NUM_DONT_CARE
,
165 .num_bulk_in
= NUM_DONT_CARE
,
166 .num_bulk_out
= NUM_DONT_CARE
,
168 .probe
= whiteheat_firmware_download
,
169 .attach
= whiteheat_firmware_attach
,
172 static struct usb_serial_device_type whiteheat_device
= {
173 .owner
= THIS_MODULE
,
174 .name
= "Connect Tech - WhiteHEAT",
175 .short_name
= "whiteheat",
176 .id_table
= id_table_std
,
177 .num_interrupt_in
= NUM_DONT_CARE
,
178 .num_bulk_in
= NUM_DONT_CARE
,
179 .num_bulk_out
= NUM_DONT_CARE
,
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
,
200 struct whiteheat_command_private
{
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];
209 #define THROTTLED 0x01
210 #define ACTUALLY_THROTTLED 0x02
212 static int urb_pool_size
= 8;
214 struct whiteheat_urb_wrap
{
215 struct list_head list
;
219 struct whiteheat_private
{
223 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
;
227 struct list_head tx_urbs_free
;
228 struct list_head tx_urbs_submitted
;
232 /* local function prototypes */
233 static int start_command_port(struct usb_serial
*serial
);
234 static void stop_command_port(struct usb_serial
*serial
);
235 static void command_port_write_callback(struct urb
*urb
, struct pt_regs
*regs
);
236 static void command_port_read_callback(struct urb
*urb
, struct pt_regs
*regs
);
238 static int start_port_read(struct usb_serial_port
*port
);
239 static struct whiteheat_urb_wrap
*urb_to_wrap(struct urb
*urb
, struct list_head
*head
);
240 static struct list_head
*list_first(struct list_head
*head
);
241 static void rx_data_softint(void *private);
243 static int firm_send_command(struct usb_serial_port
*port
, __u8 command
, __u8
*data
, __u8 datasize
);
244 static int firm_open(struct usb_serial_port
*port
);
245 static int firm_close(struct usb_serial_port
*port
);
246 static int firm_setup_port(struct usb_serial_port
*port
);
247 static int firm_set_rts(struct usb_serial_port
*port
, __u8 onoff
);
248 static int firm_set_dtr(struct usb_serial_port
*port
, __u8 onoff
);
249 static int firm_set_break(struct usb_serial_port
*port
, __u8 onoff
);
250 static int firm_purge(struct usb_serial_port
*port
, __u8 rxtx
);
251 static int firm_get_dtr_rts(struct usb_serial_port
*port
);
252 static int firm_report_tx_done(struct usb_serial_port
*port
);
255 #define COMMAND_PORT 4
256 #define COMMAND_TIMEOUT (2*HZ) /* 2 second timeout for a command */
257 #define CLOSING_DELAY (30 * HZ)
260 /*****************************************************************************
261 * Connect Tech's White Heat prerenumeration driver functions
262 *****************************************************************************/
264 /* steps to download the firmware to the WhiteHEAT device:
265 - hold the reset (by writing to the reset bit of the CPUCS register)
266 - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD
267 - release the reset (by writing to the CPUCS register)
268 - download the WH.HEX file for all addresses greater than 0x1b3f using
269 VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD
271 - download the WH.HEX file for all addresses less than 0x1b40 using
272 VENDOR_REQUEST_ANCHOR_LOAD
274 - device renumerated itself and comes up as new device id with all
275 firmware download completed.
277 static int whiteheat_firmware_download (struct usb_serial
*serial
, const struct usb_device_id
*id
)
280 const struct whiteheat_hex_record
*record
;
282 dbg("%s", __FUNCTION__
);
284 response
= ezusb_set_reset (serial
, 1);
286 record
= &whiteheat_loader
[0];
287 while (record
->address
!= 0xffff) {
288 response
= ezusb_writememory (serial
, record
->address
,
289 (unsigned char *)record
->data
, record
->data_size
, 0xa0);
291 err("%s - ezusb_writememory failed for loader (%d %04X %p %d)",
292 __FUNCTION__
, response
, record
->address
, record
->data
, record
->data_size
);
298 response
= ezusb_set_reset (serial
, 0);
300 record
= &whiteheat_firmware
[0];
301 while (record
->address
< 0x1b40) {
304 while (record
->address
!= 0xffff) {
305 response
= ezusb_writememory (serial
, record
->address
,
306 (unsigned char *)record
->data
, record
->data_size
, 0xa3);
308 err("%s - ezusb_writememory failed for first firmware step (%d %04X %p %d)",
309 __FUNCTION__
, response
, record
->address
, record
->data
, record
->data_size
);
315 response
= ezusb_set_reset (serial
, 1);
317 record
= &whiteheat_firmware
[0];
318 while (record
->address
< 0x1b40) {
319 response
= ezusb_writememory (serial
, record
->address
,
320 (unsigned char *)record
->data
, record
->data_size
, 0xa0);
322 err("%s - ezusb_writememory failed for second firmware step (%d %04X %p %d)",
323 __FUNCTION__
, response
, record
->address
, record
->data
, record
->data_size
);
329 response
= ezusb_set_reset (serial
, 0);
335 static int whiteheat_firmware_attach (struct usb_serial
*serial
)
337 /* We want this device to fail to have a driver assigned to it */
342 /*****************************************************************************
343 * Connect Tech's White Heat serial driver functions
344 *****************************************************************************/
345 static int whiteheat_attach (struct usb_serial
*serial
)
347 struct usb_serial_port
*command_port
;
348 struct whiteheat_command_private
*command_info
;
349 struct usb_serial_port
*port
;
350 struct whiteheat_private
*info
;
351 struct whiteheat_hw_info
*hw_info
;
361 struct whiteheat_urb_wrap
*wrap
;
362 struct list_head
*tmp
;
364 command_port
= serial
->port
[COMMAND_PORT
];
366 pipe
= usb_sndbulkpipe (serial
->dev
, command_port
->bulk_out_endpointAddress
);
367 command
= kmalloc(2, GFP_KERNEL
);
369 goto no_command_buffer
;
370 command
[0] = WHITEHEAT_GET_HW_INFO
;
373 result
= kmalloc(sizeof(*hw_info
) + 1, GFP_KERNEL
);
375 goto no_result_buffer
;
377 * When the module is reloaded the firmware is still there and
378 * the endpoints are still in the usb core unchanged. This is the
379 * unlinking bug in disguise. Same for the call below.
381 usb_clear_halt(serial
->dev
, pipe
);
382 ret
= usb_bulk_msg (serial
->dev
, pipe
, command
, 2, &alen
, COMMAND_TIMEOUT
);
384 err("%s: Couldn't send command [%d]", serial
->type
->name
, ret
);
386 } else if (alen
!= sizeof(command
)) {
387 err("%s: Send command incomplete [%d]", serial
->type
->name
, alen
);
391 pipe
= usb_rcvbulkpipe (serial
->dev
, command_port
->bulk_in_endpointAddress
);
392 /* See the comment on the usb_clear_halt() above */
393 usb_clear_halt(serial
->dev
, pipe
);
394 ret
= usb_bulk_msg (serial
->dev
, pipe
, result
, sizeof(*hw_info
) + 1, &alen
, COMMAND_TIMEOUT
);
396 err("%s: Couldn't get results [%d]", serial
->type
->name
, ret
);
398 } else if (alen
!= sizeof(result
)) {
399 err("%s: Get results incomplete [%d]", serial
->type
->name
, alen
);
401 } else if (result
[0] != command
[0]) {
402 err("%s: Command failed [%d]", serial
->type
->name
, result
[0]);
406 hw_info
= (struct whiteheat_hw_info
*)&result
[1];
408 info("%s: Driver %s: Firmware v%d.%02d", serial
->type
->name
,
409 DRIVER_VERSION
, hw_info
->sw_major_rev
, hw_info
->sw_minor_rev
);
411 for (i
= 0; i
< serial
->num_ports
; i
++) {
412 port
= serial
->port
[i
];
414 info
= (struct whiteheat_private
*)kmalloc(sizeof(struct whiteheat_private
), GFP_KERNEL
);
416 err("%s: Out of memory for port structures\n", serial
->type
->name
);
420 spin_lock_init(&info
->lock
);
423 INIT_WORK(&info
->rx_work
, rx_data_softint
, port
);
425 INIT_LIST_HEAD(&info
->rx_urbs_free
);
426 INIT_LIST_HEAD(&info
->rx_urbs_submitted
);
427 INIT_LIST_HEAD(&info
->rx_urb_q
);
428 INIT_LIST_HEAD(&info
->tx_urbs_free
);
429 INIT_LIST_HEAD(&info
->tx_urbs_submitted
);
431 for (j
= 0; j
< urb_pool_size
; j
++) {
432 urb
= usb_alloc_urb(0, GFP_KERNEL
);
434 err("No free urbs available");
437 buf_size
= port
->read_urb
->transfer_buffer_length
;
438 urb
->transfer_buffer
= kmalloc(buf_size
, GFP_KERNEL
);
439 if (!urb
->transfer_buffer
) {
440 err("Couldn't allocate urb buffer");
443 wrap
= kmalloc(sizeof(*wrap
), GFP_KERNEL
);
445 err("Couldn't allocate urb wrapper");
448 usb_fill_bulk_urb(urb
, serial
->dev
,
449 usb_rcvbulkpipe(serial
->dev
,
450 port
->bulk_in_endpointAddress
),
451 urb
->transfer_buffer
, buf_size
,
452 whiteheat_read_callback
, port
);
454 list_add(&wrap
->list
, &info
->rx_urbs_free
);
456 urb
= usb_alloc_urb(0, GFP_KERNEL
);
458 err("No free urbs available");
461 buf_size
= port
->write_urb
->transfer_buffer_length
;
462 urb
->transfer_buffer
= kmalloc(buf_size
, GFP_KERNEL
);
463 if (!urb
->transfer_buffer
) {
464 err("Couldn't allocate urb buffer");
467 wrap
= kmalloc(sizeof(*wrap
), GFP_KERNEL
);
469 err("Couldn't allocate urb wrapper");
472 usb_fill_bulk_urb(urb
, serial
->dev
,
473 usb_sndbulkpipe(serial
->dev
,
474 port
->bulk_out_endpointAddress
),
475 urb
->transfer_buffer
, buf_size
,
476 whiteheat_write_callback
, port
);
478 list_add(&wrap
->list
, &info
->tx_urbs_free
);
481 usb_set_serial_port_data(port
, info
);
484 command_info
= (struct whiteheat_command_private
*)kmalloc(sizeof(struct whiteheat_command_private
), GFP_KERNEL
);
485 if (command_info
== NULL
) {
486 err("%s: Out of memory for port structures\n", serial
->type
->name
);
487 goto no_command_private
;
490 spin_lock_init(&command_info
->lock
);
491 command_info
->port_running
= 0;
492 init_waitqueue_head(&command_info
->wait_command
);
493 usb_set_serial_port_data(command_port
, command_info
);
494 command_port
->write_urb
->complete
= command_port_write_callback
;
495 command_port
->read_urb
->complete
= command_port_read_callback
;
502 /* Firmware likely not running */
503 err("%s: Unable to retrieve firmware version, try replugging\n", serial
->type
->name
);
504 err("%s: If the firmware is not running (status led not blinking)\n", serial
->type
->name
);
505 err("%s: please contact support@connecttech.com\n", serial
->type
->name
);
509 for (i
= serial
->num_ports
- 1; i
>= 0; i
--) {
510 port
= serial
->port
[i
];
511 info
= usb_get_serial_port_data(port
);
512 for (j
= urb_pool_size
- 1; j
>= 0; j
--) {
513 tmp
= list_first(&info
->tx_urbs_free
);
515 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
519 kfree(urb
->transfer_buffer
);
523 tmp
= list_first(&info
->rx_urbs_free
);
525 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
529 kfree(urb
->transfer_buffer
);
547 static void whiteheat_shutdown (struct usb_serial
*serial
)
549 struct usb_serial_port
*command_port
;
550 struct usb_serial_port
*port
;
551 struct whiteheat_private
*info
;
552 struct whiteheat_urb_wrap
*wrap
;
554 struct list_head
*tmp
;
555 struct list_head
*tmp2
;
558 dbg("%s", __FUNCTION__
);
560 /* free up our private data for our command port */
561 command_port
= serial
->port
[COMMAND_PORT
];
562 kfree (usb_get_serial_port_data(command_port
));
564 for (i
= 0; i
< serial
->num_ports
; i
++) {
565 port
= serial
->port
[i
];
566 info
= usb_get_serial_port_data(port
);
567 list_for_each_safe(tmp
, tmp2
, &info
->rx_urbs_free
) {
569 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
572 kfree(urb
->transfer_buffer
);
575 list_for_each_safe(tmp
, tmp2
, &info
->tx_urbs_free
) {
577 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
580 kfree(urb
->transfer_buffer
);
590 static int whiteheat_open (struct usb_serial_port
*port
, struct file
*filp
)
593 struct termios old_term
;
595 dbg("%s - port %d", __FUNCTION__
, port
->number
);
597 retval
= start_command_port(port
->serial
);
602 port
->tty
->low_latency
= 1;
604 /* send an open port command */
605 retval
= firm_open(port
);
607 stop_command_port(port
->serial
);
611 retval
= firm_purge(port
, WHITEHEAT_PURGE_RX
| WHITEHEAT_PURGE_TX
);
614 stop_command_port(port
->serial
);
618 old_term
.c_cflag
= ~port
->tty
->termios
->c_cflag
;
619 old_term
.c_iflag
= ~port
->tty
->termios
->c_iflag
;
620 whiteheat_set_termios(port
, &old_term
);
622 /* Work around HCD bugs */
623 usb_clear_halt(port
->serial
->dev
, port
->read_urb
->pipe
);
624 usb_clear_halt(port
->serial
->dev
, port
->write_urb
->pipe
);
626 /* Start reading from the device */
627 retval
= start_port_read(port
);
629 err("%s - failed submitting read urb, error %d", __FUNCTION__
, retval
);
631 stop_command_port(port
->serial
);
636 dbg("%s - exit, retval = %d", __FUNCTION__
, retval
);
641 static void whiteheat_close(struct usb_serial_port
*port
, struct file
* filp
)
643 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
644 struct whiteheat_urb_wrap
*wrap
;
646 struct list_head
*tmp
;
647 struct list_head
*tmp2
;
650 dbg("%s - port %d", __FUNCTION__
, port
->number
);
652 /* filp is NULL when called from usb_serial_disconnect */
653 if (filp
&& (tty_hung_up_p(filp
))) {
657 port
->tty
->closing
= 1;
660 * Not currently in use; tty_wait_until_sent() calls
661 * serial_chars_in_buffer() which deadlocks on the second semaphore
662 * acquisition. This should be fixed at some point. Greg's been
664 if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) {
665 tty_wait_until_sent(port->tty, CLOSING_DELAY);
669 if (port
->tty
->driver
->flush_buffer
)
670 port
->tty
->driver
->flush_buffer(port
->tty
);
671 tty_ldisc_flush(port
->tty
);
673 firm_report_tx_done(port
);
677 /* shutdown our bulk reads and writes */
678 spin_lock_irqsave(&info
->lock
, flags
);
679 list_for_each_safe(tmp
, tmp2
, &info
->rx_urbs_submitted
) {
680 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
684 list_add(tmp
, &info
->rx_urbs_free
);
686 list_for_each_safe(tmp
, tmp2
, &info
->rx_urb_q
) {
688 list_add(tmp
, &info
->rx_urbs_free
);
690 list_for_each_safe(tmp
, tmp2
, &info
->tx_urbs_submitted
) {
691 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
695 list_add(tmp
, &info
->tx_urbs_free
);
697 spin_unlock_irqrestore(&info
->lock
, flags
);
699 stop_command_port(port
->serial
);
701 port
->tty
->closing
= 0;
705 static int whiteheat_write(struct usb_serial_port
*port
, int from_user
, const unsigned char *buf
, int count
)
707 struct usb_serial
*serial
= port
->serial
;
708 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
709 struct whiteheat_urb_wrap
*wrap
;
715 struct list_head
*tmp
;
717 dbg("%s - port %d", __FUNCTION__
, port
->number
);
720 dbg("%s - write request of 0 bytes", __FUNCTION__
);
725 spin_lock_irqsave(&info
->lock
, flags
);
726 if (list_empty(&info
->tx_urbs_free
)) {
727 spin_unlock_irqrestore(&info
->lock
, flags
);
730 tmp
= list_first(&info
->tx_urbs_free
);
732 spin_unlock_irqrestore(&info
->lock
, flags
);
734 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
736 bytes
= (count
> port
->bulk_out_size
) ? port
->bulk_out_size
: count
;
738 if (copy_from_user(urb
->transfer_buffer
, buf
+ sent
, bytes
))
741 memcpy (urb
->transfer_buffer
, buf
+ sent
, bytes
);
744 usb_serial_debug_data(debug
, &port
->dev
, __FUNCTION__
, bytes
, urb
->transfer_buffer
);
746 urb
->dev
= serial
->dev
;
747 urb
->transfer_buffer_length
= bytes
;
748 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
750 err("%s - failed submitting write urb, error %d", __FUNCTION__
, result
);
752 spin_lock_irqsave(&info
->lock
, flags
);
753 list_add(tmp
, &info
->tx_urbs_free
);
754 spin_unlock_irqrestore(&info
->lock
, flags
);
759 spin_lock_irqsave(&info
->lock
, flags
);
760 list_add(tmp
, &info
->tx_urbs_submitted
);
761 spin_unlock_irqrestore(&info
->lock
, flags
);
769 static int whiteheat_write_room(struct usb_serial_port
*port
)
771 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
772 struct list_head
*tmp
;
776 dbg("%s - port %d", __FUNCTION__
, port
->number
);
778 spin_lock_irqsave(&info
->lock
, flags
);
779 list_for_each(tmp
, &info
->tx_urbs_free
)
781 spin_unlock_irqrestore(&info
->lock
, flags
);
782 room
*= port
->bulk_out_size
;
784 dbg("%s - returns %d", __FUNCTION__
, room
);
789 static int whiteheat_tiocmget (struct usb_serial_port
*port
, struct file
*file
)
791 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
792 unsigned int modem_signals
= 0;
794 dbg("%s - port %d", __FUNCTION__
, port
->number
);
796 firm_get_dtr_rts(port
);
797 if (info
->mcr
& UART_MCR_DTR
)
798 modem_signals
|= TIOCM_DTR
;
799 if (info
->mcr
& UART_MCR_RTS
)
800 modem_signals
|= TIOCM_RTS
;
802 return modem_signals
;
806 static int whiteheat_tiocmset (struct usb_serial_port
*port
, struct file
*file
,
807 unsigned int set
, unsigned int clear
)
809 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
811 dbg("%s - port %d", __FUNCTION__
, port
->number
);
814 info
->mcr
|= UART_MCR_RTS
;
816 info
->mcr
|= UART_MCR_DTR
;
818 if (clear
& TIOCM_RTS
)
819 info
->mcr
&= ~UART_MCR_RTS
;
820 if (clear
& TIOCM_DTR
)
821 info
->mcr
&= ~UART_MCR_DTR
;
823 firm_set_dtr(port
, info
->mcr
& UART_MCR_DTR
);
824 firm_set_rts(port
, info
->mcr
& UART_MCR_RTS
);
829 static int whiteheat_ioctl (struct usb_serial_port
*port
, struct file
* file
, unsigned int cmd
, unsigned long arg
)
831 struct serial_struct serstruct
;
832 void __user
*user_arg
= (void __user
*)arg
;
834 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__
, port
->number
, cmd
);
838 memset(&serstruct
, 0, sizeof(serstruct
));
839 serstruct
.type
= PORT_16654
;
840 serstruct
.line
= port
->serial
->minor
;
841 serstruct
.port
= port
->number
;
842 serstruct
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTO_IRQ
;
843 serstruct
.xmit_fifo_size
= port
->bulk_out_size
;
844 serstruct
.custom_divisor
= 0;
845 serstruct
.baud_base
= 460800;
846 serstruct
.close_delay
= CLOSING_DELAY
;
847 serstruct
.closing_wait
= CLOSING_DELAY
;
849 if (copy_to_user(user_arg
, &serstruct
, sizeof(serstruct
)))
855 if (copy_from_user(&serstruct
, user_arg
, sizeof(serstruct
)))
859 * For now this is ignored. dip sets the ASYNC_[V]HI flags
860 * but this isn't used by us at all. Maybe someone somewhere
861 * will need the custom_divisor setting.
874 static void whiteheat_set_termios (struct usb_serial_port
*port
, struct termios
*old_termios
)
876 dbg("%s -port %d", __FUNCTION__
, port
->number
);
878 if ((!port
->tty
) || (!port
->tty
->termios
)) {
879 dbg("%s - no tty structures", __FUNCTION__
);
883 /* check that they really want us to change something */
885 if ((port
->tty
->termios
->c_cflag
== old_termios
->c_cflag
) &&
886 (port
->tty
->termios
->c_iflag
== old_termios
->c_iflag
)) {
887 dbg("%s - nothing to change...", __FUNCTION__
);
892 firm_setup_port(port
);
899 static void whiteheat_break_ctl(struct usb_serial_port
*port
, int break_state
) {
900 firm_set_break(port
, break_state
);
904 static int whiteheat_chars_in_buffer(struct usb_serial_port
*port
)
906 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
907 struct list_head
*tmp
;
908 struct whiteheat_urb_wrap
*wrap
;
912 dbg("%s - port %d", __FUNCTION__
, port
->number
);
914 spin_lock_irqsave(&info
->lock
, flags
);
915 list_for_each(tmp
, &info
->tx_urbs_submitted
) {
916 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
917 chars
+= wrap
->urb
->transfer_buffer_length
;
919 spin_unlock_irqrestore(&info
->lock
, flags
);
921 dbg ("%s - returns %d", __FUNCTION__
, chars
);
926 static void whiteheat_throttle (struct usb_serial_port
*port
)
928 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
931 dbg("%s - port %d", __FUNCTION__
, port
->number
);
933 spin_lock_irqsave(&info
->lock
, flags
);
934 info
->flags
|= THROTTLED
;
935 spin_unlock_irqrestore(&info
->lock
, flags
);
941 static void whiteheat_unthrottle (struct usb_serial_port
*port
)
943 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
944 int actually_throttled
;
947 dbg("%s - port %d", __FUNCTION__
, port
->number
);
949 spin_lock_irqsave(&info
->lock
, flags
);
950 actually_throttled
= info
->flags
& ACTUALLY_THROTTLED
;
951 info
->flags
&= ~(THROTTLED
| ACTUALLY_THROTTLED
);
952 spin_unlock_irqrestore(&info
->lock
, flags
);
954 if (actually_throttled
)
955 rx_data_softint(port
);
961 /*****************************************************************************
962 * Connect Tech's White Heat callback routines
963 *****************************************************************************/
964 static void command_port_write_callback (struct urb
*urb
, struct pt_regs
*regs
)
966 dbg("%s", __FUNCTION__
);
969 dbg ("nonzero urb status: %d", urb
->status
);
975 static void command_port_read_callback (struct urb
*urb
, struct pt_regs
*regs
)
977 struct usb_serial_port
*command_port
= (struct usb_serial_port
*)urb
->context
;
978 struct whiteheat_command_private
*command_info
;
979 unsigned char *data
= urb
->transfer_buffer
;
983 dbg("%s", __FUNCTION__
);
986 dbg("%s - nonzero urb status: %d", __FUNCTION__
, urb
->status
);
990 usb_serial_debug_data(debug
, &command_port
->dev
, __FUNCTION__
, urb
->actual_length
, data
);
992 command_info
= usb_get_serial_port_data(command_port
);
994 dbg ("%s - command_info is NULL, exiting.", __FUNCTION__
);
997 spin_lock_irqsave(&command_info
->lock
, flags
);
999 if (data
[0] == WHITEHEAT_CMD_COMPLETE
) {
1000 command_info
->command_finished
= WHITEHEAT_CMD_COMPLETE
;
1001 wake_up_interruptible(&command_info
->wait_command
);
1002 } else if (data
[0] == WHITEHEAT_CMD_FAILURE
) {
1003 command_info
->command_finished
= WHITEHEAT_CMD_FAILURE
;
1004 wake_up_interruptible(&command_info
->wait_command
);
1005 } else if (data
[0] == WHITEHEAT_EVENT
) {
1006 /* These are unsolicited reports from the firmware, hence no waiting command to wakeup */
1007 dbg("%s - event received", __FUNCTION__
);
1008 } else if (data
[0] == WHITEHEAT_GET_DTR_RTS
) {
1009 memcpy(command_info
->result_buffer
, &data
[1], urb
->actual_length
- 1);
1010 command_info
->command_finished
= WHITEHEAT_CMD_COMPLETE
;
1011 wake_up_interruptible(&command_info
->wait_command
);
1013 dbg("%s - bad reply from firmware", __FUNCTION__
);
1016 /* Continue trying to always read */
1017 command_port
->read_urb
->dev
= command_port
->serial
->dev
;
1018 result
= usb_submit_urb(command_port
->read_urb
, GFP_ATOMIC
);
1019 spin_unlock_irqrestore(&command_info
->lock
, flags
);
1021 dbg("%s - failed resubmitting read urb, error %d", __FUNCTION__
, result
);
1025 static void whiteheat_read_callback(struct urb
*urb
, struct pt_regs
*regs
)
1027 struct usb_serial_port
*port
= (struct usb_serial_port
*)urb
->context
;
1028 struct whiteheat_urb_wrap
*wrap
;
1029 unsigned char *data
= urb
->transfer_buffer
;
1030 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
1032 dbg("%s - port %d", __FUNCTION__
, port
->number
);
1034 spin_lock(&info
->lock
);
1035 wrap
= urb_to_wrap(urb
, &info
->rx_urbs_submitted
);
1037 spin_unlock(&info
->lock
);
1038 err("%s - Not my urb!", __FUNCTION__
);
1041 list_del(&wrap
->list
);
1042 spin_unlock(&info
->lock
);
1045 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__
, urb
->status
);
1046 spin_lock(&info
->lock
);
1047 list_add(&wrap
->list
, &info
->rx_urbs_free
);
1048 spin_unlock(&info
->lock
);
1052 usb_serial_debug_data(debug
, &port
->dev
, __FUNCTION__
, urb
->actual_length
, data
);
1054 spin_lock(&info
->lock
);
1055 list_add_tail(&wrap
->list
, &info
->rx_urb_q
);
1056 if (info
->flags
& THROTTLED
) {
1057 info
->flags
|= ACTUALLY_THROTTLED
;
1058 spin_unlock(&info
->lock
);
1061 spin_unlock(&info
->lock
);
1063 schedule_work(&info
->rx_work
);
1067 static void whiteheat_write_callback(struct urb
*urb
, struct pt_regs
*regs
)
1069 struct usb_serial_port
*port
= (struct usb_serial_port
*)urb
->context
;
1070 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
1071 struct whiteheat_urb_wrap
*wrap
;
1073 dbg("%s - port %d", __FUNCTION__
, port
->number
);
1075 spin_lock(&info
->lock
);
1076 wrap
= urb_to_wrap(urb
, &info
->tx_urbs_submitted
);
1078 spin_unlock(&info
->lock
);
1079 err("%s - Not my urb!", __FUNCTION__
);
1082 list_del(&wrap
->list
);
1083 list_add(&wrap
->list
, &info
->tx_urbs_free
);
1084 spin_unlock(&info
->lock
);
1087 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__
, urb
->status
);
1091 usb_serial_port_softint((void *)port
);
1093 schedule_work(&port
->work
);
1097 /*****************************************************************************
1098 * Connect Tech's White Heat firmware interface
1099 *****************************************************************************/
1100 static int firm_send_command (struct usb_serial_port
*port
, __u8 command
, __u8
*data
, __u8 datasize
)
1102 struct usb_serial_port
*command_port
;
1103 struct whiteheat_command_private
*command_info
;
1104 struct whiteheat_private
*info
;
1105 __u8
*transfer_buffer
;
1107 unsigned long flags
;
1109 dbg("%s - command %d", __FUNCTION__
, command
);
1111 command_port
= port
->serial
->port
[COMMAND_PORT
];
1112 command_info
= usb_get_serial_port_data(command_port
);
1113 spin_lock_irqsave(&command_info
->lock
, flags
);
1114 command_info
->command_finished
= FALSE
;
1116 transfer_buffer
= (__u8
*)command_port
->write_urb
->transfer_buffer
;
1117 transfer_buffer
[0] = command
;
1118 memcpy (&transfer_buffer
[1], data
, datasize
);
1119 command_port
->write_urb
->transfer_buffer_length
= datasize
+ 1;
1120 command_port
->write_urb
->dev
= port
->serial
->dev
;
1121 retval
= usb_submit_urb (command_port
->write_urb
, GFP_KERNEL
);
1122 spin_unlock_irqrestore(&command_info
->lock
, flags
);
1124 dbg("%s - submit urb failed", __FUNCTION__
);
1128 /* wait for the command to complete */
1129 wait_event_interruptible_timeout(command_info
->wait_command
,
1130 (command_info
->command_finished
!= FALSE
), COMMAND_TIMEOUT
);
1132 spin_lock_irqsave(&command_info
->lock
, flags
);
1134 if (command_info
->command_finished
== FALSE
) {
1135 dbg("%s - command timed out.", __FUNCTION__
);
1136 retval
= -ETIMEDOUT
;
1140 if (command_info
->command_finished
== WHITEHEAT_CMD_FAILURE
) {
1141 dbg("%s - command failed.", __FUNCTION__
);
1146 if (command_info
->command_finished
== WHITEHEAT_CMD_COMPLETE
) {
1147 dbg("%s - command completed.", __FUNCTION__
);
1149 case WHITEHEAT_GET_DTR_RTS
:
1150 info
= usb_get_serial_port_data(port
);
1151 memcpy(&info
->mcr
, command_info
->result_buffer
, sizeof(struct whiteheat_dr_info
));
1157 spin_unlock_irqrestore(&command_info
->lock
, flags
);
1162 static int firm_open(struct usb_serial_port
*port
) {
1163 struct whiteheat_simple open_command
;
1165 open_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1166 return firm_send_command(port
, WHITEHEAT_OPEN
, (__u8
*)&open_command
, sizeof(open_command
));
1170 static int firm_close(struct usb_serial_port
*port
) {
1171 struct whiteheat_simple close_command
;
1173 close_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1174 return firm_send_command(port
, WHITEHEAT_CLOSE
, (__u8
*)&close_command
, sizeof(close_command
));
1178 static int firm_setup_port(struct usb_serial_port
*port
) {
1179 struct whiteheat_port_settings port_settings
;
1180 unsigned int cflag
= port
->tty
->termios
->c_cflag
;
1182 port_settings
.port
= port
->number
+ 1;
1184 /* get the byte size */
1185 switch (cflag
& CSIZE
) {
1186 case CS5
: port_settings
.bits
= 5; break;
1187 case CS6
: port_settings
.bits
= 6; break;
1188 case CS7
: port_settings
.bits
= 7; break;
1190 case CS8
: port_settings
.bits
= 8; break;
1192 dbg("%s - data bits = %d", __FUNCTION__
, port_settings
.bits
);
1194 /* determine the parity */
1198 port_settings
.parity
= WHITEHEAT_PAR_MARK
;
1200 port_settings
.parity
= WHITEHEAT_PAR_SPACE
;
1203 port_settings
.parity
= WHITEHEAT_PAR_ODD
;
1205 port_settings
.parity
= WHITEHEAT_PAR_EVEN
;
1207 port_settings
.parity
= WHITEHEAT_PAR_NONE
;
1208 dbg("%s - parity = %c", __FUNCTION__
, port_settings
.parity
);
1210 /* figure out the stop bits requested */
1212 port_settings
.stop
= 2;
1214 port_settings
.stop
= 1;
1215 dbg("%s - stop bits = %d", __FUNCTION__
, port_settings
.stop
);
1217 /* figure out the flow control settings */
1218 if (cflag
& CRTSCTS
)
1219 port_settings
.hflow
= (WHITEHEAT_HFLOW_CTS
| WHITEHEAT_HFLOW_RTS
);
1221 port_settings
.hflow
= WHITEHEAT_HFLOW_NONE
;
1222 dbg("%s - hardware flow control = %s %s %s %s", __FUNCTION__
,
1223 (port_settings
.hflow
& WHITEHEAT_HFLOW_CTS
) ? "CTS" : "",
1224 (port_settings
.hflow
& WHITEHEAT_HFLOW_RTS
) ? "RTS" : "",
1225 (port_settings
.hflow
& WHITEHEAT_HFLOW_DSR
) ? "DSR" : "",
1226 (port_settings
.hflow
& WHITEHEAT_HFLOW_DTR
) ? "DTR" : "");
1228 /* determine software flow control */
1229 if (I_IXOFF(port
->tty
))
1230 port_settings
.sflow
= WHITEHEAT_SFLOW_RXTX
;
1232 port_settings
.sflow
= WHITEHEAT_SFLOW_NONE
;
1233 dbg("%s - software flow control = %c", __FUNCTION__
, port_settings
.sflow
);
1235 port_settings
.xon
= START_CHAR(port
->tty
);
1236 port_settings
.xoff
= STOP_CHAR(port
->tty
);
1237 dbg("%s - XON = %2x, XOFF = %2x", __FUNCTION__
, port_settings
.xon
, port_settings
.xoff
);
1239 /* get the baud rate wanted */
1240 port_settings
.baud
= tty_get_baud_rate(port
->tty
);
1241 dbg("%s - baud rate = %d", __FUNCTION__
, port_settings
.baud
);
1243 /* handle any settings that aren't specified in the tty structure */
1244 port_settings
.lloop
= 0;
1246 /* now send the message to the device */
1247 return firm_send_command(port
, WHITEHEAT_SETUP_PORT
, (__u8
*)&port_settings
, sizeof(port_settings
));
1251 static int firm_set_rts(struct usb_serial_port
*port
, __u8 onoff
) {
1252 struct whiteheat_set_rdb rts_command
;
1254 rts_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1255 rts_command
.state
= onoff
;
1256 return firm_send_command(port
, WHITEHEAT_SET_RTS
, (__u8
*)&rts_command
, sizeof(rts_command
));
1260 static int firm_set_dtr(struct usb_serial_port
*port
, __u8 onoff
) {
1261 struct whiteheat_set_rdb dtr_command
;
1263 dtr_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1264 dtr_command
.state
= onoff
;
1265 return firm_send_command(port
, WHITEHEAT_SET_RTS
, (__u8
*)&dtr_command
, sizeof(dtr_command
));
1269 static int firm_set_break(struct usb_serial_port
*port
, __u8 onoff
) {
1270 struct whiteheat_set_rdb break_command
;
1272 break_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1273 break_command
.state
= onoff
;
1274 return firm_send_command(port
, WHITEHEAT_SET_RTS
, (__u8
*)&break_command
, sizeof(break_command
));
1278 static int firm_purge(struct usb_serial_port
*port
, __u8 rxtx
) {
1279 struct whiteheat_purge purge_command
;
1281 purge_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1282 purge_command
.what
= rxtx
;
1283 return firm_send_command(port
, WHITEHEAT_PURGE
, (__u8
*)&purge_command
, sizeof(purge_command
));
1287 static int firm_get_dtr_rts(struct usb_serial_port
*port
) {
1288 struct whiteheat_simple get_dr_command
;
1290 get_dr_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1291 return firm_send_command(port
, WHITEHEAT_GET_DTR_RTS
, (__u8
*)&get_dr_command
, sizeof(get_dr_command
));
1295 static int firm_report_tx_done(struct usb_serial_port
*port
) {
1296 struct whiteheat_simple close_command
;
1298 close_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1299 return firm_send_command(port
, WHITEHEAT_REPORT_TX_DONE
, (__u8
*)&close_command
, sizeof(close_command
));
1303 /*****************************************************************************
1304 * Connect Tech's White Heat utility functions
1305 *****************************************************************************/
1306 static int start_command_port(struct usb_serial
*serial
)
1308 struct usb_serial_port
*command_port
;
1309 struct whiteheat_command_private
*command_info
;
1310 unsigned long flags
;
1313 command_port
= serial
->port
[COMMAND_PORT
];
1314 command_info
= usb_get_serial_port_data(command_port
);
1315 spin_lock_irqsave(&command_info
->lock
, flags
);
1316 if (!command_info
->port_running
) {
1317 /* Work around HCD bugs */
1318 usb_clear_halt(serial
->dev
, command_port
->read_urb
->pipe
);
1320 command_port
->read_urb
->dev
= serial
->dev
;
1321 retval
= usb_submit_urb(command_port
->read_urb
, GFP_KERNEL
);
1323 err("%s - failed submitting read urb, error %d", __FUNCTION__
, retval
);
1327 command_info
->port_running
++;
1330 spin_unlock_irqrestore(&command_info
->lock
, flags
);
1335 static void stop_command_port(struct usb_serial
*serial
)
1337 struct usb_serial_port
*command_port
;
1338 struct whiteheat_command_private
*command_info
;
1339 unsigned long flags
;
1341 command_port
= serial
->port
[COMMAND_PORT
];
1342 command_info
= usb_get_serial_port_data(command_port
);
1343 spin_lock_irqsave(&command_info
->lock
, flags
);
1344 command_info
->port_running
--;
1345 if (!command_info
->port_running
)
1346 usb_unlink_urb(command_port
->read_urb
);
1347 spin_unlock_irqrestore(&command_info
->lock
, flags
);
1351 static int start_port_read(struct usb_serial_port
*port
)
1353 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
1354 struct whiteheat_urb_wrap
*wrap
;
1357 unsigned long flags
;
1358 struct list_head
*tmp
;
1359 struct list_head
*tmp2
;
1361 spin_lock_irqsave(&info
->lock
, flags
);
1363 list_for_each_safe(tmp
, tmp2
, &info
->rx_urbs_free
) {
1365 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
1367 urb
->dev
= port
->serial
->dev
;
1368 retval
= usb_submit_urb(urb
, GFP_KERNEL
);
1370 list_add(tmp
, &info
->rx_urbs_free
);
1371 list_for_each_safe(tmp
, tmp2
, &info
->rx_urbs_submitted
) {
1372 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
1374 usb_unlink_urb(urb
);
1376 list_add(tmp
, &info
->rx_urbs_free
);
1380 list_add(tmp
, &info
->rx_urbs_submitted
);
1383 spin_unlock_irqrestore(&info
->lock
, flags
);
1389 static struct whiteheat_urb_wrap
*urb_to_wrap(struct urb
* urb
, struct list_head
*head
)
1391 struct whiteheat_urb_wrap
*wrap
;
1392 struct list_head
*tmp
;
1394 list_for_each(tmp
, head
) {
1395 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
1396 if (wrap
->urb
== urb
)
1404 static struct list_head
*list_first(struct list_head
*head
)
1410 static void rx_data_softint(void *private)
1412 struct usb_serial_port
*port
= (struct usb_serial_port
*)private;
1413 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
1414 struct tty_struct
*tty
= port
->tty
;
1415 struct whiteheat_urb_wrap
*wrap
;
1417 unsigned long flags
;
1418 struct list_head
*tmp
;
1419 struct list_head
*tmp2
;
1423 spin_lock_irqsave(&info
->lock
, flags
);
1424 if (info
->flags
& THROTTLED
) {
1425 spin_unlock_irqrestore(&info
->lock
, flags
);
1429 list_for_each_safe(tmp
, tmp2
, &info
->rx_urb_q
) {
1431 spin_unlock_irqrestore(&info
->lock
, flags
);
1433 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
1436 if (tty
&& urb
->actual_length
) {
1437 if (urb
->actual_length
> TTY_FLIPBUF_SIZE
- tty
->flip
.count
) {
1438 spin_lock_irqsave(&info
->lock
, flags
);
1439 list_add(tmp
, &info
->rx_urb_q
);
1440 spin_unlock_irqrestore(&info
->lock
, flags
);
1441 tty_flip_buffer_push(tty
);
1442 schedule_work(&info
->rx_work
);
1446 memcpy(tty
->flip
.char_buf_ptr
, urb
->transfer_buffer
, urb
->actual_length
);
1447 tty
->flip
.char_buf_ptr
+= urb
->actual_length
;
1448 tty
->flip
.count
+= urb
->actual_length
;
1449 sent
+= urb
->actual_length
;
1452 urb
->dev
= port
->serial
->dev
;
1453 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
1455 err("%s - failed resubmitting read urb, error %d", __FUNCTION__
, result
);
1456 spin_lock_irqsave(&info
->lock
, flags
);
1457 list_add(tmp
, &info
->rx_urbs_free
);
1461 spin_lock_irqsave(&info
->lock
, flags
);
1462 list_add(tmp
, &info
->rx_urbs_submitted
);
1464 spin_unlock_irqrestore(&info
->lock
, flags
);
1467 tty_flip_buffer_push(tty
);
1471 /*****************************************************************************
1472 * Connect Tech's White Heat module functions
1473 *****************************************************************************/
1474 static int __init
whiteheat_init (void)
1477 retval
= usb_serial_register(&whiteheat_fake_device
);
1479 goto failed_fake_register
;
1480 retval
= usb_serial_register(&whiteheat_device
);
1482 goto failed_device_register
;
1483 retval
= usb_register(&whiteheat_driver
);
1485 goto failed_usb_register
;
1486 info(DRIVER_DESC
" " DRIVER_VERSION
);
1488 failed_usb_register
:
1489 usb_serial_deregister(&whiteheat_device
);
1490 failed_device_register
:
1491 usb_serial_deregister(&whiteheat_fake_device
);
1492 failed_fake_register
:
1497 static void __exit
whiteheat_exit (void)
1499 usb_deregister (&whiteheat_driver
);
1500 usb_serial_deregister (&whiteheat_fake_device
);
1501 usb_serial_deregister (&whiteheat_device
);
1505 module_init(whiteheat_init
);
1506 module_exit(whiteheat_exit
);
1508 MODULE_AUTHOR( DRIVER_AUTHOR
);
1509 MODULE_DESCRIPTION( DRIVER_DESC
);
1510 MODULE_LICENSE("GPL");
1512 module_param(urb_pool_size
, int, 0);
1513 MODULE_PARM_DESC(urb_pool_size
, "Number of urbs to use for buffering");
1515 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
1516 MODULE_PARM_DESC(debug
, "Debug enabled or not");