aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/option.c
diff options
context:
space:
mode:
authorAndrew Morton <akpm@osdl.org>2005-07-27 04:08:30 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-09-08 19:22:15 -0400
commit7bb75aeeeec7417a961920b3f63a83007475260f (patch)
treef96fc9e827db52efe44ca7822c3fbb5f63db8b08 /drivers/usb/serial/option.c
parentb9db07fba7f113764d7379b0f68324a9a5450306 (diff)
[PATCH] USB: option card driver coding style tweaks
Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/serial/option.c')
-rw-r--r--drivers/usb/serial/option.c195
1 files changed, 89 insertions, 106 deletions
diff --git a/drivers/usb/serial/option.c b/drivers/usb/serial/option.c
index e9256408757f..4f985f43e79e 100644
--- a/drivers/usb/serial/option.c
+++ b/drivers/usb/serial/option.c
@@ -45,29 +45,29 @@
45#include "usb-serial.h" 45#include "usb-serial.h"
46 46
47/* Function prototypes */ 47/* Function prototypes */
48static int option_open (struct usb_serial_port *port, struct file *filp); 48static int option_open(struct usb_serial_port *port, struct file *filp);
49static void option_close (struct usb_serial_port *port, struct file *filp); 49static void option_close(struct usb_serial_port *port, struct file *filp);
50static int option_startup (struct usb_serial *serial); 50static int option_startup(struct usb_serial *serial);
51static void option_shutdown (struct usb_serial *serial); 51static void option_shutdown(struct usb_serial *serial);
52static void option_rx_throttle (struct usb_serial_port *port); 52static void option_rx_throttle(struct usb_serial_port *port);
53static void option_rx_unthrottle (struct usb_serial_port *port); 53static void option_rx_unthrottle(struct usb_serial_port *port);
54static int option_write_room (struct usb_serial_port *port); 54static int option_write_room(struct usb_serial_port *port);
55 55
56static void option_instat_callback(struct urb *urb, struct pt_regs *regs); 56static void option_instat_callback(struct urb *urb, struct pt_regs *regs);
57 57
58static int option_write (struct usb_serial_port *port, 58static int option_write(struct usb_serial_port *port,
59 const unsigned char *buf, int count); 59 const unsigned char *buf, int count);
60 60
61static int option_chars_in_buffer (struct usb_serial_port *port); 61static int option_chars_in_buffer(struct usb_serial_port *port);
62static int option_ioctl (struct usb_serial_port *port, struct file *file, 62static int option_ioctl(struct usb_serial_port *port, struct file *file,
63 unsigned int cmd, unsigned long arg); 63 unsigned int cmd, unsigned long arg);
64static void option_set_termios (struct usb_serial_port *port, 64static void option_set_termios(struct usb_serial_port *port,
65 struct termios *old); 65 struct termios *old);
66static void option_break_ctl (struct usb_serial_port *port, int break_state); 66static void option_break_ctl(struct usb_serial_port *port, int break_state);
67static int option_tiocmget (struct usb_serial_port *port, struct file *file); 67static int option_tiocmget(struct usb_serial_port *port, struct file *file);
68static int option_tiocmset (struct usb_serial_port *port, struct file *file, 68static int option_tiocmset(struct usb_serial_port *port, struct file *file,
69 unsigned int set, unsigned int clear); 69 unsigned int set, unsigned int clear);
70static int option_send_setup (struct usb_serial_port *port); 70static int option_send_setup(struct usb_serial_port *port);
71 71
72/* Vendor and product IDs */ 72/* Vendor and product IDs */
73#define OPTION_VENDOR_ID 0x0AF0 73#define OPTION_VENDOR_ID 0x0AF0
@@ -76,7 +76,6 @@ static int option_send_setup (struct usb_serial_port *port);
76#define OPTION_PRODUCT_FUSION 0x6000 76#define OPTION_PRODUCT_FUSION 0x6000
77#define OPTION_PRODUCT_FUSION2 0x6300 77#define OPTION_PRODUCT_FUSION2 0x6300
78 78
79
80static struct usb_device_id option_ids[] = { 79static struct usb_device_id option_ids[] = {
81 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) }, 80 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_OLD) },
82 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) }, 81 { USB_DEVICE(OPTION_VENDOR_ID, OPTION_PRODUCT_FUSION) },
@@ -129,7 +128,6 @@ static int debug;
129#define debug 0 128#define debug 0
130#endif 129#endif
131 130
132
133/* per port private data */ 131/* per port private data */
134 132
135#define N_IN_URB 4 133#define N_IN_URB 4
@@ -156,10 +154,8 @@ struct option_port_private {
156 unsigned long tx_start_time[N_OUT_URB]; 154 unsigned long tx_start_time[N_OUT_URB];
157}; 155};
158 156
159
160/* Functions used by new usb-serial code. */ 157/* Functions used by new usb-serial code. */
161static int __init 158static int __init option_init(void)
162option_init (void)
163{ 159{
164 int retval; 160 int retval;
165 retval = usb_serial_register(&option_3port_device); 161 retval = usb_serial_register(&option_3port_device);
@@ -179,8 +175,7 @@ failed_3port_device_register:
179 return retval; 175 return retval;
180} 176}
181 177
182static void __exit 178static void __exit option_exit(void)
183option_exit (void)
184{ 179{
185 usb_deregister (&option_driver); 180 usb_deregister (&option_driver);
186 usb_serial_deregister (&option_3port_device); 181 usb_serial_deregister (&option_3port_device);
@@ -189,39 +184,31 @@ option_exit (void)
189module_init(option_init); 184module_init(option_init);
190module_exit(option_exit); 185module_exit(option_exit);
191 186
192static void 187static void option_rx_throttle(struct usb_serial_port *port)
193option_rx_throttle (struct usb_serial_port *port)
194{ 188{
195 dbg("%s", __FUNCTION__); 189 dbg("%s", __FUNCTION__);
196} 190}
197 191
198 192static void option_rx_unthrottle(struct usb_serial_port *port)
199static void
200option_rx_unthrottle (struct usb_serial_port *port)
201{ 193{
202 dbg("%s", __FUNCTION__); 194 dbg("%s", __FUNCTION__);
203} 195}
204 196
205 197static void option_break_ctl(struct usb_serial_port *port, int break_state)
206static void
207option_break_ctl (struct usb_serial_port *port, int break_state)
208{ 198{
209 /* Unfortunately, I don't know how to send a break */ 199 /* Unfortunately, I don't know how to send a break */
210 dbg("%s", __FUNCTION__); 200 dbg("%s", __FUNCTION__);
211} 201}
212 202
213 203static void option_set_termios(struct usb_serial_port *port,
214static void 204 struct termios *old_termios)
215option_set_termios (struct usb_serial_port *port,
216 struct termios *old_termios)
217{ 205{
218 dbg("%s", __FUNCTION__); 206 dbg("%s", __FUNCTION__);
219 207
220 option_send_setup(port); 208 option_send_setup(port);
221} 209}
222 210
223static int 211static int option_tiocmget(struct usb_serial_port *port, struct file *file)
224option_tiocmget (struct usb_serial_port *port, struct file *file)
225{ 212{
226 unsigned int value; 213 unsigned int value;
227 struct option_port_private *portdata; 214 struct option_port_private *portdata;
@@ -238,9 +225,8 @@ option_tiocmget (struct usb_serial_port *port, struct file *file)
238 return value; 225 return value;
239} 226}
240 227
241static int 228static int option_tiocmset(struct usb_serial_port *port, struct file *file,
242option_tiocmset (struct usb_serial_port *port, struct file *file, 229 unsigned int set, unsigned int clear)
243 unsigned int set, unsigned int clear)
244{ 230{
245 struct option_port_private *portdata; 231 struct option_port_private *portdata;
246 232
@@ -258,17 +244,15 @@ option_tiocmset (struct usb_serial_port *port, struct file *file,
258 return option_send_setup(port); 244 return option_send_setup(port);
259} 245}
260 246
261static int 247static int option_ioctl(struct usb_serial_port *port, struct file *file,
262option_ioctl (struct usb_serial_port *port, struct file *file, 248 unsigned int cmd, unsigned long arg)
263 unsigned int cmd, unsigned long arg)
264{ 249{
265 return -ENOIOCTLCMD; 250 return -ENOIOCTLCMD;
266} 251}
267 252
268/* Write */ 253/* Write */
269static int 254static int option_write(struct usb_serial_port *port,
270option_write (struct usb_serial_port *port, 255 const unsigned char *buf, int count)
271 const unsigned char *buf, int count)
272{ 256{
273 struct option_port_private *portdata; 257 struct option_port_private *portdata;
274 int i; 258 int i;
@@ -291,16 +275,19 @@ option_write (struct usb_serial_port *port,
291 if (this_urb->status == -EINPROGRESS) { 275 if (this_urb->status == -EINPROGRESS) {
292 if (this_urb->transfer_flags & URB_ASYNC_UNLINK) 276 if (this_urb->transfer_flags & URB_ASYNC_UNLINK)
293 continue; 277 continue;
294 if (time_before(jiffies, portdata->tx_start_time[i] + 10 * HZ)) 278 if (time_before(jiffies,
279 portdata->tx_start_time[i] + 10 * HZ))
295 continue; 280 continue;
296 this_urb->transfer_flags |= URB_ASYNC_UNLINK; 281 this_urb->transfer_flags |= URB_ASYNC_UNLINK;
297 usb_unlink_urb(this_urb); 282 usb_unlink_urb(this_urb);
298 continue; 283 continue;
299 } 284 }
300 if (this_urb->status != 0) 285 if (this_urb->status != 0)
301 dbg("usb_write %p failed (err=%d)", this_urb, this_urb->status); 286 dbg("usb_write %p failed (err=%d)",
287 this_urb, this_urb->status);
302 288
303 dbg("%s: endpoint %d buf %d", __FUNCTION__, usb_pipeendpoint(this_urb->pipe), i); 289 dbg("%s: endpoint %d buf %d", __FUNCTION__,
290 usb_pipeendpoint(this_urb->pipe), i);
304 291
305 /* send the data */ 292 /* send the data */
306 memcpy (this_urb->transfer_buffer, buf, todo); 293 memcpy (this_urb->transfer_buffer, buf, todo);
@@ -310,7 +297,9 @@ option_write (struct usb_serial_port *port,
310 this_urb->dev = port->serial->dev; 297 this_urb->dev = port->serial->dev;
311 err = usb_submit_urb(this_urb, GFP_ATOMIC); 298 err = usb_submit_urb(this_urb, GFP_ATOMIC);
312 if (err) { 299 if (err) {
313 dbg("usb_submit_urb %p (write bulk) failed (%d, has %d)", this_urb, err, this_urb->status); 300 dbg("usb_submit_urb %p (write bulk) failed "
301 "(%d, has %d)", this_urb,
302 err, this_urb->status);
314 continue; 303 continue;
315 } 304 }
316 portdata->tx_start_time[i] = jiffies; 305 portdata->tx_start_time[i] = jiffies;
@@ -323,8 +312,7 @@ option_write (struct usb_serial_port *port,
323 return count; 312 return count;
324} 313}
325 314
326static void 315static void option_indat_callback(struct urb *urb, struct pt_regs *regs)
327option_indat_callback (struct urb *urb, struct pt_regs *regs)
328{ 316{
329 int i, err; 317 int i, err;
330 int endpoint; 318 int endpoint;
@@ -357,14 +345,14 @@ option_indat_callback (struct urb *urb, struct pt_regs *regs)
357 if (port->open_count && urb->status != -ESHUTDOWN) { 345 if (port->open_count && urb->status != -ESHUTDOWN) {
358 err = usb_submit_urb(urb, GFP_ATOMIC); 346 err = usb_submit_urb(urb, GFP_ATOMIC);
359 if (err) 347 if (err)
360 printk(KERN_ERR "%s: resubmit read urb failed. (%d)", __FUNCTION__, err); 348 printk(KERN_ERR "%s: resubmit read urb failed. "
349 "(%d)", __FUNCTION__, err);
361 } 350 }
362 } 351 }
363 return; 352 return;
364} 353}
365 354
366static void 355static void option_outdat_callback(struct urb *urb, struct pt_regs *regs)
367option_outdat_callback (struct urb *urb, struct pt_regs *regs)
368{ 356{
369 struct usb_serial_port *port; 357 struct usb_serial_port *port;
370 358
@@ -376,8 +364,7 @@ option_outdat_callback (struct urb *urb, struct pt_regs *regs)
376 schedule_work(&port->work); 364 schedule_work(&port->work);
377} 365}
378 366
379static void 367static void option_instat_callback(struct urb *urb, struct pt_regs *regs)
380option_instat_callback (struct urb *urb, struct pt_regs *regs)
381{ 368{
382 int err; 369 int err;
383 struct usb_serial_port *port = (struct usb_serial_port *) urb->context; 370 struct usb_serial_port *port = (struct usb_serial_port *) urb->context;
@@ -395,10 +382,12 @@ option_instat_callback (struct urb *urb, struct pt_regs *regs)
395 dbg("%s: NULL req_pkt\n", __FUNCTION__); 382 dbg("%s: NULL req_pkt\n", __FUNCTION__);
396 return; 383 return;
397 } 384 }
398 if ((req_pkt->bRequestType == 0xA1) && (req_pkt->bRequest == 0x20)) { 385 if ((req_pkt->bRequestType == 0xA1) &&
386 (req_pkt->bRequest == 0x20)) {
399 int old_dcd_state; 387 int old_dcd_state;
400 unsigned char signals = *((unsigned char *) 388 unsigned char signals = *((unsigned char *)
401 urb->transfer_buffer + sizeof(struct usb_ctrlrequest)); 389 urb->transfer_buffer +
390 sizeof(struct usb_ctrlrequest));
402 391
403 dbg("%s: signal x%x", __FUNCTION__, signals); 392 dbg("%s: signal x%x", __FUNCTION__, signals);
404 393
@@ -408,12 +397,13 @@ option_instat_callback (struct urb *urb, struct pt_regs *regs)
408 portdata->dsr_state = ((signals & 0x02) ? 1 : 0); 397 portdata->dsr_state = ((signals & 0x02) ? 1 : 0);
409 portdata->ri_state = ((signals & 0x08) ? 1 : 0); 398 portdata->ri_state = ((signals & 0x08) ? 1 : 0);
410 399
411 if (port->tty && !C_CLOCAL(port->tty) 400 if (port->tty && !C_CLOCAL(port->tty) &&
412 && old_dcd_state && !portdata->dcd_state) { 401 old_dcd_state && !portdata->dcd_state)
413 tty_hangup(port->tty); 402 tty_hangup(port->tty);
414 } 403 } else {
415 } else 404 dbg("%s: type %x req %x", __FUNCTION__,
416 dbg("%s: type %x req %x", __FUNCTION__, req_pkt->bRequestType,req_pkt->bRequest); 405 req_pkt->bRequestType,req_pkt->bRequest);
406 }
417 } else 407 } else
418 dbg("%s: error %d", __FUNCTION__, urb->status); 408 dbg("%s: error %d", __FUNCTION__, urb->status);
419 409
@@ -422,13 +412,12 @@ option_instat_callback (struct urb *urb, struct pt_regs *regs)
422 urb->dev = serial->dev; 412 urb->dev = serial->dev;
423 err = usb_submit_urb(urb, GFP_ATOMIC); 413 err = usb_submit_urb(urb, GFP_ATOMIC);
424 if (err) 414 if (err)
425 dbg("%s: resubmit intr urb failed. (%d)", __FUNCTION__, err); 415 dbg("%s: resubmit intr urb failed. (%d)",
416 __FUNCTION__, err);
426 } 417 }
427} 418}
428 419
429 420static int option_write_room(struct usb_serial_port *port)
430static int
431option_write_room (struct usb_serial_port *port)
432{ 421{
433 struct option_port_private *portdata; 422 struct option_port_private *portdata;
434 int i; 423 int i;
@@ -447,9 +436,7 @@ option_write_room (struct usb_serial_port *port)
447 return data_len; 436 return data_len;
448} 437}
449 438
450 439static int option_chars_in_buffer(struct usb_serial_port *port)
451static int
452option_chars_in_buffer (struct usb_serial_port *port)
453{ 440{
454 struct option_port_private *portdata; 441 struct option_port_private *portdata;
455 int i; 442 int i;
@@ -467,9 +454,7 @@ option_chars_in_buffer (struct usb_serial_port *port)
467 return data_len; 454 return data_len;
468} 455}
469 456
470 457static int option_open(struct usb_serial_port *port, struct file *filp)
471static int
472option_open (struct usb_serial_port *port, struct file *filp)
473{ 458{
474 struct option_port_private *portdata; 459 struct option_port_private *portdata;
475 struct usb_serial *serial = port->serial; 460 struct usb_serial *serial = port->serial;
@@ -490,17 +475,21 @@ option_open (struct usb_serial_port *port, struct file *filp)
490 if (! urb) 475 if (! urb)
491 continue; 476 continue;
492 if (urb->dev != serial->dev) { 477 if (urb->dev != serial->dev) {
493 dbg("%s: dev %p != %p", __FUNCTION__, urb->dev, serial->dev); 478 dbg("%s: dev %p != %p", __FUNCTION__,
479 urb->dev, serial->dev);
494 continue; 480 continue;
495 } 481 }
496 482
497 /* make sure endpoint data toggle is synchronized with the device */ 483 /*
498 484 * make sure endpoint data toggle is synchronized with the
485 * device
486 */
499 usb_clear_halt(urb->dev, urb->pipe); 487 usb_clear_halt(urb->dev, urb->pipe);
500 488
501 err = usb_submit_urb(urb, GFP_KERNEL); 489 err = usb_submit_urb(urb, GFP_KERNEL);
502 if (err) { 490 if (err) {
503 dbg("%s: submit urb %d failed (%d) %d", __FUNCTION__, i, err, 491 dbg("%s: submit urb %d failed (%d) %d",
492 __FUNCTION__, i, err,
504 urb->transfer_buffer_length); 493 urb->transfer_buffer_length);
505 } 494 }
506 } 495 }
@@ -511,7 +500,8 @@ option_open (struct usb_serial_port *port, struct file *filp)
511 if (! urb) 500 if (! urb)
512 continue; 501 continue;
513 urb->dev = serial->dev; 502 urb->dev = serial->dev;
514 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */ 503 /* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
504 usb_pipeout(urb->pipe), 0); */
515 } 505 }
516 506
517 port->tty->low_latency = 1; 507 port->tty->low_latency = 1;
@@ -521,8 +511,7 @@ option_open (struct usb_serial_port *port, struct file *filp)
521 return (0); 511 return (0);
522} 512}
523 513
524static inline void 514static inline void stop_urb(struct urb *urb)
525stop_urb (struct urb *urb)
526{ 515{
527 if (urb && urb->status == -EINPROGRESS) { 516 if (urb && urb->status == -EINPROGRESS) {
528 urb->transfer_flags &= ~URB_ASYNC_UNLINK; 517 urb->transfer_flags &= ~URB_ASYNC_UNLINK;
@@ -530,8 +519,7 @@ stop_urb (struct urb *urb)
530 } 519 }
531} 520}
532 521
533static void 522static void option_close(struct usb_serial_port *port, struct file *filp)
534option_close (struct usb_serial_port *port, struct file *filp)
535{ 523{
536 int i; 524 int i;
537 struct usb_serial *serial = port->serial; 525 struct usb_serial *serial = port->serial;
@@ -555,12 +543,10 @@ option_close (struct usb_serial_port *port, struct file *filp)
555 port->tty = NULL; 543 port->tty = NULL;
556} 544}
557 545
558
559/* Helper functions used by option_setup_urbs */ 546/* Helper functions used by option_setup_urbs */
560static struct urb * 547static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint,
561option_setup_urb (struct usb_serial *serial, int endpoint, 548 int dir, void *ctx, char *buf, int len,
562 int dir, void *ctx, char *buf, int len, 549 void (*callback)(struct urb *, struct pt_regs *regs))
563 void (*callback)(struct urb *, struct pt_regs *regs))
564{ 550{
565 struct urb *urb; 551 struct urb *urb;
566 552
@@ -582,8 +568,7 @@ option_setup_urb (struct usb_serial *serial, int endpoint,
582} 568}
583 569
584/* Setup urbs */ 570/* Setup urbs */
585static void 571static void option_setup_urbs(struct usb_serial *serial)
586option_setup_urbs (struct usb_serial *serial)
587{ 572{
588 int j; 573 int j;
589 struct usb_serial_port *port; 574 struct usb_serial_port *port;
@@ -609,9 +594,7 @@ option_setup_urbs (struct usb_serial *serial)
609 } 594 }
610} 595}
611 596
612 597static int option_send_setup(struct usb_serial_port *port)
613static int
614option_send_setup (struct usb_serial_port *port)
615{ 598{
616 struct usb_serial *serial = port->serial; 599 struct usb_serial *serial = port->serial;
617 struct option_port_private *portdata; 600 struct option_port_private *portdata;
@@ -627,16 +610,15 @@ option_send_setup (struct usb_serial_port *port)
627 if (portdata->rts_state) 610 if (portdata->rts_state)
628 val |= 0x02; 611 val |= 0x02;
629 612
630 return usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0), 613 return usb_control_msg(serial->dev,
631 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT); 614 usb_rcvctrlpipe(serial->dev, 0),
615 0x22,0x21,val,0,NULL,0,USB_CTRL_SET_TIMEOUT);
632 } 616 }
633 617
634 return 0; 618 return 0;
635} 619}
636 620
637 621static int option_startup(struct usb_serial *serial)
638static int
639option_startup (struct usb_serial *serial)
640{ 622{
641 int i, err; 623 int i, err;
642 struct usb_serial_port *port; 624 struct usb_serial_port *port;
@@ -647,9 +629,10 @@ option_startup (struct usb_serial *serial)
647 /* Now setup per port private data */ 629 /* Now setup per port private data */
648 for (i = 0; i < serial->num_ports; i++) { 630 for (i = 0; i < serial->num_ports; i++) {
649 port = serial->port[i]; 631 port = serial->port[i];
650 portdata = kmalloc(sizeof(struct option_port_private), GFP_KERNEL); 632 portdata = kmalloc(sizeof(*portdata), GFP_KERNEL);
651 if (!portdata) { 633 if (!portdata) {
652 dbg("%s: kmalloc for option_port_private (%d) failed!.", __FUNCTION__, i); 634 dbg("%s: kmalloc for option_port_private (%d) failed!.",
635 __FUNCTION__, i);
653 return (1); 636 return (1);
654 } 637 }
655 memset(portdata, 0, sizeof(struct option_port_private)); 638 memset(portdata, 0, sizeof(struct option_port_private));
@@ -660,7 +643,8 @@ option_startup (struct usb_serial *serial)
660 continue; 643 continue;
661 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); 644 err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL);
662 if (err) 645 if (err)
663 dbg("%s: submit irq_in urb failed %d", __FUNCTION__, err); 646 dbg("%s: submit irq_in urb failed %d",
647 __FUNCTION__, err);
664 } 648 }
665 649
666 option_setup_urbs(serial); 650 option_setup_urbs(serial);
@@ -668,8 +652,7 @@ option_startup (struct usb_serial *serial)
668 return (0); 652 return (0);
669} 653}
670 654
671static void 655static void option_shutdown(struct usb_serial *serial)
672option_shutdown (struct usb_serial *serial)
673{ 656{
674 int i, j; 657 int i, j;
675 struct usb_serial_port *port; 658 struct usb_serial_port *port;