USB: serial: keyspan_pda.c: remove debug module parameter
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / usb / serial / keyspan_pda.c
1 /*
2  * USB Keyspan PDA / Xircom / Entregra Converter driver
3  *
4  * Copyright (C) 1999 - 2001 Greg Kroah-Hartman <greg@kroah.com>
5  * Copyright (C) 1999, 2000 Brian Warner        <warner@lothar.com>
6  * Copyright (C) 2000 Al Borchers               <borchers@steinerpoint.com>
7  *
8  *      This program is free software; you can redistribute it and/or modify
9  *      it under the terms of the GNU General Public License as published by
10  *      the Free Software Foundation; either version 2 of the License, or
11  *      (at your option) any later version.
12  *
13  * See Documentation/usb/usb-serial.txt for more information on using this
14  * driver
15  */
16
17
18 #include <linux/kernel.h>
19 #include <linux/errno.h>
20 #include <linux/init.h>
21 #include <linux/slab.h>
22 #include <linux/tty.h>
23 #include <linux/tty_driver.h>
24 #include <linux/tty_flip.h>
25 #include <linux/module.h>
26 #include <linux/spinlock.h>
27 #include <linux/workqueue.h>
28 #include <linux/firmware.h>
29 #include <linux/ihex.h>
30 #include <linux/uaccess.h>
31 #include <linux/usb.h>
32 #include <linux/usb/serial.h>
33
34 /* make a simple define to handle if we are compiling keyspan_pda or xircom support */
35 #if defined(CONFIG_USB_SERIAL_KEYSPAN_PDA) || defined(CONFIG_USB_SERIAL_KEYSPAN_PDA_MODULE)
36         #define KEYSPAN
37 #else
38         #undef KEYSPAN
39 #endif
40 #if defined(CONFIG_USB_SERIAL_XIRCOM) || defined(CONFIG_USB_SERIAL_XIRCOM_MODULE)
41         #define XIRCOM
42 #else
43         #undef XIRCOM
44 #endif
45
46 /*
47  * Version Information
48  */
49 #define DRIVER_VERSION "v1.1"
50 #define DRIVER_AUTHOR "Brian Warner <warner@lothar.com>"
51 #define DRIVER_DESC "USB Keyspan PDA Converter driver"
52
53 struct keyspan_pda_private {
54         int                     tx_room;
55         int                     tx_throttled;
56         struct work_struct                      wakeup_work;
57         struct work_struct                      unthrottle_work;
58         struct usb_serial       *serial;
59         struct usb_serial_port  *port;
60 };
61
62
63 #define KEYSPAN_VENDOR_ID               0x06cd
64 #define KEYSPAN_PDA_FAKE_ID             0x0103
65 #define KEYSPAN_PDA_ID                  0x0104 /* no clue */
66
67 /* For Xircom PGSDB9 and older Entregra version of the same device */
68 #define XIRCOM_VENDOR_ID                0x085a
69 #define XIRCOM_FAKE_ID                  0x8027
70 #define ENTREGRA_VENDOR_ID              0x1645
71 #define ENTREGRA_FAKE_ID                0x8093
72
73 static const struct usb_device_id id_table_combined[] = {
74 #ifdef KEYSPAN
75         { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) },
76 #endif
77 #ifdef XIRCOM
78         { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
79         { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) },
80 #endif
81         { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) },
82         { }                                             /* Terminating entry */
83 };
84
85 MODULE_DEVICE_TABLE(usb, id_table_combined);
86
87 static const struct usb_device_id id_table_std[] = {
88         { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_ID) },
89         { }                                             /* Terminating entry */
90 };
91
92 #ifdef KEYSPAN
93 static const struct usb_device_id id_table_fake[] = {
94         { USB_DEVICE(KEYSPAN_VENDOR_ID, KEYSPAN_PDA_FAKE_ID) },
95         { }                                             /* Terminating entry */
96 };
97 #endif
98
99 #ifdef XIRCOM
100 static const struct usb_device_id id_table_fake_xircom[] = {
101         { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
102         { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) },
103         { }
104 };
105 #endif
106
107 static void keyspan_pda_wakeup_write(struct work_struct *work)
108 {
109         struct keyspan_pda_private *priv =
110                 container_of(work, struct keyspan_pda_private, wakeup_work);
111         struct usb_serial_port *port = priv->port;
112         struct tty_struct *tty = tty_port_tty_get(&port->port);
113         if (tty)
114                 tty_wakeup(tty);
115         tty_kref_put(tty);
116 }
117
118 static void keyspan_pda_request_unthrottle(struct work_struct *work)
119 {
120         struct keyspan_pda_private *priv =
121                 container_of(work, struct keyspan_pda_private, unthrottle_work);
122         struct usb_serial *serial = priv->serial;
123         int result;
124
125         /* ask the device to tell us when the tx buffer becomes
126            sufficiently empty */
127         result = usb_control_msg(serial->dev,
128                                  usb_sndctrlpipe(serial->dev, 0),
129                                  7, /* request_unthrottle */
130                                  USB_TYPE_VENDOR | USB_RECIP_INTERFACE
131                                  | USB_DIR_OUT,
132                                  16, /* value: threshold */
133                                  0, /* index */
134                                  NULL,
135                                  0,
136                                  2000);
137         if (result < 0)
138                 dev_dbg(&serial->dev->dev, "%s - error %d from usb_control_msg\n",
139                         __func__, result);
140 }
141
142
143 static void keyspan_pda_rx_interrupt(struct urb *urb)
144 {
145         struct usb_serial_port *port = urb->context;
146         struct tty_struct *tty;
147         unsigned char *data = urb->transfer_buffer;
148         int retval;
149         int status = urb->status;
150         struct keyspan_pda_private *priv;
151         priv = usb_get_serial_port_data(port);
152
153         switch (status) {
154         case 0:
155                 /* success */
156                 break;
157         case -ECONNRESET:
158         case -ENOENT:
159         case -ESHUTDOWN:
160                 /* this urb is terminated, clean up */
161                 dev_dbg(&urb->dev->dev, "%s - urb shutting down with status: %d\n", __func__, status);
162                 return;
163         default:
164                 dev_dbg(&urb->dev->dev, "%s - nonzero urb status received: %d\n", __func__, status);
165                 goto exit;
166         }
167
168         /* see if the message is data or a status interrupt */
169         switch (data[0]) {
170         case 0:
171                 tty = tty_port_tty_get(&port->port);
172                  /* rest of message is rx data */
173                 if (tty && urb->actual_length) {
174                         tty_insert_flip_string(tty, data + 1,
175                                                 urb->actual_length - 1);
176                         tty_flip_buffer_push(tty);
177                 }
178                 tty_kref_put(tty);
179                 break;
180         case 1:
181                 /* status interrupt */
182                 dev_dbg(&port->dev, "rx int, d1=%d, d2=%d\n", data[1], data[2]);
183                 switch (data[1]) {
184                 case 1: /* modemline change */
185                         break;
186                 case 2: /* tx unthrottle interrupt */
187                         priv->tx_throttled = 0;
188                         /* queue up a wakeup at scheduler time */
189                         schedule_work(&priv->wakeup_work);
190                         break;
191                 default:
192                         break;
193                 }
194                 break;
195         default:
196                 break;
197         }
198
199 exit:
200         retval = usb_submit_urb(urb, GFP_ATOMIC);
201         if (retval)
202                 dev_err(&port->dev,
203                         "%s - usb_submit_urb failed with result %d",
204                         __func__, retval);
205 }
206
207
208 static void keyspan_pda_rx_throttle(struct tty_struct *tty)
209 {
210         /* stop receiving characters. We just turn off the URB request, and
211            let chars pile up in the device. If we're doing hardware
212            flowcontrol, the device will signal the other end when its buffer
213            fills up. If we're doing XON/XOFF, this would be a good time to
214            send an XOFF, although it might make sense to foist that off
215            upon the device too. */
216         struct usb_serial_port *port = tty->driver_data;
217
218         usb_kill_urb(port->interrupt_in_urb);
219 }
220
221
222 static void keyspan_pda_rx_unthrottle(struct tty_struct *tty)
223 {
224         struct usb_serial_port *port = tty->driver_data;
225         /* just restart the receive interrupt URB */
226
227         if (usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL))
228                 dev_dbg(&port->dev, "usb_submit_urb(read urb) failed\n");
229 }
230
231
232 static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud)
233 {
234         int rc;
235         int bindex;
236
237         switch (baud) {
238         case 110:
239                 bindex = 0;
240                 break;
241         case 300:
242                 bindex = 1;
243                 break;
244         case 1200:
245                 bindex = 2;
246                 break;
247         case 2400:
248                 bindex = 3;
249                 break;
250         case 4800:
251                 bindex = 4;
252                 break;
253         case 9600:
254                 bindex = 5;
255                 break;
256         case 19200:
257                 bindex = 6;
258                 break;
259         case 38400:
260                 bindex = 7;
261                 break;
262         case 57600:
263                 bindex = 8;
264                 break;
265         case 115200:
266                 bindex = 9;
267                 break;
268         default:
269                 bindex = 5;     /* Default to 9600 */
270                 baud = 9600;
271         }
272
273         /* rather than figure out how to sleep while waiting for this
274            to complete, I just use the "legacy" API. */
275         rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
276                              0, /* set baud */
277                              USB_TYPE_VENDOR
278                              | USB_RECIP_INTERFACE
279                              | USB_DIR_OUT, /* type */
280                              bindex, /* value */
281                              0, /* index */
282                              NULL, /* &data */
283                              0, /* size */
284                              2000); /* timeout */
285         if (rc < 0)
286                 return 0;
287         return baud;
288 }
289
290
291 static void keyspan_pda_break_ctl(struct tty_struct *tty, int break_state)
292 {
293         struct usb_serial_port *port = tty->driver_data;
294         struct usb_serial *serial = port->serial;
295         int value;
296         int result;
297
298         if (break_state == -1)
299                 value = 1; /* start break */
300         else
301                 value = 0; /* clear break */
302         result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
303                         4, /* set break */
304                         USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
305                         value, 0, NULL, 0, 2000);
306         if (result < 0)
307                 dev_dbg(&port->dev, "%s - error %d from usb_control_msg\n",
308                         __func__, result);
309         /* there is something funky about this.. the TCSBRK that 'cu' performs
310            ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4
311            seconds apart, but it feels like the break sent isn't as long as it
312            is on /dev/ttyS0 */
313 }
314
315
316 static void keyspan_pda_set_termios(struct tty_struct *tty,
317                 struct usb_serial_port *port, struct ktermios *old_termios)
318 {
319         struct usb_serial *serial = port->serial;
320         speed_t speed;
321
322         /* cflag specifies lots of stuff: number of stop bits, parity, number
323            of data bits, baud. What can the device actually handle?:
324            CSTOPB (1 stop bit or 2)
325            PARENB (parity)
326            CSIZE (5bit .. 8bit)
327            There is minimal hw support for parity (a PSW bit seems to hold the
328            parity of whatever is in the accumulator). The UART either deals
329            with 10 bits (start, 8 data, stop) or 11 bits (start, 8 data,
330            1 special, stop). So, with firmware changes, we could do:
331            8N1: 10 bit
332            8N2: 11 bit, extra bit always (mark?)
333            8[EOMS]1: 11 bit, extra bit is parity
334            7[EOMS]1: 10 bit, b0/b7 is parity
335            7[EOMS]2: 11 bit, b0/b7 is parity, extra bit always (mark?)
336
337            HW flow control is dictated by the tty->termios->c_cflags & CRTSCTS
338            bit.
339
340            For now, just do baud. */
341
342         speed = tty_get_baud_rate(tty);
343         speed = keyspan_pda_setbaud(serial, speed);
344
345         if (speed == 0) {
346                 dev_dbg(&port->dev, "can't handle requested baud rate\n");
347                 /* It hasn't changed so.. */
348                 speed = tty_termios_baud_rate(old_termios);
349         }
350         /* Only speed can change so copy the old h/w parameters
351            then encode the new speed */
352         tty_termios_copy_hw(tty->termios, old_termios);
353         tty_encode_baud_rate(tty, speed, speed);
354 }
355
356
357 /* modem control pins: DTR and RTS are outputs and can be controlled.
358    DCD, RI, DSR, CTS are inputs and can be read. All outputs can also be
359    read. The byte passed is: DTR(b7) DCD RI DSR CTS RTS(b2) unused unused */
360
361 static int keyspan_pda_get_modem_info(struct usb_serial *serial,
362                                       unsigned char *value)
363 {
364         int rc;
365         u8 *data;
366
367         data = kmalloc(1, GFP_KERNEL);
368         if (!data)
369                 return -ENOMEM;
370
371         rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
372                              3, /* get pins */
373                              USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_IN,
374                              0, 0, data, 1, 2000);
375         if (rc >= 0)
376                 *value = *data;
377
378         kfree(data);
379         return rc;
380 }
381
382
383 static int keyspan_pda_set_modem_info(struct usb_serial *serial,
384                                       unsigned char value)
385 {
386         int rc;
387         rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
388                              3, /* set pins */
389                              USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_OUT,
390                              value, 0, NULL, 0, 2000);
391         return rc;
392 }
393
394 static int keyspan_pda_tiocmget(struct tty_struct *tty)
395 {
396         struct usb_serial_port *port = tty->driver_data;
397         struct usb_serial *serial = port->serial;
398         int rc;
399         unsigned char status;
400         int value;
401
402         rc = keyspan_pda_get_modem_info(serial, &status);
403         if (rc < 0)
404                 return rc;
405         value =
406                 ((status & (1<<7)) ? TIOCM_DTR : 0) |
407                 ((status & (1<<6)) ? TIOCM_CAR : 0) |
408                 ((status & (1<<5)) ? TIOCM_RNG : 0) |
409                 ((status & (1<<4)) ? TIOCM_DSR : 0) |
410                 ((status & (1<<3)) ? TIOCM_CTS : 0) |
411                 ((status & (1<<2)) ? TIOCM_RTS : 0);
412         return value;
413 }
414
415 static int keyspan_pda_tiocmset(struct tty_struct *tty,
416                                 unsigned int set, unsigned int clear)
417 {
418         struct usb_serial_port *port = tty->driver_data;
419         struct usb_serial *serial = port->serial;
420         int rc;
421         unsigned char status;
422
423         rc = keyspan_pda_get_modem_info(serial, &status);
424         if (rc < 0)
425                 return rc;
426
427         if (set & TIOCM_RTS)
428                 status |= (1<<2);
429         if (set & TIOCM_DTR)
430                 status |= (1<<7);
431
432         if (clear & TIOCM_RTS)
433                 status &= ~(1<<2);
434         if (clear & TIOCM_DTR)
435                 status &= ~(1<<7);
436         rc = keyspan_pda_set_modem_info(serial, status);
437         return rc;
438 }
439
440 static int keyspan_pda_write(struct tty_struct *tty,
441         struct usb_serial_port *port, const unsigned char *buf, int count)
442 {
443         struct usb_serial *serial = port->serial;
444         int request_unthrottle = 0;
445         int rc = 0;
446         struct keyspan_pda_private *priv;
447
448         priv = usb_get_serial_port_data(port);
449         /* guess how much room is left in the device's ring buffer, and if we
450            want to send more than that, check first, updating our notion of
451            what is left. If our write will result in no room left, ask the
452            device to give us an interrupt when the room available rises above
453            a threshold, and hold off all writers (eventually, those using
454            select() or poll() too) until we receive that unthrottle interrupt.
455            Block if we can't write anything at all, otherwise write as much as
456            we can. */
457         if (count == 0) {
458                 dev_dbg(&port->dev, "write request of 0 bytes\n");
459                 return 0;
460         }
461
462         /* we might block because of:
463            the TX urb is in-flight (wait until it completes)
464            the device is full (wait until it says there is room)
465         */
466         spin_lock_bh(&port->lock);
467         if (!test_bit(0, &port->write_urbs_free) || priv->tx_throttled) {
468                 spin_unlock_bh(&port->lock);
469                 return 0;
470         }
471         clear_bit(0, &port->write_urbs_free);
472         spin_unlock_bh(&port->lock);
473
474         /* At this point the URB is in our control, nobody else can submit it
475            again (the only sudden transition was the one from EINPROGRESS to
476            finished).  Also, the tx process is not throttled. So we are
477            ready to write. */
478
479         count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
480
481         /* Check if we might overrun the Tx buffer.   If so, ask the
482            device how much room it really has.  This is done only on
483            scheduler time, since usb_control_msg() sleeps. */
484         if (count > priv->tx_room && !in_interrupt()) {
485                 u8 *room;
486
487                 room = kmalloc(1, GFP_KERNEL);
488                 if (!room) {
489                         rc = -ENOMEM;
490                         goto exit;
491                 }
492
493                 rc = usb_control_msg(serial->dev,
494                                      usb_rcvctrlpipe(serial->dev, 0),
495                                      6, /* write_room */
496                                      USB_TYPE_VENDOR | USB_RECIP_INTERFACE
497                                      | USB_DIR_IN,
498                                      0, /* value: 0 means "remaining room" */
499                                      0, /* index */
500                                      room,
501                                      1,
502                                      2000);
503                 if (rc > 0) {
504                         dev_dbg(&port->dev, "roomquery says %d\n", *room);
505                         priv->tx_room = *room;
506                 }
507                 kfree(room);
508                 if (rc < 0) {
509                         dev_dbg(&port->dev, "roomquery failed\n");
510                         goto exit;
511                 }
512                 if (rc == 0) {
513                         dev_dbg(&port->dev, "roomquery returned 0 bytes\n");
514                         rc = -EIO; /* device didn't return any data */
515                         goto exit;
516                 }
517         }
518         if (count > priv->tx_room) {
519                 /* we're about to completely fill the Tx buffer, so
520                    we'll be throttled afterwards. */
521                 count = priv->tx_room;
522                 request_unthrottle = 1;
523         }
524
525         if (count) {
526                 /* now transfer data */
527                 memcpy(port->write_urb->transfer_buffer, buf, count);
528                 /* send the data out the bulk port */
529                 port->write_urb->transfer_buffer_length = count;
530
531                 priv->tx_room -= count;
532
533                 rc = usb_submit_urb(port->write_urb, GFP_ATOMIC);
534                 if (rc) {
535                         dev_dbg(&port->dev, "usb_submit_urb(write bulk) failed\n");
536                         goto exit;
537                 }
538         } else {
539                 /* There wasn't any room left, so we are throttled until
540                    the buffer empties a bit */
541                 request_unthrottle = 1;
542         }
543
544         if (request_unthrottle) {
545                 priv->tx_throttled = 1; /* block writers */
546                 schedule_work(&priv->unthrottle_work);
547         }
548
549         rc = count;
550 exit:
551         if (rc < 0)
552                 set_bit(0, &port->write_urbs_free);
553         return rc;
554 }
555
556
557 static void keyspan_pda_write_bulk_callback(struct urb *urb)
558 {
559         struct usb_serial_port *port = urb->context;
560         struct keyspan_pda_private *priv;
561
562         set_bit(0, &port->write_urbs_free);
563         priv = usb_get_serial_port_data(port);
564
565         /* queue up a wakeup at scheduler time */
566         schedule_work(&priv->wakeup_work);
567 }
568
569
570 static int keyspan_pda_write_room(struct tty_struct *tty)
571 {
572         struct usb_serial_port *port = tty->driver_data;
573         struct keyspan_pda_private *priv;
574         priv = usb_get_serial_port_data(port);
575         /* used by n_tty.c for processing of tabs and such. Giving it our
576            conservative guess is probably good enough, but needs testing by
577            running a console through the device. */
578         return priv->tx_room;
579 }
580
581
582 static int keyspan_pda_chars_in_buffer(struct tty_struct *tty)
583 {
584         struct usb_serial_port *port = tty->driver_data;
585         struct keyspan_pda_private *priv;
586         unsigned long flags;
587         int ret = 0;
588
589         priv = usb_get_serial_port_data(port);
590
591         /* when throttled, return at least WAKEUP_CHARS to tell select() (via
592            n_tty.c:normal_poll() ) that we're not writeable. */
593
594         spin_lock_irqsave(&port->lock, flags);
595         if (!test_bit(0, &port->write_urbs_free) || priv->tx_throttled)
596                 ret = 256;
597         spin_unlock_irqrestore(&port->lock, flags);
598         return ret;
599 }
600
601
602 static void keyspan_pda_dtr_rts(struct usb_serial_port *port, int on)
603 {
604         struct usb_serial *serial = port->serial;
605
606         if (serial->dev) {
607                 if (on)
608                         keyspan_pda_set_modem_info(serial, (1<<7) | (1<< 2));
609                 else
610                         keyspan_pda_set_modem_info(serial, 0);
611         }
612 }
613
614
615 static int keyspan_pda_open(struct tty_struct *tty,
616                                         struct usb_serial_port *port)
617 {
618         struct usb_serial *serial = port->serial;
619         u8 *room;
620         int rc = 0;
621         struct keyspan_pda_private *priv;
622
623         /* find out how much room is in the Tx ring */
624         room = kmalloc(1, GFP_KERNEL);
625         if (!room)
626                 return -ENOMEM;
627
628         rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
629                              6, /* write_room */
630                              USB_TYPE_VENDOR | USB_RECIP_INTERFACE
631                              | USB_DIR_IN,
632                              0, /* value */
633                              0, /* index */
634                              room,
635                              1,
636                              2000);
637         if (rc < 0) {
638                 dev_dbg(&port->dev, "%s - roomquery failed\n", __func__);
639                 goto error;
640         }
641         if (rc == 0) {
642                 dev_dbg(&port->dev, "%s - roomquery returned 0 bytes\n", __func__);
643                 rc = -EIO;
644                 goto error;
645         }
646         priv = usb_get_serial_port_data(port);
647         priv->tx_room = *room;
648         priv->tx_throttled = *room ? 0 : 1;
649
650         /*Start reading from the device*/
651         rc = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
652         if (rc) {
653                 dev_dbg(&port->dev, "%s - usb_submit_urb(read int) failed\n", __func__);
654                 goto error;
655         }
656 error:
657         kfree(room);
658         return rc;
659 }
660 static void keyspan_pda_close(struct usb_serial_port *port)
661 {
662         struct usb_serial *serial = port->serial;
663
664         if (serial->dev) {
665                 /* shutdown our bulk reads and writes */
666                 usb_kill_urb(port->write_urb);
667                 usb_kill_urb(port->interrupt_in_urb);
668         }
669 }
670
671
672 /* download the firmware to a "fake" device (pre-renumeration) */
673 static int keyspan_pda_fake_startup(struct usb_serial *serial)
674 {
675         int response;
676         const char *fw_name;
677         const struct ihex_binrec *record;
678         const struct firmware *fw;
679
680         /* download the firmware here ... */
681         response = ezusb_set_reset(serial->dev, 1);
682
683         if (0) { ; }
684 #ifdef KEYSPAN
685         else if (le16_to_cpu(serial->dev->descriptor.idVendor) == KEYSPAN_VENDOR_ID)
686                 fw_name = "keyspan_pda/keyspan_pda.fw";
687 #endif
688 #ifdef XIRCOM
689         else if ((le16_to_cpu(serial->dev->descriptor.idVendor) == XIRCOM_VENDOR_ID) ||
690                  (le16_to_cpu(serial->dev->descriptor.idVendor) == ENTREGRA_VENDOR_ID))
691                 fw_name = "keyspan_pda/xircom_pgs.fw";
692 #endif
693         else {
694                 dev_err(&serial->dev->dev, "%s: unknown vendor, aborting.\n",
695                         __func__);
696                 return -ENODEV;
697         }
698         if (request_ihex_firmware(&fw, fw_name, &serial->dev->dev)) {
699                 dev_err(&serial->dev->dev, "failed to load firmware \"%s\"\n",
700                         fw_name);
701                 return -ENOENT;
702         }
703         record = (const struct ihex_binrec *)fw->data;
704
705         while (record) {
706                 response = ezusb_writememory(serial->dev, be32_to_cpu(record->addr),
707                                              (unsigned char *)record->data,
708                                              be16_to_cpu(record->len), 0xa0);
709                 if (response < 0) {
710                         dev_err(&serial->dev->dev, "ezusb_writememory failed "
711                                 "for Keyspan PDA firmware (%d %04X %p %d)\n",
712                                 response, be32_to_cpu(record->addr),
713                                 record->data, be16_to_cpu(record->len));
714                         break;
715                 }
716                 record = ihex_next_binrec(record);
717         }
718         release_firmware(fw);
719         /* bring device out of reset. Renumeration will occur in a moment
720            and the new device will bind to the real driver */
721         response = ezusb_set_reset(serial->dev, 0);
722
723         /* we want this device to fail to have a driver assigned to it. */
724         return 1;
725 }
726
727 #ifdef KEYSPAN
728 MODULE_FIRMWARE("keyspan_pda/keyspan_pda.fw");
729 #endif
730 #ifdef XIRCOM
731 MODULE_FIRMWARE("keyspan_pda/xircom_pgs.fw");
732 #endif
733
734 static int keyspan_pda_startup(struct usb_serial *serial)
735 {
736
737         struct keyspan_pda_private *priv;
738
739         /* allocate the private data structures for all ports. Well, for all
740            one ports. */
741
742         priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL);
743         if (!priv)
744                 return 1; /* error */
745         usb_set_serial_port_data(serial->port[0], priv);
746         init_waitqueue_head(&serial->port[0]->write_wait);
747         INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write);
748         INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle);
749         priv->serial = serial;
750         priv->port = serial->port[0];
751         return 0;
752 }
753
754 static void keyspan_pda_release(struct usb_serial *serial)
755 {
756         kfree(usb_get_serial_port_data(serial->port[0]));
757 }
758
759 #ifdef KEYSPAN
760 static struct usb_serial_driver keyspan_pda_fake_device = {
761         .driver = {
762                 .owner =        THIS_MODULE,
763                 .name =         "keyspan_pda_pre",
764         },
765         .description =          "Keyspan PDA - (prerenumeration)",
766         .id_table =             id_table_fake,
767         .num_ports =            1,
768         .attach =               keyspan_pda_fake_startup,
769 };
770 #endif
771
772 #ifdef XIRCOM
773 static struct usb_serial_driver xircom_pgs_fake_device = {
774         .driver = {
775                 .owner =        THIS_MODULE,
776                 .name =         "xircom_no_firm",
777         },
778         .description =          "Xircom / Entregra PGS - (prerenumeration)",
779         .id_table =             id_table_fake_xircom,
780         .num_ports =            1,
781         .attach =               keyspan_pda_fake_startup,
782 };
783 #endif
784
785 static struct usb_serial_driver keyspan_pda_device = {
786         .driver = {
787                 .owner =        THIS_MODULE,
788                 .name =         "keyspan_pda",
789         },
790         .description =          "Keyspan PDA",
791         .id_table =             id_table_std,
792         .num_ports =            1,
793         .dtr_rts =              keyspan_pda_dtr_rts,
794         .open =                 keyspan_pda_open,
795         .close =                keyspan_pda_close,
796         .write =                keyspan_pda_write,
797         .write_room =           keyspan_pda_write_room,
798         .write_bulk_callback =  keyspan_pda_write_bulk_callback,
799         .read_int_callback =    keyspan_pda_rx_interrupt,
800         .chars_in_buffer =      keyspan_pda_chars_in_buffer,
801         .throttle =             keyspan_pda_rx_throttle,
802         .unthrottle =           keyspan_pda_rx_unthrottle,
803         .set_termios =          keyspan_pda_set_termios,
804         .break_ctl =            keyspan_pda_break_ctl,
805         .tiocmget =             keyspan_pda_tiocmget,
806         .tiocmset =             keyspan_pda_tiocmset,
807         .attach =               keyspan_pda_startup,
808         .release =              keyspan_pda_release,
809 };
810
811 static struct usb_serial_driver * const serial_drivers[] = {
812         &keyspan_pda_device,
813 #ifdef KEYSPAN
814         &keyspan_pda_fake_device,
815 #endif
816 #ifdef XIRCOM
817         &xircom_pgs_fake_device,
818 #endif
819         NULL
820 };
821
822 module_usb_serial_driver(serial_drivers, id_table_combined);
823
824 MODULE_AUTHOR(DRIVER_AUTHOR);
825 MODULE_DESCRIPTION(DRIVER_DESC);
826 MODULE_LICENSE("GPL");