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>
50 #define DRIVER_VERSION "v1.1.5"
51 #define DRIVER_AUTHOR "Hugh Blemings <hugh@misc.nu"
52 #define DRIVER_DESC "Keyspan USB to Serial Converter Driver"
54 #define INSTAT_BUFLEN 32
55 #define GLOCONT_BUFLEN 64
56 #define INDAT49W_BUFLEN 512
58 /* Per device and per port private data */
59 struct keyspan_serial_private {
60 const struct keyspan_device_details *device_details;
62 struct urb *instat_urb;
63 char instat_buf[INSTAT_BUFLEN];
65 /* added to support 49wg, where data from all 4 ports comes in
66 on 1 EP and high-speed supported */
67 struct urb *indat_urb;
68 char indat_buf[INDAT49W_BUFLEN];
70 /* XXX this one probably will need a lock */
71 struct urb *glocont_urb;
72 char glocont_buf[GLOCONT_BUFLEN];
73 char ctrl_buf[8]; /* for EP0 control message */
76 struct keyspan_port_private {
77 /* Keep track of which input & output endpoints to use */
81 /* Keep duplicate of device details in each port
82 structure as well - simplifies some of the
83 callback functions etc. */
84 const struct keyspan_device_details *device_details;
86 /* Input endpoints and buffer for this port */
87 struct urb *in_urbs[2];
88 char in_buffer[2][64];
89 /* Output endpoints and buffer for this port */
90 struct urb *out_urbs[2];
91 char out_buffer[2][64];
93 /* Input ack endpoint */
94 struct urb *inack_urb;
97 /* Output control endpoint */
98 struct urb *outcont_urb;
99 char outcont_buffer[64];
101 /* Settings for the port */
105 unsigned int old_cflag;
106 enum {flow_none, flow_cts, flow_xon} flow_control;
107 int rts_state; /* Handshaking pins (outputs) */
109 int cts_state; /* Handshaking pins (inputs) */
115 unsigned long tx_start_time[2];
116 int resend_cont; /* need to resend control packet */
119 /* Include Keyspan message headers. All current Keyspan Adapters
120 make use of one of five message formats which are referred
121 to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and
122 within this driver. */
123 #include "keyspan_usa26msg.h"
124 #include "keyspan_usa28msg.h"
125 #include "keyspan_usa49msg.h"
126 #include "keyspan_usa90msg.h"
127 #include "keyspan_usa67msg.h"
130 module_usb_serial_driver(serial_drivers, keyspan_ids_combined);
132 static void keyspan_break_ctl(struct tty_struct *tty, int break_state)
134 struct usb_serial_port *port = tty->driver_data;
135 struct keyspan_port_private *p_priv;
137 p_priv = usb_get_serial_port_data(port);
139 if (break_state == -1)
140 p_priv->break_on = 1;
142 p_priv->break_on = 0;
144 keyspan_send_setup(port, 0);
148 static void keyspan_set_termios(struct tty_struct *tty,
149 struct usb_serial_port *port, struct ktermios *old_termios)
151 int baud_rate, device_port;
152 struct keyspan_port_private *p_priv;
153 const struct keyspan_device_details *d_details;
156 p_priv = usb_get_serial_port_data(port);
157 d_details = p_priv->device_details;
158 cflag = tty->termios.c_cflag;
159 device_port = port->number - port->serial->minor;
161 /* Baud rate calculation takes baud rate as an integer
162 so other rates can be generated if desired. */
163 baud_rate = tty_get_baud_rate(tty);
164 /* If no match or invalid, don't change */
165 if (d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
166 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
167 /* FIXME - more to do here to ensure rate changes cleanly */
168 /* FIXME - calcuate exact rate from divisor ? */
169 p_priv->baud = baud_rate;
171 baud_rate = tty_termios_baud_rate(old_termios);
173 tty_encode_baud_rate(tty, baud_rate, baud_rate);
174 /* set CTS/RTS handshake etc. */
175 p_priv->cflag = cflag;
176 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
178 /* Mark/Space not supported */
179 tty->termios.c_cflag &= ~CMSPAR;
181 keyspan_send_setup(port, 0);
184 static int keyspan_tiocmget(struct tty_struct *tty)
186 struct usb_serial_port *port = tty->driver_data;
187 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
190 value = ((p_priv->rts_state) ? TIOCM_RTS : 0) |
191 ((p_priv->dtr_state) ? TIOCM_DTR : 0) |
192 ((p_priv->cts_state) ? TIOCM_CTS : 0) |
193 ((p_priv->dsr_state) ? TIOCM_DSR : 0) |
194 ((p_priv->dcd_state) ? TIOCM_CAR : 0) |
195 ((p_priv->ri_state) ? TIOCM_RNG : 0);
200 static int keyspan_tiocmset(struct tty_struct *tty,
201 unsigned int set, unsigned int clear)
203 struct usb_serial_port *port = tty->driver_data;
204 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
207 p_priv->rts_state = 1;
209 p_priv->dtr_state = 1;
210 if (clear & TIOCM_RTS)
211 p_priv->rts_state = 0;
212 if (clear & TIOCM_DTR)
213 p_priv->dtr_state = 0;
214 keyspan_send_setup(port, 0);
218 /* Write function is similar for the four protocols used
219 with only a minor change for usa90 (usa19hs) required */
220 static int keyspan_write(struct tty_struct *tty,
221 struct usb_serial_port *port, const unsigned char *buf, int count)
223 struct keyspan_port_private *p_priv;
224 const struct keyspan_device_details *d_details;
227 struct urb *this_urb;
228 int err, maxDataLen, dataOffset;
230 p_priv = usb_get_serial_port_data(port);
231 d_details = p_priv->device_details;
233 if (d_details->msg_format == msg_usa90) {
241 dev_dbg(&port->dev, "%s - for port %d (%d chars), flip=%d\n",
242 __func__, port->number, count, p_priv->out_flip);
244 for (left = count; left > 0; left -= todo) {
246 if (todo > maxDataLen)
249 flip = p_priv->out_flip;
251 /* Check we have a valid urb/endpoint before we use it... */
252 this_urb = p_priv->out_urbs[flip];
253 if (this_urb == NULL) {
254 /* no bulk out, so return 0 bytes written */
255 dev_dbg(&port->dev, "%s - no output urb :(\n", __func__);
259 dev_dbg(&port->dev, "%s - endpoint %d flip %d\n",
260 __func__, usb_pipeendpoint(this_urb->pipe), flip);
262 if (this_urb->status == -EINPROGRESS) {
263 if (time_before(jiffies,
264 p_priv->tx_start_time[flip] + 10 * HZ))
266 usb_unlink_urb(this_urb);
270 /* First byte in buffer is "last flag" (except for usa19hx)
271 - unused so for now so set to zero */
272 ((char *)this_urb->transfer_buffer)[0] = 0;
274 memcpy(this_urb->transfer_buffer + dataOffset, buf, todo);
277 /* send the data out the bulk port */
278 this_urb->transfer_buffer_length = todo + dataOffset;
280 err = usb_submit_urb(this_urb, GFP_ATOMIC);
282 dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed (%d)\n", err);
283 p_priv->tx_start_time[flip] = jiffies;
285 /* Flip for next time if usa26 or usa28 interface
286 (not used on usa49) */
287 p_priv->out_flip = (flip + 1) & d_details->outdat_endp_flip;
293 static void usa26_indat_callback(struct urb *urb)
297 struct usb_serial_port *port;
298 struct tty_struct *tty;
299 unsigned char *data = urb->transfer_buffer;
300 int status = urb->status;
302 endpoint = usb_pipeendpoint(urb->pipe);
305 dev_dbg(&urb->dev->dev,"%s - nonzero status: %x on endpoint %d.\n",
306 __func__, status, endpoint);
311 tty = tty_port_tty_get(&port->port);
312 if (tty && urb->actual_length) {
313 /* 0x80 bit is error flag */
314 if ((data[0] & 0x80) == 0) {
315 /* no errors on individual bytes, only
316 possible overrun err */
317 if (data[0] & RXERROR_OVERRUN)
321 for (i = 1; i < urb->actual_length ; ++i)
322 tty_insert_flip_char(tty, data[i], err);
324 /* some bytes had errors, every byte has status */
325 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
326 for (i = 0; i + 1 < urb->actual_length; i += 2) {
327 int stat = data[i], flag = 0;
328 if (stat & RXERROR_OVERRUN)
330 if (stat & RXERROR_FRAMING)
332 if (stat & RXERROR_PARITY)
334 /* XXX should handle break (0x10) */
335 tty_insert_flip_char(tty, data[i+1], flag);
338 tty_flip_buffer_push(tty);
342 /* Resubmit urb so we continue receiving */
343 err = usb_submit_urb(urb, GFP_ATOMIC);
345 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
348 /* Outdat handling is common for all devices */
349 static void usa2x_outdat_callback(struct urb *urb)
351 struct usb_serial_port *port;
352 struct keyspan_port_private *p_priv;
355 p_priv = usb_get_serial_port_data(port);
356 dev_dbg(&port->dev, "%s - urb %d\n", __func__, urb == p_priv->out_urbs[1]);
358 usb_serial_port_softint(port);
361 static void usa26_inack_callback(struct urb *urb)
365 static void usa26_outcont_callback(struct urb *urb)
367 struct usb_serial_port *port;
368 struct keyspan_port_private *p_priv;
371 p_priv = usb_get_serial_port_data(port);
373 if (p_priv->resend_cont) {
374 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
375 keyspan_usa26_send_setup(port->serial, port,
376 p_priv->resend_cont - 1);
380 static void usa26_instat_callback(struct urb *urb)
382 unsigned char *data = urb->transfer_buffer;
383 struct keyspan_usa26_portStatusMessage *msg;
384 struct usb_serial *serial;
385 struct usb_serial_port *port;
386 struct keyspan_port_private *p_priv;
387 struct tty_struct *tty;
388 int old_dcd_state, err;
389 int status = urb->status;
391 serial = urb->context;
394 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
397 if (urb->actual_length != 9) {
398 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
402 msg = (struct keyspan_usa26_portStatusMessage *)data;
405 dev_dbg(&urb->dev->dev,
406 "%s - port status: port %d cts %d dcd %d dsr %d ri %d toff %d txoff %d rxen %d cr %d",
407 __func__, msg->port, msg->hskia_cts, msg->gpia_dcd, msg->dsr,
408 msg->ri, msg->_txOff, msg->_txXoff, msg->rxEnabled,
409 msg->controlResponse);
412 /* Now do something useful with the data */
415 /* Check port number from message and retrieve private data */
416 if (msg->port >= serial->num_ports) {
417 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
420 port = serial->port[msg->port];
421 p_priv = usb_get_serial_port_data(port);
423 /* Update handshaking pin state information */
424 old_dcd_state = p_priv->dcd_state;
425 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
426 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
427 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
428 p_priv->ri_state = ((msg->ri) ? 1 : 0);
430 if (old_dcd_state != p_priv->dcd_state) {
431 tty = tty_port_tty_get(&port->port);
432 if (tty && !C_CLOCAL(tty))
437 /* Resubmit urb so we continue receiving */
438 err = usb_submit_urb(urb, GFP_ATOMIC);
440 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
444 static void usa26_glocont_callback(struct urb *urb)
449 static void usa28_indat_callback(struct urb *urb)
452 struct usb_serial_port *port;
453 struct tty_struct *tty;
455 struct keyspan_port_private *p_priv;
456 int status = urb->status;
459 p_priv = usb_get_serial_port_data(port);
460 data = urb->transfer_buffer;
462 if (urb != p_priv->in_urbs[p_priv->in_flip])
467 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
468 __func__, status, usb_pipeendpoint(urb->pipe));
473 p_priv = usb_get_serial_port_data(port);
474 data = urb->transfer_buffer;
476 tty = tty_port_tty_get(&port->port);
477 if (tty && urb->actual_length) {
478 tty_insert_flip_string(tty, data, urb->actual_length);
479 tty_flip_buffer_push(tty);
483 /* Resubmit urb so we continue receiving */
484 err = usb_submit_urb(urb, GFP_ATOMIC);
486 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n",
488 p_priv->in_flip ^= 1;
490 urb = p_priv->in_urbs[p_priv->in_flip];
491 } while (urb->status != -EINPROGRESS);
494 static void usa28_inack_callback(struct urb *urb)
498 static void usa28_outcont_callback(struct urb *urb)
500 struct usb_serial_port *port;
501 struct keyspan_port_private *p_priv;
504 p_priv = usb_get_serial_port_data(port);
506 if (p_priv->resend_cont) {
507 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
508 keyspan_usa28_send_setup(port->serial, port,
509 p_priv->resend_cont - 1);
513 static void usa28_instat_callback(struct urb *urb)
516 unsigned char *data = urb->transfer_buffer;
517 struct keyspan_usa28_portStatusMessage *msg;
518 struct usb_serial *serial;
519 struct usb_serial_port *port;
520 struct keyspan_port_private *p_priv;
521 struct tty_struct *tty;
523 int status = urb->status;
525 serial = urb->context;
528 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
532 if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) {
533 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
538 dev_dbg(&urb->dev->dev,
539 "%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__,
540 data[0], data[1], data[2], data[3], data[4], data[5],
541 data[6], data[7], data[8], data[9], data[10], data[11]);
544 /* Now do something useful with the data */
545 msg = (struct keyspan_usa28_portStatusMessage *)data;
547 /* Check port number from message and retrieve private data */
548 if (msg->port >= serial->num_ports) {
549 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
552 port = serial->port[msg->port];
553 p_priv = usb_get_serial_port_data(port);
555 /* Update handshaking pin state information */
556 old_dcd_state = p_priv->dcd_state;
557 p_priv->cts_state = ((msg->cts) ? 1 : 0);
558 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
559 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
560 p_priv->ri_state = ((msg->ri) ? 1 : 0);
562 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
563 tty = tty_port_tty_get(&port->port);
564 if (tty && !C_CLOCAL(tty))
569 /* Resubmit urb so we continue receiving */
570 err = usb_submit_urb(urb, GFP_ATOMIC);
572 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
576 static void usa28_glocont_callback(struct urb *urb)
581 static void usa49_glocont_callback(struct urb *urb)
583 struct usb_serial *serial;
584 struct usb_serial_port *port;
585 struct keyspan_port_private *p_priv;
588 serial = urb->context;
589 for (i = 0; i < serial->num_ports; ++i) {
590 port = serial->port[i];
591 p_priv = usb_get_serial_port_data(port);
593 if (p_priv->resend_cont) {
594 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
595 keyspan_usa49_send_setup(serial, port,
596 p_priv->resend_cont - 1);
602 /* This is actually called glostat in the Keyspan
604 static void usa49_instat_callback(struct urb *urb)
607 unsigned char *data = urb->transfer_buffer;
608 struct keyspan_usa49_portStatusMessage *msg;
609 struct usb_serial *serial;
610 struct usb_serial_port *port;
611 struct keyspan_port_private *p_priv;
613 int status = urb->status;
615 serial = urb->context;
618 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
622 if (urb->actual_length !=
623 sizeof(struct keyspan_usa49_portStatusMessage)) {
624 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
629 dev_dbg(&urb->dev->dev, "%s: %x %x %x %x %x %x %x %x %x %x %x",
630 __func__, data[0], data[1], data[2], data[3], data[4],
631 data[5], data[6], data[7], data[8], data[9], data[10]);
634 /* Now do something useful with the data */
635 msg = (struct keyspan_usa49_portStatusMessage *)data;
637 /* Check port number from message and retrieve private data */
638 if (msg->portNumber >= serial->num_ports) {
639 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
640 __func__, msg->portNumber);
643 port = serial->port[msg->portNumber];
644 p_priv = usb_get_serial_port_data(port);
646 /* Update handshaking pin state information */
647 old_dcd_state = p_priv->dcd_state;
648 p_priv->cts_state = ((msg->cts) ? 1 : 0);
649 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
650 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
651 p_priv->ri_state = ((msg->ri) ? 1 : 0);
653 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
654 struct tty_struct *tty = tty_port_tty_get(&port->port);
655 if (tty && !C_CLOCAL(tty))
660 /* Resubmit urb so we continue receiving */
661 err = usb_submit_urb(urb, GFP_ATOMIC);
663 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
667 static void usa49_inack_callback(struct urb *urb)
671 static void usa49_indat_callback(struct urb *urb)
675 struct usb_serial_port *port;
676 struct tty_struct *tty;
677 unsigned char *data = urb->transfer_buffer;
678 int status = urb->status;
680 endpoint = usb_pipeendpoint(urb->pipe);
683 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
684 __func__, status, endpoint);
689 tty = tty_port_tty_get(&port->port);
690 if (tty && urb->actual_length) {
691 /* 0x80 bit is error flag */
692 if ((data[0] & 0x80) == 0) {
693 /* no error on any byte */
694 tty_insert_flip_string(tty, data + 1,
695 urb->actual_length - 1);
697 /* some bytes had errors, every byte has status */
698 for (i = 0; i + 1 < urb->actual_length; i += 2) {
699 int stat = data[i], flag = 0;
700 if (stat & RXERROR_OVERRUN)
702 if (stat & RXERROR_FRAMING)
704 if (stat & RXERROR_PARITY)
706 /* XXX should handle break (0x10) */
707 tty_insert_flip_char(tty, data[i+1], flag);
710 tty_flip_buffer_push(tty);
714 /* Resubmit urb so we continue receiving */
715 err = usb_submit_urb(urb, GFP_ATOMIC);
717 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
720 static void usa49wg_indat_callback(struct urb *urb)
723 struct usb_serial *serial;
724 struct usb_serial_port *port;
725 struct tty_struct *tty;
726 unsigned char *data = urb->transfer_buffer;
727 int status = urb->status;
729 serial = urb->context;
732 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
736 /* inbound data is in the form P#, len, status, data */
740 if (urb->actual_length) {
741 while (i < urb->actual_length) {
743 /* Check port number from message*/
744 if (data[i] >= serial->num_ports) {
745 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
749 port = serial->port[data[i++]];
750 tty = tty_port_tty_get(&port->port);
753 /* 0x80 bit is error flag */
754 if ((data[i] & 0x80) == 0) {
755 /* no error on any byte */
757 for (x = 1; x < len ; ++x)
758 tty_insert_flip_char(tty, data[i++], 0);
761 * some bytes had errors, every byte has status
763 for (x = 0; x + 1 < len; x += 2) {
764 int stat = data[i], flag = 0;
765 if (stat & RXERROR_OVERRUN)
767 if (stat & RXERROR_FRAMING)
769 if (stat & RXERROR_PARITY)
771 /* XXX should handle break (0x10) */
772 tty_insert_flip_char(tty,
777 tty_flip_buffer_push(tty);
782 /* Resubmit urb so we continue receiving */
783 err = usb_submit_urb(urb, GFP_ATOMIC);
785 dev_dbg(&urb->dev->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
788 /* not used, usa-49 doesn't have per-port control endpoints */
789 static void usa49_outcont_callback(struct urb *urb)
793 static void usa90_indat_callback(struct urb *urb)
797 struct usb_serial_port *port;
798 struct keyspan_port_private *p_priv;
799 struct tty_struct *tty;
800 unsigned char *data = urb->transfer_buffer;
801 int status = urb->status;
803 endpoint = usb_pipeendpoint(urb->pipe);
806 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
807 __func__, status, endpoint);
812 p_priv = usb_get_serial_port_data(port);
814 if (urb->actual_length) {
815 tty = tty_port_tty_get(&port->port);
816 /* if current mode is DMA, looks like usa28 format
817 otherwise looks like usa26 data format */
819 if (p_priv->baud > 57600)
820 tty_insert_flip_string(tty, data, urb->actual_length);
822 /* 0x80 bit is error flag */
823 if ((data[0] & 0x80) == 0) {
824 /* no errors on individual bytes, only
825 possible overrun err*/
826 if (data[0] & RXERROR_OVERRUN)
830 for (i = 1; i < urb->actual_length ; ++i)
831 tty_insert_flip_char(tty, data[i],
834 /* some bytes had errors, every byte has status */
835 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
836 for (i = 0; i + 1 < urb->actual_length; i += 2) {
837 int stat = data[i], flag = 0;
838 if (stat & RXERROR_OVERRUN)
840 if (stat & RXERROR_FRAMING)
842 if (stat & RXERROR_PARITY)
844 /* XXX should handle break (0x10) */
845 tty_insert_flip_char(tty, data[i+1],
850 tty_flip_buffer_push(tty);
854 /* Resubmit urb so we continue receiving */
855 err = usb_submit_urb(urb, GFP_ATOMIC);
857 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
861 static void usa90_instat_callback(struct urb *urb)
863 unsigned char *data = urb->transfer_buffer;
864 struct keyspan_usa90_portStatusMessage *msg;
865 struct usb_serial *serial;
866 struct usb_serial_port *port;
867 struct keyspan_port_private *p_priv;
868 struct tty_struct *tty;
869 int old_dcd_state, err;
870 int status = urb->status;
872 serial = urb->context;
875 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
878 if (urb->actual_length < 14) {
879 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
883 msg = (struct keyspan_usa90_portStatusMessage *)data;
885 /* Now do something useful with the data */
887 port = serial->port[0];
888 p_priv = usb_get_serial_port_data(port);
890 /* Update handshaking pin state information */
891 old_dcd_state = p_priv->dcd_state;
892 p_priv->cts_state = ((msg->cts) ? 1 : 0);
893 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
894 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
895 p_priv->ri_state = ((msg->ri) ? 1 : 0);
897 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
898 tty = tty_port_tty_get(&port->port);
899 if (tty && !C_CLOCAL(tty))
904 /* Resubmit urb so we continue receiving */
905 err = usb_submit_urb(urb, GFP_ATOMIC);
907 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
912 static void usa90_outcont_callback(struct urb *urb)
914 struct usb_serial_port *port;
915 struct keyspan_port_private *p_priv;
918 p_priv = usb_get_serial_port_data(port);
920 if (p_priv->resend_cont) {
921 dev_dbg(&urb->dev->dev, "%s - sending setup\n", __func__);
922 keyspan_usa90_send_setup(port->serial, port,
923 p_priv->resend_cont - 1);
927 /* Status messages from the 28xg */
928 static void usa67_instat_callback(struct urb *urb)
931 unsigned char *data = urb->transfer_buffer;
932 struct keyspan_usa67_portStatusMessage *msg;
933 struct usb_serial *serial;
934 struct usb_serial_port *port;
935 struct keyspan_port_private *p_priv;
937 int status = urb->status;
939 serial = urb->context;
942 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
946 if (urb->actual_length !=
947 sizeof(struct keyspan_usa67_portStatusMessage)) {
948 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
953 /* Now do something useful with the data */
954 msg = (struct keyspan_usa67_portStatusMessage *)data;
956 /* Check port number from message and retrieve private data */
957 if (msg->port >= serial->num_ports) {
958 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
962 port = serial->port[msg->port];
963 p_priv = usb_get_serial_port_data(port);
965 /* Update handshaking pin state information */
966 old_dcd_state = p_priv->dcd_state;
967 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
968 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
970 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
971 struct tty_struct *tty = tty_port_tty_get(&port->port);
972 if (tty && !C_CLOCAL(tty))
977 /* Resubmit urb so we continue receiving */
978 err = usb_submit_urb(urb, GFP_ATOMIC);
980 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
983 static void usa67_glocont_callback(struct urb *urb)
985 struct usb_serial *serial;
986 struct usb_serial_port *port;
987 struct keyspan_port_private *p_priv;
990 serial = urb->context;
991 for (i = 0; i < serial->num_ports; ++i) {
992 port = serial->port[i];
993 p_priv = usb_get_serial_port_data(port);
995 if (p_priv->resend_cont) {
996 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
997 keyspan_usa67_send_setup(serial, port,
998 p_priv->resend_cont - 1);
1004 static int keyspan_write_room(struct tty_struct *tty)
1006 struct usb_serial_port *port = tty->driver_data;
1007 struct keyspan_port_private *p_priv;
1008 const struct keyspan_device_details *d_details;
1011 struct urb *this_urb;
1013 p_priv = usb_get_serial_port_data(port);
1014 d_details = p_priv->device_details;
1016 /* FIXME: locking */
1017 if (d_details->msg_format == msg_usa90)
1022 flip = p_priv->out_flip;
1024 /* Check both endpoints to see if any are available. */
1025 this_urb = p_priv->out_urbs[flip];
1026 if (this_urb != NULL) {
1027 if (this_urb->status != -EINPROGRESS)
1029 flip = (flip + 1) & d_details->outdat_endp_flip;
1030 this_urb = p_priv->out_urbs[flip];
1031 if (this_urb != NULL) {
1032 if (this_urb->status != -EINPROGRESS)
1040 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1042 struct keyspan_port_private *p_priv;
1043 const struct keyspan_device_details *d_details;
1045 int baud_rate, device_port;
1047 unsigned int cflag = 0;
1049 p_priv = usb_get_serial_port_data(port);
1050 d_details = p_priv->device_details;
1052 /* Set some sane defaults */
1053 p_priv->rts_state = 1;
1054 p_priv->dtr_state = 1;
1055 p_priv->baud = 9600;
1057 /* force baud and lcr to be set on open */
1058 p_priv->old_baud = 0;
1059 p_priv->old_cflag = 0;
1061 p_priv->out_flip = 0;
1062 p_priv->in_flip = 0;
1064 /* Reset low level data toggle and start reading from endpoints */
1065 for (i = 0; i < 2; i++) {
1066 urb = p_priv->in_urbs[i];
1070 /* make sure endpoint data toggle is synchronized
1072 usb_clear_halt(urb->dev, urb->pipe);
1073 err = usb_submit_urb(urb, GFP_KERNEL);
1075 dev_dbg(&port->dev, "%s - submit urb %d failed (%d)\n", __func__, i, err);
1078 /* Reset low level data toggle on out endpoints */
1079 for (i = 0; i < 2; i++) {
1080 urb = p_priv->out_urbs[i];
1083 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1084 usb_pipeout(urb->pipe), 0); */
1087 /* get the terminal config for the setup message now so we don't
1088 * need to send 2 of them */
1090 device_port = port->number - port->serial->minor;
1092 cflag = tty->termios.c_cflag;
1093 /* Baud rate calculation takes baud rate as an integer
1094 so other rates can be generated if desired. */
1095 baud_rate = tty_get_baud_rate(tty);
1096 /* If no match or invalid, leave as default */
1098 && d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
1099 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1100 p_priv->baud = baud_rate;
1103 /* set CTS/RTS handshake etc. */
1104 p_priv->cflag = cflag;
1105 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
1107 keyspan_send_setup(port, 1);
1109 /* keyspan_set_termios(port, NULL); */
1114 static inline void stop_urb(struct urb *urb)
1116 if (urb && urb->status == -EINPROGRESS)
1120 static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1122 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
1124 p_priv->rts_state = on;
1125 p_priv->dtr_state = on;
1126 keyspan_send_setup(port, 0);
1129 static void keyspan_close(struct usb_serial_port *port)
1132 struct usb_serial *serial = port->serial;
1133 struct keyspan_port_private *p_priv;
1135 p_priv = usb_get_serial_port_data(port);
1137 p_priv->rts_state = 0;
1138 p_priv->dtr_state = 0;
1141 keyspan_send_setup(port, 2);
1142 /* pilot-xfer seems to work best with this delay */
1144 /* keyspan_set_termios(port, NULL); */
1147 /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
1148 dev_dbg(&port->dev, "%s - urb in progress\n", __func__);
1151 p_priv->out_flip = 0;
1152 p_priv->in_flip = 0;
1155 /* Stop reading/writing urbs */
1156 stop_urb(p_priv->inack_urb);
1157 /* stop_urb(p_priv->outcont_urb); */
1158 for (i = 0; i < 2; i++) {
1159 stop_urb(p_priv->in_urbs[i]);
1160 stop_urb(p_priv->out_urbs[i]);
1165 /* download the firmware to a pre-renumeration device */
1166 static int keyspan_fake_startup(struct usb_serial *serial)
1170 dev_dbg(&serial->dev->dev, "Keyspan startup version %04x product %04x\n",
1171 le16_to_cpu(serial->dev->descriptor.bcdDevice),
1172 le16_to_cpu(serial->dev->descriptor.idProduct));
1174 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
1176 dev_dbg(&serial->dev->dev, "Firmware already loaded. Quitting.\n");
1180 /* Select firmware image on the basis of idProduct */
1181 switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {
1182 case keyspan_usa28_pre_product_id:
1183 fw_name = "keyspan/usa28.fw";
1186 case keyspan_usa28x_pre_product_id:
1187 fw_name = "keyspan/usa28x.fw";
1190 case keyspan_usa28xa_pre_product_id:
1191 fw_name = "keyspan/usa28xa.fw";
1194 case keyspan_usa28xb_pre_product_id:
1195 fw_name = "keyspan/usa28xb.fw";
1198 case keyspan_usa19_pre_product_id:
1199 fw_name = "keyspan/usa19.fw";
1202 case keyspan_usa19qi_pre_product_id:
1203 fw_name = "keyspan/usa19qi.fw";
1206 case keyspan_mpr_pre_product_id:
1207 fw_name = "keyspan/mpr.fw";
1210 case keyspan_usa19qw_pre_product_id:
1211 fw_name = "keyspan/usa19qw.fw";
1214 case keyspan_usa18x_pre_product_id:
1215 fw_name = "keyspan/usa18x.fw";
1218 case keyspan_usa19w_pre_product_id:
1219 fw_name = "keyspan/usa19w.fw";
1222 case keyspan_usa49w_pre_product_id:
1223 fw_name = "keyspan/usa49w.fw";
1226 case keyspan_usa49wlc_pre_product_id:
1227 fw_name = "keyspan/usa49wlc.fw";
1231 dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n",
1232 le16_to_cpu(serial->dev->descriptor.idProduct));
1236 dev_dbg(&serial->dev->dev, "Uploading Keyspan %s firmware.\n", fw_name);
1238 if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
1239 dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
1244 /* after downloading firmware Renumeration will occur in a
1245 moment and the new device will bind to the real driver */
1247 /* we don't want this device to have a driver assigned to it. */
1251 /* Helper functions used by keyspan_setup_urbs */
1252 static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial,
1255 struct usb_host_interface *iface_desc;
1256 struct usb_endpoint_descriptor *ep;
1259 iface_desc = serial->interface->cur_altsetting;
1260 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1261 ep = &iface_desc->endpoint[i].desc;
1262 if (ep->bEndpointAddress == endpoint)
1265 dev_warn(&serial->interface->dev, "found no endpoint descriptor for "
1266 "endpoint %x\n", endpoint);
1270 static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1271 int dir, void *ctx, char *buf, int len,
1272 void (*callback)(struct urb *))
1275 struct usb_endpoint_descriptor const *ep_desc;
1276 char const *ep_type_name;
1279 return NULL; /* endpoint not needed */
1281 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d.\n", __func__, endpoint);
1282 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1284 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d failed.\n", __func__, endpoint);
1288 if (endpoint == 0) {
1289 /* control EP filled in when used */
1293 ep_desc = find_ep(serial, endpoint);
1295 /* leak the urb, something's wrong and the callers don't care */
1298 if (usb_endpoint_xfer_int(ep_desc)) {
1299 ep_type_name = "INT";
1300 usb_fill_int_urb(urb, serial->dev,
1301 usb_sndintpipe(serial->dev, endpoint) | dir,
1302 buf, len, callback, ctx,
1303 ep_desc->bInterval);
1304 } else if (usb_endpoint_xfer_bulk(ep_desc)) {
1305 ep_type_name = "BULK";
1306 usb_fill_bulk_urb(urb, serial->dev,
1307 usb_sndbulkpipe(serial->dev, endpoint) | dir,
1308 buf, len, callback, ctx);
1310 dev_warn(&serial->interface->dev,
1311 "unsupported endpoint type %x\n",
1312 usb_endpoint_type(ep_desc));
1317 dev_dbg(&serial->interface->dev, "%s - using urb %p for %s endpoint %x\n",
1318 __func__, urb, ep_type_name, endpoint);
1322 static struct callbacks {
1323 void (*instat_callback)(struct urb *);
1324 void (*glocont_callback)(struct urb *);
1325 void (*indat_callback)(struct urb *);
1326 void (*outdat_callback)(struct urb *);
1327 void (*inack_callback)(struct urb *);
1328 void (*outcont_callback)(struct urb *);
1329 } keyspan_callbacks[] = {
1331 /* msg_usa26 callbacks */
1332 .instat_callback = usa26_instat_callback,
1333 .glocont_callback = usa26_glocont_callback,
1334 .indat_callback = usa26_indat_callback,
1335 .outdat_callback = usa2x_outdat_callback,
1336 .inack_callback = usa26_inack_callback,
1337 .outcont_callback = usa26_outcont_callback,
1339 /* msg_usa28 callbacks */
1340 .instat_callback = usa28_instat_callback,
1341 .glocont_callback = usa28_glocont_callback,
1342 .indat_callback = usa28_indat_callback,
1343 .outdat_callback = usa2x_outdat_callback,
1344 .inack_callback = usa28_inack_callback,
1345 .outcont_callback = usa28_outcont_callback,
1347 /* msg_usa49 callbacks */
1348 .instat_callback = usa49_instat_callback,
1349 .glocont_callback = usa49_glocont_callback,
1350 .indat_callback = usa49_indat_callback,
1351 .outdat_callback = usa2x_outdat_callback,
1352 .inack_callback = usa49_inack_callback,
1353 .outcont_callback = usa49_outcont_callback,
1355 /* msg_usa90 callbacks */
1356 .instat_callback = usa90_instat_callback,
1357 .glocont_callback = usa28_glocont_callback,
1358 .indat_callback = usa90_indat_callback,
1359 .outdat_callback = usa2x_outdat_callback,
1360 .inack_callback = usa28_inack_callback,
1361 .outcont_callback = usa90_outcont_callback,
1363 /* msg_usa67 callbacks */
1364 .instat_callback = usa67_instat_callback,
1365 .glocont_callback = usa67_glocont_callback,
1366 .indat_callback = usa26_indat_callback,
1367 .outdat_callback = usa2x_outdat_callback,
1368 .inack_callback = usa26_inack_callback,
1369 .outcont_callback = usa26_outcont_callback,
1373 /* Generic setup urbs function that uses
1374 data in device_details */
1375 static void keyspan_setup_urbs(struct usb_serial *serial)
1377 struct keyspan_serial_private *s_priv;
1378 const struct keyspan_device_details *d_details;
1379 struct callbacks *cback;
1381 s_priv = usb_get_serial_data(serial);
1382 d_details = s_priv->device_details;
1384 /* Setup values for the various callback routines */
1385 cback = &keyspan_callbacks[d_details->msg_format];
1387 /* Allocate and set up urbs for each one that is in use,
1388 starting with instat endpoints */
1389 s_priv->instat_urb = keyspan_setup_urb
1390 (serial, d_details->instat_endpoint, USB_DIR_IN,
1391 serial, s_priv->instat_buf, INSTAT_BUFLEN,
1392 cback->instat_callback);
1394 s_priv->indat_urb = keyspan_setup_urb
1395 (serial, d_details->indat_endpoint, USB_DIR_IN,
1396 serial, s_priv->indat_buf, INDAT49W_BUFLEN,
1397 usa49wg_indat_callback);
1399 s_priv->glocont_urb = keyspan_setup_urb
1400 (serial, d_details->glocont_endpoint, USB_DIR_OUT,
1401 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1402 cback->glocont_callback);
1405 /* usa19 function doesn't require prescaler */
1406 static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
1407 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1408 u8 *rate_low, u8 *prescaler, int portnum)
1410 u32 b16, /* baud rate times 16 (actual rate used internally) */
1412 cnt; /* inverse of divisor (programmed into 8051) */
1414 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1416 /* prevent divide by zero... */
1417 b16 = baud_rate * 16L;
1419 return KEYSPAN_INVALID_BAUD_RATE;
1420 /* Any "standard" rate over 57k6 is marginal on the USA-19
1421 as we run out of divisor resolution. */
1422 if (baud_rate > 57600)
1423 return KEYSPAN_INVALID_BAUD_RATE;
1425 /* calculate the divisor and the counter (its inverse) */
1426 div = baudclk / b16;
1428 return KEYSPAN_INVALID_BAUD_RATE;
1433 return KEYSPAN_INVALID_BAUD_RATE;
1435 /* return the counter values if non-null */
1437 *rate_low = (u8) (cnt & 0xff);
1439 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1440 if (rate_low && rate_hi)
1441 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1442 __func__, baud_rate, *rate_hi, *rate_low);
1443 return KEYSPAN_BAUD_RATE_OK;
1446 /* usa19hs function doesn't require prescaler */
1447 static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
1448 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1449 u8 *rate_low, u8 *prescaler, int portnum)
1451 u32 b16, /* baud rate times 16 (actual rate used internally) */
1454 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1456 /* prevent divide by zero... */
1457 b16 = baud_rate * 16L;
1459 return KEYSPAN_INVALID_BAUD_RATE;
1461 /* calculate the divisor */
1462 div = baudclk / b16;
1464 return KEYSPAN_INVALID_BAUD_RATE;
1467 return KEYSPAN_INVALID_BAUD_RATE;
1469 /* return the counter values if non-null */
1471 *rate_low = (u8) (div & 0xff);
1474 *rate_hi = (u8) ((div >> 8) & 0xff);
1476 if (rate_low && rate_hi)
1477 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1478 __func__, baud_rate, *rate_hi, *rate_low);
1480 return KEYSPAN_BAUD_RATE_OK;
1483 static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
1484 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1485 u8 *rate_low, u8 *prescaler, int portnum)
1487 u32 b16, /* baud rate times 16 (actual rate used internally) */
1488 clk, /* clock with 13/8 prescaler */
1489 div, /* divisor using 13/8 prescaler */
1490 res, /* resulting baud rate using 13/8 prescaler */
1491 diff, /* error using 13/8 prescaler */
1496 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1498 /* prevent divide by zero */
1499 b16 = baud_rate * 16L;
1501 return KEYSPAN_INVALID_BAUD_RATE;
1503 /* Calculate prescaler by trying them all and looking
1506 /* start with largest possible difference */
1507 smallest_diff = 0xffffffff;
1509 /* 0 is an invalid prescaler, used as a flag */
1512 for (i = 8; i <= 0xff; ++i) {
1513 clk = (baudclk * 8) / (u32) i;
1520 diff = (res > b16) ? (res-b16) : (b16-res);
1522 if (diff < smallest_diff) {
1524 smallest_diff = diff;
1528 if (best_prescaler == 0)
1529 return KEYSPAN_INVALID_BAUD_RATE;
1531 clk = (baudclk * 8) / (u32) best_prescaler;
1534 /* return the divisor and prescaler if non-null */
1536 *rate_low = (u8) (div & 0xff);
1538 *rate_hi = (u8) ((div >> 8) & 0xff);
1540 *prescaler = best_prescaler;
1541 /* dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
1543 return KEYSPAN_BAUD_RATE_OK;
1546 /* USA-28 supports different maximum baud rates on each port */
1547 static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
1548 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1549 u8 *rate_low, u8 *prescaler, int portnum)
1551 u32 b16, /* baud rate times 16 (actual rate used internally) */
1553 cnt; /* inverse of divisor (programmed into 8051) */
1555 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1557 /* prevent divide by zero */
1558 b16 = baud_rate * 16L;
1560 return KEYSPAN_INVALID_BAUD_RATE;
1562 /* calculate the divisor and the counter (its inverse) */
1563 div = KEYSPAN_USA28_BAUDCLK / b16;
1565 return KEYSPAN_INVALID_BAUD_RATE;
1569 /* check for out of range, based on portnum,
1570 and return result */
1573 return KEYSPAN_INVALID_BAUD_RATE;
1577 return KEYSPAN_INVALID_BAUD_RATE;
1579 return KEYSPAN_INVALID_BAUD_RATE;
1582 /* return the counter values if not NULL
1583 (port 1 will ignore retHi) */
1585 *rate_low = (u8) (cnt & 0xff);
1587 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1588 dev_dbg(&port->dev, "%s - %d OK.\n", __func__, baud_rate);
1589 return KEYSPAN_BAUD_RATE_OK;
1592 static int keyspan_usa26_send_setup(struct usb_serial *serial,
1593 struct usb_serial_port *port,
1596 struct keyspan_usa26_portControlMessage msg;
1597 struct keyspan_serial_private *s_priv;
1598 struct keyspan_port_private *p_priv;
1599 const struct keyspan_device_details *d_details;
1601 struct urb *this_urb;
1602 int device_port, err;
1604 dev_dbg(&port->dev, "%s reset=%d\n", __func__, reset_port);
1606 s_priv = usb_get_serial_data(serial);
1607 p_priv = usb_get_serial_port_data(port);
1608 d_details = s_priv->device_details;
1609 device_port = port->number - port->serial->minor;
1611 outcont_urb = d_details->outcont_endpoints[port->number];
1612 this_urb = p_priv->outcont_urb;
1614 dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
1616 /* Make sure we have an urb then send the message */
1617 if (this_urb == NULL) {
1618 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1622 /* Save reset port val for resend.
1623 Don't overwrite resend for open/close condition. */
1624 if ((reset_port + 1) > p_priv->resend_cont)
1625 p_priv->resend_cont = reset_port + 1;
1626 if (this_urb->status == -EINPROGRESS) {
1627 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1632 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1634 /* Only set baud rate if it's changed */
1635 if (p_priv->old_baud != p_priv->baud) {
1636 p_priv->old_baud = p_priv->baud;
1637 msg.setClocking = 0xff;
1638 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1639 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1640 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1641 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1642 __func__, p_priv->baud);
1644 msg.baudHi = 125; /* Values for 9600 baud */
1647 msg.setPrescaler = 0xff;
1650 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1651 switch (p_priv->cflag & CSIZE) {
1653 msg.lcr |= USA_DATABITS_5;
1656 msg.lcr |= USA_DATABITS_6;
1659 msg.lcr |= USA_DATABITS_7;
1662 msg.lcr |= USA_DATABITS_8;
1665 if (p_priv->cflag & PARENB) {
1666 /* note USA_PARITY_NONE == 0 */
1667 msg.lcr |= (p_priv->cflag & PARODD) ?
1668 USA_PARITY_ODD : USA_PARITY_EVEN;
1672 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1673 msg.xonFlowControl = 0;
1674 msg.setFlowControl = 0xff;
1675 msg.forwardingLength = 16;
1680 if (reset_port == 1) {
1689 msg.returnStatus = 0;
1690 msg.resetDataToggle = 0xff;
1694 else if (reset_port == 2) {
1703 msg.returnStatus = 0;
1704 msg.resetDataToggle = 0;
1707 /* Sending intermediate configs */
1709 msg._txOn = (!p_priv->break_on);
1712 msg.txBreak = (p_priv->break_on);
1717 msg.returnStatus = 0;
1718 msg.resetDataToggle = 0x0;
1721 /* Do handshaking outputs */
1722 msg.setTxTriState_setRts = 0xff;
1723 msg.txTriState_rts = p_priv->rts_state;
1725 msg.setHskoa_setDtr = 0xff;
1726 msg.hskoa_dtr = p_priv->dtr_state;
1728 p_priv->resend_cont = 0;
1729 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1731 /* send the data out the device on control endpoint */
1732 this_urb->transfer_buffer_length = sizeof(msg);
1734 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1736 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1739 dev_dbg(&port->dev, "%s - usb_submit_urb(%d) OK %d bytes (end %d)\n", __func__
1740 outcont_urb, this_urb->transfer_buffer_length,
1741 usb_pipeendpoint(this_urb->pipe));
1748 static int keyspan_usa28_send_setup(struct usb_serial *serial,
1749 struct usb_serial_port *port,
1752 struct keyspan_usa28_portControlMessage msg;
1753 struct keyspan_serial_private *s_priv;
1754 struct keyspan_port_private *p_priv;
1755 const struct keyspan_device_details *d_details;
1756 struct urb *this_urb;
1757 int device_port, err;
1759 s_priv = usb_get_serial_data(serial);
1760 p_priv = usb_get_serial_port_data(port);
1761 d_details = s_priv->device_details;
1762 device_port = port->number - port->serial->minor;
1764 /* only do something if we have a bulk out endpoint */
1765 this_urb = p_priv->outcont_urb;
1766 if (this_urb == NULL) {
1767 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1771 /* Save reset port val for resend.
1772 Don't overwrite resend for open/close condition. */
1773 if ((reset_port + 1) > p_priv->resend_cont)
1774 p_priv->resend_cont = reset_port + 1;
1775 if (this_urb->status == -EINPROGRESS) {
1776 dev_dbg(&port->dev, "%s already writing\n", __func__);
1781 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
1783 msg.setBaudRate = 1;
1784 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1785 &msg.baudHi, &msg.baudLo, NULL,
1786 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1787 dev_dbg(&port->dev, "%s - Invalid baud rate requested %d.\n",
1788 __func__, p_priv->baud);
1790 msg.baudHi = 0xb2; /* Values for 9600 baud */
1793 /* If parity is enabled, we must calculate it ourselves. */
1794 msg.parity = 0; /* XXX for now */
1796 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1797 msg.xonFlowControl = 0;
1799 /* Do handshaking outputs, DTR is inverted relative to RTS */
1800 msg.rts = p_priv->rts_state;
1801 msg.dtr = p_priv->dtr_state;
1803 msg.forwardingLength = 16;
1805 msg.breakThreshold = 45;
1809 /*msg.returnStatus = 1;
1810 msg.resetDataToggle = 0xff;*/
1812 if (reset_port == 1) {
1816 msg.txForceXoff = 0;
1822 msg.returnStatus = 0;
1823 msg.resetDataToggle = 0xff;
1826 else if (reset_port == 2) {
1830 msg.txForceXoff = 0;
1836 msg.returnStatus = 0;
1837 msg.resetDataToggle = 0;
1839 /* Sending intermediate configs */
1841 msg._txOn = (!p_priv->break_on);
1844 msg.txForceXoff = 0;
1845 msg.txBreak = (p_priv->break_on);
1850 msg.returnStatus = 0;
1851 msg.resetDataToggle = 0x0;
1854 p_priv->resend_cont = 0;
1855 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1857 /* send the data out the device on control endpoint */
1858 this_urb->transfer_buffer_length = sizeof(msg);
1860 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1862 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed\n", __func__);
1865 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) OK %d bytes\n", __func__,
1866 this_urb->transfer_buffer_length);
1873 static int keyspan_usa49_send_setup(struct usb_serial *serial,
1874 struct usb_serial_port *port,
1877 struct keyspan_usa49_portControlMessage msg;
1878 struct usb_ctrlrequest *dr = NULL;
1879 struct keyspan_serial_private *s_priv;
1880 struct keyspan_port_private *p_priv;
1881 const struct keyspan_device_details *d_details;
1882 struct urb *this_urb;
1883 int err, device_port;
1885 s_priv = usb_get_serial_data(serial);
1886 p_priv = usb_get_serial_port_data(port);
1887 d_details = s_priv->device_details;
1889 this_urb = s_priv->glocont_urb;
1891 /* Work out which port within the device is being setup */
1892 device_port = port->number - port->serial->minor;
1894 /* Make sure we have an urb then send the message */
1895 if (this_urb == NULL) {
1896 dev_dbg(&port->dev, "%s - oops no urb for port %d.\n", __func__, port->number);
1900 dev_dbg(&port->dev, "%s - endpoint %d port %d (%d)\n",
1901 __func__, usb_pipeendpoint(this_urb->pipe),
1902 port->number, device_port);
1904 /* Save reset port val for resend.
1905 Don't overwrite resend for open/close condition. */
1906 if ((reset_port + 1) > p_priv->resend_cont)
1907 p_priv->resend_cont = reset_port + 1;
1909 if (this_urb->status == -EINPROGRESS) {
1910 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1915 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
1917 /*msg.portNumber = port->number;*/
1918 msg.portNumber = device_port;
1920 /* Only set baud rate if it's changed */
1921 if (p_priv->old_baud != p_priv->baud) {
1922 p_priv->old_baud = p_priv->baud;
1923 msg.setClocking = 0xff;
1924 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1925 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1926 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1927 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1928 __func__, p_priv->baud);
1930 msg.baudHi = 125; /* Values for 9600 baud */
1933 /* msg.setPrescaler = 0xff; */
1936 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1937 switch (p_priv->cflag & CSIZE) {
1939 msg.lcr |= USA_DATABITS_5;
1942 msg.lcr |= USA_DATABITS_6;
1945 msg.lcr |= USA_DATABITS_7;
1948 msg.lcr |= USA_DATABITS_8;
1951 if (p_priv->cflag & PARENB) {
1952 /* note USA_PARITY_NONE == 0 */
1953 msg.lcr |= (p_priv->cflag & PARODD) ?
1954 USA_PARITY_ODD : USA_PARITY_EVEN;
1958 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1959 msg.xonFlowControl = 0;
1960 msg.setFlowControl = 0xff;
1962 msg.forwardingLength = 16;
1967 if (reset_port == 1) {
1976 msg.returnStatus = 0;
1977 msg.resetDataToggle = 0xff;
1979 msg.disablePort = 0;
1982 else if (reset_port == 2) {
1991 msg.returnStatus = 0;
1992 msg.resetDataToggle = 0;
1994 msg.disablePort = 1;
1996 /* Sending intermediate configs */
1998 msg._txOn = (!p_priv->break_on);
2001 msg.txBreak = (p_priv->break_on);
2006 msg.returnStatus = 0;
2007 msg.resetDataToggle = 0x0;
2009 msg.disablePort = 0;
2012 /* Do handshaking outputs */
2014 msg.rts = p_priv->rts_state;
2017 msg.dtr = p_priv->dtr_state;
2019 p_priv->resend_cont = 0;
2021 /* if the device is a 49wg, we send control message on usb
2024 if (d_details->product_id == keyspan_usa49wg_product_id) {
2025 dr = (void *)(s_priv->ctrl_buf);
2026 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
2027 dr->bRequest = 0xB0; /* 49wg control message */;
2030 dr->wLength = cpu_to_le16(sizeof(msg));
2032 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
2034 usb_fill_control_urb(this_urb, serial->dev,
2035 usb_sndctrlpipe(serial->dev, 0),
2036 (unsigned char *)dr, s_priv->glocont_buf,
2037 sizeof(msg), usa49_glocont_callback, serial);
2040 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2042 /* send the data out the device on control endpoint */
2043 this_urb->transfer_buffer_length = sizeof(msg);
2045 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2047 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2050 dev_dbg(&port->dev, "%s - usb_submit_urb(%d) OK %d bytes (end %d)\n", __func__,
2051 outcont_urb, this_urb->transfer_buffer_length,
2052 usb_pipeendpoint(this_urb->pipe));
2059 static int keyspan_usa90_send_setup(struct usb_serial *serial,
2060 struct usb_serial_port *port,
2063 struct keyspan_usa90_portControlMessage msg;
2064 struct keyspan_serial_private *s_priv;
2065 struct keyspan_port_private *p_priv;
2066 const struct keyspan_device_details *d_details;
2067 struct urb *this_urb;
2071 s_priv = usb_get_serial_data(serial);
2072 p_priv = usb_get_serial_port_data(port);
2073 d_details = s_priv->device_details;
2075 /* only do something if we have a bulk out endpoint */
2076 this_urb = p_priv->outcont_urb;
2077 if (this_urb == NULL) {
2078 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
2082 /* Save reset port val for resend.
2083 Don't overwrite resend for open/close condition. */
2084 if ((reset_port + 1) > p_priv->resend_cont)
2085 p_priv->resend_cont = reset_port + 1;
2086 if (this_urb->status == -EINPROGRESS) {
2087 dev_dbg(&port->dev, "%s already writing\n", __func__);
2092 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2094 /* Only set baud rate if it's changed */
2095 if (p_priv->old_baud != p_priv->baud) {
2096 p_priv->old_baud = p_priv->baud;
2097 msg.setClocking = 0x01;
2098 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2099 &msg.baudHi, &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2100 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2101 __func__, p_priv->baud);
2102 p_priv->baud = 9600;
2103 d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2104 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2110 /* modes must always be correctly specified */
2111 if (p_priv->baud > 57600) {
2112 msg.rxMode = RXMODE_DMA;
2113 msg.txMode = TXMODE_DMA;
2115 msg.rxMode = RXMODE_BYHAND;
2116 msg.txMode = TXMODE_BYHAND;
2119 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2120 switch (p_priv->cflag & CSIZE) {
2122 msg.lcr |= USA_DATABITS_5;
2125 msg.lcr |= USA_DATABITS_6;
2128 msg.lcr |= USA_DATABITS_7;
2131 msg.lcr |= USA_DATABITS_8;
2134 if (p_priv->cflag & PARENB) {
2135 /* note USA_PARITY_NONE == 0 */
2136 msg.lcr |= (p_priv->cflag & PARODD) ?
2137 USA_PARITY_ODD : USA_PARITY_EVEN;
2139 if (p_priv->old_cflag != p_priv->cflag) {
2140 p_priv->old_cflag = p_priv->cflag;
2144 if (p_priv->flow_control == flow_cts)
2145 msg.txFlowControl = TXFLOW_CTS;
2146 msg.setTxFlowControl = 0x01;
2147 msg.setRxFlowControl = 0x01;
2149 msg.rxForwardingLength = 16;
2150 msg.rxForwardingTimeout = 16;
2151 msg.txAckSetting = 0;
2156 if (reset_port == 1) {
2157 msg.portEnabled = 1;
2159 msg.txBreak = (p_priv->break_on);
2162 else if (reset_port == 2)
2163 msg.portEnabled = 0;
2164 /* Sending intermediate configs */
2166 msg.portEnabled = 1;
2167 msg.txBreak = (p_priv->break_on);
2170 /* Do handshaking outputs */
2172 msg.rts = p_priv->rts_state;
2175 msg.dtr = p_priv->dtr_state;
2177 p_priv->resend_cont = 0;
2178 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2180 /* send the data out the device on control endpoint */
2181 this_urb->transfer_buffer_length = sizeof(msg);
2183 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2185 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2189 static int keyspan_usa67_send_setup(struct usb_serial *serial,
2190 struct usb_serial_port *port,
2193 struct keyspan_usa67_portControlMessage msg;
2194 struct keyspan_serial_private *s_priv;
2195 struct keyspan_port_private *p_priv;
2196 const struct keyspan_device_details *d_details;
2197 struct urb *this_urb;
2198 int err, device_port;
2200 s_priv = usb_get_serial_data(serial);
2201 p_priv = usb_get_serial_port_data(port);
2202 d_details = s_priv->device_details;
2204 this_urb = s_priv->glocont_urb;
2206 /* Work out which port within the device is being setup */
2207 device_port = port->number - port->serial->minor;
2209 /* Make sure we have an urb then send the message */
2210 if (this_urb == NULL) {
2211 dev_dbg(&port->dev, "%s - oops no urb for port %d.\n", __func__,
2216 /* Save reset port val for resend.
2217 Don't overwrite resend for open/close condition. */
2218 if ((reset_port + 1) > p_priv->resend_cont)
2219 p_priv->resend_cont = reset_port + 1;
2220 if (this_urb->status == -EINPROGRESS) {
2221 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2226 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
2228 msg.port = device_port;
2230 /* Only set baud rate if it's changed */
2231 if (p_priv->old_baud != p_priv->baud) {
2232 p_priv->old_baud = p_priv->baud;
2233 msg.setClocking = 0xff;
2234 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2235 &msg.baudHi, &msg.baudLo, &msg.prescaler,
2236 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2237 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2238 __func__, p_priv->baud);
2240 msg.baudHi = 125; /* Values for 9600 baud */
2243 msg.setPrescaler = 0xff;
2246 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2247 switch (p_priv->cflag & CSIZE) {
2249 msg.lcr |= USA_DATABITS_5;
2252 msg.lcr |= USA_DATABITS_6;
2255 msg.lcr |= USA_DATABITS_7;
2258 msg.lcr |= USA_DATABITS_8;
2261 if (p_priv->cflag & PARENB) {
2262 /* note USA_PARITY_NONE == 0 */
2263 msg.lcr |= (p_priv->cflag & PARODD) ?
2264 USA_PARITY_ODD : USA_PARITY_EVEN;
2268 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2269 msg.xonFlowControl = 0;
2270 msg.setFlowControl = 0xff;
2271 msg.forwardingLength = 16;
2275 if (reset_port == 1) {
2285 msg.returnStatus = 0;
2286 msg.resetDataToggle = 0xff;
2287 } else if (reset_port == 2) {
2297 msg.returnStatus = 0;
2298 msg.resetDataToggle = 0;
2300 /* Sending intermediate configs */
2301 msg._txOn = (!p_priv->break_on);
2304 msg.txBreak = (p_priv->break_on);
2309 msg.returnStatus = 0;
2310 msg.resetDataToggle = 0x0;
2313 /* Do handshaking outputs */
2314 msg.setTxTriState_setRts = 0xff;
2315 msg.txTriState_rts = p_priv->rts_state;
2317 msg.setHskoa_setDtr = 0xff;
2318 msg.hskoa_dtr = p_priv->dtr_state;
2320 p_priv->resend_cont = 0;
2322 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2324 /* send the data out the device on control endpoint */
2325 this_urb->transfer_buffer_length = sizeof(msg);
2327 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2329 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2333 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2335 struct usb_serial *serial = port->serial;
2336 struct keyspan_serial_private *s_priv;
2337 const struct keyspan_device_details *d_details;
2339 s_priv = usb_get_serial_data(serial);
2340 d_details = s_priv->device_details;
2342 switch (d_details->msg_format) {
2344 keyspan_usa26_send_setup(serial, port, reset_port);
2347 keyspan_usa28_send_setup(serial, port, reset_port);
2350 keyspan_usa49_send_setup(serial, port, reset_port);
2353 keyspan_usa90_send_setup(serial, port, reset_port);
2356 keyspan_usa67_send_setup(serial, port, reset_port);
2362 /* Gets called by the "real" driver (ie once firmware is loaded
2363 and renumeration has taken place. */
2364 static int keyspan_startup(struct usb_serial *serial)
2367 struct keyspan_serial_private *s_priv;
2368 const struct keyspan_device_details *d_details;
2370 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2371 if (d_details->product_id ==
2372 le16_to_cpu(serial->dev->descriptor.idProduct))
2374 if (d_details == NULL) {
2375 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2376 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2380 /* Setup private data for serial driver */
2381 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2383 dev_dbg(&serial->dev->dev, "%s - kmalloc for keyspan_serial_private failed.\n", __func__);
2387 s_priv->device_details = d_details;
2388 usb_set_serial_data(serial, s_priv);
2390 keyspan_setup_urbs(serial);
2392 if (s_priv->instat_urb != NULL) {
2393 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2395 dev_dbg(&serial->dev->dev, "%s - submit instat urb failed %d\n", __func__, err);
2397 if (s_priv->indat_urb != NULL) {
2398 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2400 dev_dbg(&serial->dev->dev, "%s - submit indat urb failed %d\n", __func__, err);
2406 static void keyspan_disconnect(struct usb_serial *serial)
2408 struct keyspan_serial_private *s_priv;
2410 s_priv = usb_get_serial_data(serial);
2412 stop_urb(s_priv->instat_urb);
2413 stop_urb(s_priv->glocont_urb);
2414 stop_urb(s_priv->indat_urb);
2417 static void keyspan_release(struct usb_serial *serial)
2419 struct keyspan_serial_private *s_priv;
2421 s_priv = usb_get_serial_data(serial);
2423 usb_free_urb(s_priv->instat_urb);
2424 usb_free_urb(s_priv->indat_urb);
2425 usb_free_urb(s_priv->glocont_urb);
2430 static int keyspan_port_probe(struct usb_serial_port *port)
2432 struct usb_serial *serial = port->serial;
2433 struct keyspan_serial_private *s_priv;
2434 struct keyspan_port_private *p_priv;
2435 const struct keyspan_device_details *d_details;
2436 struct callbacks *cback;
2441 s_priv = usb_get_serial_data(serial);
2442 d_details = s_priv->device_details;
2444 p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL);
2448 p_priv->device_details = d_details;
2450 /* Setup values for the various callback routines */
2451 cback = &keyspan_callbacks[d_details->msg_format];
2453 port_num = port->number - port->serial->minor;
2455 /* Do indat endpoints first, once for each flip */
2456 endp = d_details->indat_endpoints[port_num];
2457 for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) {
2458 p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp,
2460 p_priv->in_buffer[i], 64,
2461 cback->indat_callback);
2463 /* outdat endpoints also have flip */
2464 endp = d_details->outdat_endpoints[port_num];
2465 for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) {
2466 p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp,
2468 p_priv->out_buffer[i], 64,
2469 cback->outdat_callback);
2471 /* inack endpoint */
2472 p_priv->inack_urb = keyspan_setup_urb(serial,
2473 d_details->inack_endpoints[port_num],
2475 p_priv->inack_buffer, 1,
2476 cback->inack_callback);
2477 /* outcont endpoint */
2478 p_priv->outcont_urb = keyspan_setup_urb(serial,
2479 d_details->outcont_endpoints[port_num],
2481 p_priv->outcont_buffer, 64,
2482 cback->outcont_callback);
2484 usb_set_serial_port_data(port, p_priv);
2489 static int keyspan_port_remove(struct usb_serial_port *port)
2491 struct keyspan_port_private *p_priv;
2494 p_priv = usb_get_serial_port_data(port);
2496 stop_urb(p_priv->inack_urb);
2497 stop_urb(p_priv->outcont_urb);
2498 for (i = 0; i < 2; i++) {
2499 stop_urb(p_priv->in_urbs[i]);
2500 stop_urb(p_priv->out_urbs[i]);
2503 usb_free_urb(p_priv->inack_urb);
2504 usb_free_urb(p_priv->outcont_urb);
2505 for (i = 0; i < 2; i++) {
2506 usb_free_urb(p_priv->in_urbs[i]);
2507 usb_free_urb(p_priv->out_urbs[i]);
2515 MODULE_AUTHOR(DRIVER_AUTHOR);
2516 MODULE_DESCRIPTION(DRIVER_DESC);
2517 MODULE_LICENSE("GPL");
2519 MODULE_FIRMWARE("keyspan/usa28.fw");
2520 MODULE_FIRMWARE("keyspan/usa28x.fw");
2521 MODULE_FIRMWARE("keyspan/usa28xa.fw");
2522 MODULE_FIRMWARE("keyspan/usa28xb.fw");
2523 MODULE_FIRMWARE("keyspan/usa19.fw");
2524 MODULE_FIRMWARE("keyspan/usa19qi.fw");
2525 MODULE_FIRMWARE("keyspan/mpr.fw");
2526 MODULE_FIRMWARE("keyspan/usa19qw.fw");
2527 MODULE_FIRMWARE("keyspan/usa18x.fw");
2528 MODULE_FIRMWARE("keyspan/usa19w.fw");
2529 MODULE_FIRMWARE("keyspan/usa49w.fw");
2530 MODULE_FIRMWARE("keyspan/usa49wlc.fw");