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(&port->port, 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(&port->port, data[i+1],
335 tty_flip_buffer_push(tty);
339 /* Resubmit urb so we continue receiving */
340 err = usb_submit_urb(urb, GFP_ATOMIC);
342 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
345 /* Outdat handling is common for all devices */
346 static void usa2x_outdat_callback(struct urb *urb)
348 struct usb_serial_port *port;
349 struct keyspan_port_private *p_priv;
352 p_priv = usb_get_serial_port_data(port);
353 dev_dbg(&port->dev, "%s - urb %d\n", __func__, urb == p_priv->out_urbs[1]);
355 usb_serial_port_softint(port);
358 static void usa26_inack_callback(struct urb *urb)
362 static void usa26_outcont_callback(struct urb *urb)
364 struct usb_serial_port *port;
365 struct keyspan_port_private *p_priv;
368 p_priv = usb_get_serial_port_data(port);
370 if (p_priv->resend_cont) {
371 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
372 keyspan_usa26_send_setup(port->serial, port,
373 p_priv->resend_cont - 1);
377 static void usa26_instat_callback(struct urb *urb)
379 unsigned char *data = urb->transfer_buffer;
380 struct keyspan_usa26_portStatusMessage *msg;
381 struct usb_serial *serial;
382 struct usb_serial_port *port;
383 struct keyspan_port_private *p_priv;
384 struct tty_struct *tty;
385 int old_dcd_state, err;
386 int status = urb->status;
388 serial = urb->context;
391 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
394 if (urb->actual_length != 9) {
395 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
399 msg = (struct keyspan_usa26_portStatusMessage *)data;
402 dev_dbg(&urb->dev->dev,
403 "%s - port status: port %d cts %d dcd %d dsr %d ri %d toff %d txoff %d rxen %d cr %d",
404 __func__, msg->port, msg->hskia_cts, msg->gpia_dcd, msg->dsr,
405 msg->ri, msg->_txOff, msg->_txXoff, msg->rxEnabled,
406 msg->controlResponse);
409 /* Now do something useful with the data */
412 /* Check port number from message and retrieve private data */
413 if (msg->port >= serial->num_ports) {
414 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
417 port = serial->port[msg->port];
418 p_priv = usb_get_serial_port_data(port);
420 /* Update handshaking pin state information */
421 old_dcd_state = p_priv->dcd_state;
422 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
423 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
424 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
425 p_priv->ri_state = ((msg->ri) ? 1 : 0);
427 if (old_dcd_state != p_priv->dcd_state) {
428 tty = tty_port_tty_get(&port->port);
429 if (tty && !C_CLOCAL(tty))
434 /* Resubmit urb so we continue receiving */
435 err = usb_submit_urb(urb, GFP_ATOMIC);
437 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
441 static void usa26_glocont_callback(struct urb *urb)
446 static void usa28_indat_callback(struct urb *urb)
449 struct usb_serial_port *port;
450 struct tty_struct *tty;
452 struct keyspan_port_private *p_priv;
453 int status = urb->status;
456 p_priv = usb_get_serial_port_data(port);
457 data = urb->transfer_buffer;
459 if (urb != p_priv->in_urbs[p_priv->in_flip])
464 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
465 __func__, status, usb_pipeendpoint(urb->pipe));
470 p_priv = usb_get_serial_port_data(port);
471 data = urb->transfer_buffer;
473 tty = tty_port_tty_get(&port->port);
474 if (tty && urb->actual_length) {
475 tty_insert_flip_string(&port->port, data,
477 tty_flip_buffer_push(tty);
481 /* Resubmit urb so we continue receiving */
482 err = usb_submit_urb(urb, GFP_ATOMIC);
484 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n",
486 p_priv->in_flip ^= 1;
488 urb = p_priv->in_urbs[p_priv->in_flip];
489 } while (urb->status != -EINPROGRESS);
492 static void usa28_inack_callback(struct urb *urb)
496 static void usa28_outcont_callback(struct urb *urb)
498 struct usb_serial_port *port;
499 struct keyspan_port_private *p_priv;
502 p_priv = usb_get_serial_port_data(port);
504 if (p_priv->resend_cont) {
505 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
506 keyspan_usa28_send_setup(port->serial, port,
507 p_priv->resend_cont - 1);
511 static void usa28_instat_callback(struct urb *urb)
514 unsigned char *data = urb->transfer_buffer;
515 struct keyspan_usa28_portStatusMessage *msg;
516 struct usb_serial *serial;
517 struct usb_serial_port *port;
518 struct keyspan_port_private *p_priv;
519 struct tty_struct *tty;
521 int status = urb->status;
523 serial = urb->context;
526 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
530 if (urb->actual_length != sizeof(struct keyspan_usa28_portStatusMessage)) {
531 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
536 dev_dbg(&urb->dev->dev,
537 "%s %x %x %x %x %x %x %x %x %x %x %x %x", __func__,
538 data[0], data[1], data[2], data[3], data[4], data[5],
539 data[6], data[7], data[8], data[9], data[10], data[11]);
542 /* Now do something useful with the data */
543 msg = (struct keyspan_usa28_portStatusMessage *)data;
545 /* Check port number from message and retrieve private data */
546 if (msg->port >= serial->num_ports) {
547 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
550 port = serial->port[msg->port];
551 p_priv = usb_get_serial_port_data(port);
553 /* Update handshaking pin state information */
554 old_dcd_state = p_priv->dcd_state;
555 p_priv->cts_state = ((msg->cts) ? 1 : 0);
556 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
557 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
558 p_priv->ri_state = ((msg->ri) ? 1 : 0);
560 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
561 tty = tty_port_tty_get(&port->port);
562 if (tty && !C_CLOCAL(tty))
567 /* Resubmit urb so we continue receiving */
568 err = usb_submit_urb(urb, GFP_ATOMIC);
570 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
574 static void usa28_glocont_callback(struct urb *urb)
579 static void usa49_glocont_callback(struct urb *urb)
581 struct usb_serial *serial;
582 struct usb_serial_port *port;
583 struct keyspan_port_private *p_priv;
586 serial = urb->context;
587 for (i = 0; i < serial->num_ports; ++i) {
588 port = serial->port[i];
589 p_priv = usb_get_serial_port_data(port);
591 if (p_priv->resend_cont) {
592 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
593 keyspan_usa49_send_setup(serial, port,
594 p_priv->resend_cont - 1);
600 /* This is actually called glostat in the Keyspan
602 static void usa49_instat_callback(struct urb *urb)
605 unsigned char *data = urb->transfer_buffer;
606 struct keyspan_usa49_portStatusMessage *msg;
607 struct usb_serial *serial;
608 struct usb_serial_port *port;
609 struct keyspan_port_private *p_priv;
611 int status = urb->status;
613 serial = urb->context;
616 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
620 if (urb->actual_length !=
621 sizeof(struct keyspan_usa49_portStatusMessage)) {
622 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
627 dev_dbg(&urb->dev->dev, "%s: %x %x %x %x %x %x %x %x %x %x %x",
628 __func__, data[0], data[1], data[2], data[3], data[4],
629 data[5], data[6], data[7], data[8], data[9], data[10]);
632 /* Now do something useful with the data */
633 msg = (struct keyspan_usa49_portStatusMessage *)data;
635 /* Check port number from message and retrieve private data */
636 if (msg->portNumber >= serial->num_ports) {
637 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
638 __func__, msg->portNumber);
641 port = serial->port[msg->portNumber];
642 p_priv = usb_get_serial_port_data(port);
644 /* Update handshaking pin state information */
645 old_dcd_state = p_priv->dcd_state;
646 p_priv->cts_state = ((msg->cts) ? 1 : 0);
647 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
648 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
649 p_priv->ri_state = ((msg->ri) ? 1 : 0);
651 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
652 struct tty_struct *tty = tty_port_tty_get(&port->port);
653 if (tty && !C_CLOCAL(tty))
658 /* Resubmit urb so we continue receiving */
659 err = usb_submit_urb(urb, GFP_ATOMIC);
661 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
665 static void usa49_inack_callback(struct urb *urb)
669 static void usa49_indat_callback(struct urb *urb)
673 struct usb_serial_port *port;
674 struct tty_struct *tty;
675 unsigned char *data = urb->transfer_buffer;
676 int status = urb->status;
678 endpoint = usb_pipeendpoint(urb->pipe);
681 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
682 __func__, status, endpoint);
687 tty = tty_port_tty_get(&port->port);
688 if (tty && urb->actual_length) {
689 /* 0x80 bit is error flag */
690 if ((data[0] & 0x80) == 0) {
691 /* no error on any byte */
692 tty_insert_flip_string(&port->port, data + 1,
693 urb->actual_length - 1);
695 /* some bytes had errors, every byte has status */
696 for (i = 0; i + 1 < urb->actual_length; i += 2) {
697 int stat = data[i], flag = 0;
698 if (stat & RXERROR_OVERRUN)
700 if (stat & RXERROR_FRAMING)
702 if (stat & RXERROR_PARITY)
704 /* XXX should handle break (0x10) */
705 tty_insert_flip_char(&port->port, data[i+1],
709 tty_flip_buffer_push(tty);
713 /* Resubmit urb so we continue receiving */
714 err = usb_submit_urb(urb, GFP_ATOMIC);
716 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
719 static void usa49wg_indat_callback(struct urb *urb)
722 struct usb_serial *serial;
723 struct usb_serial_port *port;
724 struct tty_struct *tty;
725 unsigned char *data = urb->transfer_buffer;
726 int status = urb->status;
728 serial = urb->context;
731 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
735 /* inbound data is in the form P#, len, status, data */
739 if (urb->actual_length) {
740 while (i < urb->actual_length) {
742 /* Check port number from message*/
743 if (data[i] >= serial->num_ports) {
744 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n",
748 port = serial->port[data[i++]];
749 tty = tty_port_tty_get(&port->port);
752 /* 0x80 bit is error flag */
753 if ((data[i] & 0x80) == 0) {
754 /* no error on any byte */
756 for (x = 1; x < len ; ++x)
757 tty_insert_flip_char(&port->port,
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(&port->port,
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(&port->port, data,
823 /* 0x80 bit is error flag */
824 if ((data[0] & 0x80) == 0) {
825 /* no errors on individual bytes, only
826 possible overrun err*/
827 if (data[0] & RXERROR_OVERRUN)
831 for (i = 1; i < urb->actual_length ; ++i)
832 tty_insert_flip_char(&port->port,
835 /* some bytes had errors, every byte has status */
836 dev_dbg(&port->dev, "%s - RX error!!!!\n", __func__);
837 for (i = 0; i + 1 < urb->actual_length; i += 2) {
838 int stat = data[i], flag = 0;
839 if (stat & RXERROR_OVERRUN)
841 if (stat & RXERROR_FRAMING)
843 if (stat & RXERROR_PARITY)
845 /* XXX should handle break (0x10) */
846 tty_insert_flip_char(&port->port,
851 tty_flip_buffer_push(tty);
855 /* Resubmit urb so we continue receiving */
856 err = usb_submit_urb(urb, GFP_ATOMIC);
858 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
862 static void usa90_instat_callback(struct urb *urb)
864 unsigned char *data = urb->transfer_buffer;
865 struct keyspan_usa90_portStatusMessage *msg;
866 struct usb_serial *serial;
867 struct usb_serial_port *port;
868 struct keyspan_port_private *p_priv;
869 struct tty_struct *tty;
870 int old_dcd_state, err;
871 int status = urb->status;
873 serial = urb->context;
876 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
879 if (urb->actual_length < 14) {
880 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
884 msg = (struct keyspan_usa90_portStatusMessage *)data;
886 /* Now do something useful with the data */
888 port = serial->port[0];
889 p_priv = usb_get_serial_port_data(port);
891 /* Update handshaking pin state information */
892 old_dcd_state = p_priv->dcd_state;
893 p_priv->cts_state = ((msg->cts) ? 1 : 0);
894 p_priv->dsr_state = ((msg->dsr) ? 1 : 0);
895 p_priv->dcd_state = ((msg->dcd) ? 1 : 0);
896 p_priv->ri_state = ((msg->ri) ? 1 : 0);
898 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
899 tty = tty_port_tty_get(&port->port);
900 if (tty && !C_CLOCAL(tty))
905 /* Resubmit urb so we continue receiving */
906 err = usb_submit_urb(urb, GFP_ATOMIC);
908 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
913 static void usa90_outcont_callback(struct urb *urb)
915 struct usb_serial_port *port;
916 struct keyspan_port_private *p_priv;
919 p_priv = usb_get_serial_port_data(port);
921 if (p_priv->resend_cont) {
922 dev_dbg(&urb->dev->dev, "%s - sending setup\n", __func__);
923 keyspan_usa90_send_setup(port->serial, port,
924 p_priv->resend_cont - 1);
928 /* Status messages from the 28xg */
929 static void usa67_instat_callback(struct urb *urb)
932 unsigned char *data = urb->transfer_buffer;
933 struct keyspan_usa67_portStatusMessage *msg;
934 struct usb_serial *serial;
935 struct usb_serial_port *port;
936 struct keyspan_port_private *p_priv;
938 int status = urb->status;
940 serial = urb->context;
943 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
947 if (urb->actual_length !=
948 sizeof(struct keyspan_usa67_portStatusMessage)) {
949 dev_dbg(&urb->dev->dev, "%s - bad length %d\n", __func__, urb->actual_length);
954 /* Now do something useful with the data */
955 msg = (struct keyspan_usa67_portStatusMessage *)data;
957 /* Check port number from message and retrieve private data */
958 if (msg->port >= serial->num_ports) {
959 dev_dbg(&urb->dev->dev, "%s - Unexpected port number %d\n", __func__, msg->port);
963 port = serial->port[msg->port];
964 p_priv = usb_get_serial_port_data(port);
966 /* Update handshaking pin state information */
967 old_dcd_state = p_priv->dcd_state;
968 p_priv->cts_state = ((msg->hskia_cts) ? 1 : 0);
969 p_priv->dcd_state = ((msg->gpia_dcd) ? 1 : 0);
971 if (old_dcd_state != p_priv->dcd_state && old_dcd_state) {
972 struct tty_struct *tty = tty_port_tty_get(&port->port);
973 if (tty && !C_CLOCAL(tty))
978 /* Resubmit urb so we continue receiving */
979 err = usb_submit_urb(urb, GFP_ATOMIC);
981 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
984 static void usa67_glocont_callback(struct urb *urb)
986 struct usb_serial *serial;
987 struct usb_serial_port *port;
988 struct keyspan_port_private *p_priv;
991 serial = urb->context;
992 for (i = 0; i < serial->num_ports; ++i) {
993 port = serial->port[i];
994 p_priv = usb_get_serial_port_data(port);
996 if (p_priv->resend_cont) {
997 dev_dbg(&port->dev, "%s - sending setup\n", __func__);
998 keyspan_usa67_send_setup(serial, port,
999 p_priv->resend_cont - 1);
1005 static int keyspan_write_room(struct tty_struct *tty)
1007 struct usb_serial_port *port = tty->driver_data;
1008 struct keyspan_port_private *p_priv;
1009 const struct keyspan_device_details *d_details;
1012 struct urb *this_urb;
1014 p_priv = usb_get_serial_port_data(port);
1015 d_details = p_priv->device_details;
1017 /* FIXME: locking */
1018 if (d_details->msg_format == msg_usa90)
1023 flip = p_priv->out_flip;
1025 /* Check both endpoints to see if any are available. */
1026 this_urb = p_priv->out_urbs[flip];
1027 if (this_urb != NULL) {
1028 if (this_urb->status != -EINPROGRESS)
1030 flip = (flip + 1) & d_details->outdat_endp_flip;
1031 this_urb = p_priv->out_urbs[flip];
1032 if (this_urb != NULL) {
1033 if (this_urb->status != -EINPROGRESS)
1041 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1043 struct keyspan_port_private *p_priv;
1044 const struct keyspan_device_details *d_details;
1046 int baud_rate, device_port;
1048 unsigned int cflag = 0;
1050 p_priv = usb_get_serial_port_data(port);
1051 d_details = p_priv->device_details;
1053 /* Set some sane defaults */
1054 p_priv->rts_state = 1;
1055 p_priv->dtr_state = 1;
1056 p_priv->baud = 9600;
1058 /* force baud and lcr to be set on open */
1059 p_priv->old_baud = 0;
1060 p_priv->old_cflag = 0;
1062 p_priv->out_flip = 0;
1063 p_priv->in_flip = 0;
1065 /* Reset low level data toggle and start reading from endpoints */
1066 for (i = 0; i < 2; i++) {
1067 urb = p_priv->in_urbs[i];
1071 /* make sure endpoint data toggle is synchronized
1073 usb_clear_halt(urb->dev, urb->pipe);
1074 err = usb_submit_urb(urb, GFP_KERNEL);
1076 dev_dbg(&port->dev, "%s - submit urb %d failed (%d)\n", __func__, i, err);
1079 /* Reset low level data toggle on out endpoints */
1080 for (i = 0; i < 2; i++) {
1081 urb = p_priv->out_urbs[i];
1084 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1085 usb_pipeout(urb->pipe), 0); */
1088 /* get the terminal config for the setup message now so we don't
1089 * need to send 2 of them */
1091 device_port = port->number - port->serial->minor;
1093 cflag = tty->termios.c_cflag;
1094 /* Baud rate calculation takes baud rate as an integer
1095 so other rates can be generated if desired. */
1096 baud_rate = tty_get_baud_rate(tty);
1097 /* If no match or invalid, leave as default */
1099 && d_details->calculate_baud_rate(port, baud_rate, d_details->baudclk,
1100 NULL, NULL, NULL, device_port) == KEYSPAN_BAUD_RATE_OK) {
1101 p_priv->baud = baud_rate;
1104 /* set CTS/RTS handshake etc. */
1105 p_priv->cflag = cflag;
1106 p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
1108 keyspan_send_setup(port, 1);
1110 /* keyspan_set_termios(port, NULL); */
1115 static inline void stop_urb(struct urb *urb)
1117 if (urb && urb->status == -EINPROGRESS)
1121 static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1123 struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
1125 p_priv->rts_state = on;
1126 p_priv->dtr_state = on;
1127 keyspan_send_setup(port, 0);
1130 static void keyspan_close(struct usb_serial_port *port)
1133 struct usb_serial *serial = port->serial;
1134 struct keyspan_port_private *p_priv;
1136 p_priv = usb_get_serial_port_data(port);
1138 p_priv->rts_state = 0;
1139 p_priv->dtr_state = 0;
1142 keyspan_send_setup(port, 2);
1143 /* pilot-xfer seems to work best with this delay */
1145 /* keyspan_set_termios(port, NULL); */
1148 /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
1149 dev_dbg(&port->dev, "%s - urb in progress\n", __func__);
1152 p_priv->out_flip = 0;
1153 p_priv->in_flip = 0;
1156 /* Stop reading/writing urbs */
1157 stop_urb(p_priv->inack_urb);
1158 /* stop_urb(p_priv->outcont_urb); */
1159 for (i = 0; i < 2; i++) {
1160 stop_urb(p_priv->in_urbs[i]);
1161 stop_urb(p_priv->out_urbs[i]);
1166 /* download the firmware to a pre-renumeration device */
1167 static int keyspan_fake_startup(struct usb_serial *serial)
1171 dev_dbg(&serial->dev->dev, "Keyspan startup version %04x product %04x\n",
1172 le16_to_cpu(serial->dev->descriptor.bcdDevice),
1173 le16_to_cpu(serial->dev->descriptor.idProduct));
1175 if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
1177 dev_dbg(&serial->dev->dev, "Firmware already loaded. Quitting.\n");
1181 /* Select firmware image on the basis of idProduct */
1182 switch (le16_to_cpu(serial->dev->descriptor.idProduct)) {
1183 case keyspan_usa28_pre_product_id:
1184 fw_name = "keyspan/usa28.fw";
1187 case keyspan_usa28x_pre_product_id:
1188 fw_name = "keyspan/usa28x.fw";
1191 case keyspan_usa28xa_pre_product_id:
1192 fw_name = "keyspan/usa28xa.fw";
1195 case keyspan_usa28xb_pre_product_id:
1196 fw_name = "keyspan/usa28xb.fw";
1199 case keyspan_usa19_pre_product_id:
1200 fw_name = "keyspan/usa19.fw";
1203 case keyspan_usa19qi_pre_product_id:
1204 fw_name = "keyspan/usa19qi.fw";
1207 case keyspan_mpr_pre_product_id:
1208 fw_name = "keyspan/mpr.fw";
1211 case keyspan_usa19qw_pre_product_id:
1212 fw_name = "keyspan/usa19qw.fw";
1215 case keyspan_usa18x_pre_product_id:
1216 fw_name = "keyspan/usa18x.fw";
1219 case keyspan_usa19w_pre_product_id:
1220 fw_name = "keyspan/usa19w.fw";
1223 case keyspan_usa49w_pre_product_id:
1224 fw_name = "keyspan/usa49w.fw";
1227 case keyspan_usa49wlc_pre_product_id:
1228 fw_name = "keyspan/usa49wlc.fw";
1232 dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n",
1233 le16_to_cpu(serial->dev->descriptor.idProduct));
1237 dev_dbg(&serial->dev->dev, "Uploading Keyspan %s firmware.\n", fw_name);
1239 if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
1240 dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
1245 /* after downloading firmware Renumeration will occur in a
1246 moment and the new device will bind to the real driver */
1248 /* we don't want this device to have a driver assigned to it. */
1252 /* Helper functions used by keyspan_setup_urbs */
1253 static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial,
1256 struct usb_host_interface *iface_desc;
1257 struct usb_endpoint_descriptor *ep;
1260 iface_desc = serial->interface->cur_altsetting;
1261 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
1262 ep = &iface_desc->endpoint[i].desc;
1263 if (ep->bEndpointAddress == endpoint)
1266 dev_warn(&serial->interface->dev, "found no endpoint descriptor for "
1267 "endpoint %x\n", endpoint);
1271 static struct urb *keyspan_setup_urb(struct usb_serial *serial, int endpoint,
1272 int dir, void *ctx, char *buf, int len,
1273 void (*callback)(struct urb *))
1276 struct usb_endpoint_descriptor const *ep_desc;
1277 char const *ep_type_name;
1280 return NULL; /* endpoint not needed */
1282 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d.\n", __func__, endpoint);
1283 urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */
1285 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d failed.\n", __func__, endpoint);
1289 if (endpoint == 0) {
1290 /* control EP filled in when used */
1294 ep_desc = find_ep(serial, endpoint);
1296 /* leak the urb, something's wrong and the callers don't care */
1299 if (usb_endpoint_xfer_int(ep_desc)) {
1300 ep_type_name = "INT";
1301 usb_fill_int_urb(urb, serial->dev,
1302 usb_sndintpipe(serial->dev, endpoint) | dir,
1303 buf, len, callback, ctx,
1304 ep_desc->bInterval);
1305 } else if (usb_endpoint_xfer_bulk(ep_desc)) {
1306 ep_type_name = "BULK";
1307 usb_fill_bulk_urb(urb, serial->dev,
1308 usb_sndbulkpipe(serial->dev, endpoint) | dir,
1309 buf, len, callback, ctx);
1311 dev_warn(&serial->interface->dev,
1312 "unsupported endpoint type %x\n",
1313 usb_endpoint_type(ep_desc));
1318 dev_dbg(&serial->interface->dev, "%s - using urb %p for %s endpoint %x\n",
1319 __func__, urb, ep_type_name, endpoint);
1323 static struct callbacks {
1324 void (*instat_callback)(struct urb *);
1325 void (*glocont_callback)(struct urb *);
1326 void (*indat_callback)(struct urb *);
1327 void (*outdat_callback)(struct urb *);
1328 void (*inack_callback)(struct urb *);
1329 void (*outcont_callback)(struct urb *);
1330 } keyspan_callbacks[] = {
1332 /* msg_usa26 callbacks */
1333 .instat_callback = usa26_instat_callback,
1334 .glocont_callback = usa26_glocont_callback,
1335 .indat_callback = usa26_indat_callback,
1336 .outdat_callback = usa2x_outdat_callback,
1337 .inack_callback = usa26_inack_callback,
1338 .outcont_callback = usa26_outcont_callback,
1340 /* msg_usa28 callbacks */
1341 .instat_callback = usa28_instat_callback,
1342 .glocont_callback = usa28_glocont_callback,
1343 .indat_callback = usa28_indat_callback,
1344 .outdat_callback = usa2x_outdat_callback,
1345 .inack_callback = usa28_inack_callback,
1346 .outcont_callback = usa28_outcont_callback,
1348 /* msg_usa49 callbacks */
1349 .instat_callback = usa49_instat_callback,
1350 .glocont_callback = usa49_glocont_callback,
1351 .indat_callback = usa49_indat_callback,
1352 .outdat_callback = usa2x_outdat_callback,
1353 .inack_callback = usa49_inack_callback,
1354 .outcont_callback = usa49_outcont_callback,
1356 /* msg_usa90 callbacks */
1357 .instat_callback = usa90_instat_callback,
1358 .glocont_callback = usa28_glocont_callback,
1359 .indat_callback = usa90_indat_callback,
1360 .outdat_callback = usa2x_outdat_callback,
1361 .inack_callback = usa28_inack_callback,
1362 .outcont_callback = usa90_outcont_callback,
1364 /* msg_usa67 callbacks */
1365 .instat_callback = usa67_instat_callback,
1366 .glocont_callback = usa67_glocont_callback,
1367 .indat_callback = usa26_indat_callback,
1368 .outdat_callback = usa2x_outdat_callback,
1369 .inack_callback = usa26_inack_callback,
1370 .outcont_callback = usa26_outcont_callback,
1374 /* Generic setup urbs function that uses
1375 data in device_details */
1376 static void keyspan_setup_urbs(struct usb_serial *serial)
1378 struct keyspan_serial_private *s_priv;
1379 const struct keyspan_device_details *d_details;
1380 struct callbacks *cback;
1382 s_priv = usb_get_serial_data(serial);
1383 d_details = s_priv->device_details;
1385 /* Setup values for the various callback routines */
1386 cback = &keyspan_callbacks[d_details->msg_format];
1388 /* Allocate and set up urbs for each one that is in use,
1389 starting with instat endpoints */
1390 s_priv->instat_urb = keyspan_setup_urb
1391 (serial, d_details->instat_endpoint, USB_DIR_IN,
1392 serial, s_priv->instat_buf, INSTAT_BUFLEN,
1393 cback->instat_callback);
1395 s_priv->indat_urb = keyspan_setup_urb
1396 (serial, d_details->indat_endpoint, USB_DIR_IN,
1397 serial, s_priv->indat_buf, INDAT49W_BUFLEN,
1398 usa49wg_indat_callback);
1400 s_priv->glocont_urb = keyspan_setup_urb
1401 (serial, d_details->glocont_endpoint, USB_DIR_OUT,
1402 serial, s_priv->glocont_buf, GLOCONT_BUFLEN,
1403 cback->glocont_callback);
1406 /* usa19 function doesn't require prescaler */
1407 static int keyspan_usa19_calc_baud(struct usb_serial_port *port,
1408 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1409 u8 *rate_low, u8 *prescaler, int portnum)
1411 u32 b16, /* baud rate times 16 (actual rate used internally) */
1413 cnt; /* inverse of divisor (programmed into 8051) */
1415 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1417 /* prevent divide by zero... */
1418 b16 = baud_rate * 16L;
1420 return KEYSPAN_INVALID_BAUD_RATE;
1421 /* Any "standard" rate over 57k6 is marginal on the USA-19
1422 as we run out of divisor resolution. */
1423 if (baud_rate > 57600)
1424 return KEYSPAN_INVALID_BAUD_RATE;
1426 /* calculate the divisor and the counter (its inverse) */
1427 div = baudclk / b16;
1429 return KEYSPAN_INVALID_BAUD_RATE;
1434 return KEYSPAN_INVALID_BAUD_RATE;
1436 /* return the counter values if non-null */
1438 *rate_low = (u8) (cnt & 0xff);
1440 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1441 if (rate_low && rate_hi)
1442 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1443 __func__, baud_rate, *rate_hi, *rate_low);
1444 return KEYSPAN_BAUD_RATE_OK;
1447 /* usa19hs function doesn't require prescaler */
1448 static int keyspan_usa19hs_calc_baud(struct usb_serial_port *port,
1449 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1450 u8 *rate_low, u8 *prescaler, int portnum)
1452 u32 b16, /* baud rate times 16 (actual rate used internally) */
1455 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1457 /* prevent divide by zero... */
1458 b16 = baud_rate * 16L;
1460 return KEYSPAN_INVALID_BAUD_RATE;
1462 /* calculate the divisor */
1463 div = baudclk / b16;
1465 return KEYSPAN_INVALID_BAUD_RATE;
1468 return KEYSPAN_INVALID_BAUD_RATE;
1470 /* return the counter values if non-null */
1472 *rate_low = (u8) (div & 0xff);
1475 *rate_hi = (u8) ((div >> 8) & 0xff);
1477 if (rate_low && rate_hi)
1478 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1479 __func__, baud_rate, *rate_hi, *rate_low);
1481 return KEYSPAN_BAUD_RATE_OK;
1484 static int keyspan_usa19w_calc_baud(struct usb_serial_port *port,
1485 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1486 u8 *rate_low, u8 *prescaler, int portnum)
1488 u32 b16, /* baud rate times 16 (actual rate used internally) */
1489 clk, /* clock with 13/8 prescaler */
1490 div, /* divisor using 13/8 prescaler */
1491 res, /* resulting baud rate using 13/8 prescaler */
1492 diff, /* error using 13/8 prescaler */
1497 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1499 /* prevent divide by zero */
1500 b16 = baud_rate * 16L;
1502 return KEYSPAN_INVALID_BAUD_RATE;
1504 /* Calculate prescaler by trying them all and looking
1507 /* start with largest possible difference */
1508 smallest_diff = 0xffffffff;
1510 /* 0 is an invalid prescaler, used as a flag */
1513 for (i = 8; i <= 0xff; ++i) {
1514 clk = (baudclk * 8) / (u32) i;
1521 diff = (res > b16) ? (res-b16) : (b16-res);
1523 if (diff < smallest_diff) {
1525 smallest_diff = diff;
1529 if (best_prescaler == 0)
1530 return KEYSPAN_INVALID_BAUD_RATE;
1532 clk = (baudclk * 8) / (u32) best_prescaler;
1535 /* return the divisor and prescaler if non-null */
1537 *rate_low = (u8) (div & 0xff);
1539 *rate_hi = (u8) ((div >> 8) & 0xff);
1541 *prescaler = best_prescaler;
1542 /* dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
1544 return KEYSPAN_BAUD_RATE_OK;
1547 /* USA-28 supports different maximum baud rates on each port */
1548 static int keyspan_usa28_calc_baud(struct usb_serial_port *port,
1549 u32 baud_rate, u32 baudclk, u8 *rate_hi,
1550 u8 *rate_low, u8 *prescaler, int portnum)
1552 u32 b16, /* baud rate times 16 (actual rate used internally) */
1554 cnt; /* inverse of divisor (programmed into 8051) */
1556 dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1558 /* prevent divide by zero */
1559 b16 = baud_rate * 16L;
1561 return KEYSPAN_INVALID_BAUD_RATE;
1563 /* calculate the divisor and the counter (its inverse) */
1564 div = KEYSPAN_USA28_BAUDCLK / b16;
1566 return KEYSPAN_INVALID_BAUD_RATE;
1570 /* check for out of range, based on portnum,
1571 and return result */
1574 return KEYSPAN_INVALID_BAUD_RATE;
1578 return KEYSPAN_INVALID_BAUD_RATE;
1580 return KEYSPAN_INVALID_BAUD_RATE;
1583 /* return the counter values if not NULL
1584 (port 1 will ignore retHi) */
1586 *rate_low = (u8) (cnt & 0xff);
1588 *rate_hi = (u8) ((cnt >> 8) & 0xff);
1589 dev_dbg(&port->dev, "%s - %d OK.\n", __func__, baud_rate);
1590 return KEYSPAN_BAUD_RATE_OK;
1593 static int keyspan_usa26_send_setup(struct usb_serial *serial,
1594 struct usb_serial_port *port,
1597 struct keyspan_usa26_portControlMessage msg;
1598 struct keyspan_serial_private *s_priv;
1599 struct keyspan_port_private *p_priv;
1600 const struct keyspan_device_details *d_details;
1602 struct urb *this_urb;
1603 int device_port, err;
1605 dev_dbg(&port->dev, "%s reset=%d\n", __func__, reset_port);
1607 s_priv = usb_get_serial_data(serial);
1608 p_priv = usb_get_serial_port_data(port);
1609 d_details = s_priv->device_details;
1610 device_port = port->number - port->serial->minor;
1612 outcont_urb = d_details->outcont_endpoints[port->number];
1613 this_urb = p_priv->outcont_urb;
1615 dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
1617 /* Make sure we have an urb then send the message */
1618 if (this_urb == NULL) {
1619 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1623 /* Save reset port val for resend.
1624 Don't overwrite resend for open/close condition. */
1625 if ((reset_port + 1) > p_priv->resend_cont)
1626 p_priv->resend_cont = reset_port + 1;
1627 if (this_urb->status == -EINPROGRESS) {
1628 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1633 memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1635 /* Only set baud rate if it's changed */
1636 if (p_priv->old_baud != p_priv->baud) {
1637 p_priv->old_baud = p_priv->baud;
1638 msg.setClocking = 0xff;
1639 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1640 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1641 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1642 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1643 __func__, p_priv->baud);
1645 msg.baudHi = 125; /* Values for 9600 baud */
1648 msg.setPrescaler = 0xff;
1651 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1652 switch (p_priv->cflag & CSIZE) {
1654 msg.lcr |= USA_DATABITS_5;
1657 msg.lcr |= USA_DATABITS_6;
1660 msg.lcr |= USA_DATABITS_7;
1663 msg.lcr |= USA_DATABITS_8;
1666 if (p_priv->cflag & PARENB) {
1667 /* note USA_PARITY_NONE == 0 */
1668 msg.lcr |= (p_priv->cflag & PARODD) ?
1669 USA_PARITY_ODD : USA_PARITY_EVEN;
1673 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1674 msg.xonFlowControl = 0;
1675 msg.setFlowControl = 0xff;
1676 msg.forwardingLength = 16;
1681 if (reset_port == 1) {
1690 msg.returnStatus = 0;
1691 msg.resetDataToggle = 0xff;
1695 else if (reset_port == 2) {
1704 msg.returnStatus = 0;
1705 msg.resetDataToggle = 0;
1708 /* Sending intermediate configs */
1710 msg._txOn = (!p_priv->break_on);
1713 msg.txBreak = (p_priv->break_on);
1718 msg.returnStatus = 0;
1719 msg.resetDataToggle = 0x0;
1722 /* Do handshaking outputs */
1723 msg.setTxTriState_setRts = 0xff;
1724 msg.txTriState_rts = p_priv->rts_state;
1726 msg.setHskoa_setDtr = 0xff;
1727 msg.hskoa_dtr = p_priv->dtr_state;
1729 p_priv->resend_cont = 0;
1730 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1732 /* send the data out the device on control endpoint */
1733 this_urb->transfer_buffer_length = sizeof(msg);
1735 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1737 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1740 dev_dbg(&port->dev, "%s - usb_submit_urb(%d) OK %d bytes (end %d)\n", __func__
1741 outcont_urb, this_urb->transfer_buffer_length,
1742 usb_pipeendpoint(this_urb->pipe));
1749 static int keyspan_usa28_send_setup(struct usb_serial *serial,
1750 struct usb_serial_port *port,
1753 struct keyspan_usa28_portControlMessage msg;
1754 struct keyspan_serial_private *s_priv;
1755 struct keyspan_port_private *p_priv;
1756 const struct keyspan_device_details *d_details;
1757 struct urb *this_urb;
1758 int device_port, err;
1760 s_priv = usb_get_serial_data(serial);
1761 p_priv = usb_get_serial_port_data(port);
1762 d_details = s_priv->device_details;
1763 device_port = port->number - port->serial->minor;
1765 /* only do something if we have a bulk out endpoint */
1766 this_urb = p_priv->outcont_urb;
1767 if (this_urb == NULL) {
1768 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
1772 /* Save reset port val for resend.
1773 Don't overwrite resend for open/close condition. */
1774 if ((reset_port + 1) > p_priv->resend_cont)
1775 p_priv->resend_cont = reset_port + 1;
1776 if (this_urb->status == -EINPROGRESS) {
1777 dev_dbg(&port->dev, "%s already writing\n", __func__);
1782 memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
1784 msg.setBaudRate = 1;
1785 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1786 &msg.baudHi, &msg.baudLo, NULL,
1787 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1788 dev_dbg(&port->dev, "%s - Invalid baud rate requested %d.\n",
1789 __func__, p_priv->baud);
1791 msg.baudHi = 0xb2; /* Values for 9600 baud */
1794 /* If parity is enabled, we must calculate it ourselves. */
1795 msg.parity = 0; /* XXX for now */
1797 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1798 msg.xonFlowControl = 0;
1800 /* Do handshaking outputs, DTR is inverted relative to RTS */
1801 msg.rts = p_priv->rts_state;
1802 msg.dtr = p_priv->dtr_state;
1804 msg.forwardingLength = 16;
1806 msg.breakThreshold = 45;
1810 /*msg.returnStatus = 1;
1811 msg.resetDataToggle = 0xff;*/
1813 if (reset_port == 1) {
1817 msg.txForceXoff = 0;
1823 msg.returnStatus = 0;
1824 msg.resetDataToggle = 0xff;
1827 else if (reset_port == 2) {
1831 msg.txForceXoff = 0;
1837 msg.returnStatus = 0;
1838 msg.resetDataToggle = 0;
1840 /* Sending intermediate configs */
1842 msg._txOn = (!p_priv->break_on);
1845 msg.txForceXoff = 0;
1846 msg.txBreak = (p_priv->break_on);
1851 msg.returnStatus = 0;
1852 msg.resetDataToggle = 0x0;
1855 p_priv->resend_cont = 0;
1856 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1858 /* send the data out the device on control endpoint */
1859 this_urb->transfer_buffer_length = sizeof(msg);
1861 err = usb_submit_urb(this_urb, GFP_ATOMIC);
1863 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed\n", __func__);
1866 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) OK %d bytes\n", __func__,
1867 this_urb->transfer_buffer_length);
1874 static int keyspan_usa49_send_setup(struct usb_serial *serial,
1875 struct usb_serial_port *port,
1878 struct keyspan_usa49_portControlMessage msg;
1879 struct usb_ctrlrequest *dr = NULL;
1880 struct keyspan_serial_private *s_priv;
1881 struct keyspan_port_private *p_priv;
1882 const struct keyspan_device_details *d_details;
1883 struct urb *this_urb;
1884 int err, device_port;
1886 s_priv = usb_get_serial_data(serial);
1887 p_priv = usb_get_serial_port_data(port);
1888 d_details = s_priv->device_details;
1890 this_urb = s_priv->glocont_urb;
1892 /* Work out which port within the device is being setup */
1893 device_port = port->number - port->serial->minor;
1895 /* Make sure we have an urb then send the message */
1896 if (this_urb == NULL) {
1897 dev_dbg(&port->dev, "%s - oops no urb for port %d.\n", __func__, port->number);
1901 dev_dbg(&port->dev, "%s - endpoint %d port %d (%d)\n",
1902 __func__, usb_pipeendpoint(this_urb->pipe),
1903 port->number, device_port);
1905 /* Save reset port val for resend.
1906 Don't overwrite resend for open/close condition. */
1907 if ((reset_port + 1) > p_priv->resend_cont)
1908 p_priv->resend_cont = reset_port + 1;
1910 if (this_urb->status == -EINPROGRESS) {
1911 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1916 memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
1918 /*msg.portNumber = port->number;*/
1919 msg.portNumber = device_port;
1921 /* Only set baud rate if it's changed */
1922 if (p_priv->old_baud != p_priv->baud) {
1923 p_priv->old_baud = p_priv->baud;
1924 msg.setClocking = 0xff;
1925 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
1926 &msg.baudHi, &msg.baudLo, &msg.prescaler,
1927 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
1928 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
1929 __func__, p_priv->baud);
1931 msg.baudHi = 125; /* Values for 9600 baud */
1934 /* msg.setPrescaler = 0xff; */
1937 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1938 switch (p_priv->cflag & CSIZE) {
1940 msg.lcr |= USA_DATABITS_5;
1943 msg.lcr |= USA_DATABITS_6;
1946 msg.lcr |= USA_DATABITS_7;
1949 msg.lcr |= USA_DATABITS_8;
1952 if (p_priv->cflag & PARENB) {
1953 /* note USA_PARITY_NONE == 0 */
1954 msg.lcr |= (p_priv->cflag & PARODD) ?
1955 USA_PARITY_ODD : USA_PARITY_EVEN;
1959 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1960 msg.xonFlowControl = 0;
1961 msg.setFlowControl = 0xff;
1963 msg.forwardingLength = 16;
1968 if (reset_port == 1) {
1977 msg.returnStatus = 0;
1978 msg.resetDataToggle = 0xff;
1980 msg.disablePort = 0;
1983 else if (reset_port == 2) {
1992 msg.returnStatus = 0;
1993 msg.resetDataToggle = 0;
1995 msg.disablePort = 1;
1997 /* Sending intermediate configs */
1999 msg._txOn = (!p_priv->break_on);
2002 msg.txBreak = (p_priv->break_on);
2007 msg.returnStatus = 0;
2008 msg.resetDataToggle = 0x0;
2010 msg.disablePort = 0;
2013 /* Do handshaking outputs */
2015 msg.rts = p_priv->rts_state;
2018 msg.dtr = p_priv->dtr_state;
2020 p_priv->resend_cont = 0;
2022 /* if the device is a 49wg, we send control message on usb
2025 if (d_details->product_id == keyspan_usa49wg_product_id) {
2026 dr = (void *)(s_priv->ctrl_buf);
2027 dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
2028 dr->bRequest = 0xB0; /* 49wg control message */;
2031 dr->wLength = cpu_to_le16(sizeof(msg));
2033 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
2035 usb_fill_control_urb(this_urb, serial->dev,
2036 usb_sndctrlpipe(serial->dev, 0),
2037 (unsigned char *)dr, s_priv->glocont_buf,
2038 sizeof(msg), usa49_glocont_callback, serial);
2041 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2043 /* send the data out the device on control endpoint */
2044 this_urb->transfer_buffer_length = sizeof(msg);
2046 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2048 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2051 dev_dbg(&port->dev, "%s - usb_submit_urb(%d) OK %d bytes (end %d)\n", __func__,
2052 outcont_urb, this_urb->transfer_buffer_length,
2053 usb_pipeendpoint(this_urb->pipe));
2060 static int keyspan_usa90_send_setup(struct usb_serial *serial,
2061 struct usb_serial_port *port,
2064 struct keyspan_usa90_portControlMessage msg;
2065 struct keyspan_serial_private *s_priv;
2066 struct keyspan_port_private *p_priv;
2067 const struct keyspan_device_details *d_details;
2068 struct urb *this_urb;
2072 s_priv = usb_get_serial_data(serial);
2073 p_priv = usb_get_serial_port_data(port);
2074 d_details = s_priv->device_details;
2076 /* only do something if we have a bulk out endpoint */
2077 this_urb = p_priv->outcont_urb;
2078 if (this_urb == NULL) {
2079 dev_dbg(&port->dev, "%s - oops no urb.\n", __func__);
2083 /* Save reset port val for resend.
2084 Don't overwrite resend for open/close condition. */
2085 if ((reset_port + 1) > p_priv->resend_cont)
2086 p_priv->resend_cont = reset_port + 1;
2087 if (this_urb->status == -EINPROGRESS) {
2088 dev_dbg(&port->dev, "%s already writing\n", __func__);
2093 memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2095 /* Only set baud rate if it's changed */
2096 if (p_priv->old_baud != p_priv->baud) {
2097 p_priv->old_baud = p_priv->baud;
2098 msg.setClocking = 0x01;
2099 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2100 &msg.baudHi, &msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
2101 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2102 __func__, p_priv->baud);
2103 p_priv->baud = 9600;
2104 d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2105 &msg.baudHi, &msg.baudLo, &prescaler, 0);
2111 /* modes must always be correctly specified */
2112 if (p_priv->baud > 57600) {
2113 msg.rxMode = RXMODE_DMA;
2114 msg.txMode = TXMODE_DMA;
2116 msg.rxMode = RXMODE_BYHAND;
2117 msg.txMode = TXMODE_BYHAND;
2120 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2121 switch (p_priv->cflag & CSIZE) {
2123 msg.lcr |= USA_DATABITS_5;
2126 msg.lcr |= USA_DATABITS_6;
2129 msg.lcr |= USA_DATABITS_7;
2132 msg.lcr |= USA_DATABITS_8;
2135 if (p_priv->cflag & PARENB) {
2136 /* note USA_PARITY_NONE == 0 */
2137 msg.lcr |= (p_priv->cflag & PARODD) ?
2138 USA_PARITY_ODD : USA_PARITY_EVEN;
2140 if (p_priv->old_cflag != p_priv->cflag) {
2141 p_priv->old_cflag = p_priv->cflag;
2145 if (p_priv->flow_control == flow_cts)
2146 msg.txFlowControl = TXFLOW_CTS;
2147 msg.setTxFlowControl = 0x01;
2148 msg.setRxFlowControl = 0x01;
2150 msg.rxForwardingLength = 16;
2151 msg.rxForwardingTimeout = 16;
2152 msg.txAckSetting = 0;
2157 if (reset_port == 1) {
2158 msg.portEnabled = 1;
2160 msg.txBreak = (p_priv->break_on);
2163 else if (reset_port == 2)
2164 msg.portEnabled = 0;
2165 /* Sending intermediate configs */
2167 msg.portEnabled = 1;
2168 msg.txBreak = (p_priv->break_on);
2171 /* Do handshaking outputs */
2173 msg.rts = p_priv->rts_state;
2176 msg.dtr = p_priv->dtr_state;
2178 p_priv->resend_cont = 0;
2179 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2181 /* send the data out the device on control endpoint */
2182 this_urb->transfer_buffer_length = sizeof(msg);
2184 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2186 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2190 static int keyspan_usa67_send_setup(struct usb_serial *serial,
2191 struct usb_serial_port *port,
2194 struct keyspan_usa67_portControlMessage msg;
2195 struct keyspan_serial_private *s_priv;
2196 struct keyspan_port_private *p_priv;
2197 const struct keyspan_device_details *d_details;
2198 struct urb *this_urb;
2199 int err, device_port;
2201 s_priv = usb_get_serial_data(serial);
2202 p_priv = usb_get_serial_port_data(port);
2203 d_details = s_priv->device_details;
2205 this_urb = s_priv->glocont_urb;
2207 /* Work out which port within the device is being setup */
2208 device_port = port->number - port->serial->minor;
2210 /* Make sure we have an urb then send the message */
2211 if (this_urb == NULL) {
2212 dev_dbg(&port->dev, "%s - oops no urb for port %d.\n", __func__,
2217 /* Save reset port val for resend.
2218 Don't overwrite resend for open/close condition. */
2219 if ((reset_port + 1) > p_priv->resend_cont)
2220 p_priv->resend_cont = reset_port + 1;
2221 if (this_urb->status == -EINPROGRESS) {
2222 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2227 memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
2229 msg.port = device_port;
2231 /* Only set baud rate if it's changed */
2232 if (p_priv->old_baud != p_priv->baud) {
2233 p_priv->old_baud = p_priv->baud;
2234 msg.setClocking = 0xff;
2235 if (d_details->calculate_baud_rate(port, p_priv->baud, d_details->baudclk,
2236 &msg.baudHi, &msg.baudLo, &msg.prescaler,
2237 device_port) == KEYSPAN_INVALID_BAUD_RATE) {
2238 dev_dbg(&port->dev, "%s - Invalid baud rate %d requested, using 9600.\n",
2239 __func__, p_priv->baud);
2241 msg.baudHi = 125; /* Values for 9600 baud */
2244 msg.setPrescaler = 0xff;
2247 msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2248 switch (p_priv->cflag & CSIZE) {
2250 msg.lcr |= USA_DATABITS_5;
2253 msg.lcr |= USA_DATABITS_6;
2256 msg.lcr |= USA_DATABITS_7;
2259 msg.lcr |= USA_DATABITS_8;
2262 if (p_priv->cflag & PARENB) {
2263 /* note USA_PARITY_NONE == 0 */
2264 msg.lcr |= (p_priv->cflag & PARODD) ?
2265 USA_PARITY_ODD : USA_PARITY_EVEN;
2269 msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2270 msg.xonFlowControl = 0;
2271 msg.setFlowControl = 0xff;
2272 msg.forwardingLength = 16;
2276 if (reset_port == 1) {
2286 msg.returnStatus = 0;
2287 msg.resetDataToggle = 0xff;
2288 } else if (reset_port == 2) {
2298 msg.returnStatus = 0;
2299 msg.resetDataToggle = 0;
2301 /* Sending intermediate configs */
2302 msg._txOn = (!p_priv->break_on);
2305 msg.txBreak = (p_priv->break_on);
2310 msg.returnStatus = 0;
2311 msg.resetDataToggle = 0x0;
2314 /* Do handshaking outputs */
2315 msg.setTxTriState_setRts = 0xff;
2316 msg.txTriState_rts = p_priv->rts_state;
2318 msg.setHskoa_setDtr = 0xff;
2319 msg.hskoa_dtr = p_priv->dtr_state;
2321 p_priv->resend_cont = 0;
2323 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2325 /* send the data out the device on control endpoint */
2326 this_urb->transfer_buffer_length = sizeof(msg);
2328 err = usb_submit_urb(this_urb, GFP_ATOMIC);
2330 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2334 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2336 struct usb_serial *serial = port->serial;
2337 struct keyspan_serial_private *s_priv;
2338 const struct keyspan_device_details *d_details;
2340 s_priv = usb_get_serial_data(serial);
2341 d_details = s_priv->device_details;
2343 switch (d_details->msg_format) {
2345 keyspan_usa26_send_setup(serial, port, reset_port);
2348 keyspan_usa28_send_setup(serial, port, reset_port);
2351 keyspan_usa49_send_setup(serial, port, reset_port);
2354 keyspan_usa90_send_setup(serial, port, reset_port);
2357 keyspan_usa67_send_setup(serial, port, reset_port);
2363 /* Gets called by the "real" driver (ie once firmware is loaded
2364 and renumeration has taken place. */
2365 static int keyspan_startup(struct usb_serial *serial)
2368 struct keyspan_serial_private *s_priv;
2369 const struct keyspan_device_details *d_details;
2371 for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
2372 if (d_details->product_id ==
2373 le16_to_cpu(serial->dev->descriptor.idProduct))
2375 if (d_details == NULL) {
2376 dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
2377 __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
2381 /* Setup private data for serial driver */
2382 s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2384 dev_dbg(&serial->dev->dev, "%s - kmalloc for keyspan_serial_private failed.\n", __func__);
2388 s_priv->device_details = d_details;
2389 usb_set_serial_data(serial, s_priv);
2391 keyspan_setup_urbs(serial);
2393 if (s_priv->instat_urb != NULL) {
2394 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2396 dev_dbg(&serial->dev->dev, "%s - submit instat urb failed %d\n", __func__, err);
2398 if (s_priv->indat_urb != NULL) {
2399 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2401 dev_dbg(&serial->dev->dev, "%s - submit indat urb failed %d\n", __func__, err);
2407 static void keyspan_disconnect(struct usb_serial *serial)
2409 struct keyspan_serial_private *s_priv;
2411 s_priv = usb_get_serial_data(serial);
2413 stop_urb(s_priv->instat_urb);
2414 stop_urb(s_priv->glocont_urb);
2415 stop_urb(s_priv->indat_urb);
2418 static void keyspan_release(struct usb_serial *serial)
2420 struct keyspan_serial_private *s_priv;
2422 s_priv = usb_get_serial_data(serial);
2424 usb_free_urb(s_priv->instat_urb);
2425 usb_free_urb(s_priv->indat_urb);
2426 usb_free_urb(s_priv->glocont_urb);
2431 static int keyspan_port_probe(struct usb_serial_port *port)
2433 struct usb_serial *serial = port->serial;
2434 struct keyspan_serial_private *s_priv;
2435 struct keyspan_port_private *p_priv;
2436 const struct keyspan_device_details *d_details;
2437 struct callbacks *cback;
2442 s_priv = usb_get_serial_data(serial);
2443 d_details = s_priv->device_details;
2445 p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL);
2449 p_priv->device_details = d_details;
2451 /* Setup values for the various callback routines */
2452 cback = &keyspan_callbacks[d_details->msg_format];
2454 port_num = port->number - port->serial->minor;
2456 /* Do indat endpoints first, once for each flip */
2457 endp = d_details->indat_endpoints[port_num];
2458 for (i = 0; i <= d_details->indat_endp_flip; ++i, ++endp) {
2459 p_priv->in_urbs[i] = keyspan_setup_urb(serial, endp,
2461 p_priv->in_buffer[i], 64,
2462 cback->indat_callback);
2464 /* outdat endpoints also have flip */
2465 endp = d_details->outdat_endpoints[port_num];
2466 for (i = 0; i <= d_details->outdat_endp_flip; ++i, ++endp) {
2467 p_priv->out_urbs[i] = keyspan_setup_urb(serial, endp,
2469 p_priv->out_buffer[i], 64,
2470 cback->outdat_callback);
2472 /* inack endpoint */
2473 p_priv->inack_urb = keyspan_setup_urb(serial,
2474 d_details->inack_endpoints[port_num],
2476 p_priv->inack_buffer, 1,
2477 cback->inack_callback);
2478 /* outcont endpoint */
2479 p_priv->outcont_urb = keyspan_setup_urb(serial,
2480 d_details->outcont_endpoints[port_num],
2482 p_priv->outcont_buffer, 64,
2483 cback->outcont_callback);
2485 usb_set_serial_port_data(port, p_priv);
2490 static int keyspan_port_remove(struct usb_serial_port *port)
2492 struct keyspan_port_private *p_priv;
2495 p_priv = usb_get_serial_port_data(port);
2497 stop_urb(p_priv->inack_urb);
2498 stop_urb(p_priv->outcont_urb);
2499 for (i = 0; i < 2; i++) {
2500 stop_urb(p_priv->in_urbs[i]);
2501 stop_urb(p_priv->out_urbs[i]);
2504 usb_free_urb(p_priv->inack_urb);
2505 usb_free_urb(p_priv->outcont_urb);
2506 for (i = 0; i < 2; i++) {
2507 usb_free_urb(p_priv->in_urbs[i]);
2508 usb_free_urb(p_priv->out_urbs[i]);
2516 MODULE_AUTHOR(DRIVER_AUTHOR);
2517 MODULE_DESCRIPTION(DRIVER_DESC);
2518 MODULE_LICENSE("GPL");
2520 MODULE_FIRMWARE("keyspan/usa28.fw");
2521 MODULE_FIRMWARE("keyspan/usa28x.fw");
2522 MODULE_FIRMWARE("keyspan/usa28xa.fw");
2523 MODULE_FIRMWARE("keyspan/usa28xb.fw");
2524 MODULE_FIRMWARE("keyspan/usa19.fw");
2525 MODULE_FIRMWARE("keyspan/usa19qi.fw");
2526 MODULE_FIRMWARE("keyspan/mpr.fw");
2527 MODULE_FIRMWARE("keyspan/usa19qw.fw");
2528 MODULE_FIRMWARE("keyspan/usa18x.fw");
2529 MODULE_FIRMWARE("keyspan/usa19w.fw");
2530 MODULE_FIRMWARE("keyspan/usa49w.fw");
2531 MODULE_FIRMWARE("keyspan/usa49wlc.fw");