]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/usb/serial/navman.c
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[mirror_ubuntu-bionic-kernel.git] / drivers / usb / serial / navman.c
CommitLineData
e9a66c64
GKH
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.
a5b6f60c
AC
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.
e9a66c64
GKH
13 */
14
5a0e3ad6 15#include <linux/gfp.h>
e9a66c64
GKH
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>
a969888c 22#include <linux/usb/serial.h>
e9a66c64
GKH
23
24static int debug;
25
7d40d7e8 26static const struct usb_device_id id_table[] = {
e9a66c64
GKH
27 { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */
28 { },
29};
30MODULE_DEVICE_TABLE(usb, id_table);
31
32static struct usb_driver navman_driver = {
33 .name = "navman",
34 .probe = usb_serial_probe,
35 .disconnect = usb_serial_disconnect,
36 .id_table = id_table,
37 .no_dynamic_id = 1,
38};
39
7d12e780 40static void navman_read_int_callback(struct urb *urb)
e9a66c64
GKH
41{
42 struct usb_serial_port *port = urb->context;
43 unsigned char *data = urb->transfer_buffer;
44 struct tty_struct *tty;
9965d612 45 int status = urb->status;
e9a66c64
GKH
46 int result;
47
9965d612 48 switch (status) {
e9a66c64
GKH
49 case 0:
50 /* success */
51 break;
52 case -ECONNRESET:
53 case -ENOENT:
54 case -ESHUTDOWN:
55 /* this urb is terminated, clean up */
56 dbg("%s - urb shutting down with status: %d",
441b62c1 57 __func__, status);
e9a66c64
GKH
58 return;
59 default:
60 dbg("%s - nonzero urb status received: %d",
441b62c1 61 __func__, status);
e9a66c64
GKH
62 goto exit;
63 }
64
441b62c1 65 usb_serial_debug_data(debug, &port->dev, __func__,
e9a66c64
GKH
66 urb->actual_length, data);
67
4a90f09b 68 tty = tty_port_tty_get(&port->port);
e9a66c64 69 if (tty && urb->actual_length) {
e9a66c64
GKH
70 tty_insert_flip_string(tty, data, urb->actual_length);
71 tty_flip_buffer_push(tty);
72 }
4a90f09b 73 tty_kref_put(tty);
e9a66c64
GKH
74
75exit:
76 result = usb_submit_urb(urb, GFP_ATOMIC);
77 if (result)
78 dev_err(&urb->dev->dev,
79 "%s - Error %d submitting interrupt urb\n",
441b62c1 80 __func__, result);
e9a66c64
GKH
81}
82
a509a7e4 83static int navman_open(struct tty_struct *tty, struct usb_serial_port *port)
e9a66c64
GKH
84{
85 int result = 0;
86
441b62c1 87 dbg("%s - port %d", __func__, port->number);
e9a66c64
GKH
88
89 if (port->interrupt_in_urb) {
441b62c1 90 dbg("%s - adding interrupt input for treo", __func__);
e9a66c64
GKH
91 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
92 if (result)
93 dev_err(&port->dev,
94 "%s - failed submitting interrupt urb, error %d\n",
441b62c1 95 __func__, result);
e9a66c64
GKH
96 }
97 return result;
98}
99
335f8514 100static void navman_close(struct usb_serial_port *port)
e9a66c64 101{
441b62c1 102 dbg("%s - port %d", __func__, port->number);
e9a66c64 103
9aac10ff 104 usb_kill_urb(port->interrupt_in_urb);
e9a66c64
GKH
105}
106
95da310e 107static int navman_write(struct tty_struct *tty, struct usb_serial_port *port,
e9a66c64
GKH
108 const unsigned char *buf, int count)
109{
441b62c1 110 dbg("%s - port %d", __func__, port->number);
e9a66c64
GKH
111
112 /*
113 * This device can't write any data, only read from the device
e9a66c64 114 */
a5b6f60c 115 return -EOPNOTSUPP;
e9a66c64
GKH
116}
117
118static struct usb_serial_driver navman_device = {
119 .driver = {
120 .owner = THIS_MODULE,
121 .name = "navman",
122 },
123 .id_table = id_table,
d9b1b787 124 .usb_driver = &navman_driver,
e9a66c64
GKH
125 .num_ports = 1,
126 .open = navman_open,
127 .close = navman_close,
128 .write = navman_write,
129 .read_int_callback = navman_read_int_callback,
130};
131
132static int __init navman_init(void)
133{
134 int retval;
135
136 retval = usb_serial_register(&navman_device);
137 if (retval)
138 return retval;
139 retval = usb_register(&navman_driver);
140 if (retval)
141 usb_serial_deregister(&navman_device);
142 return retval;
143}
144
145static void __exit navman_exit(void)
146{
147 usb_deregister(&navman_driver);
148 usb_serial_deregister(&navman_device);
149}
150
151module_init(navman_init);
152module_exit(navman_exit);
153MODULE_LICENSE("GPL");
154
155module_param(debug, bool, S_IRUGO | S_IWUSR);
156MODULE_PARM_DESC(debug, "Debug enabled or not");