aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-03-08 16:50:54 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-03-08 16:50:54 -0500
commitd4cbd6e990a798d21577ee2f42a3880da09edf3a (patch)
treed9a100ceeac9b70d8a59bcb440f3d2650e99f5aa /drivers/usb
parent159d4d8d5e9416dba78b84d4be10d7b1172728ee (diff)
USB: serial: metro-usb: fix up coding style errors
This fixes up all of the coding style errors, and removes the initial, unneeded comments on how to load the module and the old changelog which are no longer needed. There are still a number of coding style warnings left, I'll get to them later. Cc: Aleksey Babahin <tamerlan311@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/serial/metro-usb.c160
1 files changed, 65 insertions, 95 deletions
diff --git a/drivers/usb/serial/metro-usb.c b/drivers/usb/serial/metro-usb.c
index d22a603597e8..66e9355cfd00 100644
--- a/drivers/usb/serial/metro-usb.c
+++ b/drivers/usb/serial/metro-usb.c
@@ -1,32 +1,9 @@
1/* 1/*
2 Date Created: 9/15/2006 2 Some of this code is credited to Linux USB open source files that are
3 File Name: metro-usb.c 3 distributed with Linux.
4 Description: metro-usb.c is the drivers main source file. The driver is a USB to Serial converter.
5 The driver takes USB data and sends it to a virtual ttyUSB# serial port.
6 The driver interfaces with the usbserial.ko driver supplied by Linux.
7
8 NOTES:
9 To install the driver:
10 1. Install the usbserial.ko module supplied by Linux with: # insmod usbserial.ko
11 2. Install the metro-usb.ko module with: # insmod metro-usb.ko
12
13 Some of this code is credited to Linux USB open source files that are distributed with Linux.
14 4
15 Copyright: 2007 Metrologic Instruments. All rights reserved. 5 Copyright: 2007 Metrologic Instruments. All rights reserved.
16 Copyright: 2011 Azimut Ltd. <http://azimutrzn.ru/> 6 Copyright: 2011 Azimut Ltd. <http://azimutrzn.ru/>
17 Requirements: gedit.exe, notepad.exe
18
19 Revision History:
20
21 Date: Developer: Revisions:
22 ------------------------------------------------------------------------------
23 1/30/2007 Philip Nicastro Initial release. (v1.0.0.0)
24 2/27/2007 Philip Nicastro Changed the metrousb_read_int_callback function to use a loop with the tty_insert_flip_char function to copy each byte to the tty layer. Removed the tty_buffer_request_room and the tty_insert_flip_string function calls. These calls were not supported on Fedora.
25 2/27/2007 Philip Nicastro Released. (v1.1.0.0)
26 10/07/2011 Aleksey Babahin Update for new kernel (tested on 2.6.38)
27 Add unidirection mode support
28
29
30*/ 7*/
31 8
32#include <linux/kernel.h> 9#include <linux/kernel.h>
@@ -41,8 +18,8 @@
41#include <linux/moduleparam.h> 18#include <linux/moduleparam.h>
42#include <linux/spinlock.h> 19#include <linux/spinlock.h>
43#include <linux/errno.h> 20#include <linux/errno.h>
21#include <linux/uaccess.h>
44#include <linux/usb/serial.h> 22#include <linux/usb/serial.h>
45#include <asm/uaccess.h>
46 23
47/* Version Information */ 24/* Version Information */
48#define DRIVER_VERSION "v1.2.0.0" 25#define DRIVER_VERSION "v1.2.0.0"
@@ -59,7 +36,7 @@
59#define METROUSB_MCR_NONE 0x08 /* Deactivate DTR and RTS. */ 36#define METROUSB_MCR_NONE 0x08 /* Deactivate DTR and RTS. */
60#define METROUSB_MCR_RTS 0x0a /* Activate RTS. */ 37#define METROUSB_MCR_RTS 0x0a /* Activate RTS. */
61#define METROUSB_MCR_DTR 0x09 /* Activate DTR. */ 38#define METROUSB_MCR_DTR 0x09 /* Activate DTR. */
62#define WDR_TIMEOUT 5000 /* default urb timeout. */ 39#define WDR_TIMEOUT 5000 /* default urb timeout. */
63 40
64/* Private data structure. */ 41/* Private data structure. */
65struct metrousb_private { 42struct metrousb_private {
@@ -69,7 +46,7 @@ struct metrousb_private {
69}; 46};
70 47
71/* Device table list. */ 48/* Device table list. */
72static struct usb_device_id id_table [] = { 49static struct usb_device_id id_table[] = {
73 { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID) }, 50 { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID) },
74 { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) }, 51 { USB_DEVICE(FOCUS_VENDOR_ID, FOCUS_PRODUCT_ID_UNI) },
75 { }, /* Terminating entry. */ 52 { }, /* Terminating entry. */
@@ -80,12 +57,12 @@ MODULE_DEVICE_TABLE(usb, id_table);
80static bool debug; 57static bool debug;
81 58
82/* Function prototypes. */ 59/* Function prototypes. */
83static void metrousb_cleanup (struct usb_serial_port *port); 60static void metrousb_cleanup(struct usb_serial_port *port);
84static void metrousb_close (struct usb_serial_port *port); 61static void metrousb_close(struct usb_serial_port *port);
85static int metrousb_open (struct tty_struct *tty, struct usb_serial_port *port); 62static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port);
86static void metrousb_read_int_callback (struct urb *urb); 63static void metrousb_read_int_callback(struct urb *urb);
87static void metrousb_shutdown (struct usb_serial *serial); 64static void metrousb_shutdown(struct usb_serial *serial);
88static int metrousb_startup (struct usb_serial *serial); 65static int metrousb_startup(struct usb_serial *serial);
89static void metrousb_throttle(struct tty_struct *tty); 66static void metrousb_throttle(struct tty_struct *tty);
90static int metrousb_tiocmget(struct tty_struct *tty); 67static int metrousb_tiocmget(struct tty_struct *tty);
91static int metrousb_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear); 68static int metrousb_tiocmset(struct tty_struct *tty, unsigned int set, unsigned int clear);
@@ -105,18 +82,18 @@ static struct usb_serial_driver metrousb_device = {
105 .owner = THIS_MODULE, 82 .owner = THIS_MODULE,
106 .name = "metro-usb", 83 .name = "metro-usb",
107 }, 84 },
108 .description = "Metrologic USB to serial converter.", 85 .description = "Metrologic USB to serial converter.",
109 .id_table = id_table, 86 .id_table = id_table,
110 .num_ports = 1, 87 .num_ports = 1,
111 .open = metrousb_open, 88 .open = metrousb_open,
112 .close = metrousb_close, 89 .close = metrousb_close,
113 .read_int_callback = metrousb_read_int_callback, 90 .read_int_callback = metrousb_read_int_callback,
114 .attach = metrousb_startup, 91 .attach = metrousb_startup,
115 .release = metrousb_shutdown, 92 .release = metrousb_shutdown,
116 .throttle = metrousb_throttle, 93 .throttle = metrousb_throttle,
117 .unthrottle = metrousb_unthrottle, 94 .unthrottle = metrousb_unthrottle,
118 .tiocmget = metrousb_tiocmget, 95 .tiocmget = metrousb_tiocmget,
119 .tiocmset = metrousb_tiocmset, 96 .tiocmset = metrousb_tiocmset,
120}; 97};
121 98
122static struct usb_serial_driver * const serial_drivers[] = { 99static struct usb_serial_driver * const serial_drivers[] = {
@@ -134,7 +111,7 @@ static struct usb_serial_driver * const serial_drivers[] = {
134 Output: 111 Output:
135 int: Returns true (0) if successful, false otherwise. 112 int: Returns true (0) if successful, false otherwise.
136*/ 113*/
137static void metrousb_cleanup (struct usb_serial_port *port) 114static void metrousb_cleanup(struct usb_serial_port *port)
138{ 115{
139 dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); 116 dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number);
140 117
@@ -144,12 +121,6 @@ static void metrousb_cleanup (struct usb_serial_port *port)
144 usb_unlink_urb(port->interrupt_in_urb); 121 usb_unlink_urb(port->interrupt_in_urb);
145 usb_kill_urb(port->interrupt_in_urb); 122 usb_kill_urb(port->interrupt_in_urb);
146 } 123 }
147
148 // temp
149 // this will be needed for the write urb
150 /* Shutdown any interrupt_out_urbs. */
151 //if (serial->num_bulk_in)
152 // usb_kill_urb(port->read_urb);
153 } 124 }
154} 125}
155 126
@@ -164,7 +135,7 @@ static void metrousb_cleanup (struct usb_serial_port *port)
164 Output: 135 Output:
165 int: Returns true (0) if successful, false otherwise. 136 int: Returns true (0) if successful, false otherwise.
166*/ 137*/
167static void metrousb_close (struct usb_serial_port *port) 138static void metrousb_close(struct usb_serial_port *port)
168{ 139{
169 dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); 140 dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number);
170 metrousb_cleanup(port); 141 metrousb_cleanup(port);
@@ -181,7 +152,7 @@ static void metrousb_close (struct usb_serial_port *port)
181 Output: 152 Output:
182 int: Returns true (0) if successful, false otherwise. 153 int: Returns true (0) if successful, false otherwise.
183*/ 154*/
184static int metrousb_open (struct tty_struct *tty, struct usb_serial_port *port) 155static int metrousb_open(struct tty_struct *tty, struct usb_serial_port *port)
185{ 156{
186 struct usb_serial *serial = port->serial; 157 struct usb_serial *serial = port->serial;
187 struct metrousb_private *metro_priv = usb_get_serial_port_data(port); 158 struct metrousb_private *metro_priv = usb_get_serial_port_data(port);
@@ -207,16 +178,15 @@ static int metrousb_open (struct tty_struct *tty, struct usb_serial_port *port)
207 * through, otherwise it is scheduled, and with high data rates (like 178 * through, otherwise it is scheduled, and with high data rates (like
208 * with OHCI) data can get lost. 179 * with OHCI) data can get lost.
209 */ 180 */
210 if (tty) { 181 if (tty)
211 tty->low_latency = 1; 182 tty->low_latency = 1;
212 }
213 183
214 /* Clear the urb pipe. */ 184 /* Clear the urb pipe. */
215 usb_clear_halt(serial->dev, port->interrupt_in_urb->pipe); 185 usb_clear_halt(serial->dev, port->interrupt_in_urb->pipe);
216 186
217 /* Start reading from the device */ 187 /* Start reading from the device */
218 usb_fill_int_urb (port->interrupt_in_urb, serial->dev, 188 usb_fill_int_urb(port->interrupt_in_urb, serial->dev,
219 usb_rcvintpipe (serial->dev, port->interrupt_in_endpointAddress), 189 usb_rcvintpipe(serial->dev, port->interrupt_in_endpointAddress),
220 port->interrupt_in_urb->transfer_buffer, 190 port->interrupt_in_urb->transfer_buffer,
221 port->interrupt_in_urb->transfer_buffer_length, 191 port->interrupt_in_urb->transfer_buffer_length,
222 metrousb_read_int_callback, port, 1); 192 metrousb_read_int_callback, port, 1);
@@ -244,7 +214,7 @@ exit:
244 Output: 214 Output:
245 None: 215 None:
246*/ 216*/
247static void metrousb_read_int_callback (struct urb *urb) 217static void metrousb_read_int_callback(struct urb *urb)
248{ 218{
249 struct usb_serial_port *port = (struct usb_serial_port *)urb->context; 219 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
250 struct metrousb_private *metro_priv = usb_get_serial_port_data(port); 220 struct metrousb_private *metro_priv = usb_get_serial_port_data(port);
@@ -257,20 +227,20 @@ static void metrousb_read_int_callback (struct urb *urb)
257 dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number); 227 dbg("METRO-USB - %s - port number=%d", __FUNCTION__, port->number);
258 228
259 switch (urb->status) { 229 switch (urb->status) {
260 case 0: 230 case 0:
261 /* Success status, read from the port. */ 231 /* Success status, read from the port. */
262 break; 232 break;
263 case -ECONNRESET: 233 case -ECONNRESET:
264 case -ENOENT: 234 case -ENOENT:
265 case -ESHUTDOWN: 235 case -ESHUTDOWN:
266 /* urb has been terminated. */ 236 /* urb has been terminated. */
267 dbg("METRO-USB - %s - urb shutting down, port number=%d, error code=%d", 237 dbg("METRO-USB - %s - urb shutting down, port number=%d, error code=%d",
268 __FUNCTION__, port->number, result); 238 __FUNCTION__, port->number, result);
269 return; 239 return;
270 default: 240 default:
271 dbg("METRO-USB - %s - non-zero urb received, port number=%d, error code=%d", 241 dbg("METRO-USB - %s - non-zero urb received, port number=%d, error code=%d",
272 __FUNCTION__, port->number, result); 242 __FUNCTION__, port->number, result);
273 goto exit; 243 goto exit;
274 } 244 }
275 245
276 246
@@ -282,10 +252,10 @@ static void metrousb_read_int_callback (struct urb *urb)
282 } 252 }
283 253
284 if (tty && urb->actual_length) { 254 if (tty && urb->actual_length) {
285 // Loop through the data copying each byte to the tty layer. 255 /* Loop through the data copying each byte to the tty layer. */
286 tty_insert_flip_string(tty, data, urb->actual_length); 256 tty_insert_flip_string(tty, data, urb->actual_length);
287 257
288 // Force the data to the tty layer. 258 /* Force the data to the tty layer. */
289 tty_flip_buffer_push(tty); 259 tty_flip_buffer_push(tty);
290 } 260 }
291 tty_kref_put(tty); 261 tty_kref_put(tty);
@@ -297,11 +267,11 @@ static void metrousb_read_int_callback (struct urb *urb)
297 267
298 /* Continue trying to read if set. */ 268 /* Continue trying to read if set. */
299 if (!throttled) { 269 if (!throttled) {
300 usb_fill_int_urb (port->interrupt_in_urb, port->serial->dev, 270 usb_fill_int_urb(port->interrupt_in_urb, port->serial->dev,
301 usb_rcvintpipe (port->serial->dev, port->interrupt_in_endpointAddress), 271 usb_rcvintpipe(port->serial->dev, port->interrupt_in_endpointAddress),
302 port->interrupt_in_urb->transfer_buffer, 272 port->interrupt_in_urb->transfer_buffer,
303 port->interrupt_in_urb->transfer_buffer_length, 273 port->interrupt_in_urb->transfer_buffer_length,
304 metrousb_read_int_callback, port, 1); 274 metrousb_read_int_callback, port, 1);
305 275
306 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); 276 result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC);
307 277
@@ -314,7 +284,7 @@ static void metrousb_read_int_callback (struct urb *urb)
314 284
315exit: 285exit:
316 /* Try to resubmit the urb. */ 286 /* Try to resubmit the urb. */
317 result = usb_submit_urb (urb, GFP_ATOMIC); 287 result = usb_submit_urb(urb, GFP_ATOMIC);
318 if (result) { 288 if (result) {
319 dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d", 289 dbg("METRO-USB - %s - failed submitting interrupt in urb for port number=%d, error code=%d",
320 __FUNCTION__, port->number, result); 290 __FUNCTION__, port->number, result);
@@ -366,14 +336,14 @@ static int metrousb_set_modem_ctrl(struct usb_serial *serial, unsigned int contr
366 Output: 336 Output:
367 int: Returns true (0) if successful, false otherwise. 337 int: Returns true (0) if successful, false otherwise.
368*/ 338*/
369static void metrousb_shutdown (struct usb_serial *serial) 339static void metrousb_shutdown(struct usb_serial *serial)
370{ 340{
371 int i = 0; 341 int i = 0;
372 342
373 dbg("METRO-USB - %s", __FUNCTION__); 343 dbg("METRO-USB - %s", __FUNCTION__);
374 344
375 /* Stop reading and writing on all ports. */ 345 /* Stop reading and writing on all ports. */
376 for (i=0; i < serial->num_ports; ++i) { 346 for (i = 0; i < serial->num_ports; ++i) {
377 /* Close any open urbs. */ 347 /* Close any open urbs. */
378 metrousb_cleanup(serial->port[i]); 348 metrousb_cleanup(serial->port[i]);
379 349
@@ -409,12 +379,12 @@ static int metrousb_startup(struct usb_serial *serial)
409 port = serial->port[i]; 379 port = serial->port[i];
410 380
411 /* Declare memory. */ 381 /* Declare memory. */
412 metro_priv = (struct metrousb_private *) kmalloc (sizeof(struct metrousb_private), GFP_KERNEL); 382 metro_priv = kmalloc(sizeof(struct metrousb_private), GFP_KERNEL);
413 if (!metro_priv) 383 if (!metro_priv)
414 return -ENOMEM; 384 return -ENOMEM;
415 385
416 /* Clear memory. */ 386 /* Clear memory. */
417 memset (metro_priv, 0x00, sizeof(struct metrousb_private)); 387 memset(metro_priv, 0x00, sizeof(struct metrousb_private));
418 388
419 /* Initialize memory. */ 389 /* Initialize memory. */
420 spin_lock_init(&metro_priv->lock); 390 spin_lock_init(&metro_priv->lock);
@@ -436,7 +406,7 @@ static int metrousb_startup(struct usb_serial *serial)
436 Output: 406 Output:
437 None: 407 None:
438*/ 408*/
439static void metrousb_throttle (struct tty_struct *tty) 409static void metrousb_throttle(struct tty_struct *tty)
440{ 410{
441 struct usb_serial_port *port = tty->driver_data; 411 struct usb_serial_port *port = tty->driver_data;
442 struct metrousb_private *metro_priv = usb_get_serial_port_data(port); 412 struct metrousb_private *metro_priv = usb_get_serial_port_data(port);
@@ -461,7 +431,7 @@ static void metrousb_throttle (struct tty_struct *tty)
461 Output: 431 Output:
462 int: Returns the state of the control lines. 432 int: Returns the state of the control lines.
463*/ 433*/
464static int metrousb_tiocmget (struct tty_struct *tty) 434static int metrousb_tiocmget(struct tty_struct *tty)
465{ 435{
466 unsigned long control_state = 0; 436 unsigned long control_state = 0;
467 struct usb_serial_port *port = tty->driver_data; 437 struct usb_serial_port *port = tty->driver_data;
@@ -490,8 +460,8 @@ static int metrousb_tiocmget (struct tty_struct *tty)
490 Output: 460 Output:
491 int: Returns the state of the control lines. 461 int: Returns the state of the control lines.
492*/ 462*/
493static int metrousb_tiocmset (struct tty_struct *tty, 463static int metrousb_tiocmset(struct tty_struct *tty,
494 unsigned int set, unsigned int clear) 464 unsigned int set, unsigned int clear)
495{ 465{
496 struct usb_serial_port *port = tty->driver_data; 466 struct usb_serial_port *port = tty->driver_data;
497 struct usb_serial *serial = port->serial; 467 struct usb_serial *serial = port->serial;
@@ -504,7 +474,7 @@ static int metrousb_tiocmset (struct tty_struct *tty,
504 spin_lock_irqsave(&metro_priv->lock, flags); 474 spin_lock_irqsave(&metro_priv->lock, flags);
505 control_state = metro_priv->control_state; 475 control_state = metro_priv->control_state;
506 476
507 // Set the RTS and DTR values. 477 /* Set the RTS and DTR values. */
508 if (set & TIOCM_RTS) 478 if (set & TIOCM_RTS)
509 control_state |= TIOCM_RTS; 479 control_state |= TIOCM_RTS;
510 if (set & TIOCM_DTR) 480 if (set & TIOCM_DTR)
@@ -529,7 +499,7 @@ static int metrousb_tiocmset (struct tty_struct *tty,
529 Output: 499 Output:
530 None: 500 None:
531*/ 501*/
532static void metrousb_unthrottle (struct tty_struct *tty) 502static void metrousb_unthrottle(struct tty_struct *tty)
533{ 503{
534 struct usb_serial_port *port = tty->driver_data; 504 struct usb_serial_port *port = tty->driver_data;
535 struct metrousb_private *metro_priv = usb_get_serial_port_data(port); 505 struct metrousb_private *metro_priv = usb_get_serial_port_data(port);
@@ -555,9 +525,9 @@ static void metrousb_unthrottle (struct tty_struct *tty)
555module_usb_serial_driver(metrousb_driver, serial_drivers); 525module_usb_serial_driver(metrousb_driver, serial_drivers);
556 526
557MODULE_LICENSE("GPL"); 527MODULE_LICENSE("GPL");
558MODULE_AUTHOR( "Philip Nicastro" ); 528MODULE_AUTHOR("Philip Nicastro");
559MODULE_AUTHOR( "Aleksey Babahin <tamerlan311@gmail.com>" ); 529MODULE_AUTHOR("Aleksey Babahin <tamerlan311@gmail.com>");
560MODULE_DESCRIPTION( DRIVER_DESC ); 530MODULE_DESCRIPTION(DRIVER_DESC);
561 531
562/* Module input parameters */ 532/* Module input parameters */
563module_param(debug, bool, S_IRUGO | S_IWUSR); 533module_param(debug, bool, S_IRUGO | S_IWUSR);