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/slab.h>
35 #include <linux/tty.h>
36 #include <linux/tty_driver.h>
37 #include <linux/tty_flip.h>
38 #include <linux/module.h>
39 #include <linux/spinlock.h>
40 #include <linux/uaccess.h>
41 #include <linux/usb.h>
42 #include <linux/usb/serial.h>
43 #include <linux/usb/ezusb.h>
46 #define DRIVER_AUTHOR "Hugh Blemings <hugh@misc.nu"
47 #define DRIVER_DESC "Keyspan USB to Serial Converter Driver"
49 #define INSTAT_BUFLEN 32
50 #define GLOCONT_BUFLEN 64
51 #define INDAT49W_BUFLEN 512
54 #define INACK_BUFLEN 1
55 #define OUTCONT_BUFLEN 64
57 /* Per device and per port private data */
58 struct keyspan_serial_private {
59 const struct keyspan_device_details *device_details;
61 struct urb *instat_urb;
64 /* added to support 49wg, where data from all 4 ports comes in
65 on 1 EP and high-speed supported */
66 struct urb *indat_urb;
69 /* XXX this one probably will need a lock */
70 struct urb *glocont_urb;
72 char *ctrl_buf; /* for EP0 control message */
75 struct keyspan_port_private {
76 /* Keep track of which input & output endpoints to use */
80 /* Keep duplicate of device details in each port
81 structure as well - simplifies some of the
82 callback functions etc. */
83 const struct keyspan_device_details *device_details;
85 /* Input endpoints and buffer for this port */
86 struct urb *in_urbs[2];
88 /* Output endpoints and buffer for this port */
89 struct urb *out_urbs[2];
92 /* Input ack endpoint */
93 struct urb *inack_urb;
96 /* Output control endpoint */
97 struct urb *outcont_urb;
100 /* Settings for the port */
104 unsigned int old_cflag;
105 enum {flow_none, flow_cts, flow_xon} flow_control;
106 int rts_state; /* Handshaking pins (outputs) */
108 int cts_state; /* Handshaking pins (inputs) */
114 unsigned long tx_start_time[2];
115 int resend_cont; /* need to resend control packet */
118 /* Include Keyspan message headers. All current Keyspan Adapters
119 make use of one of five message formats which are referred
120 to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and
121 within this driver. */
122 #include "keyspan_usa26msg.h"
123 #include "keyspan_usa28msg.h"
124 #include "keyspan_usa49msg.h"
125 #include "keyspan_usa90msg.h"
126 #include "keyspan_usa67msg.h"
129 module_usb_serial_driver(serial_drivers, keyspan_ids_combined);
131 static void keyspan_break_ctl(struct tty_struct *tty, int break_state)
133 struct usb_serial_port *port = tty->driver_data;
134 struct keyspan_port_private *p_priv;
136 p_priv = usb_get_serial_port_data(port);
138 if (break_state == -1)
139 p_priv->break_on = 1;
141 p_priv->break_on = 0;
143 keyspan_send_setup(port, 0);
147 static void keyspan_set_termios(struct tty_struct *tty,
148 struct usb_serial_port *port, struct ktermios *old_termios)
150 int baud_rate, device_port;
151 struct keyspan_port_private *p_priv;
152 const struct keyspan_device_details *d_details;
155 p_priv = usb_get_serial_port_data(port);
156 d_details = p_priv->device_details;
157 cflag = tty->termios.c_cflag;
158 device_port = port->port_number;
160 /* Baud rate calculation takes baud rate as an integer
161 so other rates can be generated if desired. */
162 baud_rate = tty_get_baud_rate(tty);
163 /* If no match or invalid, don't change */
164 if (d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
165 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
166 /* FIXME - more to do here to ensure rate changes cleanly */
167 /* FIXME - calculate exact rate from divisor ? */
168 p_priv->baud = baud_rate;
170 baud_rate = tty_termios_baud_rate(old_termios);
172 tty_encode_baud_rate(tty, baud_rate, baud_rate);
173 /* set CTS/RTS handshake etc. */
174 p_priv->cflag = cflag;
175 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
177 /* Mark/Space not supported */
178 tty->termios.c_cflag &= ~CMSPAR;
180 keyspan_send_setup(port, 0);
183 static int keyspan_tiocmget(struct tty_struct *tty)
185 struct usb_serial_port *port = tty->driver_data;
186 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
189 value = ((p_priv->rts_state) ? TIOCM_RTS : 0) |
190 ((p_priv->dtr_state) ? TIOCM_DTR : 0) |
191 ((p_priv->cts_state) ? TIOCM_CTS : 0) |
192 ((p_priv->dsr_state) ? TIOCM_DSR : 0) |
193 ((p_priv->dcd_state) ? TIOCM_CAR : 0) |
194 ((p_priv->ri_state) ? TIOCM_RNG : 0);
199 static int keyspan_tiocmset(struct tty_struct *tty,
200 unsigned int set, unsigned int clear)
202 struct usb_serial_port *port = tty->driver_data;
203 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
206 p_priv->rts_state = 1;
208 p_priv->dtr_state = 1;
209 if (clear & TIOCM_RTS)
210 p_priv->rts_state = 0;
211 if (clear & TIOCM_DTR)
212 p_priv->dtr_state = 0;
213 keyspan_send_setup(port, 0);
217 /* Write function is similar for the four protocols used
218 with only a minor change for usa90 (usa19hs) required */
219 static int keyspan_write(struct tty_struct *tty,
220 struct usb_serial_port *port, const unsigned char *buf, int count)
222 struct keyspan_port_private *p_priv;
223 const struct keyspan_device_details *d_details;
226 struct urb *this_urb;
227 int err, maxDataLen, dataOffset;
229 p_priv = usb_get_serial_port_data(port);
230 d_details = p_priv->device_details;
232 if (d_details->msg_format == msg_usa90) {
240 dev_dbg(&port->dev, "%s - %d chars, flip=%d\n", __func__, count,
243 for (left = count; left > 0; left -= todo) {
245 if (todo > maxDataLen)
248 flip = p_priv->out_flip;
250 /* Check we have a valid urb/endpoint before we use it... */
251 this_urb = p_priv->out_urbs[flip];
252 if (this_urb == NULL) {
253 /* no bulk out, so return 0 bytes written */
254 dev_dbg(&port->dev, "%s - no output urb :(\n", __func__);
258 dev_dbg(&port->dev, "%s - endpoint %d flip %d\n",
259 __func__, usb_pipeendpoint(this_urb->pipe), flip);
261 if (this_urb->status == -EINPROGRESS) {
262 if (time_before(jiffies,
263 p_priv->tx_start_time[flip] + 10 * HZ))
265 usb_unlink_urb(this_urb);
269 /* First byte in buffer is "last flag" (except for usa19hx)
270 - unused so for now so set to zero */
271 ((char *)this_urb->transfer_buffer)[0] = 0;
273 memcpy(this_urb->transfer_buffer + dataOffset, buf, todo);
276 /* send the data out the bulk port */
277 this_urb->transfer_buffer_length = todo + dataOffset;
279 err = usb_submit_urb(this_urb, GFP_ATOMIC);
281 dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed (%d)\n", err);
282 p_priv->tx_start_time[flip] = jiffies;
284 /* Flip for next time if usa26 or usa28 interface
285 (not used on usa49) */
286 p_priv->out_flip = (flip + 1) & d_details->outdat_endp_flip;
292 static void usa26_indat_callback(struct urb *urb)
296 struct usb_serial_port *port;
297 unsigned char *data = urb->transfer_buffer;
298 int status = urb->status;
300 endpoint = usb_pipeendpoint(urb->pipe);
303 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
304 __func__, status, endpoint);
309 if (urb->actual_length) {
310 /* 0x80 bit is error flag */
311 if ((data[0] & 0x80) == 0) {
312 /* no errors on individual bytes, only
313 possible overrun err */
314 if (data[0] & RXERROR_OVERRUN)
318 for (i = 1; i < urb->actual_length ; ++i)
319 tty_insert_flip_char(&port->port, data[i], err);
321 /* some bytes had errors, every byte has status */
322 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
323 for (i = 0; i + 1 < urb->actual_length; i += 2) {
325 int flag = TTY_NORMAL;
327 if (stat & RXERROR_OVERRUN) {
328 tty_insert_flip_char(&port->port, 0,
331 /* XXX should handle break (0x10) */
332 if (stat & RXERROR_PARITY)
334 else if (stat & RXERROR_FRAMING)
337 tty_insert_flip_char(&port->port, data[i+1],
341 tty_flip_buffer_push(&port->port);
344 /* Resubmit urb so we continue receiving */
345 err = usb_submit_urb(urb, GFP_ATOMIC);
347 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
350 /* Outdat handling is common for all devices */
351 static void usa2x_outdat_callback(struct urb *urb)
353 struct usb_serial_port *port;
354 struct keyspan_port_private *p_priv;
357 p_priv = usb_get_serial_port_data(port);
358 dev_dbg(&port->dev, "%s - urb %d\n", __func__, urb == p_priv->out_urbs[1]);
360 usb_serial_port_softint(port);
363 static void usa26_inack_callback(struct urb *urb)
367 static void usa26_outcont_callback(struct urb *urb)
369 struct usb_serial_port *port;
370 struct keyspan_port_private *p_priv;
373 p_priv = usb_get_serial_port_data(port);
375 if (p_priv->resend_cont) {
376 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
377 keyspan_usa26_send_setup(port->serial, port,
378 p_priv->resend_cont - 1);
382 static void usa26_instat_callback(struct urb *urb)
384 unsigned char *data = urb->transfer_buffer;
385 struct keyspan_usa26_portStatusMessage *msg;
386 struct usb_serial *serial;
387 struct usb_serial_port *port;
388 struct keyspan_port_private *p_priv;
389 int old_dcd_state, err;
390 int status = urb->status;
392 serial = urb->context;
395 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
398 if (urb->actual_length != 9) {
399 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
403 msg = (struct keyspan_usa26_portStatusMessage *)data;
405 /* Check port number from message and retrieve private data */
406 if (msg->port >= serial->num_ports) {
407 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
410 port = serial->port[msg->port];
411 p_priv = usb_get_serial_port_data(port);
413 /* Update handshaking pin state information */
414 old_dcd_state = p_priv->dcd_state;
415 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
416 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
417 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
418 p_priv->ri_state = ((msg->ri) ? 1 : 0);
420 if (old_dcd_state != p_priv->dcd_state)
421 tty_port_tty_hangup(&port->port, true);
423 /* Resubmit urb so we continue receiving */
424 err = usb_submit_urb(urb, GFP_ATOMIC);
426 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
430 static void usa26_glocont_callback(struct urb *urb)
435 static void usa28_indat_callback(struct urb *urb)
438 struct usb_serial_port *port;
440 struct keyspan_port_private *p_priv;
441 int status = urb->status;
444 p_priv = usb_get_serial_port_data(port);
445 data = urb->transfer_buffer;
447 if (urb != p_priv->in_urbs[p_priv->in_flip])
452 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
453 __func__, status, usb_pipeendpoint(urb->pipe));
458 p_priv = usb_get_serial_port_data(port);
459 data = urb->transfer_buffer;
461 if (urb->actual_length) {
462 tty_insert_flip_string(&port->port, data,
464 tty_flip_buffer_push(&port->port);
467 /* Resubmit urb so we continue receiving */
468 err = usb_submit_urb(urb, GFP_ATOMIC);
470 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n",
472 p_priv->in_flip ^= 1;
474 urb = p_priv->in_urbs[p_priv->in_flip];
475 } while (urb->status != -EINPROGRESS);
478 static void usa28_inack_callback(struct urb *urb)
482 static void usa28_outcont_callback(struct urb *urb)
484 struct usb_serial_port *port;
485 struct keyspan_port_private *p_priv;
488 p_priv = usb_get_serial_port_data(port);
490 if (p_priv->resend_cont) {
491 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
492 keyspan_usa28_send_setup(port->serial, port,
493 p_priv->resend_cont - 1);
497 static void usa28_instat_callback(struct urb *urb)
500 unsigned char *data = urb->transfer_buffer;
501 struct keyspan_usa28_portStatusMessage *msg;
502 struct usb_serial *serial;
503 struct usb_serial_port *port;
504 struct keyspan_port_private *p_priv;
506 int status = urb->status;
508 serial = urb->context;
511 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
515 if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) {
516 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
520 msg = (struct keyspan_usa28_portStatusMessage *)data;
522 /* Check port number from message and retrieve private data */
523 if (msg->port >= serial->num_ports) {
524 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
527 port = serial->port[msg->port];
528 p_priv = usb_get_serial_port_data(port);
530 /* Update handshaking pin state information */
531 old_dcd_state = p_priv->dcd_state;
532 p_priv->cts_state = ((msg->cts) ? 1 : 0);
533 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
534 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
535 p_priv->ri_state = ((msg->ri) ? 1 : 0);
537 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
538 tty_port_tty_hangup(&port->port, true);
540 /* Resubmit urb so we continue receiving */
541 err = usb_submit_urb(urb, GFP_ATOMIC);
543 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
547 static void usa28_glocont_callback(struct urb *urb)
552 static void usa49_glocont_callback(struct urb *urb)
554 struct usb_serial *serial;
555 struct usb_serial_port *port;
556 struct keyspan_port_private *p_priv;
559 serial = urb->context;
560 for (i = 0; i < serial->num_ports; ++i) {
561 port = serial->port[i];
562 p_priv = usb_get_serial_port_data(port);
564 if (p_priv->resend_cont) {
565 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
566 keyspan_usa49_send_setup(serial, port,
567 p_priv->resend_cont - 1);
573 /* This is actually called glostat in the Keyspan
575 static void usa49_instat_callback(struct urb *urb)
578 unsigned char *data = urb->transfer_buffer;
579 struct keyspan_usa49_portStatusMessage *msg;
580 struct usb_serial *serial;
581 struct usb_serial_port *port;
582 struct keyspan_port_private *p_priv;
584 int status = urb->status;
586 serial = urb->context;
589 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
593 if (urb->actual_length !=
594 sizeof(struct keyspan_usa49_portStatusMessage)) {
595 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
599 msg = (struct keyspan_usa49_portStatusMessage *)data;
601 /* Check port number from message and retrieve private data */
602 if (msg->portNumber >= serial->num_ports) {
603 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
604 __func__, msg->portNumber);
607 port = serial->port[msg->portNumber];
608 p_priv = usb_get_serial_port_data(port);
610 /* Update handshaking pin state information */
611 old_dcd_state = p_priv->dcd_state;
612 p_priv->cts_state = ((msg->cts) ? 1 : 0);
613 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
614 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
615 p_priv->ri_state = ((msg->ri) ? 1 : 0);
617 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
618 tty_port_tty_hangup(&port->port, true);
620 /* Resubmit urb so we continue receiving */
621 err = usb_submit_urb(urb, GFP_ATOMIC);
623 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
627 static void usa49_inack_callback(struct urb *urb)
631 static void usa49_indat_callback(struct urb *urb)
635 struct usb_serial_port *port;
636 unsigned char *data = urb->transfer_buffer;
637 int status = urb->status;
639 endpoint = usb_pipeendpoint(urb->pipe);
642 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
643 __func__, status, endpoint);
648 if (urb->actual_length) {
649 /* 0x80 bit is error flag */
650 if ((data[0] & 0x80) == 0) {
651 /* no error on any byte */
652 tty_insert_flip_string(&port->port, data + 1,
653 urb->actual_length - 1);
655 /* some bytes had errors, every byte has status */
656 for (i = 0; i + 1 < urb->actual_length; i += 2) {
658 int flag = TTY_NORMAL;
660 if (stat & RXERROR_OVERRUN) {
661 tty_insert_flip_char(&port->port, 0,
664 /* XXX should handle break (0x10) */
665 if (stat & RXERROR_PARITY)
667 else if (stat & RXERROR_FRAMING)
670 tty_insert_flip_char(&port->port, data[i+1],
674 tty_flip_buffer_push(&port->port);
677 /* Resubmit urb so we continue receiving */
678 err = usb_submit_urb(urb, GFP_ATOMIC);
680 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
683 static void usa49wg_indat_callback(struct urb *urb)
686 struct usb_serial *serial;
687 struct usb_serial_port *port;
688 unsigned char *data = urb->transfer_buffer;
689 int status = urb->status;
691 serial = urb->context;
694 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
698 /* inbound data is in the form P#, len, status, data */
702 while (i < urb->actual_length) {
704 /* Check port number from message */
705 if (data[i] >= serial->num_ports) {
706 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
710 port = serial->port[data[i++]];
713 /* 0x80 bit is error flag */
714 if ((data[i] & 0x80) == 0) {
715 /* no error on any byte */
717 for (x = 1; x < len && i < urb->actual_length; ++x)
718 tty_insert_flip_char(&port->port,
722 * some bytes had errors, every byte has status
724 for (x = 0; x + 1 < len &&
725 i + 1 < urb->actual_length; x += 2) {
727 int flag = TTY_NORMAL;
729 if (stat & RXERROR_OVERRUN) {
730 tty_insert_flip_char(&port->port, 0,
733 /* XXX should handle break (0x10) */
734 if (stat & RXERROR_PARITY)
736 else if (stat & RXERROR_FRAMING)
739 tty_insert_flip_char(&port->port, data[i+1],
744 tty_flip_buffer_push(&port->port);
747 /* Resubmit urb so we continue receiving */
748 err = usb_submit_urb(urb, GFP_ATOMIC);
750 dev_dbg(&urb->dev->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
753 /* not used, usa-49 doesn't have per-port control endpoints */
754 static void usa49_outcont_callback(struct urb *urb)
758 static void usa90_indat_callback(struct urb *urb)
762 struct usb_serial_port *port;
763 struct keyspan_port_private *p_priv;
764 unsigned char *data = urb->transfer_buffer;
765 int status = urb->status;
767 endpoint = usb_pipeendpoint(urb->pipe);
770 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
771 __func__, status, endpoint);
776 p_priv = usb_get_serial_port_data(port);
778 if (urb->actual_length) {
779 /* if current mode is DMA, looks like usa28 format
780 otherwise looks like usa26 data format */
782 if (p_priv->baud > 57600)
783 tty_insert_flip_string(&port->port, data,
786 /* 0x80 bit is error flag */
787 if ((data[0] & 0x80) == 0) {
788 /* no errors on individual bytes, only
789 possible overrun err*/
790 if (data[0] & RXERROR_OVERRUN)
794 for (i = 1; i < urb->actual_length ; ++i)
795 tty_insert_flip_char(&port->port,
798 /* some bytes had errors, every byte has status */
799 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
800 for (i = 0; i + 1 < urb->actual_length; i += 2) {
802 int flag = TTY_NORMAL;
804 if (stat & RXERROR_OVERRUN) {
805 tty_insert_flip_char(
809 /* XXX should handle break (0x10) */
810 if (stat & RXERROR_PARITY)
812 else if (stat & RXERROR_FRAMING)
815 tty_insert_flip_char(&port->port,
820 tty_flip_buffer_push(&port->port);
823 /* Resubmit urb so we continue receiving */
824 err = usb_submit_urb(urb, GFP_ATOMIC);
826 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
830 static void usa90_instat_callback(struct urb *urb)
832 unsigned char *data = urb->transfer_buffer;
833 struct keyspan_usa90_portStatusMessage *msg;
834 struct usb_serial *serial;
835 struct usb_serial_port *port;
836 struct keyspan_port_private *p_priv;
837 int old_dcd_state, err;
838 int status = urb->status;
840 serial = urb->context;
843 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
846 if (urb->actual_length < 14) {
847 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
851 msg = (struct keyspan_usa90_portStatusMessage *)data;
853 /* Now do something useful with the data */
855 port = serial->port[0];
856 p_priv = usb_get_serial_port_data(port);
858 /* Update handshaking pin state information */
859 old_dcd_state = p_priv->dcd_state;
860 p_priv->cts_state = ((msg->cts) ? 1 : 0);
861 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
862 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
863 p_priv->ri_state = ((msg->ri) ? 1 : 0);
865 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
866 tty_port_tty_hangup(&port->port, true);
868 /* Resubmit urb so we continue receiving */
869 err = usb_submit_urb(urb, GFP_ATOMIC);
871 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
876 static void usa90_outcont_callback(struct urb *urb)
878 struct usb_serial_port *port;
879 struct keyspan_port_private *p_priv;
882 p_priv = usb_get_serial_port_data(port);
884 if (p_priv->resend_cont) {
885 dev_dbg(&urb->dev->dev, "%s - sending setup\n", __func__);
886 keyspan_usa90_send_setup(port->serial, port,
887 p_priv->resend_cont - 1);
891 /* Status messages from the 28xg */
892 static void usa67_instat_callback(struct urb *urb)
895 unsigned char *data = urb->transfer_buffer;
896 struct keyspan_usa67_portStatusMessage *msg;
897 struct usb_serial *serial;
898 struct usb_serial_port *port;
899 struct keyspan_port_private *p_priv;
901 int status = urb->status;
903 serial = urb->context;
906 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
910 if (urb->actual_length !=
911 sizeof(struct keyspan_usa67_portStatusMessage)) {
912 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
917 /* Now do something useful with the data */
918 msg = (struct keyspan_usa67_portStatusMessage *)data;
920 /* Check port number from message and retrieve private data */
921 if (msg->port >= serial->num_ports) {
922 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
926 port = serial->port[msg->port];
927 p_priv = usb_get_serial_port_data(port);
929 /* Update handshaking pin state information */
930 old_dcd_state = p_priv->dcd_state;
931 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
932 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
934 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
935 tty_port_tty_hangup(&port->port, true);
937 /* Resubmit urb so we continue receiving */
938 err = usb_submit_urb(urb, GFP_ATOMIC);
940 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
943 static void usa67_glocont_callback(struct urb *urb)
945 struct usb_serial *serial;
946 struct usb_serial_port *port;
947 struct keyspan_port_private *p_priv;
950 serial = urb->context;
951 for (i = 0; i < serial->num_ports; ++i) {
952 port = serial->port[i];
953 p_priv = usb_get_serial_port_data(port);
955 if (p_priv->resend_cont) {
956 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
957 keyspan_usa67_send_setup(serial, port,
958 p_priv->resend_cont - 1);
964 static int keyspan_write_room(struct tty_struct *tty)
966 struct usb_serial_port *port = tty->driver_data;
967 struct keyspan_port_private *p_priv;
968 const struct keyspan_device_details *d_details;
971 struct urb *this_urb;
973 p_priv = usb_get_serial_port_data(port);
974 d_details = p_priv->device_details;
977 if (d_details->msg_format == msg_usa90)
982 flip = p_priv->out_flip;
984 /* Check both endpoints to see if any are available. */
985 this_urb = p_priv->out_urbs[flip];
986 if (this_urb != NULL) {
987 if (this_urb->status != -EINPROGRESS)
989 flip = (flip + 1) & d_details->outdat_endp_flip;
990 this_urb = p_priv->out_urbs[flip];
991 if (this_urb != NULL) {
992 if (this_urb->status != -EINPROGRESS)
1000 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1002 struct keyspan_port_private *p_priv;
1003 const struct keyspan_device_details *d_details;
1005 int baud_rate, device_port;
1007 unsigned int cflag = 0;
1009 p_priv = usb_get_serial_port_data(port);
1010 d_details = p_priv->device_details;
1012 /* Set some sane defaults */
1013 p_priv->rts_state = 1;
1014 p_priv->dtr_state = 1;
1015 p_priv->baud = 9600;
1017 /* force baud and lcr to be set on open */
1018 p_priv->old_baud = 0;
1019 p_priv->old_cflag = 0;
1021 p_priv->out_flip = 0;
1022 p_priv->in_flip = 0;
1024 /* Reset low level data toggle and start reading from endpoints */
1025 for (i = 0; i < 2; i++) {
1026 urb = p_priv->in_urbs[i];
1030 /* make sure endpoint data toggle is synchronized
1032 usb_clear_halt(urb->dev, urb->pipe);
1033 err = usb_submit_urb(urb, GFP_KERNEL);
1035 dev_dbg(&port->dev, "%s - submit urb %d failed (%d)\n", __func__, i, err);
1038 /* Reset low level data toggle on out endpoints */
1039 for (i = 0; i < 2; i++) {
1040 urb = p_priv->out_urbs[i];
1043 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1044 usb_pipeout(urb->pipe), 0); */
1047 /* get the terminal config for the setup message now so we don't
1048 * need to send 2 of them */
1050 device_port = port->port_number;
1052 cflag = tty->termios.c_cflag;
1053 /* Baud rate calculation takes baud rate as an integer
1054 so other rates can be generated if desired. */
1055 baud_rate = tty_get_baud_rate(tty);
1056 /* If no match or invalid, leave as default */
1058 && d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
1059 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1060 p_priv->baud = baud_rate;
1063 /* set CTS/RTS handshake etc. */
1064 p_priv->cflag = cflag;
1065 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
1067 keyspan_send_setup(port, 1);
1069 /* keyspan_set_termios(port, NULL); */
1074 static inline void stop_urb(struct urb *urb)
1076 if (urb && urb->status == -EINPROGRESS)
1080 static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1082 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
1084 p_priv->rts_state = on;
1085 p_priv->dtr_state = on;
1086 keyspan_send_setup(port, 0);
1089 static void keyspan_close(struct usb_serial_port *port)
1092 struct keyspan_port_private *p_priv;
1094 p_priv = usb_get_serial_port_data(port);
1096 p_priv->rts_state = 0;
1097 p_priv->dtr_state = 0;
1099 keyspan_send_setup(port, 2);
1100 /* pilot-xfer seems to work best with this delay */
1103 p_priv->out_flip = 0;
1104 p_priv->in_flip = 0;
1106 stop_urb(p_priv->inack_urb);
1107 for (i = 0; i < 2; i++) {
1108 stop_urb(p_priv->in_urbs[i]);
1109 stop_urb(p_priv->out_urbs[i]);
1113 /* download the firmware to a pre-renumeration device */
1114 static int keyspan_fake_startup(struct usb_serial *serial)
1118 dev_dbg(&serial->dev->dev, "Keyspan startup version %04x product %04x\n",
1119 le16_to_cpu(serial->dev->descriptor.bcdDevice),
1120 le16_to_cpu(serial->dev->descriptor.idProduct));
1122 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
1124 dev_dbg(&serial->dev->dev, "Firmware already loaded. Quitting.\n");
1128 /* Select firmware image on the basis of idProduct */
1129 switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {
1130 case keyspan_usa28_pre_product_id:
1131 fw_name = "keyspan/usa28.fw";
1134 case keyspan_usa28x_pre_product_id:
1135 fw_name = "keyspan/usa28x.fw";
1138 case keyspan_usa28xa_pre_product_id:
1139 fw_name = "keyspan/usa28xa.fw";
1142 case keyspan_usa28xb_pre_product_id:
1143 fw_name = "keyspan/usa28xb.fw";
1146 case keyspan_usa19_pre_product_id:
1147 fw_name = "keyspan/usa19.fw";
1150 case keyspan_usa19qi_pre_product_id:
1151 fw_name = "keyspan/usa19qi.fw";
1154 case keyspan_mpr_pre_product_id:
1155 fw_name = "keyspan/mpr.fw";
1158 case keyspan_usa19qw_pre_product_id:
1159 fw_name = "keyspan/usa19qw.fw";
1162 case keyspan_usa18x_pre_product_id:
1163 fw_name = "keyspan/usa18x.fw";
1166 case keyspan_usa19w_pre_product_id:
1167 fw_name = "keyspan/usa19w.fw";
1170 case keyspan_usa49w_pre_product_id:
1171 fw_name = "keyspan/usa49w.fw";
1174 case keyspan_usa49wlc_pre_product_id:
1175 fw_name = "keyspan/usa49wlc.fw";
1179 dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n",
1180 le16_to_cpu(serial->dev->descriptor.idProduct));
1184 dev_dbg(&serial->dev->dev, "Uploading Keyspan %s firmware.\n", fw_name);
1186 if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
1187 dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
1192 /* after downloading firmware Renumeration will occur in a
1193 moment and the new device will bind to the real driver */
1195 /* we don't want this device to have a driver assigned to it. */
1199 /* Helper functions used by keyspan_setup_urbs */
1200 static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial,
1203 struct usb_host_interface *iface_desc;
1204 struct usb_endpoint_descriptor *ep;
1207 iface_desc = serial->interface->cur_altsetting;
1208 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1209 ep = &iface_desc->endpoint[i].desc;
1210 if (ep->bEndpointAddress == endpoint)
1213 dev_warn(&serial->interface->dev, "found no endpoint descriptor for "
1214 "endpoint %x\n", endpoint);
1218 static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1219 int dir, void *ctx, char *buf, int len,
1220 void (*callback)(struct urb *))
1223 struct usb_endpoint_descriptor const *ep_desc;
1224 char const *ep_type_name;
1227 return NULL; /* endpoint not needed */
1229 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d.\n", __func__, endpoint);
1230 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1234 if (endpoint == 0) {
1235 /* control EP filled in when used */
1239 ep_desc = find_ep(serial, endpoint);
1241 /* leak the urb, something's wrong and the callers don't care */
1244 if (usb_endpoint_xfer_int(ep_desc)) {
1245 ep_type_name = "INT";
1246 usb_fill_int_urb(urb, serial->dev,
1247 usb_sndintpipe(serial->dev, endpoint) | dir,
1248 buf, len, callback, ctx,
1249 ep_desc->bInterval);
1250 } else if (usb_endpoint_xfer_bulk(ep_desc)) {
1251 ep_type_name = "BULK";
1252 usb_fill_bulk_urb(urb, serial->dev,
1253 usb_sndbulkpipe(serial->dev, endpoint) | dir,
1254 buf, len, callback, ctx);
1256 dev_warn(&serial->interface->dev,
1257 "unsupported endpoint type %x\n",
1258 usb_endpoint_type(ep_desc));
1263 dev_dbg(&serial->interface->dev, "%s - using urb %p for %s endpoint %x\n",
1264 __func__, urb, ep_type_name, endpoint);
1268 static struct callbacks {
1269 void (*instat_callback)(struct urb *);
1270 void (*glocont_callback)(struct urb *);
1271 void (*indat_callback)(struct urb *);
1272 void (*outdat_callback)(struct urb *);
1273 void (*inack_callback)(struct urb *);
1274 void (*outcont_callback)(struct urb *);
1275 } keyspan_callbacks[] = {
1277 /* msg_usa26 callbacks */
1278 .instat_callback = usa26_instat_callback,
1279 .glocont_callback = usa26_glocont_callback,
1280 .indat_callback = usa26_indat_callback,
1281 .outdat_callback = usa2x_outdat_callback,
1282 .inack_callback = usa26_inack_callback,
1283 .outcont_callback = usa26_outcont_callback,
1285 /* msg_usa28 callbacks */
1286 .instat_callback = usa28_instat_callback,
1287 .glocont_callback = usa28_glocont_callback,
1288 .indat_callback = usa28_indat_callback,
1289 .outdat_callback = usa2x_outdat_callback,
1290 .inack_callback = usa28_inack_callback,
1291 .outcont_callback = usa28_outcont_callback,
1293 /* msg_usa49 callbacks */
1294 .instat_callback = usa49_instat_callback,
1295 .glocont_callback = usa49_glocont_callback,
1296 .indat_callback = usa49_indat_callback,
1297 .outdat_callback = usa2x_outdat_callback,
1298 .inack_callback = usa49_inack_callback,
1299 .outcont_callback = usa49_outcont_callback,
1301 /* msg_usa90 callbacks */
1302 .instat_callback = usa90_instat_callback,
1303 .glocont_callback = usa28_glocont_callback,
1304 .indat_callback = usa90_indat_callback,
1305 .outdat_callback = usa2x_outdat_callback,
1306 .inack_callback = usa28_inack_callback,
1307 .outcont_callback = usa90_outcont_callback,
1309 /* msg_usa67 callbacks */
1310 .instat_callback = usa67_instat_callback,
1311 .glocont_callback = usa67_glocont_callback,
1312 .indat_callback = usa26_indat_callback,
1313 .outdat_callback = usa2x_outdat_callback,
1314 .inack_callback = usa26_inack_callback,
1315 .outcont_callback = usa26_outcont_callback,
1319 /* Generic setup urbs function that uses
1320 data in device_details */
1321 static void keyspan_setup_urbs(struct usb_serial *serial)
1323 struct keyspan_serial_private *s_priv;
1324 const struct keyspan_device_details *d_details;
1325 struct callbacks *cback;
1327 s_priv = usb_get_serial_data(serial);
1328 d_details = s_priv->device_details;
1330 /* Setup values for the various callback routines */
1331 cback = &keyspan_callbacks[d_details->msg_format];
1333 /* Allocate and set up urbs for each one that is in use,
1334 starting with instat endpoints */
1335 s_priv->instat_urb = keyspan_setup_urb
1336 (serial, d_details->instat_endpoint, USB_DIR_IN,
1337 serial, s_priv->instat_buf, INSTAT_BUFLEN,
1338 cback->instat_callback);
1340 s_priv->indat_urb = keyspan_setup_urb
1341 (serial, d_details->indat_endpoint, USB_DIR_IN,
1342 serial, s_priv->indat_buf, INDAT49W_BUFLEN,
1343 usa49wg_indat_callback);
1345 s_priv->glocont_urb = keyspan_setup_urb
1346 (serial, d_details->glocont_endpoint, USB_DIR_OUT,
1347 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1348 cback->glocont_callback);
1351 /* usa19 function doesn't require prescaler */
1352 static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
1353 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1354 u8 *rate_low, u8 *prescaler, int portnum)
1356 u32 b16, /* baud rate times 16 (actual rate used internally) */
1358 cnt; /* inverse of divisor (programmed into 8051) */
1360 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1362 /* prevent divide by zero... */
1363 b16 = baud_rate * 16L;
1365 return KEYSPAN_INVALID_BAUD_RATE;
1366 /* Any "standard" rate over 57k6 is marginal on the USA-19
1367 as we run out of divisor resolution. */
1368 if (baud_rate > 57600)
1369 return KEYSPAN_INVALID_BAUD_RATE;
1371 /* calculate the divisor and the counter (its inverse) */
1372 div = baudclk / b16;
1374 return KEYSPAN_INVALID_BAUD_RATE;
1379 return KEYSPAN_INVALID_BAUD_RATE;
1381 /* return the counter values if non-null */
1383 *rate_low = (u8) (cnt & 0xff);
1385 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1386 if (rate_low && rate_hi)
1387 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1388 __func__, baud_rate, *rate_hi, *rate_low);
1389 return KEYSPAN_BAUD_RATE_OK;
1392 /* usa19hs function doesn't require prescaler */
1393 static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
1394 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1395 u8 *rate_low, u8 *prescaler, int portnum)
1397 u32 b16, /* baud rate times 16 (actual rate used internally) */
1400 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1402 /* prevent divide by zero... */
1403 b16 = baud_rate * 16L;
1405 return KEYSPAN_INVALID_BAUD_RATE;
1407 /* calculate the divisor */
1408 div = baudclk / b16;
1410 return KEYSPAN_INVALID_BAUD_RATE;
1413 return KEYSPAN_INVALID_BAUD_RATE;
1415 /* return the counter values if non-null */
1417 *rate_low = (u8) (div & 0xff);
1420 *rate_hi = (u8) ((div >> 8) & 0xff);
1422 if (rate_low && rate_hi)
1423 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1424 __func__, baud_rate, *rate_hi, *rate_low);
1426 return KEYSPAN_BAUD_RATE_OK;
1429 static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
1430 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1431 u8 *rate_low, u8 *prescaler, int portnum)
1433 u32 b16, /* baud rate times 16 (actual rate used internally) */
1434 clk, /* clock with 13/8 prescaler */
1435 div, /* divisor using 13/8 prescaler */
1436 res, /* resulting baud rate using 13/8 prescaler */
1437 diff, /* error using 13/8 prescaler */
1442 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1444 /* prevent divide by zero */
1445 b16 = baud_rate * 16L;
1447 return KEYSPAN_INVALID_BAUD_RATE;
1449 /* Calculate prescaler by trying them all and looking
1452 /* start with largest possible difference */
1453 smallest_diff = 0xffffffff;
1455 /* 0 is an invalid prescaler, used as a flag */
1458 for (i = 8; i <= 0xff; ++i) {
1459 clk = (baudclk * 8) / (u32) i;
1466 diff = (res > b16) ? (res-b16) : (b16-res);
1468 if (diff < smallest_diff) {
1470 smallest_diff = diff;
1474 if (best_prescaler == 0)
1475 return KEYSPAN_INVALID_BAUD_RATE;
1477 clk = (baudclk * 8) / (u32) best_prescaler;
1480 /* return the divisor and prescaler if non-null */
1482 *rate_low = (u8) (div & 0xff);
1484 *rate_hi = (u8) ((div >> 8) & 0xff);
1486 *prescaler = best_prescaler;
1487 /* dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
1489 return KEYSPAN_BAUD_RATE_OK;
1492 /* USA-28 supports different maximum baud rates on each port */
1493 static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
1494 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1495 u8 *rate_low, u8 *prescaler, int portnum)
1497 u32 b16, /* baud rate times 16 (actual rate used internally) */
1499 cnt; /* inverse of divisor (programmed into 8051) */
1501 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1503 /* prevent divide by zero */
1504 b16 = baud_rate * 16L;
1506 return KEYSPAN_INVALID_BAUD_RATE;
1508 /* calculate the divisor and the counter (its inverse) */
1509 div = KEYSPAN_USA28_BAUDCLK / b16;
1511 return KEYSPAN_INVALID_BAUD_RATE;
1515 /* check for out of range, based on portnum,
1516 and return result */
1519 return KEYSPAN_INVALID_BAUD_RATE;
1523 return KEYSPAN_INVALID_BAUD_RATE;
1525 return KEYSPAN_INVALID_BAUD_RATE;
1528 /* return the counter values if not NULL
1529 (port 1 will ignore retHi) */
1531 *rate_low = (u8) (cnt & 0xff);
1533 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1534 dev_dbg(&port->dev, "%s - %d OK.\n", __func__, baud_rate);
1535 return KEYSPAN_BAUD_RATE_OK;
1538 static int keyspan_usa26_send_setup(struct usb_serial *serial,
1539 struct usb_serial_port *port,
1542 struct keyspan_usa26_portControlMessage msg;
1543 struct keyspan_serial_private *s_priv;
1544 struct keyspan_port_private *p_priv;
1545 const struct keyspan_device_details *d_details;
1546 struct urb *this_urb;
1547 int device_port, err;
1549 dev_dbg(&port->dev, "%s reset=%d\n", __func__, reset_port);
1551 s_priv = usb_get_serial_data(serial);
1552 p_priv = usb_get_serial_port_data(port);
1553 d_details = s_priv->device_details;
1554 device_port = port->port_number;
1556 this_urb = p_priv->outcont_urb;
1558 /* Make sure we have an urb then send the message */
1559 if (this_urb == NULL) {
1560 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1564 dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
1566 /* Save reset port val for resend.
1567 Don't overwrite resend for open/close condition. */
1568 if ((reset_port + 1) > p_priv->resend_cont)
1569 p_priv->resend_cont = reset_port + 1;
1570 if (this_urb->status == -EINPROGRESS) {
1571 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1576 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1578 /* Only set baud rate if it's changed */
1579 if (p_priv->old_baud != p_priv->baud) {
1580 p_priv->old_baud = p_priv->baud;
1581 msg.setClocking = 0xff;
1582 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1583 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1584 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1585 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1586 __func__, p_priv->baud);
1588 msg.baudHi = 125; /* Values for 9600 baud */
1591 msg.setPrescaler = 0xff;
1594 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1595 switch (p_priv->cflag & CSIZE) {
1597 msg.lcr |= USA_DATABITS_5;
1600 msg.lcr |= USA_DATABITS_6;
1603 msg.lcr |= USA_DATABITS_7;
1606 msg.lcr |= USA_DATABITS_8;
1609 if (p_priv->cflag & PARENB) {
1610 /* note USA_PARITY_NONE == 0 */
1611 msg.lcr |= (p_priv->cflag & PARODD) ?
1612 USA_PARITY_ODD : USA_PARITY_EVEN;
1616 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1617 msg.xonFlowControl = 0;
1618 msg.setFlowControl = 0xff;
1619 msg.forwardingLength = 16;
1624 if (reset_port == 1) {
1633 msg.returnStatus = 0;
1634 msg.resetDataToggle = 0xff;
1638 else if (reset_port == 2) {
1647 msg.returnStatus = 0;
1648 msg.resetDataToggle = 0;
1651 /* Sending intermediate configs */
1653 msg._txOn = (!p_priv->break_on);
1656 msg.txBreak = (p_priv->break_on);
1661 msg.returnStatus = 0;
1662 msg.resetDataToggle = 0x0;
1665 /* Do handshaking outputs */
1666 msg.setTxTriState_setRts = 0xff;
1667 msg.txTriState_rts = p_priv->rts_state;
1669 msg.setHskoa_setDtr = 0xff;
1670 msg.hskoa_dtr = p_priv->dtr_state;
1672 p_priv->resend_cont = 0;
1673 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1675 /* send the data out the device on control endpoint */
1676 this_urb->transfer_buffer_length = sizeof(msg);
1678 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1680 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1684 static int keyspan_usa28_send_setup(struct usb_serial *serial,
1685 struct usb_serial_port *port,
1688 struct keyspan_usa28_portControlMessage msg;
1689 struct keyspan_serial_private *s_priv;
1690 struct keyspan_port_private *p_priv;
1691 const struct keyspan_device_details *d_details;
1692 struct urb *this_urb;
1693 int device_port, err;
1695 s_priv = usb_get_serial_data(serial);
1696 p_priv = usb_get_serial_port_data(port);
1697 d_details = s_priv->device_details;
1698 device_port = port->port_number;
1700 /* only do something if we have a bulk out endpoint */
1701 this_urb = p_priv->outcont_urb;
1702 if (this_urb == NULL) {
1703 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1707 /* Save reset port val for resend.
1708 Don't overwrite resend for open/close condition. */
1709 if ((reset_port + 1) > p_priv->resend_cont)
1710 p_priv->resend_cont = reset_port + 1;
1711 if (this_urb->status == -EINPROGRESS) {
1712 dev_dbg(&port->dev, "%s already writing\n", __func__);
1717 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
1719 msg.setBaudRate = 1;
1720 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1721 &msg.baudHi, &msg.baudLo, NULL,
1722 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1723 dev_dbg(&port->dev, "%s - Invalid baud rate requested %d.\n",
1724 __func__, p_priv->baud);
1726 msg.baudHi = 0xb2; /* Values for 9600 baud */
1729 /* If parity is enabled, we must calculate it ourselves. */
1730 msg.parity = 0; /* XXX for now */
1732 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1733 msg.xonFlowControl = 0;
1735 /* Do handshaking outputs, DTR is inverted relative to RTS */
1736 msg.rts = p_priv->rts_state;
1737 msg.dtr = p_priv->dtr_state;
1739 msg.forwardingLength = 16;
1741 msg.breakThreshold = 45;
1745 /*msg.returnStatus = 1;
1746 msg.resetDataToggle = 0xff;*/
1748 if (reset_port == 1) {
1752 msg.txForceXoff = 0;
1758 msg.returnStatus = 0;
1759 msg.resetDataToggle = 0xff;
1762 else if (reset_port == 2) {
1766 msg.txForceXoff = 0;
1772 msg.returnStatus = 0;
1773 msg.resetDataToggle = 0;
1775 /* Sending intermediate configs */
1777 msg._txOn = (!p_priv->break_on);
1780 msg.txForceXoff = 0;
1781 msg.txBreak = (p_priv->break_on);
1786 msg.returnStatus = 0;
1787 msg.resetDataToggle = 0x0;
1790 p_priv->resend_cont = 0;
1791 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1793 /* send the data out the device on control endpoint */
1794 this_urb->transfer_buffer_length = sizeof(msg);
1796 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1798 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed\n", __func__);
1803 static int keyspan_usa49_send_setup(struct usb_serial *serial,
1804 struct usb_serial_port *port,
1807 struct keyspan_usa49_portControlMessage msg;
1808 struct usb_ctrlrequest *dr = NULL;
1809 struct keyspan_serial_private *s_priv;
1810 struct keyspan_port_private *p_priv;
1811 const struct keyspan_device_details *d_details;
1812 struct urb *this_urb;
1813 int err, device_port;
1815 s_priv = usb_get_serial_data(serial);
1816 p_priv = usb_get_serial_port_data(port);
1817 d_details = s_priv->device_details;
1819 this_urb = s_priv->glocont_urb;
1821 /* Work out which port within the device is being setup */
1822 device_port = port->port_number;
1824 /* Make sure we have an urb then send the message */
1825 if (this_urb == NULL) {
1826 dev_dbg(&port->dev, "%s - oops no urb for port.\n", __func__);
1830 dev_dbg(&port->dev, "%s - endpoint %d (%d)\n",
1831 __func__, usb_pipeendpoint(this_urb->pipe), device_port);
1833 /* Save reset port val for resend.
1834 Don't overwrite resend for open/close condition. */
1835 if ((reset_port + 1) > p_priv->resend_cont)
1836 p_priv->resend_cont = reset_port + 1;
1838 if (this_urb->status == -EINPROGRESS) {
1839 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1844 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
1846 msg.portNumber = device_port;
1848 /* Only set baud rate if it's changed */
1849 if (p_priv->old_baud != p_priv->baud) {
1850 p_priv->old_baud = p_priv->baud;
1851 msg.setClocking = 0xff;
1852 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1853 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1854 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1855 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1856 __func__, p_priv->baud);
1858 msg.baudHi = 125; /* Values for 9600 baud */
1861 /* msg.setPrescaler = 0xff; */
1864 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1865 switch (p_priv->cflag & CSIZE) {
1867 msg.lcr |= USA_DATABITS_5;
1870 msg.lcr |= USA_DATABITS_6;
1873 msg.lcr |= USA_DATABITS_7;
1876 msg.lcr |= USA_DATABITS_8;
1879 if (p_priv->cflag & PARENB) {
1880 /* note USA_PARITY_NONE == 0 */
1881 msg.lcr |= (p_priv->cflag & PARODD) ?
1882 USA_PARITY_ODD : USA_PARITY_EVEN;
1886 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1887 msg.xonFlowControl = 0;
1888 msg.setFlowControl = 0xff;
1890 msg.forwardingLength = 16;
1895 if (reset_port == 1) {
1904 msg.returnStatus = 0;
1905 msg.resetDataToggle = 0xff;
1907 msg.disablePort = 0;
1910 else if (reset_port == 2) {
1919 msg.returnStatus = 0;
1920 msg.resetDataToggle = 0;
1922 msg.disablePort = 1;
1924 /* Sending intermediate configs */
1926 msg._txOn = (!p_priv->break_on);
1929 msg.txBreak = (p_priv->break_on);
1934 msg.returnStatus = 0;
1935 msg.resetDataToggle = 0x0;
1937 msg.disablePort = 0;
1940 /* Do handshaking outputs */
1942 msg.rts = p_priv->rts_state;
1945 msg.dtr = p_priv->dtr_state;
1947 p_priv->resend_cont = 0;
1949 /* if the device is a 49wg, we send control message on usb
1952 if (d_details->product_id == keyspan_usa49wg_product_id) {
1953 dr = (void *)(s_priv->ctrl_buf);
1954 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
1955 dr->bRequest = 0xB0; /* 49wg control message */;
1958 dr->wLength = cpu_to_le16(sizeof(msg));
1960 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
1962 usb_fill_control_urb(this_urb, serial->dev,
1963 usb_sndctrlpipe(serial->dev, 0),
1964 (unsigned char *)dr, s_priv->glocont_buf,
1965 sizeof(msg), usa49_glocont_callback, serial);
1968 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1970 /* send the data out the device on control endpoint */
1971 this_urb->transfer_buffer_length = sizeof(msg);
1973 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1975 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1980 static int keyspan_usa90_send_setup(struct usb_serial *serial,
1981 struct usb_serial_port *port,
1984 struct keyspan_usa90_portControlMessage msg;
1985 struct keyspan_serial_private *s_priv;
1986 struct keyspan_port_private *p_priv;
1987 const struct keyspan_device_details *d_details;
1988 struct urb *this_urb;
1992 s_priv = usb_get_serial_data(serial);
1993 p_priv = usb_get_serial_port_data(port);
1994 d_details = s_priv->device_details;
1996 /* only do something if we have a bulk out endpoint */
1997 this_urb = p_priv->outcont_urb;
1998 if (this_urb == NULL) {
1999 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
2003 /* Save reset port val for resend.
2004 Don't overwrite resend for open/close condition. */
2005 if ((reset_port + 1) > p_priv->resend_cont)
2006 p_priv->resend_cont = reset_port + 1;
2007 if (this_urb->status == -EINPROGRESS) {
2008 dev_dbg(&port->dev, "%s already writing\n", __func__);
2013 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2015 /* Only set baud rate if it's changed */
2016 if (p_priv->old_baud != p_priv->baud) {
2017 p_priv->old_baud = p_priv->baud;
2018 msg.setClocking = 0x01;
2019 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2020 &msg.baudHi, &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2021 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2022 __func__, p_priv->baud);
2023 p_priv->baud = 9600;
2024 d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2025 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2031 /* modes must always be correctly specified */
2032 if (p_priv->baud > 57600) {
2033 msg.rxMode = RXMODE_DMA;
2034 msg.txMode = TXMODE_DMA;
2036 msg.rxMode = RXMODE_BYHAND;
2037 msg.txMode = TXMODE_BYHAND;
2040 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2041 switch (p_priv->cflag & CSIZE) {
2043 msg.lcr |= USA_DATABITS_5;
2046 msg.lcr |= USA_DATABITS_6;
2049 msg.lcr |= USA_DATABITS_7;
2052 msg.lcr |= USA_DATABITS_8;
2055 if (p_priv->cflag & PARENB) {
2056 /* note USA_PARITY_NONE == 0 */
2057 msg.lcr |= (p_priv->cflag & PARODD) ?
2058 USA_PARITY_ODD : USA_PARITY_EVEN;
2060 if (p_priv->old_cflag != p_priv->cflag) {
2061 p_priv->old_cflag = p_priv->cflag;
2065 if (p_priv->flow_control == flow_cts)
2066 msg.txFlowControl = TXFLOW_CTS;
2067 msg.setTxFlowControl = 0x01;
2068 msg.setRxFlowControl = 0x01;
2070 msg.rxForwardingLength = 16;
2071 msg.rxForwardingTimeout = 16;
2072 msg.txAckSetting = 0;
2077 if (reset_port == 1) {
2078 msg.portEnabled = 1;
2080 msg.txBreak = (p_priv->break_on);
2083 else if (reset_port == 2)
2084 msg.portEnabled = 0;
2085 /* Sending intermediate configs */
2087 msg.portEnabled = 1;
2088 msg.txBreak = (p_priv->break_on);
2091 /* Do handshaking outputs */
2093 msg.rts = p_priv->rts_state;
2096 msg.dtr = p_priv->dtr_state;
2098 p_priv->resend_cont = 0;
2099 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2101 /* send the data out the device on control endpoint */
2102 this_urb->transfer_buffer_length = sizeof(msg);
2104 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2106 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2110 static int keyspan_usa67_send_setup(struct usb_serial *serial,
2111 struct usb_serial_port *port,
2114 struct keyspan_usa67_portControlMessage msg;
2115 struct keyspan_serial_private *s_priv;
2116 struct keyspan_port_private *p_priv;
2117 const struct keyspan_device_details *d_details;
2118 struct urb *this_urb;
2119 int err, device_port;
2121 s_priv = usb_get_serial_data(serial);
2122 p_priv = usb_get_serial_port_data(port);
2123 d_details = s_priv->device_details;
2125 this_urb = s_priv->glocont_urb;
2127 /* Work out which port within the device is being setup */
2128 device_port = port->port_number;
2130 /* Make sure we have an urb then send the message */
2131 if (this_urb == NULL) {
2132 dev_dbg(&port->dev, "%s - oops no urb for port.\n", __func__);
2136 /* Save reset port val for resend.
2137 Don't overwrite resend for open/close condition. */
2138 if ((reset_port + 1) > p_priv->resend_cont)
2139 p_priv->resend_cont = reset_port + 1;
2140 if (this_urb->status == -EINPROGRESS) {
2141 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2146 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
2148 msg.port = device_port;
2150 /* Only set baud rate if it's changed */
2151 if (p_priv->old_baud != p_priv->baud) {
2152 p_priv->old_baud = p_priv->baud;
2153 msg.setClocking = 0xff;
2154 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2155 &msg.baudHi, &msg.baudLo, &msg.prescaler,
2156 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2157 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2158 __func__, p_priv->baud);
2160 msg.baudHi = 125; /* Values for 9600 baud */
2163 msg.setPrescaler = 0xff;
2166 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2167 switch (p_priv->cflag & CSIZE) {
2169 msg.lcr |= USA_DATABITS_5;
2172 msg.lcr |= USA_DATABITS_6;
2175 msg.lcr |= USA_DATABITS_7;
2178 msg.lcr |= USA_DATABITS_8;
2181 if (p_priv->cflag & PARENB) {
2182 /* note USA_PARITY_NONE == 0 */
2183 msg.lcr |= (p_priv->cflag & PARODD) ?
2184 USA_PARITY_ODD : USA_PARITY_EVEN;
2188 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2189 msg.xonFlowControl = 0;
2190 msg.setFlowControl = 0xff;
2191 msg.forwardingLength = 16;
2195 if (reset_port == 1) {
2205 msg.returnStatus = 0;
2206 msg.resetDataToggle = 0xff;
2207 } else if (reset_port == 2) {
2217 msg.returnStatus = 0;
2218 msg.resetDataToggle = 0;
2220 /* Sending intermediate configs */
2221 msg._txOn = (!p_priv->break_on);
2224 msg.txBreak = (p_priv->break_on);
2229 msg.returnStatus = 0;
2230 msg.resetDataToggle = 0x0;
2233 /* Do handshaking outputs */
2234 msg.setTxTriState_setRts = 0xff;
2235 msg.txTriState_rts = p_priv->rts_state;
2237 msg.setHskoa_setDtr = 0xff;
2238 msg.hskoa_dtr = p_priv->dtr_state;
2240 p_priv->resend_cont = 0;
2242 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2244 /* send the data out the device on control endpoint */
2245 this_urb->transfer_buffer_length = sizeof(msg);
2247 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2249 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2253 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2255 struct usb_serial *serial = port->serial;
2256 struct keyspan_serial_private *s_priv;
2257 const struct keyspan_device_details *d_details;
2259 s_priv = usb_get_serial_data(serial);
2260 d_details = s_priv->device_details;
2262 switch (d_details->msg_format) {
2264 keyspan_usa26_send_setup(serial, port, reset_port);
2267 keyspan_usa28_send_setup(serial, port, reset_port);
2270 keyspan_usa49_send_setup(serial, port, reset_port);
2273 keyspan_usa90_send_setup(serial, port, reset_port);
2276 keyspan_usa67_send_setup(serial, port, reset_port);
2282 /* Gets called by the "real" driver (ie once firmware is loaded
2283 and renumeration has taken place. */
2284 static int keyspan_startup(struct usb_serial *serial)
2287 struct keyspan_serial_private *s_priv;
2288 const struct keyspan_device_details *d_details;
2290 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2291 if (d_details->product_id ==
2292 le16_to_cpu(serial->dev->descriptor.idProduct))
2294 if (d_details == NULL) {
2295 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2296 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2300 /* Setup private data for serial driver */
2301 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2305 s_priv->instat_buf = kzalloc(INSTAT_BUFLEN, GFP_KERNEL);
2306 if (!s_priv->instat_buf)
2307 goto err_instat_buf;
2309 s_priv->indat_buf = kzalloc(INDAT49W_BUFLEN, GFP_KERNEL);
2310 if (!s_priv->indat_buf)
2313 s_priv->glocont_buf = kzalloc(GLOCONT_BUFLEN, GFP_KERNEL);
2314 if (!s_priv->glocont_buf)
2315 goto err_glocont_buf;
2317 s_priv->ctrl_buf = kzalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
2318 if (!s_priv->ctrl_buf)
2321 s_priv->device_details = d_details;
2322 usb_set_serial_data(serial, s_priv);
2324 keyspan_setup_urbs(serial);
2326 if (s_priv->instat_urb != NULL) {
2327 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2329 dev_dbg(&serial->dev->dev, "%s - submit instat urb failed %d\n", __func__, err);
2331 if (s_priv->indat_urb != NULL) {
2332 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2334 dev_dbg(&serial->dev->dev, "%s - submit indat urb failed %d\n", __func__, err);
2340 kfree(s_priv->glocont_buf);
2342 kfree(s_priv->indat_buf);
2344 kfree(s_priv->instat_buf);
2351 static void keyspan_disconnect(struct usb_serial *serial)
2353 struct keyspan_serial_private *s_priv;
2355 s_priv = usb_get_serial_data(serial);
2357 stop_urb(s_priv->instat_urb);
2358 stop_urb(s_priv->glocont_urb);
2359 stop_urb(s_priv->indat_urb);
2362 static void keyspan_release(struct usb_serial *serial)
2364 struct keyspan_serial_private *s_priv;
2366 s_priv = usb_get_serial_data(serial);
2368 usb_free_urb(s_priv->instat_urb);
2369 usb_free_urb(s_priv->indat_urb);
2370 usb_free_urb(s_priv->glocont_urb);
2372 kfree(s_priv->ctrl_buf);
2373 kfree(s_priv->glocont_buf);
2374 kfree(s_priv->indat_buf);
2375 kfree(s_priv->instat_buf);
2380 static int keyspan_port_probe(struct usb_serial_port *port)
2382 struct usb_serial *serial = port->serial;
2383 struct keyspan_serial_private *s_priv;
2384 struct keyspan_port_private *p_priv;
2385 const struct keyspan_device_details *d_details;
2386 struct callbacks *cback;
2391 s_priv = usb_get_serial_data(serial);
2392 d_details = s_priv->device_details;
2394 p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL);
2398 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i) {
2399 p_priv->in_buffer[i] = kzalloc(IN_BUFLEN, GFP_KERNEL);
2400 if (!p_priv->in_buffer[i])
2404 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i) {
2405 p_priv->out_buffer[i] = kzalloc(OUT_BUFLEN, GFP_KERNEL);
2406 if (!p_priv->out_buffer[i])
2407 goto err_out_buffer;
2410 p_priv->inack_buffer = kzalloc(INACK_BUFLEN, GFP_KERNEL);
2411 if (!p_priv->inack_buffer)
2412 goto err_inack_buffer;
2414 p_priv->outcont_buffer = kzalloc(OUTCONT_BUFLEN, GFP_KERNEL);
2415 if (!p_priv->outcont_buffer)
2416 goto err_outcont_buffer;
2418 p_priv->device_details = d_details;
2420 /* Setup values for the various callback routines */
2421 cback = &keyspan_callbacks[d_details->msg_format];
2423 port_num = port->port_number;
2425 /* Do indat endpoints first, once for each flip */
2426 endp = d_details->indat_endpoints[port_num];
2427 for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) {
2428 p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp,
2430 p_priv->in_buffer[i],
2432 cback->indat_callback);
2434 /* outdat endpoints also have flip */
2435 endp = d_details->outdat_endpoints[port_num];
2436 for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) {
2437 p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp,
2439 p_priv->out_buffer[i],
2441 cback->outdat_callback);
2443 /* inack endpoint */
2444 p_priv->inack_urb = keyspan_setup_urb(serial,
2445 d_details->inack_endpoints[port_num],
2447 p_priv->inack_buffer,
2449 cback->inack_callback);
2450 /* outcont endpoint */
2451 p_priv->outcont_urb = keyspan_setup_urb(serial,
2452 d_details->outcont_endpoints[port_num],
2454 p_priv->outcont_buffer,
2456 cback->outcont_callback);
2458 usb_set_serial_port_data(port, p_priv);
2463 kfree(p_priv->inack_buffer);
2465 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
2466 kfree(p_priv->out_buffer[i]);
2468 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
2469 kfree(p_priv->in_buffer[i]);
2476 static int keyspan_port_remove(struct usb_serial_port *port)
2478 struct keyspan_port_private *p_priv;
2481 p_priv = usb_get_serial_port_data(port);
2483 stop_urb(p_priv->inack_urb);
2484 stop_urb(p_priv->outcont_urb);
2485 for (i = 0; i < 2; i++) {
2486 stop_urb(p_priv->in_urbs[i]);
2487 stop_urb(p_priv->out_urbs[i]);
2490 usb_free_urb(p_priv->inack_urb);
2491 usb_free_urb(p_priv->outcont_urb);
2492 for (i = 0; i < 2; i++) {
2493 usb_free_urb(p_priv->in_urbs[i]);
2494 usb_free_urb(p_priv->out_urbs[i]);
2497 kfree(p_priv->outcont_buffer);
2498 kfree(p_priv->inack_buffer);
2499 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
2500 kfree(p_priv->out_buffer[i]);
2501 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
2502 kfree(p_priv->in_buffer[i]);
2509 MODULE_AUTHOR(DRIVER_AUTHOR);
2510 MODULE_DESCRIPTION(DRIVER_DESC);
2511 MODULE_LICENSE("GPL");
2513 MODULE_FIRMWARE("keyspan/usa28.fw");
2514 MODULE_FIRMWARE("keyspan/usa28x.fw");
2515 MODULE_FIRMWARE("keyspan/usa28xa.fw");
2516 MODULE_FIRMWARE("keyspan/usa28xb.fw");
2517 MODULE_FIRMWARE("keyspan/usa19.fw");
2518 MODULE_FIRMWARE("keyspan/usa19qi.fw");
2519 MODULE_FIRMWARE("keyspan/mpr.fw");
2520 MODULE_FIRMWARE("keyspan/usa19qw.fw");
2521 MODULE_FIRMWARE("keyspan/usa18x.fw");
2522 MODULE_FIRMWARE("keyspan/usa19w.fw");
2523 MODULE_FIRMWARE("keyspan/usa49w.fw");
2524 MODULE_FIRMWARE("keyspan/usa49wlc.fw");