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