2 * Navman Serial USB driver
4 * Copyright (C) 2006 Greg Kroah-Hartman <gregkh@suse.de>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * version 2 as published by the Free Software Foundation.
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/tty.h>
14 #include <linux/tty_flip.h>
15 #include <linux/module.h>
16 #include <linux/usb.h>
17 #include <linux/usb/serial.h>
21 static struct usb_device_id id_table [] = {
22 { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */
25 MODULE_DEVICE_TABLE(usb, id_table);
27 static struct usb_driver navman_driver = {
29 .probe = usb_serial_probe,
30 .disconnect = usb_serial_disconnect,
35 static void navman_read_int_callback(struct urb *urb)
37 struct usb_serial_port *port = urb->context;
38 unsigned char *data = urb->transfer_buffer;
39 struct tty_struct *tty;
42 switch (urb->status) {
49 /* this urb is terminated, clean up */
50 dbg("%s - urb shutting down with status: %d",
51 __FUNCTION__, urb->status);
54 dbg("%s - nonzero urb status received: %d",
55 __FUNCTION__, urb->status);
59 usb_serial_debug_data(debug, &port->dev, __FUNCTION__,
60 urb->actual_length, data);
63 if (tty && urb->actual_length) {
64 tty_buffer_request_room(tty, urb->actual_length);
65 tty_insert_flip_string(tty, data, urb->actual_length);
66 tty_flip_buffer_push(tty);
70 result = usb_submit_urb(urb, GFP_ATOMIC);
72 dev_err(&urb->dev->dev,
73 "%s - Error %d submitting interrupt urb\n",
74 __FUNCTION__, result);
77 static int navman_open(struct usb_serial_port *port, struct file *filp)
81 dbg("%s - port %d", __FUNCTION__, port->number);
83 if (port->interrupt_in_urb) {
84 dbg("%s - adding interrupt input for treo", __FUNCTION__);
85 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
88 "%s - failed submitting interrupt urb, error %d\n",
89 __FUNCTION__, result);
94 static void navman_close(struct usb_serial_port *port, struct file *filp)
96 dbg("%s - port %d", __FUNCTION__, port->number);
98 usb_kill_urb(port->interrupt_in_urb);
101 static int navman_write(struct usb_serial_port *port,
102 const unsigned char *buf, int count)
104 dbg("%s - port %d", __FUNCTION__, port->number);
107 * This device can't write any data, only read from the device
108 * so we just silently eat all data sent to us and say it was
110 * Evil, I know, but do you have a better idea?
116 static struct usb_serial_driver navman_device = {
118 .owner = THIS_MODULE,
121 .id_table = id_table,
122 .num_interrupt_in = NUM_DONT_CARE,
123 .num_bulk_in = NUM_DONT_CARE,
124 .num_bulk_out = NUM_DONT_CARE,
127 .close = navman_close,
128 .write = navman_write,
129 .read_int_callback = navman_read_int_callback,
132 static int __init navman_init(void)
136 retval = usb_serial_register(&navman_device);
139 retval = usb_register(&navman_driver);
141 usb_serial_deregister(&navman_device);
145 static void __exit navman_exit(void)
147 usb_deregister(&navman_driver);
148 usb_serial_deregister(&navman_device);
151 module_init(navman_init);
152 module_exit(navman_exit);
153 MODULE_LICENSE("GPL");
155 module_param(debug, bool, S_IRUGO | S_IWUSR);
156 MODULE_PARM_DESC(debug, "Debug enabled or not");