aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/serial
diff options
context:
space:
mode:
authorAlan Cox <alan@redhat.com>2008-07-22 06:13:42 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-07-22 16:03:25 -0400
commit9e70f319d14ac4dd077de7fc835a391ece804500 (patch)
treeea5550d3a0a092469eeb69f2c46e326a7b486696 /drivers/usb/serial
parentf035a8ad158f0bdc94125004488b0ea8438edaa9 (diff)
tty-usb-keyspan-pda: 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/keyspan_pda.c161
1 files changed, 91 insertions, 70 deletions
diff --git a/drivers/usb/serial/keyspan_pda.c b/drivers/usb/serial/keyspan_pda.c
index 24a08ac2e4ee..b60012ce4c91 100644
--- a/drivers/usb/serial/keyspan_pda.c
+++ b/drivers/usb/serial/keyspan_pda.c
@@ -10,8 +10,9 @@
10 * the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version. 11 * (at your option) any later version.
12 * 12 *
13 * See Documentation/usb/usb-serial.txt for more information on using this driver 13 * See Documentation/usb/usb-serial.txt for more information on using this
14 * 14 * driver
15 *
15 * (09/07/2001) gkh 16 * (09/07/2001) gkh
16 * cleaned up the Xircom support. Added ids for Entregra device which is 17 * cleaned up the Xircom support. Added ids for Entregra device which is
17 * the same as the Xircom device. Enabled the code to be compiled for 18 * the same as the Xircom device. Enabled the code to be compiled for
@@ -21,23 +22,24 @@
21 * support for Xircom PGSDB9 22 * support for Xircom PGSDB9
22 * 23 *
23 * (05/31/2001) gkh 24 * (05/31/2001) gkh
24 * switched from using spinlock to a semaphore, which fixes lots of problems. 25 * switched from using spinlock to a semaphore, which fixes lots of
26 * problems.
25 * 27 *
26 * (04/08/2001) gb 28 * (04/08/2001) gb
27 * Identify version on module load. 29 * Identify version on module load.
28 * 30 *
29 * (11/01/2000) Adam J. Richter 31 * (11/01/2000) Adam J. Richter
30 * usb_device_id table support 32 * usb_device_id table support
31 * 33 *
32 * (10/05/2000) gkh 34 * (10/05/2000) gkh
33 * Fixed bug with urb->dev not being set properly, now that the usb 35 * Fixed bug with urb->dev not being set properly, now that the usb
34 * core needs it. 36 * core needs it.
35 * 37 *
36 * (08/28/2000) gkh 38 * (08/28/2000) gkh
37 * Added locks for SMP safeness. 39 * Added locks for SMP safeness.
38 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more 40 * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
39 * than once. 41 * than once.
40 * 42 *
41 * (07/20/2000) borchers 43 * (07/20/2000) borchers
42 * - keyspan_pda_write no longer sleeps if it is called on interrupt time; 44 * - keyspan_pda_write no longer sleeps if it is called on interrupt time;
43 * PPP and the line discipline with stty echo on can call write on 45 * PPP and the line discipline with stty echo on can call write on
@@ -55,14 +57,14 @@
55 * than done directly from the callback to avoid the race in write_chan 57 * than done directly from the callback to avoid the race in write_chan
56 * - keyspan_pda_chars_in_buffer also indicates its buffer is full if the 58 * - keyspan_pda_chars_in_buffer also indicates its buffer is full if the
57 * urb status is -EINPROGRESS, meaning it cannot write at the moment 59 * urb status is -EINPROGRESS, meaning it cannot write at the moment
58 * 60 *
59 * (07/19/2000) gkh 61 * (07/19/2000) gkh
60 * Added module_init and module_exit functions to handle the fact that this 62 * Added module_init and module_exit functions to handle the fact that this
61 * driver is a loadable module now. 63 * driver is a loadable module now.
62 * 64 *
63 * (03/26/2000) gkh 65 * (03/26/2000) gkh
64 * Split driver up into device specific pieces. 66 * Split driver up into device specific pieces.
65 * 67 *
66 */ 68 */
67 69
68 70
@@ -78,7 +80,7 @@
78#include <linux/workqueue.h> 80#include <linux/workqueue.h>
79#include <linux/firmware.h> 81#include <linux/firmware.h>
80#include <linux/ihex.h> 82#include <linux/ihex.h>
81#include <asm/uaccess.h> 83#include <linux/uaccess.h>
82#include <linux/usb.h> 84#include <linux/usb.h>
83#include <linux/usb/serial.h> 85#include <linux/usb/serial.h>
84 86
@@ -135,7 +137,7 @@ static struct usb_device_id id_table_combined [] = {
135 { } /* Terminating entry */ 137 { } /* Terminating entry */
136}; 138};
137 139
138MODULE_DEVICE_TABLE (usb, id_table_combined); 140MODULE_DEVICE_TABLE(usb, id_table_combined);
139 141
140static struct usb_driver keyspan_pda_driver = { 142static struct usb_driver keyspan_pda_driver = {
141 .name = "keyspan_pda", 143 .name = "keyspan_pda",
@@ -159,9 +161,9 @@ static struct usb_device_id id_table_fake [] = {
159 161
160#ifdef XIRCOM 162#ifdef XIRCOM
161static struct usb_device_id id_table_fake_xircom [] = { 163static struct usb_device_id id_table_fake_xircom [] = {
162 { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) }, 164 { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
163 { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) }, 165 { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) },
164 { } 166 { }
165}; 167};
166#endif 168#endif
167 169
@@ -184,7 +186,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
184 dbg(" request_unthrottle"); 186 dbg(" request_unthrottle");
185 /* ask the device to tell us when the tx buffer becomes 187 /* ask the device to tell us when the tx buffer becomes
186 sufficiently empty */ 188 sufficiently empty */
187 result = usb_control_msg(serial->dev, 189 result = usb_control_msg(serial->dev,
188 usb_sndctrlpipe(serial->dev, 0), 190 usb_sndctrlpipe(serial->dev, 0),
189 7, /* request_unthrottle */ 191 7, /* request_unthrottle */
190 USB_TYPE_VENDOR | USB_RECIP_INTERFACE 192 USB_TYPE_VENDOR | USB_RECIP_INTERFACE
@@ -195,15 +197,15 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
195 0, 197 0,
196 2000); 198 2000);
197 if (result < 0) 199 if (result < 0)
198 dbg("%s - error %d from usb_control_msg", 200 dbg("%s - error %d from usb_control_msg",
199 __func__, result); 201 __func__, result);
200} 202}
201 203
202 204
203static void keyspan_pda_rx_interrupt (struct urb *urb) 205static void keyspan_pda_rx_interrupt(struct urb *urb)
204{ 206{
205 struct usb_serial_port *port = urb->context; 207 struct usb_serial_port *port = urb->context;
206 struct tty_struct *tty = port->port.tty; 208 struct tty_struct *tty = port->port.tty;
207 unsigned char *data = urb->transfer_buffer; 209 unsigned char *data = urb->transfer_buffer;
208 int i; 210 int i;
209 int retval; 211 int retval;
@@ -228,14 +230,13 @@ static void keyspan_pda_rx_interrupt (struct urb *urb)
228 goto exit; 230 goto exit;
229 } 231 }
230 232
231 /* see if the message is data or a status interrupt */ 233 /* see if the message is data or a status interrupt */
232 switch (data[0]) { 234 switch (data[0]) {
233 case 0: 235 case 0:
234 /* rest of message is rx data */ 236 /* rest of message is rx data */
235 if (urb->actual_length) { 237 if (urb->actual_length) {
236 for (i = 1; i < urb->actual_length ; ++i) { 238 for (i = 1; i < urb->actual_length ; ++i)
237 tty_insert_flip_char(tty, data[i], 0); 239 tty_insert_flip_char(tty, data[i], 0);
238 }
239 tty_flip_buffer_push(tty); 240 tty_flip_buffer_push(tty);
240 } 241 }
241 break; 242 break;
@@ -259,9 +260,9 @@ static void keyspan_pda_rx_interrupt (struct urb *urb)
259 } 260 }
260 261
261exit: 262exit:
262 retval = usb_submit_urb (urb, GFP_ATOMIC); 263 retval = usb_submit_urb(urb, GFP_ATOMIC);
263 if (retval) 264 if (retval)
264 err ("%s - usb_submit_urb failed with result %d", 265 err("%s - usb_submit_urb failed with result %d",
265 __func__, retval); 266 __func__, retval);
266} 267}
267 268
@@ -292,32 +293,52 @@ static void keyspan_pda_rx_unthrottle(struct tty_struct *tty)
292} 293}
293 294
294 295
295static speed_t keyspan_pda_setbaud (struct usb_serial *serial, speed_t baud) 296static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud)
296{ 297{
297 int rc; 298 int rc;
298 int bindex; 299 int bindex;
299 300
300 switch(baud) { 301 switch (baud) {
301 case 110: bindex = 0; break; 302 case 110:
302 case 300: bindex = 1; break; 303 bindex = 0;
303 case 1200: bindex = 2; break; 304 break;
304 case 2400: bindex = 3; break; 305 case 300:
305 case 4800: bindex = 4; break; 306 bindex = 1;
306 case 9600: bindex = 5; break; 307 break;
307 case 19200: bindex = 6; break; 308 case 1200:
308 case 38400: bindex = 7; break; 309 bindex = 2;
309 case 57600: bindex = 8; break; 310 break;
310 case 115200: bindex = 9; break; 311 case 2400:
311 default: 312 bindex = 3;
312 bindex = 5; /* Default to 9600 */ 313 break;
313 baud = 9600; 314 case 4800:
315 bindex = 4;
316 break;
317 case 9600:
318 bindex = 5;
319 break;
320 case 19200:
321 bindex = 6;
322 break;
323 case 38400:
324 bindex = 7;
325 break;
326 case 57600:
327 bindex = 8;
328 break;
329 case 115200:
330 bindex = 9;
331 break;
332 default:
333 bindex = 5; /* Default to 9600 */
334 baud = 9600;
314 } 335 }
315 336
316 /* rather than figure out how to sleep while waiting for this 337 /* rather than figure out how to sleep while waiting for this
317 to complete, I just use the "legacy" API. */ 338 to complete, I just use the "legacy" API. */
318 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 339 rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
319 0, /* set baud */ 340 0, /* set baud */
320 USB_TYPE_VENDOR 341 USB_TYPE_VENDOR
321 | USB_RECIP_INTERFACE 342 | USB_RECIP_INTERFACE
322 | USB_DIR_OUT, /* type */ 343 | USB_DIR_OUT, /* type */
323 bindex, /* value */ 344 bindex, /* value */
@@ -343,11 +364,11 @@ static void keyspan_pda_break_ctl(struct tty_struct *tty, int break_state)
343 else 364 else
344 value = 0; /* clear break */ 365 value = 0; /* clear break */
345 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 366 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
346 4, /* set break */ 367 4, /* set break */
347 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, 368 USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
348 value, 0, NULL, 0, 2000); 369 value, 0, NULL, 0, 2000);
349 if (result < 0) 370 if (result < 0)
350 dbg("%s - error %d from usb_control_msg", 371 dbg("%s - error %d from usb_control_msg",
351 __func__, result); 372 __func__, result);
352 /* there is something funky about this.. the TCSBRK that 'cu' performs 373 /* there is something funky about this.. the TCSBRK that 'cu' performs
353 ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4 374 ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4
@@ -490,10 +511,10 @@ static int keyspan_pda_write(struct tty_struct *tty,
490 select() or poll() too) until we receive that unthrottle interrupt. 511 select() or poll() too) until we receive that unthrottle interrupt.
491 Block if we can't write anything at all, otherwise write as much as 512 Block if we can't write anything at all, otherwise write as much as
492 we can. */ 513 we can. */
493 dbg("keyspan_pda_write(%d)",count); 514 dbg("keyspan_pda_write(%d)", count);
494 if (count == 0) { 515 if (count == 0) {
495 dbg(" write request of 0 bytes"); 516 dbg(" write request of 0 bytes");
496 return (0); 517 return 0;
497 } 518 }
498 519
499 /* we might block because of: 520 /* we might block because of:
@@ -520,7 +541,7 @@ static int keyspan_pda_write(struct tty_struct *tty,
520 scheduler time, since usb_control_msg() sleeps. */ 541 scheduler time, since usb_control_msg() sleeps. */
521 if (count > priv->tx_room && !in_interrupt()) { 542 if (count > priv->tx_room && !in_interrupt()) {
522 unsigned char room; 543 unsigned char room;
523 rc = usb_control_msg(serial->dev, 544 rc = usb_control_msg(serial->dev,
524 usb_rcvctrlpipe(serial->dev, 0), 545 usb_rcvctrlpipe(serial->dev, 0),
525 6, /* write_room */ 546 6, /* write_room */
526 USB_TYPE_VENDOR | USB_RECIP_INTERFACE 547 USB_TYPE_VENDOR | USB_RECIP_INTERFACE
@@ -551,7 +572,7 @@ static int keyspan_pda_write(struct tty_struct *tty,
551 572
552 if (count) { 573 if (count) {
553 /* now transfer data */ 574 /* now transfer data */
554 memcpy (port->write_urb->transfer_buffer, buf, count); 575 memcpy(port->write_urb->transfer_buffer, buf, count);
555 /* send the data out the bulk port */ 576 /* send the data out the bulk port */
556 port->write_urb->transfer_buffer_length = count; 577 port->write_urb->transfer_buffer_length = count;
557 578
@@ -563,8 +584,7 @@ static int keyspan_pda_write(struct tty_struct *tty,
563 dbg(" usb_submit_urb(write bulk) failed"); 584 dbg(" usb_submit_urb(write bulk) failed");
564 goto exit; 585 goto exit;
565 } 586 }
566 } 587 } else {
567 else {
568 /* There wasn't any room left, so we are throttled until 588 /* There wasn't any room left, so we are throttled until
569 the buffer empties a bit */ 589 the buffer empties a bit */
570 request_unthrottle = 1; 590 request_unthrottle = 1;
@@ -583,7 +603,7 @@ exit:
583} 603}
584 604
585 605
586static void keyspan_pda_write_bulk_callback (struct urb *urb) 606static void keyspan_pda_write_bulk_callback(struct urb *urb)
587{ 607{
588 struct usb_serial_port *port = urb->context; 608 struct usb_serial_port *port = urb->context;
589 struct keyspan_pda_private *priv; 609 struct keyspan_pda_private *priv;
@@ -604,7 +624,7 @@ static int keyspan_pda_write_room(struct tty_struct *tty)
604 /* used by n_tty.c for processing of tabs and such. Giving it our 624 /* used by n_tty.c for processing of tabs and such. Giving it our
605 conservative guess is probably good enough, but needs testing by 625 conservative guess is probably good enough, but needs testing by
606 running a console through the device. */ 626 running a console through the device. */
607 return (priv->tx_room); 627 return priv->tx_room;
608} 628}
609 629
610 630
@@ -662,7 +682,7 @@ static int keyspan_pda_open(struct tty_struct *tty,
662 /* the normal serial device seems to always turn on DTR and RTS here, 682 /* the normal serial device seems to always turn on DTR and RTS here,
663 so do the same */ 683 so do the same */
664 if (tty && (tty->termios->c_cflag & CBAUD)) 684 if (tty && (tty->termios->c_cflag & CBAUD))
665 keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2) ); 685 keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2));
666 else 686 else
667 keyspan_pda_set_modem_info(serial, 0); 687 keyspan_pda_set_modem_info(serial, 0);
668 688
@@ -685,7 +705,8 @@ static void keyspan_pda_close(struct tty_struct *tty,
685 struct usb_serial *serial = port->serial; 705 struct usb_serial *serial = port->serial;
686 706
687 if (serial->dev) { 707 if (serial->dev) {
688 /* the normal serial device seems to always shut off DTR and RTS now */ 708 /* the normal serial device seems to always shut
709 off DTR and RTS now */
689 if (tty->termios->c_cflag & HUPCL) 710 if (tty->termios->c_cflag & HUPCL)
690 keyspan_pda_set_modem_info(serial, 0); 711 keyspan_pda_set_modem_info(serial, 0);
691 712
@@ -697,7 +718,7 @@ static void keyspan_pda_close(struct tty_struct *tty,
697 718
698 719
699/* download the firmware to a "fake" device (pre-renumeration) */ 720/* download the firmware to a "fake" device (pre-renumeration) */
700static int keyspan_pda_fake_startup (struct usb_serial *serial) 721static int keyspan_pda_fake_startup(struct usb_serial *serial)
701{ 722{
702 int response; 723 int response;
703 const char *fw_name; 724 const char *fw_name;
@@ -746,10 +767,10 @@ static int keyspan_pda_fake_startup (struct usb_serial *serial)
746 response = ezusb_set_reset(serial, 0); 767 response = ezusb_set_reset(serial, 0);
747 768
748 /* we want this device to fail to have a driver assigned to it. */ 769 /* we want this device to fail to have a driver assigned to it. */
749 return (1); 770 return 1;
750} 771}
751 772
752static int keyspan_pda_startup (struct usb_serial *serial) 773static int keyspan_pda_startup(struct usb_serial *serial)
753{ 774{
754 775
755 struct keyspan_pda_private *priv; 776 struct keyspan_pda_private *priv;
@@ -759,20 +780,20 @@ static int keyspan_pda_startup (struct usb_serial *serial)
759 780
760 priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL); 781 priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL);
761 if (!priv) 782 if (!priv)
762 return (1); /* error */ 783 return 1; /* error */
763 usb_set_serial_port_data(serial->port[0], priv); 784 usb_set_serial_port_data(serial->port[0], priv);
764 init_waitqueue_head(&serial->port[0]->write_wait); 785 init_waitqueue_head(&serial->port[0]->write_wait);
765 INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write); 786 INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write);
766 INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle); 787 INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle);
767 priv->serial = serial; 788 priv->serial = serial;
768 priv->port = serial->port[0]; 789 priv->port = serial->port[0];
769 return (0); 790 return 0;
770} 791}
771 792
772static void keyspan_pda_shutdown (struct usb_serial *serial) 793static void keyspan_pda_shutdown(struct usb_serial *serial)
773{ 794{
774 dbg("%s", __func__); 795 dbg("%s", __func__);
775 796
776 kfree(usb_get_serial_port_data(serial->port[0])); 797 kfree(usb_get_serial_port_data(serial->port[0]));
777} 798}
778 799
@@ -831,7 +852,7 @@ static struct usb_serial_driver keyspan_pda_device = {
831}; 852};
832 853
833 854
834static int __init keyspan_pda_init (void) 855static int __init keyspan_pda_init(void)
835{ 856{
836 int retval; 857 int retval;
837 retval = usb_serial_register(&keyspan_pda_device); 858 retval = usb_serial_register(&keyspan_pda_device);
@@ -852,7 +873,7 @@ static int __init keyspan_pda_init (void)
852 goto failed_usb_register; 873 goto failed_usb_register;
853 info(DRIVER_DESC " " DRIVER_VERSION); 874 info(DRIVER_DESC " " DRIVER_VERSION);
854 return 0; 875 return 0;
855failed_usb_register: 876failed_usb_register:
856#ifdef XIRCOM 877#ifdef XIRCOM
857 usb_serial_deregister(&xircom_pgs_fake_device); 878 usb_serial_deregister(&xircom_pgs_fake_device);
858failed_xircom_register: 879failed_xircom_register:
@@ -869,15 +890,15 @@ failed_pda_register:
869} 890}
870 891
871 892
872static void __exit keyspan_pda_exit (void) 893static void __exit keyspan_pda_exit(void)
873{ 894{
874 usb_deregister (&keyspan_pda_driver); 895 usb_deregister(&keyspan_pda_driver);
875 usb_serial_deregister (&keyspan_pda_device); 896 usb_serial_deregister(&keyspan_pda_device);
876#ifdef KEYSPAN 897#ifdef KEYSPAN
877 usb_serial_deregister (&keyspan_pda_fake_device); 898 usb_serial_deregister(&keyspan_pda_fake_device);
878#endif 899#endif
879#ifdef XIRCOM 900#ifdef XIRCOM
880 usb_serial_deregister (&xircom_pgs_fake_device); 901 usb_serial_deregister(&xircom_pgs_fake_device);
881#endif 902#endif
882} 903}
883 904
@@ -885,8 +906,8 @@ static void __exit keyspan_pda_exit (void)
885module_init(keyspan_pda_init); 906module_init(keyspan_pda_init);
886module_exit(keyspan_pda_exit); 907module_exit(keyspan_pda_exit);
887 908
888MODULE_AUTHOR( DRIVER_AUTHOR ); 909MODULE_AUTHOR(DRIVER_AUTHOR);
889MODULE_DESCRIPTION( DRIVER_DESC ); 910MODULE_DESCRIPTION(DRIVER_DESC);
890MODULE_LICENSE("GPL"); 911MODULE_LICENSE("GPL");
891 912
892module_param(debug, bool, S_IRUGO | S_IWUSR); 913module_param(debug, bool, S_IRUGO | S_IWUSR);