USB serial console support added
[opensuse:kernel.git] / drivers / usb / serial / visor.c
1 /*
2  * USB HandSpring Visor, Palm m50x, and Sony Clie driver
3  * (supports all of the Palm OS USB devices)
4  *
5  *      Copyright (C) 1999 - 2002
6  *          Greg Kroah-Hartman (greg@kroah.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 driver
14  *
15  * (03/27/2002) gkh
16  *      Removed assumptions that port->tty was always valid (is not true
17  *      for usb serial console devices.)
18  *
19  * (03/23/2002) gkh
20  *      Added support for the Palm i705 device, thanks to Thomas Riemer
21  *      <tom@netmech.com> for the information.
22  *
23  * (03/21/2002) gkh
24  *      Added support for the Palm m130 device, thanks to Udo Eisenbarth
25  *      <udo.eisenbarth@web.de> for the information.
26  *
27  * (02/27/2002) gkh
28  *      Reworked the urb handling logic.  We have no more pool, but dynamically
29  *      allocate the urb and the transfer buffer on the fly.  In testing this
30  *      does not incure any measurable overhead.  This also relies on the fact
31  *      that we have proper reference counting logic for urbs.
32  *
33  * (02/21/2002) SilaS
34  *  Added initial support for the Palm m515 devices.
35  *
36  * (02/14/2002) gkh
37  *      Added support for the Clie S-360 device.
38  *
39  * (12/18/2001) gkh
40  *      Added better Clie support for 3.5 devices.  Thanks to Geoffrey Levand
41  *      for the patch.
42  *
43  * (11/11/2001) gkh
44  *      Added support for the m125 devices, and added check to prevent oopses
45  *      for Clié devices that lie about the number of ports they have.
46  *
47  * (08/30/2001) gkh
48  *      Added support for the Clie devices, both the 3.5 and 4.0 os versions.
49  *      Many thanks to Daniel Burke, and Bryan Payne for helping with this.
50  *
51  * (08/23/2001) gkh
52  *      fixed a few potential bugs pointed out by Oliver Neukum.
53  *
54  * (05/30/2001) gkh
55  *      switched from using spinlock to a semaphore, which fixes lots of problems.
56  *
57  * (05/28/2000) gkh
58  *      Added initial support for the Palm m500 and Palm m505 devices.
59  *
60  * (04/08/2001) gb
61  *      Identify version on module load.
62  *
63  * (01/21/2000) gkh
64  *      Added write_room and chars_in_buffer, as they were previously using the
65  *      generic driver versions which is all wrong now that we are using an urb
66  *      pool.  Thanks to Wolfgang Grandegger for pointing this out to me.
67  *      Removed count assignment in the write function, which was not needed anymore
68  *      either.  Thanks to Al Borchers for pointing this out.
69  *
70  * (12/12/2000) gkh
71  *      Moved MOD_DEC to end of visor_close to be nicer, as the final write 
72  *      message can sleep.
73  * 
74  * (11/12/2000) gkh
75  *      Fixed bug with data being dropped on the floor by forcing tty->low_latency
76  *      to be on.  Hopefully this fixes the OHCI issue!
77  *
78  * (11/01/2000) Adam J. Richter
79  *      usb_device_id table support
80  * 
81  * (10/05/2000) gkh
82  *      Fixed bug with urb->dev not being set properly, now that the usb
83  *      core needs it.
84  * 
85  * (09/11/2000) gkh
86  *      Got rid of always calling kmalloc for every urb we wrote out to the
87  *      device.
88  *      Added visor_read_callback so we can keep track of bytes in and out for
89  *      those people who like to know the speed of their device.
90  *      Removed DEBUG #ifdefs with call to usb_serial_debug_data
91  *
92  * (09/06/2000) gkh
93  *      Fixed oops in visor_exit.  Need to uncomment usb_unlink_urb call _after_
94  *      the host controller drivers set urb->dev = NULL when the urb is finished.
95  *
96  * (08/28/2000) gkh
97  *      Added locks for SMP safeness.
98  *
99  * (08/08/2000) gkh
100  *      Fixed endian problem in visor_startup.
101  *      Fixed MOD_INC and MOD_DEC logic and the ability to open a port more 
102  *      than once.
103  * 
104  * (07/23/2000) gkh
105  *      Added pool of write urbs to speed up transfers to the visor.
106  * 
107  * (07/19/2000) gkh
108  *      Added module_init and module_exit functions to handle the fact that this
109  *      driver is a loadable module now.
110  *
111  * (07/03/2000) gkh
112  *      Added visor_set_ioctl and visor_set_termios functions (they don't do much
113  *      of anything, but are good for debugging.)
114  * 
115  * (06/25/2000) gkh
116  *      Fixed bug in visor_unthrottle that should help with the disconnect in PPP
117  *      bug that people have been reporting.
118  *
119  * (06/23/2000) gkh
120  *      Cleaned up debugging statements in a quest to find UHCI timeout bug.
121  *
122  * (04/27/2000) Ryan VanderBijl
123  *      Fixed memory leak in visor_close
124  *
125  * (03/26/2000) gkh
126  *      Split driver up into device specific pieces.
127  * 
128  */
129
130 #include <linux/config.h>
131 #include <linux/kernel.h>
132 #include <linux/sched.h>
133 #include <linux/signal.h>
134 #include <linux/errno.h>
135 #include <linux/poll.h>
136 #include <linux/init.h>
137 #include <linux/slab.h>
138 #include <linux/fcntl.h>
139 #include <linux/tty.h>
140 #include <linux/tty_driver.h>
141 #include <linux/tty_flip.h>
142 #include <linux/module.h>
143 #include <linux/spinlock.h>
144 #include <linux/usb.h>
145
146 #ifdef CONFIG_USB_SERIAL_DEBUG
147         static int debug = 1;
148 #else
149         static int debug;
150 #endif
151
152 #include "usb-serial.h"
153 #include "visor.h"
154
155 /*
156  * Version Information
157  */
158 #define DRIVER_VERSION "v2.0"
159 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>"
160 #define DRIVER_DESC "USB HandSpring Visor, Palm m50x, Sony Clié driver"
161
162 /* function prototypes for a handspring visor */
163 static int  visor_open          (struct usb_serial_port *port, struct file *filp);
164 static void visor_close         (struct usb_serial_port *port, struct file *filp);
165 static int  visor_write         (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);
166 static int  visor_write_room            (struct usb_serial_port *port);
167 static int  visor_chars_in_buffer       (struct usb_serial_port *port);
168 static void visor_throttle      (struct usb_serial_port *port);
169 static void visor_unthrottle    (struct usb_serial_port *port);
170 static int  visor_startup       (struct usb_serial *serial);
171 static void visor_shutdown      (struct usb_serial *serial);
172 static int  visor_ioctl         (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
173 static void visor_set_termios   (struct usb_serial_port *port, struct termios *old_termios);
174 static void visor_write_bulk_callback   (struct urb *urb);
175 static void visor_read_bulk_callback    (struct urb *urb);
176 static int  clie_3_5_startup    (struct usb_serial *serial);
177
178
179 static __devinitdata struct usb_device_id combined_id_table [] = {
180         { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID) },
181         { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID) },
182         { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID) },
183         { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID) },
184         { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID) },
185         { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID) },
186         { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) },
187         { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID) },
188         { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID) },
189         { }                                     /* Terminating entry */
190 };
191
192 static __devinitdata struct usb_device_id clie_id_3_5_table [] = {
193         { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
194         { }                                     /* Terminating entry */
195 };
196
197 static __devinitdata struct usb_device_id id_table [] = {
198         { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) },
199         { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID) },
200         { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID) },
201         { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID) },
202         { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID) },
203         { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID) },
204         { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID) },
205         { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
206         { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID) },
207         { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID) },
208         { }                                     /* Terminating entry */
209 };
210
211 MODULE_DEVICE_TABLE (usb, id_table);
212
213
214
215 /* All of the device info needed for the Handspring Visor, and Palm 4.0 devices */
216 static struct usb_serial_device_type handspring_device = {
217         owner:                  THIS_MODULE,
218         name:                   "Handspring Visor / Palm 4.0 / Clié 4.0",
219         id_table:               combined_id_table,
220         num_interrupt_in:       0,
221         num_bulk_in:            2,
222         num_bulk_out:           2,
223         num_ports:              2,
224         open:                   visor_open,
225         close:                  visor_close,
226         throttle:               visor_throttle,
227         unthrottle:             visor_unthrottle,
228         startup:                visor_startup,
229         shutdown:               visor_shutdown,
230         ioctl:                  visor_ioctl,
231         set_termios:            visor_set_termios,
232         write:                  visor_write,
233         write_room:             visor_write_room,
234         chars_in_buffer:        visor_chars_in_buffer,
235         write_bulk_callback:    visor_write_bulk_callback,
236         read_bulk_callback:     visor_read_bulk_callback,
237 };
238
239 /* device info for the Sony Clie OS version 3.5 */
240 static struct usb_serial_device_type clie_3_5_device = {
241         owner:                  THIS_MODULE,
242         name:                   "Sony Clié 3.5",
243         id_table:               clie_id_3_5_table,
244         num_interrupt_in:       0,
245         num_bulk_in:            1,
246         num_bulk_out:           1,
247         num_ports:              1,
248         open:                   visor_open,
249         close:                  visor_close,
250         throttle:               visor_throttle,
251         unthrottle:             visor_unthrottle,
252         startup:                clie_3_5_startup,
253         ioctl:                  visor_ioctl,
254         set_termios:            visor_set_termios,
255         write:                  visor_write,
256         write_room:             visor_write_room,
257         chars_in_buffer:        visor_chars_in_buffer,
258         write_bulk_callback:    visor_write_bulk_callback,
259         read_bulk_callback:     visor_read_bulk_callback,
260 };
261
262
263 static int bytes_in;
264 static int bytes_out;
265
266
267 /******************************************************************************
268  * Handspring Visor specific driver functions
269  ******************************************************************************/
270 static int visor_open (struct usb_serial_port *port, struct file *filp)
271 {
272         struct usb_serial *serial = port->serial;
273         int result = 0;
274
275         if (port_paranoia_check (port, __FUNCTION__))
276                 return -ENODEV;
277         
278         dbg(__FUNCTION__ " - port %d", port->number);
279
280         if (!port->read_urb) {
281                 /* this is needed for some brain dead Sony devices */
282                 err ("Device lied about number of ports, please use a lower one.");
283                 return -ENODEV;
284         }
285
286         bytes_in = 0;
287         bytes_out = 0;
288
289         /*
290          * Force low_latency on so that our tty_push actually forces the data
291          * through, otherwise it is scheduled, and with high data rates (like
292          * with OHCI) data can get lost.
293          */
294         if (port->tty)
295                 port->tty->low_latency = 1;
296         
297         /* Start reading from the device */
298         usb_fill_bulk_urb (port->read_urb, serial->dev,
299                            usb_rcvbulkpipe (serial->dev, 
300                                             port->bulk_in_endpointAddress),
301                            port->read_urb->transfer_buffer,
302                            port->read_urb->transfer_buffer_length,
303                            visor_read_bulk_callback, port);
304         result = usb_submit_urb(port->read_urb, GFP_KERNEL);
305         if (result)
306                 err(__FUNCTION__ " - failed submitting read urb, error %d", result);
307         
308         return result;
309 }
310
311
312 static void visor_close (struct usb_serial_port *port, struct file * filp)
313 {
314         struct usb_serial *serial;
315         unsigned char *transfer_buffer;
316
317         if (port_paranoia_check (port, __FUNCTION__))
318                 return;
319         
320         dbg(__FUNCTION__ " - port %d", port->number);
321                          
322         serial = get_usb_serial (port, __FUNCTION__);
323         if (!serial)
324                 return;
325         
326         if (serial->dev) {
327                 /* only send a shutdown message if the 
328                  * device is still here */
329                 transfer_buffer =  kmalloc (0x12, GFP_KERNEL);
330                 if (!transfer_buffer) {
331                         err(__FUNCTION__ " - kmalloc(%d) failed.", 0x12);
332                 } else {
333                         /* send a shutdown message to the device */
334                         usb_control_msg (serial->dev,
335                                          usb_rcvctrlpipe(serial->dev, 0),
336                                          VISOR_CLOSE_NOTIFICATION, 0xc2,
337                                          0x0000, 0x0000, 
338                                          transfer_buffer, 0x12, 300);
339                         kfree (transfer_buffer);
340                 }
341                 /* shutdown our bulk read */
342                 usb_unlink_urb (port->read_urb);
343         }
344         /* Uncomment the following line if you want to see some statistics in your syslog */
345         /* info ("Bytes In = %d  Bytes Out = %d", bytes_in, bytes_out); */
346 }
347
348
349 static int visor_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
350 {
351         struct usb_serial *serial = port->serial;
352         struct urb *urb;
353         unsigned char *buffer;
354         int status;
355
356         dbg(__FUNCTION__ " - port %d", port->number);
357
358         buffer = kmalloc (count, GFP_ATOMIC);
359         if (!buffer) {
360                 err ("out of memory");
361                 return -ENOMEM;
362         }
363
364         urb = usb_alloc_urb(0, GFP_ATOMIC);
365         if (!urb) {
366                 err ("no more free urbs");
367                 kfree (buffer);
368                 return -ENOMEM;
369         }
370
371         if (from_user) {
372                 if (copy_from_user (buffer, buf, count)) {
373                         kfree (buffer);
374                         usb_free_urb (urb);
375                         return -EFAULT;
376                 }
377         } else {
378                 memcpy (buffer, buf, count);
379         }
380
381         usb_serial_debug_data (__FILE__, __FUNCTION__, count, buffer);
382
383         usb_fill_bulk_urb (urb, serial->dev,
384                            usb_sndbulkpipe (serial->dev,
385                                             port->bulk_out_endpointAddress),
386                            buffer, count, 
387                            visor_write_bulk_callback, port);
388         urb->transfer_flags |= USB_QUEUE_BULK;
389
390         /* send it down the pipe */
391         status = usb_submit_urb(urb, GFP_ATOMIC);
392         if (status) {
393                 err(__FUNCTION__ " - usb_submit_urb(write bulk) failed with status = %d", status);
394                 count = status;
395         } else {
396                 bytes_out += count;
397         }
398
399         /* we are done with this urb, so let the host driver
400          * really free it when it is finished with it */
401         usb_free_urb (urb);
402
403         return count;
404 }
405
406
407 static int visor_write_room (struct usb_serial_port *port)
408 {
409         dbg(__FUNCTION__ " - port %d", port->number);
410
411         /*
412          * We really can take anything the user throws at us
413          * but let's pick a nice big number to tell the tty
414          * layer that we have lots of free space
415          */
416         return 2048;
417 }
418
419
420 static int visor_chars_in_buffer (struct usb_serial_port *port)
421 {
422         dbg(__FUNCTION__ " - port %d", port->number);
423
424         /* 
425          * We can't really account for how much data we
426          * have sent out, but hasn't made it through to the
427          * device, so just tell the tty layer that everything
428          * is flushed.
429          */
430         return 0;
431 }
432
433
434 static void visor_write_bulk_callback (struct urb *urb)
435 {
436         struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
437
438         if (port_paranoia_check (port, __FUNCTION__))
439                 return;
440         
441         dbg(__FUNCTION__ " - port %d", port->number);
442         
443         if (urb->status) {
444                 dbg(__FUNCTION__ " - nonzero write bulk status received: %d", urb->status);
445                 return;
446         }
447
448         /* free up the transfer buffer, as usb_free_urb() does not do this */
449         kfree (urb->transfer_buffer);
450
451         queue_task(&port->tqueue, &tq_immediate);
452         mark_bh(IMMEDIATE_BH);
453
454         return;
455 }
456
457
458 static void visor_read_bulk_callback (struct urb *urb)
459 {
460         struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
461         struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
462         struct tty_struct *tty;
463         unsigned char *data = urb->transfer_buffer;
464         int i;
465         int result;
466
467         if (port_paranoia_check (port, __FUNCTION__))
468                 return;
469
470         dbg(__FUNCTION__ " - port %d", port->number);
471
472         if (!serial) {
473                 dbg(__FUNCTION__ " - bad serial pointer, exiting");
474                 return;
475         }
476
477         if (urb->status) {
478                 dbg(__FUNCTION__ " - nonzero read bulk status received: %d", urb->status);
479                 return;
480         }
481
482         usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
483
484         tty = port->tty;
485         if (tty && urb->actual_length) {
486                 for (i = 0; i < urb->actual_length ; ++i) {
487                         /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
488                         if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
489                                 tty_flip_buffer_push(tty);
490                         }
491                         /* this doesn't actually push the data through unless tty->low_latency is set */
492                         tty_insert_flip_char(tty, data[i], 0);
493                 }
494                 tty_flip_buffer_push(tty);
495         }
496         bytes_in += urb->actual_length;
497
498         /* Continue trying to always read  */
499         usb_fill_bulk_urb (port->read_urb, serial->dev,
500                            usb_rcvbulkpipe (serial->dev,
501                                             port->bulk_in_endpointAddress),
502                            port->read_urb->transfer_buffer,
503                            port->read_urb->transfer_buffer_length,
504                            visor_read_bulk_callback, port);
505         result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
506         if (result)
507                 err(__FUNCTION__ " - failed resubmitting read urb, error %d", result);
508         return;
509 }
510
511
512 static void visor_throttle (struct usb_serial_port *port)
513 {
514         dbg(__FUNCTION__ " - port %d", port->number);
515         usb_unlink_urb (port->read_urb);
516 }
517
518
519 static void visor_unthrottle (struct usb_serial_port *port)
520 {
521         int result;
522
523         dbg(__FUNCTION__ " - port %d", port->number);
524
525         port->read_urb->dev = port->serial->dev;
526         result = usb_submit_urb(port->read_urb, GFP_ATOMIC);
527         if (result)
528                 err(__FUNCTION__ " - failed submitting read urb, error %d", result);
529 }
530
531
532 static int  visor_startup (struct usb_serial *serial)
533 {
534         int response;
535         int i;
536         unsigned char *transfer_buffer =  kmalloc (256, GFP_KERNEL);
537
538         if (!transfer_buffer) {
539                 err(__FUNCTION__ " - kmalloc(%d) failed.", 256);
540                 return -ENOMEM;
541         }
542
543         dbg(__FUNCTION__);
544
545         dbg(__FUNCTION__ " - Set config to 1");
546         usb_set_configuration (serial->dev, 1);
547
548         /* send a get connection info request */
549         response = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), VISOR_GET_CONNECTION_INFORMATION,
550                                         0xc2, 0x0000, 0x0000, transfer_buffer, 0x12, 300);
551         if (response < 0) {
552                 err(__FUNCTION__ " - error getting connection information");
553         } else {
554                 struct visor_connection_info *connection_info = (struct visor_connection_info *)transfer_buffer;
555                 char *string;
556
557                 le16_to_cpus(&connection_info->num_ports);
558                 info("%s: Number of ports: %d", serial->type->name, connection_info->num_ports);
559                 for (i = 0; i < connection_info->num_ports; ++i) {
560                         switch (connection_info->connections[i].port_function_id) {
561                                 case VISOR_FUNCTION_GENERIC:
562                                         string = "Generic";
563                                         break;
564                                 case VISOR_FUNCTION_DEBUGGER:
565                                         string = "Debugger";
566                                         break;
567                                 case VISOR_FUNCTION_HOTSYNC:
568                                         string = "HotSync";
569                                         break;
570                                 case VISOR_FUNCTION_CONSOLE:
571                                         string = "Console";
572                                         break;
573                                 case VISOR_FUNCTION_REMOTE_FILE_SYS:
574                                         string = "Remote File System";
575                                         break;
576                                 default:
577                                         string = "unknown";
578                                         break;  
579                         }
580                         info("%s: port %d, is for %s use and is bound to ttyUSB%d", serial->type->name, connection_info->connections[i].port, string, serial->minor + i);
581                 }
582         }
583
584         if ((serial->dev->descriptor.idVendor == PALM_VENDOR_ID) ||
585             (serial->dev->descriptor.idVendor == SONY_VENDOR_ID)) {
586                 /* Palm OS 4.0 Hack */
587                 response = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), 
588                                             PALM_GET_SOME_UNKNOWN_INFORMATION,
589                                             0xc2, 0x0000, 0x0000, transfer_buffer, 
590                                             0x14, 300);
591                 if (response < 0) {
592                         err(__FUNCTION__ " - error getting first unknown palm command");
593                 } else {
594                         usb_serial_debug_data (__FILE__, __FUNCTION__, 0x14, transfer_buffer);
595                 }
596                 response = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), 
597                                             PALM_GET_SOME_UNKNOWN_INFORMATION,
598                                             0xc2, 0x0000, 0x0000, transfer_buffer, 
599                                             0x14, 300);
600                 if (response < 0) {
601                         err(__FUNCTION__ " - error getting second unknown palm command");
602                 } else {
603                         usb_serial_debug_data (__FILE__, __FUNCTION__, 0x14, transfer_buffer);
604                 }
605         }
606
607         /* ask for the number of bytes available, but ignore the response as it is broken */
608         response = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), VISOR_REQUEST_BYTES_AVAILABLE,
609                                         0xc2, 0x0000, 0x0005, transfer_buffer, 0x02, 300);
610         if (response < 0) {
611                 err(__FUNCTION__ " - error getting bytes available request");
612         }
613
614         kfree (transfer_buffer);
615
616         /* continue on with initialization */
617         return 0;
618 }
619
620 static int clie_3_5_startup (struct usb_serial *serial)
621 {
622         int result;
623         u8 data;
624
625         dbg(__FUNCTION__);
626
627         /*
628          * Note that PEG-300 series devices expect the following two calls.
629          */
630
631         /* get the config number */
632         result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),
633                                   USB_REQ_GET_CONFIGURATION, USB_DIR_IN,
634                                   0, 0, &data, 1, HZ * 3);
635         if (result < 0) {
636                 err(__FUNCTION__ ": get config number failed: %d", result);
637                 return result;
638         }
639         if (result != 1) {
640                 err(__FUNCTION__ ": get config number bad return length: %d", result);
641                 return -EIO;
642         }
643
644         /* get the interface number */
645         result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),
646                                   USB_REQ_GET_INTERFACE, 
647                                   USB_DIR_IN | USB_DT_DEVICE,
648                                   0, 0, &data, 1, HZ * 3);
649         if (result < 0) {
650                 err(__FUNCTION__ ": get interface number failed: %d", result);
651                 return result;
652         }
653         if (result != 1) {
654                 err(__FUNCTION__ ": get interface number bad return length: %d", result);
655                 return -EIO;
656         }
657
658         return 0;
659 }
660
661 static void visor_shutdown (struct usb_serial *serial)
662 {
663         dbg (__FUNCTION__);
664 }
665
666 static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
667 {
668         dbg(__FUNCTION__ " - port %d, cmd 0x%.4x", port->number, cmd);
669
670         return -ENOIOCTLCMD;
671 }
672
673
674 /* This function is all nice and good, but we don't change anything based on it :) */
675 static void visor_set_termios (struct usb_serial_port *port, struct termios *old_termios)
676 {
677         unsigned int cflag;
678
679         dbg(__FUNCTION__ " - port %d", port->number);
680
681         if ((!port->tty) || (!port->tty->termios)) {
682                 dbg(__FUNCTION__" - no tty structures");
683                 return;
684         }
685
686         cflag = port->tty->termios->c_cflag;
687         /* check that they really want us to change something */
688         if (old_termios) {
689                 if ((cflag == old_termios->c_cflag) &&
690                     (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
691                         dbg(__FUNCTION__ " - nothing to change...");
692                         return;
693                 }
694         }
695
696         /* get the byte size */
697         switch (cflag & CSIZE) {
698                 case CS5:       dbg(__FUNCTION__ " - data bits = 5");   break;
699                 case CS6:       dbg(__FUNCTION__ " - data bits = 6");   break;
700                 case CS7:       dbg(__FUNCTION__ " - data bits = 7");   break;
701                 default:
702                 case CS8:       dbg(__FUNCTION__ " - data bits = 8");   break;
703         }
704         
705         /* determine the parity */
706         if (cflag & PARENB)
707                 if (cflag & PARODD)
708                         dbg(__FUNCTION__ " - parity = odd");
709                 else
710                         dbg(__FUNCTION__ " - parity = even");
711         else
712                 dbg(__FUNCTION__ " - parity = none");
713
714         /* figure out the stop bits requested */
715         if (cflag & CSTOPB)
716                 dbg(__FUNCTION__ " - stop bits = 2");
717         else
718                 dbg(__FUNCTION__ " - stop bits = 1");
719
720         
721         /* figure out the flow control settings */
722         if (cflag & CRTSCTS)
723                 dbg(__FUNCTION__ " - RTS/CTS is enabled");
724         else
725                 dbg(__FUNCTION__ " - RTS/CTS is disabled");
726         
727         /* determine software flow control */
728         if (I_IXOFF(port->tty))
729                 dbg(__FUNCTION__ " - XON/XOFF is enabled, XON = %2x, XOFF = %2x", START_CHAR(port->tty), STOP_CHAR(port->tty));
730         else
731                 dbg(__FUNCTION__ " - XON/XOFF is disabled");
732
733         /* get the baud rate wanted */
734         dbg(__FUNCTION__ " - baud rate = %d", tty_get_baud_rate(port->tty));
735
736         return;
737 }
738
739
740 static int __init visor_init (void)
741 {
742         usb_serial_register (&handspring_device);
743         usb_serial_register (&clie_3_5_device);
744         info(DRIVER_DESC " " DRIVER_VERSION);
745
746         return 0;
747 }
748
749
750 static void __exit visor_exit (void)
751 {
752         usb_serial_deregister (&handspring_device);
753         usb_serial_deregister (&clie_3_5_device);
754 }
755
756
757 module_init(visor_init);
758 module_exit(visor_exit);
759
760 MODULE_AUTHOR( DRIVER_AUTHOR );
761 MODULE_DESCRIPTION( DRIVER_DESC );
762 MODULE_LICENSE("GPL");
763
764 MODULE_PARM(debug, "i");
765 MODULE_PARM_DESC(debug, "Debug enabled or not");
766