2 Keyspan USB to Serial Converter driver
4 (C) Copyright (C) 2000-2001 Hugh Blemings <hugh@blemings.org>
5 (C) Copyright (C) 2002 Greg Kroah-Hartman <greg@kroah.com>
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 See http://blemings.org/hugh/keyspan.html for more information.
14 Code in this driver inspired by and in a number of places taken
15 from Brian Warner's original Keyspan-PDA driver.
17 This driver has been put together with the support of Innosys, Inc.
18 and Keyspan, Inc the manufacturers of the Keyspan USB-serial products.
21 Thanks to Paulus for miscellaneous tidy ups, some largish chunks
22 of much nicer and/or completely new code and (perhaps most uniquely)
23 having the patience to sit down and explain why and where he'd changed
26 Tip 'o the hat to IBM (and previously Linuxcare :) for supporting
27 staff in their work on open source projects.
31 #include <linux/kernel.h>
32 #include <linux/jiffies.h>
33 #include <linux/errno.h>
34 #include <linux/slab.h>
35 #include <linux/tty.h>
36 #include <linux/tty_driver.h>
37 #include <linux/tty_flip.h>
38 #include <linux/module.h>
39 #include <linux/spinlock.h>
40 #include <linux/uaccess.h>
41 #include <linux/usb.h>
42 #include <linux/usb/serial.h>
43 #include <linux/usb/ezusb.h>
46 #define DRIVER_AUTHOR "Hugh Blemings <hugh@misc.nu"
47 #define DRIVER_DESC "Keyspan USB to Serial Converter Driver"
49 #define INSTAT_BUFLEN 32
50 #define GLOCONT_BUFLEN 64
51 #define INDAT49W_BUFLEN 512
54 #define INACK_BUFLEN 1
55 #define OUTCONT_BUFLEN 64
57 /* Per device and per port private data */
58 struct keyspan_serial_private
{
59 const struct keyspan_device_details
*device_details
;
61 struct urb
*instat_urb
;
64 /* added to support 49wg, where data from all 4 ports comes in
65 on 1 EP and high-speed supported */
66 struct urb
*indat_urb
;
69 /* XXX this one probably will need a lock */
70 struct urb
*glocont_urb
;
72 char *ctrl_buf
; /* for EP0 control message */
75 struct keyspan_port_private
{
76 /* Keep track of which input & output endpoints to use */
80 /* Keep duplicate of device details in each port
81 structure as well - simplifies some of the
82 callback functions etc. */
83 const struct keyspan_device_details
*device_details
;
85 /* Input endpoints and buffer for this port */
86 struct urb
*in_urbs
[2];
88 /* Output endpoints and buffer for this port */
89 struct urb
*out_urbs
[2];
92 /* Input ack endpoint */
93 struct urb
*inack_urb
;
96 /* Output control endpoint */
97 struct urb
*outcont_urb
;
100 /* Settings for the port */
104 unsigned int old_cflag
;
105 enum {flow_none
, flow_cts
, flow_xon
} flow_control
;
106 int rts_state
; /* Handshaking pins (outputs) */
108 int cts_state
; /* Handshaking pins (inputs) */
114 unsigned long tx_start_time
[2];
115 int resend_cont
; /* need to resend control packet */
118 /* Include Keyspan message headers. All current Keyspan Adapters
119 make use of one of five message formats which are referred
120 to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and
121 within this driver. */
122 #include "keyspan_usa26msg.h"
123 #include "keyspan_usa28msg.h"
124 #include "keyspan_usa49msg.h"
125 #include "keyspan_usa90msg.h"
126 #include "keyspan_usa67msg.h"
129 module_usb_serial_driver(serial_drivers
, keyspan_ids_combined
);
131 static void keyspan_break_ctl(struct tty_struct
*tty
, int break_state
)
133 struct usb_serial_port
*port
= tty
->driver_data
;
134 struct keyspan_port_private
*p_priv
;
136 p_priv
= usb_get_serial_port_data(port
);
138 if (break_state
== -1)
139 p_priv
->break_on
= 1;
141 p_priv
->break_on
= 0;
143 keyspan_send_setup(port
, 0);
147 static void keyspan_set_termios(struct tty_struct
*tty
,
148 struct usb_serial_port
*port
, struct ktermios
*old_termios
)
150 int baud_rate
, device_port
;
151 struct keyspan_port_private
*p_priv
;
152 const struct keyspan_device_details
*d_details
;
155 p_priv
= usb_get_serial_port_data(port
);
156 d_details
= p_priv
->device_details
;
157 cflag
= tty
->termios
.c_cflag
;
158 device_port
= port
->port_number
;
160 /* Baud rate calculation takes baud rate as an integer
161 so other rates can be generated if desired. */
162 baud_rate
= tty_get_baud_rate(tty
);
163 /* If no match or invalid, don't change */
164 if (d_details
->calculate_baud_rate(port
, baud_rate
, d_details
->baudclk
,
165 NULL
, NULL
, NULL
, device_port
) == KEYSPAN_BAUD_RATE_OK
) {
166 /* FIXME - more to do here to ensure rate changes cleanly */
167 /* FIXME - calculate exact rate from divisor ? */
168 p_priv
->baud
= baud_rate
;
170 baud_rate
= tty_termios_baud_rate(old_termios
);
172 tty_encode_baud_rate(tty
, baud_rate
, baud_rate
);
173 /* set CTS/RTS handshake etc. */
174 p_priv
->cflag
= cflag
;
175 p_priv
->flow_control
= (cflag
& CRTSCTS
) ? flow_cts
: flow_none
;
177 /* Mark/Space not supported */
178 tty
->termios
.c_cflag
&= ~CMSPAR
;
180 keyspan_send_setup(port
, 0);
183 static int keyspan_tiocmget(struct tty_struct
*tty
)
185 struct usb_serial_port
*port
= tty
->driver_data
;
186 struct keyspan_port_private
*p_priv
= usb_get_serial_port_data(port
);
189 value
= ((p_priv
->rts_state
) ? TIOCM_RTS
: 0) |
190 ((p_priv
->dtr_state
) ? TIOCM_DTR
: 0) |
191 ((p_priv
->cts_state
) ? TIOCM_CTS
: 0) |
192 ((p_priv
->dsr_state
) ? TIOCM_DSR
: 0) |
193 ((p_priv
->dcd_state
) ? TIOCM_CAR
: 0) |
194 ((p_priv
->ri_state
) ? TIOCM_RNG
: 0);
199 static int keyspan_tiocmset(struct tty_struct
*tty
,
200 unsigned int set
, unsigned int clear
)
202 struct usb_serial_port
*port
= tty
->driver_data
;
203 struct keyspan_port_private
*p_priv
= usb_get_serial_port_data(port
);
206 p_priv
->rts_state
= 1;
208 p_priv
->dtr_state
= 1;
209 if (clear
& TIOCM_RTS
)
210 p_priv
->rts_state
= 0;
211 if (clear
& TIOCM_DTR
)
212 p_priv
->dtr_state
= 0;
213 keyspan_send_setup(port
, 0);
217 /* Write function is similar for the four protocols used
218 with only a minor change for usa90 (usa19hs) required */
219 static int keyspan_write(struct tty_struct
*tty
,
220 struct usb_serial_port
*port
, const unsigned char *buf
, int count
)
222 struct keyspan_port_private
*p_priv
;
223 const struct keyspan_device_details
*d_details
;
226 struct urb
*this_urb
;
227 int err
, maxDataLen
, dataOffset
;
229 p_priv
= usb_get_serial_port_data(port
);
230 d_details
= p_priv
->device_details
;
232 if (d_details
->msg_format
== msg_usa90
) {
240 dev_dbg(&port
->dev
, "%s - %d chars, flip=%d\n", __func__
, count
,
243 for (left
= count
; left
> 0; left
-= todo
) {
245 if (todo
> maxDataLen
)
248 flip
= p_priv
->out_flip
;
250 /* Check we have a valid urb/endpoint before we use it... */
251 this_urb
= p_priv
->out_urbs
[flip
];
252 if (this_urb
== NULL
) {
253 /* no bulk out, so return 0 bytes written */
254 dev_dbg(&port
->dev
, "%s - no output urb :(\n", __func__
);
258 dev_dbg(&port
->dev
, "%s - endpoint %d flip %d\n",
259 __func__
, usb_pipeendpoint(this_urb
->pipe
), flip
);
261 if (this_urb
->status
== -EINPROGRESS
) {
262 if (time_before(jiffies
,
263 p_priv
->tx_start_time
[flip
] + 10 * HZ
))
265 usb_unlink_urb(this_urb
);
269 /* First byte in buffer is "last flag" (except for usa19hx)
270 - unused so for now so set to zero */
271 ((char *)this_urb
->transfer_buffer
)[0] = 0;
273 memcpy(this_urb
->transfer_buffer
+ dataOffset
, buf
, todo
);
276 /* send the data out the bulk port */
277 this_urb
->transfer_buffer_length
= todo
+ dataOffset
;
279 err
= usb_submit_urb(this_urb
, GFP_ATOMIC
);
281 dev_dbg(&port
->dev
, "usb_submit_urb(write bulk) failed (%d)\n", err
);
282 p_priv
->tx_start_time
[flip
] = jiffies
;
284 /* Flip for next time if usa26 or usa28 interface
285 (not used on usa49) */
286 p_priv
->out_flip
= (flip
+ 1) & d_details
->outdat_endp_flip
;
292 static void usa26_indat_callback(struct urb
*urb
)
296 struct usb_serial_port
*port
;
297 unsigned char *data
= urb
->transfer_buffer
;
298 int status
= urb
->status
;
300 endpoint
= usb_pipeendpoint(urb
->pipe
);
303 dev_dbg(&urb
->dev
->dev
, "%s - nonzero status: %x on endpoint %d.\n",
304 __func__
, status
, endpoint
);
309 if (urb
->actual_length
) {
310 /* 0x80 bit is error flag */
311 if ((data
[0] & 0x80) == 0) {
312 /* no errors on individual bytes, only
313 possible overrun err */
314 if (data
[0] & RXERROR_OVERRUN
)
318 for (i
= 1; i
< urb
->actual_length
; ++i
)
319 tty_insert_flip_char(&port
->port
, data
[i
], err
);
321 /* some bytes had errors, every byte has status */
322 dev_dbg(&port
->dev
, "%s - RX error!!!!\n", __func__
);
323 for (i
= 0; i
+ 1 < urb
->actual_length
; i
+= 2) {
324 int stat
= data
[i
], flag
= 0;
325 if (stat
& RXERROR_OVERRUN
)
327 if (stat
& RXERROR_FRAMING
)
329 if (stat
& RXERROR_PARITY
)
331 /* XXX should handle break (0x10) */
332 tty_insert_flip_char(&port
->port
, data
[i
+1],
336 tty_flip_buffer_push(&port
->port
);
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 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_port_tty_hangup(&port
->port
, true);
429 /* Resubmit urb so we continue receiving */
430 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
432 dev_dbg(&port
->dev
, "%s - resubmit read urb failed. (%d)\n", __func__
, err
);
436 static void usa26_glocont_callback(struct urb
*urb
)
441 static void usa28_indat_callback(struct urb
*urb
)
444 struct usb_serial_port
*port
;
446 struct keyspan_port_private
*p_priv
;
447 int status
= urb
->status
;
450 p_priv
= usb_get_serial_port_data(port
);
451 data
= urb
->transfer_buffer
;
453 if (urb
!= p_priv
->in_urbs
[p_priv
->in_flip
])
458 dev_dbg(&urb
->dev
->dev
, "%s - nonzero status: %x on endpoint %d.\n",
459 __func__
, status
, usb_pipeendpoint(urb
->pipe
));
464 p_priv
= usb_get_serial_port_data(port
);
465 data
= urb
->transfer_buffer
;
467 if (urb
->actual_length
) {
468 tty_insert_flip_string(&port
->port
, data
,
470 tty_flip_buffer_push(&port
->port
);
473 /* Resubmit urb so we continue receiving */
474 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
476 dev_dbg(&port
->dev
, "%s - resubmit read urb failed. (%d)\n",
478 p_priv
->in_flip
^= 1;
480 urb
= p_priv
->in_urbs
[p_priv
->in_flip
];
481 } while (urb
->status
!= -EINPROGRESS
);
484 static void usa28_inack_callback(struct urb
*urb
)
488 static void usa28_outcont_callback(struct urb
*urb
)
490 struct usb_serial_port
*port
;
491 struct keyspan_port_private
*p_priv
;
494 p_priv
= usb_get_serial_port_data(port
);
496 if (p_priv
->resend_cont
) {
497 dev_dbg(&port
->dev
, "%s - sending setup\n", __func__
);
498 keyspan_usa28_send_setup(port
->serial
, port
,
499 p_priv
->resend_cont
- 1);
503 static void usa28_instat_callback(struct urb
*urb
)
506 unsigned char *data
= urb
->transfer_buffer
;
507 struct keyspan_usa28_portStatusMessage
*msg
;
508 struct usb_serial
*serial
;
509 struct usb_serial_port
*port
;
510 struct keyspan_port_private
*p_priv
;
512 int status
= urb
->status
;
514 serial
= urb
->context
;
517 dev_dbg(&urb
->dev
->dev
, "%s - nonzero status: %x\n", __func__
, status
);
521 if (urb
->actual_length
!= sizeof(struct keyspan_usa28_portStatusMessage
)) {
522 dev_dbg(&urb
->dev
->dev
, "%s - bad length %d\n", __func__
, urb
->actual_length
);
526 /*dev_dbg(&urb->dev->dev, "%s %12ph", __func__, data);*/
528 /* Now do something useful with the data */
529 msg
= (struct keyspan_usa28_portStatusMessage
*)data
;
531 /* Check port number from message and retrieve private data */
532 if (msg
->port
>= serial
->num_ports
) {
533 dev_dbg(&urb
->dev
->dev
, "%s - Unexpected port number %d\n", __func__
, msg
->port
);
536 port
= serial
->port
[msg
->port
];
537 p_priv
= usb_get_serial_port_data(port
);
539 /* Update handshaking pin state information */
540 old_dcd_state
= p_priv
->dcd_state
;
541 p_priv
->cts_state
= ((msg
->cts
) ? 1 : 0);
542 p_priv
->dsr_state
= ((msg
->dsr
) ? 1 : 0);
543 p_priv
->dcd_state
= ((msg
->dcd
) ? 1 : 0);
544 p_priv
->ri_state
= ((msg
->ri
) ? 1 : 0);
546 if (old_dcd_state
!= p_priv
->dcd_state
&& old_dcd_state
)
547 tty_port_tty_hangup(&port
->port
, true);
549 /* Resubmit urb so we continue receiving */
550 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
552 dev_dbg(&port
->dev
, "%s - resubmit read urb failed. (%d)\n", __func__
, err
);
556 static void usa28_glocont_callback(struct urb
*urb
)
561 static void usa49_glocont_callback(struct urb
*urb
)
563 struct usb_serial
*serial
;
564 struct usb_serial_port
*port
;
565 struct keyspan_port_private
*p_priv
;
568 serial
= urb
->context
;
569 for (i
= 0; i
< serial
->num_ports
; ++i
) {
570 port
= serial
->port
[i
];
571 p_priv
= usb_get_serial_port_data(port
);
573 if (p_priv
->resend_cont
) {
574 dev_dbg(&port
->dev
, "%s - sending setup\n", __func__
);
575 keyspan_usa49_send_setup(serial
, port
,
576 p_priv
->resend_cont
- 1);
582 /* This is actually called glostat in the Keyspan
584 static void usa49_instat_callback(struct urb
*urb
)
587 unsigned char *data
= urb
->transfer_buffer
;
588 struct keyspan_usa49_portStatusMessage
*msg
;
589 struct usb_serial
*serial
;
590 struct usb_serial_port
*port
;
591 struct keyspan_port_private
*p_priv
;
593 int status
= urb
->status
;
595 serial
= urb
->context
;
598 dev_dbg(&urb
->dev
->dev
, "%s - nonzero status: %x\n", __func__
, status
);
602 if (urb
->actual_length
!=
603 sizeof(struct keyspan_usa49_portStatusMessage
)) {
604 dev_dbg(&urb
->dev
->dev
, "%s - bad length %d\n", __func__
, urb
->actual_length
);
608 /*dev_dbg(&urb->dev->dev, "%s: %11ph", __func__, data);*/
610 /* Now do something useful with the data */
611 msg
= (struct keyspan_usa49_portStatusMessage
*)data
;
613 /* Check port number from message and retrieve private data */
614 if (msg
->portNumber
>= serial
->num_ports
) {
615 dev_dbg(&urb
->dev
->dev
, "%s - Unexpected port number %d\n",
616 __func__
, msg
->portNumber
);
619 port
= serial
->port
[msg
->portNumber
];
620 p_priv
= usb_get_serial_port_data(port
);
622 /* Update handshaking pin state information */
623 old_dcd_state
= p_priv
->dcd_state
;
624 p_priv
->cts_state
= ((msg
->cts
) ? 1 : 0);
625 p_priv
->dsr_state
= ((msg
->dsr
) ? 1 : 0);
626 p_priv
->dcd_state
= ((msg
->dcd
) ? 1 : 0);
627 p_priv
->ri_state
= ((msg
->ri
) ? 1 : 0);
629 if (old_dcd_state
!= p_priv
->dcd_state
&& old_dcd_state
)
630 tty_port_tty_hangup(&port
->port
, true);
632 /* Resubmit urb so we continue receiving */
633 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
635 dev_dbg(&port
->dev
, "%s - resubmit read urb failed. (%d)\n", __func__
, err
);
639 static void usa49_inack_callback(struct urb
*urb
)
643 static void usa49_indat_callback(struct urb
*urb
)
647 struct usb_serial_port
*port
;
648 unsigned char *data
= urb
->transfer_buffer
;
649 int status
= urb
->status
;
651 endpoint
= usb_pipeendpoint(urb
->pipe
);
654 dev_dbg(&urb
->dev
->dev
, "%s - nonzero status: %x on endpoint %d.\n",
655 __func__
, status
, endpoint
);
660 if (urb
->actual_length
) {
661 /* 0x80 bit is error flag */
662 if ((data
[0] & 0x80) == 0) {
663 /* no error on any byte */
664 tty_insert_flip_string(&port
->port
, data
+ 1,
665 urb
->actual_length
- 1);
667 /* some bytes had errors, every byte has status */
668 for (i
= 0; i
+ 1 < urb
->actual_length
; i
+= 2) {
669 int stat
= data
[i
], flag
= 0;
670 if (stat
& RXERROR_OVERRUN
)
672 if (stat
& RXERROR_FRAMING
)
674 if (stat
& RXERROR_PARITY
)
676 /* XXX should handle break (0x10) */
677 tty_insert_flip_char(&port
->port
, data
[i
+1],
681 tty_flip_buffer_push(&port
->port
);
684 /* Resubmit urb so we continue receiving */
685 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
687 dev_dbg(&port
->dev
, "%s - resubmit read urb failed. (%d)\n", __func__
, err
);
690 static void usa49wg_indat_callback(struct urb
*urb
)
693 struct usb_serial
*serial
;
694 struct usb_serial_port
*port
;
695 unsigned char *data
= urb
->transfer_buffer
;
696 int status
= urb
->status
;
698 serial
= urb
->context
;
701 dev_dbg(&urb
->dev
->dev
, "%s - nonzero status: %x\n", __func__
, status
);
705 /* inbound data is in the form P#, len, status, data */
709 while (i
< urb
->actual_length
) {
711 /* Check port number from message */
712 if (data
[i
] >= serial
->num_ports
) {
713 dev_dbg(&urb
->dev
->dev
, "%s - Unexpected port number %d\n",
717 port
= serial
->port
[data
[i
++]];
720 /* 0x80 bit is error flag */
721 if ((data
[i
] & 0x80) == 0) {
722 /* no error on any byte */
724 for (x
= 1; x
< len
&& i
< urb
->actual_length
; ++x
)
725 tty_insert_flip_char(&port
->port
,
729 * some bytes had errors, every byte has status
731 for (x
= 0; x
+ 1 < len
&&
732 i
+ 1 < urb
->actual_length
; x
+= 2) {
733 int stat
= data
[i
], flag
= 0;
735 if (stat
& RXERROR_OVERRUN
)
737 if (stat
& RXERROR_FRAMING
)
739 if (stat
& RXERROR_PARITY
)
741 /* XXX should handle break (0x10) */
742 tty_insert_flip_char(&port
->port
, data
[i
+1],
747 tty_flip_buffer_push(&port
->port
);
750 /* Resubmit urb so we continue receiving */
751 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
753 dev_dbg(&urb
->dev
->dev
, "%s - resubmit read urb failed. (%d)\n", __func__
, err
);
756 /* not used, usa-49 doesn't have per-port control endpoints */
757 static void usa49_outcont_callback(struct urb
*urb
)
761 static void usa90_indat_callback(struct urb
*urb
)
765 struct usb_serial_port
*port
;
766 struct keyspan_port_private
*p_priv
;
767 unsigned char *data
= urb
->transfer_buffer
;
768 int status
= urb
->status
;
770 endpoint
= usb_pipeendpoint(urb
->pipe
);
773 dev_dbg(&urb
->dev
->dev
, "%s - nonzero status: %x on endpoint %d.\n",
774 __func__
, status
, endpoint
);
779 p_priv
= usb_get_serial_port_data(port
);
781 if (urb
->actual_length
) {
782 /* if current mode is DMA, looks like usa28 format
783 otherwise looks like usa26 data format */
785 if (p_priv
->baud
> 57600)
786 tty_insert_flip_string(&port
->port
, data
,
789 /* 0x80 bit is error flag */
790 if ((data
[0] & 0x80) == 0) {
791 /* no errors on individual bytes, only
792 possible overrun err*/
793 if (data
[0] & RXERROR_OVERRUN
)
797 for (i
= 1; i
< urb
->actual_length
; ++i
)
798 tty_insert_flip_char(&port
->port
,
801 /* some bytes had errors, every byte has status */
802 dev_dbg(&port
->dev
, "%s - RX error!!!!\n", __func__
);
803 for (i
= 0; i
+ 1 < urb
->actual_length
; i
+= 2) {
804 int stat
= data
[i
], flag
= 0;
805 if (stat
& RXERROR_OVERRUN
)
807 if (stat
& RXERROR_FRAMING
)
809 if (stat
& RXERROR_PARITY
)
811 /* XXX should handle break (0x10) */
812 tty_insert_flip_char(&port
->port
,
817 tty_flip_buffer_push(&port
->port
);
820 /* Resubmit urb so we continue receiving */
821 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
823 dev_dbg(&port
->dev
, "%s - resubmit read urb failed. (%d)\n", __func__
, err
);
827 static void usa90_instat_callback(struct urb
*urb
)
829 unsigned char *data
= urb
->transfer_buffer
;
830 struct keyspan_usa90_portStatusMessage
*msg
;
831 struct usb_serial
*serial
;
832 struct usb_serial_port
*port
;
833 struct keyspan_port_private
*p_priv
;
834 int old_dcd_state
, err
;
835 int status
= urb
->status
;
837 serial
= urb
->context
;
840 dev_dbg(&urb
->dev
->dev
, "%s - nonzero status: %x\n", __func__
, status
);
843 if (urb
->actual_length
< 14) {
844 dev_dbg(&urb
->dev
->dev
, "%s - %d byte report??\n", __func__
, urb
->actual_length
);
848 msg
= (struct keyspan_usa90_portStatusMessage
*)data
;
850 /* Now do something useful with the data */
852 port
= serial
->port
[0];
853 p_priv
= usb_get_serial_port_data(port
);
855 /* Update handshaking pin state information */
856 old_dcd_state
= p_priv
->dcd_state
;
857 p_priv
->cts_state
= ((msg
->cts
) ? 1 : 0);
858 p_priv
->dsr_state
= ((msg
->dsr
) ? 1 : 0);
859 p_priv
->dcd_state
= ((msg
->dcd
) ? 1 : 0);
860 p_priv
->ri_state
= ((msg
->ri
) ? 1 : 0);
862 if (old_dcd_state
!= p_priv
->dcd_state
&& old_dcd_state
)
863 tty_port_tty_hangup(&port
->port
, true);
865 /* Resubmit urb so we continue receiving */
866 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
868 dev_dbg(&port
->dev
, "%s - resubmit read urb failed. (%d)\n", __func__
, err
);
873 static void usa90_outcont_callback(struct urb
*urb
)
875 struct usb_serial_port
*port
;
876 struct keyspan_port_private
*p_priv
;
879 p_priv
= usb_get_serial_port_data(port
);
881 if (p_priv
->resend_cont
) {
882 dev_dbg(&urb
->dev
->dev
, "%s - sending setup\n", __func__
);
883 keyspan_usa90_send_setup(port
->serial
, port
,
884 p_priv
->resend_cont
- 1);
888 /* Status messages from the 28xg */
889 static void usa67_instat_callback(struct urb
*urb
)
892 unsigned char *data
= urb
->transfer_buffer
;
893 struct keyspan_usa67_portStatusMessage
*msg
;
894 struct usb_serial
*serial
;
895 struct usb_serial_port
*port
;
896 struct keyspan_port_private
*p_priv
;
898 int status
= urb
->status
;
900 serial
= urb
->context
;
903 dev_dbg(&urb
->dev
->dev
, "%s - nonzero status: %x\n", __func__
, status
);
907 if (urb
->actual_length
!=
908 sizeof(struct keyspan_usa67_portStatusMessage
)) {
909 dev_dbg(&urb
->dev
->dev
, "%s - bad length %d\n", __func__
, urb
->actual_length
);
914 /* Now do something useful with the data */
915 msg
= (struct keyspan_usa67_portStatusMessage
*)data
;
917 /* Check port number from message and retrieve private data */
918 if (msg
->port
>= serial
->num_ports
) {
919 dev_dbg(&urb
->dev
->dev
, "%s - Unexpected port number %d\n", __func__
, msg
->port
);
923 port
= serial
->port
[msg
->port
];
924 p_priv
= usb_get_serial_port_data(port
);
926 /* Update handshaking pin state information */
927 old_dcd_state
= p_priv
->dcd_state
;
928 p_priv
->cts_state
= ((msg
->hskia_cts
) ? 1 : 0);
929 p_priv
->dcd_state
= ((msg
->gpia_dcd
) ? 1 : 0);
931 if (old_dcd_state
!= p_priv
->dcd_state
&& old_dcd_state
)
932 tty_port_tty_hangup(&port
->port
, true);
934 /* Resubmit urb so we continue receiving */
935 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
937 dev_dbg(&port
->dev
, "%s - resubmit read urb failed. (%d)\n", __func__
, err
);
940 static void usa67_glocont_callback(struct urb
*urb
)
942 struct usb_serial
*serial
;
943 struct usb_serial_port
*port
;
944 struct keyspan_port_private
*p_priv
;
947 serial
= urb
->context
;
948 for (i
= 0; i
< serial
->num_ports
; ++i
) {
949 port
= serial
->port
[i
];
950 p_priv
= usb_get_serial_port_data(port
);
952 if (p_priv
->resend_cont
) {
953 dev_dbg(&port
->dev
, "%s - sending setup\n", __func__
);
954 keyspan_usa67_send_setup(serial
, port
,
955 p_priv
->resend_cont
- 1);
961 static int keyspan_write_room(struct tty_struct
*tty
)
963 struct usb_serial_port
*port
= tty
->driver_data
;
964 struct keyspan_port_private
*p_priv
;
965 const struct keyspan_device_details
*d_details
;
968 struct urb
*this_urb
;
970 p_priv
= usb_get_serial_port_data(port
);
971 d_details
= p_priv
->device_details
;
974 if (d_details
->msg_format
== msg_usa90
)
979 flip
= p_priv
->out_flip
;
981 /* Check both endpoints to see if any are available. */
982 this_urb
= p_priv
->out_urbs
[flip
];
983 if (this_urb
!= NULL
) {
984 if (this_urb
->status
!= -EINPROGRESS
)
986 flip
= (flip
+ 1) & d_details
->outdat_endp_flip
;
987 this_urb
= p_priv
->out_urbs
[flip
];
988 if (this_urb
!= NULL
) {
989 if (this_urb
->status
!= -EINPROGRESS
)
997 static int keyspan_open(struct tty_struct
*tty
, struct usb_serial_port
*port
)
999 struct keyspan_port_private
*p_priv
;
1000 const struct keyspan_device_details
*d_details
;
1002 int baud_rate
, device_port
;
1004 unsigned int cflag
= 0;
1006 p_priv
= usb_get_serial_port_data(port
);
1007 d_details
= p_priv
->device_details
;
1009 /* Set some sane defaults */
1010 p_priv
->rts_state
= 1;
1011 p_priv
->dtr_state
= 1;
1012 p_priv
->baud
= 9600;
1014 /* force baud and lcr to be set on open */
1015 p_priv
->old_baud
= 0;
1016 p_priv
->old_cflag
= 0;
1018 p_priv
->out_flip
= 0;
1019 p_priv
->in_flip
= 0;
1021 /* Reset low level data toggle and start reading from endpoints */
1022 for (i
= 0; i
< 2; i
++) {
1023 urb
= p_priv
->in_urbs
[i
];
1027 /* make sure endpoint data toggle is synchronized
1029 usb_clear_halt(urb
->dev
, urb
->pipe
);
1030 err
= usb_submit_urb(urb
, GFP_KERNEL
);
1032 dev_dbg(&port
->dev
, "%s - submit urb %d failed (%d)\n", __func__
, i
, err
);
1035 /* Reset low level data toggle on out endpoints */
1036 for (i
= 0; i
< 2; i
++) {
1037 urb
= p_priv
->out_urbs
[i
];
1040 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1041 usb_pipeout(urb->pipe), 0); */
1044 /* get the terminal config for the setup message now so we don't
1045 * need to send 2 of them */
1047 device_port
= port
->port_number
;
1049 cflag
= tty
->termios
.c_cflag
;
1050 /* Baud rate calculation takes baud rate as an integer
1051 so other rates can be generated if desired. */
1052 baud_rate
= tty_get_baud_rate(tty
);
1053 /* If no match or invalid, leave as default */
1055 && d_details
->calculate_baud_rate(port
, baud_rate
, d_details
->baudclk
,
1056 NULL
, NULL
, NULL
, device_port
) == KEYSPAN_BAUD_RATE_OK
) {
1057 p_priv
->baud
= baud_rate
;
1060 /* set CTS/RTS handshake etc. */
1061 p_priv
->cflag
= cflag
;
1062 p_priv
->flow_control
= (cflag
& CRTSCTS
) ? flow_cts
: flow_none
;
1064 keyspan_send_setup(port
, 1);
1066 /* keyspan_set_termios(port, NULL); */
1071 static inline void stop_urb(struct urb
*urb
)
1073 if (urb
&& urb
->status
== -EINPROGRESS
)
1077 static void keyspan_dtr_rts(struct usb_serial_port
*port
, int on
)
1079 struct keyspan_port_private
*p_priv
= usb_get_serial_port_data(port
);
1081 p_priv
->rts_state
= on
;
1082 p_priv
->dtr_state
= on
;
1083 keyspan_send_setup(port
, 0);
1086 static void keyspan_close(struct usb_serial_port
*port
)
1089 struct keyspan_port_private
*p_priv
;
1091 p_priv
= usb_get_serial_port_data(port
);
1093 p_priv
->rts_state
= 0;
1094 p_priv
->dtr_state
= 0;
1096 keyspan_send_setup(port
, 2);
1097 /* pilot-xfer seems to work best with this delay */
1100 p_priv
->out_flip
= 0;
1101 p_priv
->in_flip
= 0;
1103 stop_urb(p_priv
->inack_urb
);
1104 for (i
= 0; i
< 2; i
++) {
1105 stop_urb(p_priv
->in_urbs
[i
]);
1106 stop_urb(p_priv
->out_urbs
[i
]);
1110 /* download the firmware to a pre-renumeration device */
1111 static int keyspan_fake_startup(struct usb_serial
*serial
)
1115 dev_dbg(&serial
->dev
->dev
, "Keyspan startup version %04x product %04x\n",
1116 le16_to_cpu(serial
->dev
->descriptor
.bcdDevice
),
1117 le16_to_cpu(serial
->dev
->descriptor
.idProduct
));
1119 if ((le16_to_cpu(serial
->dev
->descriptor
.bcdDevice
) & 0x8000)
1121 dev_dbg(&serial
->dev
->dev
, "Firmware already loaded. Quitting.\n");
1125 /* Select firmware image on the basis of idProduct */
1126 switch (le16_to_cpu(serial
->dev
->descriptor
.idProduct
)) {
1127 case keyspan_usa28_pre_product_id
:
1128 fw_name
= "keyspan/usa28.fw";
1131 case keyspan_usa28x_pre_product_id
:
1132 fw_name
= "keyspan/usa28x.fw";
1135 case keyspan_usa28xa_pre_product_id
:
1136 fw_name
= "keyspan/usa28xa.fw";
1139 case keyspan_usa28xb_pre_product_id
:
1140 fw_name
= "keyspan/usa28xb.fw";
1143 case keyspan_usa19_pre_product_id
:
1144 fw_name
= "keyspan/usa19.fw";
1147 case keyspan_usa19qi_pre_product_id
:
1148 fw_name
= "keyspan/usa19qi.fw";
1151 case keyspan_mpr_pre_product_id
:
1152 fw_name
= "keyspan/mpr.fw";
1155 case keyspan_usa19qw_pre_product_id
:
1156 fw_name
= "keyspan/usa19qw.fw";
1159 case keyspan_usa18x_pre_product_id
:
1160 fw_name
= "keyspan/usa18x.fw";
1163 case keyspan_usa19w_pre_product_id
:
1164 fw_name
= "keyspan/usa19w.fw";
1167 case keyspan_usa49w_pre_product_id
:
1168 fw_name
= "keyspan/usa49w.fw";
1171 case keyspan_usa49wlc_pre_product_id
:
1172 fw_name
= "keyspan/usa49wlc.fw";
1176 dev_err(&serial
->dev
->dev
, "Unknown product ID (%04x)\n",
1177 le16_to_cpu(serial
->dev
->descriptor
.idProduct
));
1181 dev_dbg(&serial
->dev
->dev
, "Uploading Keyspan %s firmware.\n", fw_name
);
1183 if (ezusb_fx1_ihex_firmware_download(serial
->dev
, fw_name
) < 0) {
1184 dev_err(&serial
->dev
->dev
, "failed to load firmware \"%s\"\n",
1189 /* after downloading firmware Renumeration will occur in a
1190 moment and the new device will bind to the real driver */
1192 /* we don't want this device to have a driver assigned to it. */
1196 /* Helper functions used by keyspan_setup_urbs */
1197 static struct usb_endpoint_descriptor
const *find_ep(struct usb_serial
const *serial
,
1200 struct usb_host_interface
*iface_desc
;
1201 struct usb_endpoint_descriptor
*ep
;
1204 iface_desc
= serial
->interface
->cur_altsetting
;
1205 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; ++i
) {
1206 ep
= &iface_desc
->endpoint
[i
].desc
;
1207 if (ep
->bEndpointAddress
== endpoint
)
1210 dev_warn(&serial
->interface
->dev
, "found no endpoint descriptor for "
1211 "endpoint %x\n", endpoint
);
1215 static struct urb
*keyspan_setup_urb(struct usb_serial
*serial
, int endpoint
,
1216 int dir
, void *ctx
, char *buf
, int len
,
1217 void (*callback
)(struct urb
*))
1220 struct usb_endpoint_descriptor
const *ep_desc
;
1221 char const *ep_type_name
;
1224 return NULL
; /* endpoint not needed */
1226 dev_dbg(&serial
->interface
->dev
, "%s - alloc for endpoint %d.\n", __func__
, endpoint
);
1227 urb
= usb_alloc_urb(0, GFP_KERNEL
); /* No ISO */
1231 if (endpoint
== 0) {
1232 /* control EP filled in when used */
1236 ep_desc
= find_ep(serial
, endpoint
);
1238 /* leak the urb, something's wrong and the callers don't care */
1241 if (usb_endpoint_xfer_int(ep_desc
)) {
1242 ep_type_name
= "INT";
1243 usb_fill_int_urb(urb
, serial
->dev
,
1244 usb_sndintpipe(serial
->dev
, endpoint
) | dir
,
1245 buf
, len
, callback
, ctx
,
1246 ep_desc
->bInterval
);
1247 } else if (usb_endpoint_xfer_bulk(ep_desc
)) {
1248 ep_type_name
= "BULK";
1249 usb_fill_bulk_urb(urb
, serial
->dev
,
1250 usb_sndbulkpipe(serial
->dev
, endpoint
) | dir
,
1251 buf
, len
, callback
, ctx
);
1253 dev_warn(&serial
->interface
->dev
,
1254 "unsupported endpoint type %x\n",
1255 usb_endpoint_type(ep_desc
));
1260 dev_dbg(&serial
->interface
->dev
, "%s - using urb %p for %s endpoint %x\n",
1261 __func__
, urb
, ep_type_name
, endpoint
);
1265 static struct callbacks
{
1266 void (*instat_callback
)(struct urb
*);
1267 void (*glocont_callback
)(struct urb
*);
1268 void (*indat_callback
)(struct urb
*);
1269 void (*outdat_callback
)(struct urb
*);
1270 void (*inack_callback
)(struct urb
*);
1271 void (*outcont_callback
)(struct urb
*);
1272 } keyspan_callbacks
[] = {
1274 /* msg_usa26 callbacks */
1275 .instat_callback
= usa26_instat_callback
,
1276 .glocont_callback
= usa26_glocont_callback
,
1277 .indat_callback
= usa26_indat_callback
,
1278 .outdat_callback
= usa2x_outdat_callback
,
1279 .inack_callback
= usa26_inack_callback
,
1280 .outcont_callback
= usa26_outcont_callback
,
1282 /* msg_usa28 callbacks */
1283 .instat_callback
= usa28_instat_callback
,
1284 .glocont_callback
= usa28_glocont_callback
,
1285 .indat_callback
= usa28_indat_callback
,
1286 .outdat_callback
= usa2x_outdat_callback
,
1287 .inack_callback
= usa28_inack_callback
,
1288 .outcont_callback
= usa28_outcont_callback
,
1290 /* msg_usa49 callbacks */
1291 .instat_callback
= usa49_instat_callback
,
1292 .glocont_callback
= usa49_glocont_callback
,
1293 .indat_callback
= usa49_indat_callback
,
1294 .outdat_callback
= usa2x_outdat_callback
,
1295 .inack_callback
= usa49_inack_callback
,
1296 .outcont_callback
= usa49_outcont_callback
,
1298 /* msg_usa90 callbacks */
1299 .instat_callback
= usa90_instat_callback
,
1300 .glocont_callback
= usa28_glocont_callback
,
1301 .indat_callback
= usa90_indat_callback
,
1302 .outdat_callback
= usa2x_outdat_callback
,
1303 .inack_callback
= usa28_inack_callback
,
1304 .outcont_callback
= usa90_outcont_callback
,
1306 /* msg_usa67 callbacks */
1307 .instat_callback
= usa67_instat_callback
,
1308 .glocont_callback
= usa67_glocont_callback
,
1309 .indat_callback
= usa26_indat_callback
,
1310 .outdat_callback
= usa2x_outdat_callback
,
1311 .inack_callback
= usa26_inack_callback
,
1312 .outcont_callback
= usa26_outcont_callback
,
1316 /* Generic setup urbs function that uses
1317 data in device_details */
1318 static void keyspan_setup_urbs(struct usb_serial
*serial
)
1320 struct keyspan_serial_private
*s_priv
;
1321 const struct keyspan_device_details
*d_details
;
1322 struct callbacks
*cback
;
1324 s_priv
= usb_get_serial_data(serial
);
1325 d_details
= s_priv
->device_details
;
1327 /* Setup values for the various callback routines */
1328 cback
= &keyspan_callbacks
[d_details
->msg_format
];
1330 /* Allocate and set up urbs for each one that is in use,
1331 starting with instat endpoints */
1332 s_priv
->instat_urb
= keyspan_setup_urb
1333 (serial
, d_details
->instat_endpoint
, USB_DIR_IN
,
1334 serial
, s_priv
->instat_buf
, INSTAT_BUFLEN
,
1335 cback
->instat_callback
);
1337 s_priv
->indat_urb
= keyspan_setup_urb
1338 (serial
, d_details
->indat_endpoint
, USB_DIR_IN
,
1339 serial
, s_priv
->indat_buf
, INDAT49W_BUFLEN
,
1340 usa49wg_indat_callback
);
1342 s_priv
->glocont_urb
= keyspan_setup_urb
1343 (serial
, d_details
->glocont_endpoint
, USB_DIR_OUT
,
1344 serial
, s_priv
->glocont_buf
, GLOCONT_BUFLEN
,
1345 cback
->glocont_callback
);
1348 /* usa19 function doesn't require prescaler */
1349 static int keyspan_usa19_calc_baud(struct usb_serial_port
*port
,
1350 u32 baud_rate
, u32 baudclk
, u8
*rate_hi
,
1351 u8
*rate_low
, u8
*prescaler
, int portnum
)
1353 u32 b16
, /* baud rate times 16 (actual rate used internally) */
1355 cnt
; /* inverse of divisor (programmed into 8051) */
1357 dev_dbg(&port
->dev
, "%s - %d.\n", __func__
, baud_rate
);
1359 /* prevent divide by zero... */
1360 b16
= baud_rate
* 16L;
1362 return KEYSPAN_INVALID_BAUD_RATE
;
1363 /* Any "standard" rate over 57k6 is marginal on the USA-19
1364 as we run out of divisor resolution. */
1365 if (baud_rate
> 57600)
1366 return KEYSPAN_INVALID_BAUD_RATE
;
1368 /* calculate the divisor and the counter (its inverse) */
1369 div
= baudclk
/ b16
;
1371 return KEYSPAN_INVALID_BAUD_RATE
;
1376 return KEYSPAN_INVALID_BAUD_RATE
;
1378 /* return the counter values if non-null */
1380 *rate_low
= (u8
) (cnt
& 0xff);
1382 *rate_hi
= (u8
) ((cnt
>> 8) & 0xff);
1383 if (rate_low
&& rate_hi
)
1384 dev_dbg(&port
->dev
, "%s - %d %02x %02x.\n",
1385 __func__
, baud_rate
, *rate_hi
, *rate_low
);
1386 return KEYSPAN_BAUD_RATE_OK
;
1389 /* usa19hs function doesn't require prescaler */
1390 static int keyspan_usa19hs_calc_baud(struct usb_serial_port
*port
,
1391 u32 baud_rate
, u32 baudclk
, u8
*rate_hi
,
1392 u8
*rate_low
, u8
*prescaler
, int portnum
)
1394 u32 b16
, /* baud rate times 16 (actual rate used internally) */
1397 dev_dbg(&port
->dev
, "%s - %d.\n", __func__
, baud_rate
);
1399 /* prevent divide by zero... */
1400 b16
= baud_rate
* 16L;
1402 return KEYSPAN_INVALID_BAUD_RATE
;
1404 /* calculate the divisor */
1405 div
= baudclk
/ b16
;
1407 return KEYSPAN_INVALID_BAUD_RATE
;
1410 return KEYSPAN_INVALID_BAUD_RATE
;
1412 /* return the counter values if non-null */
1414 *rate_low
= (u8
) (div
& 0xff);
1417 *rate_hi
= (u8
) ((div
>> 8) & 0xff);
1419 if (rate_low
&& rate_hi
)
1420 dev_dbg(&port
->dev
, "%s - %d %02x %02x.\n",
1421 __func__
, baud_rate
, *rate_hi
, *rate_low
);
1423 return KEYSPAN_BAUD_RATE_OK
;
1426 static int keyspan_usa19w_calc_baud(struct usb_serial_port
*port
,
1427 u32 baud_rate
, u32 baudclk
, u8
*rate_hi
,
1428 u8
*rate_low
, u8
*prescaler
, int portnum
)
1430 u32 b16
, /* baud rate times 16 (actual rate used internally) */
1431 clk
, /* clock with 13/8 prescaler */
1432 div
, /* divisor using 13/8 prescaler */
1433 res
, /* resulting baud rate using 13/8 prescaler */
1434 diff
, /* error using 13/8 prescaler */
1439 dev_dbg(&port
->dev
, "%s - %d.\n", __func__
, baud_rate
);
1441 /* prevent divide by zero */
1442 b16
= baud_rate
* 16L;
1444 return KEYSPAN_INVALID_BAUD_RATE
;
1446 /* Calculate prescaler by trying them all and looking
1449 /* start with largest possible difference */
1450 smallest_diff
= 0xffffffff;
1452 /* 0 is an invalid prescaler, used as a flag */
1455 for (i
= 8; i
<= 0xff; ++i
) {
1456 clk
= (baudclk
* 8) / (u32
) i
;
1463 diff
= (res
> b16
) ? (res
-b16
) : (b16
-res
);
1465 if (diff
< smallest_diff
) {
1467 smallest_diff
= diff
;
1471 if (best_prescaler
== 0)
1472 return KEYSPAN_INVALID_BAUD_RATE
;
1474 clk
= (baudclk
* 8) / (u32
) best_prescaler
;
1477 /* return the divisor and prescaler if non-null */
1479 *rate_low
= (u8
) (div
& 0xff);
1481 *rate_hi
= (u8
) ((div
>> 8) & 0xff);
1483 *prescaler
= best_prescaler
;
1484 /* dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
1486 return KEYSPAN_BAUD_RATE_OK
;
1489 /* USA-28 supports different maximum baud rates on each port */
1490 static int keyspan_usa28_calc_baud(struct usb_serial_port
*port
,
1491 u32 baud_rate
, u32 baudclk
, u8
*rate_hi
,
1492 u8
*rate_low
, u8
*prescaler
, int portnum
)
1494 u32 b16
, /* baud rate times 16 (actual rate used internally) */
1496 cnt
; /* inverse of divisor (programmed into 8051) */
1498 dev_dbg(&port
->dev
, "%s - %d.\n", __func__
, baud_rate
);
1500 /* prevent divide by zero */
1501 b16
= baud_rate
* 16L;
1503 return KEYSPAN_INVALID_BAUD_RATE
;
1505 /* calculate the divisor and the counter (its inverse) */
1506 div
= KEYSPAN_USA28_BAUDCLK
/ b16
;
1508 return KEYSPAN_INVALID_BAUD_RATE
;
1512 /* check for out of range, based on portnum,
1513 and return result */
1516 return KEYSPAN_INVALID_BAUD_RATE
;
1520 return KEYSPAN_INVALID_BAUD_RATE
;
1522 return KEYSPAN_INVALID_BAUD_RATE
;
1525 /* return the counter values if not NULL
1526 (port 1 will ignore retHi) */
1528 *rate_low
= (u8
) (cnt
& 0xff);
1530 *rate_hi
= (u8
) ((cnt
>> 8) & 0xff);
1531 dev_dbg(&port
->dev
, "%s - %d OK.\n", __func__
, baud_rate
);
1532 return KEYSPAN_BAUD_RATE_OK
;
1535 static int keyspan_usa26_send_setup(struct usb_serial
*serial
,
1536 struct usb_serial_port
*port
,
1539 struct keyspan_usa26_portControlMessage msg
;
1540 struct keyspan_serial_private
*s_priv
;
1541 struct keyspan_port_private
*p_priv
;
1542 const struct keyspan_device_details
*d_details
;
1543 struct urb
*this_urb
;
1544 int device_port
, err
;
1546 dev_dbg(&port
->dev
, "%s reset=%d\n", __func__
, reset_port
);
1548 s_priv
= usb_get_serial_data(serial
);
1549 p_priv
= usb_get_serial_port_data(port
);
1550 d_details
= s_priv
->device_details
;
1551 device_port
= port
->port_number
;
1553 this_urb
= p_priv
->outcont_urb
;
1555 dev_dbg(&port
->dev
, "%s - endpoint %d\n", __func__
, usb_pipeendpoint(this_urb
->pipe
));
1557 /* Make sure we have an urb then send the message */
1558 if (this_urb
== NULL
) {
1559 dev_dbg(&port
->dev
, "%s - oops no urb.\n", __func__
);
1563 /* Save reset port val for resend.
1564 Don't overwrite resend for open/close condition. */
1565 if ((reset_port
+ 1) > p_priv
->resend_cont
)
1566 p_priv
->resend_cont
= reset_port
+ 1;
1567 if (this_urb
->status
== -EINPROGRESS
) {
1568 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1573 memset(&msg
, 0, sizeof(struct keyspan_usa26_portControlMessage
));
1575 /* Only set baud rate if it's changed */
1576 if (p_priv
->old_baud
!= p_priv
->baud
) {
1577 p_priv
->old_baud
= p_priv
->baud
;
1578 msg
.setClocking
= 0xff;
1579 if (d_details
->calculate_baud_rate(port
, p_priv
->baud
, d_details
->baudclk
,
1580 &msg
.baudHi
, &msg
.baudLo
, &msg
.prescaler
,
1581 device_port
) == KEYSPAN_INVALID_BAUD_RATE
) {
1582 dev_dbg(&port
->dev
, "%s - Invalid baud rate %d requested, using 9600.\n",
1583 __func__
, p_priv
->baud
);
1585 msg
.baudHi
= 125; /* Values for 9600 baud */
1588 msg
.setPrescaler
= 0xff;
1591 msg
.lcr
= (p_priv
->cflag
& CSTOPB
) ? STOPBITS_678_2
: STOPBITS_5678_1
;
1592 switch (p_priv
->cflag
& CSIZE
) {
1594 msg
.lcr
|= USA_DATABITS_5
;
1597 msg
.lcr
|= USA_DATABITS_6
;
1600 msg
.lcr
|= USA_DATABITS_7
;
1603 msg
.lcr
|= USA_DATABITS_8
;
1606 if (p_priv
->cflag
& PARENB
) {
1607 /* note USA_PARITY_NONE == 0 */
1608 msg
.lcr
|= (p_priv
->cflag
& PARODD
) ?
1609 USA_PARITY_ODD
: USA_PARITY_EVEN
;
1613 msg
.ctsFlowControl
= (p_priv
->flow_control
== flow_cts
);
1614 msg
.xonFlowControl
= 0;
1615 msg
.setFlowControl
= 0xff;
1616 msg
.forwardingLength
= 16;
1621 if (reset_port
== 1) {
1630 msg
.returnStatus
= 0;
1631 msg
.resetDataToggle
= 0xff;
1635 else if (reset_port
== 2) {
1644 msg
.returnStatus
= 0;
1645 msg
.resetDataToggle
= 0;
1648 /* Sending intermediate configs */
1650 msg
._txOn
= (!p_priv
->break_on
);
1653 msg
.txBreak
= (p_priv
->break_on
);
1658 msg
.returnStatus
= 0;
1659 msg
.resetDataToggle
= 0x0;
1662 /* Do handshaking outputs */
1663 msg
.setTxTriState_setRts
= 0xff;
1664 msg
.txTriState_rts
= p_priv
->rts_state
;
1666 msg
.setHskoa_setDtr
= 0xff;
1667 msg
.hskoa_dtr
= p_priv
->dtr_state
;
1669 p_priv
->resend_cont
= 0;
1670 memcpy(this_urb
->transfer_buffer
, &msg
, sizeof(msg
));
1672 /* send the data out the device on control endpoint */
1673 this_urb
->transfer_buffer_length
= sizeof(msg
);
1675 err
= usb_submit_urb(this_urb
, GFP_ATOMIC
);
1677 dev_dbg(&port
->dev
, "%s - usb_submit_urb(setup) failed (%d)\n", __func__
, err
);
1681 static int keyspan_usa28_send_setup(struct usb_serial
*serial
,
1682 struct usb_serial_port
*port
,
1685 struct keyspan_usa28_portControlMessage msg
;
1686 struct keyspan_serial_private
*s_priv
;
1687 struct keyspan_port_private
*p_priv
;
1688 const struct keyspan_device_details
*d_details
;
1689 struct urb
*this_urb
;
1690 int device_port
, err
;
1692 s_priv
= usb_get_serial_data(serial
);
1693 p_priv
= usb_get_serial_port_data(port
);
1694 d_details
= s_priv
->device_details
;
1695 device_port
= port
->port_number
;
1697 /* only do something if we have a bulk out endpoint */
1698 this_urb
= p_priv
->outcont_urb
;
1699 if (this_urb
== NULL
) {
1700 dev_dbg(&port
->dev
, "%s - oops no urb.\n", __func__
);
1704 /* Save reset port val for resend.
1705 Don't overwrite resend for open/close condition. */
1706 if ((reset_port
+ 1) > p_priv
->resend_cont
)
1707 p_priv
->resend_cont
= reset_port
+ 1;
1708 if (this_urb
->status
== -EINPROGRESS
) {
1709 dev_dbg(&port
->dev
, "%s already writing\n", __func__
);
1714 memset(&msg
, 0, sizeof(struct keyspan_usa28_portControlMessage
));
1716 msg
.setBaudRate
= 1;
1717 if (d_details
->calculate_baud_rate(port
, p_priv
->baud
, d_details
->baudclk
,
1718 &msg
.baudHi
, &msg
.baudLo
, NULL
,
1719 device_port
) == KEYSPAN_INVALID_BAUD_RATE
) {
1720 dev_dbg(&port
->dev
, "%s - Invalid baud rate requested %d.\n",
1721 __func__
, p_priv
->baud
);
1723 msg
.baudHi
= 0xb2; /* Values for 9600 baud */
1726 /* If parity is enabled, we must calculate it ourselves. */
1727 msg
.parity
= 0; /* XXX for now */
1729 msg
.ctsFlowControl
= (p_priv
->flow_control
== flow_cts
);
1730 msg
.xonFlowControl
= 0;
1732 /* Do handshaking outputs, DTR is inverted relative to RTS */
1733 msg
.rts
= p_priv
->rts_state
;
1734 msg
.dtr
= p_priv
->dtr_state
;
1736 msg
.forwardingLength
= 16;
1738 msg
.breakThreshold
= 45;
1742 /*msg.returnStatus = 1;
1743 msg.resetDataToggle = 0xff;*/
1745 if (reset_port
== 1) {
1749 msg
.txForceXoff
= 0;
1755 msg
.returnStatus
= 0;
1756 msg
.resetDataToggle
= 0xff;
1759 else if (reset_port
== 2) {
1763 msg
.txForceXoff
= 0;
1769 msg
.returnStatus
= 0;
1770 msg
.resetDataToggle
= 0;
1772 /* Sending intermediate configs */
1774 msg
._txOn
= (!p_priv
->break_on
);
1777 msg
.txForceXoff
= 0;
1778 msg
.txBreak
= (p_priv
->break_on
);
1783 msg
.returnStatus
= 0;
1784 msg
.resetDataToggle
= 0x0;
1787 p_priv
->resend_cont
= 0;
1788 memcpy(this_urb
->transfer_buffer
, &msg
, sizeof(msg
));
1790 /* send the data out the device on control endpoint */
1791 this_urb
->transfer_buffer_length
= sizeof(msg
);
1793 err
= usb_submit_urb(this_urb
, GFP_ATOMIC
);
1795 dev_dbg(&port
->dev
, "%s - usb_submit_urb(setup) failed\n", __func__
);
1798 dev_dbg(&port
->dev
, "%s - usb_submit_urb(setup) OK %d bytes\n", __func__
,
1799 this_urb
->transfer_buffer_length
);
1806 static int keyspan_usa49_send_setup(struct usb_serial
*serial
,
1807 struct usb_serial_port
*port
,
1810 struct keyspan_usa49_portControlMessage msg
;
1811 struct usb_ctrlrequest
*dr
= NULL
;
1812 struct keyspan_serial_private
*s_priv
;
1813 struct keyspan_port_private
*p_priv
;
1814 const struct keyspan_device_details
*d_details
;
1815 struct urb
*this_urb
;
1816 int err
, device_port
;
1818 s_priv
= usb_get_serial_data(serial
);
1819 p_priv
= usb_get_serial_port_data(port
);
1820 d_details
= s_priv
->device_details
;
1822 this_urb
= s_priv
->glocont_urb
;
1824 /* Work out which port within the device is being setup */
1825 device_port
= port
->port_number
;
1827 /* Make sure we have an urb then send the message */
1828 if (this_urb
== NULL
) {
1829 dev_dbg(&port
->dev
, "%s - oops no urb for port.\n", __func__
);
1833 dev_dbg(&port
->dev
, "%s - endpoint %d (%d)\n",
1834 __func__
, usb_pipeendpoint(this_urb
->pipe
), device_port
);
1836 /* Save reset port val for resend.
1837 Don't overwrite resend for open/close condition. */
1838 if ((reset_port
+ 1) > p_priv
->resend_cont
)
1839 p_priv
->resend_cont
= reset_port
+ 1;
1841 if (this_urb
->status
== -EINPROGRESS
) {
1842 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1847 memset(&msg
, 0, sizeof(struct keyspan_usa49_portControlMessage
));
1849 msg
.portNumber
= device_port
;
1851 /* Only set baud rate if it's changed */
1852 if (p_priv
->old_baud
!= p_priv
->baud
) {
1853 p_priv
->old_baud
= p_priv
->baud
;
1854 msg
.setClocking
= 0xff;
1855 if (d_details
->calculate_baud_rate(port
, p_priv
->baud
, d_details
->baudclk
,
1856 &msg
.baudHi
, &msg
.baudLo
, &msg
.prescaler
,
1857 device_port
) == KEYSPAN_INVALID_BAUD_RATE
) {
1858 dev_dbg(&port
->dev
, "%s - Invalid baud rate %d requested, using 9600.\n",
1859 __func__
, p_priv
->baud
);
1861 msg
.baudHi
= 125; /* Values for 9600 baud */
1864 /* msg.setPrescaler = 0xff; */
1867 msg
.lcr
= (p_priv
->cflag
& CSTOPB
) ? STOPBITS_678_2
: STOPBITS_5678_1
;
1868 switch (p_priv
->cflag
& CSIZE
) {
1870 msg
.lcr
|= USA_DATABITS_5
;
1873 msg
.lcr
|= USA_DATABITS_6
;
1876 msg
.lcr
|= USA_DATABITS_7
;
1879 msg
.lcr
|= USA_DATABITS_8
;
1882 if (p_priv
->cflag
& PARENB
) {
1883 /* note USA_PARITY_NONE == 0 */
1884 msg
.lcr
|= (p_priv
->cflag
& PARODD
) ?
1885 USA_PARITY_ODD
: USA_PARITY_EVEN
;
1889 msg
.ctsFlowControl
= (p_priv
->flow_control
== flow_cts
);
1890 msg
.xonFlowControl
= 0;
1891 msg
.setFlowControl
= 0xff;
1893 msg
.forwardingLength
= 16;
1898 if (reset_port
== 1) {
1907 msg
.returnStatus
= 0;
1908 msg
.resetDataToggle
= 0xff;
1910 msg
.disablePort
= 0;
1913 else if (reset_port
== 2) {
1922 msg
.returnStatus
= 0;
1923 msg
.resetDataToggle
= 0;
1925 msg
.disablePort
= 1;
1927 /* Sending intermediate configs */
1929 msg
._txOn
= (!p_priv
->break_on
);
1932 msg
.txBreak
= (p_priv
->break_on
);
1937 msg
.returnStatus
= 0;
1938 msg
.resetDataToggle
= 0x0;
1940 msg
.disablePort
= 0;
1943 /* Do handshaking outputs */
1945 msg
.rts
= p_priv
->rts_state
;
1948 msg
.dtr
= p_priv
->dtr_state
;
1950 p_priv
->resend_cont
= 0;
1952 /* if the device is a 49wg, we send control message on usb
1955 if (d_details
->product_id
== keyspan_usa49wg_product_id
) {
1956 dr
= (void *)(s_priv
->ctrl_buf
);
1957 dr
->bRequestType
= USB_TYPE_VENDOR
| USB_DIR_OUT
;
1958 dr
->bRequest
= 0xB0; /* 49wg control message */;
1961 dr
->wLength
= cpu_to_le16(sizeof(msg
));
1963 memcpy(s_priv
->glocont_buf
, &msg
, sizeof(msg
));
1965 usb_fill_control_urb(this_urb
, serial
->dev
,
1966 usb_sndctrlpipe(serial
->dev
, 0),
1967 (unsigned char *)dr
, s_priv
->glocont_buf
,
1968 sizeof(msg
), usa49_glocont_callback
, serial
);
1971 memcpy(this_urb
->transfer_buffer
, &msg
, sizeof(msg
));
1973 /* send the data out the device on control endpoint */
1974 this_urb
->transfer_buffer_length
= sizeof(msg
);
1976 err
= usb_submit_urb(this_urb
, GFP_ATOMIC
);
1978 dev_dbg(&port
->dev
, "%s - usb_submit_urb(setup) failed (%d)\n", __func__
, err
);
1981 dev_dbg(&port
->dev
, "%s - usb_submit_urb(%d) OK %d bytes (end %d)\n", __func__
,
1982 outcont_urb
, this_urb
->transfer_buffer_length
,
1983 usb_pipeendpoint(this_urb
->pipe
));
1990 static int keyspan_usa90_send_setup(struct usb_serial
*serial
,
1991 struct usb_serial_port
*port
,
1994 struct keyspan_usa90_portControlMessage msg
;
1995 struct keyspan_serial_private
*s_priv
;
1996 struct keyspan_port_private
*p_priv
;
1997 const struct keyspan_device_details
*d_details
;
1998 struct urb
*this_urb
;
2002 s_priv
= usb_get_serial_data(serial
);
2003 p_priv
= usb_get_serial_port_data(port
);
2004 d_details
= s_priv
->device_details
;
2006 /* only do something if we have a bulk out endpoint */
2007 this_urb
= p_priv
->outcont_urb
;
2008 if (this_urb
== NULL
) {
2009 dev_dbg(&port
->dev
, "%s - oops no urb.\n", __func__
);
2013 /* Save reset port val for resend.
2014 Don't overwrite resend for open/close condition. */
2015 if ((reset_port
+ 1) > p_priv
->resend_cont
)
2016 p_priv
->resend_cont
= reset_port
+ 1;
2017 if (this_urb
->status
== -EINPROGRESS
) {
2018 dev_dbg(&port
->dev
, "%s already writing\n", __func__
);
2023 memset(&msg
, 0, sizeof(struct keyspan_usa90_portControlMessage
));
2025 /* Only set baud rate if it's changed */
2026 if (p_priv
->old_baud
!= p_priv
->baud
) {
2027 p_priv
->old_baud
= p_priv
->baud
;
2028 msg
.setClocking
= 0x01;
2029 if (d_details
->calculate_baud_rate(port
, p_priv
->baud
, d_details
->baudclk
,
2030 &msg
.baudHi
, &msg
.baudLo
, &prescaler
, 0) == KEYSPAN_INVALID_BAUD_RATE
) {
2031 dev_dbg(&port
->dev
, "%s - Invalid baud rate %d requested, using 9600.\n",
2032 __func__
, p_priv
->baud
);
2033 p_priv
->baud
= 9600;
2034 d_details
->calculate_baud_rate(port
, p_priv
->baud
, d_details
->baudclk
,
2035 &msg
.baudHi
, &msg
.baudLo
, &prescaler
, 0);
2041 /* modes must always be correctly specified */
2042 if (p_priv
->baud
> 57600) {
2043 msg
.rxMode
= RXMODE_DMA
;
2044 msg
.txMode
= TXMODE_DMA
;
2046 msg
.rxMode
= RXMODE_BYHAND
;
2047 msg
.txMode
= TXMODE_BYHAND
;
2050 msg
.lcr
= (p_priv
->cflag
& CSTOPB
) ? STOPBITS_678_2
: STOPBITS_5678_1
;
2051 switch (p_priv
->cflag
& CSIZE
) {
2053 msg
.lcr
|= USA_DATABITS_5
;
2056 msg
.lcr
|= USA_DATABITS_6
;
2059 msg
.lcr
|= USA_DATABITS_7
;
2062 msg
.lcr
|= USA_DATABITS_8
;
2065 if (p_priv
->cflag
& PARENB
) {
2066 /* note USA_PARITY_NONE == 0 */
2067 msg
.lcr
|= (p_priv
->cflag
& PARODD
) ?
2068 USA_PARITY_ODD
: USA_PARITY_EVEN
;
2070 if (p_priv
->old_cflag
!= p_priv
->cflag
) {
2071 p_priv
->old_cflag
= p_priv
->cflag
;
2075 if (p_priv
->flow_control
== flow_cts
)
2076 msg
.txFlowControl
= TXFLOW_CTS
;
2077 msg
.setTxFlowControl
= 0x01;
2078 msg
.setRxFlowControl
= 0x01;
2080 msg
.rxForwardingLength
= 16;
2081 msg
.rxForwardingTimeout
= 16;
2082 msg
.txAckSetting
= 0;
2087 if (reset_port
== 1) {
2088 msg
.portEnabled
= 1;
2090 msg
.txBreak
= (p_priv
->break_on
);
2093 else if (reset_port
== 2)
2094 msg
.portEnabled
= 0;
2095 /* Sending intermediate configs */
2097 msg
.portEnabled
= 1;
2098 msg
.txBreak
= (p_priv
->break_on
);
2101 /* Do handshaking outputs */
2103 msg
.rts
= p_priv
->rts_state
;
2106 msg
.dtr
= p_priv
->dtr_state
;
2108 p_priv
->resend_cont
= 0;
2109 memcpy(this_urb
->transfer_buffer
, &msg
, sizeof(msg
));
2111 /* send the data out the device on control endpoint */
2112 this_urb
->transfer_buffer_length
= sizeof(msg
);
2114 err
= usb_submit_urb(this_urb
, GFP_ATOMIC
);
2116 dev_dbg(&port
->dev
, "%s - usb_submit_urb(setup) failed (%d)\n", __func__
, err
);
2120 static int keyspan_usa67_send_setup(struct usb_serial
*serial
,
2121 struct usb_serial_port
*port
,
2124 struct keyspan_usa67_portControlMessage msg
;
2125 struct keyspan_serial_private
*s_priv
;
2126 struct keyspan_port_private
*p_priv
;
2127 const struct keyspan_device_details
*d_details
;
2128 struct urb
*this_urb
;
2129 int err
, device_port
;
2131 s_priv
= usb_get_serial_data(serial
);
2132 p_priv
= usb_get_serial_port_data(port
);
2133 d_details
= s_priv
->device_details
;
2135 this_urb
= s_priv
->glocont_urb
;
2137 /* Work out which port within the device is being setup */
2138 device_port
= port
->port_number
;
2140 /* Make sure we have an urb then send the message */
2141 if (this_urb
== NULL
) {
2142 dev_dbg(&port
->dev
, "%s - oops no urb for port.\n", __func__
);
2146 /* Save reset port val for resend.
2147 Don't overwrite resend for open/close condition. */
2148 if ((reset_port
+ 1) > p_priv
->resend_cont
)
2149 p_priv
->resend_cont
= reset_port
+ 1;
2150 if (this_urb
->status
== -EINPROGRESS
) {
2151 /* dev_dbg(&port->dev, "%s - already writing\n", __func__); */
2156 memset(&msg
, 0, sizeof(struct keyspan_usa67_portControlMessage
));
2158 msg
.port
= device_port
;
2160 /* Only set baud rate if it's changed */
2161 if (p_priv
->old_baud
!= p_priv
->baud
) {
2162 p_priv
->old_baud
= p_priv
->baud
;
2163 msg
.setClocking
= 0xff;
2164 if (d_details
->calculate_baud_rate(port
, p_priv
->baud
, d_details
->baudclk
,
2165 &msg
.baudHi
, &msg
.baudLo
, &msg
.prescaler
,
2166 device_port
) == KEYSPAN_INVALID_BAUD_RATE
) {
2167 dev_dbg(&port
->dev
, "%s - Invalid baud rate %d requested, using 9600.\n",
2168 __func__
, p_priv
->baud
);
2170 msg
.baudHi
= 125; /* Values for 9600 baud */
2173 msg
.setPrescaler
= 0xff;
2176 msg
.lcr
= (p_priv
->cflag
& CSTOPB
) ? STOPBITS_678_2
: STOPBITS_5678_1
;
2177 switch (p_priv
->cflag
& CSIZE
) {
2179 msg
.lcr
|= USA_DATABITS_5
;
2182 msg
.lcr
|= USA_DATABITS_6
;
2185 msg
.lcr
|= USA_DATABITS_7
;
2188 msg
.lcr
|= USA_DATABITS_8
;
2191 if (p_priv
->cflag
& PARENB
) {
2192 /* note USA_PARITY_NONE == 0 */
2193 msg
.lcr
|= (p_priv
->cflag
& PARODD
) ?
2194 USA_PARITY_ODD
: USA_PARITY_EVEN
;
2198 msg
.ctsFlowControl
= (p_priv
->flow_control
== flow_cts
);
2199 msg
.xonFlowControl
= 0;
2200 msg
.setFlowControl
= 0xff;
2201 msg
.forwardingLength
= 16;
2205 if (reset_port
== 1) {
2215 msg
.returnStatus
= 0;
2216 msg
.resetDataToggle
= 0xff;
2217 } else if (reset_port
== 2) {
2227 msg
.returnStatus
= 0;
2228 msg
.resetDataToggle
= 0;
2230 /* Sending intermediate configs */
2231 msg
._txOn
= (!p_priv
->break_on
);
2234 msg
.txBreak
= (p_priv
->break_on
);
2239 msg
.returnStatus
= 0;
2240 msg
.resetDataToggle
= 0x0;
2243 /* Do handshaking outputs */
2244 msg
.setTxTriState_setRts
= 0xff;
2245 msg
.txTriState_rts
= p_priv
->rts_state
;
2247 msg
.setHskoa_setDtr
= 0xff;
2248 msg
.hskoa_dtr
= p_priv
->dtr_state
;
2250 p_priv
->resend_cont
= 0;
2252 memcpy(this_urb
->transfer_buffer
, &msg
, sizeof(msg
));
2254 /* send the data out the device on control endpoint */
2255 this_urb
->transfer_buffer_length
= sizeof(msg
);
2257 err
= usb_submit_urb(this_urb
, GFP_ATOMIC
);
2259 dev_dbg(&port
->dev
, "%s - usb_submit_urb(setup) failed (%d)\n", __func__
, err
);
2263 static void keyspan_send_setup(struct usb_serial_port
*port
, int reset_port
)
2265 struct usb_serial
*serial
= port
->serial
;
2266 struct keyspan_serial_private
*s_priv
;
2267 const struct keyspan_device_details
*d_details
;
2269 s_priv
= usb_get_serial_data(serial
);
2270 d_details
= s_priv
->device_details
;
2272 switch (d_details
->msg_format
) {
2274 keyspan_usa26_send_setup(serial
, port
, reset_port
);
2277 keyspan_usa28_send_setup(serial
, port
, reset_port
);
2280 keyspan_usa49_send_setup(serial
, port
, reset_port
);
2283 keyspan_usa90_send_setup(serial
, port
, reset_port
);
2286 keyspan_usa67_send_setup(serial
, port
, reset_port
);
2292 /* Gets called by the "real" driver (ie once firmware is loaded
2293 and renumeration has taken place. */
2294 static int keyspan_startup(struct usb_serial
*serial
)
2297 struct keyspan_serial_private
*s_priv
;
2298 const struct keyspan_device_details
*d_details
;
2300 for (i
= 0; (d_details
= keyspan_devices
[i
]) != NULL
; ++i
)
2301 if (d_details
->product_id
==
2302 le16_to_cpu(serial
->dev
->descriptor
.idProduct
))
2304 if (d_details
== NULL
) {
2305 dev_err(&serial
->dev
->dev
, "%s - unknown product id %x\n",
2306 __func__
, le16_to_cpu(serial
->dev
->descriptor
.idProduct
));
2310 /* Setup private data for serial driver */
2311 s_priv
= kzalloc(sizeof(struct keyspan_serial_private
), GFP_KERNEL
);
2315 s_priv
->instat_buf
= kzalloc(INSTAT_BUFLEN
, GFP_KERNEL
);
2316 if (!s_priv
->instat_buf
)
2317 goto err_instat_buf
;
2319 s_priv
->indat_buf
= kzalloc(INDAT49W_BUFLEN
, GFP_KERNEL
);
2320 if (!s_priv
->indat_buf
)
2323 s_priv
->glocont_buf
= kzalloc(GLOCONT_BUFLEN
, GFP_KERNEL
);
2324 if (!s_priv
->glocont_buf
)
2325 goto err_glocont_buf
;
2327 s_priv
->ctrl_buf
= kzalloc(sizeof(struct usb_ctrlrequest
), GFP_KERNEL
);
2328 if (!s_priv
->ctrl_buf
)
2331 s_priv
->device_details
= d_details
;
2332 usb_set_serial_data(serial
, s_priv
);
2334 keyspan_setup_urbs(serial
);
2336 if (s_priv
->instat_urb
!= NULL
) {
2337 err
= usb_submit_urb(s_priv
->instat_urb
, GFP_KERNEL
);
2339 dev_dbg(&serial
->dev
->dev
, "%s - submit instat urb failed %d\n", __func__
, err
);
2341 if (s_priv
->indat_urb
!= NULL
) {
2342 err
= usb_submit_urb(s_priv
->indat_urb
, GFP_KERNEL
);
2344 dev_dbg(&serial
->dev
->dev
, "%s - submit indat urb failed %d\n", __func__
, err
);
2350 kfree(s_priv
->glocont_buf
);
2352 kfree(s_priv
->indat_buf
);
2354 kfree(s_priv
->instat_buf
);
2361 static void keyspan_disconnect(struct usb_serial
*serial
)
2363 struct keyspan_serial_private
*s_priv
;
2365 s_priv
= usb_get_serial_data(serial
);
2367 stop_urb(s_priv
->instat_urb
);
2368 stop_urb(s_priv
->glocont_urb
);
2369 stop_urb(s_priv
->indat_urb
);
2372 static void keyspan_release(struct usb_serial
*serial
)
2374 struct keyspan_serial_private
*s_priv
;
2376 s_priv
= usb_get_serial_data(serial
);
2378 usb_free_urb(s_priv
->instat_urb
);
2379 usb_free_urb(s_priv
->indat_urb
);
2380 usb_free_urb(s_priv
->glocont_urb
);
2382 kfree(s_priv
->ctrl_buf
);
2383 kfree(s_priv
->glocont_buf
);
2384 kfree(s_priv
->indat_buf
);
2385 kfree(s_priv
->instat_buf
);
2390 static int keyspan_port_probe(struct usb_serial_port
*port
)
2392 struct usb_serial
*serial
= port
->serial
;
2393 struct keyspan_serial_private
*s_priv
;
2394 struct keyspan_port_private
*p_priv
;
2395 const struct keyspan_device_details
*d_details
;
2396 struct callbacks
*cback
;
2401 s_priv
= usb_get_serial_data(serial
);
2402 d_details
= s_priv
->device_details
;
2404 p_priv
= kzalloc(sizeof(*p_priv
), GFP_KERNEL
);
2408 for (i
= 0; i
< ARRAY_SIZE(p_priv
->in_buffer
); ++i
) {
2409 p_priv
->in_buffer
[i
] = kzalloc(IN_BUFLEN
, GFP_KERNEL
);
2410 if (!p_priv
->in_buffer
[i
])
2414 for (i
= 0; i
< ARRAY_SIZE(p_priv
->out_buffer
); ++i
) {
2415 p_priv
->out_buffer
[i
] = kzalloc(OUT_BUFLEN
, GFP_KERNEL
);
2416 if (!p_priv
->out_buffer
[i
])
2417 goto err_out_buffer
;
2420 p_priv
->inack_buffer
= kzalloc(INACK_BUFLEN
, GFP_KERNEL
);
2421 if (!p_priv
->inack_buffer
)
2422 goto err_inack_buffer
;
2424 p_priv
->outcont_buffer
= kzalloc(OUTCONT_BUFLEN
, GFP_KERNEL
);
2425 if (!p_priv
->outcont_buffer
)
2426 goto err_outcont_buffer
;
2428 p_priv
->device_details
= d_details
;
2430 /* Setup values for the various callback routines */
2431 cback
= &keyspan_callbacks
[d_details
->msg_format
];
2433 port_num
= port
->port_number
;
2435 /* Do indat endpoints first, once for each flip */
2436 endp
= d_details
->indat_endpoints
[port_num
];
2437 for (i
= 0; i
<= d_details
->indat_endp_flip
; ++i
, ++endp
) {
2438 p_priv
->in_urbs
[i
] = keyspan_setup_urb(serial
, endp
,
2440 p_priv
->in_buffer
[i
],
2442 cback
->indat_callback
);
2444 /* outdat endpoints also have flip */
2445 endp
= d_details
->outdat_endpoints
[port_num
];
2446 for (i
= 0; i
<= d_details
->outdat_endp_flip
; ++i
, ++endp
) {
2447 p_priv
->out_urbs
[i
] = keyspan_setup_urb(serial
, endp
,
2449 p_priv
->out_buffer
[i
],
2451 cback
->outdat_callback
);
2453 /* inack endpoint */
2454 p_priv
->inack_urb
= keyspan_setup_urb(serial
,
2455 d_details
->inack_endpoints
[port_num
],
2457 p_priv
->inack_buffer
,
2459 cback
->inack_callback
);
2460 /* outcont endpoint */
2461 p_priv
->outcont_urb
= keyspan_setup_urb(serial
,
2462 d_details
->outcont_endpoints
[port_num
],
2464 p_priv
->outcont_buffer
,
2466 cback
->outcont_callback
);
2468 usb_set_serial_port_data(port
, p_priv
);
2473 kfree(p_priv
->inack_buffer
);
2475 for (i
= 0; i
< ARRAY_SIZE(p_priv
->out_buffer
); ++i
)
2476 kfree(p_priv
->out_buffer
[i
]);
2478 for (i
= 0; i
< ARRAY_SIZE(p_priv
->in_buffer
); ++i
)
2479 kfree(p_priv
->in_buffer
[i
]);
2486 static int keyspan_port_remove(struct usb_serial_port
*port
)
2488 struct keyspan_port_private
*p_priv
;
2491 p_priv
= usb_get_serial_port_data(port
);
2493 stop_urb(p_priv
->inack_urb
);
2494 stop_urb(p_priv
->outcont_urb
);
2495 for (i
= 0; i
< 2; i
++) {
2496 stop_urb(p_priv
->in_urbs
[i
]);
2497 stop_urb(p_priv
->out_urbs
[i
]);
2500 usb_free_urb(p_priv
->inack_urb
);
2501 usb_free_urb(p_priv
->outcont_urb
);
2502 for (i
= 0; i
< 2; i
++) {
2503 usb_free_urb(p_priv
->in_urbs
[i
]);
2504 usb_free_urb(p_priv
->out_urbs
[i
]);
2507 kfree(p_priv
->outcont_buffer
);
2508 kfree(p_priv
->inack_buffer
);
2509 for (i
= 0; i
< ARRAY_SIZE(p_priv
->out_buffer
); ++i
)
2510 kfree(p_priv
->out_buffer
[i
]);
2511 for (i
= 0; i
< ARRAY_SIZE(p_priv
->in_buffer
); ++i
)
2512 kfree(p_priv
->in_buffer
[i
]);
2519 MODULE_AUTHOR(DRIVER_AUTHOR
);
2520 MODULE_DESCRIPTION(DRIVER_DESC
);
2521 MODULE_LICENSE("GPL");
2523 MODULE_FIRMWARE("keyspan/usa28.fw");
2524 MODULE_FIRMWARE("keyspan/usa28x.fw");
2525 MODULE_FIRMWARE("keyspan/usa28xa.fw");
2526 MODULE_FIRMWARE("keyspan/usa28xb.fw");
2527 MODULE_FIRMWARE("keyspan/usa19.fw");
2528 MODULE_FIRMWARE("keyspan/usa19qi.fw");
2529 MODULE_FIRMWARE("keyspan/mpr.fw");
2530 MODULE_FIRMWARE("keyspan/usa19qw.fw");
2531 MODULE_FIRMWARE("keyspan/usa18x.fw");
2532 MODULE_FIRMWARE("keyspan/usa19w.fw");
2533 MODULE_FIRMWARE("keyspan/usa49w.fw");
2534 MODULE_FIRMWARE("keyspan/usa49wlc.fw");