14a219ba4ee62578a3b264d738b845739d0fa124
[firefly-linux-kernel-4.4.55.git] / drivers / usb / serial / keyspan.c
1 /*
2   Keyspan USB to Serial Converter driver
3
4   (C) Copyright (C) 2000-2001   Hugh Blemings <hugh@blemings.org>
5   (C) Copyright (C) 2002        Greg Kroah-Hartman <greg@kroah.com>
6
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.
11
12   See http://blemings.org/hugh/keyspan.html for more information.
13
14   Code in this driver inspired by and in a number of places taken
15   from Brian Warner's original Keyspan-PDA driver.
16
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.
19   Thanks Guys :)
20
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
24   stuff.
25
26   Tip 'o the hat to IBM (and previously Linuxcare :) for supporting
27   staff in their work on open source projects.
28 */
29
30
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>
45 #include "keyspan.h"
46
47 #define DRIVER_AUTHOR "Hugh Blemings <hugh@misc.nu"
48 #define DRIVER_DESC "Keyspan USB to Serial Converter Driver"
49
50 #define INSTAT_BUFLEN   32
51 #define GLOCONT_BUFLEN  64
52 #define INDAT49W_BUFLEN 512
53
54         /* Per device and per port private data */
55 struct keyspan_serial_private {
56         const struct keyspan_device_details     *device_details;
57
58         struct urb      *instat_urb;
59         char            instat_buf[INSTAT_BUFLEN];
60
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];
65
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 */
70 };
71
72 struct keyspan_port_private {
73         /* Keep track of which input & output endpoints to use */
74         int             in_flip;
75         int             out_flip;
76
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;
81
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];
88
89         /* Input ack endpoint */
90         struct urb      *inack_urb;
91         char            inack_buffer[1];
92
93         /* Output control endpoint */
94         struct urb      *outcont_urb;
95         char            outcont_buffer[64];
96
97         /* Settings for the port */
98         int             baud;
99         int             old_baud;
100         unsigned int    cflag;
101         unsigned int    old_cflag;
102         enum            {flow_none, flow_cts, flow_xon} flow_control;
103         int             rts_state;      /* Handshaking pins (outputs) */
104         int             dtr_state;
105         int             cts_state;      /* Handshaking pins (inputs) */
106         int             dsr_state;
107         int             dcd_state;
108         int             ri_state;
109         int             break_on;
110
111         unsigned long   tx_start_time[2];
112         int             resend_cont;    /* need to resend control packet */
113 };
114
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"
124
125
126 module_usb_serial_driver(serial_drivers, keyspan_ids_combined);
127
128 static void keyspan_break_ctl(struct tty_struct *tty, int break_state)
129 {
130         struct usb_serial_port *port = tty->driver_data;
131         struct keyspan_port_private     *p_priv;
132
133         p_priv = usb_get_serial_port_data(port);
134
135         if (break_state == -1)
136                 p_priv->break_on = 1;
137         else
138                 p_priv->break_on = 0;
139
140         keyspan_send_setup(port, 0);
141 }
142
143
144 static void keyspan_set_termios(struct tty_struct *tty,
145                 struct usb_serial_port *port, struct ktermios *old_termios)
146 {
147         int                             baud_rate, device_port;
148         struct keyspan_port_private     *p_priv;
149         const struct keyspan_device_details     *d_details;
150         unsigned int                    cflag;
151
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;
156
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;
166         } else
167                 baud_rate = tty_termios_baud_rate(old_termios);
168
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;
173
174         /* Mark/Space not supported */
175         tty->termios.c_cflag &= ~CMSPAR;
176
177         keyspan_send_setup(port, 0);
178 }
179
180 static int keyspan_tiocmget(struct tty_struct *tty)
181 {
182         struct usb_serial_port *port = tty->driver_data;
183         struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
184         unsigned int                    value;
185
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);
192
193         return value;
194 }
195
196 static int keyspan_tiocmset(struct tty_struct *tty,
197                             unsigned int set, unsigned int clear)
198 {
199         struct usb_serial_port *port = tty->driver_data;
200         struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
201
202         if (set & TIOCM_RTS)
203                 p_priv->rts_state = 1;
204         if (set & TIOCM_DTR)
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);
211         return 0;
212 }
213
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)
218 {
219         struct keyspan_port_private     *p_priv;
220         const struct keyspan_device_details     *d_details;
221         int                             flip;
222         int                             left, todo;
223         struct urb                      *this_urb;
224         int                             err, maxDataLen, dataOffset;
225
226         p_priv = usb_get_serial_port_data(port);
227         d_details = p_priv->device_details;
228
229         if (d_details->msg_format == msg_usa90) {
230                 maxDataLen = 64;
231                 dataOffset = 0;
232         } else {
233                 maxDataLen = 63;
234                 dataOffset = 1;
235         }
236
237         dev_dbg(&port->dev, "%s - for port %d (%d chars), flip=%d\n",
238                 __func__, port->number, count, p_priv->out_flip);
239
240         for (left = count; left > 0; left -= todo) {
241                 todo = left;
242                 if (todo > maxDataLen)
243                         todo = maxDataLen;
244
245                 flip = p_priv->out_flip;
246
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__);
252                         return count;
253                 }
254
255                 dev_dbg(&port->dev, "%s - endpoint %d flip %d\n",
256                         __func__, usb_pipeendpoint(this_urb->pipe), flip);
257
258                 if (this_urb->status == -EINPROGRESS) {
259                         if (time_before(jiffies,
260                                         p_priv->tx_start_time[flip] + 10 * HZ))
261                                 break;
262                         usb_unlink_urb(this_urb);
263                         break;
264                 }
265
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;
269
270                 memcpy(this_urb->transfer_buffer + dataOffset, buf, todo);
271                 buf += todo;
272
273                 /* send the data out the bulk port */
274                 this_urb->transfer_buffer_length = todo + dataOffset;
275
276                 err = usb_submit_urb(this_urb, GFP_ATOMIC);
277                 if (err != 0)
278                         dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed (%d)\n", err);
279                 p_priv->tx_start_time[flip] = jiffies;
280
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;
284         }
285
286         return count - left;
287 }
288
289 static void     usa26_indat_callback(struct urb *urb)
290 {
291         int                     i, err;
292         int                     endpoint;
293         struct usb_serial_port  *port;
294         struct tty_struct       *tty;
295         unsigned char           *data = urb->transfer_buffer;
296         int status = urb->status;
297
298         endpoint = usb_pipeendpoint(urb->pipe);
299
300         if (status) {
301                 dev_dbg(&urb->dev->dev,"%s - nonzero status: %x on endpoint %d.\n",
302                         __func__, status, endpoint);
303                 return;
304         }
305
306         port =  urb->context;
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)
314                                 err = TTY_OVERRUN;
315                         else
316                                 err = 0;
317                         for (i = 1; i < urb->actual_length ; ++i)
318                                 tty_insert_flip_char(&port->port, data[i], err);
319                 } else {
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)
325                                         flag |= TTY_OVERRUN;
326                                 if (stat & RXERROR_FRAMING)
327                                         flag |= TTY_FRAME;
328                                 if (stat & RXERROR_PARITY)
329                                         flag |= TTY_PARITY;
330                                 /* XXX should handle break (0x10) */
331                                 tty_insert_flip_char(&port->port, data[i+1],
332                                                 flag);
333                         }
334                 }
335                 tty_flip_buffer_push(tty);
336         }
337         tty_kref_put(tty);
338
339         /* Resubmit urb so we continue receiving */
340         err = usb_submit_urb(urb, GFP_ATOMIC);
341         if (err != 0)
342                 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
343 }
344
345 /* Outdat handling is common for all devices */
346 static void     usa2x_outdat_callback(struct urb *urb)
347 {
348         struct usb_serial_port *port;
349         struct keyspan_port_private *p_priv;
350
351         port =  urb->context;
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]);
354
355         usb_serial_port_softint(port);
356 }
357
358 static void     usa26_inack_callback(struct urb *urb)
359 {
360 }
361
362 static void     usa26_outcont_callback(struct urb *urb)
363 {
364         struct usb_serial_port *port;
365         struct keyspan_port_private *p_priv;
366
367         port =  urb->context;
368         p_priv = usb_get_serial_port_data(port);
369
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);
374         }
375 }
376
377 static void     usa26_instat_callback(struct urb *urb)
378 {
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;
387
388         serial =  urb->context;
389
390         if (status) {
391                 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
392                 return;
393         }
394         if (urb->actual_length != 9) {
395                 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
396                 goto exit;
397         }
398
399         msg = (struct keyspan_usa26_portStatusMessage *)data;
400
401 #if 0
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);
407 #endif
408
409         /* Now do something useful with the data */
410
411
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);
415                 goto exit;
416         }
417         port = serial->port[msg->port];
418         p_priv = usb_get_serial_port_data(port);
419
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);
426
427         if (old_dcd_state != p_priv->dcd_state) {
428                 tty = tty_port_tty_get(&port->port);
429                 if (tty && !C_CLOCAL(tty))
430                         tty_hangup(tty);
431                 tty_kref_put(tty);
432         }
433
434         /* Resubmit urb so we continue receiving */
435         err = usb_submit_urb(urb, GFP_ATOMIC);
436         if (err != 0)
437                 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
438 exit: ;
439 }
440
441 static void     usa26_glocont_callback(struct urb *urb)
442 {
443 }
444
445
446 static void usa28_indat_callback(struct urb *urb)
447 {
448         int                     err;
449         struct usb_serial_port  *port;
450         struct tty_struct       *tty;
451         unsigned char           *data;
452         struct keyspan_port_private             *p_priv;
453         int status = urb->status;
454
455         port =  urb->context;
456         p_priv = usb_get_serial_port_data(port);
457         data = urb->transfer_buffer;
458
459         if (urb != p_priv->in_urbs[p_priv->in_flip])
460                 return;
461
462         do {
463                 if (status) {
464                         dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
465                                 __func__, status, usb_pipeendpoint(urb->pipe));
466                         return;
467                 }
468
469                 port =  urb->context;
470                 p_priv = usb_get_serial_port_data(port);
471                 data = urb->transfer_buffer;
472
473                 tty = tty_port_tty_get(&port->port);
474                 if (tty && urb->actual_length) {
475                         tty_insert_flip_string(&port->port, data,
476                                         urb->actual_length);
477                         tty_flip_buffer_push(tty);
478                 }
479                 tty_kref_put(tty);
480
481                 /* Resubmit urb so we continue receiving */
482                 err = usb_submit_urb(urb, GFP_ATOMIC);
483                 if (err != 0)
484                         dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n",
485                                                         __func__, err);
486                 p_priv->in_flip ^= 1;
487
488                 urb = p_priv->in_urbs[p_priv->in_flip];
489         } while (urb->status != -EINPROGRESS);
490 }
491
492 static void     usa28_inack_callback(struct urb *urb)
493 {
494 }
495
496 static void     usa28_outcont_callback(struct urb *urb)
497 {
498         struct usb_serial_port *port;
499         struct keyspan_port_private *p_priv;
500
501         port =  urb->context;
502         p_priv = usb_get_serial_port_data(port);
503
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);
508         }
509 }
510
511 static void     usa28_instat_callback(struct urb *urb)
512 {
513         int                                     err;
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;
520         int old_dcd_state;
521         int status = urb->status;
522
523         serial =  urb->context;
524
525         if (status) {
526                 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
527                 return;
528         }
529
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);
532                 goto exit;
533         }
534
535         /*
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]);
540         */
541
542         /* Now do something useful with the data */
543         msg = (struct keyspan_usa28_portStatusMessage *)data;
544
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);
548                 goto exit;
549         }
550         port = serial->port[msg->port];
551         p_priv = usb_get_serial_port_data(port);
552
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);
559
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))
563                         tty_hangup(tty);
564                 tty_kref_put(tty);
565         }
566
567                 /* Resubmit urb so we continue receiving */
568         err = usb_submit_urb(urb, GFP_ATOMIC);
569         if (err != 0)
570                 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
571 exit: ;
572 }
573
574 static void     usa28_glocont_callback(struct urb *urb)
575 {
576 }
577
578
579 static void     usa49_glocont_callback(struct urb *urb)
580 {
581         struct usb_serial *serial;
582         struct usb_serial_port *port;
583         struct keyspan_port_private *p_priv;
584         int i;
585
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);
590
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);
595                         break;
596                 }
597         }
598 }
599
600         /* This is actually called glostat in the Keyspan
601            doco */
602 static void     usa49_instat_callback(struct urb *urb)
603 {
604         int                                     err;
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;
610         int old_dcd_state;
611         int status = urb->status;
612
613         serial =  urb->context;
614
615         if (status) {
616                 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
617                 return;
618         }
619
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);
623                 goto exit;
624         }
625
626         /*
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]);
630         */
631
632         /* Now do something useful with the data */
633         msg = (struct keyspan_usa49_portStatusMessage *)data;
634
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);
639                 goto exit;
640         }
641         port = serial->port[msg->portNumber];
642         p_priv = usb_get_serial_port_data(port);
643
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);
650
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))
654                         tty_hangup(tty);
655                 tty_kref_put(tty);
656         }
657
658         /* Resubmit urb so we continue receiving */
659         err = usb_submit_urb(urb, GFP_ATOMIC);
660         if (err != 0)
661                 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
662 exit:   ;
663 }
664
665 static void     usa49_inack_callback(struct urb *urb)
666 {
667 }
668
669 static void     usa49_indat_callback(struct urb *urb)
670 {
671         int                     i, err;
672         int                     endpoint;
673         struct usb_serial_port  *port;
674         struct tty_struct       *tty;
675         unsigned char           *data = urb->transfer_buffer;
676         int status = urb->status;
677
678         endpoint = usb_pipeendpoint(urb->pipe);
679
680         if (status) {
681                 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
682                         __func__, status, endpoint);
683                 return;
684         }
685
686         port =  urb->context;
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);
694                 } else {
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)
699                                         flag |= TTY_OVERRUN;
700                                 if (stat & RXERROR_FRAMING)
701                                         flag |= TTY_FRAME;
702                                 if (stat & RXERROR_PARITY)
703                                         flag |= TTY_PARITY;
704                                 /* XXX should handle break (0x10) */
705                                 tty_insert_flip_char(&port->port, data[i+1],
706                                                 flag);
707                         }
708                 }
709                 tty_flip_buffer_push(tty);
710         }
711         tty_kref_put(tty);
712
713         /* Resubmit urb so we continue receiving */
714         err = usb_submit_urb(urb, GFP_ATOMIC);
715         if (err != 0)
716                 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
717 }
718
719 static void usa49wg_indat_callback(struct urb *urb)
720 {
721         int                     i, len, x, err;
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;
727
728         serial = urb->context;
729
730         if (status) {
731                 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
732                 return;
733         }
734
735         /* inbound data is in the form P#, len, status, data */
736         i = 0;
737         len = 0;
738
739         if (urb->actual_length) {
740                 while (i < urb->actual_length) {
741
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",
745                                         __func__, data[i]);
746                                 return;
747                         }
748                         port = serial->port[data[i++]];
749                         tty = tty_port_tty_get(&port->port);
750                         len = data[i++];
751
752                         /* 0x80 bit is error flag */
753                         if ((data[i] & 0x80) == 0) {
754                                 /* no error on any byte */
755                                 i++;
756                                 for (x = 1; x < len ; ++x)
757                                         tty_insert_flip_char(&port->port,
758                                                         data[i++], 0);
759                         } else {
760                                 /*
761                                  * some bytes had errors, every byte has status
762                                  */
763                                 for (x = 0; x + 1 < len; x += 2) {
764                                         int stat = data[i], flag = 0;
765                                         if (stat & RXERROR_OVERRUN)
766                                                 flag |= TTY_OVERRUN;
767                                         if (stat & RXERROR_FRAMING)
768                                                 flag |= TTY_FRAME;
769                                         if (stat & RXERROR_PARITY)
770                                                 flag |= TTY_PARITY;
771                                         /* XXX should handle break (0x10) */
772                                         tty_insert_flip_char(&port->port,
773                                                         data[i+1], flag);
774                                         i += 2;
775                                 }
776                         }
777                         tty_flip_buffer_push(tty);
778                         tty_kref_put(tty);
779                 }
780         }
781
782         /* Resubmit urb so we continue receiving */
783         err = usb_submit_urb(urb, GFP_ATOMIC);
784         if (err != 0)
785                 dev_dbg(&urb->dev->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
786 }
787
788 /* not used, usa-49 doesn't have per-port control endpoints */
789 static void usa49_outcont_callback(struct urb *urb)
790 {
791 }
792
793 static void usa90_indat_callback(struct urb *urb)
794 {
795         int                     i, err;
796         int                     endpoint;
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;
802
803         endpoint = usb_pipeendpoint(urb->pipe);
804
805         if (status) {
806                 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x on endpoint %d.\n",
807                     __func__, status, endpoint);
808                 return;
809         }
810
811         port =  urb->context;
812         p_priv = usb_get_serial_port_data(port);
813
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 */
818
819                 if (p_priv->baud > 57600)
820                         tty_insert_flip_string(&port->port, data,
821                                         urb->actual_length);
822                 else {
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)
828                                         err = TTY_OVERRUN;
829                                 else
830                                         err = 0;
831                                 for (i = 1; i < urb->actual_length ; ++i)
832                                         tty_insert_flip_char(&port->port,
833                                                         data[i], err);
834                         }  else {
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)
840                                                 flag |= TTY_OVERRUN;
841                                         if (stat & RXERROR_FRAMING)
842                                                 flag |= TTY_FRAME;
843                                         if (stat & RXERROR_PARITY)
844                                                 flag |= TTY_PARITY;
845                                         /* XXX should handle break (0x10) */
846                                         tty_insert_flip_char(&port->port,
847                                                         data[i+1], flag);
848                                 }
849                         }
850                 }
851                 tty_flip_buffer_push(tty);
852                 tty_kref_put(tty);
853         }
854
855         /* Resubmit urb so we continue receiving */
856         err = usb_submit_urb(urb, GFP_ATOMIC);
857         if (err != 0)
858                 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
859 }
860
861
862 static void     usa90_instat_callback(struct urb *urb)
863 {
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;
872
873         serial =  urb->context;
874
875         if (status) {
876                 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
877                 return;
878         }
879         if (urb->actual_length < 14) {
880                 dev_dbg(&urb->dev->dev, "%s - %d byte report??\n", __func__, urb->actual_length);
881                 goto exit;
882         }
883
884         msg = (struct keyspan_usa90_portStatusMessage *)data;
885
886         /* Now do something useful with the data */
887
888         port = serial->port[0];
889         p_priv = usb_get_serial_port_data(port);
890
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);
897
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))
901                         tty_hangup(tty);
902                 tty_kref_put(tty);
903         }
904
905         /* Resubmit urb so we continue receiving */
906         err = usb_submit_urb(urb, GFP_ATOMIC);
907         if (err != 0)
908                 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
909 exit:
910         ;
911 }
912
913 static void     usa90_outcont_callback(struct urb *urb)
914 {
915         struct usb_serial_port *port;
916         struct keyspan_port_private *p_priv;
917
918         port =  urb->context;
919         p_priv = usb_get_serial_port_data(port);
920
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);
925         }
926 }
927
928 /* Status messages from the 28xg */
929 static void     usa67_instat_callback(struct urb *urb)
930 {
931         int                                     err;
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;
937         int old_dcd_state;
938         int status = urb->status;
939
940         serial = urb->context;
941
942         if (status) {
943                 dev_dbg(&urb->dev->dev, "%s - nonzero status: %x\n", __func__, status);
944                 return;
945         }
946
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);
950                 return;
951         }
952
953
954         /* Now do something useful with the data */
955         msg = (struct keyspan_usa67_portStatusMessage *)data;
956
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);
960                 return;
961         }
962
963         port = serial->port[msg->port];
964         p_priv = usb_get_serial_port_data(port);
965
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);
970
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))
974                         tty_hangup(tty);
975                 tty_kref_put(tty);
976         }
977
978         /* Resubmit urb so we continue receiving */
979         err = usb_submit_urb(urb, GFP_ATOMIC);
980         if (err != 0)
981                 dev_dbg(&port->dev, "%s - resubmit read urb failed. (%d)\n", __func__, err);
982 }
983
984 static void usa67_glocont_callback(struct urb *urb)
985 {
986         struct usb_serial *serial;
987         struct usb_serial_port *port;
988         struct keyspan_port_private *p_priv;
989         int i;
990
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);
995
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);
1000                         break;
1001                 }
1002         }
1003 }
1004
1005 static int keyspan_write_room(struct tty_struct *tty)
1006 {
1007         struct usb_serial_port *port = tty->driver_data;
1008         struct keyspan_port_private     *p_priv;
1009         const struct keyspan_device_details     *d_details;
1010         int                             flip;
1011         int                             data_len;
1012         struct urb                      *this_urb;
1013
1014         p_priv = usb_get_serial_port_data(port);
1015         d_details = p_priv->device_details;
1016
1017         /* FIXME: locking */
1018         if (d_details->msg_format == msg_usa90)
1019                 data_len = 64;
1020         else
1021                 data_len = 63;
1022
1023         flip = p_priv->out_flip;
1024
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)
1029                         return data_len;
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)
1034                                 return data_len;
1035                 }
1036         }
1037         return 0;
1038 }
1039
1040
1041 static int keyspan_open(struct tty_struct *tty, struct usb_serial_port *port)
1042 {
1043         struct keyspan_port_private     *p_priv;
1044         const struct keyspan_device_details     *d_details;
1045         int                             i, err;
1046         int                             baud_rate, device_port;
1047         struct urb                      *urb;
1048         unsigned int                    cflag = 0;
1049
1050         p_priv = usb_get_serial_port_data(port);
1051         d_details = p_priv->device_details;
1052
1053         /* Set some sane defaults */
1054         p_priv->rts_state = 1;
1055         p_priv->dtr_state = 1;
1056         p_priv->baud = 9600;
1057
1058         /* force baud and lcr to be set on open */
1059         p_priv->old_baud = 0;
1060         p_priv->old_cflag = 0;
1061
1062         p_priv->out_flip = 0;
1063         p_priv->in_flip = 0;
1064
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];
1068                 if (urb == NULL)
1069                         continue;
1070
1071                 /* make sure endpoint data toggle is synchronized
1072                    with the device */
1073                 usb_clear_halt(urb->dev, urb->pipe);
1074                 err = usb_submit_urb(urb, GFP_KERNEL);
1075                 if (err != 0)
1076                         dev_dbg(&port->dev, "%s - submit urb %d failed (%d)\n", __func__, i, err);
1077         }
1078
1079         /* Reset low level data toggle on out endpoints */
1080         for (i = 0; i < 2; i++) {
1081                 urb = p_priv->out_urbs[i];
1082                 if (urb == NULL)
1083                         continue;
1084                 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
1085                                                 usb_pipeout(urb->pipe), 0); */
1086         }
1087
1088         /* get the terminal config for the setup message now so we don't
1089          * need to send 2 of them */
1090
1091         device_port = port->number - port->serial->minor;
1092         if (tty) {
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 */
1098                 if (baud_rate >= 0
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;
1102                 }
1103         }
1104         /* set CTS/RTS handshake etc. */
1105         p_priv->cflag = cflag;
1106         p_priv->flow_control = (cflag & CRTSCTS) ? flow_cts : flow_none;
1107
1108         keyspan_send_setup(port, 1);
1109         /* mdelay(100); */
1110         /* keyspan_set_termios(port, NULL); */
1111
1112         return 0;
1113 }
1114
1115 static inline void stop_urb(struct urb *urb)
1116 {
1117         if (urb && urb->status == -EINPROGRESS)
1118                 usb_kill_urb(urb);
1119 }
1120
1121 static void keyspan_dtr_rts(struct usb_serial_port *port, int on)
1122 {
1123         struct keyspan_port_private *p_priv = usb_get_serial_port_data(port);
1124
1125         p_priv->rts_state = on;
1126         p_priv->dtr_state = on;
1127         keyspan_send_setup(port, 0);
1128 }
1129
1130 static void keyspan_close(struct usb_serial_port *port)
1131 {
1132         int                     i;
1133         struct usb_serial       *serial = port->serial;
1134         struct keyspan_port_private     *p_priv;
1135
1136         p_priv = usb_get_serial_port_data(port);
1137
1138         p_priv->rts_state = 0;
1139         p_priv->dtr_state = 0;
1140
1141         if (serial->dev) {
1142                 keyspan_send_setup(port, 2);
1143                 /* pilot-xfer seems to work best with this delay */
1144                 mdelay(100);
1145                 /* keyspan_set_termios(port, NULL); */
1146         }
1147
1148         /*while (p_priv->outcont_urb->status == -EINPROGRESS) {
1149                 dev_dbg(&port->dev, "%s - urb in progress\n", __func__);
1150         }*/
1151
1152         p_priv->out_flip = 0;
1153         p_priv->in_flip = 0;
1154
1155         if (serial->dev) {
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]);
1162                 }
1163         }
1164 }
1165
1166 /* download the firmware to a pre-renumeration device */
1167 static int keyspan_fake_startup(struct usb_serial *serial)
1168 {
1169         char    *fw_name;
1170
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));
1174
1175         if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
1176                                                                 != 0x8000) {
1177                 dev_dbg(&serial->dev->dev, "Firmware already loaded.  Quitting.\n");
1178                 return 1;
1179         }
1180
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";
1185                 break;
1186
1187         case keyspan_usa28x_pre_product_id:
1188                 fw_name = "keyspan/usa28x.fw";
1189                 break;
1190
1191         case keyspan_usa28xa_pre_product_id:
1192                 fw_name = "keyspan/usa28xa.fw";
1193                 break;
1194
1195         case keyspan_usa28xb_pre_product_id:
1196                 fw_name = "keyspan/usa28xb.fw";
1197                 break;
1198
1199         case keyspan_usa19_pre_product_id:
1200                 fw_name = "keyspan/usa19.fw";
1201                 break;
1202
1203         case keyspan_usa19qi_pre_product_id:
1204                 fw_name = "keyspan/usa19qi.fw";
1205                 break;
1206
1207         case keyspan_mpr_pre_product_id:
1208                 fw_name = "keyspan/mpr.fw";
1209                 break;
1210
1211         case keyspan_usa19qw_pre_product_id:
1212                 fw_name = "keyspan/usa19qw.fw";
1213                 break;
1214
1215         case keyspan_usa18x_pre_product_id:
1216                 fw_name = "keyspan/usa18x.fw";
1217                 break;
1218
1219         case keyspan_usa19w_pre_product_id:
1220                 fw_name = "keyspan/usa19w.fw";
1221                 break;
1222
1223         case keyspan_usa49w_pre_product_id:
1224                 fw_name = "keyspan/usa49w.fw";
1225                 break;
1226
1227         case keyspan_usa49wlc_pre_product_id:
1228                 fw_name = "keyspan/usa49wlc.fw";
1229                 break;
1230
1231         default:
1232                 dev_err(&serial->dev->dev, "Unknown product ID (%04x)\n",
1233                         le16_to_cpu(serial->dev->descriptor.idProduct));
1234                 return 1;
1235         }
1236
1237         dev_dbg(&serial->dev->dev, "Uploading Keyspan %s firmware.\n", fw_name);
1238
1239         if (ezusb_fx1_ihex_firmware_download(serial->dev, fw_name) < 0) {
1240                 dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
1241                         fw_name);
1242                 return -ENOENT;
1243         }
1244
1245         /* after downloading firmware Renumeration will occur in a
1246           moment and the new device will bind to the real driver */
1247
1248         /* we don't want this device to have a driver assigned to it. */
1249         return 1;
1250 }
1251
1252 /* Helper functions used by keyspan_setup_urbs */
1253 static struct usb_endpoint_descriptor const *find_ep(struct usb_serial const *serial,
1254                                                      int endpoint)
1255 {
1256         struct usb_host_interface *iface_desc;
1257         struct usb_endpoint_descriptor *ep;
1258         int i;
1259
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)
1264                         return ep;
1265         }
1266         dev_warn(&serial->interface->dev, "found no endpoint descriptor for "
1267                  "endpoint %x\n", endpoint);
1268         return NULL;
1269 }
1270
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 *))
1274 {
1275         struct urb *urb;
1276         struct usb_endpoint_descriptor const *ep_desc;
1277         char const *ep_type_name;
1278
1279         if (endpoint == -1)
1280                 return NULL;            /* endpoint not needed */
1281
1282         dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d.\n", __func__, endpoint);
1283         urb = usb_alloc_urb(0, GFP_KERNEL);             /* No ISO */
1284         if (urb == NULL) {
1285                 dev_dbg(&serial->interface->dev, "%s - alloc for endpoint %d failed.\n", __func__, endpoint);
1286                 return NULL;
1287         }
1288
1289         if (endpoint == 0) {
1290                 /* control EP filled in when used */
1291                 return urb;
1292         }
1293
1294         ep_desc = find_ep(serial, endpoint);
1295         if (!ep_desc) {
1296                 /* leak the urb, something's wrong and the callers don't care */
1297                 return urb;
1298         }
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);
1310         } else {
1311                 dev_warn(&serial->interface->dev,
1312                          "unsupported endpoint type %x\n",
1313                          usb_endpoint_type(ep_desc));
1314                 usb_free_urb(urb);
1315                 return NULL;
1316         }
1317
1318         dev_dbg(&serial->interface->dev, "%s - using urb %p for %s endpoint %x\n",
1319             __func__, urb, ep_type_name, endpoint);
1320         return urb;
1321 }
1322
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[] = {
1331         {
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,
1339         }, {
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,
1347         }, {
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,
1355         }, {
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,
1363         }, {
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,
1371         }
1372 };
1373
1374         /* Generic setup urbs function that uses
1375            data in device_details */
1376 static void keyspan_setup_urbs(struct usb_serial *serial)
1377 {
1378         struct keyspan_serial_private   *s_priv;
1379         const struct keyspan_device_details     *d_details;
1380         struct callbacks                *cback;
1381
1382         s_priv = usb_get_serial_data(serial);
1383         d_details = s_priv->device_details;
1384
1385         /* Setup values for the various callback routines */
1386         cback = &keyspan_callbacks[d_details->msg_format];
1387
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);
1394
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);
1399
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);
1404 }
1405
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)
1410 {
1411         u32     b16,    /* baud rate times 16 (actual rate used internally) */
1412                 div,    /* divisor */
1413                 cnt;    /* inverse of divisor (programmed into 8051) */
1414
1415         dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1416
1417         /* prevent divide by zero...  */
1418         b16 = baud_rate * 16L;
1419         if (b16 == 0)
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;
1425
1426         /* calculate the divisor and the counter (its inverse) */
1427         div = baudclk / b16;
1428         if (div == 0)
1429                 return KEYSPAN_INVALID_BAUD_RATE;
1430         else
1431                 cnt = 0 - div;
1432
1433         if (div > 0xffff)
1434                 return KEYSPAN_INVALID_BAUD_RATE;
1435
1436         /* return the counter values if non-null */
1437         if (rate_low)
1438                 *rate_low = (u8) (cnt & 0xff);
1439         if (rate_hi)
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;
1445 }
1446
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)
1451 {
1452         u32     b16,    /* baud rate times 16 (actual rate used internally) */
1453                         div;    /* divisor */
1454
1455         dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1456
1457         /* prevent divide by zero...  */
1458         b16 = baud_rate * 16L;
1459         if (b16 == 0)
1460                 return KEYSPAN_INVALID_BAUD_RATE;
1461
1462         /* calculate the divisor */
1463         div = baudclk / b16;
1464         if (div == 0)
1465                 return KEYSPAN_INVALID_BAUD_RATE;
1466
1467         if (div > 0xffff)
1468                 return KEYSPAN_INVALID_BAUD_RATE;
1469
1470         /* return the counter values if non-null */
1471         if (rate_low)
1472                 *rate_low = (u8) (div & 0xff);
1473
1474         if (rate_hi)
1475                 *rate_hi = (u8) ((div >> 8) & 0xff);
1476
1477         if (rate_low && rate_hi)
1478                 dev_dbg(&port->dev, "%s - %d %02x %02x.\n",
1479                         __func__, baud_rate, *rate_hi, *rate_low);
1480
1481         return KEYSPAN_BAUD_RATE_OK;
1482 }
1483
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)
1487 {
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 */
1493                 smallest_diff;
1494         u8      best_prescaler;
1495         int     i;
1496
1497         dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1498
1499         /* prevent divide by zero */
1500         b16 = baud_rate * 16L;
1501         if (b16 == 0)
1502                 return KEYSPAN_INVALID_BAUD_RATE;
1503
1504         /* Calculate prescaler by trying them all and looking
1505            for best fit */
1506
1507         /* start with largest possible difference */
1508         smallest_diff = 0xffffffff;
1509
1510                 /* 0 is an invalid prescaler, used as a flag */
1511         best_prescaler = 0;
1512
1513         for (i = 8; i <= 0xff; ++i) {
1514                 clk = (baudclk * 8) / (u32) i;
1515
1516                 div = clk / b16;
1517                 if (div == 0)
1518                         continue;
1519
1520                 res = clk / div;
1521                 diff = (res > b16) ? (res-b16) : (b16-res);
1522
1523                 if (diff < smallest_diff) {
1524                         best_prescaler = i;
1525                         smallest_diff = diff;
1526                 }
1527         }
1528
1529         if (best_prescaler == 0)
1530                 return KEYSPAN_INVALID_BAUD_RATE;
1531
1532         clk = (baudclk * 8) / (u32) best_prescaler;
1533         div = clk / b16;
1534
1535         /* return the divisor and prescaler if non-null */
1536         if (rate_low)
1537                 *rate_low = (u8) (div & 0xff);
1538         if (rate_hi)
1539                 *rate_hi = (u8) ((div >> 8) & 0xff);
1540         if (prescaler) {
1541                 *prescaler = best_prescaler;
1542                 /*  dev_dbg(&port->dev, "%s - %d %d\n", __func__, *prescaler, div); */
1543         }
1544         return KEYSPAN_BAUD_RATE_OK;
1545 }
1546
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)
1551 {
1552         u32     b16,    /* baud rate times 16 (actual rate used internally) */
1553                 div,    /* divisor */
1554                 cnt;    /* inverse of divisor (programmed into 8051) */
1555
1556         dev_dbg(&port->dev, "%s - %d.\n", __func__, baud_rate);
1557
1558                 /* prevent divide by zero */
1559         b16 = baud_rate * 16L;
1560         if (b16 == 0)
1561                 return KEYSPAN_INVALID_BAUD_RATE;
1562
1563         /* calculate the divisor and the counter (its inverse) */
1564         div = KEYSPAN_USA28_BAUDCLK / b16;
1565         if (div == 0)
1566                 return KEYSPAN_INVALID_BAUD_RATE;
1567         else
1568                 cnt = 0 - div;
1569
1570         /* check for out of range, based on portnum,
1571            and return result */
1572         if (portnum == 0) {
1573                 if (div > 0xffff)
1574                         return KEYSPAN_INVALID_BAUD_RATE;
1575         } else {
1576                 if (portnum == 1) {
1577                         if (div > 0xff)
1578                                 return KEYSPAN_INVALID_BAUD_RATE;
1579                 } else
1580                         return KEYSPAN_INVALID_BAUD_RATE;
1581         }
1582
1583                 /* return the counter values if not NULL
1584                    (port 1 will ignore retHi) */
1585         if (rate_low)
1586                 *rate_low = (u8) (cnt & 0xff);
1587         if (rate_hi)
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;
1591 }
1592
1593 static int keyspan_usa26_send_setup(struct usb_serial *serial,
1594                                     struct usb_serial_port *port,
1595                                     int reset_port)
1596 {
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;
1601         int                                     outcont_urb;
1602         struct urb                              *this_urb;
1603         int                                     device_port, err;
1604
1605         dev_dbg(&port->dev, "%s reset=%d\n", __func__, reset_port);
1606
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;
1611
1612         outcont_urb = d_details->outcont_endpoints[port->number];
1613         this_urb = p_priv->outcont_urb;
1614
1615         dev_dbg(&port->dev, "%s - endpoint %d\n", __func__, usb_pipeendpoint(this_urb->pipe));
1616
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__);
1620                 return -1;
1621         }
1622
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__); */
1629                 mdelay(5);
1630                 return -1;
1631         }
1632
1633         memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
1634
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);
1644                         msg.baudLo = 0;
1645                         msg.baudHi = 125;       /* Values for 9600 baud */
1646                         msg.prescaler = 10;
1647                 }
1648                 msg.setPrescaler = 0xff;
1649         }
1650
1651         msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1652         switch (p_priv->cflag & CSIZE) {
1653         case CS5:
1654                 msg.lcr |= USA_DATABITS_5;
1655                 break;
1656         case CS6:
1657                 msg.lcr |= USA_DATABITS_6;
1658                 break;
1659         case CS7:
1660                 msg.lcr |= USA_DATABITS_7;
1661                 break;
1662         case CS8:
1663                 msg.lcr |= USA_DATABITS_8;
1664                 break;
1665         }
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;
1670         }
1671         msg.setLcr = 0xff;
1672
1673         msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1674         msg.xonFlowControl = 0;
1675         msg.setFlowControl = 0xff;
1676         msg.forwardingLength = 16;
1677         msg.xonChar = 17;
1678         msg.xoffChar = 19;
1679
1680         /* Opening port */
1681         if (reset_port == 1) {
1682                 msg._txOn = 1;
1683                 msg._txOff = 0;
1684                 msg.txFlush = 0;
1685                 msg.txBreak = 0;
1686                 msg.rxOn = 1;
1687                 msg.rxOff = 0;
1688                 msg.rxFlush = 1;
1689                 msg.rxForward = 0;
1690                 msg.returnStatus = 0;
1691                 msg.resetDataToggle = 0xff;
1692         }
1693
1694         /* Closing port */
1695         else if (reset_port == 2) {
1696                 msg._txOn = 0;
1697                 msg._txOff = 1;
1698                 msg.txFlush = 0;
1699                 msg.txBreak = 0;
1700                 msg.rxOn = 0;
1701                 msg.rxOff = 1;
1702                 msg.rxFlush = 1;
1703                 msg.rxForward = 0;
1704                 msg.returnStatus = 0;
1705                 msg.resetDataToggle = 0;
1706         }
1707
1708         /* Sending intermediate configs */
1709         else {
1710                 msg._txOn = (!p_priv->break_on);
1711                 msg._txOff = 0;
1712                 msg.txFlush = 0;
1713                 msg.txBreak = (p_priv->break_on);
1714                 msg.rxOn = 0;
1715                 msg.rxOff = 0;
1716                 msg.rxFlush = 0;
1717                 msg.rxForward = 0;
1718                 msg.returnStatus = 0;
1719                 msg.resetDataToggle = 0x0;
1720         }
1721
1722         /* Do handshaking outputs */
1723         msg.setTxTriState_setRts = 0xff;
1724         msg.txTriState_rts = p_priv->rts_state;
1725
1726         msg.setHskoa_setDtr = 0xff;
1727         msg.hskoa_dtr = p_priv->dtr_state;
1728
1729         p_priv->resend_cont = 0;
1730         memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1731
1732         /* send the data out the device on control endpoint */
1733         this_urb->transfer_buffer_length = sizeof(msg);
1734
1735         err = usb_submit_urb(this_urb, GFP_ATOMIC);
1736         if (err != 0)
1737                 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
1738 #if 0
1739         else {
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));
1743         }
1744 #endif
1745
1746         return 0;
1747 }
1748
1749 static int keyspan_usa28_send_setup(struct usb_serial *serial,
1750                                     struct usb_serial_port *port,
1751                                     int reset_port)
1752 {
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;
1759
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;
1764
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__);
1769                 return -1;
1770         }
1771
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__);
1778                 mdelay(5);
1779                 return -1;
1780         }
1781
1782         memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
1783
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);
1790                 msg.baudLo = 0xff;
1791                 msg.baudHi = 0xb2;      /* Values for 9600 baud */
1792         }
1793
1794         /* If parity is enabled, we must calculate it ourselves. */
1795         msg.parity = 0;         /* XXX for now */
1796
1797         msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1798         msg.xonFlowControl = 0;
1799
1800         /* Do handshaking outputs, DTR is inverted relative to RTS */
1801         msg.rts = p_priv->rts_state;
1802         msg.dtr = p_priv->dtr_state;
1803
1804         msg.forwardingLength = 16;
1805         msg.forwardMs = 10;
1806         msg.breakThreshold = 45;
1807         msg.xonChar = 17;
1808         msg.xoffChar = 19;
1809
1810         /*msg.returnStatus = 1;
1811         msg.resetDataToggle = 0xff;*/
1812         /* Opening port */
1813         if (reset_port == 1) {
1814                 msg._txOn = 1;
1815                 msg._txOff = 0;
1816                 msg.txFlush = 0;
1817                 msg.txForceXoff = 0;
1818                 msg.txBreak = 0;
1819                 msg.rxOn = 1;
1820                 msg.rxOff = 0;
1821                 msg.rxFlush = 1;
1822                 msg.rxForward = 0;
1823                 msg.returnStatus = 0;
1824                 msg.resetDataToggle = 0xff;
1825         }
1826         /* Closing port */
1827         else if (reset_port == 2) {
1828                 msg._txOn = 0;
1829                 msg._txOff = 1;
1830                 msg.txFlush = 0;
1831                 msg.txForceXoff = 0;
1832                 msg.txBreak = 0;
1833                 msg.rxOn = 0;
1834                 msg.rxOff = 1;
1835                 msg.rxFlush = 1;
1836                 msg.rxForward = 0;
1837                 msg.returnStatus = 0;
1838                 msg.resetDataToggle = 0;
1839         }
1840         /* Sending intermediate configs */
1841         else {
1842                 msg._txOn = (!p_priv->break_on);
1843                 msg._txOff = 0;
1844                 msg.txFlush = 0;
1845                 msg.txForceXoff = 0;
1846                 msg.txBreak = (p_priv->break_on);
1847                 msg.rxOn = 0;
1848                 msg.rxOff = 0;
1849                 msg.rxFlush = 0;
1850                 msg.rxForward = 0;
1851                 msg.returnStatus = 0;
1852                 msg.resetDataToggle = 0x0;
1853         }
1854
1855         p_priv->resend_cont = 0;
1856         memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
1857
1858         /* send the data out the device on control endpoint */
1859         this_urb->transfer_buffer_length = sizeof(msg);
1860
1861         err = usb_submit_urb(this_urb, GFP_ATOMIC);
1862         if (err != 0)
1863                 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed\n", __func__);
1864 #if 0
1865         else {
1866                 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) OK %d bytes\n", __func__,
1867                     this_urb->transfer_buffer_length);
1868         }
1869 #endif
1870
1871         return 0;
1872 }
1873
1874 static int keyspan_usa49_send_setup(struct usb_serial *serial,
1875                                     struct usb_serial_port *port,
1876                                     int reset_port)
1877 {
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;
1885
1886         s_priv = usb_get_serial_data(serial);
1887         p_priv = usb_get_serial_port_data(port);
1888         d_details = s_priv->device_details;
1889
1890         this_urb = s_priv->glocont_urb;
1891
1892         /* Work out which port within the device is being setup */
1893         device_port = port->number - port->serial->minor;
1894
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);
1898                 return -1;
1899         }
1900
1901         dev_dbg(&port->dev, "%s - endpoint %d port %d (%d)\n",
1902                 __func__, usb_pipeendpoint(this_urb->pipe),
1903                 port->number, device_port);
1904
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;
1909
1910         if (this_urb->status == -EINPROGRESS) {
1911                 /*  dev_dbg(&port->dev, "%s - already writing\n", __func__); */
1912                 mdelay(5);
1913                 return -1;
1914         }
1915
1916         memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
1917
1918         /*msg.portNumber = port->number;*/
1919         msg.portNumber = device_port;
1920
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);
1930                         msg.baudLo = 0;
1931                         msg.baudHi = 125;       /* Values for 9600 baud */
1932                         msg.prescaler = 10;
1933                 }
1934                 /* msg.setPrescaler = 0xff; */
1935         }
1936
1937         msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
1938         switch (p_priv->cflag & CSIZE) {
1939         case CS5:
1940                 msg.lcr |= USA_DATABITS_5;
1941                 break;
1942         case CS6:
1943                 msg.lcr |= USA_DATABITS_6;
1944                 break;
1945         case CS7:
1946                 msg.lcr |= USA_DATABITS_7;
1947                 break;
1948         case CS8:
1949                 msg.lcr |= USA_DATABITS_8;
1950                 break;
1951         }
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;
1956         }
1957         msg.setLcr = 0xff;
1958
1959         msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
1960         msg.xonFlowControl = 0;
1961         msg.setFlowControl = 0xff;
1962
1963         msg.forwardingLength = 16;
1964         msg.xonChar = 17;
1965         msg.xoffChar = 19;
1966
1967         /* Opening port */
1968         if (reset_port == 1) {
1969                 msg._txOn = 1;
1970                 msg._txOff = 0;
1971                 msg.txFlush = 0;
1972                 msg.txBreak = 0;
1973                 msg.rxOn = 1;
1974                 msg.rxOff = 0;
1975                 msg.rxFlush = 1;
1976                 msg.rxForward = 0;
1977                 msg.returnStatus = 0;
1978                 msg.resetDataToggle = 0xff;
1979                 msg.enablePort = 1;
1980                 msg.disablePort = 0;
1981         }
1982         /* Closing port */
1983         else if (reset_port == 2) {
1984                 msg._txOn = 0;
1985                 msg._txOff = 1;
1986                 msg.txFlush = 0;
1987                 msg.txBreak = 0;
1988                 msg.rxOn = 0;
1989                 msg.rxOff = 1;
1990                 msg.rxFlush = 1;
1991                 msg.rxForward = 0;
1992                 msg.returnStatus = 0;
1993                 msg.resetDataToggle = 0;
1994                 msg.enablePort = 0;
1995                 msg.disablePort = 1;
1996         }
1997         /* Sending intermediate configs */
1998         else {
1999                 msg._txOn = (!p_priv->break_on);
2000                 msg._txOff = 0;
2001                 msg.txFlush = 0;
2002                 msg.txBreak = (p_priv->break_on);
2003                 msg.rxOn = 0;
2004                 msg.rxOff = 0;
2005                 msg.rxFlush = 0;
2006                 msg.rxForward = 0;
2007                 msg.returnStatus = 0;
2008                 msg.resetDataToggle = 0x0;
2009                 msg.enablePort = 0;
2010                 msg.disablePort = 0;
2011         }
2012
2013         /* Do handshaking outputs */
2014         msg.setRts = 0xff;
2015         msg.rts = p_priv->rts_state;
2016
2017         msg.setDtr = 0xff;
2018         msg.dtr = p_priv->dtr_state;
2019
2020         p_priv->resend_cont = 0;
2021
2022         /* if the device is a 49wg, we send control message on usb
2023            control EP 0 */
2024
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 */;
2029                 dr->wValue = 0;
2030                 dr->wIndex = 0;
2031                 dr->wLength = cpu_to_le16(sizeof(msg));
2032
2033                 memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
2034
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);
2039
2040         } else {
2041                 memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2042
2043                 /* send the data out the device on control endpoint */
2044                 this_urb->transfer_buffer_length = sizeof(msg);
2045         }
2046         err = usb_submit_urb(this_urb, GFP_ATOMIC);
2047         if (err != 0)
2048                 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2049 #if 0
2050         else {
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));
2054         }
2055 #endif
2056
2057         return 0;
2058 }
2059
2060 static int keyspan_usa90_send_setup(struct usb_serial *serial,
2061                                     struct usb_serial_port *port,
2062                                     int reset_port)
2063 {
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;
2069         int                                     err;
2070         u8                                              prescaler;
2071
2072         s_priv = usb_get_serial_data(serial);
2073         p_priv = usb_get_serial_port_data(port);
2074         d_details = s_priv->device_details;
2075
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__);
2080                 return -1;
2081         }
2082
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__);
2089                 mdelay(5);
2090                 return -1;
2091         }
2092
2093         memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
2094
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);
2106                 }
2107                 msg.setRxMode = 1;
2108                 msg.setTxMode = 1;
2109         }
2110
2111         /* modes must always be correctly specified */
2112         if (p_priv->baud > 57600) {
2113                 msg.rxMode = RXMODE_DMA;
2114                 msg.txMode = TXMODE_DMA;
2115         } else {
2116                 msg.rxMode = RXMODE_BYHAND;
2117                 msg.txMode = TXMODE_BYHAND;
2118         }
2119
2120         msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2121         switch (p_priv->cflag & CSIZE) {
2122         case CS5:
2123                 msg.lcr |= USA_DATABITS_5;
2124                 break;
2125         case CS6:
2126                 msg.lcr |= USA_DATABITS_6;
2127                 break;
2128         case CS7:
2129                 msg.lcr |= USA_DATABITS_7;
2130                 break;
2131         case CS8:
2132                 msg.lcr |= USA_DATABITS_8;
2133                 break;
2134         }
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;
2139         }
2140         if (p_priv->old_cflag != p_priv->cflag) {
2141                 p_priv->old_cflag = p_priv->cflag;
2142                 msg.setLcr = 0x01;
2143         }
2144
2145         if (p_priv->flow_control == flow_cts)
2146                 msg.txFlowControl = TXFLOW_CTS;
2147         msg.setTxFlowControl = 0x01;
2148         msg.setRxFlowControl = 0x01;
2149
2150         msg.rxForwardingLength = 16;
2151         msg.rxForwardingTimeout = 16;
2152         msg.txAckSetting = 0;
2153         msg.xonChar = 17;
2154         msg.xoffChar = 19;
2155
2156         /* Opening port */
2157         if (reset_port == 1) {
2158                 msg.portEnabled = 1;
2159                 msg.rxFlush = 1;
2160                 msg.txBreak = (p_priv->break_on);
2161         }
2162         /* Closing port */
2163         else if (reset_port == 2)
2164                 msg.portEnabled = 0;
2165         /* Sending intermediate configs */
2166         else {
2167                 msg.portEnabled = 1;
2168                 msg.txBreak = (p_priv->break_on);
2169         }
2170
2171         /* Do handshaking outputs */
2172         msg.setRts = 0x01;
2173         msg.rts = p_priv->rts_state;
2174
2175         msg.setDtr = 0x01;
2176         msg.dtr = p_priv->dtr_state;
2177
2178         p_priv->resend_cont = 0;
2179         memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2180
2181         /* send the data out the device on control endpoint */
2182         this_urb->transfer_buffer_length = sizeof(msg);
2183
2184         err = usb_submit_urb(this_urb, GFP_ATOMIC);
2185         if (err != 0)
2186                 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2187         return 0;
2188 }
2189
2190 static int keyspan_usa67_send_setup(struct usb_serial *serial,
2191                                     struct usb_serial_port *port,
2192                                     int reset_port)
2193 {
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;
2200
2201         s_priv = usb_get_serial_data(serial);
2202         p_priv = usb_get_serial_port_data(port);
2203         d_details = s_priv->device_details;
2204
2205         this_urb = s_priv->glocont_urb;
2206
2207         /* Work out which port within the device is being setup */
2208         device_port = port->number - port->serial->minor;
2209
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__,
2213                         port->number);
2214                 return -1;
2215         }
2216
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__); */
2223                 mdelay(5);
2224                 return -1;
2225         }
2226
2227         memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
2228
2229         msg.port = device_port;
2230
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);
2240                         msg.baudLo = 0;
2241                         msg.baudHi = 125;       /* Values for 9600 baud */
2242                         msg.prescaler = 10;
2243                 }
2244                 msg.setPrescaler = 0xff;
2245         }
2246
2247         msg.lcr = (p_priv->cflag & CSTOPB) ? STOPBITS_678_2 : STOPBITS_5678_1;
2248         switch (p_priv->cflag & CSIZE) {
2249         case CS5:
2250                 msg.lcr |= USA_DATABITS_5;
2251                 break;
2252         case CS6:
2253                 msg.lcr |= USA_DATABITS_6;
2254                 break;
2255         case CS7:
2256                 msg.lcr |= USA_DATABITS_7;
2257                 break;
2258         case CS8:
2259                 msg.lcr |= USA_DATABITS_8;
2260                 break;
2261         }
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;
2266         }
2267         msg.setLcr = 0xff;
2268
2269         msg.ctsFlowControl = (p_priv->flow_control == flow_cts);
2270         msg.xonFlowControl = 0;
2271         msg.setFlowControl = 0xff;
2272         msg.forwardingLength = 16;
2273         msg.xonChar = 17;
2274         msg.xoffChar = 19;
2275
2276         if (reset_port == 1) {
2277                 /* Opening port */
2278                 msg._txOn = 1;
2279                 msg._txOff = 0;
2280                 msg.txFlush = 0;
2281                 msg.txBreak = 0;
2282                 msg.rxOn = 1;
2283                 msg.rxOff = 0;
2284                 msg.rxFlush = 1;
2285                 msg.rxForward = 0;
2286                 msg.returnStatus = 0;
2287                 msg.resetDataToggle = 0xff;
2288         } else if (reset_port == 2) {
2289                 /* Closing port */
2290                 msg._txOn = 0;
2291                 msg._txOff = 1;
2292                 msg.txFlush = 0;
2293                 msg.txBreak = 0;
2294                 msg.rxOn = 0;
2295                 msg.rxOff = 1;
2296                 msg.rxFlush = 1;
2297                 msg.rxForward = 0;
2298                 msg.returnStatus = 0;
2299                 msg.resetDataToggle = 0;
2300         } else {
2301                 /* Sending intermediate configs */
2302                 msg._txOn = (!p_priv->break_on);
2303                 msg._txOff = 0;
2304                 msg.txFlush = 0;
2305                 msg.txBreak = (p_priv->break_on);
2306                 msg.rxOn = 0;
2307                 msg.rxOff = 0;
2308                 msg.rxFlush = 0;
2309                 msg.rxForward = 0;
2310                 msg.returnStatus = 0;
2311                 msg.resetDataToggle = 0x0;
2312         }
2313
2314         /* Do handshaking outputs */
2315         msg.setTxTriState_setRts = 0xff;
2316         msg.txTriState_rts = p_priv->rts_state;
2317
2318         msg.setHskoa_setDtr = 0xff;
2319         msg.hskoa_dtr = p_priv->dtr_state;
2320
2321         p_priv->resend_cont = 0;
2322
2323         memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
2324
2325         /* send the data out the device on control endpoint */
2326         this_urb->transfer_buffer_length = sizeof(msg);
2327
2328         err = usb_submit_urb(this_urb, GFP_ATOMIC);
2329         if (err != 0)
2330                 dev_dbg(&port->dev, "%s - usb_submit_urb(setup) failed (%d)\n", __func__, err);
2331         return 0;
2332 }
2333
2334 static void keyspan_send_setup(struct usb_serial_port *port, int reset_port)
2335 {
2336         struct usb_serial *serial = port->serial;
2337         struct keyspan_serial_private *s_priv;
2338         const struct keyspan_device_details *d_details;
2339
2340         s_priv = usb_get_serial_data(serial);
2341         d_details = s_priv->device_details;
2342
2343         switch (d_details->msg_format) {
2344         case msg_usa26:
2345                 keyspan_usa26_send_setup(serial, port, reset_port);
2346                 break;
2347         case msg_usa28:
2348                 keyspan_usa28_send_setup(serial, port, reset_port);
2349                 break;
2350         case msg_usa49:
2351                 keyspan_usa49_send_setup(serial, port, reset_port);
2352                 break;
2353         case msg_usa90:
2354                 keyspan_usa90_send_setup(serial, port, reset_port);
2355                 break;
2356         case msg_usa67:
2357                 keyspan_usa67_send_setup(serial, port, reset_port);
2358                 break;
2359         }
2360 }
2361
2362
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)
2366 {
2367         int                             i, err;
2368         struct keyspan_serial_private   *s_priv;
2369         const struct keyspan_device_details     *d_details;
2370
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))
2374                         break;
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));
2378                 return 1;
2379         }
2380
2381         /* Setup private data for serial driver */
2382         s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
2383         if (!s_priv) {
2384                 dev_dbg(&serial->dev->dev, "%s - kmalloc for keyspan_serial_private failed.\n", __func__);
2385                 return -ENOMEM;
2386         }
2387
2388         s_priv->device_details = d_details;
2389         usb_set_serial_data(serial, s_priv);
2390
2391         keyspan_setup_urbs(serial);
2392
2393         if (s_priv->instat_urb != NULL) {
2394                 err = usb_submit_urb(s_priv->instat_urb, GFP_KERNEL);
2395                 if (err != 0)
2396                         dev_dbg(&serial->dev->dev, "%s - submit instat urb failed %d\n", __func__, err);
2397         }
2398         if (s_priv->indat_urb != NULL) {
2399                 err = usb_submit_urb(s_priv->indat_urb, GFP_KERNEL);
2400                 if (err != 0)
2401                         dev_dbg(&serial->dev->dev, "%s - submit indat urb failed %d\n", __func__, err);
2402         }
2403
2404         return 0;
2405 }
2406
2407 static void keyspan_disconnect(struct usb_serial *serial)
2408 {
2409         struct keyspan_serial_private *s_priv;
2410
2411         s_priv = usb_get_serial_data(serial);
2412
2413         stop_urb(s_priv->instat_urb);
2414         stop_urb(s_priv->glocont_urb);
2415         stop_urb(s_priv->indat_urb);
2416 }
2417
2418 static void keyspan_release(struct usb_serial *serial)
2419 {
2420         struct keyspan_serial_private *s_priv;
2421
2422         s_priv = usb_get_serial_data(serial);
2423
2424         usb_free_urb(s_priv->instat_urb);
2425         usb_free_urb(s_priv->indat_urb);
2426         usb_free_urb(s_priv->glocont_urb);
2427
2428         kfree(s_priv);
2429 }
2430
2431 static int keyspan_port_probe(struct usb_serial_port *port)
2432 {
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;
2438         int endp;
2439         int port_num;
2440         int i;
2441
2442         s_priv = usb_get_serial_data(serial);
2443         d_details = s_priv->device_details;
2444
2445         p_priv = kzalloc(sizeof(*p_priv), GFP_KERNEL);
2446         if (!p_priv)
2447                 return -ENOMEM;
2448
2449         p_priv->device_details = d_details;
2450
2451         /* Setup values for the various callback routines */
2452         cback = &keyspan_callbacks[d_details->msg_format];
2453
2454         port_num = port->number - port->serial->minor;
2455
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,
2460                                                 USB_DIR_IN, port,
2461                                                 p_priv->in_buffer[i], 64,
2462                                                 cback->indat_callback);
2463         }
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,
2468                                                 USB_DIR_OUT, port,
2469                                                 p_priv->out_buffer[i], 64,
2470                                                 cback->outdat_callback);
2471         }
2472         /* inack endpoint */
2473         p_priv->inack_urb = keyspan_setup_urb(serial,
2474                                         d_details->inack_endpoints[port_num],
2475                                         USB_DIR_IN, port,
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],
2481                                         USB_DIR_OUT, port,
2482                                         p_priv->outcont_buffer, 64,
2483                                          cback->outcont_callback);
2484
2485         usb_set_serial_port_data(port, p_priv);
2486
2487         return 0;
2488 }
2489
2490 static int keyspan_port_remove(struct usb_serial_port *port)
2491 {
2492         struct keyspan_port_private *p_priv;
2493         int i;
2494
2495         p_priv = usb_get_serial_port_data(port);
2496
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]);
2502         }
2503
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]);
2509         }
2510
2511         kfree(p_priv);
2512
2513         return 0;
2514 }
2515
2516 MODULE_AUTHOR(DRIVER_AUTHOR);
2517 MODULE_DESCRIPTION(DRIVER_DESC);
2518 MODULE_LICENSE("GPL");
2519
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");