aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial/cp2101.c
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-07-22 06:10:17 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 16:03:23 -0400
commitff7eb602605cc0100f089d57966fcd347e137137 (patch)
tree0abb6debffe367297ee40a71dab8588752cc701e /drivers/usb/serial/cp2101.c
parentc17ee886976b64d29ea89ee5d87751438e26025b (diff)
cp2101: coding style
Bring up to 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/cp2101.c')
-rw-r--r--drivers/usb/serial/cp2101.c315
1 files changed, 156 insertions, 159 deletions
diff --git a/drivers/usb/serial/cp2101.c b/drivers/usb/serial/cp2101.c
index 46c33fc9f6ce..442cba69cce5 100644
--- a/drivers/usb/serial/cp2101.c
+++ b/drivers/usb/serial/cp2101.c
@@ -25,7 +25,7 @@
25#include <linux/module.h> 25#include <linux/module.h>
26#include <linux/moduleparam.h> 26#include <linux/moduleparam.h>
27#include <linux/usb.h> 27#include <linux/usb.h>
28#include <asm/uaccess.h> 28#include <linux/uaccess.h>
29#include <linux/usb/serial.h> 29#include <linux/usb/serial.h>
30 30
31/* 31/*
@@ -45,12 +45,12 @@ static void cp2101_close(struct tty_struct *, struct usb_serial_port *,
45static void cp2101_get_termios(struct tty_struct *); 45static void cp2101_get_termios(struct tty_struct *);
46static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *, 46static void cp2101_set_termios(struct tty_struct *, struct usb_serial_port *,
47 struct ktermios*); 47 struct ktermios*);
48static int cp2101_tiocmget (struct tty_struct *, struct file *); 48static int cp2101_tiocmget(struct tty_struct *, struct file *);
49static int cp2101_tiocmset (struct tty_struct *, struct file *, 49static int cp2101_tiocmset(struct tty_struct *, struct file *,
50 unsigned int, unsigned int); 50 unsigned int, unsigned int);
51static void cp2101_break_ctl(struct tty_struct *, int); 51static void cp2101_break_ctl(struct tty_struct *, int);
52static int cp2101_startup (struct usb_serial *); 52static int cp2101_startup(struct usb_serial *);
53static void cp2101_shutdown(struct usb_serial*); 53static void cp2101_shutdown(struct usb_serial *);
54 54
55 55
56static int debug; 56static int debug;
@@ -96,7 +96,7 @@ static struct usb_device_id id_table [] = {
96 { } /* Terminating Entry */ 96 { } /* Terminating Entry */
97}; 97};
98 98
99MODULE_DEVICE_TABLE (usb, id_table); 99MODULE_DEVICE_TABLE(usb, id_table);
100 100
101static struct usb_driver cp2101_driver = { 101static struct usb_driver cp2101_driver = {
102 .name = "cp2101", 102 .name = "cp2101",
@@ -205,12 +205,12 @@ static int cp2101_get_config(struct usb_serial_port *port, u8 request,
205 request++; 205 request++;
206 206
207 /* Issue the request, attempting to read 'size' bytes */ 207 /* Issue the request, attempting to read 'size' bytes */
208 result = usb_control_msg (serial->dev,usb_rcvctrlpipe (serial->dev, 0), 208 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
209 request, REQTYPE_DEVICE_TO_HOST, 0x0000, 209 request, REQTYPE_DEVICE_TO_HOST, 0x0000,
210 0, buf, size, 300); 210 0, buf, size, 300);
211 211
212 /* Convert data into an array of integers */ 212 /* Convert data into an array of integers */
213 for (i=0; i<length; i++) 213 for (i = 0; i < length; i++)
214 data[i] = le32_to_cpu(buf[i]); 214 data[i] = le32_to_cpu(buf[i]);
215 215
216 kfree(buf); 216 kfree(buf);
@@ -253,12 +253,12 @@ static int cp2101_set_config(struct usb_serial_port *port, u8 request,
253 buf[i] = cpu_to_le32(data[i]); 253 buf[i] = cpu_to_le32(data[i]);
254 254
255 if (size > 2) { 255 if (size > 2) {
256 result = usb_control_msg (serial->dev, 256 result = usb_control_msg(serial->dev,
257 usb_sndctrlpipe(serial->dev, 0), 257 usb_sndctrlpipe(serial->dev, 0),
258 request, REQTYPE_HOST_TO_DEVICE, 0x0000, 258 request, REQTYPE_HOST_TO_DEVICE, 0x0000,
259 0, buf, size, 300); 259 0, buf, size, 300);
260 } else { 260 } else {
261 result = usb_control_msg (serial->dev, 261 result = usb_control_msg(serial->dev,
262 usb_sndctrlpipe(serial->dev, 0), 262 usb_sndctrlpipe(serial->dev, 0),
263 request, REQTYPE_HOST_TO_DEVICE, data[0], 263 request, REQTYPE_HOST_TO_DEVICE, data[0],
264 0, NULL, 0, 300); 264 0, NULL, 0, 300);
@@ -274,7 +274,7 @@ static int cp2101_set_config(struct usb_serial_port *port, u8 request,
274 } 274 }
275 275
276 /* Single data value */ 276 /* Single data value */
277 result = usb_control_msg (serial->dev, 277 result = usb_control_msg(serial->dev,
278 usb_sndctrlpipe(serial->dev, 0), 278 usb_sndctrlpipe(serial->dev, 0),
279 request, REQTYPE_HOST_TO_DEVICE, data[0], 279 request, REQTYPE_HOST_TO_DEVICE, data[0],
280 0, NULL, 0, 300); 280 0, NULL, 0, 300);
@@ -292,7 +292,7 @@ static inline int cp2101_set_config_single(struct usb_serial_port *port,
292 return cp2101_set_config(port, request, &data, 2); 292 return cp2101_set_config(port, request, &data, 2);
293} 293}
294 294
295static int cp2101_open (struct tty_struct *tty, struct usb_serial_port *port, 295static int cp2101_open(struct tty_struct *tty, struct usb_serial_port *port,
296 struct file *filp) 296 struct file *filp)
297{ 297{
298 struct usb_serial *serial = port->serial; 298 struct usb_serial *serial = port->serial;
@@ -307,7 +307,7 @@ static int cp2101_open (struct tty_struct *tty, struct usb_serial_port *port,
307 } 307 }
308 308
309 /* Start reading from the device */ 309 /* Start reading from the device */
310 usb_fill_bulk_urb (port->read_urb, serial->dev, 310 usb_fill_bulk_urb(port->read_urb, serial->dev,
311 usb_rcvbulkpipe(serial->dev, 311 usb_rcvbulkpipe(serial->dev,
312 port->bulk_in_endpointAddress), 312 port->bulk_in_endpointAddress),
313 port->read_urb->transfer_buffer, 313 port->read_urb->transfer_buffer,
@@ -330,7 +330,7 @@ static int cp2101_open (struct tty_struct *tty, struct usb_serial_port *port,
330 return 0; 330 return 0;
331} 331}
332 332
333static void cp2101_cleanup (struct usb_serial_port *port) 333static void cp2101_cleanup(struct usb_serial_port *port)
334{ 334{
335 struct usb_serial *serial = port->serial; 335 struct usb_serial *serial = port->serial;
336 336
@@ -346,7 +346,7 @@ static void cp2101_cleanup (struct usb_serial_port *port)
346} 346}
347 347
348static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port, 348static void cp2101_close(struct tty_struct *tty, struct usb_serial_port *port,
349 struct file * filp) 349 struct file *filp)
350{ 350{
351 dbg("%s - port %d", __func__, port->number); 351 dbg("%s - port %d", __func__, port->number);
352 352
@@ -388,99 +388,97 @@ static void cp2101_get_termios (struct tty_struct *tty)
388 388
389 cp2101_get_config(port, CP2101_BITS, &bits, 2); 389 cp2101_get_config(port, CP2101_BITS, &bits, 2);
390 cflag &= ~CSIZE; 390 cflag &= ~CSIZE;
391 switch(bits & BITS_DATA_MASK) { 391 switch (bits & BITS_DATA_MASK) {
392 case BITS_DATA_5: 392 case BITS_DATA_5:
393 dbg("%s - data bits = 5", __func__); 393 dbg("%s - data bits = 5", __func__);
394 cflag |= CS5; 394 cflag |= CS5;
395 break; 395 break;
396 case BITS_DATA_6: 396 case BITS_DATA_6:
397 dbg("%s - data bits = 6", __func__); 397 dbg("%s - data bits = 6", __func__);
398 cflag |= CS6; 398 cflag |= CS6;
399 break; 399 break;
400 case BITS_DATA_7: 400 case BITS_DATA_7:
401 dbg("%s - data bits = 7", __func__); 401 dbg("%s - data bits = 7", __func__);
402 cflag |= CS7; 402 cflag |= CS7;
403 break; 403 break;
404 case BITS_DATA_8: 404 case BITS_DATA_8:
405 dbg("%s - data bits = 8", __func__); 405 dbg("%s - data bits = 8", __func__);
406 cflag |= CS8; 406 cflag |= CS8;
407 break; 407 break;
408 case BITS_DATA_9: 408 case BITS_DATA_9:
409 dbg("%s - data bits = 9 (not supported, " 409 dbg("%s - data bits = 9 (not supported, using 8 data bits)",
410 "using 8 data bits)", __func__); 410 __func__);
411 cflag |= CS8; 411 cflag |= CS8;
412 bits &= ~BITS_DATA_MASK; 412 bits &= ~BITS_DATA_MASK;
413 bits |= BITS_DATA_8; 413 bits |= BITS_DATA_8;
414 cp2101_set_config(port, CP2101_BITS, &bits, 2); 414 cp2101_set_config(port, CP2101_BITS, &bits, 2);
415 break; 415 break;
416 default: 416 default:
417 dbg("%s - Unknown number of data bits, " 417 dbg("%s - Unknown number of data bits, using 8", __func__);
418 "using 8", __func__); 418 cflag |= CS8;
419 cflag |= CS8; 419 bits &= ~BITS_DATA_MASK;
420 bits &= ~BITS_DATA_MASK; 420 bits |= BITS_DATA_8;
421 bits |= BITS_DATA_8; 421 cp2101_set_config(port, CP2101_BITS, &bits, 2);
422 cp2101_set_config(port, CP2101_BITS, &bits, 2); 422 break;
423 break;
424 } 423 }
425 424
426 switch(bits & BITS_PARITY_MASK) { 425 switch (bits & BITS_PARITY_MASK) {
427 case BITS_PARITY_NONE: 426 case BITS_PARITY_NONE:
428 dbg("%s - parity = NONE", __func__); 427 dbg("%s - parity = NONE", __func__);
429 cflag &= ~PARENB; 428 cflag &= ~PARENB;
430 break; 429 break;
431 case BITS_PARITY_ODD: 430 case BITS_PARITY_ODD:
432 dbg("%s - parity = ODD", __func__); 431 dbg("%s - parity = ODD", __func__);
433 cflag |= (PARENB|PARODD); 432 cflag |= (PARENB|PARODD);
434 break; 433 break;
435 case BITS_PARITY_EVEN: 434 case BITS_PARITY_EVEN:
436 dbg("%s - parity = EVEN", __func__); 435 dbg("%s - parity = EVEN", __func__);
437 cflag &= ~PARODD; 436 cflag &= ~PARODD;
438 cflag |= PARENB; 437 cflag |= PARENB;
439 break; 438 break;
440 case BITS_PARITY_MARK: 439 case BITS_PARITY_MARK:
441 dbg("%s - parity = MARK (not supported, " 440 dbg("%s - parity = MARK (not supported, disabling parity)",
442 "disabling parity)", __func__); 441 __func__);
443 cflag &= ~PARENB; 442 cflag &= ~PARENB;
444 bits &= ~BITS_PARITY_MASK; 443 bits &= ~BITS_PARITY_MASK;
445 cp2101_set_config(port, CP2101_BITS, &bits, 2); 444 cp2101_set_config(port, CP2101_BITS, &bits, 2);
446 break; 445 break;
447 case BITS_PARITY_SPACE: 446 case BITS_PARITY_SPACE:
448 dbg("%s - parity = SPACE (not supported, " 447 dbg("%s - parity = SPACE (not supported, disabling parity)",
449 "disabling parity)", __func__); 448 __func__);
450 cflag &= ~PARENB; 449 cflag &= ~PARENB;
451 bits &= ~BITS_PARITY_MASK; 450 bits &= ~BITS_PARITY_MASK;
452 cp2101_set_config(port, CP2101_BITS, &bits, 2); 451 cp2101_set_config(port, CP2101_BITS, &bits, 2);
453 break; 452 break;
454 default: 453 default:
455 dbg("%s - Unknown parity mode, " 454 dbg("%s - Unknown parity mode, disabling parity", __func__);
456 "disabling parity", __func__); 455 cflag &= ~PARENB;
457 cflag &= ~PARENB; 456 bits &= ~BITS_PARITY_MASK;
458 bits &= ~BITS_PARITY_MASK; 457 cp2101_set_config(port, CP2101_BITS, &bits, 2);
459 cp2101_set_config(port, CP2101_BITS, &bits, 2); 458 break;
460 break;
461 } 459 }
462 460
463 cflag &= ~CSTOPB; 461 cflag &= ~CSTOPB;
464 switch(bits & BITS_STOP_MASK) { 462 switch (bits & BITS_STOP_MASK) {
465 case BITS_STOP_1: 463 case BITS_STOP_1:
466 dbg("%s - stop bits = 1", __func__); 464 dbg("%s - stop bits = 1", __func__);
467 break; 465 break;
468 case BITS_STOP_1_5: 466 case BITS_STOP_1_5:
469 dbg("%s - stop bits = 1.5 (not supported, " 467 dbg("%s - stop bits = 1.5 (not supported, using 1 stop bit)",
470 "using 1 stop bit)", __func__); 468 __func__);
471 bits &= ~BITS_STOP_MASK; 469 bits &= ~BITS_STOP_MASK;
472 cp2101_set_config(port, CP2101_BITS, &bits, 2); 470 cp2101_set_config(port, CP2101_BITS, &bits, 2);
473 break; 471 break;
474 case BITS_STOP_2: 472 case BITS_STOP_2:
475 dbg("%s - stop bits = 2", __func__); 473 dbg("%s - stop bits = 2", __func__);
476 cflag |= CSTOPB; 474 cflag |= CSTOPB;
477 break; 475 break;
478 default: 476 default:
479 dbg("%s - Unknown number of stop bits, " 477 dbg("%s - Unknown number of stop bits, using 1 stop bit",
480 "using 1 stop bit", __func__); 478 __func__);
481 bits &= ~BITS_STOP_MASK; 479 bits &= ~BITS_STOP_MASK;
482 cp2101_set_config(port, CP2101_BITS, &bits, 2); 480 cp2101_set_config(port, CP2101_BITS, &bits, 2);
483 break; 481 break;
484 } 482 }
485 483
486 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16); 484 cp2101_get_config(port, CP2101_MODEMCTL, modem_ctl, 16);
@@ -495,7 +493,7 @@ static void cp2101_get_termios (struct tty_struct *tty)
495 tty->termios->c_cflag = cflag; 493 tty->termios->c_cflag = cflag;
496} 494}
497 495
498static void cp2101_set_termios (struct tty_struct *tty, 496static void cp2101_set_termios(struct tty_struct *tty,
499 struct usb_serial_port *port, struct ktermios *old_termios) 497 struct usb_serial_port *port, struct ktermios *old_termios)
500{ 498{
501 unsigned int cflag, old_cflag; 499 unsigned int cflag, old_cflag;
@@ -515,30 +513,30 @@ static void cp2101_set_termios (struct tty_struct *tty,
515 /* If the baud rate is to be updated*/ 513 /* If the baud rate is to be updated*/
516 if (baud != tty_termios_baud_rate(old_termios)) { 514 if (baud != tty_termios_baud_rate(old_termios)) {
517 switch (baud) { 515 switch (baud) {
518 case 0: 516 case 0:
519 case 600: 517 case 600:
520 case 1200: 518 case 1200:
521 case 1800: 519 case 1800:
522 case 2400: 520 case 2400:
523 case 4800: 521 case 4800:
524 case 7200: 522 case 7200:
525 case 9600: 523 case 9600:
526 case 14400: 524 case 14400:
527 case 19200: 525 case 19200:
528 case 28800: 526 case 28800:
529 case 38400: 527 case 38400:
530 case 55854: 528 case 55854:
531 case 57600: 529 case 57600:
532 case 115200: 530 case 115200:
533 case 127117: 531 case 127117:
534 case 230400: 532 case 230400:
535 case 460800: 533 case 460800:
536 case 921600: 534 case 921600:
537 case 3686400: 535 case 3686400:
538 break; 536 break;
539 default: 537 default:
540 baud = 9600; 538 baud = 9600;
541 break; 539 break;
542 } 540 }
543 541
544 if (baud) { 542 if (baud) {
@@ -560,28 +558,28 @@ static void cp2101_set_termios (struct tty_struct *tty,
560 cp2101_get_config(port, CP2101_BITS, &bits, 2); 558 cp2101_get_config(port, CP2101_BITS, &bits, 2);
561 bits &= ~BITS_DATA_MASK; 559 bits &= ~BITS_DATA_MASK;
562 switch (cflag & CSIZE) { 560 switch (cflag & CSIZE) {
563 case CS5: 561 case CS5:
564 bits |= BITS_DATA_5; 562 bits |= BITS_DATA_5;
565 dbg("%s - data bits = 5", __func__); 563 dbg("%s - data bits = 5", __func__);
566 break; 564 break;
567 case CS6: 565 case CS6:
568 bits |= BITS_DATA_6; 566 bits |= BITS_DATA_6;
569 dbg("%s - data bits = 6", __func__); 567 dbg("%s - data bits = 6", __func__);
570 break; 568 break;
571 case CS7: 569 case CS7:
572 bits |= BITS_DATA_7; 570 bits |= BITS_DATA_7;
573 dbg("%s - data bits = 7", __func__); 571 dbg("%s - data bits = 7", __func__);
574 break; 572 break;
575 case CS8: 573 case CS8:
576 bits |= BITS_DATA_8; 574 bits |= BITS_DATA_8;
577 dbg("%s - data bits = 8", __func__); 575 dbg("%s - data bits = 8", __func__);
578 break; 576 break;
579 /*case CS9: 577 /*case CS9:
580 bits |= BITS_DATA_9; 578 bits |= BITS_DATA_9;
581 dbg("%s - data bits = 9", __func__); 579 dbg("%s - data bits = 9", __func__);
582 break;*/ 580 break;*/
583 default: 581 default:
584 dev_err(&port->dev, "cp2101 driver does not " 582 dev_err(&port->dev, "cp2101 driver does not "
585 "support the number of bits requested," 583 "support the number of bits requested,"
586 " using 8 bit mode\n"); 584 " using 8 bit mode\n");
587 bits |= BITS_DATA_8; 585 bits |= BITS_DATA_8;
@@ -714,30 +712,29 @@ static void cp2101_break_ctl (struct tty_struct *tty, int break_state)
714 else 712 else
715 state = BREAK_ON; 713 state = BREAK_ON;
716 dbg("%s - turning break %s", __func__, 714 dbg("%s - turning break %s", __func__,
717 state==BREAK_OFF ? "off" : "on"); 715 state == BREAK_OFF ? "off" : "on");
718 cp2101_set_config(port, CP2101_BREAK, &state, 2); 716 cp2101_set_config(port, CP2101_BREAK, &state, 2);
719} 717}
720 718
721static int cp2101_startup (struct usb_serial *serial) 719static int cp2101_startup(struct usb_serial *serial)
722{ 720{
723 /* CP2101 buffers behave strangely unless device is reset */ 721 /* CP2101 buffers behave strangely unless device is reset */
724 usb_reset_device(serial->dev); 722 usb_reset_device(serial->dev);
725 return 0; 723 return 0;
726} 724}
727 725
728static void cp2101_shutdown (struct usb_serial *serial) 726static void cp2101_shutdown(struct usb_serial *serial)
729{ 727{
730 int i; 728 int i;
731 729
732 dbg("%s", __func__); 730 dbg("%s", __func__);
733 731
734 /* Stop reads and writes on all ports */ 732 /* Stop reads and writes on all ports */
735 for (i=0; i < serial->num_ports; ++i) { 733 for (i = 0; i < serial->num_ports; ++i)
736 cp2101_cleanup(serial->port[i]); 734 cp2101_cleanup(serial->port[i]);
737 }
738} 735}
739 736
740static int __init cp2101_init (void) 737static int __init cp2101_init(void)
741{ 738{
742 int retval; 739 int retval;
743 740
@@ -757,10 +754,10 @@ static int __init cp2101_init (void)
757 return 0; 754 return 0;
758} 755}
759 756
760static void __exit cp2101_exit (void) 757static void __exit cp2101_exit(void)
761{ 758{
762 usb_deregister (&cp2101_driver); 759 usb_deregister(&cp2101_driver);
763 usb_serial_deregister (&cp2101_device); 760 usb_serial_deregister(&cp2101_device);
764} 761}
765 762
766module_init(cp2101_init); 763module_init(cp2101_init);