blob: 1f00f243c26cf5e1825632e40fc9c2a60287f9e3 [file] [log] [blame]
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -08001/*
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.
Alan Coxa5b6f602008-04-08 17:16:06 +01009 *
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.
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080013 */
14
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090015#include <linux/gfp.h>
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080016#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>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070022#include <linux/usb/serial.h>
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080023
24static int debug;
25
Németh Márton7d40d7e2010-01-10 15:34:24 +010026static const struct usb_device_id id_table[] = {
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080027 { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */
Ross Burton0eee6a22010-08-06 16:36:39 +010028 { USB_DEVICE(0x0df7, 0x0900) }, /* Mobile Action i-gotU */
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080029 { },
30};
31MODULE_DEVICE_TABLE(usb, id_table);
32
33static struct usb_driver navman_driver = {
34 .name = "navman",
35 .probe = usb_serial_probe,
36 .disconnect = usb_serial_disconnect,
37 .id_table = id_table,
38 .no_dynamic_id = 1,
39};
40
David Howells7d12e782006-10-05 14:55:46 +010041static void navman_read_int_callback(struct urb *urb)
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080042{
43 struct usb_serial_port *port = urb->context;
44 unsigned char *data = urb->transfer_buffer;
45 struct tty_struct *tty;
Greg Kroah-Hartman9965d612007-06-15 15:44:13 -070046 int status = urb->status;
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080047 int result;
48
Greg Kroah-Hartman9965d612007-06-15 15:44:13 -070049 switch (status) {
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080050 case 0:
51 /* success */
52 break;
53 case -ECONNRESET:
54 case -ENOENT:
55 case -ESHUTDOWN:
56 /* this urb is terminated, clean up */
57 dbg("%s - urb shutting down with status: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -080058 __func__, status);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080059 return;
60 default:
61 dbg("%s - nonzero urb status received: %d",
Harvey Harrison441b62c2008-03-03 16:08:34 -080062 __func__, status);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080063 goto exit;
64 }
65
Harvey Harrison441b62c2008-03-03 16:08:34 -080066 usb_serial_debug_data(debug, &port->dev, __func__,
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080067 urb->actual_length, data);
68
Alan Cox4a90f092008-10-13 10:39:46 +010069 tty = tty_port_tty_get(&port->port);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080070 if (tty && urb->actual_length) {
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080071 tty_insert_flip_string(tty, data, urb->actual_length);
72 tty_flip_buffer_push(tty);
73 }
Alan Cox4a90f092008-10-13 10:39:46 +010074 tty_kref_put(tty);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080075
76exit:
77 result = usb_submit_urb(urb, GFP_ATOMIC);
78 if (result)
79 dev_err(&urb->dev->dev,
80 "%s - Error %d submitting interrupt urb\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -080081 __func__, result);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080082}
83
Alan Coxa509a7e2009-09-19 13:13:26 -070084static int navman_open(struct tty_struct *tty, struct usb_serial_port *port)
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080085{
86 int result = 0;
87
Harvey Harrison441b62c2008-03-03 16:08:34 -080088 dbg("%s - port %d", __func__, port->number);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080089
90 if (port->interrupt_in_urb) {
Harvey Harrison441b62c2008-03-03 16:08:34 -080091 dbg("%s - adding interrupt input for treo", __func__);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080092 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
93 if (result)
94 dev_err(&port->dev,
95 "%s - failed submitting interrupt urb, error %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -080096 __func__, result);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080097 }
98 return result;
99}
100
Alan Cox335f8512009-06-11 12:26:29 +0100101static void navman_close(struct usb_serial_port *port)
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800102{
Harvey Harrison441b62c2008-03-03 16:08:34 -0800103 dbg("%s - port %d", __func__, port->number);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800104
Mariusz Kozlowski9aac10f2006-11-08 15:36:46 +0100105 usb_kill_urb(port->interrupt_in_urb);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800106}
107
Alan Cox95da3102008-07-22 11:09:07 +0100108static int navman_write(struct tty_struct *tty, struct usb_serial_port *port,
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800109 const unsigned char *buf, int count)
110{
Harvey Harrison441b62c2008-03-03 16:08:34 -0800111 dbg("%s - port %d", __func__, port->number);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800112
113 /*
114 * This device can't write any data, only read from the device
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800115 */
Alan Coxa5b6f602008-04-08 17:16:06 +0100116 return -EOPNOTSUPP;
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800117}
118
119static struct usb_serial_driver navman_device = {
120 .driver = {
121 .owner = THIS_MODULE,
122 .name = "navman",
123 },
124 .id_table = id_table,
Johannes Hölzld9b1b782006-12-17 21:50:24 +0100125 .usb_driver = &navman_driver,
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800126 .num_ports = 1,
127 .open = navman_open,
128 .close = navman_close,
129 .write = navman_write,
130 .read_int_callback = navman_read_int_callback,
131};
132
133static int __init navman_init(void)
134{
135 int retval;
136
137 retval = usb_serial_register(&navman_device);
138 if (retval)
139 return retval;
140 retval = usb_register(&navman_driver);
141 if (retval)
142 usb_serial_deregister(&navman_device);
143 return retval;
144}
145
146static void __exit navman_exit(void)
147{
148 usb_deregister(&navman_driver);
149 usb_serial_deregister(&navman_device);
150}
151
152module_init(navman_init);
153module_exit(navman_exit);
154MODULE_LICENSE("GPL");
155
156module_param(debug, bool, S_IRUGO | S_IWUSR);
157MODULE_PARM_DESC(debug, "Debug enabled or not");