Linux 2.4.0-test10pre1
[davej-history.git] / drivers / usb / serial / keyspan_pda.c
blob51a1f10dfd274005078e8f23703c111dc1b330d7
1 /*
2 * USB Keyspan PDA Converter driver
4 * Copyright (c) 1999, 2000 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>
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.
13 * See Documentation/usb/usb-serial.txt for more information on using this driver
15 * (10/05/2000) gkh
16 * Fixed bug with urb->dev not being set properly, now that the usb
17 * core needs it.
19 * (08/28/2000) gkh
20 * Added locks for SMP safeness.
21 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
22 * than once.
24 * (07/20/2000) borchers
25 * - keyspan_pda_write no longer sleeps if it is called on interrupt time;
26 * PPP and the line discipline with stty echo on can call write on
27 * interrupt time and this would cause an oops if write slept
28 * - if keyspan_pda_write is in an interrupt, it will not call
29 * usb_control_msg (which sleeps) to query the room in the device
30 * buffer, it simply uses the current room value it has
31 * - if the urb is busy or if it is throttled keyspan_pda_write just
32 * returns 0, rather than sleeping to wait for this to change; the
33 * write_chan code in n_tty.c will sleep if needed before calling
34 * keyspan_pda_write again
35 * - if the device needs to be unthrottled, write now queues up the
36 * call to usb_control_msg (which sleeps) to unthrottle the device
37 * - the wakeups from keyspan_pda_write_bulk_callback are queued rather
38 * than done directly from the callback to avoid the race in write_chan
39 * - keyspan_pda_chars_in_buffer also indicates its buffer is full if the
40 * urb status is -EINPROGRESS, meaning it cannot write at the moment
42 * (07/19/2000) gkh
43 * Added module_init and module_exit functions to handle the fact that this
44 * driver is a loadable module now.
46 * (03/26/2000) gkh
47 * Split driver up into device specific pieces.
52 #include <linux/config.h>
53 #include <linux/kernel.h>
54 #include <linux/sched.h>
55 #include <linux/signal.h>
56 #include <linux/errno.h>
57 #include <linux/poll.h>
58 #include <linux/init.h>
59 #include <linux/malloc.h>
60 #include <linux/fcntl.h>
61 #include <linux/tty_driver.h>
62 #include <linux/tty_flip.h>
63 #include <linux/tty.h>
64 #include <linux/module.h>
65 #include <linux/spinlock.h>
66 #include <linux/tqueue.h>
68 #ifdef CONFIG_USB_SERIAL_DEBUG
69 #define DEBUG
70 #else
71 #undef DEBUG
72 #endif
73 #include <linux/usb.h>
75 struct ezusb_hex_record {
76 __u16 address;
77 __u8 data_size;
78 __u8 data[16];
81 #include "keyspan_pda_fw.h"
83 #include "usb-serial.h"
85 struct keyspan_pda_private {
86 int tx_room;
87 int tx_throttled;
88 struct tq_struct wakeup_task;
89 struct tq_struct unthrottle_task;
92 #define KEYSPAN_VENDOR_ID 0x06cd
93 #define KEYSPAN_PDA_FAKE_ID 0x0103
94 #define KEYSPAN_PDA_ID 0x0104 /* no clue */
96 /* All of the device info needed for the Keyspan PDA serial converter */
97 static __u16 keyspan_vendor_id = KEYSPAN_VENDOR_ID;
98 static __u16 keyspan_pda_fake_product_id = KEYSPAN_PDA_FAKE_ID;
99 static __u16 keyspan_pda_product_id = KEYSPAN_PDA_ID;
103 static void keyspan_pda_wakeup_write( struct usb_serial_port *port )
106 struct tty_struct *tty = port->tty;
108 /* wake up port processes */
109 wake_up_interruptible( &port->write_wait );
111 /* wake up line discipline */
112 if( (tty->flags & (1 << TTY_DO_WRITE_WAKEUP))
113 && tty->ldisc.write_wakeup )
114 (tty->ldisc.write_wakeup)(tty);
116 /* wake up other tty processes */
117 wake_up_interruptible( &tty->write_wait );
118 /* For 2.2.16 backport -- wake_up_interruptible( &tty->poll_wait ); */
122 static void keyspan_pda_request_unthrottle( struct usb_serial *serial )
125 dbg(" request_unthrottle");
126 /* ask the device to tell us when the tx buffer becomes
127 sufficiently empty */
128 usb_control_msg(serial->dev,
129 usb_sndctrlpipe(serial->dev, 0),
130 7, /* request_unthrottle */
131 USB_TYPE_VENDOR | USB_RECIP_INTERFACE
132 | USB_DIR_OUT,
133 16, /* value: threshold */
134 0, /* index */
135 NULL,
137 2*HZ);
142 static void keyspan_pda_rx_interrupt (struct urb *urb)
144 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
145 struct usb_serial *serial;
146 struct tty_struct *tty;
147 unsigned char *data = urb->transfer_buffer;
148 int i;
149 struct keyspan_pda_private *priv;
150 priv = (struct keyspan_pda_private *)(port->private);
152 /* the urb might have been killed. */
153 if (urb->status)
154 return;
156 if (port_paranoia_check (port, "keyspan_pda_rx_interrupt")) {
157 return;
160 serial = port->serial;
161 if (serial_paranoia_check (serial, "keyspan_pda_rx_interrupt")) {
162 return;
165 /* see if the message is data or a status interrupt */
166 switch (data[0]) {
167 case 0:
168 /* rest of message is rx data */
169 if (urb->actual_length) {
170 tty = serial->port[0].tty;
171 for (i = 1; i < urb->actual_length ; ++i) {
172 tty_insert_flip_char(tty, data[i], 0);
174 tty_flip_buffer_push(tty);
176 break;
177 case 1:
178 /* status interrupt */
179 dbg(" rx int, d1=%d, d2=%d", data[1], data[2]);
180 switch (data[1]) {
181 case 1: /* modemline change */
182 break;
183 case 2: /* tx unthrottle interrupt */
184 tty = serial->port[0].tty;
185 priv->tx_throttled = 0;
186 /* queue up a wakeup at scheduler time */
187 queue_task( &priv->wakeup_task, &tq_scheduler );
188 break;
189 default:
190 break;
192 break;
193 default:
194 break;
197 /* INT urbs are automatically re-submitted */
201 static void keyspan_pda_rx_throttle (struct usb_serial_port *port)
203 /* stop receiving characters. We just turn off the URB request, and
204 let chars pile up in the device. If we're doing hardware
205 flowcontrol, the device will signal the other end when its buffer
206 fills up. If we're doing XON/XOFF, this would be a good time to
207 send an XOFF, although it might make sense to foist that off
208 upon the device too. */
210 dbg("keyspan_pda_rx_throttle port %d", port->number);
211 usb_unlink_urb(port->interrupt_in_urb);
215 static void keyspan_pda_rx_unthrottle (struct usb_serial_port *port)
217 /* just restart the receive interrupt URB */
218 dbg("keyspan_pda_rx_unthrottle port %d", port->number);
219 port->interrupt_in_urb->dev = port->serial->dev;
220 if (usb_submit_urb(port->interrupt_in_urb))
221 dbg(" usb_submit_urb(read urb) failed");
222 return;
226 static int keyspan_pda_setbaud (struct usb_serial *serial, int baud)
228 int rc;
229 int bindex;
231 switch(baud) {
232 case 110: bindex = 0; break;
233 case 300: bindex = 1; break;
234 case 1200: bindex = 2; break;
235 case 2400: bindex = 3; break;
236 case 4800: bindex = 4; break;
237 case 9600: bindex = 5; break;
238 case 19200: bindex = 6; break;
239 case 38400: bindex = 7; break;
240 case 57600: bindex = 8; break;
241 case 115200: bindex = 9; break;
242 default: return -EINVAL;
245 /* rather than figure out how to sleep while waiting for this
246 to complete, I just use the "legacy" API. */
247 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
248 0, /* set baud */
249 USB_TYPE_VENDOR
250 | USB_RECIP_INTERFACE
251 | USB_DIR_OUT, /* type */
252 bindex, /* value */
253 0, /* index */
254 NULL, /* &data */
255 0, /* size */
256 2*HZ); /* timeout */
257 return(rc);
261 static void keyspan_pda_break_ctl (struct usb_serial_port *port, int break_state)
263 struct usb_serial *serial = port->serial;
264 int value;
265 if (break_state == -1)
266 value = 1; /* start break */
267 else
268 value = 0; /* clear break */
269 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
270 4, /* set break */
271 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
272 value, 0, NULL, 0, 2*HZ);
273 /* there is something funky about this.. the TCSBRK that 'cu' performs
274 ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4
275 seconds apart, but it feels like the break sent isn't as long as it
276 is on /dev/ttyS0 */
280 static void keyspan_pda_set_termios (struct usb_serial_port *port,
281 struct termios *old_termios)
283 struct usb_serial *serial = port->serial;
284 unsigned int cflag = port->tty->termios->c_cflag;
286 /* cflag specifies lots of stuff: number of stop bits, parity, number
287 of data bits, baud. What can the device actually handle?:
288 CSTOPB (1 stop bit or 2)
289 PARENB (parity)
290 CSIZE (5bit .. 8bit)
291 There is minimal hw support for parity (a PSW bit seems to hold the
292 parity of whatever is in the accumulator). The UART either deals
293 with 10 bits (start, 8 data, stop) or 11 bits (start, 8 data,
294 1 special, stop). So, with firmware changes, we could do:
295 8N1: 10 bit
296 8N2: 11 bit, extra bit always (mark?)
297 8[EOMS]1: 11 bit, extra bit is parity
298 7[EOMS]1: 10 bit, b0/b7 is parity
299 7[EOMS]2: 11 bit, b0/b7 is parity, extra bit always (mark?)
301 HW flow control is dictated by the tty->termios->c_cflags & CRTSCTS
302 bit.
304 For now, just do baud. */
306 switch (cflag & CBAUD) {
307 /* we could support more values here, just need to calculate
308 the necessary divisors in the firmware. <asm/termbits.h>
309 has the Bnnn constants. */
310 case B110: keyspan_pda_setbaud(serial, 110); break;
311 case B300: keyspan_pda_setbaud(serial, 300); break;
312 case B1200: keyspan_pda_setbaud(serial, 1200); break;
313 case B2400: keyspan_pda_setbaud(serial, 2400); break;
314 case B4800: keyspan_pda_setbaud(serial, 4800); break;
315 case B9600: keyspan_pda_setbaud(serial, 9600); break;
316 case B19200: keyspan_pda_setbaud(serial, 19200); break;
317 case B38400: keyspan_pda_setbaud(serial, 38400); break;
318 case B57600: keyspan_pda_setbaud(serial, 57600); break;
319 case B115200: keyspan_pda_setbaud(serial, 115200); break;
320 default: dbg("can't handle requested baud rate"); break;
325 /* modem control pins: DTR and RTS are outputs and can be controlled.
326 DCD, RI, DSR, CTS are inputs and can be read. All outputs can also be
327 read. The byte passed is: DTR(b7) DCD RI DSR CTS RTS(b2) unused unused */
329 static int keyspan_pda_get_modem_info(struct usb_serial *serial,
330 unsigned char *value)
332 int rc;
333 unsigned char data;
334 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
335 3, /* get pins */
336 USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_IN,
337 0, 0, &data, 1, 2*HZ);
338 if (rc > 0)
339 *value = data;
340 return rc;
344 static int keyspan_pda_set_modem_info(struct usb_serial *serial,
345 unsigned char value)
347 int rc;
348 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
349 3, /* set pins */
350 USB_TYPE_VENDOR|USB_RECIP_INTERFACE|USB_DIR_OUT,
351 value, 0, NULL, 0, 2*HZ);
352 return rc;
356 static int keyspan_pda_ioctl(struct usb_serial_port *port, struct file *file,
357 unsigned int cmd, unsigned long arg)
359 struct usb_serial *serial = port->serial;
360 int rc;
361 unsigned int value;
362 unsigned char status, mask;
364 switch (cmd) {
365 case TIOCMGET: /* get modem pins state */
366 rc = keyspan_pda_get_modem_info(serial, &status);
367 if (rc < 0)
368 return rc;
369 value =
370 ((status & (1<<7)) ? TIOCM_DTR : 0) |
371 ((status & (1<<6)) ? TIOCM_CAR : 0) |
372 ((status & (1<<5)) ? TIOCM_RNG : 0) |
373 ((status & (1<<4)) ? TIOCM_DSR : 0) |
374 ((status & (1<<3)) ? TIOCM_CTS : 0) |
375 ((status & (1<<2)) ? TIOCM_RTS : 0);
376 if (copy_to_user((unsigned int *)arg, &value, sizeof(int)))
377 return -EFAULT;
378 return 0;
379 case TIOCMSET: /* set a state as returned by MGET */
380 if (copy_from_user(&value, (unsigned int *)arg, sizeof(int)))
381 return -EFAULT;
382 status =
383 ((value & TIOCM_DTR) ? (1<<7) : 0) |
384 ((value & TIOCM_CAR) ? (1<<6) : 0) |
385 ((value & TIOCM_RNG) ? (1<<5) : 0) |
386 ((value & TIOCM_DSR) ? (1<<4) : 0) |
387 ((value & TIOCM_CTS) ? (1<<3) : 0) |
388 ((value & TIOCM_RTS) ? (1<<2) : 0);
389 rc = keyspan_pda_set_modem_info(serial, status);
390 if (rc < 0)
391 return rc;
392 return 0;
393 case TIOCMBIS: /* set bits in bitmask <arg> */
394 case TIOCMBIC: /* clear bits from bitmask <arg> */
395 if (copy_from_user(&value, (unsigned int *)arg, sizeof(int)))
396 return -EFAULT;
397 rc = keyspan_pda_get_modem_info(serial, &status);
398 if (rc < 0)
399 return rc;
400 mask =
401 ((value & TIOCM_RTS) ? (1<<2) : 0) |
402 ((value & TIOCM_DTR) ? (1<<7) : 0);
403 if (cmd == TIOCMBIS)
404 status |= mask;
405 else
406 status &= ~mask;
407 rc = keyspan_pda_set_modem_info(serial, status);
408 if (rc < 0)
409 return rc;
410 return 0;
411 case TIOCMIWAIT:
412 /* wait for any of the 4 modem inputs (DCD,RI,DSR,CTS)*/
413 /* TODO */
414 case TIOCGICOUNT:
415 /* return count of modemline transitions */
416 return 0; /* TODO */
419 return -ENOIOCTLCMD;
422 static int keyspan_pda_write(struct usb_serial_port *port, int from_user,
423 const unsigned char *buf, int count)
425 struct usb_serial *serial = port->serial;
426 int request_unthrottle = 0;
427 int rc = 0;
428 struct keyspan_pda_private *priv;
429 unsigned long flags;
431 priv = (struct keyspan_pda_private *)(port->private);
432 /* guess how much room is left in the device's ring buffer, and if we
433 want to send more than that, check first, updating our notion of
434 what is left. If our write will result in no room left, ask the
435 device to give us an interrupt when the room available rises above
436 a threshold, and hold off all writers (eventually, those using
437 select() or poll() too) until we receive that unthrottle interrupt.
438 Block if we can't write anything at all, otherwise write as much as
439 we can. */
440 dbg("keyspan_pda_write(%d)",count);
441 if (count == 0) {
442 dbg(" write request of 0 bytes");
443 return (0);
446 /* we might block because of:
447 the TX urb is in-flight (wait until it completes)
448 the device is full (wait until it says there is room)
450 if (port->write_urb->status == -EINPROGRESS || priv->tx_throttled ) {
451 return( 0 );
454 /* At this point the URB is in our control, nobody else can submit it
455 again (the only sudden transition was the one from EINPROGRESS to
456 finished). Also, the tx process is not throttled. So we are
457 ready to write. */
459 spin_lock_irqsave (&port->port_lock, flags);
460 count = (count > port->bulk_out_size) ? port->bulk_out_size : count;
462 /* Check if we might overrun the Tx buffer. If so, ask the
463 device how much room it really has. This is done only on
464 scheduler time, since usb_control_msg() sleeps. */
465 if (count > priv->tx_room && !in_interrupt()) {
466 unsigned char room;
467 rc = usb_control_msg(serial->dev,
468 usb_rcvctrlpipe(serial->dev, 0),
469 6, /* write_room */
470 USB_TYPE_VENDOR | USB_RECIP_INTERFACE
471 | USB_DIR_IN,
472 0, /* value: 0 means "remaining room" */
473 0, /* index */
474 &room,
476 2*HZ);
477 if (rc < 0) {
478 dbg(" roomquery failed");
479 spin_unlock_irqrestore (&port->port_lock, flags);
480 return rc; /* failed */
482 if (rc == 0) {
483 dbg(" roomquery returned 0 bytes");
484 spin_unlock_irqrestore (&port->port_lock, flags);
485 return -EIO; /* device didn't return any data */
487 dbg(" roomquery says %d", room);
488 priv->tx_room = room;
490 if (count > priv->tx_room) {
491 /* we're about to completely fill the Tx buffer, so
492 we'll be throttled afterwards. */
493 count = priv->tx_room;
494 request_unthrottle = 1;
497 if (count) {
498 /* now transfer data */
499 if (from_user) {
500 if( copy_from_user(port->write_urb->transfer_buffer,
501 buf, count) ) {
502 spin_unlock_irqrestore (&port->port_lock, flags);
503 return( -EFAULT );
506 else {
507 memcpy (port->write_urb->transfer_buffer, buf, count);
509 /* send the data out the bulk port */
510 port->write_urb->transfer_buffer_length = count;
512 priv->tx_room -= count;
514 port->write_urb->dev = port->serial->dev;
515 if (usb_submit_urb(port->write_urb)) {
516 dbg(" usb_submit_urb(write bulk) failed");
517 spin_unlock_irqrestore (&port->port_lock, flags);
518 return (0);
521 else {
522 /* There wasn't any room left, so we are throttled until
523 the buffer empties a bit */
524 request_unthrottle = 1;
527 if (request_unthrottle) {
528 priv->tx_throttled = 1; /* block writers */
529 queue_task( &priv->unthrottle_task, &tq_scheduler );
532 spin_unlock_irqrestore (&port->port_lock, flags);
533 return (count);
537 static void keyspan_pda_write_bulk_callback (struct urb *urb)
539 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
540 struct usb_serial *serial;
541 struct keyspan_pda_private *priv;
543 priv = (struct keyspan_pda_private *)(port->private);
545 if (port_paranoia_check (port, "keyspan_pda_rx_interrupt")) {
546 return;
549 serial = port->serial;
550 if (serial_paranoia_check (serial, "keyspan_pda_rx_interrupt")) {
551 return;
554 /* queue up a wakeup at scheduler time */
555 queue_task( &priv->wakeup_task, &tq_scheduler );
560 static int keyspan_pda_write_room (struct usb_serial_port *port)
562 struct keyspan_pda_private *priv;
563 priv = (struct keyspan_pda_private *)(port->private);
565 /* used by n_tty.c for processing of tabs and such. Giving it our
566 conservative guess is probably good enough, but needs testing by
567 running a console through the device. */
569 return (priv->tx_room);
573 static int keyspan_pda_chars_in_buffer (struct usb_serial_port *port)
575 struct keyspan_pda_private *priv;
576 priv = (struct keyspan_pda_private *)(port->private);
578 /* when throttled, return at least WAKEUP_CHARS to tell select() (via
579 n_tty.c:normal_poll() ) that we're not writeable. */
580 if( port->write_urb->status == -EINPROGRESS || priv->tx_throttled )
581 return 256;
582 return 0;
586 static int keyspan_pda_open (struct usb_serial_port *port, struct file *filp)
588 struct usb_serial *serial = port->serial;
589 unsigned char room;
590 int rc;
591 struct keyspan_pda_private *priv;
592 unsigned long flags;
594 spin_lock_irqsave (&port->port_lock, flags);
596 MOD_INC_USE_COUNT;
597 ++port->open_count;
599 if (!port->active) {
600 port->active = 1;
602 /* find out how much room is in the Tx ring */
603 spin_unlock_irqrestore (&port->port_lock, flags);
604 rc = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
605 6, /* write_room */
606 USB_TYPE_VENDOR | USB_RECIP_INTERFACE
607 | USB_DIR_IN,
608 0, /* value */
609 0, /* index */
610 &room,
612 2*HZ);
613 spin_lock_irqsave (&port->port_lock, flags);
614 if (rc < 0) {
615 dbg(__FUNCTION__" - roomquery failed");
616 goto error;
618 if (rc == 0) {
619 dbg(__FUNCTION__" - roomquery returned 0 bytes");
620 rc = -EIO;
621 goto error;
623 priv = (struct keyspan_pda_private *)(port->private);
624 priv->tx_room = room;
625 priv->tx_throttled = room ? 0 : 1;
627 /* the normal serial device seems to always turn on DTR and RTS here,
628 so do the same */
629 spin_unlock_irqrestore (&port->port_lock, flags);
630 if (port->tty->termios->c_cflag & CBAUD)
631 keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2) );
632 else
633 keyspan_pda_set_modem_info(serial, 0);
635 /*Start reading from the device*/
636 port->interrupt_in_urb->dev = serial->dev;
637 if (usb_submit_urb(port->interrupt_in_urb))
638 dbg(__FUNCTION__" - usb_submit_urb(read int) failed");
639 } else {
640 spin_unlock_irqrestore (&port->port_lock, flags);
644 return (0);
645 error:
646 --port->open_count;
647 port->active = 0;
648 MOD_DEC_USE_COUNT;
649 spin_unlock_irqrestore (&port->port_lock, flags);
650 return rc;
654 static void keyspan_pda_close(struct usb_serial_port *port, struct file *filp)
656 struct usb_serial *serial = port->serial;
657 unsigned long flags;
659 spin_lock_irqsave (&port->port_lock, flags);
661 --port->open_count;
662 MOD_DEC_USE_COUNT;
664 if (port->open_count <= 0) {
665 /* the normal serial device seems to always shut off DTR and RTS now */
666 spin_unlock_irqrestore (&port->port_lock, flags);
667 if (port->tty->termios->c_cflag & HUPCL)
668 keyspan_pda_set_modem_info(serial, 0);
669 spin_lock_irqsave (&port->port_lock, flags);
671 /* shutdown our bulk reads and writes */
672 usb_unlink_urb (port->write_urb);
673 usb_unlink_urb (port->interrupt_in_urb);
674 port->active = 0;
675 port->open_count = 0;
678 spin_unlock_irqrestore (&port->port_lock, flags);
682 /* download the firmware to a "fake" device (pre-renumeration) */
683 static int keyspan_pda_fake_startup (struct usb_serial *serial)
685 int response;
686 const struct ezusb_hex_record *record;
688 /* download the firmware here ... */
689 response = ezusb_set_reset(serial, 1);
691 record = &keyspan_pda_firmware[0];
692 while(record->address != 0xffff) {
693 response = ezusb_writememory(serial, record->address,
694 (unsigned char *)record->data,
695 record->data_size, 0xa0);
696 if (response < 0) {
697 err("ezusb_writememory failed for Keyspan PDA "
698 "firmware (%d %04X %p %d)",
699 response,
700 record->address, record->data, record->data_size);
701 break;
703 record++;
705 /* bring device out of reset. Renumeration will occur in a moment
706 and the new device will bind to the real driver */
707 response = ezusb_set_reset(serial, 0);
709 /* we want this device to fail to have a driver assigned to it. */
710 return (1);
713 static int keyspan_pda_startup (struct usb_serial *serial)
716 struct keyspan_pda_private *priv;
718 /* allocate the private data structures for all ports. Well, for all
719 one ports. */
721 priv = serial->port[0].private
722 = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL);
723 if (!priv)
724 return (1); /* error */
725 init_waitqueue_head(&serial->port[0].write_wait);
726 priv->wakeup_task.next = NULL;
727 priv->wakeup_task.sync = 0;
728 priv->wakeup_task.routine = (void *)keyspan_pda_wakeup_write;
729 priv->wakeup_task.data = (void *)(&serial->port[0]);
730 priv->unthrottle_task.next = NULL;
731 priv->unthrottle_task.sync = 0;
732 priv->unthrottle_task.routine = (void *)keyspan_pda_request_unthrottle;
733 priv->unthrottle_task.data = (void *)(serial);
734 return (0);
737 static void keyspan_pda_shutdown (struct usb_serial *serial)
739 dbg (__FUNCTION__);
741 while (serial->port[0].open_count > 0) {
742 keyspan_pda_close (&serial->port[0], NULL);
744 kfree(serial->port[0].private);
747 struct usb_serial_device_type keyspan_pda_fake_device = {
748 name: "Keyspan PDA - (prerenumeration)",
749 idVendor: &keyspan_vendor_id,
750 idProduct: &keyspan_pda_fake_product_id,
751 needs_interrupt_in: DONT_CARE,
752 needs_bulk_in: DONT_CARE,
753 needs_bulk_out: DONT_CARE,
754 num_interrupt_in: NUM_DONT_CARE,
755 num_bulk_in: NUM_DONT_CARE,
756 num_bulk_out: NUM_DONT_CARE,
757 num_ports: 1,
758 startup: keyspan_pda_fake_startup,
761 struct usb_serial_device_type keyspan_pda_device = {
762 name: "Keyspan PDA",
763 idVendor: &keyspan_vendor_id,
764 idProduct: &keyspan_pda_product_id,
765 needs_interrupt_in: MUST_HAVE,
766 needs_bulk_in: DONT_CARE,
767 needs_bulk_out: MUST_HAVE,
768 num_interrupt_in: 1,
769 num_bulk_in: 0,
770 num_bulk_out: 1,
771 num_ports: 1,
772 open: keyspan_pda_open,
773 close: keyspan_pda_close,
774 write: keyspan_pda_write,
775 write_room: keyspan_pda_write_room,
776 write_bulk_callback: keyspan_pda_write_bulk_callback,
777 read_int_callback: keyspan_pda_rx_interrupt,
778 chars_in_buffer: keyspan_pda_chars_in_buffer,
779 throttle: keyspan_pda_rx_throttle,
780 unthrottle: keyspan_pda_rx_unthrottle,
781 ioctl: keyspan_pda_ioctl,
782 set_termios: keyspan_pda_set_termios,
783 break_ctl: keyspan_pda_break_ctl,
784 startup: keyspan_pda_startup,
785 shutdown: keyspan_pda_shutdown,
789 static int __init keyspan_pda_init (void)
791 usb_serial_register (&keyspan_pda_fake_device);
792 usb_serial_register (&keyspan_pda_device);
793 return 0;
797 static void __exit keyspan_pda_exit (void)
799 usb_serial_deregister (&keyspan_pda_fake_device);
800 usb_serial_deregister (&keyspan_pda_device);
804 module_init(keyspan_pda_init);
805 module_exit(keyspan_pda_exit);
807 MODULE_AUTHOR("Brian Warner <warner@lothar.com>");
808 MODULE_DESCRIPTION("USB Keyspan PDA Converter driver");