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>
This commit is contained in:
Alan Cox 2008-07-22 11:13:42 +01:00 committed by Linus Torvalds
parent f035a8ad15
commit 9e70f319d1

View file

@ -10,8 +10,9 @@
* the Free Software Foundation; either version 2 of the License, or * the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* See Documentation/usb/usb-serial.txt for more information on using this driver * See Documentation/usb/usb-serial.txt for more information on using this
* * driver
*
* (09/07/2001) gkh * (09/07/2001) gkh
* cleaned up the Xircom support. Added ids for Entregra device which is * cleaned up the Xircom support. Added ids for Entregra device which is
* the same as the Xircom device. Enabled the code to be compiled for * the same as the Xircom device. Enabled the code to be compiled for
@ -21,23 +22,24 @@
* support for Xircom PGSDB9 * support for Xircom PGSDB9
* *
* (05/31/2001) gkh * (05/31/2001) gkh
* switched from using spinlock to a semaphore, which fixes lots of problems. * switched from using spinlock to a semaphore, which fixes lots of
* problems.
* *
* (04/08/2001) gb * (04/08/2001) gb
* Identify version on module load. * Identify version on module load.
* *
* (11/01/2000) Adam J. Richter * (11/01/2000) Adam J. Richter
* usb_device_id table support * usb_device_id table support
* *
* (10/05/2000) gkh * (10/05/2000) gkh
* Fixed bug with urb->dev not being set properly, now that the usb * Fixed bug with urb->dev not being set properly, now that the usb
* core needs it. * core needs it.
* *
* (08/28/2000) gkh * (08/28/2000) gkh
* Added locks for SMP safeness. * Added locks for SMP safeness.
* Fixed MOD_INC and MOD_DEC logic and the ability to open a port more * Fixed MOD_INC and MOD_DEC logic and the ability to open a port more
* than once. * than once.
* *
* (07/20/2000) borchers * (07/20/2000) borchers
* - keyspan_pda_write no longer sleeps if it is called on interrupt time; * - keyspan_pda_write no longer sleeps if it is called on interrupt time;
* PPP and the line discipline with stty echo on can call write on * PPP and the line discipline with stty echo on can call write on
@ -55,14 +57,14 @@
* than done directly from the callback to avoid the race in write_chan * than done directly from the callback to avoid the race in write_chan
* - keyspan_pda_chars_in_buffer also indicates its buffer is full if the * - keyspan_pda_chars_in_buffer also indicates its buffer is full if the
* urb status is -EINPROGRESS, meaning it cannot write at the moment * urb status is -EINPROGRESS, meaning it cannot write at the moment
* *
* (07/19/2000) gkh * (07/19/2000) gkh
* Added module_init and module_exit functions to handle the fact that this * Added module_init and module_exit functions to handle the fact that this
* driver is a loadable module now. * driver is a loadable module now.
* *
* (03/26/2000) gkh * (03/26/2000) gkh
* Split driver up into device specific pieces. * Split driver up into device specific pieces.
* *
*/ */
@ -78,7 +80,7 @@
#include <linux/workqueue.h> #include <linux/workqueue.h>
#include <linux/firmware.h> #include <linux/firmware.h>
#include <linux/ihex.h> #include <linux/ihex.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/usb/serial.h> #include <linux/usb/serial.h>
@ -135,7 +137,7 @@ static struct usb_device_id id_table_combined [] = {
{ } /* Terminating entry */ { } /* Terminating entry */
}; };
MODULE_DEVICE_TABLE (usb, id_table_combined); MODULE_DEVICE_TABLE(usb, id_table_combined);
static struct usb_driver keyspan_pda_driver = { static struct usb_driver keyspan_pda_driver = {
.name = "keyspan_pda", .name = "keyspan_pda",
@ -159,9 +161,9 @@ static struct usb_device_id id_table_fake [] = {
#ifdef XIRCOM #ifdef XIRCOM
static struct usb_device_id id_table_fake_xircom [] = { static struct usb_device_id id_table_fake_xircom [] = {
{ USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) }, { USB_DEVICE(XIRCOM_VENDOR_ID, XIRCOM_FAKE_ID) },
{ USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) }, { USB_DEVICE(ENTREGRA_VENDOR_ID, ENTREGRA_FAKE_ID) },
{ } { }
}; };
#endif #endif
@ -184,7 +186,7 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
dbg(" request_unthrottle"); dbg(" request_unthrottle");
/* ask the device to tell us when the tx buffer becomes /* ask the device to tell us when the tx buffer becomes
sufficiently empty */ sufficiently empty */
result = usb_control_msg(serial->dev, result = usb_control_msg(serial->dev,
usb_sndctrlpipe(serial->dev, 0), usb_sndctrlpipe(serial->dev, 0),
7, /* request_unthrottle */ 7, /* request_unthrottle */
USB_TYPE_VENDOR | USB_RECIP_INTERFACE USB_TYPE_VENDOR | USB_RECIP_INTERFACE
@ -195,15 +197,15 @@ static void keyspan_pda_request_unthrottle(struct work_struct *work)
0, 0,
2000); 2000);
if (result < 0) if (result < 0)
dbg("%s - error %d from usb_control_msg", dbg("%s - error %d from usb_control_msg",
__func__, result); __func__, result);
} }
static void keyspan_pda_rx_interrupt (struct urb *urb) static void keyspan_pda_rx_interrupt(struct urb *urb)
{ {
struct usb_serial_port *port = urb->context; struct usb_serial_port *port = urb->context;
struct tty_struct *tty = port->port.tty; struct tty_struct *tty = port->port.tty;
unsigned char *data = urb->transfer_buffer; unsigned char *data = urb->transfer_buffer;
int i; int i;
int retval; int retval;
@ -228,14 +230,13 @@ static void keyspan_pda_rx_interrupt (struct urb *urb)
goto exit; goto exit;
} }
/* see if the message is data or a status interrupt */ /* see if the message is data or a status interrupt */
switch (data[0]) { switch (data[0]) {
case 0: case 0:
/* rest of message is rx data */ /* rest of message is rx data */
if (urb->actual_length) { if (urb->actual_length) {
for (i = 1; i < urb->actual_length ; ++i) { for (i = 1; i < urb->actual_length ; ++i)
tty_insert_flip_char(tty, data[i], 0); tty_insert_flip_char(tty, data[i], 0);
}
tty_flip_buffer_push(tty); tty_flip_buffer_push(tty);
} }
break; break;
@ -259,9 +260,9 @@ static void keyspan_pda_rx_interrupt (struct urb *urb)
} }
exit: exit:
retval = usb_submit_urb (urb, GFP_ATOMIC); retval = usb_submit_urb(urb, GFP_ATOMIC);
if (retval) if (retval)
err ("%s - usb_submit_urb failed with result %d", err("%s - usb_submit_urb failed with result %d",
__func__, retval); __func__, retval);
} }
@ -292,32 +293,52 @@ static void keyspan_pda_rx_unthrottle(struct tty_struct *tty)
} }
static speed_t keyspan_pda_setbaud (struct usb_serial *serial, speed_t baud) static speed_t keyspan_pda_setbaud(struct usb_serial *serial, speed_t baud)
{ {
int rc; int rc;
int bindex; int bindex;
switch(baud) { switch (baud) {
case 110: bindex = 0; break; case 110:
case 300: bindex = 1; break; bindex = 0;
case 1200: bindex = 2; break; break;
case 2400: bindex = 3; break; case 300:
case 4800: bindex = 4; break; bindex = 1;
case 9600: bindex = 5; break; break;
case 19200: bindex = 6; break; case 1200:
case 38400: bindex = 7; break; bindex = 2;
case 57600: bindex = 8; break; break;
case 115200: bindex = 9; break; case 2400:
default: bindex = 3;
bindex = 5; /* Default to 9600 */ break;
baud = 9600; case 4800:
bindex = 4;
break;
case 9600:
bindex = 5;
break;
case 19200:
bindex = 6;
break;
case 38400:
bindex = 7;
break;
case 57600:
bindex = 8;
break;
case 115200:
bindex = 9;
break;
default:
bindex = 5; /* Default to 9600 */
baud = 9600;
} }
/* rather than figure out how to sleep while waiting for this /* rather than figure out how to sleep while waiting for this
to complete, I just use the "legacy" API. */ to complete, I just use the "legacy" API. */
rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), rc = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
0, /* set baud */ 0, /* set baud */
USB_TYPE_VENDOR USB_TYPE_VENDOR
| USB_RECIP_INTERFACE | USB_RECIP_INTERFACE
| USB_DIR_OUT, /* type */ | USB_DIR_OUT, /* type */
bindex, /* value */ bindex, /* value */
@ -343,11 +364,11 @@ static void keyspan_pda_break_ctl(struct tty_struct *tty, int break_state)
else else
value = 0; /* clear break */ value = 0; /* clear break */
result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
4, /* set break */ 4, /* set break */
USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT, USB_TYPE_VENDOR | USB_RECIP_INTERFACE | USB_DIR_OUT,
value, 0, NULL, 0, 2000); value, 0, NULL, 0, 2000);
if (result < 0) if (result < 0)
dbg("%s - error %d from usb_control_msg", dbg("%s - error %d from usb_control_msg",
__func__, result); __func__, result);
/* there is something funky about this.. the TCSBRK that 'cu' performs /* there is something funky about this.. the TCSBRK that 'cu' performs
ought to translate into a break_ctl(-1),break_ctl(0) pair HZ/4 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,
select() or poll() too) until we receive that unthrottle interrupt. select() or poll() too) until we receive that unthrottle interrupt.
Block if we can't write anything at all, otherwise write as much as Block if we can't write anything at all, otherwise write as much as
we can. */ we can. */
dbg("keyspan_pda_write(%d)",count); dbg("keyspan_pda_write(%d)", count);
if (count == 0) { if (count == 0) {
dbg(" write request of 0 bytes"); dbg(" write request of 0 bytes");
return (0); return 0;
} }
/* we might block because of: /* we might block because of:
@ -520,7 +541,7 @@ static int keyspan_pda_write(struct tty_struct *tty,
scheduler time, since usb_control_msg() sleeps. */ scheduler time, since usb_control_msg() sleeps. */
if (count > priv->tx_room && !in_interrupt()) { if (count > priv->tx_room && !in_interrupt()) {
unsigned char room; unsigned char room;
rc = usb_control_msg(serial->dev, rc = usb_control_msg(serial->dev,
usb_rcvctrlpipe(serial->dev, 0), usb_rcvctrlpipe(serial->dev, 0),
6, /* write_room */ 6, /* write_room */
USB_TYPE_VENDOR | USB_RECIP_INTERFACE USB_TYPE_VENDOR | USB_RECIP_INTERFACE
@ -551,7 +572,7 @@ static int keyspan_pda_write(struct tty_struct *tty,
if (count) { if (count) {
/* now transfer data */ /* now transfer data */
memcpy (port->write_urb->transfer_buffer, buf, count); memcpy(port->write_urb->transfer_buffer, buf, count);
/* send the data out the bulk port */ /* send the data out the bulk port */
port->write_urb->transfer_buffer_length = count; port->write_urb->transfer_buffer_length = count;
@ -563,8 +584,7 @@ static int keyspan_pda_write(struct tty_struct *tty,
dbg(" usb_submit_urb(write bulk) failed"); dbg(" usb_submit_urb(write bulk) failed");
goto exit; goto exit;
} }
} } else {
else {
/* There wasn't any room left, so we are throttled until /* There wasn't any room left, so we are throttled until
the buffer empties a bit */ the buffer empties a bit */
request_unthrottle = 1; request_unthrottle = 1;
@ -583,7 +603,7 @@ static int keyspan_pda_write(struct tty_struct *tty,
} }
static void keyspan_pda_write_bulk_callback (struct urb *urb) static void keyspan_pda_write_bulk_callback(struct urb *urb)
{ {
struct usb_serial_port *port = urb->context; struct usb_serial_port *port = urb->context;
struct keyspan_pda_private *priv; struct keyspan_pda_private *priv;
@ -604,7 +624,7 @@ static int keyspan_pda_write_room(struct tty_struct *tty)
/* used by n_tty.c for processing of tabs and such. Giving it our /* used by n_tty.c for processing of tabs and such. Giving it our
conservative guess is probably good enough, but needs testing by conservative guess is probably good enough, but needs testing by
running a console through the device. */ running a console through the device. */
return (priv->tx_room); return priv->tx_room;
} }
@ -662,7 +682,7 @@ static int keyspan_pda_open(struct tty_struct *tty,
/* the normal serial device seems to always turn on DTR and RTS here, /* the normal serial device seems to always turn on DTR and RTS here,
so do the same */ so do the same */
if (tty && (tty->termios->c_cflag & CBAUD)) if (tty && (tty->termios->c_cflag & CBAUD))
keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2) ); keyspan_pda_set_modem_info(serial, (1<<7) | (1<<2));
else else
keyspan_pda_set_modem_info(serial, 0); keyspan_pda_set_modem_info(serial, 0);
@ -685,7 +705,8 @@ static void keyspan_pda_close(struct tty_struct *tty,
struct usb_serial *serial = port->serial; struct usb_serial *serial = port->serial;
if (serial->dev) { if (serial->dev) {
/* the normal serial device seems to always shut off DTR and RTS now */ /* the normal serial device seems to always shut
off DTR and RTS now */
if (tty->termios->c_cflag & HUPCL) if (tty->termios->c_cflag & HUPCL)
keyspan_pda_set_modem_info(serial, 0); keyspan_pda_set_modem_info(serial, 0);
@ -697,7 +718,7 @@ static void keyspan_pda_close(struct tty_struct *tty,
/* download the firmware to a "fake" device (pre-renumeration) */ /* download the firmware to a "fake" device (pre-renumeration) */
static int keyspan_pda_fake_startup (struct usb_serial *serial) static int keyspan_pda_fake_startup(struct usb_serial *serial)
{ {
int response; int response;
const char *fw_name; const char *fw_name;
@ -746,10 +767,10 @@ static int keyspan_pda_fake_startup (struct usb_serial *serial)
response = ezusb_set_reset(serial, 0); response = ezusb_set_reset(serial, 0);
/* we want this device to fail to have a driver assigned to it. */ /* we want this device to fail to have a driver assigned to it. */
return (1); return 1;
} }
static int keyspan_pda_startup (struct usb_serial *serial) static int keyspan_pda_startup(struct usb_serial *serial)
{ {
struct keyspan_pda_private *priv; struct keyspan_pda_private *priv;
@ -759,20 +780,20 @@ static int keyspan_pda_startup (struct usb_serial *serial)
priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL); priv = kmalloc(sizeof(struct keyspan_pda_private), GFP_KERNEL);
if (!priv) if (!priv)
return (1); /* error */ return 1; /* error */
usb_set_serial_port_data(serial->port[0], priv); usb_set_serial_port_data(serial->port[0], priv);
init_waitqueue_head(&serial->port[0]->write_wait); init_waitqueue_head(&serial->port[0]->write_wait);
INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write); INIT_WORK(&priv->wakeup_work, keyspan_pda_wakeup_write);
INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle); INIT_WORK(&priv->unthrottle_work, keyspan_pda_request_unthrottle);
priv->serial = serial; priv->serial = serial;
priv->port = serial->port[0]; priv->port = serial->port[0];
return (0); return 0;
} }
static void keyspan_pda_shutdown (struct usb_serial *serial) static void keyspan_pda_shutdown(struct usb_serial *serial)
{ {
dbg("%s", __func__); dbg("%s", __func__);
kfree(usb_get_serial_port_data(serial->port[0])); kfree(usb_get_serial_port_data(serial->port[0]));
} }
@ -831,7 +852,7 @@ static struct usb_serial_driver keyspan_pda_device = {
}; };
static int __init keyspan_pda_init (void) static int __init keyspan_pda_init(void)
{ {
int retval; int retval;
retval = usb_serial_register(&keyspan_pda_device); retval = usb_serial_register(&keyspan_pda_device);
@ -852,7 +873,7 @@ static int __init keyspan_pda_init (void)
goto failed_usb_register; goto failed_usb_register;
info(DRIVER_DESC " " DRIVER_VERSION); info(DRIVER_DESC " " DRIVER_VERSION);
return 0; return 0;
failed_usb_register: failed_usb_register:
#ifdef XIRCOM #ifdef XIRCOM
usb_serial_deregister(&xircom_pgs_fake_device); usb_serial_deregister(&xircom_pgs_fake_device);
failed_xircom_register: failed_xircom_register:
@ -869,15 +890,15 @@ static int __init keyspan_pda_init (void)
} }
static void __exit keyspan_pda_exit (void) static void __exit keyspan_pda_exit(void)
{ {
usb_deregister (&keyspan_pda_driver); usb_deregister(&keyspan_pda_driver);
usb_serial_deregister (&keyspan_pda_device); usb_serial_deregister(&keyspan_pda_device);
#ifdef KEYSPAN #ifdef KEYSPAN
usb_serial_deregister (&keyspan_pda_fake_device); usb_serial_deregister(&keyspan_pda_fake_device);
#endif #endif
#ifdef XIRCOM #ifdef XIRCOM
usb_serial_deregister (&xircom_pgs_fake_device); usb_serial_deregister(&xircom_pgs_fake_device);
#endif #endif
} }
@ -885,8 +906,8 @@ static void __exit keyspan_pda_exit (void)
module_init(keyspan_pda_init); module_init(keyspan_pda_init);
module_exit(keyspan_pda_exit); module_exit(keyspan_pda_exit);
MODULE_AUTHOR( DRIVER_AUTHOR ); MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION( DRIVER_DESC ); MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
module_param(debug, bool, S_IRUGO | S_IWUSR); module_param(debug, bool, S_IRUGO | S_IWUSR);