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 struct tty_struct *tty;
295 unsigned char *data = urb->transfer_buffer;
296 int status = urb->status;
298 endpoint = usb_pipeendpoint(urb->pipe);
301 dev_dbg(&urb->dev->dev,"%s - nonzero status: %x on endpoint %d.\n",
302 __func__, status, endpoint);
307 tty = tty_port_tty_get(&port->port);
308 if (tty && urb->actual_length) {
309 /* 0x80 bit is error flag */
310 if ((data[0] & 0x80) == 0) {
311 /* no errors on individual bytes, only
312 possible overrun err */
313 if (data[0] & RXERROR_OVERRUN)
317 for (i = 1; i < urb->actual_length ; ++i)
318 tty_insert_flip_char(tty, data[i], err);
320 /* some bytes had errors, every byte has status */
321 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
322 for (i = 0; i + 1 < urb->actual_length; i += 2) {
323 int stat = data[i], flag = 0;
324 if (stat & RXERROR_OVERRUN)
326 if (stat & RXERROR_FRAMING)
328 if (stat & RXERROR_PARITY)
330 /* XXX should handle break (0x10) */
331 tty_insert_flip_char(tty, data[i+1], flag);
334 tty_flip_buffer_push(tty);
338 /* Resubmit urb so we continue receiving */
339 err = usb_submit_urb(urb, GFP_ATOMIC);
341 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
344 /* Outdat handling is common for all devices */
345 static void usa2x_outdat_callback(struct urb *urb)
347 struct usb_serial_port *port;
348 struct keyspan_port_private *p_priv;
351 p_priv = usb_get_serial_port_data(port);
352 dev_dbg(&port->dev, "%s - urb %d\n", __func__, urb == p_priv->out_urbs[1]);
354 usb_serial_port_softint(port);
357 static void usa26_inack_callback(struct urb *urb)
361 static void usa26_outcont_callback(struct urb *urb)
363 struct usb_serial_port *port;
364 struct keyspan_port_private *p_priv;
367 p_priv = usb_get_serial_port_data(port);
369 if (p_priv->resend_cont) {
370 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
371 keyspan_usa26_send_setup(port->serial, port,
372 p_priv->resend_cont - 1);
376 static void usa26_instat_callback(struct urb *urb)
378 unsigned char *data = urb->transfer_buffer;
379 struct keyspan_usa26_portStatusMessage *msg;
380 struct usb_serial *serial;
381 struct usb_serial_port *port;
382 struct keyspan_port_private *p_priv;
383 struct tty_struct *tty;
384 int old_dcd_state, err;
385 int status = urb->status;
387 serial = urb->context;
390 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
393 if (urb->actual_length != 9) {
394 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
398 msg = (struct keyspan_usa26_portStatusMessage *)data;
401 dev_dbg(&urb->dev->dev,
402 "%s - port status: port %d cts %d dcd %d dsr %d ri %d toff %d txoff %d rxen %d cr %d",
403 __func__, msg->port, msg->hskia_cts, msg->gpia_dcd, msg->dsr,
404 msg->ri, msg->_txOff, msg->_txXoff, msg->rxEnabled,
405 msg->controlResponse);
408 /* Now do something useful with the data */
411 /* Check port number from message and retrieve private data */
412 if (msg->port >= serial->num_ports) {
413 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
416 port = serial->port[msg->port];
417 p_priv = usb_get_serial_port_data(port);
419 /* Update handshaking pin state information */
420 old_dcd_state = p_priv->dcd_state;
421 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
422 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
423 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
424 p_priv->ri_state = ((msg->ri) ? 1 : 0);
426 if (old_dcd_state != p_priv->dcd_state) {
427 tty = tty_port_tty_get(&port->port);
428 if (tty && !C_CLOCAL(tty))
433 /* Resubmit urb so we continue receiving */
434 err = usb_submit_urb(urb, GFP_ATOMIC);
436 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
440 static void usa26_glocont_callback(struct urb *urb)
445 static void usa28_indat_callback(struct urb *urb)
448 struct usb_serial_port *port;
449 struct tty_struct *tty;
451 struct keyspan_port_private *p_priv;
452 int status = urb->status;
455 p_priv = usb_get_serial_port_data(port);
456 data = urb->transfer_buffer;
458 if (urb != p_priv->in_urbs[p_priv->in_flip])
463 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
464 __func__, status, usb_pipeendpoint(urb->pipe));
469 p_priv = usb_get_serial_port_data(port);
470 data = urb->transfer_buffer;
472 tty = tty_port_tty_get(&port->port);
473 if (tty && urb->actual_length) {
474 tty_insert_flip_string(tty, data, urb->actual_length);
475 tty_flip_buffer_push(tty);
479 /* Resubmit urb so we continue receiving */
480 err = usb_submit_urb(urb, GFP_ATOMIC);
482 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n",
484 p_priv->in_flip ^= 1;
486 urb = p_priv->in_urbs[p_priv->in_flip];
487 } while (urb->status != -EINPROGRESS);
490 static void usa28_inack_callback(struct urb *urb)
494 static void usa28_outcont_callback(struct urb *urb)
496 struct usb_serial_port *port;
497 struct keyspan_port_private *p_priv;
500 p_priv = usb_get_serial_port_data(port);
502 if (p_priv->resend_cont) {
503 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
504 keyspan_usa28_send_setup(port->serial, port,
505 p_priv->resend_cont - 1);
509 static void usa28_instat_callback(struct urb *urb)
512 unsigned char *data = urb->transfer_buffer;
513 struct keyspan_usa28_portStatusMessage *msg;
514 struct usb_serial *serial;
515 struct usb_serial_port *port;
516 struct keyspan_port_private *p_priv;
517 struct tty_struct *tty;
519 int status = urb->status;
521 serial = urb->context;
524 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
528 if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) {
529 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
534 dev_dbg(&urb->dev->dev,
535 "%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__,
536 data[0], data[1], data[2], data[3], data[4], data[5],
537 data[6], data[7], data[8], data[9], data[10], data[11]);
540 /* Now do something useful with the data */
541 msg = (struct keyspan_usa28_portStatusMessage *)data;
543 /* Check port number from message and retrieve private data */
544 if (msg->port >= serial->num_ports) {
545 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
548 port = serial->port[msg->port];
549 p_priv = usb_get_serial_port_data(port);
551 /* Update handshaking pin state information */
552 old_dcd_state = p_priv->dcd_state;
553 p_priv->cts_state = ((msg->cts) ? 1 : 0);
554 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
555 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
556 p_priv->ri_state = ((msg->ri) ? 1 : 0);
558 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
559 tty = tty_port_tty_get(&port->port);
560 if (tty && !C_CLOCAL(tty))
565 /* Resubmit urb so we continue receiving */
566 err = usb_submit_urb(urb, GFP_ATOMIC);
568 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
572 static void usa28_glocont_callback(struct urb *urb)
577 static void usa49_glocont_callback(struct urb *urb)
579 struct usb_serial *serial;
580 struct usb_serial_port *port;
581 struct keyspan_port_private *p_priv;
584 serial = urb->context;
585 for (i = 0; i < serial->num_ports; ++i) {
586 port = serial->port[i];
587 p_priv = usb_get_serial_port_data(port);
589 if (p_priv->resend_cont) {
590 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
591 keyspan_usa49_send_setup(serial, port,
592 p_priv->resend_cont - 1);
598 /* This is actually called glostat in the Keyspan
600 static void usa49_instat_callback(struct urb *urb)
603 unsigned char *data = urb->transfer_buffer;
604 struct keyspan_usa49_portStatusMessage *msg;
605 struct usb_serial *serial;
606 struct usb_serial_port *port;
607 struct keyspan_port_private *p_priv;
609 int status = urb->status;
611 serial = urb->context;
614 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
618 if (urb->actual_length !=
619 sizeof(struct keyspan_usa49_portStatusMessage)) {
620 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
625 dev_dbg(&urb->dev->dev, "%s: %x %x %x %x %x %x %x %x %x %x %x",
626 __func__, data[0], data[1], data[2], data[3], data[4],
627 data[5], data[6], data[7], data[8], data[9], data[10]);
630 /* Now do something useful with the data */
631 msg = (struct keyspan_usa49_portStatusMessage *)data;
633 /* Check port number from message and retrieve private data */
634 if (msg->portNumber >= serial->num_ports) {
635 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
636 __func__, msg->portNumber);
639 port = serial->port[msg->portNumber];
640 p_priv = usb_get_serial_port_data(port);
642 /* Update handshaking pin state information */
643 old_dcd_state = p_priv->dcd_state;
644 p_priv->cts_state = ((msg->cts) ? 1 : 0);
645 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
646 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
647 p_priv->ri_state = ((msg->ri) ? 1 : 0);
649 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
650 struct tty_struct *tty = tty_port_tty_get(&port->port);
651 if (tty && !C_CLOCAL(tty))
656 /* Resubmit urb so we continue receiving */
657 err = usb_submit_urb(urb, GFP_ATOMIC);
659 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
663 static void usa49_inack_callback(struct urb *urb)
667 static void usa49_indat_callback(struct urb *urb)
671 struct usb_serial_port *port;
672 struct tty_struct *tty;
673 unsigned char *data = urb->transfer_buffer;
674 int status = urb->status;
676 endpoint = usb_pipeendpoint(urb->pipe);
679 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
680 __func__, status, endpoint);
685 tty = tty_port_tty_get(&port->port);
686 if (tty && urb->actual_length) {
687 /* 0x80 bit is error flag */
688 if ((data[0] & 0x80) == 0) {
689 /* no error on any byte */
690 tty_insert_flip_string(tty, data + 1,
691 urb->actual_length - 1);
693 /* some bytes had errors, every byte has status */
694 for (i = 0; i + 1 < urb->actual_length; i += 2) {
695 int stat = data[i], flag = 0;
696 if (stat & RXERROR_OVERRUN)
698 if (stat & RXERROR_FRAMING)
700 if (stat & RXERROR_PARITY)
702 /* XXX should handle break (0x10) */
703 tty_insert_flip_char(tty, data[i+1], flag);
706 tty_flip_buffer_push(tty);
710 /* Resubmit urb so we continue receiving */
711 err = usb_submit_urb(urb, GFP_ATOMIC);
713 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
716 static void usa49wg_indat_callback(struct urb *urb)
719 struct usb_serial *serial;
720 struct usb_serial_port *port;
721 struct tty_struct *tty;
722 unsigned char *data = urb->transfer_buffer;
723 int status = urb->status;
725 serial = urb->context;
728 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
732 /* inbound data is in the form P#, len, status, data */
736 if (urb->actual_length) {
737 while (i < urb->actual_length) {
739 /* Check port number from message*/
740 if (data[i] >= serial->num_ports) {
741 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
745 port = serial->port[data[i++]];
746 tty = tty_port_tty_get(&port->port);
749 /* 0x80 bit is error flag */
750 if ((data[i] & 0x80) == 0) {
751 /* no error on any byte */
753 for (x = 1; x < len ; ++x)
754 tty_insert_flip_char(tty, data[i++], 0);
757 * some bytes had errors, every byte has status
759 for (x = 0; x + 1 < len; x += 2) {
760 int stat = data[i], flag = 0;
761 if (stat & RXERROR_OVERRUN)
763 if (stat & RXERROR_FRAMING)
765 if (stat & RXERROR_PARITY)
767 /* XXX should handle break (0x10) */
768 tty_insert_flip_char(tty,
773 tty_flip_buffer_push(tty);
778 /* Resubmit urb so we continue receiving */
779 err = usb_submit_urb(urb, GFP_ATOMIC);
781 dev_dbg(&urb->dev->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
784 /* not used, usa-49 doesn't have per-port control endpoints */
785 static void usa49_outcont_callback(struct urb *urb)
789 static void usa90_indat_callback(struct urb *urb)
793 struct usb_serial_port *port;
794 struct keyspan_port_private *p_priv;
795 struct tty_struct *tty;
796 unsigned char *data = urb->transfer_buffer;
797 int status = urb->status;
799 endpoint = usb_pipeendpoint(urb->pipe);
802 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
803 __func__, status, endpoint);
808 p_priv = usb_get_serial_port_data(port);
810 if (urb->actual_length) {
811 tty = tty_port_tty_get(&port->port);
812 /* if current mode is DMA, looks like usa28 format
813 otherwise looks like usa26 data format */
815 if (p_priv->baud > 57600)
816 tty_insert_flip_string(tty, data, urb->actual_length);
818 /* 0x80 bit is error flag */
819 if ((data[0] & 0x80) == 0) {
820 /* no errors on individual bytes, only
821 possible overrun err*/
822 if (data[0] & RXERROR_OVERRUN)
826 for (i = 1; i < urb->actual_length ; ++i)
827 tty_insert_flip_char(tty, data[i],
830 /* some bytes had errors, every byte has status */
831 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
832 for (i = 0; i + 1 < urb->actual_length; i += 2) {
833 int stat = data[i], flag = 0;
834 if (stat & RXERROR_OVERRUN)
836 if (stat & RXERROR_FRAMING)
838 if (stat & RXERROR_PARITY)
840 /* XXX should handle break (0x10) */
841 tty_insert_flip_char(tty, data[i+1],
846 tty_flip_buffer_push(tty);
850 /* Resubmit urb so we continue receiving */
851 err = usb_submit_urb(urb, GFP_ATOMIC);
853 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
857 static void usa90_instat_callback(struct urb *urb)
859 unsigned char *data = urb->transfer_buffer;
860 struct keyspan_usa90_portStatusMessage *msg;
861 struct usb_serial *serial;
862 struct usb_serial_port *port;
863 struct keyspan_port_private *p_priv;
864 struct tty_struct *tty;
865 int old_dcd_state, err;
866 int status = urb->status;
868 serial = urb->context;
871 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
874 if (urb->actual_length < 14) {
875 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
879 msg = (struct keyspan_usa90_portStatusMessage *)data;
881 /* Now do something useful with the data */
883 port = serial->port[0];
884 p_priv = usb_get_serial_port_data(port);
886 /* Update handshaking pin state information */
887 old_dcd_state = p_priv->dcd_state;
888 p_priv->cts_state = ((msg->cts) ? 1 : 0);
889 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
890 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
891 p_priv->ri_state = ((msg->ri) ? 1 : 0);
893 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
894 tty = tty_port_tty_get(&port->port);
895 if (tty && !C_CLOCAL(tty))
900 /* Resubmit urb so we continue receiving */
901 err = usb_submit_urb(urb, GFP_ATOMIC);
903 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
908 static void usa90_outcont_callback(struct urb *urb)
910 struct usb_serial_port *port;
911 struct keyspan_port_private *p_priv;
914 p_priv = usb_get_serial_port_data(port);
916 if (p_priv->resend_cont) {
917 dev_dbg(&urb->dev->dev, "%s - sending setup\n", __func__);
918 keyspan_usa90_send_setup(port->serial, port,
919 p_priv->resend_cont - 1);
923 /* Status messages from the 28xg */
924 static void usa67_instat_callback(struct urb *urb)
927 unsigned char *data = urb->transfer_buffer;
928 struct keyspan_usa67_portStatusMessage *msg;
929 struct usb_serial *serial;
930 struct usb_serial_port *port;
931 struct keyspan_port_private *p_priv;
933 int status = urb->status;
935 serial = urb->context;
938 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
942 if (urb->actual_length !=
943 sizeof(struct keyspan_usa67_portStatusMessage)) {
944 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
949 /* Now do something useful with the data */
950 msg = (struct keyspan_usa67_portStatusMessage *)data;
952 /* Check port number from message and retrieve private data */
953 if (msg->port >= serial->num_ports) {
954 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
958 port = serial->port[msg->port];
959 p_priv = usb_get_serial_port_data(port);
961 /* Update handshaking pin state information */
962 old_dcd_state = p_priv->dcd_state;
963 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
964 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
966 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
967 struct tty_struct *tty = tty_port_tty_get(&port->port);
968 if (tty && !C_CLOCAL(tty))
973 /* Resubmit urb so we continue receiving */
974 err = usb_submit_urb(urb, GFP_ATOMIC);
976 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
979 static void usa67_glocont_callback(struct urb *urb)
981 struct usb_serial *serial;
982 struct usb_serial_port *port;
983 struct keyspan_port_private *p_priv;
986 serial = urb->context;
987 for (i = 0; i < serial->num_ports; ++i) {
988 port = serial->port[i];
989 p_priv = usb_get_serial_port_data(port);
991 if (p_priv->resend_cont) {
992 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
993 keyspan_usa67_send_setup(serial, port,
994 p_priv->resend_cont - 1);
1000 static int keyspan_write_room(struct tty_struct *tty)
1002 struct usb_serial_port *port = tty->driver_data;
1003 struct keyspan_port_private *p_priv;
1004 const struct keyspan_device_details *d_details;
1007 struct urb *this_urb;
1009 p_priv = usb_get_serial_port_data(port);
1010 d_details = p_priv->device_details;
1012 /* FIXME: locking */
1013 if (d_details->msg_format == msg_usa90)
1018 flip = p_priv->out_flip;
1020 /* Check both endpoints to see if any are available. */
1021 this_urb = p_priv->out_urbs[flip];
1022 if (this_urb != NULL) {
1023 if (this_urb->status != -EINPROGRESS)
1025 flip = (flip + 1) & d_details->outdat_endp_flip;
1026 this_urb = p_priv->out_urbs[flip];
1027 if (this_urb != NULL) {
1028 if (this_urb->status != -EINPROGRESS)
1036 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1038 struct keyspan_port_private *p_priv;
1039 const struct keyspan_device_details *d_details;
1041 int baud_rate, device_port;
1043 unsigned int cflag = 0;
1045 p_priv = usb_get_serial_port_data(port);
1046 d_details = p_priv->device_details;
1048 /* Set some sane defaults */
1049 p_priv->rts_state = 1;
1050 p_priv->dtr_state = 1;
1051 p_priv->baud = 9600;
1053 /* force baud and lcr to be set on open */
1054 p_priv->old_baud = 0;
1055 p_priv->old_cflag = 0;
1057 p_priv->out_flip = 0;
1058 p_priv->in_flip = 0;
1060 /* Reset low level data toggle and start reading from endpoints */
1061 for (i = 0; i < 2; i++) {
1062 urb = p_priv->in_urbs[i];
1066 /* make sure endpoint data toggle is synchronized
1068 usb_clear_halt(urb->dev, urb->pipe);
1069 err = usb_submit_urb(urb, GFP_KERNEL);
1071 dev_dbg(&port->dev, "%s - submit urb %d failed (%d)\n", __func__, i, err);
1074 /* Reset low level data toggle on out endpoints */
1075 for (i = 0; i < 2; i++) {
1076 urb = p_priv->out_urbs[i];
1079 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1080 usb_pipeout(urb->pipe), 0); */
1083 /* get the terminal config for the setup message now so we don't
1084 * need to send 2 of them */
1086 device_port = port->number - port->serial->minor;
1088 cflag = tty->termios.c_cflag;
1089 /* Baud rate calculation takes baud rate as an integer
1090 so other rates can be generated if desired. */
1091 baud_rate = tty_get_baud_rate(tty);
1092 /* If no match or invalid, leave as default */
1094 && d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
1095 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1096 p_priv->baud = baud_rate;
1099 /* set CTS/RTS handshake etc. */
1100 p_priv->cflag = cflag;
1101 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
1103 keyspan_send_setup(port, 1);
1105 /* keyspan_set_termios(port, NULL); */
1110 static inline void stop_urb(struct urb *urb)
1112 if (urb && urb->status == -EINPROGRESS)
1116 static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1118 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
1120 p_priv->rts_state = on;
1121 p_priv->dtr_state = on;
1122 keyspan_send_setup(port, 0);
1125 static void keyspan_close(struct usb_serial_port *port)
1128 struct usb_serial *serial = port->serial;
1129 struct keyspan_port_private *p_priv;
1131 p_priv = usb_get_serial_port_data(port);
1133 p_priv->rts_state = 0;
1134 p_priv->dtr_state = 0;
1137 keyspan_send_setup(port, 2);
1138 /* pilot-xfer seems to work best with this delay */
1140 /* keyspan_set_termios(port, NULL); */
1143 /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
1144 dev_dbg(&port->dev, "%s - urb in progress\n", __func__);
1147 p_priv->out_flip = 0;
1148 p_priv->in_flip = 0;
1151 /* Stop reading/writing urbs */
1152 stop_urb(p_priv->inack_urb);
1153 /* stop_urb(p_priv->outcont_urb); */
1154 for (i = 0; i < 2; i++) {
1155 stop_urb(p_priv->in_urbs[i]);
1156 stop_urb(p_priv->out_urbs[i]);
1161 /* download the firmware to a pre-renumeration device */
1162 static int keyspan_fake_startup(struct usb_serial *serial)
1166 dev_dbg(&serial->dev->dev, "Keyspan startup version %04x product %04x\n",
1167 le16_to_cpu(serial->dev->descriptor.bcdDevice),
1168 le16_to_cpu(serial->dev->descriptor.idProduct));
1170 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
1172 dev_dbg(&serial->dev->dev, "Firmware already loaded. Quitting.\n");
1176 /* Select firmware image on the basis of idProduct */
1177 switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {
1178 case keyspan_usa28_pre_product_id:
1179 fw_name = "keyspan/usa28.fw";
1182 case keyspan_usa28x_pre_product_id:
1183 fw_name = "keyspan/usa28x.fw";
1186 case keyspan_usa28xa_pre_product_id:
1187 fw_name = "keyspan/usa28xa.fw";
1190 case keyspan_usa28xb_pre_product_id:
1191 fw_name = "keyspan/usa28xb.fw";
1194 case keyspan_usa19_pre_product_id:
1195 fw_name = "keyspan/usa19.fw";
1198 case keyspan_usa19qi_pre_product_id:
1199 fw_name = "keyspan/usa19qi.fw";
1202 case keyspan_mpr_pre_product_id:
1203 fw_name = "keyspan/mpr.fw";
1206 case keyspan_usa19qw_pre_product_id:
1207 fw_name = "keyspan/usa19qw.fw";
1210 case keyspan_usa18x_pre_product_id:
1211 fw_name = "keyspan/usa18x.fw";
1214 case keyspan_usa19w_pre_product_id:
1215 fw_name = "keyspan/usa19w.fw";
1218 case keyspan_usa49w_pre_product_id:
1219 fw_name = "keyspan/usa49w.fw";
1222 case keyspan_usa49wlc_pre_product_id:
1223 fw_name = "keyspan/usa49wlc.fw";
1227 dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n",
1228 le16_to_cpu(serial->dev->descriptor.idProduct));
1232 dev_dbg(&serial->dev->dev, "Uploading Keyspan %s firmware.\n", fw_name);
1234 if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
1235 dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
1240 /* after downloading firmware Renumeration will occur in a
1241 moment and the new device will bind to the real driver */
1243 /* we don't want this device to have a driver assigned to it. */
1247 /* Helper functions used by keyspan_setup_urbs */
1248 static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial,
1251 struct usb_host_interface *iface_desc;
1252 struct usb_endpoint_descriptor *ep;
1255 iface_desc = serial->interface->cur_altsetting;
1256 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1257 ep = &iface_desc->endpoint[i].desc;
1258 if (ep->bEndpointAddress == endpoint)
1261 dev_warn(&serial->interface->dev, "found no endpoint descriptor for "
1262 "endpoint %x\n", endpoint);
1266 static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1267 int dir, void *ctx, char *buf, int len,
1268 void (*callback)(struct urb *))
1271 struct usb_endpoint_descriptor const *ep_desc;
1272 char const *ep_type_name;
1275 return NULL; /* endpoint not needed */
1277 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d.\n", __func__, endpoint);
1278 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1280 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d failed.\n", __func__, endpoint);
1284 if (endpoint == 0) {
1285 /* control EP filled in when used */
1289 ep_desc = find_ep(serial, endpoint);
1291 /* leak the urb, something's wrong and the callers don't care */
1294 if (usb_endpoint_xfer_int(ep_desc)) {
1295 ep_type_name = "INT";
1296 usb_fill_int_urb(urb, serial->dev,
1297 usb_sndintpipe(serial->dev, endpoint) | dir,
1298 buf, len, callback, ctx,
1299 ep_desc->bInterval);
1300 } else if (usb_endpoint_xfer_bulk(ep_desc)) {
1301 ep_type_name = "BULK";
1302 usb_fill_bulk_urb(urb, serial->dev,
1303 usb_sndbulkpipe(serial->dev, endpoint) | dir,
1304 buf, len, callback, ctx);
1306 dev_warn(&serial->interface->dev,
1307 "unsupported endpoint type %x\n",
1308 usb_endpoint_type(ep_desc));
1313 dev_dbg(&serial->interface->dev, "%s - using urb %p for %s endpoint %x\n",
1314 __func__, urb, ep_type_name, endpoint);
1318 static struct callbacks {
1319 void (*instat_callback)(struct urb *);
1320 void (*glocont_callback)(struct urb *);
1321 void (*indat_callback)(struct urb *);
1322 void (*outdat_callback)(struct urb *);
1323 void (*inack_callback)(struct urb *);
1324 void (*outcont_callback)(struct urb *);
1325 } keyspan_callbacks[] = {
1327 /* msg_usa26 callbacks */
1328 .instat_callback = usa26_instat_callback,
1329 .glocont_callback = usa26_glocont_callback,
1330 .indat_callback = usa26_indat_callback,
1331 .outdat_callback = usa2x_outdat_callback,
1332 .inack_callback = usa26_inack_callback,
1333 .outcont_callback = usa26_outcont_callback,
1335 /* msg_usa28 callbacks */
1336 .instat_callback = usa28_instat_callback,
1337 .glocont_callback = usa28_glocont_callback,
1338 .indat_callback = usa28_indat_callback,
1339 .outdat_callback = usa2x_outdat_callback,
1340 .inack_callback = usa28_inack_callback,
1341 .outcont_callback = usa28_outcont_callback,
1343 /* msg_usa49 callbacks */
1344 .instat_callback = usa49_instat_callback,
1345 .glocont_callback = usa49_glocont_callback,
1346 .indat_callback = usa49_indat_callback,
1347 .outdat_callback = usa2x_outdat_callback,
1348 .inack_callback = usa49_inack_callback,
1349 .outcont_callback = usa49_outcont_callback,
1351 /* msg_usa90 callbacks */
1352 .instat_callback = usa90_instat_callback,
1353 .glocont_callback = usa28_glocont_callback,
1354 .indat_callback = usa90_indat_callback,
1355 .outdat_callback = usa2x_outdat_callback,
1356 .inack_callback = usa28_inack_callback,
1357 .outcont_callback = usa90_outcont_callback,
1359 /* msg_usa67 callbacks */
1360 .instat_callback = usa67_instat_callback,
1361 .glocont_callback = usa67_glocont_callback,
1362 .indat_callback = usa26_indat_callback,
1363 .outdat_callback = usa2x_outdat_callback,
1364 .inack_callback = usa26_inack_callback,
1365 .outcont_callback = usa26_outcont_callback,
1369 /* Generic setup urbs function that uses
1370 data in device_details */
1371 static void keyspan_setup_urbs(struct usb_serial *serial)
1373 struct keyspan_serial_private *s_priv;
1374 const struct keyspan_device_details *d_details;
1375 struct callbacks *cback;
1377 s_priv = usb_get_serial_data(serial);
1378 d_details = s_priv->device_details;
1380 /* Setup values for the various callback routines */
1381 cback = &keyspan_callbacks[d_details->msg_format];
1383 /* Allocate and set up urbs for each one that is in use,
1384 starting with instat endpoints */
1385 s_priv->instat_urb = keyspan_setup_urb
1386 (serial, d_details->instat_endpoint, USB_DIR_IN,
1387 serial, s_priv->instat_buf, INSTAT_BUFLEN,
1388 cback->instat_callback);
1390 s_priv->indat_urb = keyspan_setup_urb
1391 (serial, d_details->indat_endpoint, USB_DIR_IN,
1392 serial, s_priv->indat_buf, INDAT49W_BUFLEN,
1393 usa49wg_indat_callback);
1395 s_priv->glocont_urb = keyspan_setup_urb
1396 (serial, d_details->glocont_endpoint, USB_DIR_OUT,
1397 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1398 cback->glocont_callback);
1401 /* usa19 function doesn't require prescaler */
1402 static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
1403 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1404 u8 *rate_low, u8 *prescaler, int portnum)
1406 u32 b16, /* baud rate times 16 (actual rate used internally) */
1408 cnt; /* inverse of divisor (programmed into 8051) */
1410 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1412 /* prevent divide by zero... */
1413 b16 = baud_rate * 16L;
1415 return KEYSPAN_INVALID_BAUD_RATE;
1416 /* Any "standard" rate over 57k6 is marginal on the USA-19
1417 as we run out of divisor resolution. */
1418 if (baud_rate > 57600)
1419 return KEYSPAN_INVALID_BAUD_RATE;
1421 /* calculate the divisor and the counter (its inverse) */
1422 div = baudclk / b16;
1424 return KEYSPAN_INVALID_BAUD_RATE;
1429 return KEYSPAN_INVALID_BAUD_RATE;
1431 /* return the counter values if non-null */
1433 *rate_low = (u8) (cnt & 0xff);
1435 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1436 if (rate_low && rate_hi)
1437 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1438 __func__, baud_rate, *rate_hi, *rate_low);
1439 return KEYSPAN_BAUD_RATE_OK;
1442 /* usa19hs function doesn't require prescaler */
1443 static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
1444 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1445 u8 *rate_low, u8 *prescaler, int portnum)
1447 u32 b16, /* baud rate times 16 (actual rate used internally) */
1450 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1452 /* prevent divide by zero... */
1453 b16 = baud_rate * 16L;
1455 return KEYSPAN_INVALID_BAUD_RATE;
1457 /* calculate the divisor */
1458 div = baudclk / b16;
1460 return KEYSPAN_INVALID_BAUD_RATE;
1463 return KEYSPAN_INVALID_BAUD_RATE;
1465 /* return the counter values if non-null */
1467 *rate_low = (u8) (div & 0xff);
1470 *rate_hi = (u8) ((div >> 8) & 0xff);
1472 if (rate_low && rate_hi)
1473 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1474 __func__, baud_rate, *rate_hi, *rate_low);
1476 return KEYSPAN_BAUD_RATE_OK;
1479 static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
1480 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1481 u8 *rate_low, u8 *prescaler, int portnum)
1483 u32 b16, /* baud rate times 16 (actual rate used internally) */
1484 clk, /* clock with 13/8 prescaler */
1485 div, /* divisor using 13/8 prescaler */
1486 res, /* resulting baud rate using 13/8 prescaler */
1487 diff, /* error using 13/8 prescaler */
1492 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1494 /* prevent divide by zero */
1495 b16 = baud_rate * 16L;
1497 return KEYSPAN_INVALID_BAUD_RATE;
1499 /* Calculate prescaler by trying them all and looking
1502 /* start with largest possible difference */
1503 smallest_diff = 0xffffffff;
1505 /* 0 is an invalid prescaler, used as a flag */
1508 for (i = 8; i <= 0xff; ++i) {
1509 clk = (baudclk * 8) / (u32) i;
1516 diff = (res > b16) ? (res-b16) : (b16-res);
1518 if (diff < smallest_diff) {
1520 smallest_diff = diff;
1524 if (best_prescaler == 0)
1525 return KEYSPAN_INVALID_BAUD_RATE;
1527 clk = (baudclk * 8) / (u32) best_prescaler;
1530 /* return the divisor and prescaler if non-null */
1532 *rate_low = (u8) (div & 0xff);
1534 *rate_hi = (u8) ((div >> 8) & 0xff);
1536 *prescaler = best_prescaler;
1537 /* dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
1539 return KEYSPAN_BAUD_RATE_OK;
1542 /* USA-28 supports different maximum baud rates on each port */
1543 static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
1544 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1545 u8 *rate_low, u8 *prescaler, int portnum)
1547 u32 b16, /* baud rate times 16 (actual rate used internally) */
1549 cnt; /* inverse of divisor (programmed into 8051) */
1551 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1553 /* prevent divide by zero */
1554 b16 = baud_rate * 16L;
1556 return KEYSPAN_INVALID_BAUD_RATE;
1558 /* calculate the divisor and the counter (its inverse) */
1559 div = KEYSPAN_USA28_BAUDCLK / b16;
1561 return KEYSPAN_INVALID_BAUD_RATE;
1565 /* check for out of range, based on portnum,
1566 and return result */
1569 return KEYSPAN_INVALID_BAUD_RATE;
1573 return KEYSPAN_INVALID_BAUD_RATE;
1575 return KEYSPAN_INVALID_BAUD_RATE;
1578 /* return the counter values if not NULL
1579 (port 1 will ignore retHi) */
1581 *rate_low = (u8) (cnt & 0xff);
1583 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1584 dev_dbg(&port->dev, "%s - %d OK.\n", __func__, baud_rate);
1585 return KEYSPAN_BAUD_RATE_OK;
1588 static int keyspan_usa26_send_setup(struct usb_serial *serial,
1589 struct usb_serial_port *port,
1592 struct keyspan_usa26_portControlMessage msg;
1593 struct keyspan_serial_private *s_priv;
1594 struct keyspan_port_private *p_priv;
1595 const struct keyspan_device_details *d_details;
1597 struct urb *this_urb;
1598 int device_port, err;
1600 dev_dbg(&port->dev, "%s reset=%d\n", __func__, reset_port);
1602 s_priv = usb_get_serial_data(serial);
1603 p_priv = usb_get_serial_port_data(port);
1604 d_details = s_priv->device_details;
1605 device_port = port->number - port->serial->minor;
1607 outcont_urb = d_details->outcont_endpoints[port->number];
1608 this_urb = p_priv->outcont_urb;
1610 dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
1612 /* Make sure we have an urb then send the message */
1613 if (this_urb == NULL) {
1614 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1618 /* Save reset port val for resend.
1619 Don't overwrite resend for open/close condition. */
1620 if ((reset_port + 1) > p_priv->resend_cont)
1621 p_priv->resend_cont = reset_port + 1;
1622 if (this_urb->status == -EINPROGRESS) {
1623 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1628 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1630 /* Only set baud rate if it's changed */
1631 if (p_priv->old_baud != p_priv->baud) {
1632 p_priv->old_baud = p_priv->baud;
1633 msg.setClocking = 0xff;
1634 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1635 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1636 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1637 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1638 __func__, p_priv->baud);
1640 msg.baudHi = 125; /* Values for 9600 baud */
1643 msg.setPrescaler = 0xff;
1646 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1647 switch (p_priv->cflag & CSIZE) {
1649 msg.lcr |= USA_DATABITS_5;
1652 msg.lcr |= USA_DATABITS_6;
1655 msg.lcr |= USA_DATABITS_7;
1658 msg.lcr |= USA_DATABITS_8;
1661 if (p_priv->cflag & PARENB) {
1662 /* note USA_PARITY_NONE == 0 */
1663 msg.lcr |= (p_priv->cflag & PARODD) ?
1664 USA_PARITY_ODD : USA_PARITY_EVEN;
1668 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1669 msg.xonFlowControl = 0;
1670 msg.setFlowControl = 0xff;
1671 msg.forwardingLength = 16;
1676 if (reset_port == 1) {
1685 msg.returnStatus = 0;
1686 msg.resetDataToggle = 0xff;
1690 else if (reset_port == 2) {
1699 msg.returnStatus = 0;
1700 msg.resetDataToggle = 0;
1703 /* Sending intermediate configs */
1705 msg._txOn = (!p_priv->break_on);
1708 msg.txBreak = (p_priv->break_on);
1713 msg.returnStatus = 0;
1714 msg.resetDataToggle = 0x0;
1717 /* Do handshaking outputs */
1718 msg.setTxTriState_setRts = 0xff;
1719 msg.txTriState_rts = p_priv->rts_state;
1721 msg.setHskoa_setDtr = 0xff;
1722 msg.hskoa_dtr = p_priv->dtr_state;
1724 p_priv->resend_cont = 0;
1725 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1727 /* send the data out the device on control endpoint */
1728 this_urb->transfer_buffer_length = sizeof(msg);
1730 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1732 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1735 dev_dbg(&port->dev, "%s - usb_submit_urb(%d) OK %d bytes (end %d)\n", __func__
1736 outcont_urb, this_urb->transfer_buffer_length,
1737 usb_pipeendpoint(this_urb->pipe));
1744 static int keyspan_usa28_send_setup(struct usb_serial *serial,
1745 struct usb_serial_port *port,
1748 struct keyspan_usa28_portControlMessage msg;
1749 struct keyspan_serial_private *s_priv;
1750 struct keyspan_port_private *p_priv;
1751 const struct keyspan_device_details *d_details;
1752 struct urb *this_urb;
1753 int device_port, err;
1755 s_priv = usb_get_serial_data(serial);
1756 p_priv = usb_get_serial_port_data(port);
1757 d_details = s_priv->device_details;
1758 device_port = port->number - port->serial->minor;
1760 /* only do something if we have a bulk out endpoint */
1761 this_urb = p_priv->outcont_urb;
1762 if (this_urb == NULL) {
1763 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1767 /* Save reset port val for resend.
1768 Don't overwrite resend for open/close condition. */
1769 if ((reset_port + 1) > p_priv->resend_cont)
1770 p_priv->resend_cont = reset_port + 1;
1771 if (this_urb->status == -EINPROGRESS) {
1772 dev_dbg(&port->dev, "%s already writing\n", __func__);
1777 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
1779 msg.setBaudRate = 1;
1780 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1781 &msg.baudHi, &msg.baudLo, NULL,
1782 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1783 dev_dbg(&port->dev, "%s - Invalid baud rate requested %d.\n",
1784 __func__, p_priv->baud);
1786 msg.baudHi = 0xb2; /* Values for 9600 baud */
1789 /* If parity is enabled, we must calculate it ourselves. */
1790 msg.parity = 0; /* XXX for now */
1792 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1793 msg.xonFlowControl = 0;
1795 /* Do handshaking outputs, DTR is inverted relative to RTS */
1796 msg.rts = p_priv->rts_state;
1797 msg.dtr = p_priv->dtr_state;
1799 msg.forwardingLength = 16;
1801 msg.breakThreshold = 45;
1805 /*msg.returnStatus = 1;
1806 msg.resetDataToggle = 0xff;*/
1808 if (reset_port == 1) {
1812 msg.txForceXoff = 0;
1818 msg.returnStatus = 0;
1819 msg.resetDataToggle = 0xff;
1822 else if (reset_port == 2) {
1826 msg.txForceXoff = 0;
1832 msg.returnStatus = 0;
1833 msg.resetDataToggle = 0;
1835 /* Sending intermediate configs */
1837 msg._txOn = (!p_priv->break_on);
1840 msg.txForceXoff = 0;
1841 msg.txBreak = (p_priv->break_on);
1846 msg.returnStatus = 0;
1847 msg.resetDataToggle = 0x0;
1850 p_priv->resend_cont = 0;
1851 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1853 /* send the data out the device on control endpoint */
1854 this_urb->transfer_buffer_length = sizeof(msg);
1856 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1858 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed\n", __func__);
1861 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) OK %d bytes\n", __func__,
1862 this_urb->transfer_buffer_length);
1869 static int keyspan_usa49_send_setup(struct usb_serial *serial,
1870 struct usb_serial_port *port,
1873 struct keyspan_usa49_portControlMessage msg;
1874 struct usb_ctrlrequest *dr = NULL;
1875 struct keyspan_serial_private *s_priv;
1876 struct keyspan_port_private *p_priv;
1877 const struct keyspan_device_details *d_details;
1878 struct urb *this_urb;
1879 int err, device_port;
1881 s_priv = usb_get_serial_data(serial);
1882 p_priv = usb_get_serial_port_data(port);
1883 d_details = s_priv->device_details;
1885 this_urb = s_priv->glocont_urb;
1887 /* Work out which port within the device is being setup */
1888 device_port = port->number - port->serial->minor;
1890 /* Make sure we have an urb then send the message */
1891 if (this_urb == NULL) {
1892 dev_dbg(&port->dev, "%s - oops no urb for port %d.\n", __func__, port->number);
1896 dev_dbg(&port->dev, "%s - endpoint %d port %d (%d)\n",
1897 __func__, usb_pipeendpoint(this_urb->pipe),
1898 port->number, device_port);
1900 /* Save reset port val for resend.
1901 Don't overwrite resend for open/close condition. */
1902 if ((reset_port + 1) > p_priv->resend_cont)
1903 p_priv->resend_cont = reset_port + 1;
1905 if (this_urb->status == -EINPROGRESS) {
1906 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1911 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
1913 /*msg.portNumber = port->number;*/
1914 msg.portNumber = device_port;
1916 /* Only set baud rate if it's changed */
1917 if (p_priv->old_baud != p_priv->baud) {
1918 p_priv->old_baud = p_priv->baud;
1919 msg.setClocking = 0xff;
1920 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1921 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1922 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1923 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1924 __func__, p_priv->baud);
1926 msg.baudHi = 125; /* Values for 9600 baud */
1929 /* msg.setPrescaler = 0xff; */
1932 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1933 switch (p_priv->cflag & CSIZE) {
1935 msg.lcr |= USA_DATABITS_5;
1938 msg.lcr |= USA_DATABITS_6;
1941 msg.lcr |= USA_DATABITS_7;
1944 msg.lcr |= USA_DATABITS_8;
1947 if (p_priv->cflag & PARENB) {
1948 /* note USA_PARITY_NONE == 0 */
1949 msg.lcr |= (p_priv->cflag & PARODD) ?
1950 USA_PARITY_ODD : USA_PARITY_EVEN;
1954 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1955 msg.xonFlowControl = 0;
1956 msg.setFlowControl = 0xff;
1958 msg.forwardingLength = 16;
1963 if (reset_port == 1) {
1972 msg.returnStatus = 0;
1973 msg.resetDataToggle = 0xff;
1975 msg.disablePort = 0;
1978 else if (reset_port == 2) {
1987 msg.returnStatus = 0;
1988 msg.resetDataToggle = 0;
1990 msg.disablePort = 1;
1992 /* Sending intermediate configs */
1994 msg._txOn = (!p_priv->break_on);
1997 msg.txBreak = (p_priv->break_on);
2002 msg.returnStatus = 0;
2003 msg.resetDataToggle = 0x0;
2005 msg.disablePort = 0;
2008 /* Do handshaking outputs */
2010 msg.rts = p_priv->rts_state;
2013 msg.dtr = p_priv->dtr_state;
2015 p_priv->resend_cont = 0;
2017 /* if the device is a 49wg, we send control message on usb
2020 if (d_details->product_id == keyspan_usa49wg_product_id) {
2021 dr = (void *)(s_priv->ctrl_buf);
2022 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
2023 dr->bRequest = 0xB0; /* 49wg control message */;
2026 dr->wLength = cpu_to_le16(sizeof(msg));
2028 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
2030 usb_fill_control_urb(this_urb, serial->dev,
2031 usb_sndctrlpipe(serial->dev, 0),
2032 (unsigned char *)dr, s_priv->glocont_buf,
2033 sizeof(msg), usa49_glocont_callback, serial);
2036 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2038 /* send the data out the device on control endpoint */
2039 this_urb->transfer_buffer_length = sizeof(msg);
2041 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2043 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2046 dev_dbg(&port->dev, "%s - usb_submit_urb(%d) OK %d bytes (end %d)\n", __func__,
2047 outcont_urb, this_urb->transfer_buffer_length,
2048 usb_pipeendpoint(this_urb->pipe));
2055 static int keyspan_usa90_send_setup(struct usb_serial *serial,
2056 struct usb_serial_port *port,
2059 struct keyspan_usa90_portControlMessage msg;
2060 struct keyspan_serial_private *s_priv;
2061 struct keyspan_port_private *p_priv;
2062 const struct keyspan_device_details *d_details;
2063 struct urb *this_urb;
2067 s_priv = usb_get_serial_data(serial);
2068 p_priv = usb_get_serial_port_data(port);
2069 d_details = s_priv->device_details;
2071 /* only do something if we have a bulk out endpoint */
2072 this_urb = p_priv->outcont_urb;
2073 if (this_urb == NULL) {
2074 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
2078 /* Save reset port val for resend.
2079 Don't overwrite resend for open/close condition. */
2080 if ((reset_port + 1) > p_priv->resend_cont)
2081 p_priv->resend_cont = reset_port + 1;
2082 if (this_urb->status == -EINPROGRESS) {
2083 dev_dbg(&port->dev, "%s already writing\n", __func__);
2088 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2090 /* Only set baud rate if it's changed */
2091 if (p_priv->old_baud != p_priv->baud) {
2092 p_priv->old_baud = p_priv->baud;
2093 msg.setClocking = 0x01;
2094 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2095 &msg.baudHi, &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2096 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2097 __func__, p_priv->baud);
2098 p_priv->baud = 9600;
2099 d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2100 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2106 /* modes must always be correctly specified */
2107 if (p_priv->baud > 57600) {
2108 msg.rxMode = RXMODE_DMA;
2109 msg.txMode = TXMODE_DMA;
2111 msg.rxMode = RXMODE_BYHAND;
2112 msg.txMode = TXMODE_BYHAND;
2115 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2116 switch (p_priv->cflag & CSIZE) {
2118 msg.lcr |= USA_DATABITS_5;
2121 msg.lcr |= USA_DATABITS_6;
2124 msg.lcr |= USA_DATABITS_7;
2127 msg.lcr |= USA_DATABITS_8;
2130 if (p_priv->cflag & PARENB) {
2131 /* note USA_PARITY_NONE == 0 */
2132 msg.lcr |= (p_priv->cflag & PARODD) ?
2133 USA_PARITY_ODD : USA_PARITY_EVEN;
2135 if (p_priv->old_cflag != p_priv->cflag) {
2136 p_priv->old_cflag = p_priv->cflag;
2140 if (p_priv->flow_control == flow_cts)
2141 msg.txFlowControl = TXFLOW_CTS;
2142 msg.setTxFlowControl = 0x01;
2143 msg.setRxFlowControl = 0x01;
2145 msg.rxForwardingLength = 16;
2146 msg.rxForwardingTimeout = 16;
2147 msg.txAckSetting = 0;
2152 if (reset_port == 1) {
2153 msg.portEnabled = 1;
2155 msg.txBreak = (p_priv->break_on);
2158 else if (reset_port == 2)
2159 msg.portEnabled = 0;
2160 /* Sending intermediate configs */
2162 msg.portEnabled = 1;
2163 msg.txBreak = (p_priv->break_on);
2166 /* Do handshaking outputs */
2168 msg.rts = p_priv->rts_state;
2171 msg.dtr = p_priv->dtr_state;
2173 p_priv->resend_cont = 0;
2174 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2176 /* send the data out the device on control endpoint */
2177 this_urb->transfer_buffer_length = sizeof(msg);
2179 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2181 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2185 static int keyspan_usa67_send_setup(struct usb_serial *serial,
2186 struct usb_serial_port *port,
2189 struct keyspan_usa67_portControlMessage msg;
2190 struct keyspan_serial_private *s_priv;
2191 struct keyspan_port_private *p_priv;
2192 const struct keyspan_device_details *d_details;
2193 struct urb *this_urb;
2194 int err, device_port;
2196 s_priv = usb_get_serial_data(serial);
2197 p_priv = usb_get_serial_port_data(port);
2198 d_details = s_priv->device_details;
2200 this_urb = s_priv->glocont_urb;
2202 /* Work out which port within the device is being setup */
2203 device_port = port->number - port->serial->minor;
2205 /* Make sure we have an urb then send the message */
2206 if (this_urb == NULL) {
2207 dev_dbg(&port->dev, "%s - oops no urb for port %d.\n", __func__,
2212 /* Save reset port val for resend.
2213 Don't overwrite resend for open/close condition. */
2214 if ((reset_port + 1) > p_priv->resend_cont)
2215 p_priv->resend_cont = reset_port + 1;
2216 if (this_urb->status == -EINPROGRESS) {
2217 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2222 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
2224 msg.port = device_port;
2226 /* Only set baud rate if it's changed */
2227 if (p_priv->old_baud != p_priv->baud) {
2228 p_priv->old_baud = p_priv->baud;
2229 msg.setClocking = 0xff;
2230 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2231 &msg.baudHi, &msg.baudLo, &msg.prescaler,
2232 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2233 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2234 __func__, p_priv->baud);
2236 msg.baudHi = 125; /* Values for 9600 baud */
2239 msg.setPrescaler = 0xff;
2242 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2243 switch (p_priv->cflag & CSIZE) {
2245 msg.lcr |= USA_DATABITS_5;
2248 msg.lcr |= USA_DATABITS_6;
2251 msg.lcr |= USA_DATABITS_7;
2254 msg.lcr |= USA_DATABITS_8;
2257 if (p_priv->cflag & PARENB) {
2258 /* note USA_PARITY_NONE == 0 */
2259 msg.lcr |= (p_priv->cflag & PARODD) ?
2260 USA_PARITY_ODD : USA_PARITY_EVEN;
2264 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2265 msg.xonFlowControl = 0;
2266 msg.setFlowControl = 0xff;
2267 msg.forwardingLength = 16;
2271 if (reset_port == 1) {
2281 msg.returnStatus = 0;
2282 msg.resetDataToggle = 0xff;
2283 } else if (reset_port == 2) {
2293 msg.returnStatus = 0;
2294 msg.resetDataToggle = 0;
2296 /* Sending intermediate configs */
2297 msg._txOn = (!p_priv->break_on);
2300 msg.txBreak = (p_priv->break_on);
2305 msg.returnStatus = 0;
2306 msg.resetDataToggle = 0x0;
2309 /* Do handshaking outputs */
2310 msg.setTxTriState_setRts = 0xff;
2311 msg.txTriState_rts = p_priv->rts_state;
2313 msg.setHskoa_setDtr = 0xff;
2314 msg.hskoa_dtr = p_priv->dtr_state;
2316 p_priv->resend_cont = 0;
2318 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2320 /* send the data out the device on control endpoint */
2321 this_urb->transfer_buffer_length = sizeof(msg);
2323 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2325 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2329 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2331 struct usb_serial *serial = port->serial;
2332 struct keyspan_serial_private *s_priv;
2333 const struct keyspan_device_details *d_details;
2335 s_priv = usb_get_serial_data(serial);
2336 d_details = s_priv->device_details;
2338 switch (d_details->msg_format) {
2340 keyspan_usa26_send_setup(serial, port, reset_port);
2343 keyspan_usa28_send_setup(serial, port, reset_port);
2346 keyspan_usa49_send_setup(serial, port, reset_port);
2349 keyspan_usa90_send_setup(serial, port, reset_port);
2352 keyspan_usa67_send_setup(serial, port, reset_port);
2358 /* Gets called by the "real" driver (ie once firmware is loaded
2359 and renumeration has taken place. */
2360 static int keyspan_startup(struct usb_serial *serial)
2363 struct keyspan_serial_private *s_priv;
2364 const struct keyspan_device_details *d_details;
2366 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2367 if (d_details->product_id ==
2368 le16_to_cpu(serial->dev->descriptor.idProduct))
2370 if (d_details == NULL) {
2371 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2372 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2376 /* Setup private data for serial driver */
2377 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2379 dev_dbg(&serial->dev->dev, "%s - kmalloc for keyspan_serial_private failed.\n", __func__);
2383 s_priv->device_details = d_details;
2384 usb_set_serial_data(serial, s_priv);
2386 keyspan_setup_urbs(serial);
2388 if (s_priv->instat_urb != NULL) {
2389 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2391 dev_dbg(&serial->dev->dev, "%s - submit instat urb failed %d\n", __func__, err);
2393 if (s_priv->indat_urb != NULL) {
2394 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2396 dev_dbg(&serial->dev->dev, "%s - submit indat urb failed %d\n", __func__, err);
2402 static void keyspan_disconnect(struct usb_serial *serial)
2404 struct keyspan_serial_private *s_priv;
2406 s_priv = usb_get_serial_data(serial);
2408 stop_urb(s_priv->instat_urb);
2409 stop_urb(s_priv->glocont_urb);
2410 stop_urb(s_priv->indat_urb);
2413 static void keyspan_release(struct usb_serial *serial)
2415 struct keyspan_serial_private *s_priv;
2417 s_priv = usb_get_serial_data(serial);
2419 usb_free_urb(s_priv->instat_urb);
2420 usb_free_urb(s_priv->indat_urb);
2421 usb_free_urb(s_priv->glocont_urb);
2426 static int keyspan_port_probe(struct usb_serial_port *port)
2428 struct usb_serial *serial = port->serial;
2429 struct keyspan_serial_private *s_priv;
2430 struct keyspan_port_private *p_priv;
2431 const struct keyspan_device_details *d_details;
2432 struct callbacks *cback;
2437 s_priv = usb_get_serial_data(serial);
2438 d_details = s_priv->device_details;
2440 p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL);
2444 p_priv->device_details = d_details;
2446 /* Setup values for the various callback routines */
2447 cback = &keyspan_callbacks[d_details->msg_format];
2449 port_num = port->number - port->serial->minor;
2451 /* Do indat endpoints first, once for each flip */
2452 endp = d_details->indat_endpoints[port_num];
2453 for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) {
2454 p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp,
2456 p_priv->in_buffer[i], 64,
2457 cback->indat_callback);
2459 /* outdat endpoints also have flip */
2460 endp = d_details->outdat_endpoints[port_num];
2461 for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) {
2462 p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp,
2464 p_priv->out_buffer[i], 64,
2465 cback->outdat_callback);
2467 /* inack endpoint */
2468 p_priv->inack_urb = keyspan_setup_urb(serial,
2469 d_details->inack_endpoints[port_num],
2471 p_priv->inack_buffer, 1,
2472 cback->inack_callback);
2473 /* outcont endpoint */
2474 p_priv->outcont_urb = keyspan_setup_urb(serial,
2475 d_details->outcont_endpoints[port_num],
2477 p_priv->outcont_buffer, 64,
2478 cback->outcont_callback);
2480 usb_set_serial_port_data(port, p_priv);
2485 static int keyspan_port_remove(struct usb_serial_port *port)
2487 struct keyspan_port_private *p_priv;
2490 p_priv = usb_get_serial_port_data(port);
2492 stop_urb(p_priv->inack_urb);
2493 stop_urb(p_priv->outcont_urb);
2494 for (i = 0; i < 2; i++) {
2495 stop_urb(p_priv->in_urbs[i]);
2496 stop_urb(p_priv->out_urbs[i]);
2499 usb_free_urb(p_priv->inack_urb);
2500 usb_free_urb(p_priv->outcont_urb);
2501 for (i = 0; i < 2; i++) {
2502 usb_free_urb(p_priv->in_urbs[i]);
2503 usb_free_urb(p_priv->out_urbs[i]);
2511 MODULE_AUTHOR(DRIVER_AUTHOR);
2512 MODULE_DESCRIPTION(DRIVER_DESC);
2513 MODULE_LICENSE("GPL");
2515 MODULE_FIRMWARE("keyspan/usa28.fw");
2516 MODULE_FIRMWARE("keyspan/usa28x.fw");
2517 MODULE_FIRMWARE("keyspan/usa28xa.fw");
2518 MODULE_FIRMWARE("keyspan/usa28xb.fw");
2519 MODULE_FIRMWARE("keyspan/usa19.fw");
2520 MODULE_FIRMWARE("keyspan/usa19qi.fw");
2521 MODULE_FIRMWARE("keyspan/mpr.fw");
2522 MODULE_FIRMWARE("keyspan/usa19qw.fw");
2523 MODULE_FIRMWARE("keyspan/usa18x.fw");
2524 MODULE_FIRMWARE("keyspan/usa19w.fw");
2525 MODULE_FIRMWARE("keyspan/usa49w.fw");
2526 MODULE_FIRMWARE("keyspan/usa49wlc.fw");