/*
* USB Compaq iPAQ driver
*
* Copyright (C) 2001 - 2002
* Ganesh Varadarajan <ganesh@veritas.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* (12/12/2002) ganesh
* Added support for practically all devices supported by ActiveSync
* on Windows. Thanks to Wes Cilldhaire <billybobjoehenrybob@hotmail.com>.
*
* (26/11/2002) ganesh
* Added insmod options to specify product and vendor id.
* Use modprobe ipaq vendor=0xfoo product=0xbar
*
* (26/7/2002) ganesh
* Fixed up broken error handling in ipaq_open. Retry the "kickstart"
* packet much harder - this drastically reduces connection failures.
*
* (30/4/2002) ganesh
* Added support for the Casio EM500. Completely untested. Thanks
* to info from Nathan <wfilardo@fuse.net>
*
* (19/3/2002) ganesh
* Don't submit urbs while holding spinlocks. Not strictly necessary
* in 2.5.x.
*
* (8/3/2002) ganesh
* The ipaq sometimes emits a '\0' before the CLIENT string. At this
* point of time, the ppp ldisc is not yet attached to the tty, so
* n_tty echoes "^ " to the ipaq, which messes up the chat. In 2.5.6-pre2
* this causes a panic because echo_char() tries to sleep in interrupt
* context.
* The fix is to tell the upper layers that this is a raw device so that
* echoing is suppressed. Thanks to Lyle Lindholm for a detailed bug
* report.
*
* (25/2/2002) ganesh
* Added support for the HP Jornada 548 and 568. Completely untested.
* Thanks to info from Heath Robinson and Arieh Davidoff.
*/
#include <linux/kernel.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/tty.h>
#include <linux/tty_driver.h>
#include <linux/tty_flip.h>
#include <linux/module.h>
#include <linux/spinlock.h>
#include <linux/uaccess.h>
#include <linux/usb.h>
#include <linux/usb/serial.h>
#include "ipaq.h"
#define KP_RETRIES 100
/*
* Version Information
*/
#define DRIVER_VERSION "v0.5"
#define DRIVER_AUTHOR "Ganesh Varadarajan <ganesh@veritas.com>"
#define DRIVER_DESC "USB PocketPC PDA driver"
static __u16 product, vendor;
static int debug;
static int connect_retries = KP_RETRIES;
static int initial_wait;
/* Function prototypes for an ipaq */
static int ipaq_open(struct tty_struct *tty,
struct usb_serial_port *port);
static void ipaq_close(struct usb_serial_port *port);
static int ipaq_calc_num_ports(struct usb_serial *serial);
static int ipaq_startup(struct usb_serial *serial);
static int ipaq_write(struct tty_struct *tty, struct usb_serial_port *port,
const unsigned char *buf, int count);
static int ipaq_write_bulk(struct usb_serial_port *port,
const unsigned char *buf, int count);
static void ipaq_write_gather(struct usb_serial_port *port);
static void ipaq_read_bulk_callback(struct urb *urb);
static void ipaq_write_bulk_callback(struct urb *urb);
static int ipaq_write_room(struct tty_struct *tty);
static int ipaq_chars_in_buffer(struct tty_struct *tty);
static void ipaq_destroy_lists(struct usb_serial_port *port);
static struct usb_device_id ipaq_id_table [] = {
/* The first entry is a placeholder for the insmod-specified device */
{ USB_DEVICE(0x049F, 0x0003) },
{ USB_DEVICE(0x0104, 0x00BE) }, /* Socket USB Sync */
{ USB_DEVICE(0x03F0, 0x1016) }, /* HP USB Sync */
{ USB_DEVICE(0x03F0, 0x1116) }, /* HP USB Sync 1611 */
{ USB_DEVICE(0x03F0, 0x1216) }, /* HP USB Sync 1612 */
{ USB_DEVICE(0x03F0, 0x2016) }, /* HP USB Sync 1620 */
{ USB_DEVICE(0x03F0, 0x2116) }, /* HP USB Sync 1621 */
{ USB_DEVICE(0x03F0, 0x2216) }, /* HP USB Sync 1622 */
{ USB_DEVICE(0x03F0, 0x3016) }, /* HP USB Sync 1630 */
{ USB_DEVICE(0x03F0, 0x3116) }, /* HP USB Sync 1631 */
{ USB_DEVICE(0x03F0, 0x3216) }, /* HP USB Sync 1632 */
{ USB_DEVICE(0x03F0, 0x4016) }, /* HP USB Sync 1640 */
{ USB_DEVICE(0x03F0, 0x4116) }, /* HP USB Sync 1641 */
{ USB_DEVICE(0x03F0, 0x4216) }, /* HP USB Sync 1642 */
{ USB_DEVICE(0x03F0, 0x5016) }, /* HP USB Sync 1650 */
{ USB_DEVICE(0x03F0, 0x5116) }, /* HP USB Sync 1651 */
{ USB_DEVICE(0x03F0, 0x5216) }, /* HP USB Sync 1652 */
{ USB_DEVICE(0x0409, 0x00D5) }, /* NEC USB Sync */
{ USB_DEVICE(0x0409, 0x00D6) }, /* NEC USB Sync */
{ USB_DEVICE(0x0409, 0x00D7) }, /* NEC USB Sync */
{ USB_DEVICE(0x0409, 0x8024) }, /* NEC USB Sync */
{ USB_DEVICE(0x0409, 0x8025) }, /* NEC USB Sync */
{ USB_DEVICE(0x043E, 0x9C01) }, /* LGE USB Sync */
{ USB_DEVICE(0x045E, 0x00CE) }, /* Microsoft USB Sync */
{ USB_DEVICE(0x045E, 0x0400) }, /* Windows Powered Pocket PC 2002 */
{ USB_DEVICE(0x045E, 0x0401) }, /* Windows Powered Pocket PC 2002 */
{ USB_DEVICE(0x045E, 0x0402) },