diff options
author | Alan Cox <alan@redhat.com> | 2008-07-22 06:15:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-22 16:03:26 -0400 |
commit | 2a77c8144992e21367cc15956b0ff295f1112c85 (patch) | |
tree | 85af4158877ab5a2187839408502611acd51eace /drivers/usb | |
parent | 43c8f435b2ca39f12ad89d91d9ee2be04a196f93 (diff) |
tty-usb-oti6858: 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')
-rw-r--r-- | drivers/usb/serial/oti6858.c | 136 |
1 files changed, 70 insertions, 66 deletions
diff --git a/drivers/usb/serial/oti6858.c b/drivers/usb/serial/oti6858.c index 069d276a5276..81db5715ee25 100644 --- a/drivers/usb/serial/oti6858.c +++ b/drivers/usb/serial/oti6858.c | |||
@@ -25,7 +25,8 @@ | |||
25 | * it under the terms of the GNU General Public License as published by | 25 | * it under the terms of the GNU General Public License as published by |
26 | * the Free Software Foundation; either version 2 of the License. | 26 | * the Free Software Foundation; either version 2 of the License. |
27 | * | 27 | * |
28 | * See Documentation/usb/usb-serial.txt for more information on using this driver | 28 | * See Documentation/usb/usb-serial.txt for more information on using this |
29 | * driver | ||
29 | * | 30 | * |
30 | * TODO: | 31 | * TODO: |
31 | * - implement correct flushing for ioctls and oti6858_close() | 32 | * - implement correct flushing for ioctls and oti6858_close() |
@@ -49,7 +50,7 @@ | |||
49 | #include <linux/spinlock.h> | 50 | #include <linux/spinlock.h> |
50 | #include <linux/usb.h> | 51 | #include <linux/usb.h> |
51 | #include <linux/usb/serial.h> | 52 | #include <linux/usb/serial.h> |
52 | #include <asm/uaccess.h> | 53 | #include <linux/uaccess.h> |
53 | #include "oti6858.h" | 54 | #include "oti6858.h" |
54 | 55 | ||
55 | #define OTI6858_DESCRIPTION \ | 56 | #define OTI6858_DESCRIPTION \ |
@@ -135,9 +136,9 @@ struct oti6858_control_pkt { | |||
135 | 136 | ||
136 | #define OTI6858_CTRL_PKT_SIZE sizeof(struct oti6858_control_pkt) | 137 | #define OTI6858_CTRL_PKT_SIZE sizeof(struct oti6858_control_pkt) |
137 | #define OTI6858_CTRL_EQUALS_PENDING(a, priv) \ | 138 | #define OTI6858_CTRL_EQUALS_PENDING(a, priv) \ |
138 | ( ((a)->divisor == (priv)->pending_setup.divisor) \ | 139 | (((a)->divisor == (priv)->pending_setup.divisor) \ |
139 | && ((a)->control == (priv)->pending_setup.control) \ | 140 | && ((a)->control == (priv)->pending_setup.control) \ |
140 | && ((a)->frame_fmt == (priv)->pending_setup.frame_fmt) ) | 141 | && ((a)->frame_fmt == (priv)->pending_setup.frame_fmt)) |
141 | 142 | ||
142 | /* function prototypes */ | 143 | /* function prototypes */ |
143 | static int oti6858_open(struct tty_struct *tty, | 144 | static int oti6858_open(struct tty_struct *tty, |
@@ -220,7 +221,7 @@ struct oti6858_private { | |||
220 | struct delayed_work delayed_setup_work; | 221 | struct delayed_work delayed_setup_work; |
221 | 222 | ||
222 | wait_queue_head_t intr_wait; | 223 | wait_queue_head_t intr_wait; |
223 | struct usb_serial_port *port; /* USB port with which associated */ | 224 | struct usb_serial_port *port; /* USB port with which associated */ |
224 | }; | 225 | }; |
225 | 226 | ||
226 | #undef dbg | 227 | #undef dbg |
@@ -229,7 +230,8 @@ struct oti6858_private { | |||
229 | 230 | ||
230 | static void setup_line(struct work_struct *work) | 231 | static void setup_line(struct work_struct *work) |
231 | { | 232 | { |
232 | struct oti6858_private *priv = container_of(work, struct oti6858_private, delayed_setup_work.work); | 233 | struct oti6858_private *priv = container_of(work, |
234 | struct oti6858_private, delayed_setup_work.work); | ||
233 | struct usb_serial_port *port = priv->port; | 235 | struct usb_serial_port *port = priv->port; |
234 | struct oti6858_control_pkt *new_setup; | 236 | struct oti6858_control_pkt *new_setup; |
235 | unsigned long flags; | 237 | unsigned long flags; |
@@ -237,10 +239,12 @@ static void setup_line(struct work_struct *work) | |||
237 | 239 | ||
238 | dbg("%s(port = %d)", __func__, port->number); | 240 | dbg("%s(port = %d)", __func__, port->number); |
239 | 241 | ||
240 | if ((new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL)) == NULL) { | 242 | new_setup = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL); |
243 | if (new_setup == NULL) { | ||
241 | dev_err(&port->dev, "%s(): out of memory!\n", __func__); | 244 | dev_err(&port->dev, "%s(): out of memory!\n", __func__); |
242 | /* we will try again */ | 245 | /* we will try again */ |
243 | schedule_delayed_work(&priv->delayed_setup_work, msecs_to_jiffies(2)); | 246 | schedule_delayed_work(&priv->delayed_setup_work, |
247 | msecs_to_jiffies(2)); | ||
244 | return; | 248 | return; |
245 | } | 249 | } |
246 | 250 | ||
@@ -256,7 +260,8 @@ static void setup_line(struct work_struct *work) | |||
256 | dev_err(&port->dev, "%s(): error reading status\n", __func__); | 260 | dev_err(&port->dev, "%s(): error reading status\n", __func__); |
257 | kfree(new_setup); | 261 | kfree(new_setup); |
258 | /* we will try again */ | 262 | /* we will try again */ |
259 | schedule_delayed_work(&priv->delayed_setup_work, msecs_to_jiffies(2)); | 263 | schedule_delayed_work(&priv->delayed_setup_work, |
264 | msecs_to_jiffies(2)); | ||
260 | return; | 265 | return; |
261 | } | 266 | } |
262 | 267 | ||
@@ -297,7 +302,8 @@ static void setup_line(struct work_struct *work) | |||
297 | 302 | ||
298 | void send_data(struct work_struct *work) | 303 | void send_data(struct work_struct *work) |
299 | { | 304 | { |
300 | struct oti6858_private *priv = container_of(work, struct oti6858_private, delayed_write_work.work); | 305 | struct oti6858_private *priv = container_of(work, |
306 | struct oti6858_private, delayed_write_work.work); | ||
301 | struct usb_serial_port *port = priv->port; | 307 | struct usb_serial_port *port = priv->port; |
302 | int count = 0, result; | 308 | int count = 0, result; |
303 | unsigned long flags; | 309 | unsigned long flags; |
@@ -308,7 +314,8 @@ void send_data(struct work_struct *work) | |||
308 | spin_lock_irqsave(&priv->lock, flags); | 314 | spin_lock_irqsave(&priv->lock, flags); |
309 | if (priv->flags.write_urb_in_use) { | 315 | if (priv->flags.write_urb_in_use) { |
310 | spin_unlock_irqrestore(&priv->lock, flags); | 316 | spin_unlock_irqrestore(&priv->lock, flags); |
311 | schedule_delayed_work(&priv->delayed_write_work, msecs_to_jiffies(2)); | 317 | schedule_delayed_work(&priv->delayed_write_work, |
318 | msecs_to_jiffies(2)); | ||
312 | return; | 319 | return; |
313 | } | 320 | } |
314 | priv->flags.write_urb_in_use = 1; | 321 | priv->flags.write_urb_in_use = 1; |
@@ -359,8 +366,8 @@ void send_data(struct work_struct *work) | |||
359 | 366 | ||
360 | static int oti6858_startup(struct usb_serial *serial) | 367 | static int oti6858_startup(struct usb_serial *serial) |
361 | { | 368 | { |
362 | struct usb_serial_port *port = serial->port[0]; | 369 | struct usb_serial_port *port = serial->port[0]; |
363 | struct oti6858_private *priv; | 370 | struct oti6858_private *priv; |
364 | int i; | 371 | int i; |
365 | 372 | ||
366 | for (i = 0; i < serial->num_ports; ++i) { | 373 | for (i = 0; i < serial->num_ports; ++i) { |
@@ -375,8 +382,8 @@ static int oti6858_startup(struct usb_serial *serial) | |||
375 | 382 | ||
376 | spin_lock_init(&priv->lock); | 383 | spin_lock_init(&priv->lock); |
377 | init_waitqueue_head(&priv->intr_wait); | 384 | init_waitqueue_head(&priv->intr_wait); |
378 | // INIT_WORK(&priv->setup_work, setup_line, serial->port[i]); | 385 | /* INIT_WORK(&priv->setup_work, setup_line, serial->port[i]); */ |
379 | // INIT_WORK(&priv->write_work, send_data, serial->port[i]); | 386 | /* INIT_WORK(&priv->write_work, send_data, serial->port[i]); */ |
380 | priv->port = port; | 387 | priv->port = port; |
381 | INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line); | 388 | INIT_DELAYED_WORK(&priv->delayed_setup_work, setup_line); |
382 | INIT_DELAYED_WORK(&priv->delayed_write_work, send_data); | 389 | INIT_DELAYED_WORK(&priv->delayed_write_work, send_data); |
@@ -482,19 +489,19 @@ static void oti6858_set_termios(struct tty_struct *tty, | |||
482 | 489 | ||
483 | frame_fmt &= ~FMT_DATA_BITS_MASK; | 490 | frame_fmt &= ~FMT_DATA_BITS_MASK; |
484 | switch (cflag & CSIZE) { | 491 | switch (cflag & CSIZE) { |
485 | case CS5: | 492 | case CS5: |
486 | frame_fmt |= FMT_DATA_BITS_5; | 493 | frame_fmt |= FMT_DATA_BITS_5; |
487 | break; | 494 | break; |
488 | case CS6: | 495 | case CS6: |
489 | frame_fmt |= FMT_DATA_BITS_6; | 496 | frame_fmt |= FMT_DATA_BITS_6; |
490 | break; | 497 | break; |
491 | case CS7: | 498 | case CS7: |
492 | frame_fmt |= FMT_DATA_BITS_7; | 499 | frame_fmt |= FMT_DATA_BITS_7; |
493 | break; | 500 | break; |
494 | default: | 501 | default: |
495 | case CS8: | 502 | case CS8: |
496 | frame_fmt |= FMT_DATA_BITS_8; | 503 | frame_fmt |= FMT_DATA_BITS_8; |
497 | break; | 504 | break; |
498 | } | 505 | } |
499 | 506 | ||
500 | /* manufacturer claims that this device can work with baud rates | 507 | /* manufacturer claims that this device can work with baud rates |
@@ -517,19 +524,17 @@ static void oti6858_set_termios(struct tty_struct *tty, | |||
517 | } | 524 | } |
518 | 525 | ||
519 | frame_fmt &= ~FMT_STOP_BITS_MASK; | 526 | frame_fmt &= ~FMT_STOP_BITS_MASK; |
520 | if ((cflag & CSTOPB) != 0) { | 527 | if ((cflag & CSTOPB) != 0) |
521 | frame_fmt |= FMT_STOP_BITS_2; | 528 | frame_fmt |= FMT_STOP_BITS_2; |
522 | } else { | 529 | else |
523 | frame_fmt |= FMT_STOP_BITS_1; | 530 | frame_fmt |= FMT_STOP_BITS_1; |
524 | } | ||
525 | 531 | ||
526 | frame_fmt &= ~FMT_PARITY_MASK; | 532 | frame_fmt &= ~FMT_PARITY_MASK; |
527 | if ((cflag & PARENB) != 0) { | 533 | if ((cflag & PARENB) != 0) { |
528 | if ((cflag & PARODD) != 0) { | 534 | if ((cflag & PARODD) != 0) |
529 | frame_fmt |= FMT_PARITY_ODD; | 535 | frame_fmt |= FMT_PARITY_ODD; |
530 | } else { | 536 | else |
531 | frame_fmt |= FMT_PARITY_EVEN; | 537 | frame_fmt |= FMT_PARITY_EVEN; |
532 | } | ||
533 | } else { | 538 | } else { |
534 | frame_fmt |= FMT_PARITY_NONE; | 539 | frame_fmt |= FMT_PARITY_NONE; |
535 | } | 540 | } |
@@ -584,7 +589,8 @@ static int oti6858_open(struct tty_struct *tty, | |||
584 | if (port->port.count != 1) | 589 | if (port->port.count != 1) |
585 | return 0; | 590 | return 0; |
586 | 591 | ||
587 | if ((buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL)) == NULL) { | 592 | buf = kmalloc(OTI6858_CTRL_PKT_SIZE, GFP_KERNEL); |
593 | if (buf == NULL) { | ||
588 | dev_err(&port->dev, "%s(): out of memory!\n", __func__); | 594 | dev_err(&port->dev, "%s(): out of memory!\n", __func__); |
589 | return -ENOMEM; | 595 | return -ENOMEM; |
590 | } | 596 | } |
@@ -729,11 +735,10 @@ static int oti6858_tiocmset(struct tty_struct *tty, struct file *file, | |||
729 | if ((clear & TIOCM_DTR) != 0) | 735 | if ((clear & TIOCM_DTR) != 0) |
730 | control &= ~CONTROL_DTR_HIGH; | 736 | control &= ~CONTROL_DTR_HIGH; |
731 | 737 | ||
732 | if (control != priv->pending_setup.control) { | 738 | if (control != priv->pending_setup.control) |
733 | priv->pending_setup.control = control; | 739 | priv->pending_setup.control = control; |
734 | } | ||
735 | spin_unlock_irqrestore(&priv->lock, flags); | ||
736 | 740 | ||
741 | spin_unlock_irqrestore(&priv->lock, flags); | ||
737 | return 0; | 742 | return 0; |
738 | } | 743 | } |
739 | 744 | ||
@@ -785,7 +790,8 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) | |||
785 | spin_unlock_irqrestore(&priv->lock, flags); | 790 | spin_unlock_irqrestore(&priv->lock, flags); |
786 | 791 | ||
787 | while (1) { | 792 | while (1) { |
788 | wait_event_interruptible(priv->intr_wait, priv->status.pin_state != prev); | 793 | wait_event_interruptible(priv->intr_wait, |
794 | priv->status.pin_state != prev); | ||
789 | if (signal_pending(current)) | 795 | if (signal_pending(current)) |
790 | return -ERESTARTSYS; | 796 | return -ERESTARTSYS; |
791 | 797 | ||
@@ -795,12 +801,11 @@ static int wait_modem_info(struct usb_serial_port *port, unsigned int arg) | |||
795 | 801 | ||
796 | changed = prev ^ status; | 802 | changed = prev ^ status; |
797 | /* FIXME: check if this is correct (active high/low) */ | 803 | /* FIXME: check if this is correct (active high/low) */ |
798 | if ( ((arg & TIOCM_RNG) && (changed & PIN_RI)) || | 804 | if (((arg & TIOCM_RNG) && (changed & PIN_RI)) || |
799 | ((arg & TIOCM_DSR) && (changed & PIN_DSR)) || | 805 | ((arg & TIOCM_DSR) && (changed & PIN_DSR)) || |
800 | ((arg & TIOCM_CD) && (changed & PIN_DCD)) || | 806 | ((arg & TIOCM_CD) && (changed & PIN_DCD)) || |
801 | ((arg & TIOCM_CTS) && (changed & PIN_CTS))) { | 807 | ((arg & TIOCM_CTS) && (changed & PIN_CTS))) |
802 | return 0; | 808 | return 0; |
803 | } | ||
804 | prev = status; | 809 | prev = status; |
805 | } | 810 | } |
806 | 811 | ||
@@ -817,15 +822,13 @@ static int oti6858_ioctl(struct tty_struct *tty, struct file *file, | |||
817 | __func__, port->number, cmd, arg); | 822 | __func__, port->number, cmd, arg); |
818 | 823 | ||
819 | switch (cmd) { | 824 | switch (cmd) { |
820 | case TIOCMIWAIT: | 825 | case TIOCMIWAIT: |
821 | dbg("%s(): TIOCMIWAIT", __func__); | 826 | dbg("%s(): TIOCMIWAIT", __func__); |
822 | return wait_modem_info(port, arg); | 827 | return wait_modem_info(port, arg); |
823 | 828 | default: | |
824 | default: | 829 | dbg("%s(): 0x%04x not supported", __func__, cmd); |
825 | dbg("%s(): 0x%04x not supported", __func__, cmd); | 830 | break; |
826 | break; | ||
827 | } | 831 | } |
828 | |||
829 | return -ENOIOCTLCMD; | 832 | return -ENOIOCTLCMD; |
830 | } | 833 | } |
831 | 834 | ||
@@ -941,7 +944,7 @@ static void oti6858_read_int_callback(struct urb *urb) | |||
941 | spin_lock_irqsave(&priv->lock, flags); | 944 | spin_lock_irqsave(&priv->lock, flags); |
942 | if (priv->flags.write_urb_in_use == 0 | 945 | if (priv->flags.write_urb_in_use == 0 |
943 | && oti6858_buf_data_avail(priv->buf) != 0) { | 946 | && oti6858_buf_data_avail(priv->buf) != 0) { |
944 | schedule_delayed_work(&priv->delayed_write_work,0); | 947 | schedule_delayed_work(&priv->delayed_write_work, 0); |
945 | resubmit = 0; | 948 | resubmit = 0; |
946 | } | 949 | } |
947 | spin_unlock_irqrestore(&priv->lock, flags); | 950 | spin_unlock_irqrestore(&priv->lock, flags); |
@@ -950,7 +953,7 @@ static void oti6858_read_int_callback(struct urb *urb) | |||
950 | if (resubmit) { | 953 | if (resubmit) { |
951 | int result; | 954 | int result; |
952 | 955 | ||
953 | // dbg("%s(): submitting interrupt urb", __func__); | 956 | /* dbg("%s(): submitting interrupt urb", __func__); */ |
954 | urb->dev = port->serial->dev; | 957 | urb->dev = port->serial->dev; |
955 | result = usb_submit_urb(urb, GFP_ATOMIC); | 958 | result = usb_submit_urb(urb, GFP_ATOMIC); |
956 | if (result != 0) { | 959 | if (result != 0) { |
@@ -985,8 +988,10 @@ static void oti6858_read_bulk_callback(struct urb *urb) | |||
985 | } | 988 | } |
986 | /* | 989 | /* |
987 | if (status == -EPROTO) { | 990 | if (status == -EPROTO) { |
988 | // PL2303 mysteriously fails with -EPROTO reschedule the read | 991 | * PL2303 mysteriously fails with -EPROTO reschedule |
989 | dbg("%s - caught -EPROTO, resubmitting the urb", __func__); | 992 | the read * |
993 | dbg("%s - caught -EPROTO, resubmitting the urb", | ||
994 | __func__); | ||
990 | result = usb_submit_urb(urb, GFP_ATOMIC); | 995 | result = usb_submit_urb(urb, GFP_ATOMIC); |
991 | if (result) | 996 | if (result) |
992 | dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); | 997 | dev_err(&urb->dev->dev, "%s - failed resubmitting read urb, error %d\n", __func__, result); |
@@ -1003,7 +1008,7 @@ static void oti6858_read_bulk_callback(struct urb *urb) | |||
1003 | tty_flip_buffer_push(tty); | 1008 | tty_flip_buffer_push(tty); |
1004 | } | 1009 | } |
1005 | 1010 | ||
1006 | // schedule the interrupt urb if we are still open */ | 1011 | /* schedule the interrupt urb if we are still open */ |
1007 | if (port->port.count != 0) { | 1012 | if (port->port.count != 0) { |
1008 | port->interrupt_in_urb->dev = port->serial->dev; | 1013 | port->interrupt_in_urb->dev = port->serial->dev; |
1009 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); | 1014 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); |
@@ -1055,7 +1060,7 @@ static void oti6858_write_bulk_callback(struct urb *urb) | |||
1055 | 1060 | ||
1056 | priv->flags.write_urb_in_use = 0; | 1061 | priv->flags.write_urb_in_use = 0; |
1057 | 1062 | ||
1058 | // schedule the interrupt urb if we are still open */ | 1063 | /* schedule the interrupt urb if we are still open */ |
1059 | port->interrupt_in_urb->dev = port->serial->dev; | 1064 | port->interrupt_in_urb->dev = port->serial->dev; |
1060 | dbg("%s(): submitting interrupt urb", __func__); | 1065 | dbg("%s(): submitting interrupt urb", __func__); |
1061 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); | 1066 | result = usb_submit_urb(port->interrupt_in_urb, GFP_ATOMIC); |
@@ -1130,7 +1135,7 @@ static unsigned int oti6858_buf_data_avail(struct oti6858_buf *pb) | |||
1130 | { | 1135 | { |
1131 | if (pb == NULL) | 1136 | if (pb == NULL) |
1132 | return 0; | 1137 | return 0; |
1133 | return ((pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size); | 1138 | return (pb->buf_size + pb->buf_put - pb->buf_get) % pb->buf_size; |
1134 | } | 1139 | } |
1135 | 1140 | ||
1136 | /* | 1141 | /* |
@@ -1143,7 +1148,7 @@ static unsigned int oti6858_buf_space_avail(struct oti6858_buf *pb) | |||
1143 | { | 1148 | { |
1144 | if (pb == NULL) | 1149 | if (pb == NULL) |
1145 | return 0; | 1150 | return 0; |
1146 | return ((pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size); | 1151 | return (pb->buf_size + pb->buf_get - pb->buf_put - 1) % pb->buf_size; |
1147 | } | 1152 | } |
1148 | 1153 | ||
1149 | /* | 1154 | /* |
@@ -1230,13 +1235,12 @@ static int __init oti6858_init(void) | |||
1230 | { | 1235 | { |
1231 | int retval; | 1236 | int retval; |
1232 | 1237 | ||
1233 | if ((retval = usb_serial_register(&oti6858_device)) == 0) { | 1238 | retval = usb_serial_register(&oti6858_device); |
1234 | if ((retval = usb_register(&oti6858_driver)) != 0) | 1239 | if (retval == 0) { |
1240 | retval = usb_register(&oti6858_driver); | ||
1241 | if (retval) | ||
1235 | usb_serial_deregister(&oti6858_device); | 1242 | usb_serial_deregister(&oti6858_device); |
1236 | else | ||
1237 | return 0; | ||
1238 | } | 1243 | } |
1239 | |||
1240 | return retval; | 1244 | return retval; |
1241 | } | 1245 | } |
1242 | 1246 | ||