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/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>
77 #include <linux/mutex.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 <linux/usb/serial.h>
84 #include <linux/firmware.h>
85 #include <linux/ihex.h>
86 #include "whiteheat.h" /* WhiteHEAT specific commands */
97 #define DRIVER_VERSION "v2.0"
98 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>, Stuart MacDonald <stuartm@connecttech.com>"
99 #define DRIVER_DESC "USB ConnectTech WhiteHEAT driver"
101 #define CONNECT_TECH_VENDOR_ID 0x0710
102 #define CONNECT_TECH_FAKE_WHITE_HEAT_ID 0x0001
103 #define CONNECT_TECH_WHITE_HEAT_ID 0x8001
106 ID tables for whiteheat are unusual, because we want to different
107 things for different versions of the device. Eventually, this
108 will be doable from a single table. But, for now, we define two
109 separate ID tables, and then a third table that combines them
110 just for the purpose of exporting the autoloading information.
112 static struct usb_device_id id_table_std
[] = {
113 { USB_DEVICE(CONNECT_TECH_VENDOR_ID
, CONNECT_TECH_WHITE_HEAT_ID
) },
114 { } /* Terminating entry */
117 static struct usb_device_id id_table_prerenumeration
[] = {
118 { USB_DEVICE(CONNECT_TECH_VENDOR_ID
, CONNECT_TECH_FAKE_WHITE_HEAT_ID
) },
119 { } /* Terminating entry */
122 static struct usb_device_id id_table_combined
[] = {
123 { USB_DEVICE(CONNECT_TECH_VENDOR_ID
, CONNECT_TECH_WHITE_HEAT_ID
) },
124 { USB_DEVICE(CONNECT_TECH_VENDOR_ID
, CONNECT_TECH_FAKE_WHITE_HEAT_ID
) },
125 { } /* Terminating entry */
128 MODULE_DEVICE_TABLE (usb
, id_table_combined
);
130 static struct usb_driver whiteheat_driver
= {
132 .probe
= usb_serial_probe
,
133 .disconnect
= usb_serial_disconnect
,
134 .id_table
= id_table_combined
,
138 /* function prototypes for the Connect Tech WhiteHEAT prerenumeration device */
139 static int whiteheat_firmware_download (struct usb_serial
*serial
, const struct usb_device_id
*id
);
140 static int whiteheat_firmware_attach (struct usb_serial
*serial
);
142 /* function prototypes for the Connect Tech WhiteHEAT serial converter */
143 static int whiteheat_attach (struct usb_serial
*serial
);
144 static void whiteheat_shutdown (struct usb_serial
*serial
);
145 static int whiteheat_open (struct tty_struct
*tty
, struct usb_serial_port
*port
, struct file
*filp
);
146 static void whiteheat_close (struct tty_struct
*tty
, struct usb_serial_port
*port
, struct file
*filp
);
147 static int whiteheat_write (struct tty_struct
*tty
, struct usb_serial_port
*port
, const unsigned char *buf
, int count
);
148 static int whiteheat_write_room (struct tty_struct
*tty
);
149 static int whiteheat_ioctl (struct tty_struct
*tty
, struct file
* file
, unsigned int cmd
, unsigned long arg
);
150 static void whiteheat_set_termios (struct tty_struct
*tty
, struct usb_serial_port
*port
, struct ktermios
* old
);
151 static int whiteheat_tiocmget (struct tty_struct
*tty
, struct file
*file
);
152 static int whiteheat_tiocmset (struct tty_struct
*tty
, struct file
*file
, unsigned int set
, unsigned int clear
);
153 static void whiteheat_break_ctl (struct tty_struct
*tty
, int break_state
);
154 static int whiteheat_chars_in_buffer (struct tty_struct
*tty
);
155 static void whiteheat_throttle (struct tty_struct
*tty
);
156 static void whiteheat_unthrottle (struct tty_struct
*tty
);
157 static void whiteheat_read_callback (struct urb
*urb
);
158 static void whiteheat_write_callback (struct urb
*urb
);
160 static struct usb_serial_driver whiteheat_fake_device
= {
162 .owner
= THIS_MODULE
,
163 .name
= "whiteheatnofirm",
165 .description
= "Connect Tech - WhiteHEAT - (prerenumeration)",
166 .usb_driver
= &whiteheat_driver
,
167 .id_table
= id_table_prerenumeration
,
169 .probe
= whiteheat_firmware_download
,
170 .attach
= whiteheat_firmware_attach
,
173 static struct usb_serial_driver whiteheat_device
= {
175 .owner
= THIS_MODULE
,
178 .description
= "Connect Tech - WhiteHEAT",
179 .usb_driver
= &whiteheat_driver
,
180 .id_table
= id_table_std
,
182 .attach
= whiteheat_attach
,
183 .shutdown
= whiteheat_shutdown
,
184 .open
= whiteheat_open
,
185 .close
= whiteheat_close
,
186 .write
= whiteheat_write
,
187 .write_room
= whiteheat_write_room
,
188 .ioctl
= whiteheat_ioctl
,
189 .set_termios
= whiteheat_set_termios
,
190 .break_ctl
= whiteheat_break_ctl
,
191 .tiocmget
= whiteheat_tiocmget
,
192 .tiocmset
= whiteheat_tiocmset
,
193 .chars_in_buffer
= whiteheat_chars_in_buffer
,
194 .throttle
= whiteheat_throttle
,
195 .unthrottle
= whiteheat_unthrottle
,
196 .read_bulk_callback
= whiteheat_read_callback
,
197 .write_bulk_callback
= whiteheat_write_callback
,
201 struct whiteheat_command_private
{
204 __u8 command_finished
;
205 wait_queue_head_t wait_command
; /* for handling sleeping while waiting for a command to finish */
206 __u8 result_buffer
[64];
210 #define THROTTLED 0x01
211 #define ACTUALLY_THROTTLED 0x02
213 static int urb_pool_size
= 8;
215 struct whiteheat_urb_wrap
{
216 struct list_head list
;
220 struct whiteheat_private
{
223 __u8 mcr
; /* FIXME: no locking on mcr */
224 struct list_head rx_urbs_free
;
225 struct list_head rx_urbs_submitted
;
226 struct list_head rx_urb_q
;
227 struct work_struct rx_work
;
228 struct usb_serial_port
*port
;
229 struct list_head tx_urbs_free
;
230 struct list_head tx_urbs_submitted
;
231 struct mutex deathwarrant
;
235 /* local function prototypes */
236 static int start_command_port(struct usb_serial
*serial
);
237 static void stop_command_port(struct usb_serial
*serial
);
238 static void command_port_write_callback(struct urb
*urb
);
239 static void command_port_read_callback(struct urb
*urb
);
241 static int start_port_read(struct usb_serial_port
*port
);
242 static struct whiteheat_urb_wrap
*urb_to_wrap(struct urb
*urb
, struct list_head
*head
);
243 static struct list_head
*list_first(struct list_head
*head
);
244 static void rx_data_softint(struct work_struct
*work
);
246 static int firm_send_command(struct usb_serial_port
*port
, __u8 command
, __u8
*data
, __u8 datasize
);
247 static int firm_open(struct usb_serial_port
*port
);
248 static int firm_close(struct usb_serial_port
*port
);
249 static int firm_setup_port(struct tty_struct
*tty
);
250 static int firm_set_rts(struct usb_serial_port
*port
, __u8 onoff
);
251 static int firm_set_dtr(struct usb_serial_port
*port
, __u8 onoff
);
252 static int firm_set_break(struct usb_serial_port
*port
, __u8 onoff
);
253 static int firm_purge(struct usb_serial_port
*port
, __u8 rxtx
);
254 static int firm_get_dtr_rts(struct usb_serial_port
*port
);
255 static int firm_report_tx_done(struct usb_serial_port
*port
);
258 #define COMMAND_PORT 4
259 #define COMMAND_TIMEOUT (2*HZ) /* 2 second timeout for a command */
260 #define COMMAND_TIMEOUT_MS 2000
261 #define CLOSING_DELAY (30 * HZ)
264 /*****************************************************************************
265 * Connect Tech's White Heat prerenumeration driver functions
266 *****************************************************************************/
268 /* steps to download the firmware to the WhiteHEAT device:
269 - hold the reset (by writing to the reset bit of the CPUCS register)
270 - download the VEND_AX.HEX file to the chip using VENDOR_REQUEST-ANCHOR_LOAD
271 - release the reset (by writing to the CPUCS register)
272 - download the WH.HEX file for all addresses greater than 0x1b3f using
273 VENDOR_REQUEST-ANCHOR_EXTERNAL_RAM_LOAD
275 - download the WH.HEX file for all addresses less than 0x1b40 using
276 VENDOR_REQUEST_ANCHOR_LOAD
278 - device renumerated itself and comes up as new device id with all
279 firmware download completed.
281 static int whiteheat_firmware_download (struct usb_serial
*serial
, const struct usb_device_id
*id
)
283 int response
, ret
= -ENOENT
;
284 const struct firmware
*loader_fw
= NULL
, *firmware_fw
= NULL
;
285 const struct ihex_binrec
*record
;
289 if (request_ihex_firmware(&firmware_fw
, "whiteheat.fw",
290 &serial
->dev
->dev
)) {
291 err("%s - request \"whiteheat.fw\" failed", __func__
);
294 if (request_ihex_firmware(&loader_fw
, "whiteheat_loader.fw",
295 &serial
->dev
->dev
)) {
296 err("%s - request \"whiteheat_loader.fw\" failed", __func__
);
300 response
= ezusb_set_reset (serial
, 1);
302 record
= (const struct ihex_binrec
*)loader_fw
->data
;
304 response
= ezusb_writememory (serial
, be32_to_cpu(record
->addr
),
305 (unsigned char *)record
->data
,
306 be16_to_cpu(record
->len
), 0xa0);
308 err("%s - ezusb_writememory failed for loader (%d %04X %p %d)",
309 __func__
, response
, be32_to_cpu(record
->addr
),
310 record
->data
, be16_to_cpu(record
->len
));
313 record
= ihex_next_binrec(record
);
316 response
= ezusb_set_reset (serial
, 0);
318 record
= (const struct ihex_binrec
*)firmware_fw
->data
;
319 while (record
&& be32_to_cpu(record
->addr
) < 0x1b40)
320 record
= ihex_next_binrec(record
);
322 response
= ezusb_writememory (serial
, be32_to_cpu(record
->addr
),
323 (unsigned char *)record
->data
,
324 be16_to_cpu(record
->len
), 0xa3);
326 err("%s - ezusb_writememory failed for first firmware step (%d %04X %p %d)",
327 __func__
, response
, be32_to_cpu(record
->addr
),
328 record
->data
, be16_to_cpu(record
->len
));
334 response
= ezusb_set_reset (serial
, 1);
336 record
= (const struct ihex_binrec
*)firmware_fw
->data
;
337 while (record
&& be32_to_cpu(record
->addr
) < 0x1b40) {
338 response
= ezusb_writememory (serial
, be32_to_cpu(record
->addr
),
339 (unsigned char *)record
->data
,
340 be16_to_cpu(record
->len
), 0xa0);
342 err("%s - ezusb_writememory failed for second firmware step (%d %04X %p %d)",
343 __func__
, response
, be32_to_cpu(record
->addr
),
344 record
->data
, be16_to_cpu(record
->len
));
350 response
= ezusb_set_reset (serial
, 0);
352 release_firmware(loader_fw
);
353 release_firmware(firmware_fw
);
358 static int whiteheat_firmware_attach (struct usb_serial
*serial
)
360 /* We want this device to fail to have a driver assigned to it */
365 /*****************************************************************************
366 * Connect Tech's White Heat serial driver functions
367 *****************************************************************************/
368 static int whiteheat_attach (struct usb_serial
*serial
)
370 struct usb_serial_port
*command_port
;
371 struct whiteheat_command_private
*command_info
;
372 struct usb_serial_port
*port
;
373 struct whiteheat_private
*info
;
374 struct whiteheat_hw_info
*hw_info
;
384 struct whiteheat_urb_wrap
*wrap
;
385 struct list_head
*tmp
;
387 command_port
= serial
->port
[COMMAND_PORT
];
389 pipe
= usb_sndbulkpipe (serial
->dev
, command_port
->bulk_out_endpointAddress
);
390 command
= kmalloc(2, GFP_KERNEL
);
392 goto no_command_buffer
;
393 command
[0] = WHITEHEAT_GET_HW_INFO
;
396 result
= kmalloc(sizeof(*hw_info
) + 1, GFP_KERNEL
);
398 goto no_result_buffer
;
400 * When the module is reloaded the firmware is still there and
401 * the endpoints are still in the usb core unchanged. This is the
402 * unlinking bug in disguise. Same for the call below.
404 usb_clear_halt(serial
->dev
, pipe
);
405 ret
= usb_bulk_msg (serial
->dev
, pipe
, command
, 2, &alen
, COMMAND_TIMEOUT_MS
);
407 err("%s: Couldn't send command [%d]", serial
->type
->description
, ret
);
409 } else if (alen
!= 2) {
410 err("%s: Send command incomplete [%d]", serial
->type
->description
, alen
);
414 pipe
= usb_rcvbulkpipe (serial
->dev
, command_port
->bulk_in_endpointAddress
);
415 /* See the comment on the usb_clear_halt() above */
416 usb_clear_halt(serial
->dev
, pipe
);
417 ret
= usb_bulk_msg (serial
->dev
, pipe
, result
, sizeof(*hw_info
) + 1, &alen
, COMMAND_TIMEOUT_MS
);
419 err("%s: Couldn't get results [%d]", serial
->type
->description
, ret
);
421 } else if (alen
!= sizeof(*hw_info
) + 1) {
422 err("%s: Get results incomplete [%d]", serial
->type
->description
, alen
);
424 } else if (result
[0] != command
[0]) {
425 err("%s: Command failed [%d]", serial
->type
->description
, result
[0]);
429 hw_info
= (struct whiteheat_hw_info
*)&result
[1];
431 info("%s: Driver %s: Firmware v%d.%02d", serial
->type
->description
,
432 DRIVER_VERSION
, hw_info
->sw_major_rev
, hw_info
->sw_minor_rev
);
434 for (i
= 0; i
< serial
->num_ports
; i
++) {
435 port
= serial
->port
[i
];
437 info
= kmalloc(sizeof(struct whiteheat_private
), GFP_KERNEL
);
439 err("%s: Out of memory for port structures\n", serial
->type
->description
);
443 spin_lock_init(&info
->lock
);
444 mutex_init(&info
->deathwarrant
);
447 INIT_WORK(&info
->rx_work
, rx_data_softint
);
450 INIT_LIST_HEAD(&info
->rx_urbs_free
);
451 INIT_LIST_HEAD(&info
->rx_urbs_submitted
);
452 INIT_LIST_HEAD(&info
->rx_urb_q
);
453 INIT_LIST_HEAD(&info
->tx_urbs_free
);
454 INIT_LIST_HEAD(&info
->tx_urbs_submitted
);
456 for (j
= 0; j
< urb_pool_size
; j
++) {
457 urb
= usb_alloc_urb(0, GFP_KERNEL
);
459 err("No free urbs available");
462 buf_size
= port
->read_urb
->transfer_buffer_length
;
463 urb
->transfer_buffer
= kmalloc(buf_size
, GFP_KERNEL
);
464 if (!urb
->transfer_buffer
) {
465 err("Couldn't allocate urb buffer");
468 wrap
= kmalloc(sizeof(*wrap
), GFP_KERNEL
);
470 err("Couldn't allocate urb wrapper");
473 usb_fill_bulk_urb(urb
, serial
->dev
,
474 usb_rcvbulkpipe(serial
->dev
,
475 port
->bulk_in_endpointAddress
),
476 urb
->transfer_buffer
, buf_size
,
477 whiteheat_read_callback
, port
);
479 list_add(&wrap
->list
, &info
->rx_urbs_free
);
481 urb
= usb_alloc_urb(0, GFP_KERNEL
);
483 err("No free urbs available");
486 buf_size
= port
->write_urb
->transfer_buffer_length
;
487 urb
->transfer_buffer
= kmalloc(buf_size
, GFP_KERNEL
);
488 if (!urb
->transfer_buffer
) {
489 err("Couldn't allocate urb buffer");
492 wrap
= kmalloc(sizeof(*wrap
), GFP_KERNEL
);
494 err("Couldn't allocate urb wrapper");
497 usb_fill_bulk_urb(urb
, serial
->dev
,
498 usb_sndbulkpipe(serial
->dev
,
499 port
->bulk_out_endpointAddress
),
500 urb
->transfer_buffer
, buf_size
,
501 whiteheat_write_callback
, port
);
503 list_add(&wrap
->list
, &info
->tx_urbs_free
);
506 usb_set_serial_port_data(port
, info
);
509 command_info
= kmalloc(sizeof(struct whiteheat_command_private
), GFP_KERNEL
);
510 if (command_info
== NULL
) {
511 err("%s: Out of memory for port structures\n", serial
->type
->description
);
512 goto no_command_private
;
515 mutex_init(&command_info
->mutex
);
516 command_info
->port_running
= 0;
517 init_waitqueue_head(&command_info
->wait_command
);
518 usb_set_serial_port_data(command_port
, command_info
);
519 command_port
->write_urb
->complete
= command_port_write_callback
;
520 command_port
->read_urb
->complete
= command_port_read_callback
;
527 /* Firmware likely not running */
528 err("%s: Unable to retrieve firmware version, try replugging\n", serial
->type
->description
);
529 err("%s: If the firmware is not running (status led not blinking)\n", serial
->type
->description
);
530 err("%s: please contact support@connecttech.com\n", serial
->type
->description
);
535 for (i
= serial
->num_ports
- 1; i
>= 0; i
--) {
536 port
= serial
->port
[i
];
537 info
= usb_get_serial_port_data(port
);
538 for (j
= urb_pool_size
- 1; j
>= 0; j
--) {
539 tmp
= list_first(&info
->tx_urbs_free
);
541 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
545 kfree(urb
->transfer_buffer
);
549 tmp
= list_first(&info
->rx_urbs_free
);
551 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
555 kfree(urb
->transfer_buffer
);
573 static void whiteheat_shutdown (struct usb_serial
*serial
)
575 struct usb_serial_port
*command_port
;
576 struct usb_serial_port
*port
;
577 struct whiteheat_private
*info
;
578 struct whiteheat_urb_wrap
*wrap
;
580 struct list_head
*tmp
;
581 struct list_head
*tmp2
;
586 /* free up our private data for our command port */
587 command_port
= serial
->port
[COMMAND_PORT
];
588 kfree (usb_get_serial_port_data(command_port
));
590 for (i
= 0; i
< serial
->num_ports
; i
++) {
591 port
= serial
->port
[i
];
592 info
= usb_get_serial_port_data(port
);
593 list_for_each_safe(tmp
, tmp2
, &info
->rx_urbs_free
) {
595 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
598 kfree(urb
->transfer_buffer
);
601 list_for_each_safe(tmp
, tmp2
, &info
->tx_urbs_free
) {
603 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
606 kfree(urb
->transfer_buffer
);
616 static int whiteheat_open (struct tty_struct
*tty
,
617 struct usb_serial_port
*port
, struct file
*filp
)
620 struct ktermios old_term
;
622 dbg("%s - port %d", __func__
, port
->number
);
624 retval
= start_command_port(port
->serial
);
629 tty
->low_latency
= 1;
631 /* send an open port command */
632 retval
= firm_open(port
);
634 stop_command_port(port
->serial
);
638 retval
= firm_purge(port
, WHITEHEAT_PURGE_RX
| WHITEHEAT_PURGE_TX
);
641 stop_command_port(port
->serial
);
646 old_term
.c_cflag
= ~tty
->termios
->c_cflag
;
647 old_term
.c_iflag
= ~tty
->termios
->c_iflag
;
648 whiteheat_set_termios(tty
, port
, &old_term
);
651 /* Work around HCD bugs */
652 usb_clear_halt(port
->serial
->dev
, port
->read_urb
->pipe
);
653 usb_clear_halt(port
->serial
->dev
, port
->write_urb
->pipe
);
655 /* Start reading from the device */
656 retval
= start_port_read(port
);
658 err("%s - failed submitting read urb, error %d", __func__
, retval
);
660 stop_command_port(port
->serial
);
665 dbg("%s - exit, retval = %d", __func__
, retval
);
670 static void whiteheat_close(struct tty_struct
*tty
,
671 struct usb_serial_port
*port
, struct file
* filp
)
673 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
674 struct whiteheat_urb_wrap
*wrap
;
676 struct list_head
*tmp
;
677 struct list_head
*tmp2
;
679 dbg("%s - port %d", __func__
, port
->number
);
681 mutex_lock(&port
->serial
->disc_mutex
);
682 /* filp is NULL when called from usb_serial_disconnect */
683 if ((filp
&& (tty_hung_up_p(filp
))) || port
->serial
->disconnected
) {
684 mutex_unlock(&port
->serial
->disc_mutex
);
687 mutex_unlock(&port
->serial
->disc_mutex
);
692 * Not currently in use; tty_wait_until_sent() calls
693 * serial_chars_in_buffer() which deadlocks on the second semaphore
694 * acquisition. This should be fixed at some point. Greg's been
696 if ((filp->f_flags & (O_NDELAY | O_NONBLOCK)) == 0) {
697 tty_wait_until_sent(tty, CLOSING_DELAY);
701 tty_driver_flush_buffer(tty
);
702 tty_ldisc_flush(tty
);
704 firm_report_tx_done(port
);
708 /* shutdown our bulk reads and writes */
709 mutex_lock(&info
->deathwarrant
);
710 spin_lock_irq(&info
->lock
);
711 list_for_each_safe(tmp
, tmp2
, &info
->rx_urbs_submitted
) {
712 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
715 spin_unlock_irq(&info
->lock
);
717 spin_lock_irq(&info
->lock
);
718 list_add(tmp
, &info
->rx_urbs_free
);
720 list_for_each_safe(tmp
, tmp2
, &info
->rx_urb_q
)
721 list_move(tmp
, &info
->rx_urbs_free
);
722 list_for_each_safe(tmp
, tmp2
, &info
->tx_urbs_submitted
) {
723 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
726 spin_unlock_irq(&info
->lock
);
728 spin_lock_irq(&info
->lock
);
729 list_add(tmp
, &info
->tx_urbs_free
);
731 spin_unlock_irq(&info
->lock
);
732 mutex_unlock(&info
->deathwarrant
);
734 stop_command_port(port
->serial
);
740 static int whiteheat_write(struct tty_struct
*tty
,
741 struct usb_serial_port
*port
, const unsigned char *buf
, int count
)
743 struct usb_serial
*serial
= port
->serial
;
744 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
745 struct whiteheat_urb_wrap
*wrap
;
751 struct list_head
*tmp
;
753 dbg("%s - port %d", __func__
, port
->number
);
756 dbg("%s - write request of 0 bytes", __func__
);
761 spin_lock_irqsave(&info
->lock
, flags
);
762 if (list_empty(&info
->tx_urbs_free
)) {
763 spin_unlock_irqrestore(&info
->lock
, flags
);
766 tmp
= list_first(&info
->tx_urbs_free
);
768 spin_unlock_irqrestore(&info
->lock
, flags
);
770 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
772 bytes
= (count
> port
->bulk_out_size
) ? port
->bulk_out_size
: count
;
773 memcpy (urb
->transfer_buffer
, buf
+ sent
, bytes
);
775 usb_serial_debug_data(debug
, &port
->dev
, __func__
, bytes
, urb
->transfer_buffer
);
777 urb
->dev
= serial
->dev
;
778 urb
->transfer_buffer_length
= bytes
;
779 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
781 err("%s - failed submitting write urb, error %d", __func__
, result
);
783 spin_lock_irqsave(&info
->lock
, flags
);
784 list_add(tmp
, &info
->tx_urbs_free
);
785 spin_unlock_irqrestore(&info
->lock
, flags
);
790 spin_lock_irqsave(&info
->lock
, flags
);
791 list_add(tmp
, &info
->tx_urbs_submitted
);
792 spin_unlock_irqrestore(&info
->lock
, flags
);
800 static int whiteheat_write_room(struct tty_struct
*tty
)
802 struct usb_serial_port
*port
= tty
->driver_data
;
803 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
804 struct list_head
*tmp
;
808 dbg("%s - port %d", __func__
, port
->number
);
810 spin_lock_irqsave(&info
->lock
, flags
);
811 list_for_each(tmp
, &info
->tx_urbs_free
)
813 spin_unlock_irqrestore(&info
->lock
, flags
);
814 room
*= port
->bulk_out_size
;
816 dbg("%s - returns %d", __func__
, room
);
821 static int whiteheat_tiocmget (struct tty_struct
*tty
, struct file
*file
)
823 struct usb_serial_port
*port
= tty
->driver_data
;
824 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
825 unsigned int modem_signals
= 0;
827 dbg("%s - port %d", __func__
, port
->number
);
829 firm_get_dtr_rts(port
);
830 if (info
->mcr
& UART_MCR_DTR
)
831 modem_signals
|= TIOCM_DTR
;
832 if (info
->mcr
& UART_MCR_RTS
)
833 modem_signals
|= TIOCM_RTS
;
835 return modem_signals
;
839 static int whiteheat_tiocmset (struct tty_struct
*tty
, struct file
*file
,
840 unsigned int set
, unsigned int clear
)
842 struct usb_serial_port
*port
= tty
->driver_data
;
843 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
845 dbg("%s - port %d", __func__
, port
->number
);
848 info
->mcr
|= UART_MCR_RTS
;
850 info
->mcr
|= UART_MCR_DTR
;
852 if (clear
& TIOCM_RTS
)
853 info
->mcr
&= ~UART_MCR_RTS
;
854 if (clear
& TIOCM_DTR
)
855 info
->mcr
&= ~UART_MCR_DTR
;
857 firm_set_dtr(port
, info
->mcr
& UART_MCR_DTR
);
858 firm_set_rts(port
, info
->mcr
& UART_MCR_RTS
);
863 static int whiteheat_ioctl (struct tty_struct
*tty
, struct file
* file
, unsigned int cmd
, unsigned long arg
)
865 struct usb_serial_port
*port
= tty
->driver_data
;
866 struct serial_struct serstruct
;
867 void __user
*user_arg
= (void __user
*)arg
;
869 dbg("%s - port %d, cmd 0x%.4x", __func__
, port
->number
, cmd
);
873 memset(&serstruct
, 0, sizeof(serstruct
));
874 serstruct
.type
= PORT_16654
;
875 serstruct
.line
= port
->serial
->minor
;
876 serstruct
.port
= port
->number
;
877 serstruct
.flags
= ASYNC_SKIP_TEST
| ASYNC_AUTO_IRQ
;
878 serstruct
.xmit_fifo_size
= port
->bulk_out_size
;
879 serstruct
.custom_divisor
= 0;
880 serstruct
.baud_base
= 460800;
881 serstruct
.close_delay
= CLOSING_DELAY
;
882 serstruct
.closing_wait
= CLOSING_DELAY
;
884 if (copy_to_user(user_arg
, &serstruct
, sizeof(serstruct
)))
890 if (copy_from_user(&serstruct
, user_arg
, sizeof(serstruct
)))
894 * For now this is ignored. dip sets the ASYNC_[V]HI flags
895 * but this isn't used by us at all. Maybe someone somewhere
896 * will need the custom_divisor setting.
909 static void whiteheat_set_termios(struct tty_struct
*tty
, struct usb_serial_port
*port
, struct ktermios
*old_termios
)
911 firm_setup_port(tty
);
915 static void whiteheat_break_ctl(struct tty_struct
*tty
, int break_state
) {
916 struct usb_serial_port
*port
= tty
->driver_data
;
917 firm_set_break(port
, break_state
);
921 static int whiteheat_chars_in_buffer(struct tty_struct
*tty
)
923 struct usb_serial_port
*port
= tty
->driver_data
;
924 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
925 struct list_head
*tmp
;
926 struct whiteheat_urb_wrap
*wrap
;
930 dbg("%s - port %d", __func__
, port
->number
);
932 spin_lock_irqsave(&info
->lock
, flags
);
933 list_for_each(tmp
, &info
->tx_urbs_submitted
) {
934 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
935 chars
+= wrap
->urb
->transfer_buffer_length
;
937 spin_unlock_irqrestore(&info
->lock
, flags
);
939 dbg ("%s - returns %d", __func__
, chars
);
944 static void whiteheat_throttle (struct tty_struct
*tty
)
946 struct usb_serial_port
*port
= tty
->driver_data
;
947 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
950 dbg("%s - port %d", __func__
, port
->number
);
952 spin_lock_irqsave(&info
->lock
, flags
);
953 info
->flags
|= THROTTLED
;
954 spin_unlock_irqrestore(&info
->lock
, flags
);
960 static void whiteheat_unthrottle (struct tty_struct
*tty
)
962 struct usb_serial_port
*port
= tty
->driver_data
;
963 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
964 int actually_throttled
;
967 dbg("%s - port %d", __func__
, port
->number
);
969 spin_lock_irqsave(&info
->lock
, flags
);
970 actually_throttled
= info
->flags
& ACTUALLY_THROTTLED
;
971 info
->flags
&= ~(THROTTLED
| ACTUALLY_THROTTLED
);
972 spin_unlock_irqrestore(&info
->lock
, flags
);
974 if (actually_throttled
)
975 rx_data_softint(&info
->rx_work
);
981 /*****************************************************************************
982 * Connect Tech's White Heat callback routines
983 *****************************************************************************/
984 static void command_port_write_callback(struct urb
*urb
)
986 int status
= urb
->status
;
991 dbg("nonzero urb status: %d", status
);
997 static void command_port_read_callback(struct urb
*urb
)
999 struct usb_serial_port
*command_port
= urb
->context
;
1000 struct whiteheat_command_private
*command_info
;
1001 int status
= urb
->status
;
1002 unsigned char *data
= urb
->transfer_buffer
;
1005 dbg("%s", __func__
);
1007 command_info
= usb_get_serial_port_data(command_port
);
1008 if (!command_info
) {
1009 dbg ("%s - command_info is NULL, exiting.", __func__
);
1013 dbg("%s - nonzero urb status: %d", __func__
, status
);
1014 if (status
!= -ENOENT
)
1015 command_info
->command_finished
= WHITEHEAT_CMD_FAILURE
;
1016 wake_up(&command_info
->wait_command
);
1020 usb_serial_debug_data(debug
, &command_port
->dev
, __func__
, urb
->actual_length
, data
);
1022 if (data
[0] == WHITEHEAT_CMD_COMPLETE
) {
1023 command_info
->command_finished
= WHITEHEAT_CMD_COMPLETE
;
1024 wake_up(&command_info
->wait_command
);
1025 } else if (data
[0] == WHITEHEAT_CMD_FAILURE
) {
1026 command_info
->command_finished
= WHITEHEAT_CMD_FAILURE
;
1027 wake_up(&command_info
->wait_command
);
1028 } else if (data
[0] == WHITEHEAT_EVENT
) {
1029 /* These are unsolicited reports from the firmware, hence no waiting command to wakeup */
1030 dbg("%s - event received", __func__
);
1031 } else if (data
[0] == WHITEHEAT_GET_DTR_RTS
) {
1032 memcpy(command_info
->result_buffer
, &data
[1], urb
->actual_length
- 1);
1033 command_info
->command_finished
= WHITEHEAT_CMD_COMPLETE
;
1034 wake_up(&command_info
->wait_command
);
1036 dbg("%s - bad reply from firmware", __func__
);
1039 /* Continue trying to always read */
1040 command_port
->read_urb
->dev
= command_port
->serial
->dev
;
1041 result
= usb_submit_urb(command_port
->read_urb
, GFP_ATOMIC
);
1043 dbg("%s - failed resubmitting read urb, error %d", __func__
, result
);
1047 static void whiteheat_read_callback(struct urb
*urb
)
1049 struct usb_serial_port
*port
= urb
->context
;
1050 struct whiteheat_urb_wrap
*wrap
;
1051 unsigned char *data
= urb
->transfer_buffer
;
1052 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
1053 int status
= urb
->status
;
1055 dbg("%s - port %d", __func__
, port
->number
);
1057 spin_lock(&info
->lock
);
1058 wrap
= urb_to_wrap(urb
, &info
->rx_urbs_submitted
);
1060 spin_unlock(&info
->lock
);
1061 err("%s - Not my urb!", __func__
);
1064 list_del(&wrap
->list
);
1065 spin_unlock(&info
->lock
);
1068 dbg("%s - nonzero read bulk status received: %d",
1070 spin_lock(&info
->lock
);
1071 list_add(&wrap
->list
, &info
->rx_urbs_free
);
1072 spin_unlock(&info
->lock
);
1076 usb_serial_debug_data(debug
, &port
->dev
, __func__
, urb
->actual_length
, data
);
1078 spin_lock(&info
->lock
);
1079 list_add_tail(&wrap
->list
, &info
->rx_urb_q
);
1080 if (info
->flags
& THROTTLED
) {
1081 info
->flags
|= ACTUALLY_THROTTLED
;
1082 spin_unlock(&info
->lock
);
1085 spin_unlock(&info
->lock
);
1087 schedule_work(&info
->rx_work
);
1091 static void whiteheat_write_callback(struct urb
*urb
)
1093 struct usb_serial_port
*port
= urb
->context
;
1094 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
1095 struct whiteheat_urb_wrap
*wrap
;
1096 int status
= urb
->status
;
1098 dbg("%s - port %d", __func__
, port
->number
);
1100 spin_lock(&info
->lock
);
1101 wrap
= urb_to_wrap(urb
, &info
->tx_urbs_submitted
);
1103 spin_unlock(&info
->lock
);
1104 err("%s - Not my urb!", __func__
);
1107 list_move(&wrap
->list
, &info
->tx_urbs_free
);
1108 spin_unlock(&info
->lock
);
1111 dbg("%s - nonzero write bulk status received: %d",
1116 usb_serial_port_softint(port
);
1120 /*****************************************************************************
1121 * Connect Tech's White Heat firmware interface
1122 *****************************************************************************/
1123 static int firm_send_command(struct usb_serial_port
*port
, __u8 command
, __u8
*data
, __u8 datasize
)
1125 struct usb_serial_port
*command_port
;
1126 struct whiteheat_command_private
*command_info
;
1127 struct whiteheat_private
*info
;
1128 __u8
*transfer_buffer
;
1132 dbg("%s - command %d", __func__
, command
);
1134 command_port
= port
->serial
->port
[COMMAND_PORT
];
1135 command_info
= usb_get_serial_port_data(command_port
);
1136 mutex_lock(&command_info
->mutex
);
1137 command_info
->command_finished
= false;
1139 transfer_buffer
= (__u8
*)command_port
->write_urb
->transfer_buffer
;
1140 transfer_buffer
[0] = command
;
1141 memcpy (&transfer_buffer
[1], data
, datasize
);
1142 command_port
->write_urb
->transfer_buffer_length
= datasize
+ 1;
1143 command_port
->write_urb
->dev
= port
->serial
->dev
;
1144 retval
= usb_submit_urb (command_port
->write_urb
, GFP_NOIO
);
1146 dbg("%s - submit urb failed", __func__
);
1150 /* wait for the command to complete */
1151 t
= wait_event_timeout(command_info
->wait_command
,
1152 (bool)command_info
->command_finished
, COMMAND_TIMEOUT
);
1154 usb_kill_urb(command_port
->write_urb
);
1156 if (command_info
->command_finished
== false) {
1157 dbg("%s - command timed out.", __func__
);
1158 retval
= -ETIMEDOUT
;
1162 if (command_info
->command_finished
== WHITEHEAT_CMD_FAILURE
) {
1163 dbg("%s - command failed.", __func__
);
1168 if (command_info
->command_finished
== WHITEHEAT_CMD_COMPLETE
) {
1169 dbg("%s - command completed.", __func__
);
1171 case WHITEHEAT_GET_DTR_RTS
:
1172 info
= usb_get_serial_port_data(port
);
1173 memcpy(&info
->mcr
, command_info
->result_buffer
, sizeof(struct whiteheat_dr_info
));
1179 mutex_unlock(&command_info
->mutex
);
1184 static int firm_open(struct usb_serial_port
*port
) {
1185 struct whiteheat_simple open_command
;
1187 open_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1188 return firm_send_command(port
, WHITEHEAT_OPEN
, (__u8
*)&open_command
, sizeof(open_command
));
1192 static int firm_close(struct usb_serial_port
*port
) {
1193 struct whiteheat_simple close_command
;
1195 close_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1196 return firm_send_command(port
, WHITEHEAT_CLOSE
, (__u8
*)&close_command
, sizeof(close_command
));
1200 static int firm_setup_port(struct tty_struct
*tty
) {
1201 struct usb_serial_port
*port
= tty
->driver_data
;
1202 struct whiteheat_port_settings port_settings
;
1203 unsigned int cflag
= tty
->termios
->c_cflag
;
1205 port_settings
.port
= port
->number
+ 1;
1207 /* get the byte size */
1208 switch (cflag
& CSIZE
) {
1209 case CS5
: port_settings
.bits
= 5; break;
1210 case CS6
: port_settings
.bits
= 6; break;
1211 case CS7
: port_settings
.bits
= 7; break;
1213 case CS8
: port_settings
.bits
= 8; break;
1215 dbg("%s - data bits = %d", __func__
, port_settings
.bits
);
1217 /* determine the parity */
1221 port_settings
.parity
= WHITEHEAT_PAR_MARK
;
1223 port_settings
.parity
= WHITEHEAT_PAR_SPACE
;
1226 port_settings
.parity
= WHITEHEAT_PAR_ODD
;
1228 port_settings
.parity
= WHITEHEAT_PAR_EVEN
;
1230 port_settings
.parity
= WHITEHEAT_PAR_NONE
;
1231 dbg("%s - parity = %c", __func__
, port_settings
.parity
);
1233 /* figure out the stop bits requested */
1235 port_settings
.stop
= 2;
1237 port_settings
.stop
= 1;
1238 dbg("%s - stop bits = %d", __func__
, port_settings
.stop
);
1240 /* figure out the flow control settings */
1241 if (cflag
& CRTSCTS
)
1242 port_settings
.hflow
= (WHITEHEAT_HFLOW_CTS
| WHITEHEAT_HFLOW_RTS
);
1244 port_settings
.hflow
= WHITEHEAT_HFLOW_NONE
;
1245 dbg("%s - hardware flow control = %s %s %s %s", __func__
,
1246 (port_settings
.hflow
& WHITEHEAT_HFLOW_CTS
) ? "CTS" : "",
1247 (port_settings
.hflow
& WHITEHEAT_HFLOW_RTS
) ? "RTS" : "",
1248 (port_settings
.hflow
& WHITEHEAT_HFLOW_DSR
) ? "DSR" : "",
1249 (port_settings
.hflow
& WHITEHEAT_HFLOW_DTR
) ? "DTR" : "");
1251 /* determine software flow control */
1253 port_settings
.sflow
= WHITEHEAT_SFLOW_RXTX
;
1255 port_settings
.sflow
= WHITEHEAT_SFLOW_NONE
;
1256 dbg("%s - software flow control = %c", __func__
, port_settings
.sflow
);
1258 port_settings
.xon
= START_CHAR(tty
);
1259 port_settings
.xoff
= STOP_CHAR(tty
);
1260 dbg("%s - XON = %2x, XOFF = %2x", __func__
, port_settings
.xon
, port_settings
.xoff
);
1262 /* get the baud rate wanted */
1263 port_settings
.baud
= tty_get_baud_rate(tty
);
1264 dbg("%s - baud rate = %d", __func__
, port_settings
.baud
);
1266 /* fixme: should set validated settings */
1267 tty_encode_baud_rate(tty
, port_settings
.baud
, port_settings
.baud
);
1268 /* handle any settings that aren't specified in the tty structure */
1269 port_settings
.lloop
= 0;
1271 /* now send the message to the device */
1272 return firm_send_command(port
, WHITEHEAT_SETUP_PORT
, (__u8
*)&port_settings
, sizeof(port_settings
));
1276 static int firm_set_rts(struct usb_serial_port
*port
, __u8 onoff
) {
1277 struct whiteheat_set_rdb rts_command
;
1279 rts_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1280 rts_command
.state
= onoff
;
1281 return firm_send_command(port
, WHITEHEAT_SET_RTS
, (__u8
*)&rts_command
, sizeof(rts_command
));
1285 static int firm_set_dtr(struct usb_serial_port
*port
, __u8 onoff
) {
1286 struct whiteheat_set_rdb dtr_command
;
1288 dtr_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1289 dtr_command
.state
= onoff
;
1290 return firm_send_command(port
, WHITEHEAT_SET_RTS
, (__u8
*)&dtr_command
, sizeof(dtr_command
));
1294 static int firm_set_break(struct usb_serial_port
*port
, __u8 onoff
) {
1295 struct whiteheat_set_rdb break_command
;
1297 break_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1298 break_command
.state
= onoff
;
1299 return firm_send_command(port
, WHITEHEAT_SET_RTS
, (__u8
*)&break_command
, sizeof(break_command
));
1303 static int firm_purge(struct usb_serial_port
*port
, __u8 rxtx
) {
1304 struct whiteheat_purge purge_command
;
1306 purge_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1307 purge_command
.what
= rxtx
;
1308 return firm_send_command(port
, WHITEHEAT_PURGE
, (__u8
*)&purge_command
, sizeof(purge_command
));
1312 static int firm_get_dtr_rts(struct usb_serial_port
*port
) {
1313 struct whiteheat_simple get_dr_command
;
1315 get_dr_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1316 return firm_send_command(port
, WHITEHEAT_GET_DTR_RTS
, (__u8
*)&get_dr_command
, sizeof(get_dr_command
));
1320 static int firm_report_tx_done(struct usb_serial_port
*port
) {
1321 struct whiteheat_simple close_command
;
1323 close_command
.port
= port
->number
- port
->serial
->minor
+ 1;
1324 return firm_send_command(port
, WHITEHEAT_REPORT_TX_DONE
, (__u8
*)&close_command
, sizeof(close_command
));
1328 /*****************************************************************************
1329 * Connect Tech's White Heat utility functions
1330 *****************************************************************************/
1331 static int start_command_port(struct usb_serial
*serial
)
1333 struct usb_serial_port
*command_port
;
1334 struct whiteheat_command_private
*command_info
;
1337 command_port
= serial
->port
[COMMAND_PORT
];
1338 command_info
= usb_get_serial_port_data(command_port
);
1339 mutex_lock(&command_info
->mutex
);
1340 if (!command_info
->port_running
) {
1341 /* Work around HCD bugs */
1342 usb_clear_halt(serial
->dev
, command_port
->read_urb
->pipe
);
1344 command_port
->read_urb
->dev
= serial
->dev
;
1345 retval
= usb_submit_urb(command_port
->read_urb
, GFP_KERNEL
);
1347 err("%s - failed submitting read urb, error %d", __func__
, retval
);
1351 command_info
->port_running
++;
1354 mutex_unlock(&command_info
->mutex
);
1359 static void stop_command_port(struct usb_serial
*serial
)
1361 struct usb_serial_port
*command_port
;
1362 struct whiteheat_command_private
*command_info
;
1364 command_port
= serial
->port
[COMMAND_PORT
];
1365 command_info
= usb_get_serial_port_data(command_port
);
1366 mutex_lock(&command_info
->mutex
);
1367 command_info
->port_running
--;
1368 if (!command_info
->port_running
)
1369 usb_kill_urb(command_port
->read_urb
);
1370 mutex_unlock(&command_info
->mutex
);
1374 static int start_port_read(struct usb_serial_port
*port
)
1376 struct whiteheat_private
*info
= usb_get_serial_port_data(port
);
1377 struct whiteheat_urb_wrap
*wrap
;
1380 unsigned long flags
;
1381 struct list_head
*tmp
;
1382 struct list_head
*tmp2
;
1384 spin_lock_irqsave(&info
->lock
, flags
);
1386 list_for_each_safe(tmp
, tmp2
, &info
->rx_urbs_free
) {
1388 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
1390 urb
->dev
= port
->serial
->dev
;
1391 spin_unlock_irqrestore(&info
->lock
, flags
);
1392 retval
= usb_submit_urb(urb
, GFP_KERNEL
);
1394 spin_lock_irqsave(&info
->lock
, flags
);
1395 list_add(tmp
, &info
->rx_urbs_free
);
1396 list_for_each_safe(tmp
, tmp2
, &info
->rx_urbs_submitted
) {
1397 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
1400 spin_unlock_irqrestore(&info
->lock
, flags
);
1402 spin_lock_irqsave(&info
->lock
, flags
);
1403 list_add(tmp
, &info
->rx_urbs_free
);
1407 spin_lock_irqsave(&info
->lock
, flags
);
1408 list_add(tmp
, &info
->rx_urbs_submitted
);
1411 spin_unlock_irqrestore(&info
->lock
, flags
);
1417 static struct whiteheat_urb_wrap
*urb_to_wrap(struct urb
* urb
, struct list_head
*head
)
1419 struct whiteheat_urb_wrap
*wrap
;
1420 struct list_head
*tmp
;
1422 list_for_each(tmp
, head
) {
1423 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
1424 if (wrap
->urb
== urb
)
1432 static struct list_head
*list_first(struct list_head
*head
)
1438 static void rx_data_softint(struct work_struct
*work
)
1440 struct whiteheat_private
*info
=
1441 container_of(work
, struct whiteheat_private
, rx_work
);
1442 struct usb_serial_port
*port
= info
->port
;
1443 struct tty_struct
*tty
= port
->port
.tty
;
1444 struct whiteheat_urb_wrap
*wrap
;
1446 unsigned long flags
;
1447 struct list_head
*tmp
;
1448 struct list_head
*tmp2
;
1452 spin_lock_irqsave(&info
->lock
, flags
);
1453 if (info
->flags
& THROTTLED
) {
1454 spin_unlock_irqrestore(&info
->lock
, flags
);
1458 list_for_each_safe(tmp
, tmp2
, &info
->rx_urb_q
) {
1460 spin_unlock_irqrestore(&info
->lock
, flags
);
1462 wrap
= list_entry(tmp
, struct whiteheat_urb_wrap
, list
);
1465 if (tty
&& urb
->actual_length
) {
1466 int len
= tty_buffer_request_room(tty
, urb
->actual_length
);
1467 /* This stuff can go away now I suspect */
1468 if (unlikely(len
< urb
->actual_length
)) {
1469 spin_lock_irqsave(&info
->lock
, flags
);
1470 list_add(tmp
, &info
->rx_urb_q
);
1471 spin_unlock_irqrestore(&info
->lock
, flags
);
1472 tty_flip_buffer_push(tty
);
1473 schedule_work(&info
->rx_work
);
1476 tty_insert_flip_string(tty
, urb
->transfer_buffer
, len
);
1480 urb
->dev
= port
->serial
->dev
;
1481 result
= usb_submit_urb(urb
, GFP_ATOMIC
);
1483 err("%s - failed resubmitting read urb, error %d", __func__
, result
);
1484 spin_lock_irqsave(&info
->lock
, flags
);
1485 list_add(tmp
, &info
->rx_urbs_free
);
1489 spin_lock_irqsave(&info
->lock
, flags
);
1490 list_add(tmp
, &info
->rx_urbs_submitted
);
1492 spin_unlock_irqrestore(&info
->lock
, flags
);
1495 tty_flip_buffer_push(tty
);
1499 /*****************************************************************************
1500 * Connect Tech's White Heat module functions
1501 *****************************************************************************/
1502 static int __init
whiteheat_init (void)
1505 retval
= usb_serial_register(&whiteheat_fake_device
);
1507 goto failed_fake_register
;
1508 retval
= usb_serial_register(&whiteheat_device
);
1510 goto failed_device_register
;
1511 retval
= usb_register(&whiteheat_driver
);
1513 goto failed_usb_register
;
1514 info(DRIVER_DESC
" " DRIVER_VERSION
);
1516 failed_usb_register
:
1517 usb_serial_deregister(&whiteheat_device
);
1518 failed_device_register
:
1519 usb_serial_deregister(&whiteheat_fake_device
);
1520 failed_fake_register
:
1525 static void __exit
whiteheat_exit (void)
1527 usb_deregister (&whiteheat_driver
);
1528 usb_serial_deregister (&whiteheat_fake_device
);
1529 usb_serial_deregister (&whiteheat_device
);
1533 module_init(whiteheat_init
);
1534 module_exit(whiteheat_exit
);
1536 MODULE_AUTHOR( DRIVER_AUTHOR
);
1537 MODULE_DESCRIPTION( DRIVER_DESC
);
1538 MODULE_LICENSE("GPL");
1540 MODULE_FIRMWARE("whiteheat.fw");
1541 MODULE_FIRMWARE("whiteheat_loader.fw");
1543 module_param(urb_pool_size
, int, 0);
1544 MODULE_PARM_DESC(urb_pool_size
, "Number of urbs to use for buffering");
1546 module_param(debug
, bool, S_IRUGO
| S_IWUSR
);
1547 MODULE_PARM_DESC(debug
, "Debug enabled or not");