2 * USB HandSpring Visor, Palm m50x, and Sony Clie driver
3 * (supports all of the Palm OS USB devices)
5 * Copyright (C) 1999 - 2003
6 * Greg Kroah-Hartman (greg@kroah.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 * (06/03/2003) Judd Montgomery <judd at jpilot.org>
16 * Added support for module parameter options for untested/unknown
20 * Added support for the Sony Clie NZ90V device. Thanks to Martin Brachtl
21 * <brachtl@redgrep.cz> for the information.
23 * (3/07/2003) Adam Pennington <adamp@coed.org>
24 * Backported version 2.1 of the driver from the 2.5 bitkeeper tree
25 * making Treo actually work.
27 * (2/18/2003) Adam Powell <hazelsct at debian.org>
28 * Backported 2.5 driver mods to support Handspring Treo.
30 * (2/11/2003) Adam Powell <hazelsct at debian.org>
31 * Added device and vendor ids for the Samsung I330 phone.
34 * Added support for the Sony OS 4.1 devices. Thanks to Hiroyuki ARAKI
35 * <hiro@zob.ne.jp> for the information.
38 * Added support for the Palm i705 device, thanks to Thomas Riemer
39 * <tom@netmech.com> for the information.
42 * Added support for the Palm m130 device, thanks to Udo Eisenbarth
43 * <udo.eisenbarth@web.de> for the information.
46 * Added support for the Palm m515 devices.
49 * Added support for the Clie S-360 device.
52 * Added better Clie support for 3.5 devices. Thanks to Geoffrey Levand
56 * Added support for the m125 devices, and added check to prevent oopses
57 * for CliƩ devices that lie about the number of ports they have.
60 * Added support for the Clie devices, both the 3.5 and 4.0 os versions.
61 * Many thanks to Daniel Burke, and Bryan Payne for helping with this.
64 * fixed a few potential bugs pointed out by Oliver Neukum.
67 * switched from using spinlock to a semaphore, which fixes lots of problems.
70 * Added initial support for the Palm m500 and Palm m505 devices.
73 * Identify version on module load.
76 * Added write_room and chars_in_buffer, as they were previously using the
77 * generic driver versions which is all wrong now that we are using an urb
78 * pool. Thanks to Wolfgang Grandegger for pointing this out to me.
79 * Removed count assignment in the write function, which was not needed anymore
80 * either. Thanks to Al Borchers for pointing this out.
83 * Moved MOD_DEC to end of visor_close to be nicer, as the final write
87 * Fixed bug with data being dropped on the floor by forcing tty->low_latency
88 * to be on. Hopefully this fixes the OHCI issue!
90 * (11/01/2000) Adam J. Richter
91 * usb_device_id table support
94 * Fixed bug with urb->dev not being set properly, now that the usb
98 * Got rid of always calling kmalloc for every urb we wrote out to the
100 * Added visor_read_callback so we can keep track of bytes in and out for
101 * those people who like to know the speed of their device.
102 * Removed DEBUG #ifdefs with call to usb_serial_debug_data
105 * Fixed oops in visor_exit. Need to uncomment usb_unlink_urb call _after_
106 * the host controller drivers set urb->dev = NULL when the urb is finished.
109 * Added locks for SMP safeness.
112 * Fixed endian problem in visor_startup.
113 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
117 * Added pool of write urbs to speed up transfers to the visor.
120 * Added module_init and module_exit functions to handle the fact that this
121 * driver is a loadable module now.
124 * Added visor_set_ioctl and visor_set_termios functions (they don't do much
125 * of anything, but are good for debugging.)
128 * Fixed bug in visor_unthrottle that should help with the disconnect in PPP
129 * bug that people have been reporting.
132 * Cleaned up debugging statements in a quest to find UHCI timeout bug.
134 * (04/27/2000) Ryan VanderBijl
135 * Fixed memory leak in visor_close
138 * Split driver up into device specific pieces.
142 #include <linux/config.h>
143 #include <linux/kernel.h>
144 #include <linux/errno.h>
145 #include <linux/init.h>
146 #include <linux/slab.h>
147 #include <linux/tty.h>
148 #include <linux/tty_driver.h>
149 #include <linux/tty_flip.h>
150 #include <linux/module.h>
151 #include <linux/spinlock.h>
152 #include <asm/uaccess.h>
153 #include <linux/usb.h>
155 #ifdef CONFIG_USB_SERIAL_DEBUG
156 static int debug = 1;
161 #include "usb-serial.h"
165 * Version Information
167 #define DRIVER_VERSION "v1.7"
168 #define DRIVER_AUTHOR "Greg Kroah-Hartman <greg@kroah.com>"
169 #define DRIVER_DESC "USB HandSpring Visor, Palm m50x, Treo, Sony CliƩ driver"
171 /* function prototypes for a handspring visor */
172 static int visor_open (struct usb_serial_port *port, struct file *filp);
173 static void visor_close (struct usb_serial_port *port, struct file *filp);
174 static int visor_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);
175 static int visor_write_room (struct usb_serial_port *port);
176 static int visor_chars_in_buffer (struct usb_serial_port *port);
177 static void visor_throttle (struct usb_serial_port *port);
178 static void visor_unthrottle (struct usb_serial_port *port);
179 static int visor_startup (struct usb_serial *serial);
180 static void visor_shutdown (struct usb_serial *serial);
181 static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg);
182 static void visor_set_termios (struct usb_serial_port *port, struct termios *old_termios);
183 static void visor_write_bulk_callback (struct urb *urb);
184 static void visor_read_bulk_callback (struct urb *urb);
185 static void visor_read_int_callback (struct urb *urb);
186 static int clie_3_5_startup (struct usb_serial *serial);
187 static int clie_5_startup (struct usb_serial *serial);
188 static void treo_attach (struct usb_serial *serial);
190 /* Parameters that may be passed into the module. */
191 static int vendor = -1;
192 static int product = -1;
193 static int param_register;
196 static struct usb_device_id id_table [] = {
197 { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) },
198 { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID) },
199 { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID) },
200 { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID) },
201 { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID) },
202 { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID) },
203 { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID) },
204 { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID) },
205 { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID) },
206 { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID) },
207 { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID) },
208 { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID) },
209 { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE31_ID) },
210 { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID) },
211 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID) },
212 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID) },
213 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID) },
214 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID) },
215 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID) },
216 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID) },
217 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID) },
218 { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID) },
219 { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID) },
220 { } /* Terminating entry */
223 static struct usb_device_id clie_id_3_5_table [] = {
224 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
225 { } /* Terminating entry */
229 static struct usb_device_id clie_id_5_table [] = {
230 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID) },
231 { } /* Terminating entry */
234 static __devinitdata struct usb_device_id id_table_combined [] = {
235 { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_VISOR_ID) },
236 { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO_ID) },
237 { USB_DEVICE(HANDSPRING_VENDOR_ID, HANDSPRING_TREO600_ID) },
238 { USB_DEVICE(PALM_VENDOR_ID, PALM_M500_ID) },
239 { USB_DEVICE(PALM_VENDOR_ID, PALM_M505_ID) },
240 { USB_DEVICE(PALM_VENDOR_ID, PALM_M515_ID) },
241 { USB_DEVICE(PALM_VENDOR_ID, PALM_I705_ID) },
242 { USB_DEVICE(PALM_VENDOR_ID, PALM_M100_ID) },
243 { USB_DEVICE(PALM_VENDOR_ID, PALM_M125_ID) },
244 { USB_DEVICE(PALM_VENDOR_ID, PALM_M130_ID) },
245 { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_T_ID) },
246 { USB_DEVICE(PALM_VENDOR_ID, PALM_TUNGSTEN_Z_ID) },
247 { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE31_ID) },
248 { USB_DEVICE(PALM_VENDOR_ID, PALM_ZIRE_ID) },
249 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_3_5_ID) },
250 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_0_ID) },
251 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_S360_ID) },
252 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_4_1_ID) },
253 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NX60_ID) },
254 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_NZ90V_ID) },
255 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_UX50_ID) },
256 { USB_DEVICE(SONY_VENDOR_ID, SONY_CLIE_TJ25_ID) },
257 { USB_DEVICE(SAMSUNG_VENDOR_ID, SAMSUNG_SCH_I330_ID) },
258 { USB_DEVICE(GARMIN_VENDOR_ID, GARMIN_IQUE_3600_ID) },
259 { USB_DEVICE(ACEECA_VENDOR_ID, ACEECA_MEZ1000_ID) },
260 { } /* Terminating entry */
263 /* For passed in parameters */
264 static struct usb_device_id id_param_table [] = {
266 { } /* Terminating entry */
269 MODULE_DEVICE_TABLE (usb, id_table_combined);
273 /* All of the device info needed for the Handspring Visor, and Palm 4.0 devices */
274 static struct usb_serial_device_type handspring_device = {
275 .owner = THIS_MODULE,
276 .name = "Handspring Visor / Treo / Palm 4.0 / CliƩ 4.x",
277 .id_table = id_table,
278 .num_interrupt_in = NUM_DONT_CARE,
283 .close = visor_close,
284 .throttle = visor_throttle,
285 .unthrottle = visor_unthrottle,
286 .startup = visor_startup,
287 .shutdown = visor_shutdown,
288 .ioctl = visor_ioctl,
289 .set_termios = visor_set_termios,
290 .write = visor_write,
291 .write_room = visor_write_room,
292 .chars_in_buffer = visor_chars_in_buffer,
293 .write_bulk_callback = visor_write_bulk_callback,
294 .read_bulk_callback = visor_read_bulk_callback,
295 .read_int_callback = visor_read_int_callback,
298 /* device info for the Sony Clie OS version 3.5 */
299 static struct usb_serial_device_type clie_3_5_device = {
300 .owner = THIS_MODULE,
301 .name = "Sony CliƩ 3.5",
302 .id_table = clie_id_3_5_table,
303 .num_interrupt_in = 0,
308 .close = visor_close,
309 .throttle = visor_throttle,
310 .unthrottle = visor_unthrottle,
311 .startup = clie_3_5_startup,
312 .ioctl = visor_ioctl,
313 .set_termios = visor_set_termios,
314 .write = visor_write,
315 .write_room = visor_write_room,
316 .chars_in_buffer = visor_chars_in_buffer,
317 .write_bulk_callback = visor_write_bulk_callback,
318 .read_bulk_callback = visor_read_bulk_callback,
322 /* device info for the Sony Clie OS version 5.0 */
323 static struct usb_serial_device_type clie_5_device = {
324 .owner = THIS_MODULE,
325 .name = "Sony CliƩ 5.0",
326 .id_table = clie_id_5_table,
327 .num_interrupt_in = NUM_DONT_CARE,
332 .close = visor_close,
333 .throttle = visor_throttle,
334 .unthrottle = visor_unthrottle,
335 .startup = clie_5_startup,
336 .shutdown = visor_shutdown,
337 .ioctl = visor_ioctl,
338 .set_termios = visor_set_termios,
339 .write = visor_write,
340 .write_room = visor_write_room,
341 .chars_in_buffer = visor_chars_in_buffer,
342 .write_bulk_callback = visor_write_bulk_callback,
343 .read_bulk_callback = visor_read_bulk_callback,
344 .read_int_callback = visor_read_int_callback,
347 /* This structure is for Handspring Visor, and Palm 4.0 devices that are not
348 * compiled into the kernel, but can be passed in when the module is loaded.
349 * This will allow the visor driver to work with new Vendor and Device IDs
350 * without recompiling the driver.
352 static struct usb_serial_device_type param_device = {
353 .owner = THIS_MODULE,
354 .name = "user specified device with Palm 4.x protocols",
355 .id_table = id_param_table,
356 .num_interrupt_in = NUM_DONT_CARE,
361 .close = visor_close,
362 .throttle = visor_throttle,
363 .unthrottle = visor_unthrottle,
364 .startup = visor_startup,
365 .shutdown = visor_shutdown,
366 .ioctl = visor_ioctl,
367 .set_termios = visor_set_termios,
368 .write = visor_write,
369 .write_room = visor_write_room,
370 .chars_in_buffer = visor_chars_in_buffer,
371 .write_bulk_callback = visor_write_bulk_callback,
372 .read_bulk_callback = visor_read_bulk_callback,
373 .read_int_callback = visor_read_int_callback,
377 #define URB_TRANSFER_BUFFER_SIZE 768
378 static struct urb *write_urb_pool[NUM_URBS];
379 static spinlock_t write_urb_pool_lock;
381 static int bytes_out;
384 /******************************************************************************
385 * Handspring Visor specific driver functions
386 ******************************************************************************/
387 static int visor_open (struct usb_serial_port *port, struct file *filp)
389 struct usb_serial *serial = port->serial;
392 if (port_paranoia_check (port, __FUNCTION__))
395 dbg("%s - port %d", __FUNCTION__, port->number);
397 if (!port->read_urb) {
398 /* this is needed for some brain dead Sony devices */
399 err ("Device lied about number of ports, please use a lower one.");
407 * Force low_latency on so that our tty_push actually forces the data
408 * through, otherwise it is scheduled, and with high data rates (like
409 * with OHCI) data can get lost.
412 port->tty->low_latency = 1;
414 /* Start reading from the device */
415 usb_fill_bulk_urb (port->read_urb, serial->dev,
416 usb_rcvbulkpipe (serial->dev,
417 port->bulk_in_endpointAddress),
418 port->read_urb->transfer_buffer,
419 port->read_urb->transfer_buffer_length,
420 visor_read_bulk_callback, port);
421 result = usb_submit_urb(port->read_urb);
423 err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
427 if (port->interrupt_in_urb) {
428 dbg("%s - adding interrupt input for treo", __FUNCTION__);
429 result = usb_submit_urb(port->interrupt_in_urb);
431 err("%s - failed submitting interrupt urb, error %d\n",
432 __FUNCTION__, result);
439 static void visor_close (struct usb_serial_port *port, struct file * filp)
441 struct usb_serial *serial;
442 unsigned char *transfer_buffer;
444 if (port_paranoia_check (port, __FUNCTION__))
447 dbg("%s - port %d", __FUNCTION__, port->number);
449 serial = get_usb_serial (port, __FUNCTION__);
457 /* only send a shutdown message if the
458 * device is still here */
459 transfer_buffer = kmalloc (0x12, GFP_KERNEL);
460 if (!transfer_buffer) {
461 err("%s - kmalloc(%d) failed.", __FUNCTION__, 0x12);
463 /* send a shutdown message to the device */
464 usb_control_msg (serial->dev,
465 usb_rcvctrlpipe(serial->dev, 0),
466 VISOR_CLOSE_NOTIFICATION, 0xc2,
468 transfer_buffer, 0x12, 300);
469 kfree (transfer_buffer);
472 /* shutdown our urbs */
473 usb_unlink_urb (port->read_urb);
474 if (port->interrupt_in_urb)
475 usb_unlink_urb (port->interrupt_in_urb);
476 /* Try to send shutdown message, if the device is gone, this will just fail. */
477 transfer_buffer = kmalloc (0x12, GFP_KERNEL);
478 if (transfer_buffer) {
479 usb_control_msg (serial->dev,
480 usb_rcvctrlpipe(serial->dev, 0),
481 VISOR_CLOSE_NOTIFICATION, 0xc2,
483 transfer_buffer, 0x12, 300);
484 kfree (transfer_buffer);
488 /* Uncomment the following line if you want to see some statistics in your syslog */
489 info ("Bytes In = %d Bytes Out = %d", bytes_in, bytes_out);
493 static int visor_write (struct usb_serial_port *port, int from_user, const unsigned char *buf, int count)
495 struct usb_serial *serial = port->serial;
497 const unsigned char *current_position = buf;
504 dbg("%s - port %d", __FUNCTION__, port->number);
507 /* try to find a free urb in our list of them */
509 spin_lock_irqsave (&write_urb_pool_lock, flags);
510 for (i = 0; i < NUM_URBS; ++i) {
511 if (write_urb_pool[i]->status != -EINPROGRESS) {
512 urb = write_urb_pool[i];
516 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
518 dbg("%s - no more free urbs", __FUNCTION__);
521 if (urb->transfer_buffer == NULL) {
522 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
523 if (urb->transfer_buffer == NULL) {
524 err("%s no more kernel memory...", __FUNCTION__);
529 transfer_size = min (count, URB_TRANSFER_BUFFER_SIZE);
531 if (copy_from_user (urb->transfer_buffer, current_position, transfer_size)) {
532 bytes_sent = -EFAULT;
536 memcpy (urb->transfer_buffer, current_position, transfer_size);
539 usb_serial_debug_data (__FILE__, __FUNCTION__, transfer_size, urb->transfer_buffer);
541 /* build up our urb */
542 FILL_BULK_URB (urb, serial->dev, usb_sndbulkpipe(serial->dev, port->bulk_out_endpointAddress),
543 urb->transfer_buffer, transfer_size, visor_write_bulk_callback, port);
544 urb->transfer_flags |= USB_QUEUE_BULK;
546 /* send it down the pipe */
547 status = usb_submit_urb(urb);
549 err("%s - usb_submit_urb(write bulk) failed with status = %d", __FUNCTION__, status);
554 current_position += transfer_size;
555 bytes_sent += transfer_size;
556 count -= transfer_size;
557 bytes_out += transfer_size;
565 static int visor_write_room (struct usb_serial_port *port)
571 dbg("%s - port %d", __FUNCTION__, port->number);
573 spin_lock_irqsave (&write_urb_pool_lock, flags);
575 for (i = 0; i < NUM_URBS; ++i) {
576 if (write_urb_pool[i]->status != -EINPROGRESS) {
577 room += URB_TRANSFER_BUFFER_SIZE;
581 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
583 dbg("%s - returns %d", __FUNCTION__, room);
588 static int visor_chars_in_buffer (struct usb_serial_port *port)
594 dbg("%s - port %d", __FUNCTION__, port->number);
596 spin_lock_irqsave (&write_urb_pool_lock, flags);
598 for (i = 0; i < NUM_URBS; ++i) {
599 if (write_urb_pool[i]->status == -EINPROGRESS) {
600 chars += URB_TRANSFER_BUFFER_SIZE;
604 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
606 dbg("%s - returns %d", __FUNCTION__, chars);
611 static void visor_write_bulk_callback (struct urb *urb)
613 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
615 if (port_paranoia_check (port, __FUNCTION__))
618 dbg("%s - port %d", __FUNCTION__, port->number);
621 dbg("%s - nonzero write bulk status received: %d", __FUNCTION__, urb->status);
625 queue_task(&port->tqueue, &tq_immediate);
626 mark_bh(IMMEDIATE_BH);
632 static void visor_read_bulk_callback (struct urb *urb)
634 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
635 struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
636 struct tty_struct *tty;
637 unsigned char *data = urb->transfer_buffer;
641 if (port_paranoia_check (port, __FUNCTION__))
644 dbg("%s - port %d", __FUNCTION__, port->number);
647 dbg("%s - bad serial pointer, exiting", __FUNCTION__);
652 dbg("%s - nonzero read bulk status received: %d", __FUNCTION__, urb->status);
656 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length, data);
659 if (tty && urb->actual_length) {
660 for (i = 0; i < urb->actual_length ; ++i) {
661 /* if we insert more than TTY_FLIPBUF_SIZE characters, we drop them. */
662 if(tty->flip.count >= TTY_FLIPBUF_SIZE) {
663 tty_flip_buffer_push(tty);
665 /* this doesn't actually push the data through unless tty->low_latency is set */
666 tty_insert_flip_char(tty, data[i], 0);
668 tty_flip_buffer_push(tty);
669 bytes_in += urb->actual_length;
672 /* Continue trying to always read */
673 usb_fill_bulk_urb (port->read_urb, serial->dev,
674 usb_rcvbulkpipe (serial->dev,
675 port->bulk_in_endpointAddress),
676 port->read_urb->transfer_buffer,
677 port->read_urb->transfer_buffer_length,
678 visor_read_bulk_callback, port);
679 result = usb_submit_urb(port->read_urb);
681 err("%s - failed resubmitting read urb, error %d", __FUNCTION__, result);
686 static void visor_read_int_callback (struct urb *urb)
688 switch (urb->status) {
695 /* this urb is terminated, clean up */
696 dbg("%s - urb shutting down with status: %d",
697 __FUNCTION__, urb->status);
700 dbg("%s - nonzero urb status received: %d",
701 __FUNCTION__, urb->status);
706 * This information is still unknown what it can be used for.
707 * If anyone has an idea, please let the author know...
709 * Rumor has it this endpoint is used to notify when data
710 * is ready to be read from the bulk ones.
712 usb_serial_debug_data (__FILE__, __FUNCTION__, urb->actual_length,
713 urb->transfer_buffer);
720 static void visor_throttle (struct usb_serial_port *port)
722 dbg("%s - port %d", __FUNCTION__, port->number);
723 usb_unlink_urb (port->read_urb);
727 static void visor_unthrottle (struct usb_serial_port *port)
731 dbg("%s - port %d", __FUNCTION__, port->number);
733 port->read_urb->dev = port->serial->dev;
734 result = usb_submit_urb(port->read_urb);
736 err("%s - failed submitting read urb, error %d", __FUNCTION__, result);
739 static int visor_startup (struct usb_serial *serial)
743 unsigned char *transfer_buffer;
745 dbg("%s", __FUNCTION__);
747 dbg("%s - Set config to 1", __FUNCTION__);
748 usb_set_configuration (serial->dev, 1);
750 if ((serial->dev->descriptor.idVendor == HANDSPRING_VENDOR_ID) &&
751 (serial->dev->descriptor.idProduct == HANDSPRING_VISOR_ID)) {
752 struct visor_connection_info *connection_info;
756 transfer_buffer = kmalloc (sizeof (*connection_info),
758 if (!transfer_buffer) {
759 err("%s - kmalloc(%d) failed.", __FUNCTION__,
760 sizeof (*connection_info));
764 /* send a get connection info request */
765 response = usb_control_msg (serial->dev,
766 usb_rcvctrlpipe(serial->dev, 0),
767 VISOR_GET_CONNECTION_INFORMATION,
768 0xc2, 0x0000, 0x0000,
770 sizeof (*connection_info), 300);
772 err("%s - error getting connection information",
777 connection_info = (struct visor_connection_info *)transfer_buffer;
778 le16_to_cpus(&connection_info->num_ports);
779 num_ports = connection_info->num_ports;
781 /* handle devices that report invalid stuff here */
784 info("%s: Number of ports: %d", serial->type->name, connection_info->num_ports);
785 for (i = 0; i < num_ports; ++i) {
786 switch (connection_info->connections[i].port_function_id) {
787 case VISOR_FUNCTION_GENERIC:
790 case VISOR_FUNCTION_DEBUGGER:
793 case VISOR_FUNCTION_HOTSYNC:
796 case VISOR_FUNCTION_CONSOLE:
799 case VISOR_FUNCTION_REMOTE_FILE_SYS:
800 string = "Remote File System";
806 info("%s: port %d, is for %s use and is bound to ttyUSB%d", serial->type->name,
807 connection_info->connections[i].port, string, serial->minor + i);
810 struct palm_ext_connection_info *connection_info;
812 transfer_buffer = kmalloc (sizeof (*connection_info),
814 if (!transfer_buffer) {
815 err("%s - kmalloc(%d) failed.", __FUNCTION__,
816 sizeof (*connection_info));
820 response = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),
821 PALM_GET_EXT_CONNECTION_INFORMATION,
822 0xc2, 0x0000, 0x0000, transfer_buffer,
823 sizeof (*connection_info), 300);
825 err("%s - error %d getting connection info",
826 __FUNCTION__, response);
828 usb_serial_debug_data (__FILE__, __FUNCTION__, 0x14, transfer_buffer);
832 /* Do our horrible Treo hack, if we should */
835 /* ask for the number of bytes available, but ignore the response as it is broken */
836 response = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0), VISOR_REQUEST_BYTES_AVAILABLE,
837 0xc2, 0x0000, 0x0005, transfer_buffer, 0x02, 300);
839 err("%s - error getting bytes available request", __FUNCTION__);
843 kfree (transfer_buffer);
845 /* continue on with initialization */
849 static int clie_3_5_startup (struct usb_serial *serial)
854 dbg("%s", __FUNCTION__);
857 * Note that PEG-300 series devices expect the following two calls.
860 /* get the config number */
861 result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),
862 USB_REQ_GET_CONFIGURATION, USB_DIR_IN,
863 0, 0, &data, 1, HZ * 3);
865 err("%s: get config number failed: %d", __FUNCTION__, result);
869 err("%s: get config number bad return length: %d", __FUNCTION__, result);
873 /* get the interface number */
874 result = usb_control_msg (serial->dev, usb_rcvctrlpipe(serial->dev, 0),
875 USB_REQ_GET_INTERFACE,
876 USB_DIR_IN | USB_DT_DEVICE,
877 0, 0, &data, 1, HZ * 3);
879 err("%s: get interface number failed: %d", __FUNCTION__, result);
883 err("%s: get interface number bad return length: %d", __FUNCTION__, result);
891 static int clie_5_startup (struct usb_serial *serial)
894 unsigned char *transfer_buffer;
895 struct palm_ext_connection_info *connection_info;
897 dbg("%s", __FUNCTION__);
899 dbg("%s - Set config to 1", __FUNCTION__);
900 usb_set_configuration(serial->dev, 1);
902 transfer_buffer = kmalloc(sizeof (*connection_info),
904 if (!transfer_buffer) {
905 err("%s - kmalloc(%d) failed.", __FUNCTION__,
906 sizeof (*connection_info));
910 response = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
911 PALM_GET_EXT_CONNECTION_INFORMATION,
912 0xc2, 0x0000, 0x0000, transfer_buffer,
913 sizeof(*connection_info), 300);
915 err("%s - error %d getting connection info",
916 __FUNCTION__, response);
918 usb_serial_debug_data (__FILE__, __FUNCTION__, 0x14, transfer_buffer);
921 /* ask for the number of bytes available, but ignore the response as it is broken */
922 response = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), VISOR_REQUEST_BYTES_AVAILABLE,
923 0xc2, 0x0000, 0x0005, transfer_buffer, 0x02, 300);
925 err("%s - error getting bytes available request", __FUNCTION__);
928 kfree (transfer_buffer);
930 /* UX50/TH55 registers 2 ports.
931 Communication in from the TH55 uses bulk_in_endpointAddress from port 0
932 Communication out to the TH55 uses bulk_out_endpointAddress from port 1
934 Lets do a quick and dirty mapping
937 /* some sanity check */
938 if (serial->num_ports < 2)
941 /* port 0 now uses the modified endpoint Address */
942 serial->port[0].bulk_out_endpointAddress = serial->port[1].bulk_out_endpointAddress;
944 /* continue on with initialization */
951 static void treo_attach (struct usb_serial *serial)
953 struct usb_serial_port *port;
956 /* Only do this endpoint hack for the Handspring devices with
957 * interrupt in endpoints, which for now are the Treo devices. */
958 if ((serial->dev->descriptor.idVendor != HANDSPRING_VENDOR_ID) ||
959 (serial->num_interrupt_in == 0))
962 dbg("%s", __FUNCTION__);
964 /* Ok, this is pretty ugly, but these devices want to use the
965 * interrupt endpoint as paired up with a bulk endpoint for a
966 * "virtual serial port". So let's force the endpoints to be
967 * where we want them to be. */
968 for (i = serial->num_bulk_in; i < serial->num_ports; ++i) {
969 port = &serial->port[i];
970 port->read_urb = serial->port[0].read_urb;
971 port->bulk_in_endpointAddress = serial->port[0].bulk_in_endpointAddress;
972 port->bulk_in_buffer = serial->port[0].bulk_in_buffer;
975 for (i = serial->num_bulk_out; i < serial->num_ports; ++i) {
976 port = &serial->port[i];
977 port->write_urb = serial->port[0].write_urb;
978 port->bulk_out_size = serial->port[0].bulk_out_size;
979 port->bulk_out_endpointAddress = serial->port[0].bulk_out_endpointAddress;
980 port->bulk_out_buffer = serial->port[0].bulk_out_buffer;
983 for (i = serial->num_interrupt_in; i < serial->num_ports; ++i) {
984 port = &serial->port[i];
985 port->interrupt_in_urb = serial->port[0].interrupt_in_urb;
986 port->interrupt_in_endpointAddress = serial->port[0].interrupt_in_endpointAddress;
987 port->interrupt_in_buffer = serial->port[0].interrupt_in_buffer;
991 static void visor_shutdown (struct usb_serial *serial)
993 dbg("%s", __FUNCTION__);
996 static int visor_ioctl (struct usb_serial_port *port, struct file * file, unsigned int cmd, unsigned long arg)
998 dbg("%s - port %d, cmd 0x%.4x", __FUNCTION__, port->number, cmd);
1000 return -ENOIOCTLCMD;
1004 /* This function is all nice and good, but we don't change anything based on it :) */
1005 static void visor_set_termios (struct usb_serial_port *port, struct termios *old_termios)
1009 dbg("%s - port %d", __FUNCTION__, port->number);
1011 if ((!port->tty) || (!port->tty->termios)) {
1012 dbg("%s - no tty structures", __FUNCTION__);
1016 cflag = port->tty->termios->c_cflag;
1017 /* check that they really want us to change something */
1019 if ((cflag == old_termios->c_cflag) &&
1020 (RELEVANT_IFLAG(port->tty->termios->c_iflag) == RELEVANT_IFLAG(old_termios->c_iflag))) {
1021 dbg("%s - nothing to change...", __FUNCTION__);
1026 /* get the byte size */
1027 switch (cflag & CSIZE) {
1028 case CS5: dbg("%s - data bits = 5", __FUNCTION__); break;
1029 case CS6: dbg("%s - data bits = 6", __FUNCTION__); break;
1030 case CS7: dbg("%s - data bits = 7", __FUNCTION__); break;
1032 case CS8: dbg("%s - data bits = 8", __FUNCTION__); break;
1035 /* determine the parity */
1038 dbg("%s - parity = odd", __FUNCTION__);
1040 dbg("%s - parity = even", __FUNCTION__);
1042 dbg("%s - parity = none", __FUNCTION__);
1044 /* figure out the stop bits requested */
1046 dbg("%s - stop bits = 2", __FUNCTION__);
1048 dbg("%s - stop bits = 1", __FUNCTION__);
1051 /* figure out the flow control settings */
1052 if (cflag & CRTSCTS)
1053 dbg("%s - RTS/CTS is enabled", __FUNCTION__);
1055 dbg("%s - RTS/CTS is disabled", __FUNCTION__);
1057 /* determine software flow control */
1058 if (I_IXOFF(port->tty))
1059 dbg("%s - XON/XOFF is enabled, XON = %2x, XOFF = %2x",
1060 __FUNCTION__, START_CHAR(port->tty), STOP_CHAR(port->tty));
1062 dbg("%s - XON/XOFF is disabled", __FUNCTION__);
1064 /* get the baud rate wanted */
1065 dbg("%s - baud rate = %d", __FUNCTION__, tty_get_baud_rate(port->tty));
1071 static int __init visor_init (void)
1076 /* Only if parameters were passed to us */
1077 if ((vendor > 0) && (product > 0)) {
1078 struct usb_device_id usb_dev_temp[]=
1079 {{USB_DEVICE(vendor, product)}};
1080 id_param_table[0] = usb_dev_temp[0];
1081 info("Untested USB device specified at time of module insertion");
1082 info("Warning: This is not guaranteed to work");
1083 info("Using a newer kernel is preferred to this method");
1084 info("Adding Palm OS protocol 4.x support for unknown device: 0x%x/0x%x",
1085 param_device.id_table[0].idVendor, param_device.id_table[0].idProduct);
1087 usb_serial_register (¶m_device);
1089 usb_serial_register (&handspring_device);
1090 usb_serial_register (&clie_3_5_device);
1091 usb_serial_register (&clie_5_device);
1093 /* create our write urb pool and transfer buffers */
1094 spin_lock_init (&write_urb_pool_lock);
1095 for (i = 0; i < NUM_URBS; ++i) {
1096 urb = usb_alloc_urb(0);
1097 write_urb_pool[i] = urb;
1099 err("No more urbs???");
1103 urb->transfer_buffer = NULL;
1104 urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
1105 if (!urb->transfer_buffer) {
1106 err("%s - out of memory for urb buffers.", __FUNCTION__);
1111 info(DRIVER_DESC " " DRIVER_VERSION);
1117 static void __exit visor_exit (void)
1120 unsigned long flags;
1122 if (param_register) {
1124 usb_serial_deregister (¶m_device);
1126 usb_serial_deregister (&handspring_device);
1127 usb_serial_deregister (&clie_3_5_device);
1128 usb_serial_deregister (&clie_5_device);
1130 spin_lock_irqsave (&write_urb_pool_lock, flags);
1132 for (i = 0; i < NUM_URBS; ++i) {
1133 if (write_urb_pool[i]) {
1134 /* FIXME - uncomment the following usb_unlink_urb call when
1135 * the host controllers get fixed to set urb->dev = NULL after
1136 * the urb is finished. Otherwise this call oopses. */
1137 /* usb_unlink_urb(write_urb_pool[i]); */
1138 if (write_urb_pool[i]->transfer_buffer)
1139 kfree(write_urb_pool[i]->transfer_buffer);
1140 usb_free_urb (write_urb_pool[i]);
1144 spin_unlock_irqrestore (&write_urb_pool_lock, flags);
1148 module_init(visor_init);
1149 module_exit(visor_exit);
1151 MODULE_AUTHOR( DRIVER_AUTHOR );
1152 MODULE_DESCRIPTION( DRIVER_DESC );
1153 MODULE_LICENSE("GPL");
1155 MODULE_PARM(debug, "i");
1156 MODULE_PARM_DESC(debug, "Debug enabled or not");
1157 MODULE_PARM(vendor, "i");
1158 MODULE_PARM_DESC(vendor, "User specified vendor ID");
1159 MODULE_PARM(product, "i");
1160 MODULE_PARM_DESC(product, "User specified product ID");