Greg Kroah-Hartman | e9a66c6 | 2006-03-17 17:40:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Navman Serial USB driver |
| 3 | * |
| 4 | * Copyright (C) 2006 Greg Kroah-Hartman <gregkh@suse.de> |
| 5 | * |
| 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. |
| 9 | */ |
| 10 | |
| 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> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 17 | #include <linux/usb/serial.h> |
Greg Kroah-Hartman | e9a66c6 | 2006-03-17 17:40:08 -0800 | [diff] [blame] | 18 | |
| 19 | static int debug; |
| 20 | |
| 21 | static struct usb_device_id id_table [] = { |
| 22 | { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */ |
| 23 | { }, |
| 24 | }; |
| 25 | MODULE_DEVICE_TABLE(usb, id_table); |
| 26 | |
| 27 | static struct usb_driver navman_driver = { |
| 28 | .name = "navman", |
| 29 | .probe = usb_serial_probe, |
| 30 | .disconnect = usb_serial_disconnect, |
| 31 | .id_table = id_table, |
| 32 | .no_dynamic_id = 1, |
| 33 | }; |
| 34 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 35 | static void navman_read_int_callback(struct urb *urb) |
Greg Kroah-Hartman | e9a66c6 | 2006-03-17 17:40:08 -0800 | [diff] [blame] | 36 | { |
| 37 | struct usb_serial_port *port = urb->context; |
| 38 | unsigned char *data = urb->transfer_buffer; |
| 39 | struct tty_struct *tty; |
Greg Kroah-Hartman | 9965d61 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 40 | int status = urb->status; |
Greg Kroah-Hartman | e9a66c6 | 2006-03-17 17:40:08 -0800 | [diff] [blame] | 41 | int result; |
| 42 | |
Greg Kroah-Hartman | 9965d61 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 43 | switch (status) { |
Greg Kroah-Hartman | e9a66c6 | 2006-03-17 17:40:08 -0800 | [diff] [blame] | 44 | case 0: |
| 45 | /* success */ |
| 46 | break; |
| 47 | case -ECONNRESET: |
| 48 | case -ENOENT: |
| 49 | case -ESHUTDOWN: |
| 50 | /* this urb is terminated, clean up */ |
| 51 | dbg("%s - urb shutting down with status: %d", |
Greg Kroah-Hartman | 9965d61 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 52 | __FUNCTION__, status); |
Greg Kroah-Hartman | e9a66c6 | 2006-03-17 17:40:08 -0800 | [diff] [blame] | 53 | return; |
| 54 | default: |
| 55 | dbg("%s - nonzero urb status received: %d", |
Greg Kroah-Hartman | 9965d61 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 56 | __FUNCTION__, status); |
Greg Kroah-Hartman | e9a66c6 | 2006-03-17 17:40:08 -0800 | [diff] [blame] | 57 | goto exit; |
| 58 | } |
| 59 | |
| 60 | usb_serial_debug_data(debug, &port->dev, __FUNCTION__, |
| 61 | urb->actual_length, data); |
| 62 | |
| 63 | tty = port->tty; |
| 64 | if (tty && urb->actual_length) { |
| 65 | tty_buffer_request_room(tty, urb->actual_length); |
| 66 | tty_insert_flip_string(tty, data, urb->actual_length); |
| 67 | tty_flip_buffer_push(tty); |
| 68 | } |
| 69 | |
| 70 | exit: |
| 71 | result = usb_submit_urb(urb, GFP_ATOMIC); |
| 72 | if (result) |
| 73 | dev_err(&urb->dev->dev, |
| 74 | "%s - Error %d submitting interrupt urb\n", |
| 75 | __FUNCTION__, result); |
| 76 | } |
| 77 | |
| 78 | static int navman_open(struct usb_serial_port *port, struct file *filp) |
| 79 | { |
| 80 | int result = 0; |
| 81 | |
| 82 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 83 | |
| 84 | if (port->interrupt_in_urb) { |
| 85 | dbg("%s - adding interrupt input for treo", __FUNCTION__); |
| 86 | result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
| 87 | if (result) |
| 88 | dev_err(&port->dev, |
| 89 | "%s - failed submitting interrupt urb, error %d\n", |
| 90 | __FUNCTION__, result); |
| 91 | } |
| 92 | return result; |
| 93 | } |
| 94 | |
| 95 | static void navman_close(struct usb_serial_port *port, struct file *filp) |
| 96 | { |
| 97 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 98 | |
Mariusz Kozlowski | 9aac10f | 2006-11-08 15:36:46 +0100 | [diff] [blame] | 99 | usb_kill_urb(port->interrupt_in_urb); |
Greg Kroah-Hartman | e9a66c6 | 2006-03-17 17:40:08 -0800 | [diff] [blame] | 100 | } |
| 101 | |
| 102 | static int navman_write(struct usb_serial_port *port, |
| 103 | const unsigned char *buf, int count) |
| 104 | { |
| 105 | dbg("%s - port %d", __FUNCTION__, port->number); |
| 106 | |
| 107 | /* |
| 108 | * This device can't write any data, only read from the device |
| 109 | * so we just silently eat all data sent to us and say it was |
| 110 | * successfully sent. |
| 111 | * Evil, I know, but do you have a better idea? |
| 112 | */ |
| 113 | |
| 114 | return count; |
| 115 | } |
| 116 | |
| 117 | static struct usb_serial_driver navman_device = { |
| 118 | .driver = { |
| 119 | .owner = THIS_MODULE, |
| 120 | .name = "navman", |
| 121 | }, |
| 122 | .id_table = id_table, |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 123 | .usb_driver = &navman_driver, |
Greg Kroah-Hartman | e9a66c6 | 2006-03-17 17:40:08 -0800 | [diff] [blame] | 124 | .num_interrupt_in = NUM_DONT_CARE, |
| 125 | .num_bulk_in = NUM_DONT_CARE, |
| 126 | .num_bulk_out = NUM_DONT_CARE, |
| 127 | .num_ports = 1, |
| 128 | .open = navman_open, |
| 129 | .close = navman_close, |
| 130 | .write = navman_write, |
| 131 | .read_int_callback = navman_read_int_callback, |
| 132 | }; |
| 133 | |
| 134 | static int __init navman_init(void) |
| 135 | { |
| 136 | int retval; |
| 137 | |
| 138 | retval = usb_serial_register(&navman_device); |
| 139 | if (retval) |
| 140 | return retval; |
| 141 | retval = usb_register(&navman_driver); |
| 142 | if (retval) |
| 143 | usb_serial_deregister(&navman_device); |
| 144 | return retval; |
| 145 | } |
| 146 | |
| 147 | static void __exit navman_exit(void) |
| 148 | { |
| 149 | usb_deregister(&navman_driver); |
| 150 | usb_serial_deregister(&navman_device); |
| 151 | } |
| 152 | |
| 153 | module_init(navman_init); |
| 154 | module_exit(navman_exit); |
| 155 | MODULE_LICENSE("GPL"); |
| 156 | |
| 157 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 158 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |