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 %x 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 %d on endpoint %x\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: %d\n",
400 if (urb->actual_length != 9) {
401 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
405 msg = (struct keyspan_usa26_portStatusMessage *)data;
407 /* Check port number from message and retrieve private data */
408 if (msg->port >= serial->num_ports) {
409 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
412 port = serial->port[msg->port];
413 p_priv = usb_get_serial_port_data(port);
417 /* Update handshaking pin state information */
418 old_dcd_state = p_priv->dcd_state;
419 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
420 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
421 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
422 p_priv->ri_state = ((msg->ri) ? 1 : 0);
424 if (old_dcd_state != p_priv->dcd_state)
425 tty_port_tty_hangup(&port->port, true);
427 /* Resubmit urb so we continue receiving */
428 err = usb_submit_urb(urb, GFP_ATOMIC);
430 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
434 static void usa26_glocont_callback(struct urb *urb)
439 static void usa28_indat_callback(struct urb *urb)
442 struct usb_serial_port *port;
444 struct keyspan_port_private *p_priv;
445 int status = urb->status;
448 p_priv = usb_get_serial_port_data(port);
449 data = urb->transfer_buffer;
451 if (urb != p_priv->in_urbs[p_priv->in_flip])
456 dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
457 __func__, status, usb_pipeendpoint(urb->pipe));
462 p_priv = usb_get_serial_port_data(port);
463 data = urb->transfer_buffer;
465 if (urb->actual_length) {
466 tty_insert_flip_string(&port->port, data,
468 tty_flip_buffer_push(&port->port);
471 /* Resubmit urb so we continue receiving */
472 err = usb_submit_urb(urb, GFP_ATOMIC);
474 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n",
476 p_priv->in_flip ^= 1;
478 urb = p_priv->in_urbs[p_priv->in_flip];
479 } while (urb->status != -EINPROGRESS);
482 static void usa28_inack_callback(struct urb *urb)
486 static void usa28_outcont_callback(struct urb *urb)
488 struct usb_serial_port *port;
489 struct keyspan_port_private *p_priv;
492 p_priv = usb_get_serial_port_data(port);
494 if (p_priv->resend_cont) {
495 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
496 keyspan_usa28_send_setup(port->serial, port,
497 p_priv->resend_cont - 1);
501 static void usa28_instat_callback(struct urb *urb)
504 unsigned char *data = urb->transfer_buffer;
505 struct keyspan_usa28_portStatusMessage *msg;
506 struct usb_serial *serial;
507 struct usb_serial_port *port;
508 struct keyspan_port_private *p_priv;
510 int status = urb->status;
512 serial = urb->context;
515 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
520 if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) {
521 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
525 msg = (struct keyspan_usa28_portStatusMessage *)data;
527 /* Check port number from message and retrieve private data */
528 if (msg->port >= serial->num_ports) {
529 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
532 port = serial->port[msg->port];
533 p_priv = usb_get_serial_port_data(port);
537 /* Update handshaking pin state information */
538 old_dcd_state = p_priv->dcd_state;
539 p_priv->cts_state = ((msg->cts) ? 1 : 0);
540 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
541 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
542 p_priv->ri_state = ((msg->ri) ? 1 : 0);
544 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
545 tty_port_tty_hangup(&port->port, true);
547 /* Resubmit urb so we continue receiving */
548 err = usb_submit_urb(urb, GFP_ATOMIC);
550 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
554 static void usa28_glocont_callback(struct urb *urb)
559 static void usa49_glocont_callback(struct urb *urb)
561 struct usb_serial *serial;
562 struct usb_serial_port *port;
563 struct keyspan_port_private *p_priv;
566 serial = urb->context;
567 for (i = 0; i < serial->num_ports; ++i) {
568 port = serial->port[i];
569 p_priv = usb_get_serial_port_data(port);
573 if (p_priv->resend_cont) {
574 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
575 keyspan_usa49_send_setup(serial, port,
576 p_priv->resend_cont - 1);
582 /* This is actually called glostat in the Keyspan
584 static void usa49_instat_callback(struct urb *urb)
587 unsigned char *data = urb->transfer_buffer;
588 struct keyspan_usa49_portStatusMessage *msg;
589 struct usb_serial *serial;
590 struct usb_serial_port *port;
591 struct keyspan_port_private *p_priv;
593 int status = urb->status;
595 serial = urb->context;
598 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
603 if (urb->actual_length !=
604 sizeof(struct keyspan_usa49_portStatusMessage)) {
605 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
609 msg = (struct keyspan_usa49_portStatusMessage *)data;
611 /* Check port number from message and retrieve private data */
612 if (msg->portNumber >= serial->num_ports) {
613 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
614 __func__, msg->portNumber);
617 port = serial->port[msg->portNumber];
618 p_priv = usb_get_serial_port_data(port);
622 /* Update handshaking pin state information */
623 old_dcd_state = p_priv->dcd_state;
624 p_priv->cts_state = ((msg->cts) ? 1 : 0);
625 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
626 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
627 p_priv->ri_state = ((msg->ri) ? 1 : 0);
629 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
630 tty_port_tty_hangup(&port->port, true);
632 /* Resubmit urb so we continue receiving */
633 err = usb_submit_urb(urb, GFP_ATOMIC);
635 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
639 static void usa49_inack_callback(struct urb *urb)
643 static void usa49_indat_callback(struct urb *urb)
647 struct usb_serial_port *port;
648 unsigned char *data = urb->transfer_buffer;
649 int status = urb->status;
651 endpoint = usb_pipeendpoint(urb->pipe);
654 dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
655 __func__, status, endpoint);
660 if (urb->actual_length) {
661 /* 0x80 bit is error flag */
662 if ((data[0] & 0x80) == 0) {
663 /* no error on any byte */
664 tty_insert_flip_string(&port->port, data + 1,
665 urb->actual_length - 1);
667 /* some bytes had errors, every byte has status */
668 for (i = 0; i + 1 < urb->actual_length; i += 2) {
670 int flag = TTY_NORMAL;
672 if (stat & RXERROR_OVERRUN) {
673 tty_insert_flip_char(&port->port, 0,
676 /* XXX should handle break (0x10) */
677 if (stat & RXERROR_PARITY)
679 else if (stat & RXERROR_FRAMING)
682 tty_insert_flip_char(&port->port, data[i+1],
686 tty_flip_buffer_push(&port->port);
689 /* Resubmit urb so we continue receiving */
690 err = usb_submit_urb(urb, GFP_ATOMIC);
692 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
695 static void usa49wg_indat_callback(struct urb *urb)
698 struct usb_serial *serial;
699 struct usb_serial_port *port;
700 unsigned char *data = urb->transfer_buffer;
701 int status = urb->status;
703 serial = urb->context;
706 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
711 /* inbound data is in the form P#, len, status, data */
715 while (i < urb->actual_length) {
717 /* Check port number from message */
718 if (data[i] >= serial->num_ports) {
719 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
723 port = serial->port[data[i++]];
726 /* 0x80 bit is error flag */
727 if ((data[i] & 0x80) == 0) {
728 /* no error on any byte */
730 for (x = 1; x < len && i < urb->actual_length; ++x)
731 tty_insert_flip_char(&port->port,
735 * some bytes had errors, every byte has status
737 for (x = 0; x + 1 < len &&
738 i + 1 < urb->actual_length; x += 2) {
740 int flag = TTY_NORMAL;
742 if (stat & RXERROR_OVERRUN) {
743 tty_insert_flip_char(&port->port, 0,
746 /* XXX should handle break (0x10) */
747 if (stat & RXERROR_PARITY)
749 else if (stat & RXERROR_FRAMING)
752 tty_insert_flip_char(&port->port, data[i+1],
757 tty_flip_buffer_push(&port->port);
760 /* Resubmit urb so we continue receiving */
761 err = usb_submit_urb(urb, GFP_ATOMIC);
763 dev_dbg(&urb->dev->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
766 /* not used, usa-49 doesn't have per-port control endpoints */
767 static void usa49_outcont_callback(struct urb *urb)
771 static void usa90_indat_callback(struct urb *urb)
775 struct usb_serial_port *port;
776 struct keyspan_port_private *p_priv;
777 unsigned char *data = urb->transfer_buffer;
778 int status = urb->status;
780 endpoint = usb_pipeendpoint(urb->pipe);
783 dev_dbg(&urb->dev->dev, "%s - nonzero status %d on endpoint %x\n",
784 __func__, status, endpoint);
789 p_priv = usb_get_serial_port_data(port);
791 if (urb->actual_length) {
792 /* if current mode is DMA, looks like usa28 format
793 otherwise looks like usa26 data format */
795 if (p_priv->baud > 57600)
796 tty_insert_flip_string(&port->port, data,
799 /* 0x80 bit is error flag */
800 if ((data[0] & 0x80) == 0) {
801 /* no errors on individual bytes, only
802 possible overrun err*/
803 if (data[0] & RXERROR_OVERRUN) {
804 tty_insert_flip_char(&port->port, 0,
807 for (i = 1; i < urb->actual_length ; ++i)
808 tty_insert_flip_char(&port->port,
809 data[i], TTY_NORMAL);
811 /* some bytes had errors, every byte has status */
812 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
813 for (i = 0; i + 1 < urb->actual_length; i += 2) {
815 int flag = TTY_NORMAL;
817 if (stat & RXERROR_OVERRUN) {
818 tty_insert_flip_char(
822 /* XXX should handle break (0x10) */
823 if (stat & RXERROR_PARITY)
825 else if (stat & RXERROR_FRAMING)
828 tty_insert_flip_char(&port->port,
833 tty_flip_buffer_push(&port->port);
836 /* Resubmit urb so we continue receiving */
837 err = usb_submit_urb(urb, GFP_ATOMIC);
839 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
843 static void usa90_instat_callback(struct urb *urb)
845 unsigned char *data = urb->transfer_buffer;
846 struct keyspan_usa90_portStatusMessage *msg;
847 struct usb_serial *serial;
848 struct usb_serial_port *port;
849 struct keyspan_port_private *p_priv;
850 int old_dcd_state, err;
851 int status = urb->status;
853 serial = urb->context;
856 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
860 if (urb->actual_length < 14) {
861 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
865 msg = (struct keyspan_usa90_portStatusMessage *)data;
867 /* Now do something useful with the data */
869 port = serial->port[0];
870 p_priv = usb_get_serial_port_data(port);
874 /* Update handshaking pin state information */
875 old_dcd_state = p_priv->dcd_state;
876 p_priv->cts_state = ((msg->cts) ? 1 : 0);
877 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
878 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
879 p_priv->ri_state = ((msg->ri) ? 1 : 0);
881 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
882 tty_port_tty_hangup(&port->port, true);
884 /* Resubmit urb so we continue receiving */
885 err = usb_submit_urb(urb, GFP_ATOMIC);
887 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
892 static void usa90_outcont_callback(struct urb *urb)
894 struct usb_serial_port *port;
895 struct keyspan_port_private *p_priv;
898 p_priv = usb_get_serial_port_data(port);
900 if (p_priv->resend_cont) {
901 dev_dbg(&urb->dev->dev, "%s - sending setup\n", __func__);
902 keyspan_usa90_send_setup(port->serial, port,
903 p_priv->resend_cont - 1);
907 /* Status messages from the 28xg */
908 static void usa67_instat_callback(struct urb *urb)
911 unsigned char *data = urb->transfer_buffer;
912 struct keyspan_usa67_portStatusMessage *msg;
913 struct usb_serial *serial;
914 struct usb_serial_port *port;
915 struct keyspan_port_private *p_priv;
917 int status = urb->status;
919 serial = urb->context;
922 dev_dbg(&urb->dev->dev, "%s - nonzero status: %d\n",
927 if (urb->actual_length !=
928 sizeof(struct keyspan_usa67_portStatusMessage)) {
929 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
934 /* Now do something useful with the data */
935 msg = (struct keyspan_usa67_portStatusMessage *)data;
937 /* Check port number from message and retrieve private data */
938 if (msg->port >= serial->num_ports) {
939 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
943 port = serial->port[msg->port];
944 p_priv = usb_get_serial_port_data(port);
948 /* Update handshaking pin state information */
949 old_dcd_state = p_priv->dcd_state;
950 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
951 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
953 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
954 tty_port_tty_hangup(&port->port, true);
956 /* Resubmit urb so we continue receiving */
957 err = usb_submit_urb(urb, GFP_ATOMIC);
959 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
962 static void usa67_glocont_callback(struct urb *urb)
964 struct usb_serial *serial;
965 struct usb_serial_port *port;
966 struct keyspan_port_private *p_priv;
969 serial = urb->context;
970 for (i = 0; i < serial->num_ports; ++i) {
971 port = serial->port[i];
972 p_priv = usb_get_serial_port_data(port);
976 if (p_priv->resend_cont) {
977 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
978 keyspan_usa67_send_setup(serial, port,
979 p_priv->resend_cont - 1);
985 static int keyspan_write_room(struct tty_struct *tty)
987 struct usb_serial_port *port = tty->driver_data;
988 struct keyspan_port_private *p_priv;
989 const struct keyspan_device_details *d_details;
992 struct urb *this_urb;
994 p_priv = usb_get_serial_port_data(port);
995 d_details = p_priv->device_details;
998 if (d_details->msg_format == msg_usa90)
1003 flip = p_priv->out_flip;
1005 /* Check both endpoints to see if any are available. */
1006 this_urb = p_priv->out_urbs[flip];
1007 if (this_urb != NULL) {
1008 if (this_urb->status != -EINPROGRESS)
1010 flip = (flip + 1) & d_details->outdat_endp_flip;
1011 this_urb = p_priv->out_urbs[flip];
1012 if (this_urb != NULL) {
1013 if (this_urb->status != -EINPROGRESS)
1021 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1023 struct keyspan_port_private *p_priv;
1024 const struct keyspan_device_details *d_details;
1026 int baud_rate, device_port;
1028 unsigned int cflag = 0;
1030 p_priv = usb_get_serial_port_data(port);
1031 d_details = p_priv->device_details;
1033 /* Set some sane defaults */
1034 p_priv->rts_state = 1;
1035 p_priv->dtr_state = 1;
1036 p_priv->baud = 9600;
1038 /* force baud and lcr to be set on open */
1039 p_priv->old_baud = 0;
1040 p_priv->old_cflag = 0;
1042 p_priv->out_flip = 0;
1043 p_priv->in_flip = 0;
1045 /* Reset low level data toggle and start reading from endpoints */
1046 for (i = 0; i < 2; i++) {
1047 urb = p_priv->in_urbs[i];
1051 /* make sure endpoint data toggle is synchronized
1053 usb_clear_halt(urb->dev, urb->pipe);
1054 err = usb_submit_urb(urb, GFP_KERNEL);
1056 dev_dbg(&port->dev, "%s - submit urb %d failed (%d)\n", __func__, i, err);
1059 /* Reset low level data toggle on out endpoints */
1060 for (i = 0; i < 2; i++) {
1061 urb = p_priv->out_urbs[i];
1064 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1065 usb_pipeout(urb->pipe), 0); */
1068 /* get the terminal config for the setup message now so we don't
1069 * need to send 2 of them */
1071 device_port = port->port_number;
1073 cflag = tty->termios.c_cflag;
1074 /* Baud rate calculation takes baud rate as an integer
1075 so other rates can be generated if desired. */
1076 baud_rate = tty_get_baud_rate(tty);
1077 /* If no match or invalid, leave as default */
1079 && d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
1080 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1081 p_priv->baud = baud_rate;
1084 /* set CTS/RTS handshake etc. */
1085 p_priv->cflag = cflag;
1086 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
1088 keyspan_send_setup(port, 1);
1090 /* keyspan_set_termios(port, NULL); */
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 usb_kill_urb(p_priv->inack_urb);
1122 for (i = 0; i < 2; i++) {
1123 usb_kill_urb(p_priv->in_urbs[i]);
1124 usb_kill_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 endpoint %x\n",
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 %x\n",
1245 __func__, endpoint);
1246 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1250 if (endpoint == 0) {
1251 /* control EP filled in when used */
1255 ep_desc = find_ep(serial, endpoint);
1260 if (usb_endpoint_xfer_int(ep_desc)) {
1261 ep_type_name = "INT";
1262 usb_fill_int_urb(urb, serial->dev,
1263 usb_sndintpipe(serial->dev, endpoint) | dir,
1264 buf, len, callback, ctx,
1265 ep_desc->bInterval);
1266 } else if (usb_endpoint_xfer_bulk(ep_desc)) {
1267 ep_type_name = "BULK";
1268 usb_fill_bulk_urb(urb, serial->dev,
1269 usb_sndbulkpipe(serial->dev, endpoint) | dir,
1270 buf, len, callback, ctx);
1272 dev_warn(&serial->interface->dev,
1273 "unsupported endpoint type %x\n",
1274 usb_endpoint_type(ep_desc));
1279 dev_dbg(&serial->interface->dev, "%s - using urb %p for %s endpoint %x\n",
1280 __func__, urb, ep_type_name, endpoint);
1284 static struct callbacks {
1285 void (*instat_callback)(struct urb *);
1286 void (*glocont_callback)(struct urb *);
1287 void (*indat_callback)(struct urb *);
1288 void (*outdat_callback)(struct urb *);
1289 void (*inack_callback)(struct urb *);
1290 void (*outcont_callback)(struct urb *);
1291 } keyspan_callbacks[] = {
1293 /* msg_usa26 callbacks */
1294 .instat_callback = usa26_instat_callback,
1295 .glocont_callback = usa26_glocont_callback,
1296 .indat_callback = usa26_indat_callback,
1297 .outdat_callback = usa2x_outdat_callback,
1298 .inack_callback = usa26_inack_callback,
1299 .outcont_callback = usa26_outcont_callback,
1301 /* msg_usa28 callbacks */
1302 .instat_callback = usa28_instat_callback,
1303 .glocont_callback = usa28_glocont_callback,
1304 .indat_callback = usa28_indat_callback,
1305 .outdat_callback = usa2x_outdat_callback,
1306 .inack_callback = usa28_inack_callback,
1307 .outcont_callback = usa28_outcont_callback,
1309 /* msg_usa49 callbacks */
1310 .instat_callback = usa49_instat_callback,
1311 .glocont_callback = usa49_glocont_callback,
1312 .indat_callback = usa49_indat_callback,
1313 .outdat_callback = usa2x_outdat_callback,
1314 .inack_callback = usa49_inack_callback,
1315 .outcont_callback = usa49_outcont_callback,
1317 /* msg_usa90 callbacks */
1318 .instat_callback = usa90_instat_callback,
1319 .glocont_callback = usa28_glocont_callback,
1320 .indat_callback = usa90_indat_callback,
1321 .outdat_callback = usa2x_outdat_callback,
1322 .inack_callback = usa28_inack_callback,
1323 .outcont_callback = usa90_outcont_callback,
1325 /* msg_usa67 callbacks */
1326 .instat_callback = usa67_instat_callback,
1327 .glocont_callback = usa67_glocont_callback,
1328 .indat_callback = usa26_indat_callback,
1329 .outdat_callback = usa2x_outdat_callback,
1330 .inack_callback = usa26_inack_callback,
1331 .outcont_callback = usa26_outcont_callback,
1335 /* Generic setup urbs function that uses
1336 data in device_details */
1337 static void keyspan_setup_urbs(struct usb_serial *serial)
1339 struct keyspan_serial_private *s_priv;
1340 const struct keyspan_device_details *d_details;
1341 struct callbacks *cback;
1343 s_priv = usb_get_serial_data(serial);
1344 d_details = s_priv->device_details;
1346 /* Setup values for the various callback routines */
1347 cback = &keyspan_callbacks[d_details->msg_format];
1349 /* Allocate and set up urbs for each one that is in use,
1350 starting with instat endpoints */
1351 s_priv->instat_urb = keyspan_setup_urb
1352 (serial, d_details->instat_endpoint, USB_DIR_IN,
1353 serial, s_priv->instat_buf, INSTAT_BUFLEN,
1354 cback->instat_callback);
1356 s_priv->indat_urb = keyspan_setup_urb
1357 (serial, d_details->indat_endpoint, USB_DIR_IN,
1358 serial, s_priv->indat_buf, INDAT49W_BUFLEN,
1359 usa49wg_indat_callback);
1361 s_priv->glocont_urb = keyspan_setup_urb
1362 (serial, d_details->glocont_endpoint, USB_DIR_OUT,
1363 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1364 cback->glocont_callback);
1367 /* usa19 function doesn't require prescaler */
1368 static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
1369 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1370 u8 *rate_low, u8 *prescaler, int portnum)
1372 u32 b16, /* baud rate times 16 (actual rate used internally) */
1374 cnt; /* inverse of divisor (programmed into 8051) */
1376 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1378 /* prevent divide by zero... */
1379 b16 = baud_rate * 16L;
1381 return KEYSPAN_INVALID_BAUD_RATE;
1382 /* Any "standard" rate over 57k6 is marginal on the USA-19
1383 as we run out of divisor resolution. */
1384 if (baud_rate > 57600)
1385 return KEYSPAN_INVALID_BAUD_RATE;
1387 /* calculate the divisor and the counter (its inverse) */
1388 div = baudclk / b16;
1390 return KEYSPAN_INVALID_BAUD_RATE;
1395 return KEYSPAN_INVALID_BAUD_RATE;
1397 /* return the counter values if non-null */
1399 *rate_low = (u8) (cnt & 0xff);
1401 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1402 if (rate_low && rate_hi)
1403 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1404 __func__, baud_rate, *rate_hi, *rate_low);
1405 return KEYSPAN_BAUD_RATE_OK;
1408 /* usa19hs function doesn't require prescaler */
1409 static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
1410 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1411 u8 *rate_low, u8 *prescaler, int portnum)
1413 u32 b16, /* baud rate times 16 (actual rate used internally) */
1416 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1418 /* prevent divide by zero... */
1419 b16 = baud_rate * 16L;
1421 return KEYSPAN_INVALID_BAUD_RATE;
1423 /* calculate the divisor */
1424 div = baudclk / b16;
1426 return KEYSPAN_INVALID_BAUD_RATE;
1429 return KEYSPAN_INVALID_BAUD_RATE;
1431 /* return the counter values if non-null */
1433 *rate_low = (u8) (div & 0xff);
1436 *rate_hi = (u8) ((div >> 8) & 0xff);
1438 if (rate_low && rate_hi)
1439 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1440 __func__, baud_rate, *rate_hi, *rate_low);
1442 return KEYSPAN_BAUD_RATE_OK;
1445 static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
1446 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1447 u8 *rate_low, u8 *prescaler, int portnum)
1449 u32 b16, /* baud rate times 16 (actual rate used internally) */
1450 clk, /* clock with 13/8 prescaler */
1451 div, /* divisor using 13/8 prescaler */
1452 res, /* resulting baud rate using 13/8 prescaler */
1453 diff, /* error using 13/8 prescaler */
1458 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1460 /* prevent divide by zero */
1461 b16 = baud_rate * 16L;
1463 return KEYSPAN_INVALID_BAUD_RATE;
1465 /* Calculate prescaler by trying them all and looking
1468 /* start with largest possible difference */
1469 smallest_diff = 0xffffffff;
1471 /* 0 is an invalid prescaler, used as a flag */
1474 for (i = 8; i <= 0xff; ++i) {
1475 clk = (baudclk * 8) / (u32) i;
1482 diff = (res > b16) ? (res-b16) : (b16-res);
1484 if (diff < smallest_diff) {
1486 smallest_diff = diff;
1490 if (best_prescaler == 0)
1491 return KEYSPAN_INVALID_BAUD_RATE;
1493 clk = (baudclk * 8) / (u32) best_prescaler;
1496 /* return the divisor and prescaler if non-null */
1498 *rate_low = (u8) (div & 0xff);
1500 *rate_hi = (u8) ((div >> 8) & 0xff);
1502 *prescaler = best_prescaler;
1503 /* dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
1505 return KEYSPAN_BAUD_RATE_OK;
1508 /* USA-28 supports different maximum baud rates on each port */
1509 static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
1510 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1511 u8 *rate_low, u8 *prescaler, int portnum)
1513 u32 b16, /* baud rate times 16 (actual rate used internally) */
1515 cnt; /* inverse of divisor (programmed into 8051) */
1517 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1519 /* prevent divide by zero */
1520 b16 = baud_rate * 16L;
1522 return KEYSPAN_INVALID_BAUD_RATE;
1524 /* calculate the divisor and the counter (its inverse) */
1525 div = KEYSPAN_USA28_BAUDCLK / b16;
1527 return KEYSPAN_INVALID_BAUD_RATE;
1531 /* check for out of range, based on portnum,
1532 and return result */
1535 return KEYSPAN_INVALID_BAUD_RATE;
1539 return KEYSPAN_INVALID_BAUD_RATE;
1541 return KEYSPAN_INVALID_BAUD_RATE;
1544 /* return the counter values if not NULL
1545 (port 1 will ignore retHi) */
1547 *rate_low = (u8) (cnt & 0xff);
1549 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1550 dev_dbg(&port->dev, "%s - %d OK.\n", __func__, baud_rate);
1551 return KEYSPAN_BAUD_RATE_OK;
1554 static int keyspan_usa26_send_setup(struct usb_serial *serial,
1555 struct usb_serial_port *port,
1558 struct keyspan_usa26_portControlMessage msg;
1559 struct keyspan_serial_private *s_priv;
1560 struct keyspan_port_private *p_priv;
1561 const struct keyspan_device_details *d_details;
1562 struct urb *this_urb;
1563 int device_port, err;
1565 dev_dbg(&port->dev, "%s reset=%d\n", __func__, reset_port);
1567 s_priv = usb_get_serial_data(serial);
1568 p_priv = usb_get_serial_port_data(port);
1569 d_details = s_priv->device_details;
1570 device_port = port->port_number;
1572 this_urb = p_priv->outcont_urb;
1574 /* Make sure we have an urb then send the message */
1575 if (this_urb == NULL) {
1576 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1580 dev_dbg(&port->dev, "%s - endpoint %x\n",
1581 __func__, usb_pipeendpoint(this_urb->pipe));
1583 /* Save reset port val for resend.
1584 Don't overwrite resend for open/close condition. */
1585 if ((reset_port + 1) > p_priv->resend_cont)
1586 p_priv->resend_cont = reset_port + 1;
1587 if (this_urb->status == -EINPROGRESS) {
1588 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1593 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1595 /* Only set baud rate if it's changed */
1596 if (p_priv->old_baud != p_priv->baud) {
1597 p_priv->old_baud = p_priv->baud;
1598 msg.setClocking = 0xff;
1599 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1600 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1601 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1602 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1603 __func__, p_priv->baud);
1605 msg.baudHi = 125; /* Values for 9600 baud */
1608 msg.setPrescaler = 0xff;
1611 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1612 switch (p_priv->cflag & CSIZE) {
1614 msg.lcr |= USA_DATABITS_5;
1617 msg.lcr |= USA_DATABITS_6;
1620 msg.lcr |= USA_DATABITS_7;
1623 msg.lcr |= USA_DATABITS_8;
1626 if (p_priv->cflag & PARENB) {
1627 /* note USA_PARITY_NONE == 0 */
1628 msg.lcr |= (p_priv->cflag & PARODD) ?
1629 USA_PARITY_ODD : USA_PARITY_EVEN;
1633 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1634 msg.xonFlowControl = 0;
1635 msg.setFlowControl = 0xff;
1636 msg.forwardingLength = 16;
1641 if (reset_port == 1) {
1650 msg.returnStatus = 0;
1651 msg.resetDataToggle = 0xff;
1655 else if (reset_port == 2) {
1664 msg.returnStatus = 0;
1665 msg.resetDataToggle = 0;
1668 /* Sending intermediate configs */
1670 msg._txOn = (!p_priv->break_on);
1673 msg.txBreak = (p_priv->break_on);
1678 msg.returnStatus = 0;
1679 msg.resetDataToggle = 0x0;
1682 /* Do handshaking outputs */
1683 msg.setTxTriState_setRts = 0xff;
1684 msg.txTriState_rts = p_priv->rts_state;
1686 msg.setHskoa_setDtr = 0xff;
1687 msg.hskoa_dtr = p_priv->dtr_state;
1689 p_priv->resend_cont = 0;
1690 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1692 /* send the data out the device on control endpoint */
1693 this_urb->transfer_buffer_length = sizeof(msg);
1695 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1697 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1701 static int keyspan_usa28_send_setup(struct usb_serial *serial,
1702 struct usb_serial_port *port,
1705 struct keyspan_usa28_portControlMessage msg;
1706 struct keyspan_serial_private *s_priv;
1707 struct keyspan_port_private *p_priv;
1708 const struct keyspan_device_details *d_details;
1709 struct urb *this_urb;
1710 int device_port, err;
1712 s_priv = usb_get_serial_data(serial);
1713 p_priv = usb_get_serial_port_data(port);
1714 d_details = s_priv->device_details;
1715 device_port = port->port_number;
1717 /* only do something if we have a bulk out endpoint */
1718 this_urb = p_priv->outcont_urb;
1719 if (this_urb == NULL) {
1720 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1724 /* Save reset port val for resend.
1725 Don't overwrite resend for open/close condition. */
1726 if ((reset_port + 1) > p_priv->resend_cont)
1727 p_priv->resend_cont = reset_port + 1;
1728 if (this_urb->status == -EINPROGRESS) {
1729 dev_dbg(&port->dev, "%s already writing\n", __func__);
1734 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
1736 msg.setBaudRate = 1;
1737 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1738 &msg.baudHi, &msg.baudLo, NULL,
1739 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1740 dev_dbg(&port->dev, "%s - Invalid baud rate requested %d.\n",
1741 __func__, p_priv->baud);
1743 msg.baudHi = 0xb2; /* Values for 9600 baud */
1746 /* If parity is enabled, we must calculate it ourselves. */
1747 msg.parity = 0; /* XXX for now */
1749 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1750 msg.xonFlowControl = 0;
1752 /* Do handshaking outputs, DTR is inverted relative to RTS */
1753 msg.rts = p_priv->rts_state;
1754 msg.dtr = p_priv->dtr_state;
1756 msg.forwardingLength = 16;
1758 msg.breakThreshold = 45;
1762 /*msg.returnStatus = 1;
1763 msg.resetDataToggle = 0xff;*/
1765 if (reset_port == 1) {
1769 msg.txForceXoff = 0;
1775 msg.returnStatus = 0;
1776 msg.resetDataToggle = 0xff;
1779 else if (reset_port == 2) {
1783 msg.txForceXoff = 0;
1789 msg.returnStatus = 0;
1790 msg.resetDataToggle = 0;
1792 /* Sending intermediate configs */
1794 msg._txOn = (!p_priv->break_on);
1797 msg.txForceXoff = 0;
1798 msg.txBreak = (p_priv->break_on);
1803 msg.returnStatus = 0;
1804 msg.resetDataToggle = 0x0;
1807 p_priv->resend_cont = 0;
1808 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1810 /* send the data out the device on control endpoint */
1811 this_urb->transfer_buffer_length = sizeof(msg);
1813 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1815 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed\n", __func__);
1820 static int keyspan_usa49_send_setup(struct usb_serial *serial,
1821 struct usb_serial_port *port,
1824 struct keyspan_usa49_portControlMessage msg;
1825 struct usb_ctrlrequest *dr = NULL;
1826 struct keyspan_serial_private *s_priv;
1827 struct keyspan_port_private *p_priv;
1828 const struct keyspan_device_details *d_details;
1829 struct urb *this_urb;
1830 int err, device_port;
1832 s_priv = usb_get_serial_data(serial);
1833 p_priv = usb_get_serial_port_data(port);
1834 d_details = s_priv->device_details;
1836 this_urb = s_priv->glocont_urb;
1838 /* Work out which port within the device is being setup */
1839 device_port = port->port_number;
1841 /* Make sure we have an urb then send the message */
1842 if (this_urb == NULL) {
1843 dev_dbg(&port->dev, "%s - oops no urb for port.\n", __func__);
1847 dev_dbg(&port->dev, "%s - endpoint %x (%d)\n",
1848 __func__, usb_pipeendpoint(this_urb->pipe), device_port);
1850 /* Save reset port val for resend.
1851 Don't overwrite resend for open/close condition. */
1852 if ((reset_port + 1) > p_priv->resend_cont)
1853 p_priv->resend_cont = reset_port + 1;
1855 if (this_urb->status == -EINPROGRESS) {
1856 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1861 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
1863 msg.portNumber = device_port;
1865 /* Only set baud rate if it's changed */
1866 if (p_priv->old_baud != p_priv->baud) {
1867 p_priv->old_baud = p_priv->baud;
1868 msg.setClocking = 0xff;
1869 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1870 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1871 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1872 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1873 __func__, p_priv->baud);
1875 msg.baudHi = 125; /* Values for 9600 baud */
1878 /* msg.setPrescaler = 0xff; */
1881 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1882 switch (p_priv->cflag & CSIZE) {
1884 msg.lcr |= USA_DATABITS_5;
1887 msg.lcr |= USA_DATABITS_6;
1890 msg.lcr |= USA_DATABITS_7;
1893 msg.lcr |= USA_DATABITS_8;
1896 if (p_priv->cflag & PARENB) {
1897 /* note USA_PARITY_NONE == 0 */
1898 msg.lcr |= (p_priv->cflag & PARODD) ?
1899 USA_PARITY_ODD : USA_PARITY_EVEN;
1903 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1904 msg.xonFlowControl = 0;
1905 msg.setFlowControl = 0xff;
1907 msg.forwardingLength = 16;
1912 if (reset_port == 1) {
1921 msg.returnStatus = 0;
1922 msg.resetDataToggle = 0xff;
1924 msg.disablePort = 0;
1927 else if (reset_port == 2) {
1936 msg.returnStatus = 0;
1937 msg.resetDataToggle = 0;
1939 msg.disablePort = 1;
1941 /* Sending intermediate configs */
1943 msg._txOn = (!p_priv->break_on);
1946 msg.txBreak = (p_priv->break_on);
1951 msg.returnStatus = 0;
1952 msg.resetDataToggle = 0x0;
1954 msg.disablePort = 0;
1957 /* Do handshaking outputs */
1959 msg.rts = p_priv->rts_state;
1962 msg.dtr = p_priv->dtr_state;
1964 p_priv->resend_cont = 0;
1966 /* if the device is a 49wg, we send control message on usb
1969 if (d_details->product_id == keyspan_usa49wg_product_id) {
1970 dr = (void *)(s_priv->ctrl_buf);
1971 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
1972 dr->bRequest = 0xB0; /* 49wg control message */
1975 dr->wLength = cpu_to_le16(sizeof(msg));
1977 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
1979 usb_fill_control_urb(this_urb, serial->dev,
1980 usb_sndctrlpipe(serial->dev, 0),
1981 (unsigned char *)dr, s_priv->glocont_buf,
1982 sizeof(msg), usa49_glocont_callback, serial);
1985 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1987 /* send the data out the device on control endpoint */
1988 this_urb->transfer_buffer_length = sizeof(msg);
1990 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1992 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1997 static int keyspan_usa90_send_setup(struct usb_serial *serial,
1998 struct usb_serial_port *port,
2001 struct keyspan_usa90_portControlMessage msg;
2002 struct keyspan_serial_private *s_priv;
2003 struct keyspan_port_private *p_priv;
2004 const struct keyspan_device_details *d_details;
2005 struct urb *this_urb;
2009 s_priv = usb_get_serial_data(serial);
2010 p_priv = usb_get_serial_port_data(port);
2011 d_details = s_priv->device_details;
2013 /* only do something if we have a bulk out endpoint */
2014 this_urb = p_priv->outcont_urb;
2015 if (this_urb == NULL) {
2016 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
2020 /* Save reset port val for resend.
2021 Don't overwrite resend for open/close condition. */
2022 if ((reset_port + 1) > p_priv->resend_cont)
2023 p_priv->resend_cont = reset_port + 1;
2024 if (this_urb->status == -EINPROGRESS) {
2025 dev_dbg(&port->dev, "%s already writing\n", __func__);
2030 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2032 /* Only set baud rate if it's changed */
2033 if (p_priv->old_baud != p_priv->baud) {
2034 p_priv->old_baud = p_priv->baud;
2035 msg.setClocking = 0x01;
2036 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2037 &msg.baudHi, &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2038 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2039 __func__, p_priv->baud);
2040 p_priv->baud = 9600;
2041 d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2042 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2048 /* modes must always be correctly specified */
2049 if (p_priv->baud > 57600) {
2050 msg.rxMode = RXMODE_DMA;
2051 msg.txMode = TXMODE_DMA;
2053 msg.rxMode = RXMODE_BYHAND;
2054 msg.txMode = TXMODE_BYHAND;
2057 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2058 switch (p_priv->cflag & CSIZE) {
2060 msg.lcr |= USA_DATABITS_5;
2063 msg.lcr |= USA_DATABITS_6;
2066 msg.lcr |= USA_DATABITS_7;
2069 msg.lcr |= USA_DATABITS_8;
2072 if (p_priv->cflag & PARENB) {
2073 /* note USA_PARITY_NONE == 0 */
2074 msg.lcr |= (p_priv->cflag & PARODD) ?
2075 USA_PARITY_ODD : USA_PARITY_EVEN;
2077 if (p_priv->old_cflag != p_priv->cflag) {
2078 p_priv->old_cflag = p_priv->cflag;
2082 if (p_priv->flow_control == flow_cts)
2083 msg.txFlowControl = TXFLOW_CTS;
2084 msg.setTxFlowControl = 0x01;
2085 msg.setRxFlowControl = 0x01;
2087 msg.rxForwardingLength = 16;
2088 msg.rxForwardingTimeout = 16;
2089 msg.txAckSetting = 0;
2094 if (reset_port == 1) {
2095 msg.portEnabled = 1;
2097 msg.txBreak = (p_priv->break_on);
2100 else if (reset_port == 2)
2101 msg.portEnabled = 0;
2102 /* Sending intermediate configs */
2104 msg.portEnabled = 1;
2105 msg.txBreak = (p_priv->break_on);
2108 /* Do handshaking outputs */
2110 msg.rts = p_priv->rts_state;
2113 msg.dtr = p_priv->dtr_state;
2115 p_priv->resend_cont = 0;
2116 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2118 /* send the data out the device on control endpoint */
2119 this_urb->transfer_buffer_length = sizeof(msg);
2121 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2123 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2127 static int keyspan_usa67_send_setup(struct usb_serial *serial,
2128 struct usb_serial_port *port,
2131 struct keyspan_usa67_portControlMessage msg;
2132 struct keyspan_serial_private *s_priv;
2133 struct keyspan_port_private *p_priv;
2134 const struct keyspan_device_details *d_details;
2135 struct urb *this_urb;
2136 int err, device_port;
2138 s_priv = usb_get_serial_data(serial);
2139 p_priv = usb_get_serial_port_data(port);
2140 d_details = s_priv->device_details;
2142 this_urb = s_priv->glocont_urb;
2144 /* Work out which port within the device is being setup */
2145 device_port = port->port_number;
2147 /* Make sure we have an urb then send the message */
2148 if (this_urb == NULL) {
2149 dev_dbg(&port->dev, "%s - oops no urb for port.\n", __func__);
2153 /* Save reset port val for resend.
2154 Don't overwrite resend for open/close condition. */
2155 if ((reset_port + 1) > p_priv->resend_cont)
2156 p_priv->resend_cont = reset_port + 1;
2157 if (this_urb->status == -EINPROGRESS) {
2158 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2163 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
2165 msg.port = device_port;
2167 /* Only set baud rate if it's changed */
2168 if (p_priv->old_baud != p_priv->baud) {
2169 p_priv->old_baud = p_priv->baud;
2170 msg.setClocking = 0xff;
2171 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2172 &msg.baudHi, &msg.baudLo, &msg.prescaler,
2173 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2174 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2175 __func__, p_priv->baud);
2177 msg.baudHi = 125; /* Values for 9600 baud */
2180 msg.setPrescaler = 0xff;
2183 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2184 switch (p_priv->cflag & CSIZE) {
2186 msg.lcr |= USA_DATABITS_5;
2189 msg.lcr |= USA_DATABITS_6;
2192 msg.lcr |= USA_DATABITS_7;
2195 msg.lcr |= USA_DATABITS_8;
2198 if (p_priv->cflag & PARENB) {
2199 /* note USA_PARITY_NONE == 0 */
2200 msg.lcr |= (p_priv->cflag & PARODD) ?
2201 USA_PARITY_ODD : USA_PARITY_EVEN;
2205 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2206 msg.xonFlowControl = 0;
2207 msg.setFlowControl = 0xff;
2208 msg.forwardingLength = 16;
2212 if (reset_port == 1) {
2222 msg.returnStatus = 0;
2223 msg.resetDataToggle = 0xff;
2224 } else if (reset_port == 2) {
2234 msg.returnStatus = 0;
2235 msg.resetDataToggle = 0;
2237 /* Sending intermediate configs */
2238 msg._txOn = (!p_priv->break_on);
2241 msg.txBreak = (p_priv->break_on);
2246 msg.returnStatus = 0;
2247 msg.resetDataToggle = 0x0;
2250 /* Do handshaking outputs */
2251 msg.setTxTriState_setRts = 0xff;
2252 msg.txTriState_rts = p_priv->rts_state;
2254 msg.setHskoa_setDtr = 0xff;
2255 msg.hskoa_dtr = p_priv->dtr_state;
2257 p_priv->resend_cont = 0;
2259 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2261 /* send the data out the device on control endpoint */
2262 this_urb->transfer_buffer_length = sizeof(msg);
2264 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2266 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2270 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2272 struct usb_serial *serial = port->serial;
2273 struct keyspan_serial_private *s_priv;
2274 const struct keyspan_device_details *d_details;
2276 s_priv = usb_get_serial_data(serial);
2277 d_details = s_priv->device_details;
2279 switch (d_details->msg_format) {
2281 keyspan_usa26_send_setup(serial, port, reset_port);
2284 keyspan_usa28_send_setup(serial, port, reset_port);
2287 keyspan_usa49_send_setup(serial, port, reset_port);
2290 keyspan_usa90_send_setup(serial, port, reset_port);
2293 keyspan_usa67_send_setup(serial, port, reset_port);
2299 /* Gets called by the "real" driver (ie once firmware is loaded
2300 and renumeration has taken place. */
2301 static int keyspan_startup(struct usb_serial *serial)
2304 struct keyspan_serial_private *s_priv;
2305 const struct keyspan_device_details *d_details;
2307 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2308 if (d_details->product_id ==
2309 le16_to_cpu(serial->dev->descriptor.idProduct))
2311 if (d_details == NULL) {
2312 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2313 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2317 /* Setup private data for serial driver */
2318 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2322 s_priv->instat_buf = kzalloc(INSTAT_BUFLEN, GFP_KERNEL);
2323 if (!s_priv->instat_buf)
2324 goto err_instat_buf;
2326 s_priv->indat_buf = kzalloc(INDAT49W_BUFLEN, GFP_KERNEL);
2327 if (!s_priv->indat_buf)
2330 s_priv->glocont_buf = kzalloc(GLOCONT_BUFLEN, GFP_KERNEL);
2331 if (!s_priv->glocont_buf)
2332 goto err_glocont_buf;
2334 s_priv->ctrl_buf = kzalloc(sizeof(struct usb_ctrlrequest), GFP_KERNEL);
2335 if (!s_priv->ctrl_buf)
2338 s_priv->device_details = d_details;
2339 usb_set_serial_data(serial, s_priv);
2341 keyspan_setup_urbs(serial);
2343 if (s_priv->instat_urb != NULL) {
2344 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2346 dev_dbg(&serial->dev->dev, "%s - submit instat urb failed %d\n", __func__, err);
2348 if (s_priv->indat_urb != NULL) {
2349 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2351 dev_dbg(&serial->dev->dev, "%s - submit indat urb failed %d\n", __func__, err);
2357 kfree(s_priv->glocont_buf);
2359 kfree(s_priv->indat_buf);
2361 kfree(s_priv->instat_buf);
2368 static void keyspan_disconnect(struct usb_serial *serial)
2370 struct keyspan_serial_private *s_priv;
2372 s_priv = usb_get_serial_data(serial);
2374 usb_kill_urb(s_priv->instat_urb);
2375 usb_kill_urb(s_priv->glocont_urb);
2376 usb_kill_urb(s_priv->indat_urb);
2379 static void keyspan_release(struct usb_serial *serial)
2381 struct keyspan_serial_private *s_priv;
2383 s_priv = usb_get_serial_data(serial);
2385 /* Make sure to unlink the URBs submitted in attach. */
2386 usb_kill_urb(s_priv->instat_urb);
2387 usb_kill_urb(s_priv->indat_urb);
2389 usb_free_urb(s_priv->instat_urb);
2390 usb_free_urb(s_priv->indat_urb);
2391 usb_free_urb(s_priv->glocont_urb);
2393 kfree(s_priv->ctrl_buf);
2394 kfree(s_priv->glocont_buf);
2395 kfree(s_priv->indat_buf);
2396 kfree(s_priv->instat_buf);
2401 static int keyspan_port_probe(struct usb_serial_port *port)
2403 struct usb_serial *serial = port->serial;
2404 struct keyspan_serial_private *s_priv;
2405 struct keyspan_port_private *p_priv;
2406 const struct keyspan_device_details *d_details;
2407 struct callbacks *cback;
2412 s_priv = usb_get_serial_data(serial);
2413 d_details = s_priv->device_details;
2415 p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL);
2419 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i) {
2420 p_priv->in_buffer[i] = kzalloc(IN_BUFLEN, GFP_KERNEL);
2421 if (!p_priv->in_buffer[i])
2422 goto err_free_in_buffer;
2425 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i) {
2426 p_priv->out_buffer[i] = kzalloc(OUT_BUFLEN, GFP_KERNEL);
2427 if (!p_priv->out_buffer[i])
2428 goto err_free_out_buffer;
2431 p_priv->inack_buffer = kzalloc(INACK_BUFLEN, GFP_KERNEL);
2432 if (!p_priv->inack_buffer)
2433 goto err_free_out_buffer;
2435 p_priv->outcont_buffer = kzalloc(OUTCONT_BUFLEN, GFP_KERNEL);
2436 if (!p_priv->outcont_buffer)
2437 goto err_free_inack_buffer;
2439 p_priv->device_details = d_details;
2441 /* Setup values for the various callback routines */
2442 cback = &keyspan_callbacks[d_details->msg_format];
2444 port_num = port->port_number;
2446 /* Do indat endpoints first, once for each flip */
2447 endp = d_details->indat_endpoints[port_num];
2448 for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) {
2449 p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp,
2451 p_priv->in_buffer[i],
2453 cback->indat_callback);
2455 /* outdat endpoints also have flip */
2456 endp = d_details->outdat_endpoints[port_num];
2457 for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) {
2458 p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp,
2460 p_priv->out_buffer[i],
2462 cback->outdat_callback);
2464 /* inack endpoint */
2465 p_priv->inack_urb = keyspan_setup_urb(serial,
2466 d_details->inack_endpoints[port_num],
2468 p_priv->inack_buffer,
2470 cback->inack_callback);
2471 /* outcont endpoint */
2472 p_priv->outcont_urb = keyspan_setup_urb(serial,
2473 d_details->outcont_endpoints[port_num],
2475 p_priv->outcont_buffer,
2477 cback->outcont_callback);
2479 usb_set_serial_port_data(port, p_priv);
2483 err_free_inack_buffer:
2484 kfree(p_priv->inack_buffer);
2485 err_free_out_buffer:
2486 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
2487 kfree(p_priv->out_buffer[i]);
2489 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
2490 kfree(p_priv->in_buffer[i]);
2496 static int keyspan_port_remove(struct usb_serial_port *port)
2498 struct keyspan_port_private *p_priv;
2501 p_priv = usb_get_serial_port_data(port);
2503 usb_kill_urb(p_priv->inack_urb);
2504 usb_kill_urb(p_priv->outcont_urb);
2505 for (i = 0; i < 2; i++) {
2506 usb_kill_urb(p_priv->in_urbs[i]);
2507 usb_kill_urb(p_priv->out_urbs[i]);
2510 usb_free_urb(p_priv->inack_urb);
2511 usb_free_urb(p_priv->outcont_urb);
2512 for (i = 0; i < 2; i++) {
2513 usb_free_urb(p_priv->in_urbs[i]);
2514 usb_free_urb(p_priv->out_urbs[i]);
2517 kfree(p_priv->outcont_buffer);
2518 kfree(p_priv->inack_buffer);
2519 for (i = 0; i < ARRAY_SIZE(p_priv->out_buffer); ++i)
2520 kfree(p_priv->out_buffer[i]);
2521 for (i = 0; i < ARRAY_SIZE(p_priv->in_buffer); ++i)
2522 kfree(p_priv->in_buffer[i]);
2529 MODULE_AUTHOR(DRIVER_AUTHOR);
2530 MODULE_DESCRIPTION(DRIVER_DESC);
2531 MODULE_LICENSE("GPL");