📄 ipaq.c
字号:
/* * 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. Thanks to Greg for pointing * this out. * * (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/config.h>#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 <asm/uaccess.h>#include <linux/usb.h>#ifdef CONFIG_USB_SERIAL_DEBUG static int debug = 1;#else static int debug = 0;#endif#include "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 int product, vendor;/* Function prototypes for an ipaq */static int ipaq_open (struct usb_serial_port *port, struct file *filp);static void ipaq_close (struct usb_serial_port *port, struct file *filp);static int ipaq_startup (struct usb_serial *serial);static void ipaq_shutdown (struct usb_serial *serial);static int ipaq_write(struct usb_serial_port *port, int from_user, const unsigned char *buf, int count);static int ipaq_write_bulk(struct usb_serial_port *port, int from_user, 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 usb_serial_port *port);static int ipaq_chars_in_buffer(struct usb_serial_port *port);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(COMPAQ_VENDOR_ID, COMPAQ_IPAQ_ID) }, { USB_DEVICE(ASKEY_VENDOR_ID, ASKEY_PRODUCT_ID) }, { USB_DEVICE(BCOM_VENDOR_ID, BCOM_0065_ID) }, { USB_DEVICE(BCOM_VENDOR_ID, BCOM_0066_ID) }, { USB_DEVICE(BCOM_VENDOR_ID, BCOM_0067_ID) }, { USB_DEVICE(CASIO_VENDOR_ID, CASIO_2001_ID) }, { USB_DEVICE(CASIO_VENDOR_ID, CASIO_EM500_ID) }, { USB_DEVICE(COMPAQ_VENDOR_ID, COMPAQ_IPAQ_ID) }, { USB_DEVICE(COMPAQ_VENDOR_ID, COMPAQ_0032_ID) }, { USB_DEVICE(DELL_VENDOR_ID, DELL_AXIM_ID) }, { USB_DEVICE(FSC_VENDOR_ID, FSC_LOOX_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_JORNADA_548_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_JORNADA_568_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_2016_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_2116_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_2216_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_3016_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_3116_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_3216_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_4016_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_4116_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_4216_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_5016_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_5116_ID) }, { USB_DEVICE(HP_VENDOR_ID, HP_5216_ID) }, { USB_DEVICE(LINKUP_VENDOR_ID, LINKUP_PRODUCT_ID) }, { USB_DEVICE(MICROSOFT_VENDOR_ID, MICROSOFT_00CE_ID) }, { USB_DEVICE(PORTATEC_VENDOR_ID, PORTATEC_PRODUCT_ID) }, { USB_DEVICE(SAGEM_VENDOR_ID, SAGEM_WIRELESS_ID) }, { USB_DEVICE(SOCKET_VENDOR_ID, SOCKET_PRODUCT_ID) }, { USB_DEVICE(TOSHIBA_VENDOR_ID, TOSHIBA_PRODUCT_ID) }, { USB_DEVICE(TOSHIBA_VENDOR_ID, TOSHIBA_E740_ID) }, { USB_DEVICE(HTC_VENDOR_ID, HTC_PRODUCT_ID) }, { USB_DEVICE(NEC_VENDOR_ID, NEC_PRODUCT_ID) }, { USB_DEVICE(ASUS_VENDOR_ID, ASUS_A600_PRODUCT_ID) }, { } /* Terminating entry */};MODULE_DEVICE_TABLE (usb, ipaq_id_table);/* All of the device info needed for the Compaq iPAQ */struct usb_serial_device_type ipaq_device = { .owner = THIS_MODULE, .name = "PocketPC PDA", .id_table = ipaq_id_table, .num_interrupt_in = NUM_DONT_CARE, .num_bulk_in = 1, .num_bulk_out = 1, .num_ports = 1, .open = ipaq_open, .close = ipaq_close, .startup = ipaq_startup, .shutdown = ipaq_shutdown, .write = ipaq_write, .write_room = ipaq_write_room, .chars_in_buffer = ipaq_chars_in_buffer, .read_bulk_callback = ipaq_read_bulk_callback, .write_bulk_callback = ipaq_write_bulk_callback,};static spinlock_t write_list_lock;static int bytes_in;static int bytes_out;static int ipaq_open(struct usb_serial_port *port, struct file *filp){ struct usb_serial *serial = port->serial; struct ipaq_private *priv; struct ipaq_packet *pkt; int i, result = 0; int retries = KP_RETRIES; if (port_paranoia_check(port, __FUNCTION__)) { return -ENODEV; } dbg("%s - port %d", __FUNCTION__, port->number); bytes_in = 0; bytes_out = 0; priv = (struct ipaq_private *)kmalloc(sizeof(struct ipaq_private), GFP_KERNEL); if (priv == NULL) { err("%s - Out of memory", __FUNCTION__); return -ENOMEM; } port->private = (void *)priv; priv->active = 0; priv->queue_len = 0; INIT_LIST_HEAD(&priv->queue); INIT_LIST_HEAD(&priv->freelist); for (i = 0; i < URBDATA_QUEUE_MAX / PACKET_SIZE; i++) { pkt = kmalloc(sizeof(struct ipaq_packet), GFP_KERNEL); if (pkt == NULL) { goto enomem; } pkt->data = kmalloc(PACKET_SIZE, GFP_KERNEL); if (pkt->data == NULL) { kfree(pkt); goto enomem; } pkt->len = 0; pkt->written = 0; INIT_LIST_HEAD(&pkt->list); list_add(&pkt->list, &priv->freelist); priv->free_len += PACKET_SIZE; } /* * Force low latency on. This will immediately push data to the line * discipline instead of queueing. */ port->tty->low_latency = 1; port->tty->raw = 1; port->tty->real_raw = 1; /* * Lose the small buffers usbserial provides. Make larger ones. */ kfree(port->bulk_in_buffer); kfree(port->bulk_out_buffer); port->bulk_in_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL); if (port->bulk_in_buffer == NULL) { goto enomem; } port->bulk_out_buffer = kmalloc(URBDATA_SIZE, GFP_KERNEL); if (port->bulk_out_buffer == NULL) { kfree(port->bulk_in_buffer); goto enomem; } port->read_urb->transfer_buffer = port->bulk_in_buffer; port->write_urb->transfer_buffer = port->bulk_out_buffer; port->read_urb->transfer_buffer_length = URBDATA_SIZE; port->bulk_out_size = port->write_urb->transfer_buffer_length = URBDATA_SIZE; /* Start reading from the device */ FILL_BULK_URB(port->read_urb, serial->dev, usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, ipaq_read_bulk_callback, port); result = usb_submit_urb(port->read_urb); if (result) { err("%s - failed submitting read urb, error %d", __FUNCTION__, result); goto error; } /* * Send out control message observed in win98 sniffs. Not sure what * it does, but from empirical observations, it seems that the device * will start the chat sequence once one of these messages gets * through. Since this has a reasonably high failure rate, we retry * several times. */ while (retries--) { result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 0x22, 0x21, 0x1, 0, NULL, 0, HZ / 10 + 1); if (result == 0) { return 0; } } err("%s - failed doing control urb, error %d", __FUNCTION__, result); goto error;enomem: result = -ENOMEM; err("%s - Out of memory", __FUNCTION__);error: ipaq_destroy_lists(port); kfree(priv); return result;}static void ipaq_close(struct usb_serial_port *port, struct file *filp){ struct usb_serial *serial; struct ipaq_private *priv = port->private; if (port_paranoia_check(port, __FUNCTION__)) { return; } dbg("%s - port %d", __FUNCTION__, port->number); serial = get_usb_serial(port, __FUNCTION__); if (!serial) return; /* * shut down bulk read and write */ usb_unlink_urb(port->write_urb); usb_unlink_urb(port->read_urb); ipaq_destroy_lists(port);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -