2 Keyspan USB to Serial Converter driver
4 (C) Copyright (C) 2000-2001 Hugh Blemings <hugh@blemings.org>
5 (C) Copyright (C) 2002 Greg Kroah-Hartman <greg@kroah.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 See http://blemings.org/hugh/keyspan.html for more information.
14 Code in this driver inspired by and in a number of places taken
15 from Brian Warner's original Keyspan-PDA driver.
17 This driver has been put together with the support of Innosys, Inc.
18 and Keyspan, Inc the manufacturers of the Keyspan USB-serial products.
21 Thanks to Paulus for miscellaneous tidy ups, some largish chunks
22 of much nicer and/or completely new code and (perhaps most uniquely)
23 having the patience to sit down and explain why and where he'd changed
26 Tip 'o the hat to IBM (and previously Linuxcare :) for supporting
27 staff in their work on open source projects.
31 #include <linux/kernel.h>
32 #include <linux/jiffies.h>
33 #include <linux/errno.h>
34 #include <linux/init.h>
35 #include <linux/slab.h>
36 #include <linux/tty.h>
37 #include <linux/tty_driver.h>
38 #include <linux/tty_flip.h>
39 #include <linux/module.h>
40 #include <linux/spinlock.h>
41 #include <linux/uaccess.h>
42 #include <linux/usb.h>
43 #include <linux/usb/serial.h>
44 #include <linux/usb/ezusb.h>
47 #define DRIVER_AUTHOR "Hugh Blemings <hugh@misc.nu"
48 #define DRIVER_DESC "Keyspan USB to Serial Converter Driver"
50 #define INSTAT_BUFLEN 32
51 #define GLOCONT_BUFLEN 64
52 #define INDAT49W_BUFLEN 512
54 /* Per device and per port private data */
55 struct keyspan_serial_private {
56 const struct keyspan_device_details *device_details;
58 struct urb *instat_urb;
59 char instat_buf[INSTAT_BUFLEN];
61 /* added to support 49wg, where data from all 4 ports comes in
62 on 1 EP and high-speed supported */
63 struct urb *indat_urb;
64 char indat_buf[INDAT49W_BUFLEN];
66 /* XXX this one probably will need a lock */
67 struct urb *glocont_urb;
68 char glocont_buf[GLOCONT_BUFLEN];
69 char ctrl_buf[8]; /* for EP0 control message */
72 struct keyspan_port_private {
73 /* Keep track of which input & output endpoints to use */
77 /* Keep duplicate of device details in each port
78 structure as well - simplifies some of the
79 callback functions etc. */
80 const struct keyspan_device_details *device_details;
82 /* Input endpoints and buffer for this port */
83 struct urb *in_urbs[2];
84 char in_buffer[2][64];
85 /* Output endpoints and buffer for this port */
86 struct urb *out_urbs[2];
87 char out_buffer[2][64];
89 /* Input ack endpoint */
90 struct urb *inack_urb;
93 /* Output control endpoint */
94 struct urb *outcont_urb;
95 char outcont_buffer[64];
97 /* Settings for the port */
101 unsigned int old_cflag;
102 enum {flow_none, flow_cts, flow_xon} flow_control;
103 int rts_state; /* Handshaking pins (outputs) */
105 int cts_state; /* Handshaking pins (inputs) */
111 unsigned long tx_start_time[2];
112 int resend_cont; /* need to resend control packet */
115 /* Include Keyspan message headers. All current Keyspan Adapters
116 make use of one of five message formats which are referred
117 to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and
118 within this driver. */
119 #include "keyspan_usa26msg.h"
120 #include "keyspan_usa28msg.h"
121 #include "keyspan_usa49msg.h"
122 #include "keyspan_usa90msg.h"
123 #include "keyspan_usa67msg.h"
126 module_usb_serial_driver(serial_drivers, keyspan_ids_combined);
128 static void keyspan_break_ctl(struct tty_struct *tty, int break_state)
130 struct usb_serial_port *port = tty->driver_data;
131 struct keyspan_port_private *p_priv;
133 p_priv = usb_get_serial_port_data(port);
135 if (break_state == -1)
136 p_priv->break_on = 1;
138 p_priv->break_on = 0;
140 keyspan_send_setup(port, 0);
144 static void keyspan_set_termios(struct tty_struct *tty,
145 struct usb_serial_port *port, struct ktermios *old_termios)
147 int baud_rate, device_port;
148 struct keyspan_port_private *p_priv;
149 const struct keyspan_device_details *d_details;
152 p_priv = usb_get_serial_port_data(port);
153 d_details = p_priv->device_details;
154 cflag = tty->termios.c_cflag;
155 device_port = port->number - port->serial->minor;
157 /* Baud rate calculation takes baud rate as an integer
158 so other rates can be generated if desired. */
159 baud_rate = tty_get_baud_rate(tty);
160 /* If no match or invalid, don't change */
161 if (d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
162 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
163 /* FIXME - more to do here to ensure rate changes cleanly */
164 /* FIXME - calcuate exact rate from divisor ? */
165 p_priv->baud = baud_rate;
167 baud_rate = tty_termios_baud_rate(old_termios);
169 tty_encode_baud_rate(tty, baud_rate, baud_rate);
170 /* set CTS/RTS handshake etc. */
171 p_priv->cflag = cflag;
172 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
174 /* Mark/Space not supported */
175 tty->termios.c_cflag &= ~CMSPAR;
177 keyspan_send_setup(port, 0);
180 static int keyspan_tiocmget(struct tty_struct *tty)
182 struct usb_serial_port *port = tty->driver_data;
183 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
186 value = ((p_priv->rts_state) ? TIOCM_RTS : 0) |
187 ((p_priv->dtr_state) ? TIOCM_DTR : 0) |
188 ((p_priv->cts_state) ? TIOCM_CTS : 0) |
189 ((p_priv->dsr_state) ? TIOCM_DSR : 0) |
190 ((p_priv->dcd_state) ? TIOCM_CAR : 0) |
191 ((p_priv->ri_state) ? TIOCM_RNG : 0);
196 static int keyspan_tiocmset(struct tty_struct *tty,
197 unsigned int set, unsigned int clear)
199 struct usb_serial_port *port = tty->driver_data;
200 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
203 p_priv->rts_state = 1;
205 p_priv->dtr_state = 1;
206 if (clear & TIOCM_RTS)
207 p_priv->rts_state = 0;
208 if (clear & TIOCM_DTR)
209 p_priv->dtr_state = 0;
210 keyspan_send_setup(port, 0);
214 /* Write function is similar for the four protocols used
215 with only a minor change for usa90 (usa19hs) required */
216 static int keyspan_write(struct tty_struct *tty,
217 struct usb_serial_port *port, const unsigned char *buf, int count)
219 struct keyspan_port_private *p_priv;
220 const struct keyspan_device_details *d_details;
223 struct urb *this_urb;
224 int err, maxDataLen, dataOffset;
226 p_priv = usb_get_serial_port_data(port);
227 d_details = p_priv->device_details;
229 if (d_details->msg_format == msg_usa90) {
237 dev_dbg(&port->dev, "%s - for port %d (%d chars), flip=%d\n",
238 __func__, port->number, count, p_priv->out_flip);
240 for (left = count; left > 0; left -= todo) {
242 if (todo > maxDataLen)
245 flip = p_priv->out_flip;
247 /* Check we have a valid urb/endpoint before we use it... */
248 this_urb = p_priv->out_urbs[flip];
249 if (this_urb == NULL) {
250 /* no bulk out, so return 0 bytes written */
251 dev_dbg(&port->dev, "%s - no output urb :(\n", __func__);
255 dev_dbg(&port->dev, "%s - endpoint %d flip %d\n",
256 __func__, usb_pipeendpoint(this_urb->pipe), flip);
258 if (this_urb->status == -EINPROGRESS) {
259 if (time_before(jiffies,
260 p_priv->tx_start_time[flip] + 10 * HZ))
262 usb_unlink_urb(this_urb);
266 /* First byte in buffer is "last flag" (except for usa19hx)
267 - unused so for now so set to zero */
268 ((char *)this_urb->transfer_buffer)[0] = 0;
270 memcpy(this_urb->transfer_buffer + dataOffset, buf, todo);
273 /* send the data out the bulk port */
274 this_urb->transfer_buffer_length = todo + dataOffset;
276 err = usb_submit_urb(this_urb, GFP_ATOMIC);
278 dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed (%d)\n", err);
279 p_priv->tx_start_time[flip] = jiffies;
281 /* Flip for next time if usa26 or usa28 interface
282 (not used on usa49) */
283 p_priv->out_flip = (flip + 1) & d_details->outdat_endp_flip;
289 static void usa26_indat_callback(struct urb *urb)
293 struct usb_serial_port *port;
294 unsigned char *data = urb->transfer_buffer;
295 int status = urb->status;
297 endpoint = usb_pipeendpoint(urb->pipe);
300 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
301 __func__, status, endpoint);
306 if (urb->actual_length) {
307 /* 0x80 bit is error flag */
308 if ((data[0] & 0x80) == 0) {
309 /* no errors on individual bytes, only
310 possible overrun err */
311 if (data[0] & RXERROR_OVERRUN)
315 for (i = 1; i < urb->actual_length ; ++i)
316 tty_insert_flip_char(&port->port, data[i], err);
318 /* some bytes had errors, every byte has status */
319 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
320 for (i = 0; i + 1 < urb->actual_length; i += 2) {
321 int stat = data[i], flag = 0;
322 if (stat & RXERROR_OVERRUN)
324 if (stat & RXERROR_FRAMING)
326 if (stat & RXERROR_PARITY)
328 /* XXX should handle break (0x10) */
329 tty_insert_flip_char(&port->port, data[i+1],
333 tty_flip_buffer_push(&port->port);
336 /* Resubmit urb so we continue receiving */
337 err = usb_submit_urb(urb, GFP_ATOMIC);
339 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
342 /* Outdat handling is common for all devices */
343 static void usa2x_outdat_callback(struct urb *urb)
345 struct usb_serial_port *port;
346 struct keyspan_port_private *p_priv;
349 p_priv = usb_get_serial_port_data(port);
350 dev_dbg(&port->dev, "%s - urb %d\n", __func__, urb == p_priv->out_urbs[1]);
352 usb_serial_port_softint(port);
355 static void usa26_inack_callback(struct urb *urb)
359 static void usa26_outcont_callback(struct urb *urb)
361 struct usb_serial_port *port;
362 struct keyspan_port_private *p_priv;
365 p_priv = usb_get_serial_port_data(port);
367 if (p_priv->resend_cont) {
368 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
369 keyspan_usa26_send_setup(port->serial, port,
370 p_priv->resend_cont - 1);
374 static void usa26_instat_callback(struct urb *urb)
376 unsigned char *data = urb->transfer_buffer;
377 struct keyspan_usa26_portStatusMessage *msg;
378 struct usb_serial *serial;
379 struct usb_serial_port *port;
380 struct keyspan_port_private *p_priv;
381 int old_dcd_state, err;
382 int status = urb->status;
384 serial = urb->context;
387 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
390 if (urb->actual_length != 9) {
391 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
395 msg = (struct keyspan_usa26_portStatusMessage *)data;
398 dev_dbg(&urb->dev->dev,
399 "%s - port status: port %d cts %d dcd %d dsr %d ri %d toff %d txoff %d rxen %d cr %d",
400 __func__, msg->port, msg->hskia_cts, msg->gpia_dcd, msg->dsr,
401 msg->ri, msg->_txOff, msg->_txXoff, msg->rxEnabled,
402 msg->controlResponse);
405 /* Now do something useful with the data */
408 /* Check port number from message and retrieve private data */
409 if (msg->port >= serial->num_ports) {
410 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
413 port = serial->port[msg->port];
414 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);
524 dev_dbg(&urb->dev->dev,
525 "%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__,
526 data[0], data[1], data[2], data[3], data[4], data[5],
527 data[6], data[7], data[8], data[9], data[10], data[11]);
530 /* Now do something useful with the data */
531 msg = (struct keyspan_usa28_portStatusMessage *)data;
533 /* Check port number from message and retrieve private data */
534 if (msg->port >= serial->num_ports) {
535 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
538 port = serial->port[msg->port];
539 p_priv = usb_get_serial_port_data(port);
541 /* Update handshaking pin state information */
542 old_dcd_state = p_priv->dcd_state;
543 p_priv->cts_state = ((msg->cts) ? 1 : 0);
544 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
545 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
546 p_priv->ri_state = ((msg->ri) ? 1 : 0);
548 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
549 tty_port_tty_hangup(&port->port, true);
551 /* Resubmit urb so we continue receiving */
552 err = usb_submit_urb(urb, GFP_ATOMIC);
554 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
558 static void usa28_glocont_callback(struct urb *urb)
563 static void usa49_glocont_callback(struct urb *urb)
565 struct usb_serial *serial;
566 struct usb_serial_port *port;
567 struct keyspan_port_private *p_priv;
570 serial = urb->context;
571 for (i = 0; i < serial->num_ports; ++i) {
572 port = serial->port[i];
573 p_priv = usb_get_serial_port_data(port);
575 if (p_priv->resend_cont) {
576 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
577 keyspan_usa49_send_setup(serial, port,
578 p_priv->resend_cont - 1);
584 /* This is actually called glostat in the Keyspan
586 static void usa49_instat_callback(struct urb *urb)
589 unsigned char *data = urb->transfer_buffer;
590 struct keyspan_usa49_portStatusMessage *msg;
591 struct usb_serial *serial;
592 struct usb_serial_port *port;
593 struct keyspan_port_private *p_priv;
595 int status = urb->status;
597 serial = urb->context;
600 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
604 if (urb->actual_length !=
605 sizeof(struct keyspan_usa49_portStatusMessage)) {
606 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
611 dev_dbg(&urb->dev->dev, "%s: %x %x %x %x %x %x %x %x %x %x %x",
612 __func__, data[0], data[1], data[2], data[3], data[4],
613 data[5], data[6], data[7], data[8], data[9], data[10]);
616 /* Now do something useful with the data */
617 msg = (struct keyspan_usa49_portStatusMessage *)data;
619 /* Check port number from message and retrieve private data */
620 if (msg->portNumber >= serial->num_ports) {
621 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
622 __func__, msg->portNumber);
625 port = serial->port[msg->portNumber];
626 p_priv = usb_get_serial_port_data(port);
628 /* Update handshaking pin state information */
629 old_dcd_state = p_priv->dcd_state;
630 p_priv->cts_state = ((msg->cts) ? 1 : 0);
631 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
632 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
633 p_priv->ri_state = ((msg->ri) ? 1 : 0);
635 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
636 tty_port_tty_hangup(&port->port, true);
638 /* Resubmit urb so we continue receiving */
639 err = usb_submit_urb(urb, GFP_ATOMIC);
641 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
645 static void usa49_inack_callback(struct urb *urb)
649 static void usa49_indat_callback(struct urb *urb)
653 struct usb_serial_port *port;
654 unsigned char *data = urb->transfer_buffer;
655 int status = urb->status;
657 endpoint = usb_pipeendpoint(urb->pipe);
660 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
661 __func__, status, endpoint);
666 if (urb->actual_length) {
667 /* 0x80 bit is error flag */
668 if ((data[0] & 0x80) == 0) {
669 /* no error on any byte */
670 tty_insert_flip_string(&port->port, data + 1,
671 urb->actual_length - 1);
673 /* some bytes had errors, every byte has status */
674 for (i = 0; i + 1 < urb->actual_length; i += 2) {
675 int stat = data[i], flag = 0;
676 if (stat & RXERROR_OVERRUN)
678 if (stat & RXERROR_FRAMING)
680 if (stat & RXERROR_PARITY)
682 /* XXX should handle break (0x10) */
683 tty_insert_flip_char(&port->port, data[i+1],
687 tty_flip_buffer_push(&port->port);
690 /* Resubmit urb so we continue receiving */
691 err = usb_submit_urb(urb, GFP_ATOMIC);
693 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
696 static void usa49wg_indat_callback(struct urb *urb)
699 struct usb_serial *serial;
700 struct usb_serial_port *port;
701 unsigned char *data = urb->transfer_buffer;
702 int status = urb->status;
704 serial = urb->context;
707 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
711 /* inbound data is in the form P#, len, status, data */
715 if (urb->actual_length) {
716 while (i < urb->actual_length) {
718 /* Check port number from message*/
719 if (data[i] >= serial->num_ports) {
720 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
724 port = serial->port[data[i++]];
727 /* 0x80 bit is error flag */
728 if ((data[i] & 0x80) == 0) {
729 /* no error on any byte */
731 for (x = 1; x < len ; ++x)
732 tty_insert_flip_char(&port->port,
736 * some bytes had errors, every byte has status
738 for (x = 0; x + 1 < len; x += 2) {
739 int stat = data[i], flag = 0;
740 if (stat & RXERROR_OVERRUN)
742 if (stat & RXERROR_FRAMING)
744 if (stat & RXERROR_PARITY)
746 /* XXX should handle break (0x10) */
747 tty_insert_flip_char(&port->port,
752 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)
803 for (i = 1; i < urb->actual_length ; ++i)
804 tty_insert_flip_char(&port->port,
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) {
810 int stat = data[i], flag = 0;
811 if (stat & RXERROR_OVERRUN)
813 if (stat & RXERROR_FRAMING)
815 if (stat & RXERROR_PARITY)
817 /* XXX should handle break (0x10) */
818 tty_insert_flip_char(&port->port,
823 tty_flip_buffer_push(&port->port);
826 /* Resubmit urb so we continue receiving */
827 err = usb_submit_urb(urb, GFP_ATOMIC);
829 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
833 static void usa90_instat_callback(struct urb *urb)
835 unsigned char *data = urb->transfer_buffer;
836 struct keyspan_usa90_portStatusMessage *msg;
837 struct usb_serial *serial;
838 struct usb_serial_port *port;
839 struct keyspan_port_private *p_priv;
840 int old_dcd_state, err;
841 int status = urb->status;
843 serial = urb->context;
846 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
849 if (urb->actual_length < 14) {
850 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
854 msg = (struct keyspan_usa90_portStatusMessage *)data;
856 /* Now do something useful with the data */
858 port = serial->port[0];
859 p_priv = usb_get_serial_port_data(port);
861 /* Update handshaking pin state information */
862 old_dcd_state = p_priv->dcd_state;
863 p_priv->cts_state = ((msg->cts) ? 1 : 0);
864 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
865 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
866 p_priv->ri_state = ((msg->ri) ? 1 : 0);
868 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
869 tty_port_tty_hangup(&port->port, true);
871 /* Resubmit urb so we continue receiving */
872 err = usb_submit_urb(urb, GFP_ATOMIC);
874 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
879 static void usa90_outcont_callback(struct urb *urb)
881 struct usb_serial_port *port;
882 struct keyspan_port_private *p_priv;
885 p_priv = usb_get_serial_port_data(port);
887 if (p_priv->resend_cont) {
888 dev_dbg(&urb->dev->dev, "%s - sending setup\n", __func__);
889 keyspan_usa90_send_setup(port->serial, port,
890 p_priv->resend_cont - 1);
894 /* Status messages from the 28xg */
895 static void usa67_instat_callback(struct urb *urb)
898 unsigned char *data = urb->transfer_buffer;
899 struct keyspan_usa67_portStatusMessage *msg;
900 struct usb_serial *serial;
901 struct usb_serial_port *port;
902 struct keyspan_port_private *p_priv;
904 int status = urb->status;
906 serial = urb->context;
909 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
913 if (urb->actual_length !=
914 sizeof(struct keyspan_usa67_portStatusMessage)) {
915 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
920 /* Now do something useful with the data */
921 msg = (struct keyspan_usa67_portStatusMessage *)data;
923 /* Check port number from message and retrieve private data */
924 if (msg->port >= serial->num_ports) {
925 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
929 port = serial->port[msg->port];
930 p_priv = usb_get_serial_port_data(port);
932 /* Update handshaking pin state information */
933 old_dcd_state = p_priv->dcd_state;
934 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
935 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
937 if (old_dcd_state != p_priv->dcd_state && old_dcd_state)
938 tty_port_tty_hangup(&port->port, true);
940 /* Resubmit urb so we continue receiving */
941 err = usb_submit_urb(urb, GFP_ATOMIC);
943 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
946 static void usa67_glocont_callback(struct urb *urb)
948 struct usb_serial *serial;
949 struct usb_serial_port *port;
950 struct keyspan_port_private *p_priv;
953 serial = urb->context;
954 for (i = 0; i < serial->num_ports; ++i) {
955 port = serial->port[i];
956 p_priv = usb_get_serial_port_data(port);
958 if (p_priv->resend_cont) {
959 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
960 keyspan_usa67_send_setup(serial, port,
961 p_priv->resend_cont - 1);
967 static int keyspan_write_room(struct tty_struct *tty)
969 struct usb_serial_port *port = tty->driver_data;
970 struct keyspan_port_private *p_priv;
971 const struct keyspan_device_details *d_details;
974 struct urb *this_urb;
976 p_priv = usb_get_serial_port_data(port);
977 d_details = p_priv->device_details;
980 if (d_details->msg_format == msg_usa90)
985 flip = p_priv->out_flip;
987 /* Check both endpoints to see if any are available. */
988 this_urb = p_priv->out_urbs[flip];
989 if (this_urb != NULL) {
990 if (this_urb->status != -EINPROGRESS)
992 flip = (flip + 1) & d_details->outdat_endp_flip;
993 this_urb = p_priv->out_urbs[flip];
994 if (this_urb != NULL) {
995 if (this_urb->status != -EINPROGRESS)
1003 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1005 struct keyspan_port_private *p_priv;
1006 const struct keyspan_device_details *d_details;
1008 int baud_rate, device_port;
1010 unsigned int cflag = 0;
1012 p_priv = usb_get_serial_port_data(port);
1013 d_details = p_priv->device_details;
1015 /* Set some sane defaults */
1016 p_priv->rts_state = 1;
1017 p_priv->dtr_state = 1;
1018 p_priv->baud = 9600;
1020 /* force baud and lcr to be set on open */
1021 p_priv->old_baud = 0;
1022 p_priv->old_cflag = 0;
1024 p_priv->out_flip = 0;
1025 p_priv->in_flip = 0;
1027 /* Reset low level data toggle and start reading from endpoints */
1028 for (i = 0; i < 2; i++) {
1029 urb = p_priv->in_urbs[i];
1033 /* make sure endpoint data toggle is synchronized
1035 usb_clear_halt(urb->dev, urb->pipe);
1036 err = usb_submit_urb(urb, GFP_KERNEL);
1038 dev_dbg(&port->dev, "%s - submit urb %d failed (%d)\n", __func__, i, err);
1041 /* Reset low level data toggle on out endpoints */
1042 for (i = 0; i < 2; i++) {
1043 urb = p_priv->out_urbs[i];
1046 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1047 usb_pipeout(urb->pipe), 0); */
1050 /* get the terminal config for the setup message now so we don't
1051 * need to send 2 of them */
1053 device_port = port->number - port->serial->minor;
1055 cflag = tty->termios.c_cflag;
1056 /* Baud rate calculation takes baud rate as an integer
1057 so other rates can be generated if desired. */
1058 baud_rate = tty_get_baud_rate(tty);
1059 /* If no match or invalid, leave as default */
1061 && d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
1062 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1063 p_priv->baud = baud_rate;
1066 /* set CTS/RTS handshake etc. */
1067 p_priv->cflag = cflag;
1068 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
1070 keyspan_send_setup(port, 1);
1072 /* keyspan_set_termios(port, NULL); */
1077 static inline void stop_urb(struct urb *urb)
1079 if (urb && urb->status == -EINPROGRESS)
1083 static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1085 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
1087 p_priv->rts_state = on;
1088 p_priv->dtr_state = on;
1089 keyspan_send_setup(port, 0);
1092 static void keyspan_close(struct usb_serial_port *port)
1095 struct usb_serial *serial = port->serial;
1096 struct keyspan_port_private *p_priv;
1098 p_priv = usb_get_serial_port_data(port);
1100 p_priv->rts_state = 0;
1101 p_priv->dtr_state = 0;
1104 keyspan_send_setup(port, 2);
1105 /* pilot-xfer seems to work best with this delay */
1107 /* keyspan_set_termios(port, NULL); */
1110 /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
1111 dev_dbg(&port->dev, "%s - urb in progress\n", __func__);
1114 p_priv->out_flip = 0;
1115 p_priv->in_flip = 0;
1118 /* Stop reading/writing urbs */
1119 stop_urb(p_priv->inack_urb);
1120 /* stop_urb(p_priv->outcont_urb); */
1121 for (i = 0; i < 2; i++) {
1122 stop_urb(p_priv->in_urbs[i]);
1123 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 = "keyspan/usa28.fw";
1149 case keyspan_usa28x_pre_product_id:
1150 fw_name = "keyspan/usa28x.fw";
1153 case keyspan_usa28xa_pre_product_id:
1154 fw_name = "keyspan/usa28xa.fw";
1157 case keyspan_usa28xb_pre_product_id:
1158 fw_name = "keyspan/usa28xb.fw";
1161 case keyspan_usa19_pre_product_id:
1162 fw_name = "keyspan/usa19.fw";
1165 case keyspan_usa19qi_pre_product_id:
1166 fw_name = "keyspan/usa19qi.fw";
1169 case keyspan_mpr_pre_product_id:
1170 fw_name = "keyspan/mpr.fw";
1173 case keyspan_usa19qw_pre_product_id:
1174 fw_name = "keyspan/usa19qw.fw";
1177 case keyspan_usa18x_pre_product_id:
1178 fw_name = "keyspan/usa18x.fw";
1181 case keyspan_usa19w_pre_product_id:
1182 fw_name = "keyspan/usa19w.fw";
1185 case keyspan_usa49w_pre_product_id:
1186 fw_name = "keyspan/usa49w.fw";
1189 case keyspan_usa49wlc_pre_product_id:
1190 fw_name = "keyspan/usa49wlc.fw";
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 */
1247 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d failed.\n", __func__, endpoint);
1251 if (endpoint == 0) {
1252 /* control EP filled in when used */
1256 ep_desc = find_ep(serial, endpoint);
1258 /* leak the urb, something's wrong and the callers don't care */
1261 if (usb_endpoint_xfer_int(ep_desc)) {
1262 ep_type_name = "INT";
1263 usb_fill_int_urb(urb, serial->dev,
1264 usb_sndintpipe(serial->dev, endpoint) | dir,
1265 buf, len, callback, ctx,
1266 ep_desc->bInterval);
1267 } else if (usb_endpoint_xfer_bulk(ep_desc)) {
1268 ep_type_name = "BULK";
1269 usb_fill_bulk_urb(urb, serial->dev,
1270 usb_sndbulkpipe(serial->dev, endpoint) | dir,
1271 buf, len, callback, ctx);
1273 dev_warn(&serial->interface->dev,
1274 "unsupported endpoint type %x\n",
1275 usb_endpoint_type(ep_desc));
1280 dev_dbg(&serial->interface->dev, "%s - using urb %p for %s endpoint %x\n",
1281 __func__, urb, ep_type_name, endpoint);
1285 static struct callbacks {
1286 void (*instat_callback)(struct urb *);
1287 void (*glocont_callback)(struct urb *);
1288 void (*indat_callback)(struct urb *);
1289 void (*outdat_callback)(struct urb *);
1290 void (*inack_callback)(struct urb *);
1291 void (*outcont_callback)(struct urb *);
1292 } keyspan_callbacks[] = {
1294 /* msg_usa26 callbacks */
1295 .instat_callback = usa26_instat_callback,
1296 .glocont_callback = usa26_glocont_callback,
1297 .indat_callback = usa26_indat_callback,
1298 .outdat_callback = usa2x_outdat_callback,
1299 .inack_callback = usa26_inack_callback,
1300 .outcont_callback = usa26_outcont_callback,
1302 /* msg_usa28 callbacks */
1303 .instat_callback = usa28_instat_callback,
1304 .glocont_callback = usa28_glocont_callback,
1305 .indat_callback = usa28_indat_callback,
1306 .outdat_callback = usa2x_outdat_callback,
1307 .inack_callback = usa28_inack_callback,
1308 .outcont_callback = usa28_outcont_callback,
1310 /* msg_usa49 callbacks */
1311 .instat_callback = usa49_instat_callback,
1312 .glocont_callback = usa49_glocont_callback,
1313 .indat_callback = usa49_indat_callback,
1314 .outdat_callback = usa2x_outdat_callback,
1315 .inack_callback = usa49_inack_callback,
1316 .outcont_callback = usa49_outcont_callback,
1318 /* msg_usa90 callbacks */
1319 .instat_callback = usa90_instat_callback,
1320 .glocont_callback = usa28_glocont_callback,
1321 .indat_callback = usa90_indat_callback,
1322 .outdat_callback = usa2x_outdat_callback,
1323 .inack_callback = usa28_inack_callback,
1324 .outcont_callback = usa90_outcont_callback,
1326 /* msg_usa67 callbacks */
1327 .instat_callback = usa67_instat_callback,
1328 .glocont_callback = usa67_glocont_callback,
1329 .indat_callback = usa26_indat_callback,
1330 .outdat_callback = usa2x_outdat_callback,
1331 .inack_callback = usa26_inack_callback,
1332 .outcont_callback = usa26_outcont_callback,
1336 /* Generic setup urbs function that uses
1337 data in device_details */
1338 static void keyspan_setup_urbs(struct usb_serial *serial)
1340 struct keyspan_serial_private *s_priv;
1341 const struct keyspan_device_details *d_details;
1342 struct callbacks *cback;
1344 s_priv = usb_get_serial_data(serial);
1345 d_details = s_priv->device_details;
1347 /* Setup values for the various callback routines */
1348 cback = &keyspan_callbacks[d_details->msg_format];
1350 /* Allocate and set up urbs for each one that is in use,
1351 starting with instat endpoints */
1352 s_priv->instat_urb = keyspan_setup_urb
1353 (serial, d_details->instat_endpoint, USB_DIR_IN,
1354 serial, s_priv->instat_buf, INSTAT_BUFLEN,
1355 cback->instat_callback);
1357 s_priv->indat_urb = keyspan_setup_urb
1358 (serial, d_details->indat_endpoint, USB_DIR_IN,
1359 serial, s_priv->indat_buf, INDAT49W_BUFLEN,
1360 usa49wg_indat_callback);
1362 s_priv->glocont_urb = keyspan_setup_urb
1363 (serial, d_details->glocont_endpoint, USB_DIR_OUT,
1364 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1365 cback->glocont_callback);
1368 /* usa19 function doesn't require prescaler */
1369 static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
1370 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1371 u8 *rate_low, u8 *prescaler, int portnum)
1373 u32 b16, /* baud rate times 16 (actual rate used internally) */
1375 cnt; /* inverse of divisor (programmed into 8051) */
1377 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1379 /* prevent divide by zero... */
1380 b16 = baud_rate * 16L;
1382 return KEYSPAN_INVALID_BAUD_RATE;
1383 /* Any "standard" rate over 57k6 is marginal on the USA-19
1384 as we run out of divisor resolution. */
1385 if (baud_rate > 57600)
1386 return KEYSPAN_INVALID_BAUD_RATE;
1388 /* calculate the divisor and the counter (its inverse) */
1389 div = baudclk / b16;
1391 return KEYSPAN_INVALID_BAUD_RATE;
1396 return KEYSPAN_INVALID_BAUD_RATE;
1398 /* return the counter values if non-null */
1400 *rate_low = (u8) (cnt & 0xff);
1402 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1403 if (rate_low && rate_hi)
1404 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1405 __func__, baud_rate, *rate_hi, *rate_low);
1406 return KEYSPAN_BAUD_RATE_OK;
1409 /* usa19hs function doesn't require prescaler */
1410 static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
1411 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1412 u8 *rate_low, u8 *prescaler, int portnum)
1414 u32 b16, /* baud rate times 16 (actual rate used internally) */
1417 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1419 /* prevent divide by zero... */
1420 b16 = baud_rate * 16L;
1422 return KEYSPAN_INVALID_BAUD_RATE;
1424 /* calculate the divisor */
1425 div = baudclk / b16;
1427 return KEYSPAN_INVALID_BAUD_RATE;
1430 return KEYSPAN_INVALID_BAUD_RATE;
1432 /* return the counter values if non-null */
1434 *rate_low = (u8) (div & 0xff);
1437 *rate_hi = (u8) ((div >> 8) & 0xff);
1439 if (rate_low && rate_hi)
1440 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1441 __func__, baud_rate, *rate_hi, *rate_low);
1443 return KEYSPAN_BAUD_RATE_OK;
1446 static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
1447 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1448 u8 *rate_low, u8 *prescaler, int portnum)
1450 u32 b16, /* baud rate times 16 (actual rate used internally) */
1451 clk, /* clock with 13/8 prescaler */
1452 div, /* divisor using 13/8 prescaler */
1453 res, /* resulting baud rate using 13/8 prescaler */
1454 diff, /* error using 13/8 prescaler */
1459 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1461 /* prevent divide by zero */
1462 b16 = baud_rate * 16L;
1464 return KEYSPAN_INVALID_BAUD_RATE;
1466 /* Calculate prescaler by trying them all and looking
1469 /* start with largest possible difference */
1470 smallest_diff = 0xffffffff;
1472 /* 0 is an invalid prescaler, used as a flag */
1475 for (i = 8; i <= 0xff; ++i) {
1476 clk = (baudclk * 8) / (u32) i;
1483 diff = (res > b16) ? (res-b16) : (b16-res);
1485 if (diff < smallest_diff) {
1487 smallest_diff = diff;
1491 if (best_prescaler == 0)
1492 return KEYSPAN_INVALID_BAUD_RATE;
1494 clk = (baudclk * 8) / (u32) best_prescaler;
1497 /* return the divisor and prescaler if non-null */
1499 *rate_low = (u8) (div & 0xff);
1501 *rate_hi = (u8) ((div >> 8) & 0xff);
1503 *prescaler = best_prescaler;
1504 /* dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
1506 return KEYSPAN_BAUD_RATE_OK;
1509 /* USA-28 supports different maximum baud rates on each port */
1510 static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
1511 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1512 u8 *rate_low, u8 *prescaler, int portnum)
1514 u32 b16, /* baud rate times 16 (actual rate used internally) */
1516 cnt; /* inverse of divisor (programmed into 8051) */
1518 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1520 /* prevent divide by zero */
1521 b16 = baud_rate * 16L;
1523 return KEYSPAN_INVALID_BAUD_RATE;
1525 /* calculate the divisor and the counter (its inverse) */
1526 div = KEYSPAN_USA28_BAUDCLK / b16;
1528 return KEYSPAN_INVALID_BAUD_RATE;
1532 /* check for out of range, based on portnum,
1533 and return result */
1536 return KEYSPAN_INVALID_BAUD_RATE;
1540 return KEYSPAN_INVALID_BAUD_RATE;
1542 return KEYSPAN_INVALID_BAUD_RATE;
1545 /* return the counter values if not NULL
1546 (port 1 will ignore retHi) */
1548 *rate_low = (u8) (cnt & 0xff);
1550 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1551 dev_dbg(&port->dev, "%s - %d OK.\n", __func__, baud_rate);
1552 return KEYSPAN_BAUD_RATE_OK;
1555 static int keyspan_usa26_send_setup(struct usb_serial *serial,
1556 struct usb_serial_port *port,
1559 struct keyspan_usa26_portControlMessage msg;
1560 struct keyspan_serial_private *s_priv;
1561 struct keyspan_port_private *p_priv;
1562 const struct keyspan_device_details *d_details;
1564 struct urb *this_urb;
1565 int device_port, err;
1567 dev_dbg(&port->dev, "%s reset=%d\n", __func__, reset_port);
1569 s_priv = usb_get_serial_data(serial);
1570 p_priv = usb_get_serial_port_data(port);
1571 d_details = s_priv->device_details;
1572 device_port = port->number - port->serial->minor;
1574 outcont_urb = d_details->outcont_endpoints[port->number];
1575 this_urb = p_priv->outcont_urb;
1577 dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
1579 /* Make sure we have an urb then send the message */
1580 if (this_urb == NULL) {
1581 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1585 /* Save reset port val for resend.
1586 Don't overwrite resend for open/close condition. */
1587 if ((reset_port + 1) > p_priv->resend_cont)
1588 p_priv->resend_cont = reset_port + 1;
1589 if (this_urb->status == -EINPROGRESS) {
1590 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1595 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1597 /* Only set baud rate if it's changed */
1598 if (p_priv->old_baud != p_priv->baud) {
1599 p_priv->old_baud = p_priv->baud;
1600 msg.setClocking = 0xff;
1601 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1602 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1603 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1604 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1605 __func__, p_priv->baud);
1607 msg.baudHi = 125; /* Values for 9600 baud */
1610 msg.setPrescaler = 0xff;
1613 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1614 switch (p_priv->cflag & CSIZE) {
1616 msg.lcr |= USA_DATABITS_5;
1619 msg.lcr |= USA_DATABITS_6;
1622 msg.lcr |= USA_DATABITS_7;
1625 msg.lcr |= USA_DATABITS_8;
1628 if (p_priv->cflag & PARENB) {
1629 /* note USA_PARITY_NONE == 0 */
1630 msg.lcr |= (p_priv->cflag & PARODD) ?
1631 USA_PARITY_ODD : USA_PARITY_EVEN;
1635 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1636 msg.xonFlowControl = 0;
1637 msg.setFlowControl = 0xff;
1638 msg.forwardingLength = 16;
1643 if (reset_port == 1) {
1652 msg.returnStatus = 0;
1653 msg.resetDataToggle = 0xff;
1657 else if (reset_port == 2) {
1666 msg.returnStatus = 0;
1667 msg.resetDataToggle = 0;
1670 /* Sending intermediate configs */
1672 msg._txOn = (!p_priv->break_on);
1675 msg.txBreak = (p_priv->break_on);
1680 msg.returnStatus = 0;
1681 msg.resetDataToggle = 0x0;
1684 /* Do handshaking outputs */
1685 msg.setTxTriState_setRts = 0xff;
1686 msg.txTriState_rts = p_priv->rts_state;
1688 msg.setHskoa_setDtr = 0xff;
1689 msg.hskoa_dtr = p_priv->dtr_state;
1691 p_priv->resend_cont = 0;
1692 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1694 /* send the data out the device on control endpoint */
1695 this_urb->transfer_buffer_length = sizeof(msg);
1697 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1699 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1702 dev_dbg(&port->dev, "%s - usb_submit_urb(%d) OK %d bytes (end %d)\n", __func__
1703 outcont_urb, this_urb->transfer_buffer_length,
1704 usb_pipeendpoint(this_urb->pipe));
1711 static int keyspan_usa28_send_setup(struct usb_serial *serial,
1712 struct usb_serial_port *port,
1715 struct keyspan_usa28_portControlMessage msg;
1716 struct keyspan_serial_private *s_priv;
1717 struct keyspan_port_private *p_priv;
1718 const struct keyspan_device_details *d_details;
1719 struct urb *this_urb;
1720 int device_port, err;
1722 s_priv = usb_get_serial_data(serial);
1723 p_priv = usb_get_serial_port_data(port);
1724 d_details = s_priv->device_details;
1725 device_port = port->number - port->serial->minor;
1727 /* only do something if we have a bulk out endpoint */
1728 this_urb = p_priv->outcont_urb;
1729 if (this_urb == NULL) {
1730 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1734 /* Save reset port val for resend.
1735 Don't overwrite resend for open/close condition. */
1736 if ((reset_port + 1) > p_priv->resend_cont)
1737 p_priv->resend_cont = reset_port + 1;
1738 if (this_urb->status == -EINPROGRESS) {
1739 dev_dbg(&port->dev, "%s already writing\n", __func__);
1744 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
1746 msg.setBaudRate = 1;
1747 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1748 &msg.baudHi, &msg.baudLo, NULL,
1749 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1750 dev_dbg(&port->dev, "%s - Invalid baud rate requested %d.\n",
1751 __func__, p_priv->baud);
1753 msg.baudHi = 0xb2; /* Values for 9600 baud */
1756 /* If parity is enabled, we must calculate it ourselves. */
1757 msg.parity = 0; /* XXX for now */
1759 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1760 msg.xonFlowControl = 0;
1762 /* Do handshaking outputs, DTR is inverted relative to RTS */
1763 msg.rts = p_priv->rts_state;
1764 msg.dtr = p_priv->dtr_state;
1766 msg.forwardingLength = 16;
1768 msg.breakThreshold = 45;
1772 /*msg.returnStatus = 1;
1773 msg.resetDataToggle = 0xff;*/
1775 if (reset_port == 1) {
1779 msg.txForceXoff = 0;
1785 msg.returnStatus = 0;
1786 msg.resetDataToggle = 0xff;
1789 else if (reset_port == 2) {
1793 msg.txForceXoff = 0;
1799 msg.returnStatus = 0;
1800 msg.resetDataToggle = 0;
1802 /* Sending intermediate configs */
1804 msg._txOn = (!p_priv->break_on);
1807 msg.txForceXoff = 0;
1808 msg.txBreak = (p_priv->break_on);
1813 msg.returnStatus = 0;
1814 msg.resetDataToggle = 0x0;
1817 p_priv->resend_cont = 0;
1818 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1820 /* send the data out the device on control endpoint */
1821 this_urb->transfer_buffer_length = sizeof(msg);
1823 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1825 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed\n", __func__);
1828 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) OK %d bytes\n", __func__,
1829 this_urb->transfer_buffer_length);
1836 static int keyspan_usa49_send_setup(struct usb_serial *serial,
1837 struct usb_serial_port *port,
1840 struct keyspan_usa49_portControlMessage msg;
1841 struct usb_ctrlrequest *dr = NULL;
1842 struct keyspan_serial_private *s_priv;
1843 struct keyspan_port_private *p_priv;
1844 const struct keyspan_device_details *d_details;
1845 struct urb *this_urb;
1846 int err, device_port;
1848 s_priv = usb_get_serial_data(serial);
1849 p_priv = usb_get_serial_port_data(port);
1850 d_details = s_priv->device_details;
1852 this_urb = s_priv->glocont_urb;
1854 /* Work out which port within the device is being setup */
1855 device_port = port->number - port->serial->minor;
1857 /* Make sure we have an urb then send the message */
1858 if (this_urb == NULL) {
1859 dev_dbg(&port->dev, "%s - oops no urb for port %d.\n", __func__, port->number);
1863 dev_dbg(&port->dev, "%s - endpoint %d port %d (%d)\n",
1864 __func__, usb_pipeendpoint(this_urb->pipe),
1865 port->number, device_port);
1867 /* Save reset port val for resend.
1868 Don't overwrite resend for open/close condition. */
1869 if ((reset_port + 1) > p_priv->resend_cont)
1870 p_priv->resend_cont = reset_port + 1;
1872 if (this_urb->status == -EINPROGRESS) {
1873 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1878 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
1880 /*msg.portNumber = port->number;*/
1881 msg.portNumber = device_port;
1883 /* Only set baud rate if it's changed */
1884 if (p_priv->old_baud != p_priv->baud) {
1885 p_priv->old_baud = p_priv->baud;
1886 msg.setClocking = 0xff;
1887 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1888 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1889 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1890 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1891 __func__, p_priv->baud);
1893 msg.baudHi = 125; /* Values for 9600 baud */
1896 /* msg.setPrescaler = 0xff; */
1899 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1900 switch (p_priv->cflag & CSIZE) {
1902 msg.lcr |= USA_DATABITS_5;
1905 msg.lcr |= USA_DATABITS_6;
1908 msg.lcr |= USA_DATABITS_7;
1911 msg.lcr |= USA_DATABITS_8;
1914 if (p_priv->cflag & PARENB) {
1915 /* note USA_PARITY_NONE == 0 */
1916 msg.lcr |= (p_priv->cflag & PARODD) ?
1917 USA_PARITY_ODD : USA_PARITY_EVEN;
1921 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1922 msg.xonFlowControl = 0;
1923 msg.setFlowControl = 0xff;
1925 msg.forwardingLength = 16;
1930 if (reset_port == 1) {
1939 msg.returnStatus = 0;
1940 msg.resetDataToggle = 0xff;
1942 msg.disablePort = 0;
1945 else if (reset_port == 2) {
1954 msg.returnStatus = 0;
1955 msg.resetDataToggle = 0;
1957 msg.disablePort = 1;
1959 /* Sending intermediate configs */
1961 msg._txOn = (!p_priv->break_on);
1964 msg.txBreak = (p_priv->break_on);
1969 msg.returnStatus = 0;
1970 msg.resetDataToggle = 0x0;
1972 msg.disablePort = 0;
1975 /* Do handshaking outputs */
1977 msg.rts = p_priv->rts_state;
1980 msg.dtr = p_priv->dtr_state;
1982 p_priv->resend_cont = 0;
1984 /* if the device is a 49wg, we send control message on usb
1987 if (d_details->product_id == keyspan_usa49wg_product_id) {
1988 dr = (void *)(s_priv->ctrl_buf);
1989 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
1990 dr->bRequest = 0xB0; /* 49wg control message */;
1993 dr->wLength = cpu_to_le16(sizeof(msg));
1995 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
1997 usb_fill_control_urb(this_urb, serial->dev,
1998 usb_sndctrlpipe(serial->dev, 0),
1999 (unsigned char *)dr, s_priv->glocont_buf,
2000 sizeof(msg), usa49_glocont_callback, serial);
2003 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2005 /* send the data out the device on control endpoint */
2006 this_urb->transfer_buffer_length = sizeof(msg);
2008 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2010 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2013 dev_dbg(&port->dev, "%s - usb_submit_urb(%d) OK %d bytes (end %d)\n", __func__,
2014 outcont_urb, this_urb->transfer_buffer_length,
2015 usb_pipeendpoint(this_urb->pipe));
2022 static int keyspan_usa90_send_setup(struct usb_serial *serial,
2023 struct usb_serial_port *port,
2026 struct keyspan_usa90_portControlMessage msg;
2027 struct keyspan_serial_private *s_priv;
2028 struct keyspan_port_private *p_priv;
2029 const struct keyspan_device_details *d_details;
2030 struct urb *this_urb;
2034 s_priv = usb_get_serial_data(serial);
2035 p_priv = usb_get_serial_port_data(port);
2036 d_details = s_priv->device_details;
2038 /* only do something if we have a bulk out endpoint */
2039 this_urb = p_priv->outcont_urb;
2040 if (this_urb == NULL) {
2041 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
2045 /* Save reset port val for resend.
2046 Don't overwrite resend for open/close condition. */
2047 if ((reset_port + 1) > p_priv->resend_cont)
2048 p_priv->resend_cont = reset_port + 1;
2049 if (this_urb->status == -EINPROGRESS) {
2050 dev_dbg(&port->dev, "%s already writing\n", __func__);
2055 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2057 /* Only set baud rate if it's changed */
2058 if (p_priv->old_baud != p_priv->baud) {
2059 p_priv->old_baud = p_priv->baud;
2060 msg.setClocking = 0x01;
2061 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2062 &msg.baudHi, &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2063 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2064 __func__, p_priv->baud);
2065 p_priv->baud = 9600;
2066 d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2067 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2073 /* modes must always be correctly specified */
2074 if (p_priv->baud > 57600) {
2075 msg.rxMode = RXMODE_DMA;
2076 msg.txMode = TXMODE_DMA;
2078 msg.rxMode = RXMODE_BYHAND;
2079 msg.txMode = TXMODE_BYHAND;
2082 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2083 switch (p_priv->cflag & CSIZE) {
2085 msg.lcr |= USA_DATABITS_5;
2088 msg.lcr |= USA_DATABITS_6;
2091 msg.lcr |= USA_DATABITS_7;
2094 msg.lcr |= USA_DATABITS_8;
2097 if (p_priv->cflag & PARENB) {
2098 /* note USA_PARITY_NONE == 0 */
2099 msg.lcr |= (p_priv->cflag & PARODD) ?
2100 USA_PARITY_ODD : USA_PARITY_EVEN;
2102 if (p_priv->old_cflag != p_priv->cflag) {
2103 p_priv->old_cflag = p_priv->cflag;
2107 if (p_priv->flow_control == flow_cts)
2108 msg.txFlowControl = TXFLOW_CTS;
2109 msg.setTxFlowControl = 0x01;
2110 msg.setRxFlowControl = 0x01;
2112 msg.rxForwardingLength = 16;
2113 msg.rxForwardingTimeout = 16;
2114 msg.txAckSetting = 0;
2119 if (reset_port == 1) {
2120 msg.portEnabled = 1;
2122 msg.txBreak = (p_priv->break_on);
2125 else if (reset_port == 2)
2126 msg.portEnabled = 0;
2127 /* Sending intermediate configs */
2129 msg.portEnabled = 1;
2130 msg.txBreak = (p_priv->break_on);
2133 /* Do handshaking outputs */
2135 msg.rts = p_priv->rts_state;
2138 msg.dtr = p_priv->dtr_state;
2140 p_priv->resend_cont = 0;
2141 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2143 /* send the data out the device on control endpoint */
2144 this_urb->transfer_buffer_length = sizeof(msg);
2146 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2148 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2152 static int keyspan_usa67_send_setup(struct usb_serial *serial,
2153 struct usb_serial_port *port,
2156 struct keyspan_usa67_portControlMessage msg;
2157 struct keyspan_serial_private *s_priv;
2158 struct keyspan_port_private *p_priv;
2159 const struct keyspan_device_details *d_details;
2160 struct urb *this_urb;
2161 int err, device_port;
2163 s_priv = usb_get_serial_data(serial);
2164 p_priv = usb_get_serial_port_data(port);
2165 d_details = s_priv->device_details;
2167 this_urb = s_priv->glocont_urb;
2169 /* Work out which port within the device is being setup */
2170 device_port = port->number - port->serial->minor;
2172 /* Make sure we have an urb then send the message */
2173 if (this_urb == NULL) {
2174 dev_dbg(&port->dev, "%s - oops no urb for port %d.\n", __func__,
2179 /* Save reset port val for resend.
2180 Don't overwrite resend for open/close condition. */
2181 if ((reset_port + 1) > p_priv->resend_cont)
2182 p_priv->resend_cont = reset_port + 1;
2183 if (this_urb->status == -EINPROGRESS) {
2184 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2189 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
2191 msg.port = device_port;
2193 /* Only set baud rate if it's changed */
2194 if (p_priv->old_baud != p_priv->baud) {
2195 p_priv->old_baud = p_priv->baud;
2196 msg.setClocking = 0xff;
2197 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2198 &msg.baudHi, &msg.baudLo, &msg.prescaler,
2199 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2200 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2201 __func__, p_priv->baud);
2203 msg.baudHi = 125; /* Values for 9600 baud */
2206 msg.setPrescaler = 0xff;
2209 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2210 switch (p_priv->cflag & CSIZE) {
2212 msg.lcr |= USA_DATABITS_5;
2215 msg.lcr |= USA_DATABITS_6;
2218 msg.lcr |= USA_DATABITS_7;
2221 msg.lcr |= USA_DATABITS_8;
2224 if (p_priv->cflag & PARENB) {
2225 /* note USA_PARITY_NONE == 0 */
2226 msg.lcr |= (p_priv->cflag & PARODD) ?
2227 USA_PARITY_ODD : USA_PARITY_EVEN;
2231 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2232 msg.xonFlowControl = 0;
2233 msg.setFlowControl = 0xff;
2234 msg.forwardingLength = 16;
2238 if (reset_port == 1) {
2248 msg.returnStatus = 0;
2249 msg.resetDataToggle = 0xff;
2250 } else if (reset_port == 2) {
2260 msg.returnStatus = 0;
2261 msg.resetDataToggle = 0;
2263 /* Sending intermediate configs */
2264 msg._txOn = (!p_priv->break_on);
2267 msg.txBreak = (p_priv->break_on);
2272 msg.returnStatus = 0;
2273 msg.resetDataToggle = 0x0;
2276 /* Do handshaking outputs */
2277 msg.setTxTriState_setRts = 0xff;
2278 msg.txTriState_rts = p_priv->rts_state;
2280 msg.setHskoa_setDtr = 0xff;
2281 msg.hskoa_dtr = p_priv->dtr_state;
2283 p_priv->resend_cont = 0;
2285 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2287 /* send the data out the device on control endpoint */
2288 this_urb->transfer_buffer_length = sizeof(msg);
2290 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2292 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2296 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2298 struct usb_serial *serial = port->serial;
2299 struct keyspan_serial_private *s_priv;
2300 const struct keyspan_device_details *d_details;
2302 s_priv = usb_get_serial_data(serial);
2303 d_details = s_priv->device_details;
2305 switch (d_details->msg_format) {
2307 keyspan_usa26_send_setup(serial, port, reset_port);
2310 keyspan_usa28_send_setup(serial, port, reset_port);
2313 keyspan_usa49_send_setup(serial, port, reset_port);
2316 keyspan_usa90_send_setup(serial, port, reset_port);
2319 keyspan_usa67_send_setup(serial, port, reset_port);
2325 /* Gets called by the "real" driver (ie once firmware is loaded
2326 and renumeration has taken place. */
2327 static int keyspan_startup(struct usb_serial *serial)
2330 struct keyspan_serial_private *s_priv;
2331 const struct keyspan_device_details *d_details;
2333 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2334 if (d_details->product_id ==
2335 le16_to_cpu(serial->dev->descriptor.idProduct))
2337 if (d_details == NULL) {
2338 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2339 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2343 /* Setup private data for serial driver */
2344 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2346 dev_dbg(&serial->dev->dev, "%s - kmalloc for keyspan_serial_private failed.\n", __func__);
2350 s_priv->device_details = d_details;
2351 usb_set_serial_data(serial, s_priv);
2353 keyspan_setup_urbs(serial);
2355 if (s_priv->instat_urb != NULL) {
2356 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2358 dev_dbg(&serial->dev->dev, "%s - submit instat urb failed %d\n", __func__, err);
2360 if (s_priv->indat_urb != NULL) {
2361 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2363 dev_dbg(&serial->dev->dev, "%s - submit indat urb failed %d\n", __func__, err);
2369 static void keyspan_disconnect(struct usb_serial *serial)
2371 struct keyspan_serial_private *s_priv;
2373 s_priv = usb_get_serial_data(serial);
2375 stop_urb(s_priv->instat_urb);
2376 stop_urb(s_priv->glocont_urb);
2377 stop_urb(s_priv->indat_urb);
2380 static void keyspan_release(struct usb_serial *serial)
2382 struct keyspan_serial_private *s_priv;
2384 s_priv = usb_get_serial_data(serial);
2386 usb_free_urb(s_priv->instat_urb);
2387 usb_free_urb(s_priv->indat_urb);
2388 usb_free_urb(s_priv->glocont_urb);
2393 static int keyspan_port_probe(struct usb_serial_port *port)
2395 struct usb_serial *serial = port->serial;
2396 struct keyspan_serial_private *s_priv;
2397 struct keyspan_port_private *p_priv;
2398 const struct keyspan_device_details *d_details;
2399 struct callbacks *cback;
2404 s_priv = usb_get_serial_data(serial);
2405 d_details = s_priv->device_details;
2407 p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL);
2411 p_priv->device_details = d_details;
2413 /* Setup values for the various callback routines */
2414 cback = &keyspan_callbacks[d_details->msg_format];
2416 port_num = port->number - port->serial->minor;
2418 /* Do indat endpoints first, once for each flip */
2419 endp = d_details->indat_endpoints[port_num];
2420 for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) {
2421 p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp,
2423 p_priv->in_buffer[i], 64,
2424 cback->indat_callback);
2426 /* outdat endpoints also have flip */
2427 endp = d_details->outdat_endpoints[port_num];
2428 for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) {
2429 p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp,
2431 p_priv->out_buffer[i], 64,
2432 cback->outdat_callback);
2434 /* inack endpoint */
2435 p_priv->inack_urb = keyspan_setup_urb(serial,
2436 d_details->inack_endpoints[port_num],
2438 p_priv->inack_buffer, 1,
2439 cback->inack_callback);
2440 /* outcont endpoint */
2441 p_priv->outcont_urb = keyspan_setup_urb(serial,
2442 d_details->outcont_endpoints[port_num],
2444 p_priv->outcont_buffer, 64,
2445 cback->outcont_callback);
2447 usb_set_serial_port_data(port, p_priv);
2452 static int keyspan_port_remove(struct usb_serial_port *port)
2454 struct keyspan_port_private *p_priv;
2457 p_priv = usb_get_serial_port_data(port);
2459 stop_urb(p_priv->inack_urb);
2460 stop_urb(p_priv->outcont_urb);
2461 for (i = 0; i < 2; i++) {
2462 stop_urb(p_priv->in_urbs[i]);
2463 stop_urb(p_priv->out_urbs[i]);
2466 usb_free_urb(p_priv->inack_urb);
2467 usb_free_urb(p_priv->outcont_urb);
2468 for (i = 0; i < 2; i++) {
2469 usb_free_urb(p_priv->in_urbs[i]);
2470 usb_free_urb(p_priv->out_urbs[i]);
2478 MODULE_AUTHOR(DRIVER_AUTHOR);
2479 MODULE_DESCRIPTION(DRIVER_DESC);
2480 MODULE_LICENSE("GPL");
2482 MODULE_FIRMWARE("keyspan/usa28.fw");
2483 MODULE_FIRMWARE("keyspan/usa28x.fw");
2484 MODULE_FIRMWARE("keyspan/usa28xa.fw");
2485 MODULE_FIRMWARE("keyspan/usa28xb.fw");
2486 MODULE_FIRMWARE("keyspan/usa19.fw");
2487 MODULE_FIRMWARE("keyspan/usa19qi.fw");
2488 MODULE_FIRMWARE("keyspan/mpr.fw");
2489 MODULE_FIRMWARE("keyspan/usa19qw.fw");
2490 MODULE_FIRMWARE("keyspan/usa18x.fw");
2491 MODULE_FIRMWARE("keyspan/usa19w.fw");
2492 MODULE_FIRMWARE("keyspan/usa49w.fw");
2493 MODULE_FIRMWARE("keyspan/usa49wlc.fw");