blob: 2a97cdc078d53843ce1366cd67e070bc7c3b334e [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>
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080017#include <linux/tty.h>
18#include <linux/tty_flip.h>
19#include <linux/module.h>
20#include <linux/usb.h>
Greg Kroah-Hartmana9698882006-07-11 21:22:58 -070021#include <linux/usb/serial.h>
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080022
Németh Márton7d40d7e2010-01-10 15:34:24 +010023static const struct usb_device_id id_table[] = {
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080024 { USB_DEVICE(0x0a99, 0x0001) }, /* Talon Technology device */
Ross Burton0eee6a22010-08-06 16:36:39 +010025 { USB_DEVICE(0x0df7, 0x0900) }, /* Mobile Action i-gotU */
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080026 { },
27};
28MODULE_DEVICE_TABLE(usb, id_table);
29
David Howells7d12e782006-10-05 14:55:46 +010030static void navman_read_int_callback(struct urb *urb)
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080031{
32 struct usb_serial_port *port = urb->context;
33 unsigned char *data = urb->transfer_buffer;
Greg Kroah-Hartman9965d612007-06-15 15:44:13 -070034 int status = urb->status;
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080035 int result;
36
Greg Kroah-Hartman9965d612007-06-15 15:44:13 -070037 switch (status) {
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080038 case 0:
39 /* success */
40 break;
41 case -ECONNRESET:
42 case -ENOENT:
43 case -ESHUTDOWN:
44 /* this urb is terminated, clean up */
Greg Kroah-Hartman00c533f2012-05-15 16:27:25 -070045 dev_dbg(&port->dev, "%s - urb shutting down with status: %d\n",
46 __func__, status);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080047 return;
48 default:
Greg Kroah-Hartman00c533f2012-05-15 16:27:25 -070049 dev_dbg(&port->dev, "%s - nonzero urb status received: %d\n",
50 __func__, status);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080051 goto exit;
52 }
53
Greg Kroah-Hartman59d33f22012-09-18 09:58:57 +010054 usb_serial_debug_data(&port->dev, __func__, urb->actual_length, data);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080055
Jiri Slaby2e124b42013-01-03 15:53:06 +010056 if (urb->actual_length) {
Jiri Slaby05c7cd32013-01-03 15:53:04 +010057 tty_insert_flip_string(&port->port, data, urb->actual_length);
Jiri Slaby2e124b42013-01-03 15:53:06 +010058 tty_flip_buffer_push(&port->port);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080059 }
60
61exit:
62 result = usb_submit_urb(urb, GFP_ATOMIC);
63 if (result)
64 dev_err(&urb->dev->dev,
65 "%s - Error %d submitting interrupt urb\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -080066 __func__, result);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080067}
68
Alan Coxa509a7e2009-09-19 13:13:26 -070069static int navman_open(struct tty_struct *tty, struct usb_serial_port *port)
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080070{
71 int result = 0;
72
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080073 if (port->interrupt_in_urb) {
Greg Kroah-Hartman00c533f2012-05-15 16:27:25 -070074 dev_dbg(&port->dev, "%s - adding interrupt input for treo\n",
75 __func__);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080076 result = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
77 if (result)
78 dev_err(&port->dev,
79 "%s - failed submitting interrupt urb, error %d\n",
Harvey Harrison441b62c2008-03-03 16:08:34 -080080 __func__, result);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080081 }
82 return result;
83}
84
Alan Cox335f8512009-06-11 12:26:29 +010085static void navman_close(struct usb_serial_port *port)
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080086{
Mariusz Kozlowski9aac10f2006-11-08 15:36:46 +010087 usb_kill_urb(port->interrupt_in_urb);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080088}
89
Alan Cox95da3102008-07-22 11:09:07 +010090static int navman_write(struct tty_struct *tty, struct usb_serial_port *port,
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080091 const unsigned char *buf, int count)
92{
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080093 /*
94 * This device can't write any data, only read from the device
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080095 */
Alan Coxa5b6f602008-04-08 17:16:06 +010096 return -EOPNOTSUPP;
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -080097}
98
99static struct usb_serial_driver navman_device = {
100 .driver = {
101 .owner = THIS_MODULE,
102 .name = "navman",
103 },
104 .id_table = id_table,
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800105 .num_ports = 1,
106 .open = navman_open,
107 .close = navman_close,
108 .write = navman_write,
109 .read_int_callback = navman_read_int_callback,
110};
111
Alan Sternf667dda2012-02-23 14:57:18 -0500112static struct usb_serial_driver * const serial_drivers[] = {
113 &navman_device, NULL
114};
115
Greg Kroah-Hartman68e24112012-05-08 15:46:14 -0700116module_usb_serial_driver(serial_drivers, id_table);
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800117
Greg Kroah-Hartmane9a66c62006-03-17 17:40:08 -0800118MODULE_LICENSE("GPL");