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) {
315 tty_insert_flip_char(&port->port, 0,
318 for (i = 1; i < urb->actual_length ; ++i)
319 tty_insert_flip_char(&port->port, data[i],
322 /* some bytes had errors, every byte has status */
323 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
324 for (i = 0; i + 1 < urb->actual_length; i += 2) {
326 int flag = TTY_NORMAL;
328 if (stat & RXERROR_OVERRUN) {
329 tty_insert_flip_char(&port->port, 0,
332 /* XXX should handle break (0x10) */
333 if (stat & RXERROR_PARITY)
335 else if (stat & RXERROR_FRAMING)
338 tty_insert_flip_char(&port->port, data[i+1],
342 tty_flip_buffer_push(&port->port);
345 /* Resubmit urb so we continue receiving */
346 err = usb_submit_urb(urb, GFP_ATOMIC);
348 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
351 /* Outdat handling is common for all devices */
352 static void usa2x_outdat_callback(struct urb *urb)
354 struct usb_serial_port *port;
355 struct keyspan_port_private *p_priv;
358 p_priv = usb_get_serial_port_data(port);
359 dev_dbg(&port->dev, "%s - urb %d\n", __func__, urb == p_priv->out_urbs[1]);
361 usb_serial_port_softint(port);
364 static void usa26_inack_callback(struct urb *urb)
368 static void usa26_outcont_callback(struct urb *urb)
370 struct usb_serial_port *port;
371 struct keyspan_port_private *p_priv;
374 p_priv = usb_get_serial_port_data(port);
376 if (p_priv->resend_cont) {
377 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
378 keyspan_usa26_send_setup(port->serial, port,
379 p_priv->resend_cont - 1);
383 static void usa26_instat_callback(struct urb *urb)
385 unsigned char *data = urb->transfer_buffer;
386 struct keyspan_usa26_portStatusMessage *msg;
387 struct usb_serial *serial;
388 struct usb_serial_port *port;
389 struct keyspan_port_private *p_priv;
390 int old_dcd_state, err;
391 int status = urb->status;
393 serial = urb->context;
396 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
399 if (urb->actual_length != 9) {
400 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
404 msg = (struct keyspan_usa26_portStatusMessage *)data;
406 /* Check port number from message and retrieve private data */
407 if (msg->port >= serial->num_ports) {
408 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
411 port = serial->port[msg->port];
412 p_priv = usb_get_serial_port_data(port);
416 /* Update handshaking pin state information */
417 old_dcd_state = p_priv->dcd_state;
418 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
419 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
420 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
421 p_priv->ri_state = ((msg->ri) ? 1 : 0);
423 if (old_dcd_state != p_priv->dcd_state)
424 tty_port_tty_hangup(&port->port, true);
426 /* Resubmit urb so we continue receiving */
427 err = usb_submit_urb(urb, GFP_ATOMIC);
429 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
433 static void usa26_glocont_callback(struct urb *urb)
438 static void usa28_indat_callback(struct urb *urb)
441 struct usb_serial_port *port;
443 struct keyspan_port_private *p_priv;
444 int status = urb->status;
447 p_priv = usb_get_serial_port_data(port);
448 data = urb->transfer_buffer;
450 if (urb != p_priv->in_urbs[p_priv->in_flip])
455 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
456 __func__, status, usb_pipeendpoint(urb->pipe));
461 p_priv = usb_get_serial_port_data(port);
462 data = urb->transfer_buffer;
464 if (urb->actual_length) {
465 tty_insert_flip_string(&port->port, data,
467 tty_flip_buffer_push(&port->port);
470 /* Resubmit urb so we continue receiving */
471 err = usb_submit_urb(urb, GFP_ATOMIC);
473 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n",
475 p_priv->in_flip ^= 1;
477 urb = p_priv->in_urbs[p_priv->in_flip];
478 } while (urb->status != -EINPROGRESS);
481 static void usa28_inack_callback(struct urb *urb)
485 static void usa28_outcont_callback(struct urb *urb)
487 struct usb_serial_port *port;
488 struct keyspan_port_private *p_priv;
491 p_priv = usb_get_serial_port_data(port);
493 if (p_priv->resend_cont) {
494 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
495 keyspan_usa28_send_setup(port->serial, port,
496 p_priv->resend_cont - 1);
500 static void usa28_instat_callback(struct urb *urb)
503 unsigned char *data = urb->transfer_buffer;
504 struct keyspan_usa28_portStatusMessage *msg;
505 struct usb_serial *serial;
506 struct usb_serial_port *port;
507 struct keyspan_port_private *p_priv;
509 int status = urb->status;
511 serial = urb->context;
514 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
518 if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) {
519 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
523 msg = (struct keyspan_usa28_portStatusMessage *)data;
525 /* Check port number from message and retrieve private data */
526 if (msg->port >= serial->num_ports) {
527 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
530 port = serial->port[msg->port];
531 p_priv = usb_get_serial_port_data(port);
535 /* Update handshaking pin state information */
536 old_dcd_state = p_priv->dcd_state;
537 p_priv->cts_state = ((msg->cts) ? 1 : 0);
538 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
539 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
540 p_priv->ri_state = ((msg->ri) ? 1 : 0);
542 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
543 tty_port_tty_hangup(&port->port, true);
545 /* Resubmit urb so we continue receiving */
546 err = usb_submit_urb(urb, GFP_ATOMIC);
548 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
552 static void usa28_glocont_callback(struct urb *urb)
557 static void usa49_glocont_callback(struct urb *urb)
559 struct usb_serial *serial;
560 struct usb_serial_port *port;
561 struct keyspan_port_private *p_priv;
564 serial = urb->context;
565 for (i = 0; i < serial->num_ports; ++i) {
566 port = serial->port[i];
567 p_priv = usb_get_serial_port_data(port);
571 if (p_priv->resend_cont) {
572 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
573 keyspan_usa49_send_setup(serial, port,
574 p_priv->resend_cont - 1);
580 /* This is actually called glostat in the Keyspan
582 static void usa49_instat_callback(struct urb *urb)
585 unsigned char *data = urb->transfer_buffer;
586 struct keyspan_usa49_portStatusMessage *msg;
587 struct usb_serial *serial;
588 struct usb_serial_port *port;
589 struct keyspan_port_private *p_priv;
591 int status = urb->status;
593 serial = urb->context;
596 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
600 if (urb->actual_length !=
601 sizeof(struct keyspan_usa49_portStatusMessage)) {
602 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
606 msg = (struct keyspan_usa49_portStatusMessage *)data;
608 /* Check port number from message and retrieve private data */
609 if (msg->portNumber >= serial->num_ports) {
610 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
611 __func__, msg->portNumber);
614 port = serial->port[msg->portNumber];
615 p_priv = usb_get_serial_port_data(port);
619 /* Update handshaking pin state information */
620 old_dcd_state = p_priv->dcd_state;
621 p_priv->cts_state = ((msg->cts) ? 1 : 0);
622 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
623 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
624 p_priv->ri_state = ((msg->ri) ? 1 : 0);
626 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
627 tty_port_tty_hangup(&port->port, true);
629 /* Resubmit urb so we continue receiving */
630 err = usb_submit_urb(urb, GFP_ATOMIC);
632 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
636 static void usa49_inack_callback(struct urb *urb)
640 static void usa49_indat_callback(struct urb *urb)
644 struct usb_serial_port *port;
645 unsigned char *data = urb->transfer_buffer;
646 int status = urb->status;
648 endpoint = usb_pipeendpoint(urb->pipe);
651 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
652 __func__, status, endpoint);
657 if (urb->actual_length) {
658 /* 0x80 bit is error flag */
659 if ((data[0] & 0x80) == 0) {
660 /* no error on any byte */
661 tty_insert_flip_string(&port->port, data + 1,
662 urb->actual_length - 1);
664 /* some bytes had errors, every byte has status */
665 for (i = 0; i + 1 < urb->actual_length; i += 2) {
667 int flag = TTY_NORMAL;
669 if (stat & RXERROR_OVERRUN) {
670 tty_insert_flip_char(&port->port, 0,
673 /* XXX should handle break (0x10) */
674 if (stat & RXERROR_PARITY)
676 else if (stat & RXERROR_FRAMING)
679 tty_insert_flip_char(&port->port, data[i+1],
683 tty_flip_buffer_push(&port->port);
686 /* Resubmit urb so we continue receiving */
687 err = usb_submit_urb(urb, GFP_ATOMIC);
689 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
692 static void usa49wg_indat_callback(struct urb *urb)
695 struct usb_serial *serial;
696 struct usb_serial_port *port;
697 unsigned char *data = urb->transfer_buffer;
698 int status = urb->status;
700 serial = urb->context;
703 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
707 /* inbound data is in the form P#, len, status, data */
711 while (i < urb->actual_length) {
713 /* Check port number from message */
714 if (data[i] >= serial->num_ports) {
715 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
719 port = serial->port[data[i++]];
722 /* 0x80 bit is error flag */
723 if ((data[i] & 0x80) == 0) {
724 /* no error on any byte */
726 for (x = 1; x < len && i < urb->actual_length; ++x)
727 tty_insert_flip_char(&port->port,
731 * some bytes had errors, every byte has status
733 for (x = 0; x + 1 < len &&
734 i + 1 < urb->actual_length; x += 2) {
736 int flag = TTY_NORMAL;
738 if (stat & RXERROR_OVERRUN) {
739 tty_insert_flip_char(&port->port, 0,
742 /* XXX should handle break (0x10) */
743 if (stat & RXERROR_PARITY)
745 else if (stat & RXERROR_FRAMING)
748 tty_insert_flip_char(&port->port, data[i+1],
753 tty_flip_buffer_push(&port->port);
756 /* Resubmit urb so we continue receiving */
757 err = usb_submit_urb(urb, GFP_ATOMIC);
759 dev_dbg(&urb->dev->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
762 /* not used, usa-49 doesn't have per-port control endpoints */
763 static void usa49_outcont_callback(struct urb *urb)
767 static void usa90_indat_callback(struct urb *urb)
771 struct usb_serial_port *port;
772 struct keyspan_port_private *p_priv;
773 unsigned char *data = urb->transfer_buffer;
774 int status = urb->status;
776 endpoint = usb_pipeendpoint(urb->pipe);
779 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
780 __func__, status, endpoint);
785 p_priv = usb_get_serial_port_data(port);
787 if (urb->actual_length) {
788 /* if current mode is DMA, looks like usa28 format
789 otherwise looks like usa26 data format */
791 if (p_priv->baud > 57600)
792 tty_insert_flip_string(&port->port, data,
795 /* 0x80 bit is error flag */
796 if ((data[0] & 0x80) == 0) {
797 /* no errors on individual bytes, only
798 possible overrun err*/
799 if (data[0] & RXERROR_OVERRUN) {
800 tty_insert_flip_char(&port->port, 0,
803 for (i = 1; i < urb->actual_length ; ++i)
804 tty_insert_flip_char(&port->port,
805 data[i], TTY_NORMAL);
807 /* some bytes had errors, every byte has status */
808 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
809 for (i = 0; i + 1 < urb->actual_length; i += 2) {
811 int flag = TTY_NORMAL;
813 if (stat & RXERROR_OVERRUN) {
814 tty_insert_flip_char(
818 /* XXX should handle break (0x10) */
819 if (stat & RXERROR_PARITY)
821 else if (stat & RXERROR_FRAMING)
824 tty_insert_flip_char(&port->port,
829 tty_flip_buffer_push(&port->port);
832 /* Resubmit urb so we continue receiving */
833 err = usb_submit_urb(urb, GFP_ATOMIC);
835 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
839 static void usa90_instat_callback(struct urb *urb)
841 unsigned char *data = urb->transfer_buffer;
842 struct keyspan_usa90_portStatusMessage *msg;
843 struct usb_serial *serial;
844 struct usb_serial_port *port;
845 struct keyspan_port_private *p_priv;
846 int old_dcd_state, err;
847 int status = urb->status;
849 serial = urb->context;
852 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
855 if (urb->actual_length < 14) {
856 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
860 msg = (struct keyspan_usa90_portStatusMessage *)data;
862 /* Now do something useful with the data */
864 port = serial->port[0];
865 p_priv = usb_get_serial_port_data(port);
869 /* Update handshaking pin state information */
870 old_dcd_state = p_priv->dcd_state;
871 p_priv->cts_state = ((msg->cts) ? 1 : 0);
872 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
873 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
874 p_priv->ri_state = ((msg->ri) ? 1 : 0);
876 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
877 tty_port_tty_hangup(&port->port, true);
879 /* Resubmit urb so we continue receiving */
880 err = usb_submit_urb(urb, GFP_ATOMIC);
882 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
887 static void usa90_outcont_callback(struct urb *urb)
889 struct usb_serial_port *port;
890 struct keyspan_port_private *p_priv;
893 p_priv = usb_get_serial_port_data(port);
895 if (p_priv->resend_cont) {
896 dev_dbg(&urb->dev->dev, "%s - sending setup\n", __func__);
897 keyspan_usa90_send_setup(port->serial, port,
898 p_priv->resend_cont - 1);
902 /* Status messages from the 28xg */
903 static void usa67_instat_callback(struct urb *urb)
906 unsigned char *data = urb->transfer_buffer;
907 struct keyspan_usa67_portStatusMessage *msg;
908 struct usb_serial *serial;
909 struct usb_serial_port *port;
910 struct keyspan_port_private *p_priv;
912 int status = urb->status;
914 serial = urb->context;
917 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
921 if (urb->actual_length !=
922 sizeof(struct keyspan_usa67_portStatusMessage)) {
923 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
928 /* Now do something useful with the data */
929 msg = (struct keyspan_usa67_portStatusMessage *)data;
931 /* Check port number from message and retrieve private data */
932 if (msg->port >= serial->num_ports) {
933 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
937 port = serial->port[msg->port];
938 p_priv = usb_get_serial_port_data(port);
942 /* Update handshaking pin state information */
943 old_dcd_state = p_priv->dcd_state;
944 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
945 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
947 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
948 tty_port_tty_hangup(&port->port, true);
950 /* Resubmit urb so we continue receiving */
951 err = usb_submit_urb(urb, GFP_ATOMIC);
953 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
956 static void usa67_glocont_callback(struct urb *urb)
958 struct usb_serial *serial;
959 struct usb_serial_port *port;
960 struct keyspan_port_private *p_priv;
963 serial = urb->context;
964 for (i = 0; i < serial->num_ports; ++i) {
965 port = serial->port[i];
966 p_priv = usb_get_serial_port_data(port);
970 if (p_priv->resend_cont) {
971 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
972 keyspan_usa67_send_setup(serial, port,
973 p_priv->resend_cont - 1);
979 static int keyspan_write_room(struct tty_struct *tty)
981 struct usb_serial_port *port = tty->driver_data;
982 struct keyspan_port_private *p_priv;
983 const struct keyspan_device_details *d_details;
986 struct urb *this_urb;
988 p_priv = usb_get_serial_port_data(port);
989 d_details = p_priv->device_details;
992 if (d_details->msg_format == msg_usa90)
997 flip = p_priv->out_flip;
999 /* Check both endpoints to see if any are available. */
1000 this_urb = p_priv->out_urbs[flip];
1001 if (this_urb != NULL) {
1002 if (this_urb->status != -EINPROGRESS)
1004 flip = (flip + 1) & d_details->outdat_endp_flip;
1005 this_urb = p_priv->out_urbs[flip];
1006 if (this_urb != NULL) {
1007 if (this_urb->status != -EINPROGRESS)
1015 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1017 struct keyspan_port_private *p_priv;
1018 const struct keyspan_device_details *d_details;
1020 int baud_rate, device_port;
1022 unsigned int cflag = 0;
1024 p_priv = usb_get_serial_port_data(port);
1025 d_details = p_priv->device_details;
1027 /* Set some sane defaults */
1028 p_priv->rts_state = 1;
1029 p_priv->dtr_state = 1;
1030 p_priv->baud = 9600;
1032 /* force baud and lcr to be set on open */
1033 p_priv->old_baud = 0;
1034 p_priv->old_cflag = 0;
1036 p_priv->out_flip = 0;
1037 p_priv->in_flip = 0;
1039 /* Reset low level data toggle and start reading from endpoints */
1040 for (i = 0; i < 2; i++) {
1041 urb = p_priv->in_urbs[i];
1045 /* make sure endpoint data toggle is synchronized
1047 usb_clear_halt(urb->dev, urb->pipe);
1048 err = usb_submit_urb(urb, GFP_KERNEL);
1050 dev_dbg(&port->dev, "%s - submit urb %d failed (%d)\n", __func__, i, err);
1053 /* Reset low level data toggle on out endpoints */
1054 for (i = 0; i < 2; i++) {
1055 urb = p_priv->out_urbs[i];
1058 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1059 usb_pipeout(urb->pipe), 0); */
1062 /* get the terminal config for the setup message now so we don't
1063 * need to send 2 of them */
1065 device_port = port->port_number;
1067 cflag = tty->termios.c_cflag;
1068 /* Baud rate calculation takes baud rate as an integer
1069 so other rates can be generated if desired. */
1070 baud_rate = tty_get_baud_rate(tty);
1071 /* If no match or invalid, leave as default */
1073 && d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
1074 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1075 p_priv->baud = baud_rate;
1078 /* set CTS/RTS handshake etc. */
1079 p_priv->cflag = cflag;
1080 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
1082 keyspan_send_setup(port, 1);
1084 /* keyspan_set_termios(port, NULL); */
1089 static inline void stop_urb(struct urb *urb)
1091 if (urb && urb->status == -EINPROGRESS)
1095 static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1097 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
1099 p_priv->rts_state = on;
1100 p_priv->dtr_state = on;
1101 keyspan_send_setup(port, 0);
1104 static void keyspan_close(struct usb_serial_port *port)
1107 struct keyspan_port_private *p_priv;
1109 p_priv = usb_get_serial_port_data(port);
1111 p_priv->rts_state = 0;
1112 p_priv->dtr_state = 0;
1114 keyspan_send_setup(port, 2);
1115 /* pilot-xfer seems to work best with this delay */
1118 p_priv->out_flip = 0;
1119 p_priv->in_flip = 0;
1121 stop_urb(p_priv->inack_urb);
1122 for (i = 0; i < 2; i++) {
1123 stop_urb(p_priv->in_urbs[i]);
1124 stop_urb(p_priv->out_urbs[i]);
1128 /* download the firmware to a pre-renumeration device */
1129 static int keyspan_fake_startup(struct usb_serial *serial)
1133 dev_dbg(&serial->dev->dev, "Keyspan startup version %04x product %04x\n",
1134 le16_to_cpu(serial->dev->descriptor.bcdDevice),
1135 le16_to_cpu(serial->dev->descriptor.idProduct));
1137 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
1139 dev_dbg(&serial->dev->dev, "Firmware already loaded. Quitting.\n");
1143 /* Select firmware image on the basis of idProduct */
1144 switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {
1145 case keyspan_usa28_pre_product_id:
1146 fw_name = "/*(DEBLOBBED)*/";
1149 case keyspan_usa28x_pre_product_id:
1150 fw_name = "/*(DEBLOBBED)*/";
1153 case keyspan_usa28xa_pre_product_id:
1154 fw_name = "/*(DEBLOBBED)*/";
1157 case keyspan_usa28xb_pre_product_id:
1158 fw_name = "/*(DEBLOBBED)*/";
1161 case keyspan_usa19_pre_product_id:
1162 fw_name = "/*(DEBLOBBED)*/";
1165 case keyspan_usa19qi_pre_product_id:
1166 fw_name = "/*(DEBLOBBED)*/";
1169 case keyspan_mpr_pre_product_id:
1170 fw_name = "/*(DEBLOBBED)*/";
1173 case keyspan_usa19qw_pre_product_id:
1174 fw_name = "/*(DEBLOBBED)*/";
1177 case keyspan_usa18x_pre_product_id:
1178 fw_name = "/*(DEBLOBBED)*/";
1181 case keyspan_usa19w_pre_product_id:
1182 fw_name = "/*(DEBLOBBED)*/";
1185 case keyspan_usa49w_pre_product_id:
1186 fw_name = "/*(DEBLOBBED)*/";
1189 case keyspan_usa49wlc_pre_product_id:
1190 fw_name = "/*(DEBLOBBED)*/";
1194 dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n",
1195 le16_to_cpu(serial->dev->descriptor.idProduct));
1199 dev_dbg(&serial->dev->dev, "Uploading Keyspan %s firmware.\n", fw_name);
1201 if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
1202 dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
1207 /* after downloading firmware Renumeration will occur in a
1208 moment and the new device will bind to the real driver */
1210 /* we don't want this device to have a driver assigned to it. */
1214 /* Helper functions used by keyspan_setup_urbs */
1215 static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial,
1218 struct usb_host_interface *iface_desc;
1219 struct usb_endpoint_descriptor *ep;
1222 iface_desc = serial->interface->cur_altsetting;
1223 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1224 ep = &iface_desc->endpoint[i].desc;
1225 if (ep->bEndpointAddress == endpoint)
1228 dev_warn(&serial->interface->dev, "found no endpoint descriptor for "
1229 "endpoint %x\n", endpoint);
1233 static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1234 int dir, void *ctx, char *buf, int len,
1235 void (*callback)(struct urb *))
1238 struct usb_endpoint_descriptor const *ep_desc;
1239 char const *ep_type_name;
1242 return NULL; /* endpoint not needed */
1244 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d.\n", __func__, endpoint);
1245 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1249 if (endpoint == 0) {
1250 /* control EP filled in when used */
1254 ep_desc = find_ep(serial, endpoint);
1259 if (usb_endpoint_xfer_int(ep_desc)) {
1260 ep_type_name = "INT";
1261 usb_fill_int_urb(urb, serial->dev,
1262 usb_sndintpipe(serial->dev, endpoint) | dir,
1263 buf, len, callback, ctx,
1264 ep_desc->bInterval);
1265 } else if (usb_endpoint_xfer_bulk(ep_desc)) {
1266 ep_type_name = "BULK";
1267 usb_fill_bulk_urb(urb, serial->dev,
1268 usb_sndbulkpipe(serial->dev, endpoint) | dir,
1269 buf, len, callback, ctx);
1271 dev_warn(&serial->interface->dev,
1272 "unsupported endpoint type %x\n",
1273 usb_endpoint_type(ep_desc));
1278 dev_dbg(&serial->interface->dev, "%s - using urb %p for %s endpoint %x\n",
1279 __func__, urb, ep_type_name, endpoint);
1283 static struct callbacks {
1284 void (*instat_callback)(struct urb *);
1285 void (*glocont_callback)(struct urb *);
1286 void (*indat_callback)(struct urb *);
1287 void (*outdat_callback)(struct urb *);
1288 void (*inack_callback)(struct urb *);
1289 void (*outcont_callback)(struct urb *);
1290 } keyspan_callbacks[] = {
1292 /* msg_usa26 callbacks */
1293 .instat_callback = usa26_instat_callback,
1294 .glocont_callback = usa26_glocont_callback,
1295 .indat_callback = usa26_indat_callback,
1296 .outdat_callback = usa2x_outdat_callback,
1297 .inack_callback = usa26_inack_callback,
1298 .outcont_callback = usa26_outcont_callback,
1300 /* msg_usa28 callbacks */
1301 .instat_callback = usa28_instat_callback,
1302 .glocont_callback = usa28_glocont_callback,
1303 .indat_callback = usa28_indat_callback,
1304 .outdat_callback = usa2x_outdat_callback,
1305 .inack_callback = usa28_inack_callback,
1306 .outcont_callback = usa28_outcont_callback,
1308 /* msg_usa49 callbacks */
1309 .instat_callback = usa49_instat_callback,
1310 .glocont_callback = usa49_glocont_callback,
1311 .indat_callback = usa49_indat_callback,
1312 .outdat_callback = usa2x_outdat_callback,
1313 .inack_callback = usa49_inack_callback,
1314 .outcont_callback = usa49_outcont_callback,
1316 /* msg_usa90 callbacks */
1317 .instat_callback = usa90_instat_callback,
1318 .glocont_callback = usa28_glocont_callback,
1319 .indat_callback = usa90_indat_callback,
1320 .outdat_callback = usa2x_outdat_callback,
1321 .inack_callback = usa28_inack_callback,
1322 .outcont_callback = usa90_outcont_callback,
1324 /* msg_usa67 callbacks */
1325 .instat_callback = usa67_instat_callback,
1326 .glocont_callback = usa67_glocont_callback,
1327 .indat_callback = usa26_indat_callback,
1328 .outdat_callback = usa2x_outdat_callback,
1329 .inack_callback = usa26_inack_callback,
1330 .outcont_callback = usa26_outcont_callback,
1334 /* Generic setup urbs function that uses
1335 data in device_details */
1336 static void keyspan_setup_urbs(struct usb_serial *serial)
1338 struct keyspan_serial_private *s_priv;
1339 const struct keyspan_device_details *d_details;
1340 struct callbacks *cback;
1342 s_priv = usb_get_serial_data(serial);
1343 d_details = s_priv->device_details;
1345 /* Setup values for the various callback routines */
1346 cback = &keyspan_callbacks[d_details->msg_format];
1348 /* Allocate and set up urbs for each one that is in use,
1349 starting with instat endpoints */
1350 s_priv->instat_urb = keyspan_setup_urb
1351 (serial, d_details->instat_endpoint, USB_DIR_IN,
1352 serial, s_priv->instat_buf, INSTAT_BUFLEN,
1353 cback->instat_callback);
1355 s_priv->indat_urb = keyspan_setup_urb
1356 (serial, d_details->indat_endpoint, USB_DIR_IN,
1357 serial, s_priv->indat_buf, INDAT49W_BUFLEN,
1358 usa49wg_indat_callback);
1360 s_priv->glocont_urb = keyspan_setup_urb
1361 (serial, d_details->glocont_endpoint, USB_DIR_OUT,
1362 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1363 cback->glocont_callback);
1366 /* usa19 function doesn't require prescaler */
1367 static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
1368 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1369 u8 *rate_low, u8 *prescaler, int portnum)
1371 u32 b16, /* baud rate times 16 (actual rate used internally) */
1373 cnt; /* inverse of divisor (programmed into 8051) */
1375 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1377 /* prevent divide by zero... */
1378 b16 = baud_rate * 16L;
1380 return KEYSPAN_INVALID_BAUD_RATE;
1381 /* Any "standard" rate over 57k6 is marginal on the USA-19
1382 as we run out of divisor resolution. */
1383 if (baud_rate > 57600)
1384 return KEYSPAN_INVALID_BAUD_RATE;
1386 /* calculate the divisor and the counter (its inverse) */
1387 div = baudclk / b16;
1389 return KEYSPAN_INVALID_BAUD_RATE;
1394 return KEYSPAN_INVALID_BAUD_RATE;
1396 /* return the counter values if non-null */
1398 *rate_low = (u8) (cnt & 0xff);
1400 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1401 if (rate_low && rate_hi)
1402 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1403 __func__, baud_rate, *rate_hi, *rate_low);
1404 return KEYSPAN_BAUD_RATE_OK;
1407 /* usa19hs function doesn't require prescaler */
1408 static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
1409 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1410 u8 *rate_low, u8 *prescaler, int portnum)
1412 u32 b16, /* baud rate times 16 (actual rate used internally) */
1415 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1417 /* prevent divide by zero... */
1418 b16 = baud_rate * 16L;
1420 return KEYSPAN_INVALID_BAUD_RATE;
1422 /* calculate the divisor */
1423 div = baudclk / b16;
1425 return KEYSPAN_INVALID_BAUD_RATE;
1428 return KEYSPAN_INVALID_BAUD_RATE;
1430 /* return the counter values if non-null */
1432 *rate_low = (u8) (div & 0xff);
1435 *rate_hi = (u8) ((div >> 8) & 0xff);
1437 if (rate_low && rate_hi)
1438 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1439 __func__, baud_rate, *rate_hi, *rate_low);
1441 return KEYSPAN_BAUD_RATE_OK;
1444 static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
1445 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1446 u8 *rate_low, u8 *prescaler, int portnum)
1448 u32 b16, /* baud rate times 16 (actual rate used internally) */
1449 clk, /* clock with 13/8 prescaler */
1450 div, /* divisor using 13/8 prescaler */
1451 res, /* resulting baud rate using 13/8 prescaler */
1452 diff, /* error using 13/8 prescaler */
1457 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1459 /* prevent divide by zero */
1460 b16 = baud_rate * 16L;
1462 return KEYSPAN_INVALID_BAUD_RATE;
1464 /* Calculate prescaler by trying them all and looking
1467 /* start with largest possible difference */
1468 smallest_diff = 0xffffffff;
1470 /* 0 is an invalid prescaler, used as a flag */
1473 for (i = 8; i <= 0xff; ++i) {
1474 clk = (baudclk * 8) / (u32) i;
1481 diff = (res > b16) ? (res-b16) : (b16-res);
1483 if (diff < smallest_diff) {
1485 smallest_diff = diff;
1489 if (best_prescaler == 0)
1490 return KEYSPAN_INVALID_BAUD_RATE;
1492 clk = (baudclk * 8) / (u32) best_prescaler;
1495 /* return the divisor and prescaler if non-null */
1497 *rate_low = (u8) (div & 0xff);
1499 *rate_hi = (u8) ((div >> 8) & 0xff);
1501 *prescaler = best_prescaler;
1502 /* dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
1504 return KEYSPAN_BAUD_RATE_OK;
1507 /* USA-28 supports different maximum baud rates on each port */
1508 static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
1509 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1510 u8 *rate_low, u8 *prescaler, int portnum)
1512 u32 b16, /* baud rate times 16 (actual rate used internally) */
1514 cnt; /* inverse of divisor (programmed into 8051) */
1516 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1518 /* prevent divide by zero */
1519 b16 = baud_rate * 16L;
1521 return KEYSPAN_INVALID_BAUD_RATE;
1523 /* calculate the divisor and the counter (its inverse) */
1524 div = KEYSPAN_USA28_BAUDCLK / b16;
1526 return KEYSPAN_INVALID_BAUD_RATE;
1530 /* check for out of range, based on portnum,
1531 and return result */
1534 return KEYSPAN_INVALID_BAUD_RATE;
1538 return KEYSPAN_INVALID_BAUD_RATE;
1540 return KEYSPAN_INVALID_BAUD_RATE;
1543 /* return the counter values if not NULL
1544 (port 1 will ignore retHi) */
1546 *rate_low = (u8) (cnt & 0xff);
1548 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1549 dev_dbg(&port->dev, "%s - %d OK.\n", __func__, baud_rate);
1550 return KEYSPAN_BAUD_RATE_OK;
1553 static int keyspan_usa26_send_setup(struct usb_serial *serial,
1554 struct usb_serial_port *port,
1557 struct keyspan_usa26_portControlMessage msg;
1558 struct keyspan_serial_private *s_priv;
1559 struct keyspan_port_private *p_priv;
1560 const struct keyspan_device_details *d_details;
1561 struct urb *this_urb;
1562 int device_port, err;
1564 dev_dbg(&port->dev, "%s reset=%d\n", __func__, reset_port);
1566 s_priv = usb_get_serial_data(serial);
1567 p_priv = usb_get_serial_port_data(port);
1568 d_details = s_priv->device_details;
1569 device_port = port->port_number;
1571 this_urb = p_priv->outcont_urb;
1573 /* Make sure we have an urb then send the message */
1574 if (this_urb == NULL) {
1575 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1579 dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
1581 /* Save reset port val for resend.
1582 Don't overwrite resend for open/close condition. */
1583 if ((reset_port + 1) > p_priv->resend_cont)
1584 p_priv->resend_cont = reset_port + 1;
1585 if (this_urb->status == -EINPROGRESS) {
1586 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1591 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1593 /* Only set baud rate if it's changed */
1594 if (p_priv->old_baud != p_priv->baud) {
1595 p_priv->old_baud = p_priv->baud;
1596 msg.setClocking = 0xff;
1597 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1598 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1599 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1600 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1601 __func__, p_priv->baud);
1603 msg.baudHi = 125; /* Values for 9600 baud */
1606 msg.setPrescaler = 0xff;
1609 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1610 switch (p_priv->cflag & CSIZE) {
1612 msg.lcr |= USA_DATABITS_5;
1615 msg.lcr |= USA_DATABITS_6;
1618 msg.lcr |= USA_DATABITS_7;
1621 msg.lcr |= USA_DATABITS_8;
1624 if (p_priv->cflag & PARENB) {
1625 /* note USA_PARITY_NONE == 0 */
1626 msg.lcr |= (p_priv->cflag & PARODD) ?
1627 USA_PARITY_ODD : USA_PARITY_EVEN;
1631 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1632 msg.xonFlowControl = 0;
1633 msg.setFlowControl = 0xff;
1634 msg.forwardingLength = 16;
1639 if (reset_port == 1) {
1648 msg.returnStatus = 0;
1649 msg.resetDataToggle = 0xff;
1653 else if (reset_port == 2) {
1662 msg.returnStatus = 0;
1663 msg.resetDataToggle = 0;
1666 /* Sending intermediate configs */
1668 msg._txOn = (!p_priv->break_on);
1671 msg.txBreak = (p_priv->break_on);
1676 msg.returnStatus = 0;
1677 msg.resetDataToggle = 0x0;
1680 /* Do handshaking outputs */
1681 msg.setTxTriState_setRts = 0xff;
1682 msg.txTriState_rts = p_priv->rts_state;
1684 msg.setHskoa_setDtr = 0xff;
1685 msg.hskoa_dtr = p_priv->dtr_state;
1687 p_priv->resend_cont = 0;
1688 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1690 /* send the data out the device on control endpoint */
1691 this_urb->transfer_buffer_length = sizeof(msg);
1693 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1695 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1699 static int keyspan_usa28_send_setup(struct usb_serial *serial,
1700 struct usb_serial_port *port,
1703 struct keyspan_usa28_portControlMessage msg;
1704 struct keyspan_serial_private *s_priv;
1705 struct keyspan_port_private *p_priv;
1706 const struct keyspan_device_details *d_details;
1707 struct urb *this_urb;
1708 int device_port, err;
1710 s_priv = usb_get_serial_data(serial);
1711 p_priv = usb_get_serial_port_data(port);
1712 d_details = s_priv->device_details;
1713 device_port = port->port_number;
1715 /* only do something if we have a bulk out endpoint */
1716 this_urb = p_priv->outcont_urb;
1717 if (this_urb == NULL) {
1718 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1722 /* Save reset port val for resend.
1723 Don't overwrite resend for open/close condition. */
1724 if ((reset_port + 1) > p_priv->resend_cont)
1725 p_priv->resend_cont = reset_port + 1;
1726 if (this_urb->status == -EINPROGRESS) {
1727 dev_dbg(&port->dev, "%s already writing\n", __func__);
1732 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
1734 msg.setBaudRate = 1;
1735 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1736 &msg.baudHi, &msg.baudLo, NULL,
1737 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1738 dev_dbg(&port->dev, "%s - Invalid baud rate requested %d.\n",
1739 __func__, p_priv->baud);
1741 msg.baudHi = 0xb2; /* Values for 9600 baud */
1744 /* If parity is enabled, we must calculate it ourselves. */
1745 msg.parity = 0; /* XXX for now */
1747 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1748 msg.xonFlowControl = 0;
1750 /* Do handshaking outputs, DTR is inverted relative to RTS */
1751 msg.rts = p_priv->rts_state;
1752 msg.dtr = p_priv->dtr_state;
1754 msg.forwardingLength = 16;
1756 msg.breakThreshold = 45;
1760 /*msg.returnStatus = 1;
1761 msg.resetDataToggle = 0xff;*/
1763 if (reset_port == 1) {
1767 msg.txForceXoff = 0;
1773 msg.returnStatus = 0;
1774 msg.resetDataToggle = 0xff;
1777 else if (reset_port == 2) {
1781 msg.txForceXoff = 0;
1787 msg.returnStatus = 0;
1788 msg.resetDataToggle = 0;
1790 /* Sending intermediate configs */
1792 msg._txOn = (!p_priv->break_on);
1795 msg.txForceXoff = 0;
1796 msg.txBreak = (p_priv->break_on);
1801 msg.returnStatus = 0;
1802 msg.resetDataToggle = 0x0;
1805 p_priv->resend_cont = 0;
1806 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1808 /* send the data out the device on control endpoint */
1809 this_urb->transfer_buffer_length = sizeof(msg);
1811 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1813 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed\n", __func__);
1818 static int keyspan_usa49_send_setup(struct usb_serial *serial,
1819 struct usb_serial_port *port,
1822 struct keyspan_usa49_portControlMessage msg;
1823 struct usb_ctrlrequest *dr = NULL;
1824 struct keyspan_serial_private *s_priv;
1825 struct keyspan_port_private *p_priv;
1826 const struct keyspan_device_details *d_details;
1827 struct urb *this_urb;
1828 int err, device_port;
1830 s_priv = usb_get_serial_data(serial);
1831 p_priv = usb_get_serial_port_data(port);
1832 d_details = s_priv->device_details;
1834 this_urb = s_priv->glocont_urb;
1836 /* Work out which port within the device is being setup */
1837 device_port = port->port_number;
1839 /* Make sure we have an urb then send the message */
1840 if (this_urb == NULL) {
1841 dev_dbg(&port->dev, "%s - oops no urb for port.\n", __func__);
1845 dev_dbg(&port->dev, "%s - endpoint %d (%d)\n",
1846 __func__, usb_pipeendpoint(this_urb->pipe), device_port);
1848 /* Save reset port val for resend.
1849 Don't overwrite resend for open/close condition. */
1850 if ((reset_port + 1) > p_priv->resend_cont)
1851 p_priv->resend_cont = reset_port + 1;
1853 if (this_urb->status == -EINPROGRESS) {
1854 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1859 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
1861 msg.portNumber = device_port;
1863 /* Only set baud rate if it's changed */
1864 if (p_priv->old_baud != p_priv->baud) {
1865 p_priv->old_baud = p_priv->baud;
1866 msg.setClocking = 0xff;
1867 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1868 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1869 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1870 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1871 __func__, p_priv->baud);
1873 msg.baudHi = 125; /* Values for 9600 baud */
1876 /* msg.setPrescaler = 0xff; */
1879 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1880 switch (p_priv->cflag & CSIZE) {
1882 msg.lcr |= USA_DATABITS_5;
1885 msg.lcr |= USA_DATABITS_6;
1888 msg.lcr |= USA_DATABITS_7;
1891 msg.lcr |= USA_DATABITS_8;
1894 if (p_priv->cflag & PARENB) {
1895 /* note USA_PARITY_NONE == 0 */
1896 msg.lcr |= (p_priv->cflag & PARODD) ?
1897 USA_PARITY_ODD : USA_PARITY_EVEN;
1901 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1902 msg.xonFlowControl = 0;
1903 msg.setFlowControl = 0xff;
1905 msg.forwardingLength = 16;
1910 if (reset_port == 1) {
1919 msg.returnStatus = 0;
1920 msg.resetDataToggle = 0xff;
1922 msg.disablePort = 0;
1925 else if (reset_port == 2) {
1934 msg.returnStatus = 0;
1935 msg.resetDataToggle = 0;
1937 msg.disablePort = 1;
1939 /* Sending intermediate configs */
1941 msg._txOn = (!p_priv->break_on);
1944 msg.txBreak = (p_priv->break_on);
1949 msg.returnStatus = 0;
1950 msg.resetDataToggle = 0x0;
1952 msg.disablePort = 0;
1955 /* Do handshaking outputs */
1957 msg.rts = p_priv->rts_state;
1960 msg.dtr = p_priv->dtr_state;
1962 p_priv->resend_cont = 0;
1964 /* if the device is a 49wg, we send control message on usb
1967 if (d_details->product_id == keyspan_usa49wg_product_id) {
1968 dr = (void *)(s_priv->ctrl_buf);
1969 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
1970 dr->bRequest = 0xB0; /* 49wg control message */;
1973 dr->wLength = cpu_to_le16(sizeof(msg));
1975 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
1977 usb_fill_control_urb(this_urb, serial->dev,
1978 usb_sndctrlpipe(serial->dev, 0),
1979 (unsigned char *)dr, s_priv->glocont_buf,
1980 sizeof(msg), usa49_glocont_callback, serial);
1983 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1985 /* send the data out the device on control endpoint */
1986 this_urb->transfer_buffer_length = sizeof(msg);
1988 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1990 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1995 static int keyspan_usa90_send_setup(struct usb_serial *serial,
1996 struct usb_serial_port *port,
1999 struct keyspan_usa90_portControlMessage msg;
2000 struct keyspan_serial_private *s_priv;
2001 struct keyspan_port_private *p_priv;
2002 const struct keyspan_device_details *d_details;
2003 struct urb *this_urb;
2007 s_priv = usb_get_serial_data(serial);
2008 p_priv = usb_get_serial_port_data(port);
2009 d_details = s_priv->device_details;
2011 /* only do something if we have a bulk out endpoint */
2012 this_urb = p_priv->outcont_urb;
2013 if (this_urb == NULL) {
2014 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
2018 /* Save reset port val for resend.
2019 Don't overwrite resend for open/close condition. */
2020 if ((reset_port + 1) > p_priv->resend_cont)
2021 p_priv->resend_cont = reset_port + 1;
2022 if (this_urb->status == -EINPROGRESS) {
2023 dev_dbg(&port->dev, "%s already writing\n", __func__);
2028 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2030 /* Only set baud rate if it's changed */
2031 if (p_priv->old_baud != p_priv->baud) {
2032 p_priv->old_baud = p_priv->baud;
2033 msg.setClocking = 0x01;
2034 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2035 &msg.baudHi, &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2036 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2037 __func__, p_priv->baud);
2038 p_priv->baud = 9600;
2039 d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2040 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2046 /* modes must always be correctly specified */
2047 if (p_priv->baud > 57600) {
2048 msg.rxMode = RXMODE_DMA;
2049 msg.txMode = TXMODE_DMA;
2051 msg.rxMode = RXMODE_BYHAND;
2052 msg.txMode = TXMODE_BYHAND;
2055 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2056 switch (p_priv->cflag & CSIZE) {
2058 msg.lcr |= USA_DATABITS_5;
2061 msg.lcr |= USA_DATABITS_6;
2064 msg.lcr |= USA_DATABITS_7;
2067 msg.lcr |= USA_DATABITS_8;
2070 if (p_priv->cflag & PARENB) {
2071 /* note USA_PARITY_NONE == 0 */
2072 msg.lcr |= (p_priv->cflag & PARODD) ?
2073 USA_PARITY_ODD : USA_PARITY_EVEN;
2075 if (p_priv->old_cflag != p_priv->cflag) {
2076 p_priv->old_cflag = p_priv->cflag;
2080 if (p_priv->flow_control == flow_cts)
2081 msg.txFlowControl = TXFLOW_CTS;
2082 msg.setTxFlowControl = 0x01;
2083 msg.setRxFlowControl = 0x01;
2085 msg.rxForwardingLength = 16;
2086 msg.rxForwardingTimeout = 16;
2087 msg.txAckSetting = 0;
2092 if (reset_port == 1) {
2093 msg.portEnabled = 1;
2095 msg.txBreak = (p_priv->break_on);
2098 else if (reset_port == 2)
2099 msg.portEnabled = 0;
2100 /* Sending intermediate configs */
2102 msg.portEnabled = 1;
2103 msg.txBreak = (p_priv->break_on);
2106 /* Do handshaking outputs */
2108 msg.rts = p_priv->rts_state;
2111 msg.dtr = p_priv->dtr_state;
2113 p_priv->resend_cont = 0;
2114 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2116 /* send the data out the device on control endpoint */
2117 this_urb->transfer_buffer_length = sizeof(msg);
2119 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2121 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2125 static int keyspan_usa67_send_setup(struct usb_serial *serial,
2126 struct usb_serial_port *port,
2129 struct keyspan_usa67_portControlMessage msg;
2130 struct keyspan_serial_private *s_priv;
2131 struct keyspan_port_private *p_priv;
2132 const struct keyspan_device_details *d_details;
2133 struct urb *this_urb;
2134 int err, device_port;
2136 s_priv = usb_get_serial_data(serial);
2137 p_priv = usb_get_serial_port_data(port);
2138 d_details = s_priv->device_details;
2140 this_urb = s_priv->glocont_urb;
2142 /* Work out which port within the device is being setup */
2143 device_port = port->port_number;
2145 /* Make sure we have an urb then send the message */
2146 if (this_urb == NULL) {
2147 dev_dbg(&port->dev, "%s - oops no urb for port.\n", __func__);
2151 /* Save reset port val for resend.
2152 Don't overwrite resend for open/close condition. */
2153 if ((reset_port + 1) > p_priv->resend_cont)
2154 p_priv->resend_cont = reset_port + 1;
2155 if (this_urb->status == -EINPROGRESS) {
2156 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2161 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
2163 msg.port = device_port;
2165 /* Only set baud rate if it's changed */
2166 if (p_priv->old_baud != p_priv->baud) {
2167 p_priv->old_baud = p_priv->baud;
2168 msg.setClocking = 0xff;
2169 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2170 &msg.baudHi, &msg.baudLo, &msg.prescaler,
2171 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2172 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2173 __func__, p_priv->baud);
2175 msg.baudHi = 125; /* Values for 9600 baud */
2178 msg.setPrescaler = 0xff;
2181 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2182 switch (p_priv->cflag & CSIZE) {
2184 msg.lcr |= USA_DATABITS_5;
2187 msg.lcr |= USA_DATABITS_6;
2190 msg.lcr |= USA_DATABITS_7;
2193 msg.lcr |= USA_DATABITS_8;
2196 if (p_priv->cflag & PARENB) {
2197 /* note USA_PARITY_NONE == 0 */
2198 msg.lcr |= (p_priv->cflag & PARODD) ?
2199 USA_PARITY_ODD : USA_PARITY_EVEN;
2203 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2204 msg.xonFlowControl = 0;
2205 msg.setFlowControl = 0xff;
2206 msg.forwardingLength = 16;
2210 if (reset_port == 1) {
2220 msg.returnStatus = 0;
2221 msg.resetDataToggle = 0xff;
2222 } else if (reset_port == 2) {
2232 msg.returnStatus = 0;
2233 msg.resetDataToggle = 0;
2235 /* Sending intermediate configs */
2236 msg._txOn = (!p_priv->break_on);
2239 msg.txBreak = (p_priv->break_on);
2244 msg.returnStatus = 0;
2245 msg.resetDataToggle = 0x0;
2248 /* Do handshaking outputs */
2249 msg.setTxTriState_setRts = 0xff;
2250 msg.txTriState_rts = p_priv->rts_state;
2252 msg.setHskoa_setDtr = 0xff;
2253 msg.hskoa_dtr = p_priv->dtr_state;
2255 p_priv->resend_cont = 0;
2257 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2259 /* send the data out the device on control endpoint */
2260 this_urb->transfer_buffer_length = sizeof(msg);
2262 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2264 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2268 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2270 struct usb_serial *serial = port->serial;
2271 struct keyspan_serial_private *s_priv;
2272 const struct keyspan_device_details *d_details;
2274 s_priv = usb_get_serial_data(serial);
2275 d_details = s_priv->device_details;
2277 switch (d_details->msg_format) {
2279 keyspan_usa26_send_setup(serial, port, reset_port);
2282 keyspan_usa28_send_setup(serial, port, reset_port);
2285 keyspan_usa49_send_setup(serial, port, reset_port);
2288 keyspan_usa90_send_setup(serial, port, reset_port);
2291 keyspan_usa67_send_setup(serial, port, reset_port);
2297 /* Gets called by the "real" driver (ie once firmware is loaded
2298 and renumeration has taken place. */
2299 static int keyspan_startup(struct usb_serial *serial)
2302 struct keyspan_serial_private *s_priv;
2303 const struct keyspan_device_details *d_details;
2305 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2306 if (d_details->product_id ==
2307 le16_to_cpu(serial->dev->descriptor.idProduct))
2309 if (d_details == NULL) {
2310 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2311 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2315 /* Setup private data for serial driver */
2316 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2320 s_priv->instat_buf = kzalloc(INSTAT_BUFLEN, GFP_KERNEL);
2321 if (!s_priv->instat_buf)
2322 goto err_instat_buf;
2324 s_priv->indat_buf = kzalloc(INDAT49W_BUFLEN, GFP_KERNEL);
2325 if (!s_priv->indat_buf)
2328 s_priv->glocont_buf = kzalloc(GLOCONT_BUFLEN, GFP_KERNEL);
2329 if (!s_priv->glocont_buf)
2330 goto err_glocont_buf;
2332 s_priv->ctrl_buf = kzalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
2333 if (!s_priv->ctrl_buf)
2336 s_priv->device_details = d_details;
2337 usb_set_serial_data(serial, s_priv);
2339 keyspan_setup_urbs(serial);
2341 if (s_priv->instat_urb != NULL) {
2342 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2344 dev_dbg(&serial->dev->dev, "%s - submit instat urb failed %d\n", __func__, err);
2346 if (s_priv->indat_urb != NULL) {
2347 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2349 dev_dbg(&serial->dev->dev, "%s - submit indat urb failed %d\n", __func__, err);
2355 kfree(s_priv->glocont_buf);
2357 kfree(s_priv->indat_buf);
2359 kfree(s_priv->instat_buf);
2366 static void keyspan_disconnect(struct usb_serial *serial)
2368 struct keyspan_serial_private *s_priv;
2370 s_priv = usb_get_serial_data(serial);
2372 stop_urb(s_priv->instat_urb);
2373 stop_urb(s_priv->glocont_urb);
2374 stop_urb(s_priv->indat_urb);
2377 static void keyspan_release(struct usb_serial *serial)
2379 struct keyspan_serial_private *s_priv;
2381 s_priv = usb_get_serial_data(serial);
2383 /* Make sure to unlink the URBs submitted in attach. */
2384 usb_kill_urb(s_priv->instat_urb);
2385 usb_kill_urb(s_priv->indat_urb);
2387 usb_free_urb(s_priv->instat_urb);
2388 usb_free_urb(s_priv->indat_urb);
2389 usb_free_urb(s_priv->glocont_urb);
2391 kfree(s_priv->ctrl_buf);
2392 kfree(s_priv->glocont_buf);
2393 kfree(s_priv->indat_buf);
2394 kfree(s_priv->instat_buf);
2399 static int keyspan_port_probe(struct usb_serial_port *port)
2401 struct usb_serial *serial = port->serial;
2402 struct keyspan_serial_private *s_priv;
2403 struct keyspan_port_private *p_priv;
2404 const struct keyspan_device_details *d_details;
2405 struct callbacks *cback;
2410 s_priv = usb_get_serial_data(serial);
2411 d_details = s_priv->device_details;
2413 p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL);
2417 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i) {
2418 p_priv->in_buffer[i] = kzalloc(IN_BUFLEN, GFP_KERNEL);
2419 if (!p_priv->in_buffer[i])
2423 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i) {
2424 p_priv->out_buffer[i] = kzalloc(OUT_BUFLEN, GFP_KERNEL);
2425 if (!p_priv->out_buffer[i])
2426 goto err_out_buffer;
2429 p_priv->inack_buffer = kzalloc(INACK_BUFLEN, GFP_KERNEL);
2430 if (!p_priv->inack_buffer)
2431 goto err_inack_buffer;
2433 p_priv->outcont_buffer = kzalloc(OUTCONT_BUFLEN, GFP_KERNEL);
2434 if (!p_priv->outcont_buffer)
2435 goto err_outcont_buffer;
2437 p_priv->device_details = d_details;
2439 /* Setup values for the various callback routines */
2440 cback = &keyspan_callbacks[d_details->msg_format];
2442 port_num = port->port_number;
2444 /* Do indat endpoints first, once for each flip */
2445 endp = d_details->indat_endpoints[port_num];
2446 for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) {
2447 p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp,
2449 p_priv->in_buffer[i],
2451 cback->indat_callback);
2453 /* outdat endpoints also have flip */
2454 endp = d_details->outdat_endpoints[port_num];
2455 for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) {
2456 p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp,
2458 p_priv->out_buffer[i],
2460 cback->outdat_callback);
2462 /* inack endpoint */
2463 p_priv->inack_urb = keyspan_setup_urb(serial,
2464 d_details->inack_endpoints[port_num],
2466 p_priv->inack_buffer,
2468 cback->inack_callback);
2469 /* outcont endpoint */
2470 p_priv->outcont_urb = keyspan_setup_urb(serial,
2471 d_details->outcont_endpoints[port_num],
2473 p_priv->outcont_buffer,
2475 cback->outcont_callback);
2477 usb_set_serial_port_data(port, p_priv);
2482 kfree(p_priv->inack_buffer);
2484 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
2485 kfree(p_priv->out_buffer[i]);
2487 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
2488 kfree(p_priv->in_buffer[i]);
2495 static int keyspan_port_remove(struct usb_serial_port *port)
2497 struct keyspan_port_private *p_priv;
2500 p_priv = usb_get_serial_port_data(port);
2502 stop_urb(p_priv->inack_urb);
2503 stop_urb(p_priv->outcont_urb);
2504 for (i = 0; i < 2; i++) {
2505 stop_urb(p_priv->in_urbs[i]);
2506 stop_urb(p_priv->out_urbs[i]);
2509 usb_free_urb(p_priv->inack_urb);
2510 usb_free_urb(p_priv->outcont_urb);
2511 for (i = 0; i < 2; i++) {
2512 usb_free_urb(p_priv->in_urbs[i]);
2513 usb_free_urb(p_priv->out_urbs[i]);
2516 kfree(p_priv->outcont_buffer);
2517 kfree(p_priv->inack_buffer);
2518 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
2519 kfree(p_priv->out_buffer[i]);
2520 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
2521 kfree(p_priv->in_buffer[i]);
2528 MODULE_AUTHOR(DRIVER_AUTHOR);
2529 MODULE_DESCRIPTION(DRIVER_DESC);
2530 MODULE_LICENSE("GPL");