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 * TODO: 11 * Add termios method that uses copy_hw but also kills all echo 12 * flags as the navman is rx only so cannot echo. 13 */ 14 15 #include <linux/gfp.h> 16 #include <linux/kernel.h> 17 #include <linux/init.h> 18 #include <linux/tty.h> 19 #include <linux/tty_flip.h> 20 #include <linux/module.h> 21 #include <linux/usb.h> 22 #include <linux/usb/serial.h> 23 24 static bool debug; 25 26 static const struct usb_device_id id_table[] = { 27 { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */ 28 { USB_DEVICE(0x0df7, 0x0900) }, /* Mobile Action i-gotU */ 29 { }, 30 }; 31 MODULE_DEVICE_TABLE(usb, id_table); 32 33 static struct usb_driver navman_driver = { 34 .name = "navman", 35 .id_table = id_table, 36 }; 37 38 static void navman_read_int_callback(struct urb *urb) 39 { 40 struct usb_serial_port *port = urb->context; 41 unsigned char *data = urb->transfer_buffer; 42 struct tty_struct *tty; 43 int status = urb->status; 44 int result; 45 46 switch (status) { 47 case 0: 48 /* success */ 49 break; 50 case -ECONNRESET: 51 case -ENOENT: 52 case -ESHUTDOWN: 53 /* this urb is terminated, clean up */ 54 dbg("%s - urb shutting down with status: %d", 55 __func__, status); 56 return; 57 default: 58 dbg("%s - nonzero urb status received: %d", 59 __func__, status); 60 goto exit; 61 } 62 63 usb_serial_debug_data(debug, &port->dev, __func__, 64 urb->actual_length, data); 65 66 tty = tty_port_tty_get(&port->port); 67 if (tty && urb->actual_length) { 68 tty_insert_flip_string(tty, data, urb->actual_length); 69 tty_flip_buffer_push(tty); 70 } 71 tty_kref_put(tty); 72 73 exit: 74 result = usb_submit_urb(urb, GFP_ATOMIC); 75 if (result) 76 dev_err(&urb->dev->dev, 77 "%s - Error %d submitting interrupt urb\n", 78 __func__, result); 79 } 80 81 static int navman_open(struct tty_struct *tty, struct usb_serial_port *port) 82 { 83 int result = 0; 84 85 if (port->interrupt_in_urb) { 86 dbg("%s - adding interrupt input for treo", __func__); 87 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 88 if (result) 89 dev_err(&port->dev, 90 "%s - failed submitting interrupt urb, error %d\n", 91 __func__, result); 92 } 93 return result; 94 } 95 96 static void navman_close(struct usb_serial_port *port) 97 { 98 usb_kill_urb(port->interrupt_in_urb); 99 } 100 101 static int navman_write(struct tty_struct *tty, struct usb_serial_port *port, 102 const unsigned char *buf, int count) 103 { 104 /* 105 * This device can't write any data, only read from the device 106 */ 107 return -EOPNOTSUPP; 108 } 109 110 static struct usb_serial_driver navman_device = { 111 .driver = { 112 .owner = THIS_MODULE, 113 .name = "navman", 114 }, 115 .id_table = id_table, 116 .num_ports = 1, 117 .open = navman_open, 118 .close = navman_close, 119 .write = navman_write, 120 .read_int_callback = navman_read_int_callback, 121 }; 122 123 static struct usb_serial_driver * const serial_drivers[] = { 124 &navman_device, NULL 125 }; 126 127 module_usb_serial_driver(navman_driver, serial_drivers); 128 129 MODULE_LICENSE("GPL"); 130 131 module_param(debug, bool, S_IRUGO | S_IWUSR); 132 MODULE_PARM_DESC(debug, "Debug enabled or not"); 133