aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-07-22 06:15:54 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 16:03:26 -0400
commitf89d0dff2507b6bd486b7db59a5f6a733fbfaa12 (patch)
tree4c0b58eb4ad62899b41dd7aa954d1e37eb6c8329 /drivers/usb/serial
parent19e58fae0c8f197d80fcea338b94fb5740369bc1 (diff)
tty-usb-omninet: Coding style
Signed-off-by: Alan Cox <alan@redhat.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/usb/serial')
-rw-r--r--drivers/usb/serial/omninet.c160
1 files changed, 87 insertions, 73 deletions
diff --git a/drivers/usb/serial/omninet.c b/drivers/usb/serial/omninet.c
index 5a2d045562f0..5a76f327ef52 100644
--- a/drivers/usb/serial/omninet.c
+++ b/drivers/usb/serial/omninet.c
@@ -5,26 +5,28 @@
5 * modify it under the terms of the GNU General Public License version 5 * modify it under the terms of the GNU General Public License version
6 * 2 as published by the Free Software Foundation. 6 * 2 as published by the Free Software Foundation.
7 * 7 *
8 * See Documentation/usb/usb-serial.txt for more information on using this driver 8 * See Documentation/usb/usb-serial.txt for more information on using this
9 * driver
9 * 10 *
10 * Please report both successes and troubles to the author at omninet@kroah.com 11 * Please report both successes and troubles to the author at omninet@kroah.com
11 * 12 *
12 * (05/30/2001) gkh 13 * (05/30/2001) gkh
13 * switched from using spinlock to a semaphore, which fixes lots of problems. 14 * switched from using spinlock to a semaphore, which fixes lots of
15 * problems.
14 * 16 *
15 * (04/08/2001) gb 17 * (04/08/2001) gb
16 * Identify version on module load. 18 * Identify version on module load.
17 * 19 *
18 * (11/01/2000) Adam J. Richter 20 * (11/01/2000) Adam J. Richter
19 * usb_device_id table support 21 * usb_device_id table support
20 * 22 *
21 * (10/05/2000) gkh 23 * (10/05/2000) gkh
22 * Fixed bug with urb->dev not being set properly, now that the usb 24 * Fixed bug with urb->dev not being set properly, now that the usb
23 * core needs it. 25 * core needs it.
24 * 26 *
25 * (08/28/2000) gkh 27 * (08/28/2000) gkh
26 * Added locks for SMP safeness. 28 * Added locks for SMP safeness.
27 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more 29 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
28 * than once. 30 * than once.
29 * Fixed potential race in omninet_write_bulk_callback 31 * Fixed potential race in omninet_write_bulk_callback
30 * 32 *
@@ -43,7 +45,7 @@
43#include <linux/tty_flip.h> 45#include <linux/tty_flip.h>
44#include <linux/module.h> 46#include <linux/module.h>
45#include <linux/spinlock.h> 47#include <linux/spinlock.h>
46#include <asm/uaccess.h> 48#include <linux/uaccess.h>
47#include <linux/usb.h> 49#include <linux/usb.h>
48#include <linux/usb/serial.h> 50#include <linux/usb/serial.h>
49 51
@@ -58,25 +60,29 @@ static int debug;
58 60
59#define ZYXEL_VENDOR_ID 0x0586 61#define ZYXEL_VENDOR_ID 0x0586
60#define ZYXEL_OMNINET_ID 0x1000 62#define ZYXEL_OMNINET_ID 0x1000
61#define BT_IGNITIONPRO_ID 0x2000 /* This one seems to be a re-branded ZyXEL device */ 63/* This one seems to be a re-branded ZyXEL device */
64#define BT_IGNITIONPRO_ID 0x2000
62 65
63/* function prototypes */ 66/* function prototypes */
64static int omninet_open (struct tty_struct *tty, struct usb_serial_port *port, struct file *filp); 67static int omninet_open(struct tty_struct *tty, struct usb_serial_port *port,
65static void omninet_close (struct tty_struct *tty, struct usb_serial_port *port, struct file *filp); 68 struct file *filp);
66static void omninet_read_bulk_callback (struct urb *urb); 69static void omninet_close(struct tty_struct *tty, struct usb_serial_port *port,
67static void omninet_write_bulk_callback (struct urb *urb); 70 struct file *filp);
68static int omninet_write (struct tty_struct *tty, struct usb_serial_port *port, const unsigned char *buf, int count); 71static void omninet_read_bulk_callback(struct urb *urb);
69static int omninet_write_room (struct tty_struct *tty); 72static void omninet_write_bulk_callback(struct urb *urb);
70static void omninet_shutdown (struct usb_serial *serial); 73static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
71static int omninet_attach (struct usb_serial *serial); 74 const unsigned char *buf, int count);
72 75static int omninet_write_room(struct tty_struct *tty);
73static struct usb_device_id id_table [] = { 76static void omninet_shutdown(struct usb_serial *serial);
77static int omninet_attach(struct usb_serial *serial);
78
79static struct usb_device_id id_table[] = {
74 { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) }, 80 { USB_DEVICE(ZYXEL_VENDOR_ID, ZYXEL_OMNINET_ID) },
75 { USB_DEVICE(ZYXEL_VENDOR_ID, BT_IGNITIONPRO_ID) }, 81 { USB_DEVICE(ZYXEL_VENDOR_ID, BT_IGNITIONPRO_ID) },
76 { } /* Terminating entry */ 82 { } /* Terminating entry */
77}; 83};
78 84
79MODULE_DEVICE_TABLE (usb, id_table); 85MODULE_DEVICE_TABLE(usb, id_table);
80 86
81static struct usb_driver omninet_driver = { 87static struct usb_driver omninet_driver = {
82 .name = "omninet", 88 .name = "omninet",
@@ -130,27 +136,26 @@ static struct usb_serial_driver zyxel_omninet_device = {
130 * 136 *
131 */ 137 */
132 138
133struct omninet_header 139struct omninet_header {
134{
135 __u8 oh_seq; 140 __u8 oh_seq;
136 __u8 oh_len; 141 __u8 oh_len;
137 __u8 oh_xxx; 142 __u8 oh_xxx;
138 __u8 oh_pad; 143 __u8 oh_pad;
139}; 144};
140 145
141struct omninet_data 146struct omninet_data {
142{ 147 __u8 od_outseq; /* Sequence number for bulk_out URBs */
143 __u8 od_outseq; // Sequence number for bulk_out URBs
144}; 148};
145 149
146static int omninet_attach (struct usb_serial *serial) 150static int omninet_attach(struct usb_serial *serial)
147{ 151{
148 struct omninet_data *od; 152 struct omninet_data *od;
149 struct usb_serial_port *port = serial->port[0]; 153 struct usb_serial_port *port = serial->port[0];
150 154
151 od = kmalloc( sizeof(struct omninet_data), GFP_KERNEL ); 155 od = kmalloc(sizeof(struct omninet_data), GFP_KERNEL);
152 if( !od ) { 156 if (!od) {
153 err("%s- kmalloc(%Zd) failed.", __func__, sizeof(struct omninet_data)); 157 err("%s- kmalloc(%Zd) failed.",
158 __func__, sizeof(struct omninet_data));
154 return -ENOMEM; 159 return -ENOMEM;
155 } 160 }
156 usb_set_serial_port_data(port, od); 161 usb_set_serial_port_data(port, od);
@@ -170,20 +175,21 @@ static int omninet_open(struct tty_struct *tty,
170 wport->port.tty = tty; /* FIXME */ 175 wport->port.tty = tty; /* FIXME */
171 176
172 /* Start reading from the device */ 177 /* Start reading from the device */
173 usb_fill_bulk_urb(port->read_urb, serial->dev, 178 usb_fill_bulk_urb(port->read_urb, serial->dev,
174 usb_rcvbulkpipe(serial->dev, port->bulk_in_endpointAddress), 179 usb_rcvbulkpipe(serial->dev,
175 port->read_urb->transfer_buffer, port->read_urb->transfer_buffer_length, 180 port->bulk_in_endpointAddress),
176 omninet_read_bulk_callback, port); 181 port->read_urb->transfer_buffer,
182 port->read_urb->transfer_buffer_length,
183 omninet_read_bulk_callback, port);
177 result = usb_submit_urb(port->read_urb, GFP_KERNEL); 184 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
178 if (result) { 185 if (result)
179 err("%s - failed submitting read urb, error %d", __func__, result); 186 err("%s - failed submitting read urb, error %d",
180 } 187 __func__, result);
181
182 return result; 188 return result;
183} 189}
184 190
185static void omninet_close(struct tty_struct *tty, 191static void omninet_close(struct tty_struct *tty,
186 struct usb_serial_port *port, struct file * filp) 192 struct usb_serial_port *port, struct file *filp)
187{ 193{
188 dbg("%s - port %d", __func__, port->number); 194 dbg("%s - port %d", __func__, port->number);
189 usb_kill_urb(port->read_urb); 195 usb_kill_urb(port->read_urb);
@@ -194,7 +200,7 @@ static void omninet_close(struct tty_struct *tty,
194#define OMNINET_HEADERLEN sizeof(struct omninet_header) 200#define OMNINET_HEADERLEN sizeof(struct omninet_header)
195#define OMNINET_BULKOUTSIZE (64 - OMNINET_HEADERLEN) 201#define OMNINET_BULKOUTSIZE (64 - OMNINET_HEADERLEN)
196 202
197static void omninet_read_bulk_callback (struct urb *urb) 203static void omninet_read_bulk_callback(struct urb *urb)
198{ 204{
199 struct usb_serial_port *port = urb->context; 205 struct usb_serial_port *port = urb->context;
200 unsigned char *data = urb->transfer_buffer; 206 unsigned char *data = urb->transfer_buffer;
@@ -211,31 +217,34 @@ static void omninet_read_bulk_callback (struct urb *urb)
211 return; 217 return;
212 } 218 }
213 219
214 if ((debug) && (header->oh_xxx != 0x30)) { 220 if (debug && header->oh_xxx != 0x30) {
215 if (urb->actual_length) { 221 if (urb->actual_length) {
216 printk (KERN_DEBUG __FILE__ ": omninet_read %d: ", header->oh_len); 222 printk(KERN_DEBUG __FILE__
217 for (i = 0; i < (header->oh_len + OMNINET_HEADERLEN); i++) { 223 ": omninet_read %d: ", header->oh_len);
218 printk ("%.2x ", data[i]); 224 for (i = 0; i < (header->oh_len +
219 } 225 OMNINET_HEADERLEN); i++)
220 printk ("\n"); 226 printk("%.2x ", data[i]);
227 printk("\n");
221 } 228 }
222 } 229 }
223 230
224 if (urb->actual_length && header->oh_len) { 231 if (urb->actual_length && header->oh_len) {
225 for (i = 0; i < header->oh_len; i++) { 232 for (i = 0; i < header->oh_len; i++)
226 tty_insert_flip_char(port->port.tty, data[OMNINET_DATAOFFSET + i], 0); 233 tty_insert_flip_char(port->port.tty,
227 } 234 data[OMNINET_DATAOFFSET + i], 0);
228 tty_flip_buffer_push(port->port.tty); 235 tty_flip_buffer_push(port->port.tty);
229 } 236 }
230 237
231 /* Continue trying to always read */ 238 /* Continue trying to always read */
232 usb_fill_bulk_urb(urb, port->serial->dev, 239 usb_fill_bulk_urb(urb, port->serial->dev,
233 usb_rcvbulkpipe(port->serial->dev, port->bulk_in_endpointAddress), 240 usb_rcvbulkpipe(port->serial->dev,
234 urb->transfer_buffer, urb->transfer_buffer_length, 241 port->bulk_in_endpointAddress),
235 omninet_read_bulk_callback, port); 242 urb->transfer_buffer, urb->transfer_buffer_length,
243 omninet_read_bulk_callback, port);
236 result = usb_submit_urb(urb, GFP_ATOMIC); 244 result = usb_submit_urb(urb, GFP_ATOMIC);
237 if (result) 245 if (result)
238 err("%s - failed resubmitting read urb, error %d", __func__, result); 246 err("%s - failed resubmitting read urb, error %d",
247 __func__, result);
239 248
240 return; 249 return;
241} 250}
@@ -243,11 +252,12 @@ static void omninet_read_bulk_callback (struct urb *urb)
243static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port, 252static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
244 const unsigned char *buf, int count) 253 const unsigned char *buf, int count)
245{ 254{
246 struct usb_serial *serial = port->serial; 255 struct usb_serial *serial = port->serial;
247 struct usb_serial_port *wport = serial->port[1]; 256 struct usb_serial_port *wport = serial->port[1];
248 257
249 struct omninet_data *od = usb_get_serial_port_data(port); 258 struct omninet_data *od = usb_get_serial_port_data(port);
250 struct omninet_header *header = (struct omninet_header *) wport->write_urb->transfer_buffer; 259 struct omninet_header *header = (struct omninet_header *)
260 wport->write_urb->transfer_buffer;
251 261
252 int result; 262 int result;
253 263
@@ -255,7 +265,7 @@ static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
255 265
256 if (count == 0) { 266 if (count == 0) {
257 dbg("%s - write request of 0 bytes", __func__); 267 dbg("%s - write request of 0 bytes", __func__);
258 return (0); 268 return 0;
259 } 269 }
260 270
261 spin_lock_bh(&wport->lock); 271 spin_lock_bh(&wport->lock);
@@ -269,9 +279,11 @@ static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
269 279
270 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count; 280 count = (count > OMNINET_BULKOUTSIZE) ? OMNINET_BULKOUTSIZE : count;
271 281
272 memcpy (wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET, buf, count); 282 memcpy(wport->write_urb->transfer_buffer + OMNINET_DATAOFFSET,
283 buf, count);
273 284
274 usb_serial_debug_data(debug, &port->dev, __func__, count, wport->write_urb->transfer_buffer); 285 usb_serial_debug_data(debug, &port->dev, __func__, count,
286 wport->write_urb->transfer_buffer);
275 287
276 header->oh_seq = od->od_outseq++; 288 header->oh_seq = od->od_outseq++;
277 header->oh_len = count; 289 header->oh_len = count;
@@ -285,7 +297,8 @@ static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
285 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC); 297 result = usb_submit_urb(wport->write_urb, GFP_ATOMIC);
286 if (result) { 298 if (result) {
287 wport->write_urb_busy = 0; 299 wport->write_urb_busy = 0;
288 err("%s - failed submitting write urb, error %d", __func__, result); 300 err("%s - failed submitting write urb, error %d",
301 __func__, result);
289 } else 302 } else
290 result = count; 303 result = count;
291 304
@@ -293,7 +306,7 @@ static int omninet_write(struct tty_struct *tty, struct usb_serial_port *port,
293} 306}
294 307
295 308
296static int omninet_write_room (struct tty_struct *tty) 309static int omninet_write_room(struct tty_struct *tty)
297{ 310{
298 struct usb_serial_port *port = tty->driver_data; 311 struct usb_serial_port *port = tty->driver_data;
299 struct usb_serial *serial = port->serial; 312 struct usb_serial *serial = port->serial;
@@ -307,12 +320,13 @@ static int omninet_write_room (struct tty_struct *tty)
307 320
308 dbg("%s - returns %d", __func__, room); 321 dbg("%s - returns %d", __func__, room);
309 322
310 return (room); 323 return room;
311} 324}
312 325
313static void omninet_write_bulk_callback (struct urb *urb) 326static void omninet_write_bulk_callback(struct urb *urb)
314{ 327{
315/* struct omninet_header *header = (struct omninet_header *) urb->transfer_buffer; */ 328/* struct omninet_header *header = (struct omninet_header *)
329 urb->transfer_buffer; */
316 struct usb_serial_port *port = urb->context; 330 struct usb_serial_port *port = urb->context;
317 int status = urb->status; 331 int status = urb->status;
318 332
@@ -329,18 +343,18 @@ static void omninet_write_bulk_callback (struct urb *urb)
329} 343}
330 344
331 345
332static void omninet_shutdown (struct usb_serial *serial) 346static void omninet_shutdown(struct usb_serial *serial)
333{ 347{
334 struct usb_serial_port *wport = serial->port[1]; 348 struct usb_serial_port *wport = serial->port[1];
335 struct usb_serial_port *port = serial->port[0]; 349 struct usb_serial_port *port = serial->port[0];
336 dbg ("%s", __func__); 350 dbg("%s", __func__);
337 351
338 usb_kill_urb(wport->write_urb); 352 usb_kill_urb(wport->write_urb);
339 kfree(usb_get_serial_port_data(port)); 353 kfree(usb_get_serial_port_data(port));
340} 354}
341 355
342 356
343static int __init omninet_init (void) 357static int __init omninet_init(void)
344{ 358{
345 int retval; 359 int retval;
346 retval = usb_serial_register(&zyxel_omninet_device); 360 retval = usb_serial_register(&zyxel_omninet_device);
@@ -358,18 +372,18 @@ failed_usb_serial_register:
358} 372}
359 373
360 374
361static void __exit omninet_exit (void) 375static void __exit omninet_exit(void)
362{ 376{
363 usb_deregister (&omninet_driver); 377 usb_deregister(&omninet_driver);
364 usb_serial_deregister (&zyxel_omninet_device); 378 usb_serial_deregister(&zyxel_omninet_device);
365} 379}
366 380
367 381
368module_init(omninet_init); 382module_init(omninet_init);
369module_exit(omninet_exit); 383module_exit(omninet_exit);
370 384
371MODULE_AUTHOR( DRIVER_AUTHOR ); 385MODULE_AUTHOR(DRIVER_AUTHOR);
372MODULE_DESCRIPTION( DRIVER_DESC ); 386MODULE_DESCRIPTION(DRIVER_DESC);
373MODULE_LICENSE("GPL"); 387MODULE_LICENSE("GPL");
374 388
375module_param(debug, bool, S_IRUGO | S_IWUSR); 389module_param(debug, bool, S_IRUGO | S_IWUSR);