Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Belkin USB Serial Adapter Driver |
| 3 | * |
| 4 | * Copyright (C) 2000 William Greathouse (wgreathouse@smva.com) |
| 5 | * Copyright (C) 2000-2001 Greg Kroah-Hartman (greg@kroah.com) |
| 6 | * |
| 7 | * This program is largely derived from work by the linux-usb group |
| 8 | * and associated source files. Please see the usb/serial files for |
| 9 | * individual credits and copyrights. |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 10 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License as published by |
| 13 | * the Free Software Foundation; either version 2 of the License, or |
| 14 | * (at your option) any later version. |
| 15 | * |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 16 | * See Documentation/usb/usb-serial.txt for more information on using this |
| 17 | * driver |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | * |
| 19 | * TODO: |
| 20 | * -- Add true modem contol line query capability. Currently we track the |
| 21 | * states reported by the interrupt and the states we request. |
| 22 | * -- Add error reporting back to application for UART error conditions. |
| 23 | * Just point me at how to implement this and I'll do it. I've put the |
| 24 | * framework in, but haven't analyzed the "tty_flip" interface yet. |
| 25 | * -- Add support for flush commands |
| 26 | * -- Add everything that is missing :) |
| 27 | * |
| 28 | * 27-Nov-2001 gkh |
| 29 | * compressed all the differnent device entries into 1. |
| 30 | * |
| 31 | * 30-May-2001 gkh |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 32 | * switched from using spinlock to a semaphore, which fixes lots of |
| 33 | * problems. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | * |
| 35 | * 08-Apr-2001 gb |
| 36 | * - Identify version on module load. |
| 37 | * |
| 38 | * 12-Mar-2001 gkh |
| 39 | * - Added support for the GoHubs GO-COM232 device which is the same as the |
| 40 | * Peracom device. |
| 41 | * |
| 42 | * 06-Nov-2000 gkh |
| 43 | * - Added support for the old Belkin and Peracom devices. |
| 44 | * - Made the port able to be opened multiple times. |
| 45 | * - Added some defaults incase the line settings are things these devices |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 46 | * can't support. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | * |
| 48 | * 18-Oct-2000 William Greathouse |
| 49 | * Released into the wild (linux-usb-devel) |
| 50 | * |
| 51 | * 17-Oct-2000 William Greathouse |
| 52 | * Add code to recognize firmware version and set hardware flow control |
| 53 | * appropriately. Belkin states that firmware prior to 3.05 does not |
| 54 | * operate correctly in hardware handshake mode. I have verified this |
| 55 | * on firmware 2.05 -- for both RTS and DTR input flow control, the control |
| 56 | * line is not reset. The test performed by the Belkin Win* driver is |
| 57 | * to enable hardware flow control for firmware 2.06 or greater and |
| 58 | * for 1.00 or prior. I am only enabling for 2.06 or greater. |
| 59 | * |
| 60 | * 12-Oct-2000 William Greathouse |
| 61 | * First cut at supporting Belkin USB Serial Adapter F5U103 |
| 62 | * I did not have a copy of the original work to support this |
| 63 | * adapter, so pardon any stupid mistakes. All of the information |
| 64 | * I am using to write this driver was acquired by using a modified |
| 65 | * UsbSnoop on Windows2000 and from examining the other USB drivers. |
| 66 | */ |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | #include <linux/kernel.h> |
| 69 | #include <linux/errno.h> |
| 70 | #include <linux/init.h> |
| 71 | #include <linux/slab.h> |
| 72 | #include <linux/tty.h> |
| 73 | #include <linux/tty_driver.h> |
| 74 | #include <linux/tty_flip.h> |
| 75 | #include <linux/module.h> |
| 76 | #include <linux/spinlock.h> |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 77 | #include <linux/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 79 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #include "belkin_sa.h" |
| 81 | |
| 82 | static int debug; |
| 83 | |
| 84 | /* |
| 85 | * Version Information |
| 86 | */ |
| 87 | #define DRIVER_VERSION "v1.2" |
| 88 | #define DRIVER_AUTHOR "William Greathouse <wgreathouse@smva.com>" |
| 89 | #define DRIVER_DESC "USB Belkin Serial converter driver" |
| 90 | |
| 91 | /* function prototypes for a Belkin USB Serial Adapter F5U103 */ |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 92 | static int belkin_sa_startup(struct usb_serial *serial); |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 93 | static void belkin_sa_release(struct usb_serial *serial); |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 94 | static int belkin_sa_open(struct tty_struct *tty, |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 95 | struct usb_serial_port *port); |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 96 | static void belkin_sa_close(struct usb_serial_port *port); |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 97 | static void belkin_sa_read_int_callback(struct urb *urb); |
| 98 | static void belkin_sa_set_termios(struct tty_struct *tty, |
| 99 | struct usb_serial_port *port, struct ktermios * old); |
| 100 | static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state); |
| 101 | static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file); |
| 102 | static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file, |
| 103 | unsigned int set, unsigned int clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | |
Németh Márton | 7d40d7e | 2010-01-10 15:34:24 +0100 | [diff] [blame] | 106 | static const struct usb_device_id id_table_combined[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | { USB_DEVICE(BELKIN_SA_VID, BELKIN_SA_PID) }, |
| 108 | { USB_DEVICE(BELKIN_OLD_VID, BELKIN_OLD_PID) }, |
| 109 | { USB_DEVICE(PERACOM_VID, PERACOM_PID) }, |
| 110 | { USB_DEVICE(GOHUBS_VID, GOHUBS_PID) }, |
| 111 | { USB_DEVICE(GOHUBS_VID, HANDYLINK_PID) }, |
| 112 | { USB_DEVICE(BELKIN_DOCKSTATION_VID, BELKIN_DOCKSTATION_PID) }, |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 113 | { } /* Terminating entry */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | }; |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 115 | MODULE_DEVICE_TABLE(usb, id_table_combined); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
| 117 | static struct usb_driver belkin_driver = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | .name = "belkin", |
| 119 | .probe = usb_serial_probe, |
| 120 | .disconnect = usb_serial_disconnect, |
| 121 | .id_table = id_table_combined, |
Johan Hovold | 726ef42 | 2010-05-15 17:53:51 +0200 | [diff] [blame] | 122 | .no_dynamic_id = 1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | /* All of the device info needed for the serial converters */ |
Greg Kroah-Hartman | ea65370 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 126 | static struct usb_serial_driver belkin_device = { |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 127 | .driver = { |
| 128 | .owner = THIS_MODULE, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 129 | .name = "belkin", |
Greg Kroah-Hartman | 18fcac3 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 130 | }, |
Greg Kroah-Hartman | 269bda1 | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 131 | .description = "Belkin / Peracom / GoHubs USB Serial Adapter", |
Johannes Hölzl | d9b1b78 | 2006-12-17 21:50:24 +0100 | [diff] [blame] | 132 | .usb_driver = &belkin_driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | .id_table = id_table_combined, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | .num_ports = 1, |
| 135 | .open = belkin_sa_open, |
| 136 | .close = belkin_sa_close, |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 137 | .read_int_callback = belkin_sa_read_int_callback, |
| 138 | /* How we get the status info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | .set_termios = belkin_sa_set_termios, |
| 140 | .break_ctl = belkin_sa_break_ctl, |
| 141 | .tiocmget = belkin_sa_tiocmget, |
| 142 | .tiocmset = belkin_sa_tiocmset, |
| 143 | .attach = belkin_sa_startup, |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 144 | .release = belkin_sa_release, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | struct belkin_sa_private { |
| 148 | spinlock_t lock; |
| 149 | unsigned long control_state; |
| 150 | unsigned char last_lsr; |
| 151 | unsigned char last_msr; |
| 152 | int bad_flow_control; |
| 153 | }; |
| 154 | |
| 155 | |
| 156 | /* |
| 157 | * *************************************************************************** |
| 158 | * Belkin USB Serial Adapter F5U103 specific driver functions |
| 159 | * *************************************************************************** |
| 160 | */ |
| 161 | |
| 162 | #define WDR_TIMEOUT 5000 /* default urb timeout */ |
| 163 | |
| 164 | /* assumes that struct usb_serial *serial is available */ |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 165 | #define BSA_USB_CMD(c, v) usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | (c), BELKIN_SA_SET_REQUEST_TYPE, \ |
| 167 | (v), 0, NULL, 0, WDR_TIMEOUT) |
| 168 | |
| 169 | /* do some startup allocations not currently performed by usb_serial_probe() */ |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 170 | static int belkin_sa_startup(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { |
| 172 | struct usb_device *dev = serial->dev; |
| 173 | struct belkin_sa_private *priv; |
| 174 | |
| 175 | /* allocate the private data structure */ |
| 176 | priv = kmalloc(sizeof(struct belkin_sa_private), GFP_KERNEL); |
| 177 | if (!priv) |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 178 | return -1; /* error */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | /* set initial values for control structures */ |
| 180 | spin_lock_init(&priv->lock); |
| 181 | priv->control_state = 0; |
| 182 | priv->last_lsr = 0; |
| 183 | priv->last_msr = 0; |
| 184 | /* see comments at top of file */ |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 185 | priv->bad_flow_control = |
| 186 | (le16_to_cpu(dev->descriptor.bcdDevice) <= 0x0206) ? 1 : 0; |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 187 | dev_info(&dev->dev, "bcdDevice: %04x, bfc: %d\n", |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 188 | le16_to_cpu(dev->descriptor.bcdDevice), |
| 189 | priv->bad_flow_control); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | init_waitqueue_head(&serial->port[0]->write_wait); |
| 192 | usb_set_serial_port_data(serial->port[0], priv); |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 193 | |
| 194 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | } |
| 196 | |
Alan Stern | f9c99bb | 2009-06-02 11:53:55 -0400 | [diff] [blame] | 197 | static void belkin_sa_release(struct usb_serial *serial) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | int i; |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 200 | |
| 201 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Johan Hovold | 726ef42 | 2010-05-15 17:53:51 +0200 | [diff] [blame] | 203 | for (i = 0; i < serial->num_ports; ++i) |
| 204 | kfree(usb_get_serial_port_data(serial->port[i])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | |
Johan Hovold | 726ef42 | 2010-05-15 17:53:51 +0200 | [diff] [blame] | 207 | static int belkin_sa_open(struct tty_struct *tty, |
Alan Cox | a509a7e | 2009-09-19 13:13:26 -0700 | [diff] [blame] | 208 | struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | { |
Johan Hovold | f2f8b7f | 2010-05-15 17:53:52 +0200 | [diff] [blame^] | 210 | int retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 212 | dbg("%s port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | retval = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); |
| 215 | if (retval) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 216 | dev_err(&port->dev, "usb_submit_urb(read int) failed\n"); |
Johan Hovold | f2f8b7f | 2010-05-15 17:53:52 +0200 | [diff] [blame^] | 217 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Johan Hovold | f2f8b7f | 2010-05-15 17:53:52 +0200 | [diff] [blame^] | 220 | retval = usb_serial_generic_open(tty, port); |
| 221 | if (retval) |
| 222 | usb_kill_urb(port->interrupt_in_urb); |
| 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | return retval; |
Johan Hovold | 726ef42 | 2010-05-15 17:53:51 +0200 | [diff] [blame] | 225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | |
Alan Cox | 335f851 | 2009-06-11 12:26:29 +0100 | [diff] [blame] | 227 | static void belkin_sa_close(struct usb_serial_port *port) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 229 | dbg("%s port %d", __func__, port->number); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | |
Johan Hovold | f26788d | 2010-03-17 23:00:45 +0100 | [diff] [blame] | 231 | usb_serial_generic_close(port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | usb_kill_urb(port->interrupt_in_urb); |
Johan Hovold | 726ef42 | 2010-05-15 17:53:51 +0200 | [diff] [blame] | 233 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 235 | static void belkin_sa_read_int_callback(struct urb *urb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | { |
Ming Lei | cdc9779 | 2008-02-24 18:41:47 +0800 | [diff] [blame] | 237 | struct usb_serial_port *port = urb->context; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | struct belkin_sa_private *priv; |
| 239 | unsigned char *data = urb->transfer_buffer; |
| 240 | int retval; |
Greg Kroah-Hartman | f26aad2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 241 | int status = urb->status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | unsigned long flags; |
| 243 | |
Greg Kroah-Hartman | f26aad2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 244 | switch (status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | case 0: |
| 246 | /* success */ |
| 247 | break; |
| 248 | case -ECONNRESET: |
| 249 | case -ENOENT: |
| 250 | case -ESHUTDOWN: |
| 251 | /* this urb is terminated, clean up */ |
Greg Kroah-Hartman | f26aad2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 252 | dbg("%s - urb shutting down with status: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 253 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | return; |
| 255 | default: |
Greg Kroah-Hartman | f26aad2 | 2007-06-15 15:44:13 -0700 | [diff] [blame] | 256 | dbg("%s - nonzero urb status received: %d", |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 257 | __func__, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | goto exit; |
| 259 | } |
| 260 | |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 261 | usb_serial_debug_data(debug, &port->dev, __func__, |
| 262 | urb->actual_length, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | /* Handle known interrupt data */ |
| 265 | /* ignore data[0] and data[1] */ |
| 266 | |
| 267 | priv = usb_get_serial_port_data(port); |
| 268 | spin_lock_irqsave(&priv->lock, flags); |
| 269 | priv->last_msr = data[BELKIN_SA_MSR_INDEX]; |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | /* Record Control Line states */ |
| 272 | if (priv->last_msr & BELKIN_SA_MSR_DSR) |
| 273 | priv->control_state |= TIOCM_DSR; |
| 274 | else |
| 275 | priv->control_state &= ~TIOCM_DSR; |
| 276 | |
| 277 | if (priv->last_msr & BELKIN_SA_MSR_CTS) |
| 278 | priv->control_state |= TIOCM_CTS; |
| 279 | else |
| 280 | priv->control_state &= ~TIOCM_CTS; |
| 281 | |
| 282 | if (priv->last_msr & BELKIN_SA_MSR_RI) |
| 283 | priv->control_state |= TIOCM_RI; |
| 284 | else |
| 285 | priv->control_state &= ~TIOCM_RI; |
| 286 | |
| 287 | if (priv->last_msr & BELKIN_SA_MSR_CD) |
| 288 | priv->control_state |= TIOCM_CD; |
| 289 | else |
| 290 | priv->control_state &= ~TIOCM_CD; |
| 291 | |
| 292 | /* Now to report any errors */ |
| 293 | priv->last_lsr = data[BELKIN_SA_LSR_INDEX]; |
| 294 | #if 0 |
| 295 | /* |
| 296 | * fill in the flip buffer here, but I do not know the relation |
| 297 | * to the current/next receive buffer or characters. I need |
| 298 | * to look in to this before committing any code. |
| 299 | */ |
| 300 | if (priv->last_lsr & BELKIN_SA_LSR_ERR) { |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 301 | tty = tty_port_tty_get(&port->port); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | /* Overrun Error */ |
| 303 | if (priv->last_lsr & BELKIN_SA_LSR_OE) { |
| 304 | } |
| 305 | /* Parity Error */ |
| 306 | if (priv->last_lsr & BELKIN_SA_LSR_PE) { |
| 307 | } |
| 308 | /* Framing Error */ |
| 309 | if (priv->last_lsr & BELKIN_SA_LSR_FE) { |
| 310 | } |
| 311 | /* Break Indicator */ |
| 312 | if (priv->last_lsr & BELKIN_SA_LSR_BI) { |
| 313 | } |
Alan Cox | 4a90f09 | 2008-10-13 10:39:46 +0100 | [diff] [blame] | 314 | tty_kref_put(tty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 315 | } |
| 316 | #endif |
| 317 | spin_unlock_irqrestore(&priv->lock, flags); |
| 318 | exit: |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 319 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | if (retval) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 321 | dev_err(&port->dev, "%s - usb_submit_urb failed with " |
| 322 | "result %d\n", __func__, retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 325 | static void belkin_sa_set_termios(struct tty_struct *tty, |
| 326 | struct usb_serial_port *port, struct ktermios *old_termios) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | { |
| 328 | struct usb_serial *serial = port->serial; |
| 329 | struct belkin_sa_private *priv = usb_get_serial_port_data(port); |
| 330 | unsigned int iflag; |
| 331 | unsigned int cflag; |
| 332 | unsigned int old_iflag = 0; |
| 333 | unsigned int old_cflag = 0; |
| 334 | __u16 urb_value = 0; /* Will hold the new flags */ |
| 335 | unsigned long flags; |
| 336 | unsigned long control_state; |
| 337 | int bad_flow_control; |
Alan Cox | 9a8baec | 2007-06-22 14:40:18 +0100 | [diff] [blame] | 338 | speed_t baud; |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 339 | struct ktermios *termios = tty->termios; |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 340 | |
Alan Cox | 3ec466b | 2007-12-13 16:15:26 -0800 | [diff] [blame] | 341 | iflag = termios->c_iflag; |
| 342 | cflag = termios->c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Alan Cox | 3ec466b | 2007-12-13 16:15:26 -0800 | [diff] [blame] | 344 | termios->c_cflag &= ~CMSPAR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
| 346 | /* get a local copy of the current port settings */ |
| 347 | spin_lock_irqsave(&priv->lock, flags); |
| 348 | control_state = priv->control_state; |
| 349 | bad_flow_control = priv->bad_flow_control; |
| 350 | spin_unlock_irqrestore(&priv->lock, flags); |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 351 | |
Alan Cox | 9a8baec | 2007-06-22 14:40:18 +0100 | [diff] [blame] | 352 | old_iflag = old_termios->c_iflag; |
| 353 | old_cflag = old_termios->c_cflag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | /* Set the baud rate */ |
Alan Cox | 3ec466b | 2007-12-13 16:15:26 -0800 | [diff] [blame] | 356 | if ((cflag & CBAUD) != (old_cflag & CBAUD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | /* reassert DTR and (maybe) RTS on transition from B0 */ |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 358 | if ((old_cflag & CBAUD) == B0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | control_state |= (TIOCM_DTR|TIOCM_RTS); |
| 360 | if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 1) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 361 | dev_err(&port->dev, "Set DTR error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | /* don't set RTS if using hardware flow control */ |
Alan Cox | 3ec466b | 2007-12-13 16:15:26 -0800 | [diff] [blame] | 363 | if (!(old_cflag & CRTSCTS)) |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 364 | if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST |
| 365 | , 1) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 366 | dev_err(&port->dev, "Set RTS error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } |
Alan Cox | 9a8baec | 2007-06-22 14:40:18 +0100 | [diff] [blame] | 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 370 | baud = tty_get_baud_rate(tty); |
Alan Cox | 3ec466b | 2007-12-13 16:15:26 -0800 | [diff] [blame] | 371 | if (baud) { |
| 372 | urb_value = BELKIN_SA_BAUD(baud); |
| 373 | /* Clip to maximum speed */ |
| 374 | if (urb_value == 0) |
| 375 | urb_value = 1; |
| 376 | /* Turn it back into a resulting real baud rate */ |
| 377 | baud = BELKIN_SA_BAUD(urb_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Alan Cox | 3ec466b | 2007-12-13 16:15:26 -0800 | [diff] [blame] | 379 | /* Report the actual baud rate back to the caller */ |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 380 | tty_encode_baud_rate(tty, baud, baud); |
Alan Cox | 9a8baec | 2007-06-22 14:40:18 +0100 | [diff] [blame] | 381 | if (BSA_USB_CMD(BELKIN_SA_SET_BAUDRATE_REQUEST, urb_value) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 382 | dev_err(&port->dev, "Set baudrate error\n"); |
Alan Cox | 9a8baec | 2007-06-22 14:40:18 +0100 | [diff] [blame] | 383 | } else { |
| 384 | /* Disable flow control */ |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 385 | if (BSA_USB_CMD(BELKIN_SA_SET_FLOW_CTRL_REQUEST, |
| 386 | BELKIN_SA_FLOW_NONE) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 387 | dev_err(&port->dev, "Disable flowcontrol error\n"); |
Alan Cox | 9a8baec | 2007-06-22 14:40:18 +0100 | [diff] [blame] | 388 | /* Drop RTS and DTR */ |
| 389 | control_state &= ~(TIOCM_DTR | TIOCM_RTS); |
| 390 | if (BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, 0) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 391 | dev_err(&port->dev, "DTR LOW error\n"); |
Alan Cox | 9a8baec | 2007-06-22 14:40:18 +0100 | [diff] [blame] | 392 | if (BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, 0) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 393 | dev_err(&port->dev, "RTS LOW error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* set the parity */ |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 397 | if ((cflag ^ old_cflag) & (PARENB | PARODD)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | if (cflag & PARENB) |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 399 | urb_value = (cflag & PARODD) ? BELKIN_SA_PARITY_ODD |
| 400 | : BELKIN_SA_PARITY_EVEN; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | else |
| 402 | urb_value = BELKIN_SA_PARITY_NONE; |
| 403 | if (BSA_USB_CMD(BELKIN_SA_SET_PARITY_REQUEST, urb_value) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 404 | dev_err(&port->dev, "Set parity error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | /* set the number of data bits */ |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 408 | if ((cflag & CSIZE) != (old_cflag & CSIZE)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | switch (cflag & CSIZE) { |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 410 | case CS5: |
| 411 | urb_value = BELKIN_SA_DATA_BITS(5); |
| 412 | break; |
| 413 | case CS6: |
| 414 | urb_value = BELKIN_SA_DATA_BITS(6); |
| 415 | break; |
| 416 | case CS7: |
| 417 | urb_value = BELKIN_SA_DATA_BITS(7); |
| 418 | break; |
| 419 | case CS8: |
| 420 | urb_value = BELKIN_SA_DATA_BITS(8); |
| 421 | break; |
| 422 | default: dbg("CSIZE was not CS5-CS8, using default of 8"); |
| 423 | urb_value = BELKIN_SA_DATA_BITS(8); |
| 424 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | } |
| 426 | if (BSA_USB_CMD(BELKIN_SA_SET_DATA_BITS_REQUEST, urb_value) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 427 | dev_err(&port->dev, "Set data bits error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
| 429 | |
| 430 | /* set the number of stop bits */ |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 431 | if ((cflag & CSTOPB) != (old_cflag & CSTOPB)) { |
| 432 | urb_value = (cflag & CSTOPB) ? BELKIN_SA_STOP_BITS(2) |
| 433 | : BELKIN_SA_STOP_BITS(1); |
| 434 | if (BSA_USB_CMD(BELKIN_SA_SET_STOP_BITS_REQUEST, |
| 435 | urb_value) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 436 | dev_err(&port->dev, "Set stop bits error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /* Set flow control */ |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 440 | if (((iflag ^ old_iflag) & (IXOFF | IXON)) || |
| 441 | ((cflag ^ old_cflag) & CRTSCTS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | urb_value = 0; |
| 443 | if ((iflag & IXOFF) || (iflag & IXON)) |
| 444 | urb_value |= (BELKIN_SA_FLOW_OXON | BELKIN_SA_FLOW_IXON); |
| 445 | else |
| 446 | urb_value &= ~(BELKIN_SA_FLOW_OXON | BELKIN_SA_FLOW_IXON); |
| 447 | |
| 448 | if (cflag & CRTSCTS) |
| 449 | urb_value |= (BELKIN_SA_FLOW_OCTS | BELKIN_SA_FLOW_IRTS); |
| 450 | else |
| 451 | urb_value &= ~(BELKIN_SA_FLOW_OCTS | BELKIN_SA_FLOW_IRTS); |
| 452 | |
| 453 | if (bad_flow_control) |
| 454 | urb_value &= ~(BELKIN_SA_FLOW_IRTS); |
| 455 | |
| 456 | if (BSA_USB_CMD(BELKIN_SA_SET_FLOW_CTRL_REQUEST, urb_value) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 457 | dev_err(&port->dev, "Set flow control error\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | /* save off the modified port settings */ |
| 461 | spin_lock_irqsave(&priv->lock, flags); |
| 462 | priv->control_state = control_state; |
| 463 | spin_unlock_irqrestore(&priv->lock, flags); |
Johan Hovold | 726ef42 | 2010-05-15 17:53:51 +0200 | [diff] [blame] | 464 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 466 | static void belkin_sa_break_ctl(struct tty_struct *tty, int break_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 468 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | struct usb_serial *serial = port->serial; |
| 470 | |
| 471 | if (BSA_USB_CMD(BELKIN_SA_SET_BREAK_REQUEST, break_state ? 1 : 0) < 0) |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 472 | dev_err(&port->dev, "Set break_ctl %d\n", break_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } |
| 474 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 475 | static int belkin_sa_tiocmget(struct tty_struct *tty, struct file *file) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 477 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | struct belkin_sa_private *priv = usb_get_serial_port_data(port); |
| 479 | unsigned long control_state; |
| 480 | unsigned long flags; |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 481 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 482 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
| 484 | spin_lock_irqsave(&priv->lock, flags); |
| 485 | control_state = priv->control_state; |
| 486 | spin_unlock_irqrestore(&priv->lock, flags); |
| 487 | |
| 488 | return control_state; |
| 489 | } |
| 490 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 491 | static int belkin_sa_tiocmset(struct tty_struct *tty, struct file *file, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | unsigned int set, unsigned int clear) |
| 493 | { |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 494 | struct usb_serial_port *port = tty->driver_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | struct usb_serial *serial = port->serial; |
| 496 | struct belkin_sa_private *priv = usb_get_serial_port_data(port); |
| 497 | unsigned long control_state; |
| 498 | unsigned long flags; |
| 499 | int retval; |
| 500 | int rts = 0; |
| 501 | int dtr = 0; |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 502 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 503 | dbg("%s", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
| 505 | spin_lock_irqsave(&priv->lock, flags); |
| 506 | control_state = priv->control_state; |
| 507 | |
| 508 | if (set & TIOCM_RTS) { |
| 509 | control_state |= TIOCM_RTS; |
| 510 | rts = 1; |
| 511 | } |
| 512 | if (set & TIOCM_DTR) { |
| 513 | control_state |= TIOCM_DTR; |
| 514 | dtr = 1; |
| 515 | } |
| 516 | if (clear & TIOCM_RTS) { |
| 517 | control_state &= ~TIOCM_RTS; |
| 518 | rts = 0; |
| 519 | } |
| 520 | if (clear & TIOCM_DTR) { |
| 521 | control_state &= ~TIOCM_DTR; |
| 522 | dtr = 0; |
| 523 | } |
| 524 | |
| 525 | priv->control_state = control_state; |
| 526 | spin_unlock_irqrestore(&priv->lock, flags); |
| 527 | |
| 528 | retval = BSA_USB_CMD(BELKIN_SA_SET_RTS_REQUEST, rts); |
| 529 | if (retval < 0) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 530 | dev_err(&port->dev, "Set RTS error %d\n", retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | goto exit; |
| 532 | } |
| 533 | |
| 534 | retval = BSA_USB_CMD(BELKIN_SA_SET_DTR_REQUEST, dtr); |
| 535 | if (retval < 0) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 536 | dev_err(&port->dev, "Set DTR error %d\n", retval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | goto exit; |
| 538 | } |
| 539 | exit: |
| 540 | return retval; |
| 541 | } |
| 542 | |
| 543 | |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 544 | static int __init belkin_sa_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 545 | { |
| 546 | int retval; |
| 547 | retval = usb_serial_register(&belkin_device); |
| 548 | if (retval) |
| 549 | goto failed_usb_serial_register; |
| 550 | retval = usb_register(&belkin_driver); |
| 551 | if (retval) |
| 552 | goto failed_usb_register; |
Greg Kroah-Hartman | c197a8d | 2008-08-18 13:21:04 -0700 | [diff] [blame] | 553 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" |
| 554 | DRIVER_DESC "\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | return 0; |
| 556 | failed_usb_register: |
| 557 | usb_serial_deregister(&belkin_device); |
| 558 | failed_usb_serial_register: |
| 559 | return retval; |
| 560 | } |
| 561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | static void __exit belkin_sa_exit (void) |
| 563 | { |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 564 | usb_deregister(&belkin_driver); |
Alan Cox | 95da310 | 2008-07-22 11:09:07 +0100 | [diff] [blame] | 565 | usb_serial_deregister(&belkin_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 569 | module_init(belkin_sa_init); |
| 570 | module_exit(belkin_sa_exit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Alan Cox | b69c149 | 2008-07-22 11:09:39 +0100 | [diff] [blame] | 572 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 573 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 574 | MODULE_VERSION(DRIVER_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | MODULE_LICENSE("GPL"); |
| 576 | |
| 577 | module_param(debug, bool, S_IRUGO | S_IWUSR); |
| 578 | MODULE_PARM_DESC(debug, "Debug enabled or not"); |