2 Keyspan USB to Serial Converter driver
4 (C) Copyright (C) 2000-2001 Hugh Blemings <hugh@blemings.org>
5 (C) Copyright (C) 2002 Greg Kroah-Hartman <greg@kroah.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 See http://blemings.org/hugh/keyspan.html for more information.
14 Code in this driver inspired by and in a number of places taken
15 from Brian Warner's original Keyspan-PDA driver.
17 This driver has been put together with the support of Innosys, Inc.
18 and Keyspan, Inc the manufacturers of the Keyspan USB-serial products.
21 Thanks to Paulus for miscellaneous tidy ups, some largish chunks
22 of much nicer and/or completely new code and (perhaps most uniquely)
23 having the patience to sit down and explain why and where he'd changed
26 Tip 'o the hat to IBM (and previously Linuxcare :) for supporting
27 staff in their work on open source projects.
31 #include <linux/kernel.h>
32 #include <linux/jiffies.h>
33 #include <linux/errno.h>
34 #include <linux/init.h>
35 #include <linux/slab.h>
36 #include <linux/tty.h>
37 #include <linux/tty_driver.h>
38 #include <linux/tty_flip.h>
39 #include <linux/module.h>
40 #include <linux/spinlock.h>
41 #include <linux/firmware.h>
42 #include <linux/ihex.h>
43 #include <linux/uaccess.h>
44 #include <linux/usb.h>
45 #include <linux/usb/serial.h>
53 #define DRIVER_VERSION "v1.1.5"
54 #define DRIVER_AUTHOR "Hugh Blemings <hugh@misc.nu"
55 #define DRIVER_DESC "Keyspan USB to Serial Converter Driver"
57 #define INSTAT_BUFLEN 32
58 #define GLOCONT_BUFLEN 64
59 #define INDAT49W_BUFLEN 512
61 /* Per device and per port private data */
62 struct keyspan_serial_private {
63 const struct keyspan_device_details *device_details;
65 struct urb *instat_urb;
66 char instat_buf[INSTAT_BUFLEN];
68 /* added to support 49wg, where data from all 4 ports comes in
69 on 1 EP and high-speed supported */
70 struct urb *indat_urb;
71 char indat_buf[INDAT49W_BUFLEN];
73 /* XXX this one probably will need a lock */
74 struct urb *glocont_urb;
75 char glocont_buf[GLOCONT_BUFLEN];
76 char ctrl_buf[8]; /* for EP0 control message */
79 struct keyspan_port_private {
80 /* Keep track of which input & output endpoints to use */
84 /* Keep duplicate of device details in each port
85 structure as well - simplifies some of the
86 callback functions etc. */
87 const struct keyspan_device_details *device_details;
89 /* Input endpoints and buffer for this port */
90 struct urb *in_urbs[2];
91 char in_buffer[2][64];
92 /* Output endpoints and buffer for this port */
93 struct urb *out_urbs[2];
94 char out_buffer[2][64];
96 /* Input ack endpoint */
97 struct urb *inack_urb;
100 /* Output control endpoint */
101 struct urb *outcont_urb;
102 char outcont_buffer[64];
104 /* Settings for the port */
108 unsigned int old_cflag;
109 enum {flow_none, flow_cts, flow_xon} flow_control;
110 int rts_state; /* Handshaking pins (outputs) */
112 int cts_state; /* Handshaking pins (inputs) */
118 unsigned long tx_start_time[2];
119 int resend_cont; /* need to resend control packet */
122 /* Include Keyspan message headers. All current Keyspan Adapters
123 make use of one of five message formats which are referred
124 to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and
125 within this driver. */
126 #include "keyspan_usa26msg.h"
127 #include "keyspan_usa28msg.h"
128 #include "keyspan_usa49msg.h"
129 #include "keyspan_usa90msg.h"
130 #include "keyspan_usa67msg.h"
133 module_usb_serial_driver(keyspan_driver, serial_drivers);
135 static void keyspan_break_ctl(struct tty_struct *tty, int break_state)
137 struct usb_serial_port *port = tty->driver_data;
138 struct keyspan_port_private *p_priv;
142 p_priv = usb_get_serial_port_data(port);
144 if (break_state == -1)
145 p_priv->break_on = 1;
147 p_priv->break_on = 0;
149 keyspan_send_setup(port, 0);
153 static void keyspan_set_termios(struct tty_struct *tty,
154 struct usb_serial_port *port, struct ktermios *old_termios)
156 int baud_rate, device_port;
157 struct keyspan_port_private *p_priv;
158 const struct keyspan_device_details *d_details;
163 p_priv = usb_get_serial_port_data(port);
164 d_details = p_priv->device_details;
165 cflag = tty->termios->c_cflag;
166 device_port = port->number - port->serial->minor;
168 /* Baud rate calculation takes baud rate as an integer
169 so other rates can be generated if desired. */
170 baud_rate = tty_get_baud_rate(tty);
171 /* If no match or invalid, don't change */
172 if (d_details->calculate_baud_rate(baud_rate, d_details->baudclk,
173 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
174 /* FIXME - more to do here to ensure rate changes cleanly */
175 /* FIXME - calcuate exact rate from divisor ? */
176 p_priv->baud = baud_rate;
178 baud_rate = tty_termios_baud_rate(old_termios);
180 tty_encode_baud_rate(tty, baud_rate, baud_rate);
181 /* set CTS/RTS handshake etc. */
182 p_priv->cflag = cflag;
183 p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none;
185 /* Mark/Space not supported */
186 tty->termios->c_cflag &= ~CMSPAR;
188 keyspan_send_setup(port, 0);
191 static int keyspan_tiocmget(struct tty_struct *tty)
193 struct usb_serial_port *port = tty->driver_data;
194 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
197 value = ((p_priv->rts_state) ? TIOCM_RTS : 0) |
198 ((p_priv->dtr_state) ? TIOCM_DTR : 0) |
199 ((p_priv->cts_state) ? TIOCM_CTS : 0) |
200 ((p_priv->dsr_state) ? TIOCM_DSR : 0) |
201 ((p_priv->dcd_state) ? TIOCM_CAR : 0) |
202 ((p_priv->ri_state) ? TIOCM_RNG : 0);
207 static int keyspan_tiocmset(struct tty_struct *tty,
208 unsigned int set, unsigned int clear)
210 struct usb_serial_port *port = tty->driver_data;
211 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
214 p_priv->rts_state = 1;
216 p_priv->dtr_state = 1;
217 if (clear & TIOCM_RTS)
218 p_priv->rts_state = 0;
219 if (clear & TIOCM_DTR)
220 p_priv->dtr_state = 0;
221 keyspan_send_setup(port, 0);
225 /* Write function is similar for the four protocols used
226 with only a minor change for usa90 (usa19hs) required */
227 static int keyspan_write(struct tty_struct *tty,
228 struct usb_serial_port *port, const unsigned char *buf, int count)
230 struct keyspan_port_private *p_priv;
231 const struct keyspan_device_details *d_details;
234 struct urb *this_urb;
235 int err, maxDataLen, dataOffset;
237 p_priv = usb_get_serial_port_data(port);
238 d_details = p_priv->device_details;
240 if (d_details->msg_format == msg_usa90) {
248 dbg("%s - for port %d (%d chars), flip=%d",
249 __func__, port->number, count, p_priv->out_flip);
251 for (left = count; left > 0; left -= todo) {
253 if (todo > maxDataLen)
256 flip = p_priv->out_flip;
258 /* Check we have a valid urb/endpoint before we use it... */
259 this_urb = p_priv->out_urbs[flip];
260 if (this_urb == NULL) {
261 /* no bulk out, so return 0 bytes written */
262 dbg("%s - no output urb :(", __func__);
266 dbg("%s - endpoint %d flip %d",
267 __func__, usb_pipeendpoint(this_urb->pipe), flip);
269 if (this_urb->status == -EINPROGRESS) {
270 if (time_before(jiffies,
271 p_priv->tx_start_time[flip] + 10 * HZ))
273 usb_unlink_urb(this_urb);
277 /* First byte in buffer is "last flag" (except for usa19hx)
278 - unused so for now so set to zero */
279 ((char *)this_urb->transfer_buffer)[0] = 0;
281 memcpy(this_urb->transfer_buffer + dataOffset, buf, todo);
284 /* send the data out the bulk port */
285 this_urb->transfer_buffer_length = todo + dataOffset;
287 err = usb_submit_urb(this_urb, GFP_ATOMIC);
289 dbg("usb_submit_urb(write bulk) failed (%d)", err);
290 p_priv->tx_start_time[flip] = jiffies;
292 /* Flip for next time if usa26 or usa28 interface
293 (not used on usa49) */
294 p_priv->out_flip = (flip + 1) & d_details->outdat_endp_flip;
300 static void usa26_indat_callback(struct urb *urb)
304 struct usb_serial_port *port;
305 struct tty_struct *tty;
306 unsigned char *data = urb->transfer_buffer;
307 int status = urb->status;
311 endpoint = usb_pipeendpoint(urb->pipe);
314 dbg("%s - nonzero status: %x on endpoint %d.",
315 __func__, status, endpoint);
320 tty = tty_port_tty_get(&port->port);
321 if (tty && urb->actual_length) {
322 /* 0x80 bit is error flag */
323 if ((data[0] & 0x80) == 0) {
324 /* no errors on individual bytes, only
325 possible overrun err */
326 if (data[0] & RXERROR_OVERRUN)
330 for (i = 1; i < urb->actual_length ; ++i)
331 tty_insert_flip_char(tty, data[i], err);
333 /* some bytes had errors, every byte has status */
334 dbg("%s - RX error!!!!", __func__);
335 for (i = 0; i + 1 < urb->actual_length; i += 2) {
336 int stat = data[i], flag = 0;
337 if (stat & RXERROR_OVERRUN)
339 if (stat & RXERROR_FRAMING)
341 if (stat & RXERROR_PARITY)
343 /* XXX should handle break (0x10) */
344 tty_insert_flip_char(tty, data[i+1], flag);
347 tty_flip_buffer_push(tty);
351 /* Resubmit urb so we continue receiving */
352 err = usb_submit_urb(urb, GFP_ATOMIC);
354 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
357 /* Outdat handling is common for all devices */
358 static void usa2x_outdat_callback(struct urb *urb)
360 struct usb_serial_port *port;
361 struct keyspan_port_private *p_priv;
364 p_priv = usb_get_serial_port_data(port);
365 dbg("%s - urb %d", __func__, urb == p_priv->out_urbs[1]);
367 usb_serial_port_softint(port);
370 static void usa26_inack_callback(struct urb *urb)
376 static void usa26_outcont_callback(struct urb *urb)
378 struct usb_serial_port *port;
379 struct keyspan_port_private *p_priv;
382 p_priv = usb_get_serial_port_data(port);
384 if (p_priv->resend_cont) {
385 dbg("%s - sending setup", __func__);
386 keyspan_usa26_send_setup(port->serial, port,
387 p_priv->resend_cont - 1);
391 static void usa26_instat_callback(struct urb *urb)
393 unsigned char *data = urb->transfer_buffer;
394 struct keyspan_usa26_portStatusMessage *msg;
395 struct usb_serial *serial;
396 struct usb_serial_port *port;
397 struct keyspan_port_private *p_priv;
398 struct tty_struct *tty;
399 int old_dcd_state, err;
400 int status = urb->status;
402 serial = urb->context;
405 dbg("%s - nonzero status: %x", __func__, status);
408 if (urb->actual_length != 9) {
409 dbg("%s - %d byte report??", __func__, urb->actual_length);
413 msg = (struct keyspan_usa26_portStatusMessage *)data;
416 dbg("%s - port status: port %d cts %d dcd %d dsr %d ri %d toff %d txoff %d rxen %d cr %d",
417 __func__, msg->port, msg->hskia_cts, msg->gpia_dcd, msg->dsr, msg->ri, msg->_txOff,
418 msg->_txXoff, msg->rxEnabled, msg->controlResponse);
421 /* Now do something useful with the data */
424 /* Check port number from message and retrieve private data */
425 if (msg->port >= serial->num_ports) {
426 dbg("%s - Unexpected port number %d", __func__, msg->port);
429 port = serial->port[msg->port];
430 p_priv = usb_get_serial_port_data(port);
432 /* Update handshaking pin state information */
433 old_dcd_state = p_priv->dcd_state;
434 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
435 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
436 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
437 p_priv->ri_state = ((msg->ri) ? 1 : 0);
439 if (old_dcd_state != p_priv->dcd_state) {
440 tty = tty_port_tty_get(&port->port);
441 if (tty && !C_CLOCAL(tty))
446 /* Resubmit urb so we continue receiving */
447 err = usb_submit_urb(urb, GFP_ATOMIC);
449 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
453 static void usa26_glocont_callback(struct urb *urb)
459 static void usa28_indat_callback(struct urb *urb)
462 struct usb_serial_port *port;
463 struct tty_struct *tty;
465 struct keyspan_port_private *p_priv;
466 int status = urb->status;
471 p_priv = usb_get_serial_port_data(port);
472 data = urb->transfer_buffer;
474 if (urb != p_priv->in_urbs[p_priv->in_flip])
479 dbg("%s - nonzero status: %x on endpoint %d.",
480 __func__, status, usb_pipeendpoint(urb->pipe));
485 p_priv = usb_get_serial_port_data(port);
486 data = urb->transfer_buffer;
488 tty =tty_port_tty_get(&port->port);
489 if (tty && urb->actual_length) {
490 tty_insert_flip_string(tty, data, urb->actual_length);
491 tty_flip_buffer_push(tty);
495 /* Resubmit urb so we continue receiving */
496 err = usb_submit_urb(urb, GFP_ATOMIC);
498 dbg("%s - resubmit read urb failed. (%d)",
500 p_priv->in_flip ^= 1;
502 urb = p_priv->in_urbs[p_priv->in_flip];
503 } while (urb->status != -EINPROGRESS);
506 static void usa28_inack_callback(struct urb *urb)
511 static void usa28_outcont_callback(struct urb *urb)
513 struct usb_serial_port *port;
514 struct keyspan_port_private *p_priv;
517 p_priv = usb_get_serial_port_data(port);
519 if (p_priv->resend_cont) {
520 dbg("%s - sending setup", __func__);
521 keyspan_usa28_send_setup(port->serial, port,
522 p_priv->resend_cont - 1);
526 static void usa28_instat_callback(struct urb *urb)
529 unsigned char *data = urb->transfer_buffer;
530 struct keyspan_usa28_portStatusMessage *msg;
531 struct usb_serial *serial;
532 struct usb_serial_port *port;
533 struct keyspan_port_private *p_priv;
534 struct tty_struct *tty;
536 int status = urb->status;
538 serial = urb->context;
541 dbg("%s - nonzero status: %x", __func__, status);
545 if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) {
546 dbg("%s - bad length %d", __func__, urb->actual_length);
550 /*dbg("%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__
551 data[0], data[1], data[2], data[3], data[4], data[5],
552 data[6], data[7], data[8], data[9], data[10], data[11]);*/
554 /* Now do something useful with the data */
555 msg = (struct keyspan_usa28_portStatusMessage *)data;
557 /* Check port number from message and retrieve private data */
558 if (msg->port >= serial->num_ports) {
559 dbg("%s - Unexpected port number %d", __func__, msg->port);
562 port = serial->port[msg->port];
563 p_priv = usb_get_serial_port_data(port);
565 /* Update handshaking pin state information */
566 old_dcd_state = p_priv->dcd_state;
567 p_priv->cts_state = ((msg->cts) ? 1 : 0);
568 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
569 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
570 p_priv->ri_state = ((msg->ri) ? 1 : 0);
572 if( old_dcd_state != p_priv->dcd_state && old_dcd_state) {
573 tty = tty_port_tty_get(&port->port);
574 if (tty && !C_CLOCAL(tty))
579 /* Resubmit urb so we continue receiving */
580 err = usb_submit_urb(urb, GFP_ATOMIC);
582 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
586 static void usa28_glocont_callback(struct urb *urb)
592 static void usa49_glocont_callback(struct urb *urb)
594 struct usb_serial *serial;
595 struct usb_serial_port *port;
596 struct keyspan_port_private *p_priv;
601 serial = urb->context;
602 for (i = 0; i < serial->num_ports; ++i) {
603 port = serial->port[i];
604 p_priv = usb_get_serial_port_data(port);
606 if (p_priv->resend_cont) {
607 dbg("%s - sending setup", __func__);
608 keyspan_usa49_send_setup(serial, port,
609 p_priv->resend_cont - 1);
615 /* This is actually called glostat in the Keyspan
617 static void usa49_instat_callback(struct urb *urb)
620 unsigned char *data = urb->transfer_buffer;
621 struct keyspan_usa49_portStatusMessage *msg;
622 struct usb_serial *serial;
623 struct usb_serial_port *port;
624 struct keyspan_port_private *p_priv;
626 int status = urb->status;
630 serial = urb->context;
633 dbg("%s - nonzero status: %x", __func__, status);
637 if (urb->actual_length !=
638 sizeof(struct keyspan_usa49_portStatusMessage)) {
639 dbg("%s - bad length %d", __func__, urb->actual_length);
643 /*dbg(" %x %x %x %x %x %x %x %x %x %x %x", __func__,
644 data[0], data[1], data[2], data[3], data[4], data[5],
645 data[6], data[7], data[8], data[9], data[10]);*/
647 /* Now do something useful with the data */
648 msg = (struct keyspan_usa49_portStatusMessage *)data;
650 /* Check port number from message and retrieve private data */
651 if (msg->portNumber >= serial->num_ports) {
652 dbg("%s - Unexpected port number %d",
653 __func__, msg->portNumber);
656 port = serial->port[msg->portNumber];
657 p_priv = usb_get_serial_port_data(port);
659 /* Update handshaking pin state information */
660 old_dcd_state = p_priv->dcd_state;
661 p_priv->cts_state = ((msg->cts) ? 1 : 0);
662 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
663 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
664 p_priv->ri_state = ((msg->ri) ? 1 : 0);
666 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
667 struct tty_struct *tty = tty_port_tty_get(&port->port);
668 if (tty && !C_CLOCAL(tty))
673 /* Resubmit urb so we continue receiving */
674 err = usb_submit_urb(urb, GFP_ATOMIC);
676 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
680 static void usa49_inack_callback(struct urb *urb)
685 static void usa49_indat_callback(struct urb *urb)
689 struct usb_serial_port *port;
690 struct tty_struct *tty;
691 unsigned char *data = urb->transfer_buffer;
692 int status = urb->status;
696 endpoint = usb_pipeendpoint(urb->pipe);
699 dbg("%s - nonzero status: %x on endpoint %d.", __func__,
705 tty = tty_port_tty_get(&port->port);
706 if (tty && urb->actual_length) {
707 /* 0x80 bit is error flag */
708 if ((data[0] & 0x80) == 0) {
709 /* no error on any byte */
710 tty_insert_flip_string(tty, data + 1,
711 urb->actual_length - 1);
713 /* some bytes had errors, every byte has status */
714 for (i = 0; i + 1 < urb->actual_length; i += 2) {
715 int stat = data[i], flag = 0;
716 if (stat & RXERROR_OVERRUN)
718 if (stat & RXERROR_FRAMING)
720 if (stat & RXERROR_PARITY)
722 /* XXX should handle break (0x10) */
723 tty_insert_flip_char(tty, data[i+1], flag);
726 tty_flip_buffer_push(tty);
730 /* Resubmit urb so we continue receiving */
731 err = usb_submit_urb(urb, GFP_ATOMIC);
733 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
736 static void usa49wg_indat_callback(struct urb *urb)
739 struct usb_serial *serial;
740 struct usb_serial_port *port;
741 struct tty_struct *tty;
742 unsigned char *data = urb->transfer_buffer;
743 int status = urb->status;
747 serial = urb->context;
750 dbg("%s - nonzero status: %x", __func__, status);
754 /* inbound data is in the form P#, len, status, data */
758 if (urb->actual_length) {
759 while (i < urb->actual_length) {
761 /* Check port number from message*/
762 if (data[i] >= serial->num_ports) {
763 dbg("%s - Unexpected port number %d",
767 port = serial->port[data[i++]];
768 tty = tty_port_tty_get(&port->port);
771 /* 0x80 bit is error flag */
772 if ((data[i] & 0x80) == 0) {
773 /* no error on any byte */
775 for (x = 1; x < len ; ++x)
776 tty_insert_flip_char(tty, data[i++], 0);
779 * some bytes had errors, every byte has status
781 for (x = 0; x + 1 < len; x += 2) {
782 int stat = data[i], flag = 0;
783 if (stat & RXERROR_OVERRUN)
785 if (stat & RXERROR_FRAMING)
787 if (stat & RXERROR_PARITY)
789 /* XXX should handle break (0x10) */
790 tty_insert_flip_char(tty,
795 tty_flip_buffer_push(tty);
800 /* Resubmit urb so we continue receiving */
801 err = usb_submit_urb(urb, GFP_ATOMIC);
803 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
806 /* not used, usa-49 doesn't have per-port control endpoints */
807 static void usa49_outcont_callback(struct urb *urb)
812 static void usa90_indat_callback(struct urb *urb)
816 struct usb_serial_port *port;
817 struct keyspan_port_private *p_priv;
818 struct tty_struct *tty;
819 unsigned char *data = urb->transfer_buffer;
820 int status = urb->status;
824 endpoint = usb_pipeendpoint(urb->pipe);
827 dbg("%s - nonzero status: %x on endpoint %d.",
828 __func__, status, endpoint);
833 p_priv = usb_get_serial_port_data(port);
835 if (urb->actual_length) {
836 tty = tty_port_tty_get(&port->port);
837 /* if current mode is DMA, looks like usa28 format
838 otherwise looks like usa26 data format */
840 if (p_priv->baud > 57600)
841 tty_insert_flip_string(tty, data, urb->actual_length);
843 /* 0x80 bit is error flag */
844 if ((data[0] & 0x80) == 0) {
845 /* no errors on individual bytes, only
846 possible overrun err*/
847 if (data[0] & RXERROR_OVERRUN)
851 for (i = 1; i < urb->actual_length ; ++i)
852 tty_insert_flip_char(tty, data[i],
855 /* some bytes had errors, every byte has status */
856 dbg("%s - RX error!!!!", __func__);
857 for (i = 0; i + 1 < urb->actual_length; i += 2) {
858 int stat = data[i], flag = 0;
859 if (stat & RXERROR_OVERRUN)
861 if (stat & RXERROR_FRAMING)
863 if (stat & RXERROR_PARITY)
865 /* XXX should handle break (0x10) */
866 tty_insert_flip_char(tty, data[i+1],
871 tty_flip_buffer_push(tty);
875 /* Resubmit urb so we continue receiving */
876 err = usb_submit_urb(urb, GFP_ATOMIC);
878 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
882 static void usa90_instat_callback(struct urb *urb)
884 unsigned char *data = urb->transfer_buffer;
885 struct keyspan_usa90_portStatusMessage *msg;
886 struct usb_serial *serial;
887 struct usb_serial_port *port;
888 struct keyspan_port_private *p_priv;
889 struct tty_struct *tty;
890 int old_dcd_state, err;
891 int status = urb->status;
893 serial = urb->context;
896 dbg("%s - nonzero status: %x", __func__, status);
899 if (urb->actual_length < 14) {
900 dbg("%s - %d byte report??", __func__, urb->actual_length);
904 msg = (struct keyspan_usa90_portStatusMessage *)data;
906 /* Now do something useful with the data */
908 port = serial->port[0];
909 p_priv = usb_get_serial_port_data(port);
911 /* Update handshaking pin state information */
912 old_dcd_state = p_priv->dcd_state;
913 p_priv->cts_state = ((msg->cts) ? 1 : 0);
914 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
915 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
916 p_priv->ri_state = ((msg->ri) ? 1 : 0);
918 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
919 tty = tty_port_tty_get(&port->port);
920 if (tty && !C_CLOCAL(tty))
925 /* Resubmit urb so we continue receiving */
926 err = usb_submit_urb(urb, GFP_ATOMIC);
928 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
933 static void usa90_outcont_callback(struct urb *urb)
935 struct usb_serial_port *port;
936 struct keyspan_port_private *p_priv;
939 p_priv = usb_get_serial_port_data(port);
941 if (p_priv->resend_cont) {
942 dbg("%s - sending setup", __func__);
943 keyspan_usa90_send_setup(port->serial, port,
944 p_priv->resend_cont - 1);
948 /* Status messages from the 28xg */
949 static void usa67_instat_callback(struct urb *urb)
952 unsigned char *data = urb->transfer_buffer;
953 struct keyspan_usa67_portStatusMessage *msg;
954 struct usb_serial *serial;
955 struct usb_serial_port *port;
956 struct keyspan_port_private *p_priv;
958 int status = urb->status;
962 serial = urb->context;
965 dbg("%s - nonzero status: %x", __func__, status);
969 if (urb->actual_length !=
970 sizeof(struct keyspan_usa67_portStatusMessage)) {
971 dbg("%s - bad length %d", __func__, urb->actual_length);
976 /* Now do something useful with the data */
977 msg = (struct keyspan_usa67_portStatusMessage *)data;
979 /* Check port number from message and retrieve private data */
980 if (msg->port >= serial->num_ports) {
981 dbg("%s - Unexpected port number %d", __func__, msg->port);
985 port = serial->port[msg->port];
986 p_priv = usb_get_serial_port_data(port);
988 /* Update handshaking pin state information */
989 old_dcd_state = p_priv->dcd_state;
990 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
991 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
993 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
994 struct tty_struct *tty = tty_port_tty_get(&port->port);
995 if (tty && !C_CLOCAL(tty))
1000 /* Resubmit urb so we continue receiving */
1001 err = usb_submit_urb(urb, GFP_ATOMIC);
1003 dbg("%s - resubmit read urb failed. (%d)", __func__, err);
1006 static void usa67_glocont_callback(struct urb *urb)
1008 struct usb_serial *serial;
1009 struct usb_serial_port *port;
1010 struct keyspan_port_private *p_priv;
1013 dbg("%s", __func__);
1015 serial = urb->context;
1016 for (i = 0; i < serial->num_ports; ++i) {
1017 port = serial->port[i];
1018 p_priv = usb_get_serial_port_data(port);
1020 if (p_priv->resend_cont) {
1021 dbg("%s - sending setup", __func__);
1022 keyspan_usa67_send_setup(serial, port,
1023 p_priv->resend_cont - 1);
1029 static int keyspan_write_room(struct tty_struct *tty)
1031 struct usb_serial_port *port = tty->driver_data;
1032 struct keyspan_port_private *p_priv;
1033 const struct keyspan_device_details *d_details;
1036 struct urb *this_urb;
1038 dbg("%s", __func__);
1039 p_priv = usb_get_serial_port_data(port);
1040 d_details = p_priv->device_details;
1042 /* FIXME: locking */
1043 if (d_details->msg_format == msg_usa90)
1048 flip = p_priv->out_flip;
1050 /* Check both endpoints to see if any are available. */
1051 this_urb = p_priv->out_urbs[flip];
1052 if (this_urb != NULL) {
1053 if (this_urb->status != -EINPROGRESS)
1055 flip = (flip + 1) & d_details->outdat_endp_flip;
1056 this_urb = p_priv->out_urbs[flip];
1057 if (this_urb != NULL) {
1058 if (this_urb->status != -EINPROGRESS)
1066 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1068 struct keyspan_port_private *p_priv;
1069 struct keyspan_serial_private *s_priv;
1070 struct usb_serial *serial = port->serial;
1071 const struct keyspan_device_details *d_details;
1073 int baud_rate, device_port;
1075 unsigned int cflag = 0;
1077 s_priv = usb_get_serial_data(serial);
1078 p_priv = usb_get_serial_port_data(port);
1079 d_details = p_priv->device_details;
1081 dbg("%s - port%d.", __func__, port->number);
1083 /* Set some sane defaults */
1084 p_priv->rts_state = 1;
1085 p_priv->dtr_state = 1;
1086 p_priv->baud = 9600;
1088 /* force baud and lcr to be set on open */
1089 p_priv->old_baud = 0;
1090 p_priv->old_cflag = 0;
1092 p_priv->out_flip = 0;
1093 p_priv->in_flip = 0;
1095 /* Reset low level data toggle and start reading from endpoints */
1096 for (i = 0; i < 2; i++) {
1097 urb = p_priv->in_urbs[i];
1101 /* make sure endpoint data toggle is synchronized
1103 usb_clear_halt(urb->dev, urb->pipe);
1104 err = usb_submit_urb(urb, GFP_KERNEL);
1106 dbg("%s - submit urb %d failed (%d)",
1110 /* Reset low level data toggle on out endpoints */
1111 for (i = 0; i < 2; i++) {
1112 urb = p_priv->out_urbs[i];
1115 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1116 usb_pipeout(urb->pipe), 0); */
1119 /* get the terminal config for the setup message now so we don't
1120 * need to send 2 of them */
1122 device_port = port->number - port->serial->minor;
1124 cflag = tty->termios->c_cflag;
1125 /* Baud rate calculation takes baud rate as an integer
1126 so other rates can be generated if desired. */
1127 baud_rate = tty_get_baud_rate(tty);
1128 /* If no match or invalid, leave as default */
1130 && d_details->calculate_baud_rate(baud_rate, d_details->baudclk,
1131 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1132 p_priv->baud = baud_rate;
1135 /* set CTS/RTS handshake etc. */
1136 p_priv->cflag = cflag;
1137 p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none;
1139 keyspan_send_setup(port, 1);
1141 /* keyspan_set_termios(port, NULL); */
1146 static inline void stop_urb(struct urb *urb)
1148 if (urb && urb->status == -EINPROGRESS)
1152 static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1154 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
1156 p_priv->rts_state = on;
1157 p_priv->dtr_state = on;
1158 keyspan_send_setup(port, 0);
1161 static void keyspan_close(struct usb_serial_port *port)
1164 struct usb_serial *serial = port->serial;
1165 struct keyspan_serial_private *s_priv;
1166 struct keyspan_port_private *p_priv;
1168 dbg("%s", __func__);
1169 s_priv = usb_get_serial_data(serial);
1170 p_priv = usb_get_serial_port_data(port);
1172 p_priv->rts_state = 0;
1173 p_priv->dtr_state = 0;
1176 keyspan_send_setup(port, 2);
1177 /* pilot-xfer seems to work best with this delay */
1179 /* keyspan_set_termios(port, NULL); */
1182 /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
1183 dbg("%s - urb in progress", __func__);
1186 p_priv->out_flip = 0;
1187 p_priv->in_flip = 0;
1190 /* Stop reading/writing urbs */
1191 stop_urb(p_priv->inack_urb);
1192 /* stop_urb(p_priv->outcont_urb); */
1193 for (i = 0; i < 2; i++) {
1194 stop_urb(p_priv->in_urbs[i]);
1195 stop_urb(p_priv->out_urbs[i]);
1200 /* download the firmware to a pre-renumeration device */
1201 static int keyspan_fake_startup(struct usb_serial *serial)
1204 const struct ihex_binrec *record;
1206 const struct firmware *fw;
1208 dbg("Keyspan startup version %04x product %04x",
1209 le16_to_cpu(serial->dev->descriptor.bcdDevice),
1210 le16_to_cpu(serial->dev->descriptor.idProduct));
1212 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
1214 dbg("Firmware already loaded. Quitting.");
1218 /* Select firmware image on the basis of idProduct */
1219 switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {
1220 case keyspan_usa28_pre_product_id:
1221 fw_name = "keyspan/usa28.fw";
1224 case keyspan_usa28x_pre_product_id:
1225 fw_name = "keyspan/usa28x.fw";
1228 case keyspan_usa28xa_pre_product_id:
1229 fw_name = "keyspan/usa28xa.fw";
1232 case keyspan_usa28xb_pre_product_id:
1233 fw_name = "keyspan/usa28xb.fw";
1236 case keyspan_usa19_pre_product_id:
1237 fw_name = "keyspan/usa19.fw";
1240 case keyspan_usa19qi_pre_product_id:
1241 fw_name = "keyspan/usa19qi.fw";
1244 case keyspan_mpr_pre_product_id:
1245 fw_name = "keyspan/mpr.fw";
1248 case keyspan_usa19qw_pre_product_id:
1249 fw_name = "keyspan/usa19qw.fw";
1252 case keyspan_usa18x_pre_product_id:
1253 fw_name = "keyspan/usa18x.fw";
1256 case keyspan_usa19w_pre_product_id:
1257 fw_name = "keyspan/usa19w.fw";
1260 case keyspan_usa49w_pre_product_id:
1261 fw_name = "keyspan/usa49w.fw";
1264 case keyspan_usa49wlc_pre_product_id:
1265 fw_name = "keyspan/usa49wlc.fw";
1269 dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n",
1270 le16_to_cpu(serial->dev->descriptor.idProduct));
1274 if (request_ihex_firmware(&fw, fw_name, &serial->dev->dev)) {
1275 dev_err(&serial->dev->dev, "Required keyspan firmware image (%s) unavailable.\n", fw_name);
1279 dbg("Uploading Keyspan %s firmware.", fw_name);
1281 /* download the firmware image */
1282 response = ezusb_set_reset(serial, 1);
1284 record = (const struct ihex_binrec *)fw->data;
1287 response = ezusb_writememory(serial, be32_to_cpu(record->addr),
1288 (unsigned char *)record->data,
1289 be16_to_cpu(record->len), 0xa0);
1291 dev_err(&serial->dev->dev, "ezusb_writememory failed for Keyspan firmware (%d %04X %p %d)\n",
1292 response, be32_to_cpu(record->addr),
1293 record->data, be16_to_cpu(record->len));
1296 record = ihex_next_binrec(record);
1298 release_firmware(fw);
1299 /* bring device out of reset. Renumeration will occur in a
1300 moment and the new device will bind to the real driver */
1301 response = ezusb_set_reset(serial, 0);
1303 /* we don't want this device to have a driver assigned to it. */
1307 /* Helper functions used by keyspan_setup_urbs */
1308 static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial,
1311 struct usb_host_interface *iface_desc;
1312 struct usb_endpoint_descriptor *ep;
1315 iface_desc = serial->interface->cur_altsetting;
1316 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1317 ep = &iface_desc->endpoint[i].desc;
1318 if (ep->bEndpointAddress == endpoint)
1321 dev_warn(&serial->interface->dev, "found no endpoint descriptor for "
1322 "endpoint %x\n", endpoint);
1326 static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1327 int dir, void *ctx, char *buf, int len,
1328 void (*callback)(struct urb *))
1331 struct usb_endpoint_descriptor const *ep_desc;
1332 char const *ep_type_name;
1335 return NULL; /* endpoint not needed */
1337 dbg("%s - alloc for endpoint %d.", __func__, endpoint);
1338 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1340 dbg("%s - alloc for endpoint %d failed.", __func__, endpoint);
1344 if (endpoint == 0) {
1345 /* control EP filled in when used */
1349 ep_desc = find_ep(serial, endpoint);
1351 /* leak the urb, something's wrong and the callers don't care */
1354 if (usb_endpoint_xfer_int(ep_desc)) {
1355 ep_type_name = "INT";
1356 usb_fill_int_urb(urb, serial->dev,
1357 usb_sndintpipe(serial->dev, endpoint) | dir,
1358 buf, len, callback, ctx,
1359 ep_desc->bInterval);
1360 } else if (usb_endpoint_xfer_bulk(ep_desc)) {
1361 ep_type_name = "BULK";
1362 usb_fill_bulk_urb(urb, serial->dev,
1363 usb_sndbulkpipe(serial->dev, endpoint) | dir,
1364 buf, len, callback, ctx);
1366 dev_warn(&serial->interface->dev,
1367 "unsupported endpoint type %x\n",
1368 usb_endpoint_type(ep_desc));
1373 dbg("%s - using urb %p for %s endpoint %x",
1374 __func__, urb, ep_type_name, endpoint);
1378 static struct callbacks {
1379 void (*instat_callback)(struct urb *);
1380 void (*glocont_callback)(struct urb *);
1381 void (*indat_callback)(struct urb *);
1382 void (*outdat_callback)(struct urb *);
1383 void (*inack_callback)(struct urb *);
1384 void (*outcont_callback)(struct urb *);
1385 } keyspan_callbacks[] = {
1387 /* msg_usa26 callbacks */
1388 .instat_callback = usa26_instat_callback,
1389 .glocont_callback = usa26_glocont_callback,
1390 .indat_callback = usa26_indat_callback,
1391 .outdat_callback = usa2x_outdat_callback,
1392 .inack_callback = usa26_inack_callback,
1393 .outcont_callback = usa26_outcont_callback,
1395 /* msg_usa28 callbacks */
1396 .instat_callback = usa28_instat_callback,
1397 .glocont_callback = usa28_glocont_callback,
1398 .indat_callback = usa28_indat_callback,
1399 .outdat_callback = usa2x_outdat_callback,
1400 .inack_callback = usa28_inack_callback,
1401 .outcont_callback = usa28_outcont_callback,
1403 /* msg_usa49 callbacks */
1404 .instat_callback = usa49_instat_callback,
1405 .glocont_callback = usa49_glocont_callback,
1406 .indat_callback = usa49_indat_callback,
1407 .outdat_callback = usa2x_outdat_callback,
1408 .inack_callback = usa49_inack_callback,
1409 .outcont_callback = usa49_outcont_callback,
1411 /* msg_usa90 callbacks */
1412 .instat_callback = usa90_instat_callback,
1413 .glocont_callback = usa28_glocont_callback,
1414 .indat_callback = usa90_indat_callback,
1415 .outdat_callback = usa2x_outdat_callback,
1416 .inack_callback = usa28_inack_callback,
1417 .outcont_callback = usa90_outcont_callback,
1419 /* msg_usa67 callbacks */
1420 .instat_callback = usa67_instat_callback,
1421 .glocont_callback = usa67_glocont_callback,
1422 .indat_callback = usa26_indat_callback,
1423 .outdat_callback = usa2x_outdat_callback,
1424 .inack_callback = usa26_inack_callback,
1425 .outcont_callback = usa26_outcont_callback,
1429 /* Generic setup urbs function that uses
1430 data in device_details */
1431 static void keyspan_setup_urbs(struct usb_serial *serial)
1434 struct keyspan_serial_private *s_priv;
1435 const struct keyspan_device_details *d_details;
1436 struct usb_serial_port *port;
1437 struct keyspan_port_private *p_priv;
1438 struct callbacks *cback;
1441 dbg("%s", __func__);
1443 s_priv = usb_get_serial_data(serial);
1444 d_details = s_priv->device_details;
1446 /* Setup values for the various callback routines */
1447 cback = &keyspan_callbacks[d_details->msg_format];
1449 /* Allocate and set up urbs for each one that is in use,
1450 starting with instat endpoints */
1451 s_priv->instat_urb = keyspan_setup_urb
1452 (serial, d_details->instat_endpoint, USB_DIR_IN,
1453 serial, s_priv->instat_buf, INSTAT_BUFLEN,
1454 cback->instat_callback);
1456 s_priv->indat_urb = keyspan_setup_urb
1457 (serial, d_details->indat_endpoint, USB_DIR_IN,
1458 serial, s_priv->indat_buf, INDAT49W_BUFLEN,
1459 usa49wg_indat_callback);
1461 s_priv->glocont_urb = keyspan_setup_urb
1462 (serial, d_details->glocont_endpoint, USB_DIR_OUT,
1463 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1464 cback->glocont_callback);
1466 /* Setup endpoints for each port specific thing */
1467 for (i = 0; i < d_details->num_ports; i++) {
1468 port = serial->port[i];
1469 p_priv = usb_get_serial_port_data(port);
1471 /* Do indat endpoints first, once for each flip */
1472 endp = d_details->indat_endpoints[i];
1473 for (j = 0; j <= d_details->indat_endp_flip; ++j, ++endp) {
1474 p_priv->in_urbs[j] = keyspan_setup_urb
1475 (serial, endp, USB_DIR_IN, port,
1476 p_priv->in_buffer[j], 64,
1477 cback->indat_callback);
1480 p_priv->in_urbs[j] = NULL;
1482 /* outdat endpoints also have flip */
1483 endp = d_details->outdat_endpoints[i];
1484 for (j = 0; j <= d_details->outdat_endp_flip; ++j, ++endp) {
1485 p_priv->out_urbs[j] = keyspan_setup_urb
1486 (serial, endp, USB_DIR_OUT, port,
1487 p_priv->out_buffer[j], 64,
1488 cback->outdat_callback);
1491 p_priv->out_urbs[j] = NULL;
1493 /* inack endpoint */
1494 p_priv->inack_urb = keyspan_setup_urb
1495 (serial, d_details->inack_endpoints[i], USB_DIR_IN,
1496 port, p_priv->inack_buffer, 1, cback->inack_callback);
1498 /* outcont endpoint */
1499 p_priv->outcont_urb = keyspan_setup_urb
1500 (serial, d_details->outcont_endpoints[i], USB_DIR_OUT,
1501 port, p_priv->outcont_buffer, 64,
1502 cback->outcont_callback);
1506 /* usa19 function doesn't require prescaler */
1507 static int keyspan_usa19_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1508 u8 *rate_low, u8 *prescaler, int portnum)
1510 u32 b16, /* baud rate times 16 (actual rate used internally) */
1512 cnt; /* inverse of divisor (programmed into 8051) */
1514 dbg("%s - %d.", __func__, baud_rate);
1516 /* prevent divide by zero... */
1517 b16 = baud_rate * 16L;
1519 return KEYSPAN_INVALID_BAUD_RATE;
1520 /* Any "standard" rate over 57k6 is marginal on the USA-19
1521 as we run out of divisor resolution. */
1522 if (baud_rate > 57600)
1523 return KEYSPAN_INVALID_BAUD_RATE;
1525 /* calculate the divisor and the counter (its inverse) */
1526 div = baudclk / b16;
1528 return KEYSPAN_INVALID_BAUD_RATE;
1533 return KEYSPAN_INVALID_BAUD_RATE;
1535 /* return the counter values if non-null */
1537 *rate_low = (u8) (cnt & 0xff);
1539 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1540 if (rate_low && rate_hi)
1541 dbg("%s - %d %02x %02x.",
1542 __func__, baud_rate, *rate_hi, *rate_low);
1543 return KEYSPAN_BAUD_RATE_OK;
1546 /* usa19hs function doesn't require prescaler */
1547 static int keyspan_usa19hs_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1548 u8 *rate_low, u8 *prescaler, int portnum)
1550 u32 b16, /* baud rate times 16 (actual rate used internally) */
1553 dbg("%s - %d.", __func__, baud_rate);
1555 /* prevent divide by zero... */
1556 b16 = baud_rate * 16L;
1558 return KEYSPAN_INVALID_BAUD_RATE;
1560 /* calculate the divisor */
1561 div = baudclk / b16;
1563 return KEYSPAN_INVALID_BAUD_RATE;
1566 return KEYSPAN_INVALID_BAUD_RATE;
1568 /* return the counter values if non-null */
1570 *rate_low = (u8) (div & 0xff);
1573 *rate_hi = (u8) ((div >> 8) & 0xff);
1575 if (rate_low && rate_hi)
1576 dbg("%s - %d %02x %02x.",
1577 __func__, baud_rate, *rate_hi, *rate_low);
1579 return KEYSPAN_BAUD_RATE_OK;
1582 static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1583 u8 *rate_low, u8 *prescaler, int portnum)
1585 u32 b16, /* baud rate times 16 (actual rate used internally) */
1586 clk, /* clock with 13/8 prescaler */
1587 div, /* divisor using 13/8 prescaler */
1588 res, /* resulting baud rate using 13/8 prescaler */
1589 diff, /* error using 13/8 prescaler */
1594 dbg("%s - %d.", __func__, baud_rate);
1596 /* prevent divide by zero */
1597 b16 = baud_rate * 16L;
1599 return KEYSPAN_INVALID_BAUD_RATE;
1601 /* Calculate prescaler by trying them all and looking
1604 /* start with largest possible difference */
1605 smallest_diff = 0xffffffff;
1607 /* 0 is an invalid prescaler, used as a flag */
1610 for (i = 8; i <= 0xff; ++i) {
1611 clk = (baudclk * 8) / (u32) i;
1618 diff = (res > b16) ? (res-b16) : (b16-res);
1620 if (diff < smallest_diff) {
1622 smallest_diff = diff;
1626 if (best_prescaler == 0)
1627 return KEYSPAN_INVALID_BAUD_RATE;
1629 clk = (baudclk * 8) / (u32) best_prescaler;
1632 /* return the divisor and prescaler if non-null */
1634 *rate_low = (u8) (div & 0xff);
1636 *rate_hi = (u8) ((div >> 8) & 0xff);
1638 *prescaler = best_prescaler;
1639 /* dbg("%s - %d %d", __func__, *prescaler, div); */
1641 return KEYSPAN_BAUD_RATE_OK;
1644 /* USA-28 supports different maximum baud rates on each port */
1645 static int keyspan_usa28_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
1646 u8 *rate_low, u8 *prescaler, int portnum)
1648 u32 b16, /* baud rate times 16 (actual rate used internally) */
1650 cnt; /* inverse of divisor (programmed into 8051) */
1652 dbg("%s - %d.", __func__, baud_rate);
1654 /* prevent divide by zero */
1655 b16 = baud_rate * 16L;
1657 return KEYSPAN_INVALID_BAUD_RATE;
1659 /* calculate the divisor and the counter (its inverse) */
1660 div = KEYSPAN_USA28_BAUDCLK / b16;
1662 return KEYSPAN_INVALID_BAUD_RATE;
1666 /* check for out of range, based on portnum,
1667 and return result */
1670 return KEYSPAN_INVALID_BAUD_RATE;
1674 return KEYSPAN_INVALID_BAUD_RATE;
1676 return KEYSPAN_INVALID_BAUD_RATE;
1679 /* return the counter values if not NULL
1680 (port 1 will ignore retHi) */
1682 *rate_low = (u8) (cnt & 0xff);
1684 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1685 dbg("%s - %d OK.", __func__, baud_rate);
1686 return KEYSPAN_BAUD_RATE_OK;
1689 static int keyspan_usa26_send_setup(struct usb_serial *serial,
1690 struct usb_serial_port *port,
1693 struct keyspan_usa26_portControlMessage msg;
1694 struct keyspan_serial_private *s_priv;
1695 struct keyspan_port_private *p_priv;
1696 const struct keyspan_device_details *d_details;
1698 struct urb *this_urb;
1699 int device_port, err;
1701 dbg("%s reset=%d", __func__, reset_port);
1703 s_priv = usb_get_serial_data(serial);
1704 p_priv = usb_get_serial_port_data(port);
1705 d_details = s_priv->device_details;
1706 device_port = port->number - port->serial->minor;
1708 outcont_urb = d_details->outcont_endpoints[port->number];
1709 this_urb = p_priv->outcont_urb;
1711 dbg("%s - endpoint %d", __func__, usb_pipeendpoint(this_urb->pipe));
1713 /* Make sure we have an urb then send the message */
1714 if (this_urb == NULL) {
1715 dbg("%s - oops no urb.", __func__);
1719 /* Save reset port val for resend.
1720 Don't overwrite resend for open/close condition. */
1721 if ((reset_port + 1) > p_priv->resend_cont)
1722 p_priv->resend_cont = reset_port + 1;
1723 if (this_urb->status == -EINPROGRESS) {
1724 /* dbg("%s - already writing", __func__); */
1729 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1731 /* Only set baud rate if it's changed */
1732 if (p_priv->old_baud != p_priv->baud) {
1733 p_priv->old_baud = p_priv->baud;
1734 msg.setClocking = 0xff;
1735 if (d_details->calculate_baud_rate
1736 (p_priv->baud, d_details->baudclk, &msg.baudHi,
1737 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1738 dbg("%s - Invalid baud rate %d requested, using 9600.",
1739 __func__, p_priv->baud);
1741 msg.baudHi = 125; /* Values for 9600 baud */
1744 msg.setPrescaler = 0xff;
1747 msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1;
1748 switch (p_priv->cflag & CSIZE) {
1750 msg.lcr |= USA_DATABITS_5;
1753 msg.lcr |= USA_DATABITS_6;
1756 msg.lcr |= USA_DATABITS_7;
1759 msg.lcr |= USA_DATABITS_8;
1762 if (p_priv->cflag & PARENB) {
1763 /* note USA_PARITY_NONE == 0 */
1764 msg.lcr |= (p_priv->cflag & PARODD)?
1765 USA_PARITY_ODD : USA_PARITY_EVEN;
1769 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1770 msg.xonFlowControl = 0;
1771 msg.setFlowControl = 0xff;
1772 msg.forwardingLength = 16;
1777 if (reset_port == 1) {
1786 msg.returnStatus = 0;
1787 msg.resetDataToggle = 0xff;
1791 else if (reset_port == 2) {
1800 msg.returnStatus = 0;
1801 msg.resetDataToggle = 0;
1804 /* Sending intermediate configs */
1806 msg._txOn = (!p_priv->break_on);
1809 msg.txBreak = (p_priv->break_on);
1814 msg.returnStatus = 0;
1815 msg.resetDataToggle = 0x0;
1818 /* Do handshaking outputs */
1819 msg.setTxTriState_setRts = 0xff;
1820 msg.txTriState_rts = p_priv->rts_state;
1822 msg.setHskoa_setDtr = 0xff;
1823 msg.hskoa_dtr = p_priv->dtr_state;
1825 p_priv->resend_cont = 0;
1826 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1828 /* send the data out the device on control endpoint */
1829 this_urb->transfer_buffer_length = sizeof(msg);
1831 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1833 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
1836 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__
1837 outcont_urb, this_urb->transfer_buffer_length,
1838 usb_pipeendpoint(this_urb->pipe));
1845 static int keyspan_usa28_send_setup(struct usb_serial *serial,
1846 struct usb_serial_port *port,
1849 struct keyspan_usa28_portControlMessage msg;
1850 struct keyspan_serial_private *s_priv;
1851 struct keyspan_port_private *p_priv;
1852 const struct keyspan_device_details *d_details;
1853 struct urb *this_urb;
1854 int device_port, err;
1856 dbg("%s", __func__);
1858 s_priv = usb_get_serial_data(serial);
1859 p_priv = usb_get_serial_port_data(port);
1860 d_details = s_priv->device_details;
1861 device_port = port->number - port->serial->minor;
1863 /* only do something if we have a bulk out endpoint */
1864 this_urb = p_priv->outcont_urb;
1865 if (this_urb == NULL) {
1866 dbg("%s - oops no urb.", __func__);
1870 /* Save reset port val for resend.
1871 Don't overwrite resend for open/close condition. */
1872 if ((reset_port + 1) > p_priv->resend_cont)
1873 p_priv->resend_cont = reset_port + 1;
1874 if (this_urb->status == -EINPROGRESS) {
1875 dbg("%s already writing", __func__);
1880 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
1882 msg.setBaudRate = 1;
1883 if (d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk,
1884 &msg.baudHi, &msg.baudLo, NULL, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1885 dbg("%s - Invalid baud rate requested %d.",
1886 __func__, p_priv->baud);
1888 msg.baudHi = 0xb2; /* Values for 9600 baud */
1891 /* If parity is enabled, we must calculate it ourselves. */
1892 msg.parity = 0; /* XXX for now */
1894 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1895 msg.xonFlowControl = 0;
1897 /* Do handshaking outputs, DTR is inverted relative to RTS */
1898 msg.rts = p_priv->rts_state;
1899 msg.dtr = p_priv->dtr_state;
1901 msg.forwardingLength = 16;
1903 msg.breakThreshold = 45;
1907 /*msg.returnStatus = 1;
1908 msg.resetDataToggle = 0xff;*/
1910 if (reset_port == 1) {
1914 msg.txForceXoff = 0;
1920 msg.returnStatus = 0;
1921 msg.resetDataToggle = 0xff;
1924 else if (reset_port == 2) {
1928 msg.txForceXoff = 0;
1934 msg.returnStatus = 0;
1935 msg.resetDataToggle = 0;
1937 /* Sending intermediate configs */
1939 msg._txOn = (!p_priv->break_on);
1942 msg.txForceXoff = 0;
1943 msg.txBreak = (p_priv->break_on);
1948 msg.returnStatus = 0;
1949 msg.resetDataToggle = 0x0;
1952 p_priv->resend_cont = 0;
1953 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1955 /* send the data out the device on control endpoint */
1956 this_urb->transfer_buffer_length = sizeof(msg);
1958 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1960 dbg("%s - usb_submit_urb(setup) failed", __func__);
1963 dbg("%s - usb_submit_urb(setup) OK %d bytes", __func__,
1964 this_urb->transfer_buffer_length);
1971 static int keyspan_usa49_send_setup(struct usb_serial *serial,
1972 struct usb_serial_port *port,
1975 struct keyspan_usa49_portControlMessage msg;
1976 struct usb_ctrlrequest *dr = NULL;
1977 struct keyspan_serial_private *s_priv;
1978 struct keyspan_port_private *p_priv;
1979 const struct keyspan_device_details *d_details;
1980 struct urb *this_urb;
1981 int err, device_port;
1983 dbg("%s", __func__);
1985 s_priv = usb_get_serial_data(serial);
1986 p_priv = usb_get_serial_port_data(port);
1987 d_details = s_priv->device_details;
1989 this_urb = s_priv->glocont_urb;
1991 /* Work out which port within the device is being setup */
1992 device_port = port->number - port->serial->minor;
1994 /* Make sure we have an urb then send the message */
1995 if (this_urb == NULL) {
1996 dbg("%s - oops no urb for port %d.", __func__, port->number);
2000 dbg("%s - endpoint %d port %d (%d)",
2001 __func__, usb_pipeendpoint(this_urb->pipe),
2002 port->number, device_port);
2004 /* Save reset port val for resend.
2005 Don't overwrite resend for open/close condition. */
2006 if ((reset_port + 1) > p_priv->resend_cont)
2007 p_priv->resend_cont = reset_port + 1;
2009 if (this_urb->status == -EINPROGRESS) {
2010 /* dbg("%s - already writing", __func__); */
2015 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
2017 /*msg.portNumber = port->number;*/
2018 msg.portNumber = device_port;
2020 /* Only set baud rate if it's changed */
2021 if (p_priv->old_baud != p_priv->baud) {
2022 p_priv->old_baud = p_priv->baud;
2023 msg.setClocking = 0xff;
2024 if (d_details->calculate_baud_rate
2025 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2026 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2027 dbg("%s - Invalid baud rate %d requested, using 9600.",
2028 __func__, p_priv->baud);
2030 msg.baudHi = 125; /* Values for 9600 baud */
2033 /* msg.setPrescaler = 0xff; */
2036 msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1;
2037 switch (p_priv->cflag & CSIZE) {
2039 msg.lcr |= USA_DATABITS_5;
2042 msg.lcr |= USA_DATABITS_6;
2045 msg.lcr |= USA_DATABITS_7;
2048 msg.lcr |= USA_DATABITS_8;
2051 if (p_priv->cflag & PARENB) {
2052 /* note USA_PARITY_NONE == 0 */
2053 msg.lcr |= (p_priv->cflag & PARODD)?
2054 USA_PARITY_ODD : USA_PARITY_EVEN;
2058 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2059 msg.xonFlowControl = 0;
2060 msg.setFlowControl = 0xff;
2062 msg.forwardingLength = 16;
2067 if (reset_port == 1) {
2076 msg.returnStatus = 0;
2077 msg.resetDataToggle = 0xff;
2079 msg.disablePort = 0;
2082 else if (reset_port == 2) {
2091 msg.returnStatus = 0;
2092 msg.resetDataToggle = 0;
2094 msg.disablePort = 1;
2096 /* Sending intermediate configs */
2098 msg._txOn = (!p_priv->break_on);
2101 msg.txBreak = (p_priv->break_on);
2106 msg.returnStatus = 0;
2107 msg.resetDataToggle = 0x0;
2109 msg.disablePort = 0;
2112 /* Do handshaking outputs */
2114 msg.rts = p_priv->rts_state;
2117 msg.dtr = p_priv->dtr_state;
2119 p_priv->resend_cont = 0;
2121 /* if the device is a 49wg, we send control message on usb
2124 if (d_details->product_id == keyspan_usa49wg_product_id) {
2125 dr = (void *)(s_priv->ctrl_buf);
2126 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
2127 dr->bRequest = 0xB0; /* 49wg control message */;
2130 dr->wLength = cpu_to_le16(sizeof(msg));
2132 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
2134 usb_fill_control_urb(this_urb, serial->dev,
2135 usb_sndctrlpipe(serial->dev, 0),
2136 (unsigned char *)dr, s_priv->glocont_buf,
2137 sizeof(msg), usa49_glocont_callback, serial);
2140 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2142 /* send the data out the device on control endpoint */
2143 this_urb->transfer_buffer_length = sizeof(msg);
2145 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2147 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
2150 dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__,
2151 outcont_urb, this_urb->transfer_buffer_length,
2152 usb_pipeendpoint(this_urb->pipe));
2159 static int keyspan_usa90_send_setup(struct usb_serial *serial,
2160 struct usb_serial_port *port,
2163 struct keyspan_usa90_portControlMessage msg;
2164 struct keyspan_serial_private *s_priv;
2165 struct keyspan_port_private *p_priv;
2166 const struct keyspan_device_details *d_details;
2167 struct urb *this_urb;
2171 dbg("%s", __func__);
2173 s_priv = usb_get_serial_data(serial);
2174 p_priv = usb_get_serial_port_data(port);
2175 d_details = s_priv->device_details;
2177 /* only do something if we have a bulk out endpoint */
2178 this_urb = p_priv->outcont_urb;
2179 if (this_urb == NULL) {
2180 dbg("%s - oops no urb.", __func__);
2184 /* Save reset port val for resend.
2185 Don't overwrite resend for open/close condition. */
2186 if ((reset_port + 1) > p_priv->resend_cont)
2187 p_priv->resend_cont = reset_port + 1;
2188 if (this_urb->status == -EINPROGRESS) {
2189 dbg("%s already writing", __func__);
2194 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2196 /* Only set baud rate if it's changed */
2197 if (p_priv->old_baud != p_priv->baud) {
2198 p_priv->old_baud = p_priv->baud;
2199 msg.setClocking = 0x01;
2200 if (d_details->calculate_baud_rate
2201 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2202 &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2203 dbg("%s - Invalid baud rate %d requested, using 9600.",
2204 __func__, p_priv->baud);
2205 p_priv->baud = 9600;
2206 d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk,
2207 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2213 /* modes must always be correctly specified */
2214 if (p_priv->baud > 57600) {
2215 msg.rxMode = RXMODE_DMA;
2216 msg.txMode = TXMODE_DMA;
2218 msg.rxMode = RXMODE_BYHAND;
2219 msg.txMode = TXMODE_BYHAND;
2222 msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1;
2223 switch (p_priv->cflag & CSIZE) {
2225 msg.lcr |= USA_DATABITS_5;
2228 msg.lcr |= USA_DATABITS_6;
2231 msg.lcr |= USA_DATABITS_7;
2234 msg.lcr |= USA_DATABITS_8;
2237 if (p_priv->cflag & PARENB) {
2238 /* note USA_PARITY_NONE == 0 */
2239 msg.lcr |= (p_priv->cflag & PARODD)?
2240 USA_PARITY_ODD : USA_PARITY_EVEN;
2242 if (p_priv->old_cflag != p_priv->cflag) {
2243 p_priv->old_cflag = p_priv->cflag;
2247 if (p_priv->flow_control == flow_cts)
2248 msg.txFlowControl = TXFLOW_CTS;
2249 msg.setTxFlowControl = 0x01;
2250 msg.setRxFlowControl = 0x01;
2252 msg.rxForwardingLength = 16;
2253 msg.rxForwardingTimeout = 16;
2254 msg.txAckSetting = 0;
2259 if (reset_port == 1) {
2260 msg.portEnabled = 1;
2262 msg.txBreak = (p_priv->break_on);
2265 else if (reset_port == 2)
2266 msg.portEnabled = 0;
2267 /* Sending intermediate configs */
2269 msg.portEnabled = 1;
2270 msg.txBreak = (p_priv->break_on);
2273 /* Do handshaking outputs */
2275 msg.rts = p_priv->rts_state;
2278 msg.dtr = p_priv->dtr_state;
2280 p_priv->resend_cont = 0;
2281 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2283 /* send the data out the device on control endpoint */
2284 this_urb->transfer_buffer_length = sizeof(msg);
2286 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2288 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
2292 static int keyspan_usa67_send_setup(struct usb_serial *serial,
2293 struct usb_serial_port *port,
2296 struct keyspan_usa67_portControlMessage msg;
2297 struct keyspan_serial_private *s_priv;
2298 struct keyspan_port_private *p_priv;
2299 const struct keyspan_device_details *d_details;
2300 struct urb *this_urb;
2301 int err, device_port;
2303 dbg("%s", __func__);
2305 s_priv = usb_get_serial_data(serial);
2306 p_priv = usb_get_serial_port_data(port);
2307 d_details = s_priv->device_details;
2309 this_urb = s_priv->glocont_urb;
2311 /* Work out which port within the device is being setup */
2312 device_port = port->number - port->serial->minor;
2314 /* Make sure we have an urb then send the message */
2315 if (this_urb == NULL) {
2316 dbg("%s - oops no urb for port %d.", __func__,
2321 /* Save reset port val for resend.
2322 Don't overwrite resend for open/close condition. */
2323 if ((reset_port + 1) > p_priv->resend_cont)
2324 p_priv->resend_cont = reset_port + 1;
2325 if (this_urb->status == -EINPROGRESS) {
2326 /* dbg("%s - already writing", __func__); */
2331 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
2333 msg.port = device_port;
2335 /* Only set baud rate if it's changed */
2336 if (p_priv->old_baud != p_priv->baud) {
2337 p_priv->old_baud = p_priv->baud;
2338 msg.setClocking = 0xff;
2339 if (d_details->calculate_baud_rate
2340 (p_priv->baud, d_details->baudclk, &msg.baudHi,
2341 &msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2342 dbg("%s - Invalid baud rate %d requested, using 9600.",
2343 __func__, p_priv->baud);
2345 msg.baudHi = 125; /* Values for 9600 baud */
2348 msg.setPrescaler = 0xff;
2351 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2352 switch (p_priv->cflag & CSIZE) {
2354 msg.lcr |= USA_DATABITS_5;
2357 msg.lcr |= USA_DATABITS_6;
2360 msg.lcr |= USA_DATABITS_7;
2363 msg.lcr |= USA_DATABITS_8;
2366 if (p_priv->cflag & PARENB) {
2367 /* note USA_PARITY_NONE == 0 */
2368 msg.lcr |= (p_priv->cflag & PARODD)?
2369 USA_PARITY_ODD : USA_PARITY_EVEN;
2373 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2374 msg.xonFlowControl = 0;
2375 msg.setFlowControl = 0xff;
2376 msg.forwardingLength = 16;
2380 if (reset_port == 1) {
2390 msg.returnStatus = 0;
2391 msg.resetDataToggle = 0xff;
2392 } else if (reset_port == 2) {
2402 msg.returnStatus = 0;
2403 msg.resetDataToggle = 0;
2405 /* Sending intermediate configs */
2406 msg._txOn = (!p_priv->break_on);
2409 msg.txBreak = (p_priv->break_on);
2414 msg.returnStatus = 0;
2415 msg.resetDataToggle = 0x0;
2418 /* Do handshaking outputs */
2419 msg.setTxTriState_setRts = 0xff;
2420 msg.txTriState_rts = p_priv->rts_state;
2422 msg.setHskoa_setDtr = 0xff;
2423 msg.hskoa_dtr = p_priv->dtr_state;
2425 p_priv->resend_cont = 0;
2427 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2429 /* send the data out the device on control endpoint */
2430 this_urb->transfer_buffer_length = sizeof(msg);
2432 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2434 dbg("%s - usb_submit_urb(setup) failed (%d)", __func__,
2439 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2441 struct usb_serial *serial = port->serial;
2442 struct keyspan_serial_private *s_priv;
2443 const struct keyspan_device_details *d_details;
2445 dbg("%s", __func__);
2447 s_priv = usb_get_serial_data(serial);
2448 d_details = s_priv->device_details;
2450 switch (d_details->msg_format) {
2452 keyspan_usa26_send_setup(serial, port, reset_port);
2455 keyspan_usa28_send_setup(serial, port, reset_port);
2458 keyspan_usa49_send_setup(serial, port, reset_port);
2461 keyspan_usa90_send_setup(serial, port, reset_port);
2464 keyspan_usa67_send_setup(serial, port, reset_port);
2470 /* Gets called by the "real" driver (ie once firmware is loaded
2471 and renumeration has taken place. */
2472 static int keyspan_startup(struct usb_serial *serial)
2475 struct usb_serial_port *port;
2476 struct keyspan_serial_private *s_priv;
2477 struct keyspan_port_private *p_priv;
2478 const struct keyspan_device_details *d_details;
2480 dbg("%s", __func__);
2482 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2483 if (d_details->product_id ==
2484 le16_to_cpu(serial->dev->descriptor.idProduct))
2486 if (d_details == NULL) {
2487 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2488 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2492 /* Setup private data for serial driver */
2493 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2495 dbg("%s - kmalloc for keyspan_serial_private failed.",
2500 s_priv->device_details = d_details;
2501 usb_set_serial_data(serial, s_priv);
2503 /* Now setup per port private data */
2504 for (i = 0; i < serial->num_ports; i++) {
2505 port = serial->port[i];
2506 p_priv = kzalloc(sizeof(struct keyspan_port_private),
2509 dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __func__, i);
2512 p_priv->device_details = d_details;
2513 usb_set_serial_port_data(port, p_priv);
2516 keyspan_setup_urbs(serial);
2518 if (s_priv->instat_urb != NULL) {
2519 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2521 dbg("%s - submit instat urb failed %d", __func__,
2524 if (s_priv->indat_urb != NULL) {
2525 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2527 dbg("%s - submit indat urb failed %d", __func__,
2534 static void keyspan_disconnect(struct usb_serial *serial)
2537 struct usb_serial_port *port;
2538 struct keyspan_serial_private *s_priv;
2539 struct keyspan_port_private *p_priv;
2541 dbg("%s", __func__);
2543 s_priv = usb_get_serial_data(serial);
2545 /* Stop reading/writing urbs */
2546 stop_urb(s_priv->instat_urb);
2547 stop_urb(s_priv->glocont_urb);
2548 stop_urb(s_priv->indat_urb);
2549 for (i = 0; i < serial->num_ports; ++i) {
2550 port = serial->port[i];
2551 p_priv = usb_get_serial_port_data(port);
2552 stop_urb(p_priv->inack_urb);
2553 stop_urb(p_priv->outcont_urb);
2554 for (j = 0; j < 2; j++) {
2555 stop_urb(p_priv->in_urbs[j]);
2556 stop_urb(p_priv->out_urbs[j]);
2561 usb_free_urb(s_priv->instat_urb);
2562 usb_free_urb(s_priv->indat_urb);
2563 usb_free_urb(s_priv->glocont_urb);
2564 for (i = 0; i < serial->num_ports; ++i) {
2565 port = serial->port[i];
2566 p_priv = usb_get_serial_port_data(port);
2567 usb_free_urb(p_priv->inack_urb);
2568 usb_free_urb(p_priv->outcont_urb);
2569 for (j = 0; j < 2; j++) {
2570 usb_free_urb(p_priv->in_urbs[j]);
2571 usb_free_urb(p_priv->out_urbs[j]);
2576 static void keyspan_release(struct usb_serial *serial)
2579 struct usb_serial_port *port;
2580 struct keyspan_serial_private *s_priv;
2582 dbg("%s", __func__);
2584 s_priv = usb_get_serial_data(serial);
2586 /* dbg("Freeing serial->private."); */
2589 /* dbg("Freeing port->private."); */
2590 /* Now free per port private data */
2591 for (i = 0; i < serial->num_ports; i++) {
2592 port = serial->port[i];
2593 kfree(usb_get_serial_port_data(port));
2597 MODULE_AUTHOR(DRIVER_AUTHOR);
2598 MODULE_DESCRIPTION(DRIVER_DESC);
2599 MODULE_LICENSE("GPL");
2601 MODULE_FIRMWARE("keyspan/usa28.fw");
2602 MODULE_FIRMWARE("keyspan/usa28x.fw");
2603 MODULE_FIRMWARE("keyspan/usa28xa.fw");
2604 MODULE_FIRMWARE("keyspan/usa28xb.fw");
2605 MODULE_FIRMWARE("keyspan/usa19.fw");
2606 MODULE_FIRMWARE("keyspan/usa19qi.fw");
2607 MODULE_FIRMWARE("keyspan/mpr.fw");
2608 MODULE_FIRMWARE("keyspan/usa19qw.fw");
2609 MODULE_FIRMWARE("keyspan/usa18x.fw");
2610 MODULE_FIRMWARE("keyspan/usa19w.fw");
2611 MODULE_FIRMWARE("keyspan/usa49w.fw");
2612 MODULE_FIRMWARE("keyspan/usa49wlc.fw");
2614 module_param(debug, bool, S_IRUGO | S_IWUSR);
2615 MODULE_PARM_DESC(debug, "Debug enabled or not");