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