Commit 0c265f4e authored by Alan Cox's avatar Alan Cox Committed by Linus Torvalds

tty-usb-kl5kusb105: Coding style

Signed-off-by: default avatarAlan Cox <alan@redhat.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 8dd03a5b
...@@ -15,12 +15,12 @@ ...@@ -15,12 +15,12 @@
* Neither Palm, nor their contractor (MCCI) or their supplier (KLSI) provided * Neither Palm, nor their contractor (MCCI) or their supplier (KLSI) provided
* information that was not already available. * information that was not already available.
* *
* It seems that KLSI bought some silicon-design information from ScanLogic, * It seems that KLSI bought some silicon-design information from ScanLogic,
* whose SL11R processor is at the core of the KL5KUSB chipset from KLSI. * whose SL11R processor is at the core of the KL5KUSB chipset from KLSI.
* KLSI has firmware available for their devices; it is probable that the * KLSI has firmware available for their devices; it is probable that the
* firmware differs from that used by KLSI in their products. If you have an * firmware differs from that used by KLSI in their products. If you have an
* original KLSI device and can provide some information on it, I would be * original KLSI device and can provide some information on it, I would be
* most interested in adding support for it here. If you have any information * most interested in adding support for it here. If you have any information
* on the protocol used (or find errors in my reverse-engineered stuff), please * on the protocol used (or find errors in my reverse-engineered stuff), please
* let me know. * let me know.
* *
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
* 0.2 - TIOCMGET works, so autopilot(1) can be used! * 0.2 - TIOCMGET works, so autopilot(1) can be used!
* 0.1 - can be used to to pilot-xfer -p /dev/ttyUSB0 -l * 0.1 - can be used to to pilot-xfer -p /dev/ttyUSB0 -l
* *
* The driver skeleton is mainly based on mct_u232.c and various other * The driver skeleton is mainly based on mct_u232.c and various other
* pieces of code shamelessly copied from the drivers/usb/serial/ directory. * pieces of code shamelessly copied from the drivers/usb/serial/ directory.
*/ */
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
#include <linux/tty_driver.h> #include <linux/tty_driver.h>
#include <linux/tty_flip.h> #include <linux/tty_flip.h>
#include <linux/module.h> #include <linux/module.h>
#include <asm/uaccess.h> #include <linux/uaccess.h>
#include <asm/unaligned.h> #include <asm/unaligned.h>
#include <linux/usb.h> #include <linux/usb.h>
#include <linux/usb/serial.h> #include <linux/usb/serial.h>
...@@ -72,37 +72,25 @@ static int debug; ...@@ -72,37 +72,25 @@ static int debug;
/* /*
* Function prototypes * Function prototypes
*/ */
static int klsi_105_startup (struct usb_serial *serial); static int klsi_105_startup(struct usb_serial *serial);
static void klsi_105_shutdown (struct usb_serial *serial); static void klsi_105_shutdown(struct usb_serial *serial);
static int klsi_105_open (struct tty_struct *tty, static int klsi_105_open(struct tty_struct *tty,
struct usb_serial_port *port, struct usb_serial_port *port, struct file *filp);
struct file *filp); static void klsi_105_close(struct tty_struct *tty,
static void klsi_105_close (struct tty_struct *tty, struct usb_serial_port *port, struct file *filp);
struct usb_serial_port *port, static int klsi_105_write(struct tty_struct *tty,
struct file *filp); struct usb_serial_port *port, const unsigned char *buf, int count);
static int klsi_105_write (struct tty_struct *tty, static void klsi_105_write_bulk_callback(struct urb *urb);
struct usb_serial_port *port, static int klsi_105_chars_in_buffer(struct tty_struct *tty);
const unsigned char *buf, static int klsi_105_write_room(struct tty_struct *tty);
int count); static void klsi_105_read_bulk_callback(struct urb *urb);
static void klsi_105_write_bulk_callback (struct urb *urb); static void klsi_105_set_termios(struct tty_struct *tty,
static int klsi_105_chars_in_buffer (struct tty_struct *tty); struct usb_serial_port *port, struct ktermios *old);
static int klsi_105_write_room (struct tty_struct *tty); static void klsi_105_throttle(struct tty_struct *tty);
static void klsi_105_unthrottle(struct tty_struct *tty);
static void klsi_105_read_bulk_callback (struct urb *urb); static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file);
static void klsi_105_set_termios (struct tty_struct *tty, static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
struct usb_serial_port *port, unsigned int set, unsigned int clear);
struct ktermios *old);
static void klsi_105_throttle (struct tty_struct *tty);
static void klsi_105_unthrottle (struct tty_struct *tty);
/*
static void klsi_105_break_ctl (struct tty_struct *tty,
int break_state );
*/
static int klsi_105_tiocmget (struct tty_struct *tty,
struct file *file);
static int klsi_105_tiocmset (struct tty_struct *tty,
struct file *file, unsigned int set,
unsigned int clear);
/* /*
* All of the device info needed for the KLSI converters. * All of the device info needed for the KLSI converters.
...@@ -113,7 +101,7 @@ static struct usb_device_id id_table [] = { ...@@ -113,7 +101,7 @@ static struct usb_device_id id_table [] = {
{ } /* Terminating entry */ { } /* Terminating entry */
}; };
MODULE_DEVICE_TABLE (usb, id_table); MODULE_DEVICE_TABLE(usb, id_table);
static struct usb_driver kl5kusb105d_driver = { static struct usb_driver kl5kusb105d_driver = {
.name = "kl5kusb105d", .name = "kl5kusb105d",
...@@ -138,7 +126,7 @@ static struct usb_serial_driver kl5kusb105d_device = { ...@@ -138,7 +126,7 @@ static struct usb_serial_driver kl5kusb105d_device = {
.write_bulk_callback = klsi_105_write_bulk_callback, .write_bulk_callback = klsi_105_write_bulk_callback,
.chars_in_buffer = klsi_105_chars_in_buffer, .chars_in_buffer = klsi_105_chars_in_buffer,
.write_room = klsi_105_write_room, .write_room = klsi_105_write_room,
.read_bulk_callback =klsi_105_read_bulk_callback, .read_bulk_callback = klsi_105_read_bulk_callback,
.set_termios = klsi_105_set_termios, .set_termios = klsi_105_set_termios,
/*.break_ctl = klsi_105_break_ctl,*/ /*.break_ctl = klsi_105_break_ctl,*/
.tiocmget = klsi_105_tiocmget, .tiocmget = klsi_105_tiocmget,
...@@ -165,7 +153,7 @@ struct klsi_105_private { ...@@ -165,7 +153,7 @@ struct klsi_105_private {
struct ktermios termios; struct ktermios termios;
unsigned long line_state; /* modem line settings */ unsigned long line_state; /* modem line settings */
/* write pool */ /* write pool */
struct urb * write_urb_pool[NUM_URBS]; struct urb *write_urb_pool[NUM_URBS];
spinlock_t lock; spinlock_t lock;
unsigned long bytes_in; unsigned long bytes_in;
unsigned long bytes_out; unsigned long bytes_out;
...@@ -184,15 +172,15 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port, ...@@ -184,15 +172,15 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port,
{ {
int rc; int rc;
rc = usb_control_msg(port->serial->dev, rc = usb_control_msg(port->serial->dev,
usb_sndctrlpipe(port->serial->dev, 0), usb_sndctrlpipe(port->serial->dev, 0),
KL5KUSB105A_SIO_SET_DATA, KL5KUSB105A_SIO_SET_DATA,
USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE, USB_TYPE_VENDOR | USB_DIR_OUT | USB_RECIP_INTERFACE,
0, /* value */ 0, /* value */
0, /* index */ 0, /* index */
settings, settings,
sizeof(struct klsi_105_port_settings), sizeof(struct klsi_105_port_settings),
KLSI_TIMEOUT); KLSI_TIMEOUT);
if (rc < 0) if (rc < 0)
err("Change port settings failed (error = %d)", rc); err("Change port settings failed (error = %d)", rc);
info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d", info("%s - %d byte block, baudrate %x, databits %d, u1 %d, u2 %d",
...@@ -200,7 +188,7 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port, ...@@ -200,7 +188,7 @@ static int klsi_105_chg_port_settings(struct usb_serial_port *port,
settings->pktlen, settings->pktlen,
settings->baudrate, settings->databits, settings->baudrate, settings->databits,
settings->unknown1, settings->unknown2); settings->unknown1, settings->unknown2);
return rc; return rc;
} /* klsi_105_chg_port_settings */ } /* klsi_105_chg_port_settings */
/* translate a 16-bit status value from the device to linux's TIO bits */ /* translate a 16-bit status value from the device to linux's TIO bits */
...@@ -214,9 +202,9 @@ static unsigned long klsi_105_status2linestate(const __u16 status) ...@@ -214,9 +202,9 @@ static unsigned long klsi_105_status2linestate(const __u16 status)
return res; return res;
} }
/* /*
* Read line control via vendor command and return result through * Read line control via vendor command and return result through
* *line_state_p * *line_state_p
*/ */
/* It seems that the status buffer has always only 2 bytes length */ /* It seems that the status buffer has always only 2 bytes length */
#define KLSI_STATUSBUF_LEN 2 #define KLSI_STATUSBUF_LEN 2
...@@ -224,14 +212,14 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, ...@@ -224,14 +212,14 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
unsigned long *line_state_p) unsigned long *line_state_p)
{ {
int rc; int rc;
__u8 status_buf[KLSI_STATUSBUF_LEN] = { -1,-1}; __u8 status_buf[KLSI_STATUSBUF_LEN] = { -1, -1};
__u16 status; __u16 status;
info("%s - sending SIO Poll request", __func__); info("%s - sending SIO Poll request", __func__);
rc = usb_control_msg(port->serial->dev, rc = usb_control_msg(port->serial->dev,
usb_rcvctrlpipe(port->serial->dev, 0), usb_rcvctrlpipe(port->serial->dev, 0),
KL5KUSB105A_SIO_POLL, KL5KUSB105A_SIO_POLL,
USB_TYPE_VENDOR | USB_DIR_IN, USB_TYPE_VENDOR | USB_DIR_IN,
0, /* value */ 0, /* value */
0, /* index */ 0, /* index */
status_buf, KLSI_STATUSBUF_LEN, status_buf, KLSI_STATUSBUF_LEN,
...@@ -247,8 +235,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, ...@@ -247,8 +235,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
*line_state_p = klsi_105_status2linestate(status); *line_state_p = klsi_105_status2linestate(status);
} }
return rc;
return rc;
} }
...@@ -256,7 +243,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port, ...@@ -256,7 +243,7 @@ static int klsi_105_get_line_state(struct usb_serial_port *port,
* Driver's tty interface functions * Driver's tty interface functions
*/ */
static int klsi_105_startup (struct usb_serial *serial) static int klsi_105_startup(struct usb_serial *serial)
{ {
struct klsi_105_private *priv; struct klsi_105_private *priv;
int i, j; int i, j;
...@@ -266,7 +253,7 @@ static int klsi_105_startup (struct usb_serial *serial) ...@@ -266,7 +253,7 @@ static int klsi_105_startup (struct usb_serial *serial)
*/ */
/* allocate the private data structure */ /* allocate the private data structure */
for (i=0; i<serial->num_ports; i++) { for (i = 0; i < serial->num_ports; i++) {
priv = kmalloc(sizeof(struct klsi_105_private), priv = kmalloc(sizeof(struct klsi_105_private),
GFP_KERNEL); GFP_KERNEL);
if (!priv) { if (!priv) {
...@@ -287,9 +274,9 @@ static int klsi_105_startup (struct usb_serial *serial) ...@@ -287,9 +274,9 @@ static int klsi_105_startup (struct usb_serial *serial)
priv->bytes_out = 0; priv->bytes_out = 0;
usb_set_serial_port_data(serial->port[i], priv); usb_set_serial_port_data(serial->port[i], priv);
spin_lock_init (&priv->lock); spin_lock_init(&priv->lock);
for (j=0; j<NUM_URBS; j++) { for (j = 0; j < NUM_URBS; j++) {
struct urb* urb = usb_alloc_urb(0, GFP_KERNEL); struct urb *urb = usb_alloc_urb(0, GFP_KERNEL);
priv->write_urb_pool[j] = urb; priv->write_urb_pool[j] = urb;
if (urb == NULL) { if (urb == NULL) {
...@@ -297,10 +284,11 @@ static int klsi_105_startup (struct usb_serial *serial) ...@@ -297,10 +284,11 @@ static int klsi_105_startup (struct usb_serial *serial)
goto err_cleanup; goto err_cleanup;
} }
urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, urb->transfer_buffer =
GFP_KERNEL); kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
if (!urb->transfer_buffer) { if (!urb->transfer_buffer) {
err("%s - out of memory for urb buffers.", __func__); err("%s - out of memory for urb buffers.",
__func__);
goto err_cleanup; goto err_cleanup;
} }
} }
...@@ -308,13 +296,13 @@ static int klsi_105_startup (struct usb_serial *serial) ...@@ -308,13 +296,13 @@ static int klsi_105_startup (struct usb_serial *serial)
/* priv->termios is left uninitalized until port opening */ /* priv->termios is left uninitalized until port opening */
init_waitqueue_head(&serial->port[i]->write_wait); init_waitqueue_head(&serial->port[i]->write_wait);
} }
return 0; return 0;
err_cleanup: err_cleanup:
for (; i >= 0; i--) { for (; i >= 0; i--) {
priv = usb_get_serial_port_data(serial->port[i]); priv = usb_get_serial_port_data(serial->port[i]);
for (j=0; j < NUM_URBS; j++) { for (j = 0; j < NUM_URBS; j++) {
if (priv->write_urb_pool[j]) { if (priv->write_urb_pool[j]) {
kfree(priv->write_urb_pool[j]->transfer_buffer); kfree(priv->write_urb_pool[j]->transfer_buffer);
usb_free_urb(priv->write_urb_pool[j]); usb_free_urb(priv->write_urb_pool[j]);
...@@ -326,22 +314,23 @@ err_cleanup: ...@@ -326,22 +314,23 @@ err_cleanup:
} /* klsi_105_startup */ } /* klsi_105_startup */
static void klsi_105_shutdown (struct usb_serial *serial) static void klsi_105_shutdown(struct usb_serial *serial)
{ {
int i; int i;
dbg("%s", __func__); dbg("%s", __func__);
/* stop reads and writes on all ports */ /* stop reads and writes on all ports */
for (i=0; i < serial->num_ports; ++i) { for (i = 0; i < serial->num_ports; ++i) {
struct klsi_105_private *priv = usb_get_serial_port_data(serial->port[i]); struct klsi_105_private *priv =
usb_get_serial_port_data(serial->port[i]);
unsigned long flags; unsigned long flags;
if (priv) { if (priv) {
/* kill our write urb pool */ /* kill our write urb pool */
int j; int j;
struct urb **write_urbs = priv->write_urb_pool; struct urb **write_urbs = priv->write_urb_pool;
spin_lock_irqsave(&priv->lock,flags); spin_lock_irqsave(&priv->lock, flags);
for (j = 0; j < NUM_URBS; j++) { for (j = 0; j < NUM_URBS; j++) {
if (write_urbs[j]) { if (write_urbs[j]) {
...@@ -353,12 +342,10 @@ static void klsi_105_shutdown (struct usb_serial *serial) ...@@ -353,12 +342,10 @@ static void klsi_105_shutdown (struct usb_serial *serial)
* oopses. */ * oopses. */
/* usb_kill_urb(write_urbs[j]); */ /* usb_kill_urb(write_urbs[j]); */
kfree(write_urbs[j]->transfer_buffer); kfree(write_urbs[j]->transfer_buffer);
usb_free_urb (write_urbs[j]); usb_free_urb(write_urbs[j]);
} }
} }
spin_unlock_irqrestore(&priv->lock, flags);
spin_unlock_irqrestore (&priv->lock, flags);
kfree(priv); kfree(priv);
usb_set_serial_port_data(serial->port[i], NULL); usb_set_serial_port_data(serial->port[i], NULL);
} }
...@@ -384,7 +371,7 @@ static int klsi_105_open(struct tty_struct *tty, ...@@ -384,7 +371,7 @@ static int klsi_105_open(struct tty_struct *tty,
/* Do a defined restart: /* Do a defined restart:
* Set up sane default baud rate and send the 'READ_ON' * Set up sane default baud rate and send the 'READ_ON'
* vendor command. * vendor command.
* FIXME: set modem line control (how?) * FIXME: set modem line control (how?)
* Then read the modem line control and store values in * Then read the modem line control and store values in
* priv->line_state. * priv->line_state.
...@@ -395,24 +382,24 @@ static int klsi_105_open(struct tty_struct *tty, ...@@ -395,24 +382,24 @@ static int klsi_105_open(struct tty_struct *tty,
cfg.unknown1 = 0; cfg.unknown1 = 0;
cfg.unknown2 = 1; cfg.unknown2 = 1;
klsi_105_chg_port_settings(port, &cfg); klsi_105_chg_port_settings(port, &cfg);
/* set up termios structure */ /* set up termios structure */
spin_lock_irqsave (&priv->lock, flags); spin_lock_irqsave(&priv->lock, flags);
priv->termios.c_iflag = tty->termios->c_iflag; priv->termios.c_iflag = tty->termios->c_iflag;
priv->termios.c_oflag = tty->termios->c_oflag; priv->termios.c_oflag = tty->termios->c_oflag;
priv->termios.c_cflag = tty->termios->c_cflag; priv->termios.c_cflag = tty->termios->c_cflag;
priv->termios.c_lflag = tty->termios->c_lflag; priv->termios.c_lflag = tty->termios->c_lflag;
for (i=0; i<NCCS; i++) for (i = 0; i < NCCS; i++)
priv->termios.c_cc[i] = tty->termios->c_cc[i]; priv->termios.c_cc[i] = tty->termios->c_cc[i];
priv->cfg.pktlen = cfg.pktlen; priv->cfg.pktlen = cfg.pktlen;
priv->cfg.baudrate = cfg.baudrate; priv->cfg.baudrate = cfg.baudrate;
priv->cfg.databits = cfg.databits; priv->cfg.databits = cfg.databits;
priv->cfg.unknown1 = cfg.unknown1; priv->cfg.unknown1 = cfg.unknown1;
priv->cfg.unknown2 = cfg.unknown2; priv->cfg.unknown2 = cfg.unknown2;
spin_unlock_irqrestore (&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
/* READ_ON and urb submission */ /* READ_ON and urb submission */
usb_fill_bulk_urb(port->read_urb, port->serial->dev, usb_fill_bulk_urb(port->read_urb, port->serial->dev,
usb_rcvbulkpipe(port->serial->dev, usb_rcvbulkpipe(port->serial->dev,
port->bulk_in_endpointAddress), port->bulk_in_endpointAddress),
port->read_urb->transfer_buffer, port->read_urb->transfer_buffer,
...@@ -428,7 +415,7 @@ static int klsi_105_open(struct tty_struct *tty, ...@@ -428,7 +415,7 @@ static int klsi_105_open(struct tty_struct *tty,
} }
rc = usb_control_msg(port->serial->dev, rc = usb_control_msg(port->serial->dev,
usb_sndctrlpipe(port->serial->dev,0), usb_sndctrlpipe(port->serial->dev, 0),
KL5KUSB105A_SIO_CONFIGURE, KL5KUSB105A_SIO_CONFIGURE,
USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE, USB_TYPE_VENDOR|USB_DIR_OUT|USB_RECIP_INTERFACE,
KL5KUSB105A_SIO_CONFIGURE_READ_ON, KL5KUSB105A_SIO_CONFIGURE_READ_ON,
...@@ -439,14 +426,14 @@ static int klsi_105_open(struct tty_struct *tty, ...@@ -439,14 +426,14 @@ static int klsi_105_open(struct tty_struct *tty,
if (rc < 0) { if (rc < 0) {
err("Enabling read failed (error = %d)", rc); err("Enabling read failed (error = %d)", rc);
retval = rc; retval = rc;
} else } else
dbg("%s - enabled reading", __func__); dbg("%s - enabled reading", __func__);
rc = klsi_105_get_line_state(port, &line_state); rc = klsi_105_get_line_state(port, &line_state);
if (rc >= 0) { if (rc >= 0) {
spin_lock_irqsave (&priv->lock, flags); spin_lock_irqsave(&priv->lock, flags);
priv->line_state = line_state; priv->line_state = line_state;
spin_unlock_irqrestore (&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
dbg("%s - read line state 0x%lx", __func__, line_state); dbg("%s - read line state 0x%lx", __func__, line_state);
retval = 0; retval = 0;
} else } else
...@@ -468,14 +455,14 @@ static void klsi_105_close(struct tty_struct *tty, ...@@ -468,14 +455,14 @@ static void klsi_105_close(struct tty_struct *tty,
mutex_lock(&port->serial->disc_mutex); mutex_lock(&port->serial->disc_mutex);
if (!port->serial->disconnected) { if (!port->serial->disconnected) {
/* send READ_OFF */ /* send READ_OFF */
rc = usb_control_msg (port->serial->dev, rc = usb_control_msg(port->serial->dev,
usb_sndctrlpipe(port->serial->dev, 0), usb_sndctrlpipe(port->serial->dev, 0),
KL5KUSB105A_SIO_CONFIGURE, KL5KUSB105A_SIO_CONFIGURE,
USB_TYPE_VENDOR | USB_DIR_OUT, USB_TYPE_VENDOR | USB_DIR_OUT,
KL5KUSB105A_SIO_CONFIGURE_READ_OFF, KL5KUSB105A_SIO_CONFIGURE_READ_OFF,
0, /* index */ 0, /* index */
NULL, 0, NULL, 0,
KLSI_TIMEOUT); KLSI_TIMEOUT);
if (rc < 0) if (rc < 0)
err("Disabling read failed (error = %d)", rc); err("Disabling read failed (error = %d)", rc);
} }
...@@ -488,12 +475,13 @@ static void klsi_105_close(struct tty_struct *tty, ...@@ -488,12 +475,13 @@ static void klsi_105_close(struct tty_struct *tty,
/* FIXME */ /* FIXME */
/* wgg - do I need this? I think so. */ /* wgg - do I need this? I think so. */
usb_kill_urb(port->interrupt_in_urb); usb_kill_urb(port->interrupt_in_urb);
info("kl5kusb105 port stats: %ld bytes in, %ld bytes out", priv->bytes_in, priv->bytes_out); info("kl5kusb105 port stats: %ld bytes in, %ld bytes out",
priv->bytes_in, priv->bytes_out);
} /* klsi_105_close */ } /* klsi_105_close */
/* We need to write a complete 64-byte data block and encode the /* We need to write a complete 64-byte data block and encode the
* number actually sent in the first double-byte, LSB-order. That * number actually sent in the first double-byte, LSB-order. That
* leaves at most 62 bytes of payload. * leaves at most 62 bytes of payload.
*/ */
#define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */ #define KLSI_105_DATA_OFFSET 2 /* in the bulk urb data block */
...@@ -504,7 +492,7 @@ static int klsi_105_write(struct tty_struct *tty, ...@@ -504,7 +492,7 @@ static int klsi_105_write(struct tty_struct *tty,
{ {
struct klsi_105_private *priv = usb_get_serial_port_data(port); struct klsi_105_private *priv = usb_get_serial_port_data(port);
int result, size; int result, size;
int bytes_sent=0; int bytes_sent = 0;
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
...@@ -513,34 +501,37 @@ static int klsi_105_write(struct tty_struct *tty, ...@@ -513,34 +501,37 @@ static int klsi_105_write(struct tty_struct *tty,
struct urb *urb = NULL; struct urb *urb = NULL;
unsigned long flags; unsigned long flags;
int i; int i;
/* since the pool is per-port we might not need the spin lock !? */ /* since the pool is per-port we might not need
spin_lock_irqsave (&priv->lock, flags); the spin lock !? */
for (i=0; i<NUM_URBS; i++) { spin_lock_irqsave(&priv->lock, flags);
for (i = 0; i < NUM_URBS; i++) {
if (priv->write_urb_pool[i]->status != -EINPROGRESS) { if (priv->write_urb_pool[i]->status != -EINPROGRESS) {
urb = priv->write_urb_pool[i]; urb = priv->write_urb_pool[i];
dbg("%s - using pool URB %d", __func__, i); dbg("%s - using pool URB %d", __func__, i);
break; break;
} }
} }
spin_unlock_irqrestore (&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
if (urb==NULL) { if (urb == NULL) {
dbg("%s - no more free urbs", __func__); dbg("%s - no more free urbs", __func__);
goto exit; goto exit;
} }
if (urb->transfer_buffer == NULL) { if (urb->transfer_buffer == NULL) {
urb->transfer_buffer = kmalloc (URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC); urb->transfer_buffer =
kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);
if (urb->transfer_buffer == NULL) { if (urb->transfer_buffer == NULL) {
err("%s - no more kernel memory...", __func__); err("%s - no more kernel memory...", __func__);
goto exit; goto exit;
} }
} }
size = min (count, port->bulk_out_size - KLSI_105_DATA_OFFSET); size = min(count, port->bulk_out_size - KLSI_105_DATA_OFFSET);
size = min (size, URB_TRANSFER_BUFFER_SIZE - KLSI_105_DATA_OFFSET); size = min(size, URB_TRANSFER_BUFFER_SIZE -
KLSI_105_DATA_OFFSET);
memcpy (urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size); memcpy(urb->transfer_buffer + KLSI_105_DATA_OFFSET, buf, size);
/* write payload size into transfer buffer */ /* write payload size into transfer buffer */
((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF); ((__u8 *)urb->transfer_buffer)[0] = (__u8) (size & 0xFF);
...@@ -558,7 +549,8 @@ static int klsi_105_write(struct tty_struct *tty, ...@@ -558,7 +549,8 @@ static int klsi_105_write(struct tty_struct *tty,
/* send the data out the bulk port */ /* send the data out the bulk port */
result = usb_submit_urb(urb, GFP_ATOMIC); result = usb_submit_urb(urb, GFP_ATOMIC);
if (result) { if (result) {
err("%s - failed submitting write urb, error %d", __func__, result); err("%s - failed submitting write urb, error %d",
__func__, result);
goto exit; goto exit;
} }
buf += size; buf += size;
...@@ -567,12 +559,12 @@ static int klsi_105_write(struct tty_struct *tty, ...@@ -567,12 +559,12 @@ static int klsi_105_write(struct tty_struct *tty,
} }
exit: exit:
/* lockless, but it's for debug info only... */ /* lockless, but it's for debug info only... */
priv->bytes_out+=bytes_sent; priv->bytes_out += bytes_sent;
return bytes_sent; /* that's how much we wrote */ return bytes_sent; /* that's how much we wrote */
} /* klsi_105_write */ } /* klsi_105_write */
static void klsi_105_write_bulk_callback ( struct urb *urb) static void klsi_105_write_bulk_callback(struct urb *urb)
{ {
struct usb_serial_port *port = urb->context; struct usb_serial_port *port = urb->context;
int status = urb->status; int status = urb->status;
...@@ -590,7 +582,7 @@ static void klsi_105_write_bulk_callback ( struct urb *urb) ...@@ -590,7 +582,7 @@ static void klsi_105_write_bulk_callback ( struct urb *urb)
/* return number of characters currently in the writing process */ /* return number of characters currently in the writing process */
static int klsi_105_chars_in_buffer (struct tty_struct *tty) static int klsi_105_chars_in_buffer(struct tty_struct *tty)
{ {
struct usb_serial_port *port = tty->driver_data; struct usb_serial_port *port = tty->driver_data;
int chars = 0; int chars = 0;
...@@ -598,21 +590,20 @@ static int klsi_105_chars_in_buffer (struct tty_struct *tty) ...@@ -598,21 +590,20 @@ static int klsi_105_chars_in_buffer (struct tty_struct *tty)
unsigned long flags; unsigned long flags;
struct klsi_105_private *priv = usb_get_serial_port_data(port); struct klsi_105_private *priv = usb_get_serial_port_data(port);
spin_lock_irqsave (&priv->lock, flags); spin_lock_irqsave(&priv->lock, flags);
for (i = 0; i < NUM_URBS; ++i) { for (i = 0; i < NUM_URBS; ++i) {
if (priv->write_urb_pool[i]->status == -EINPROGRESS) { if (priv->write_urb_pool[i]->status == -EINPROGRESS)
chars += URB_TRANSFER_BUFFER_SIZE; chars += URB_TRANSFER_BUFFER_SIZE;
}
} }
spin_unlock_irqrestore (&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
dbg("%s - returns %d", __func__, chars); dbg("%s - returns %d", __func__, chars);
return (chars); return chars;
} }
static int klsi_105_write_room (struct tty_struct *tty) static int klsi_105_write_room(struct tty_struct *tty)
{ {
struct usb_serial_port *port = tty->driver_data; struct usb_serial_port *port = tty->driver_data;
unsigned long flags; unsigned long flags;
...@@ -620,22 +611,21 @@ static int klsi_105_write_room (struct tty_struct *tty) ...@@ -620,22 +611,21 @@ static int klsi_105_write_room (struct tty_struct *tty)
int room = 0; int room = 0;
struct klsi_105_private *priv = usb_get_serial_port_data(port); struct klsi_105_private *priv = usb_get_serial_port_data(port);
spin_lock_irqsave (&priv->lock, flags); spin_lock_irqsave(&priv->lock, flags);
for (i = 0; i < NUM_URBS; ++i) { for (i = 0; i < NUM_URBS; ++i) {
if (priv->write_urb_pool[i]->status != -EINPROGRESS) { if (priv->write_urb_pool[i]->status != -EINPROGRESS)
room += URB_TRANSFER_BUFFER_SIZE; room += URB_TRANSFER_BUFFER_SIZE;
}
} }
spin_unlock_irqrestore (&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
dbg("%s - returns %d", __func__, room); dbg("%s - returns %d", __func__, room);
return (room); return room;
} }
static void klsi_105_read_bulk_callback (struct urb *urb) static void klsi_105_read_bulk_callback(struct urb *urb)
{ {
struct usb_serial_port *port = urb->context; struct usb_serial_port *port = urb->context;
struct klsi_105_private *priv = usb_get_serial_port_data(port); struct klsi_105_private *priv = usb_get_serial_port_data(port);
...@@ -674,7 +664,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb) ...@@ -674,7 +664,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
* against re-entry an then mixed-up data because of * against re-entry an then mixed-up data because of
* intermixed tty_flip_buffer_push()s * intermixed tty_flip_buffer_push()s
* FIXME * FIXME
*/ */
usb_serial_debug_data(debug, &port->dev, __func__, usb_serial_debug_data(debug, &port->dev, __func__,
urb->actual_length, data); urb->actual_length, data);
...@@ -694,7 +684,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb) ...@@ -694,7 +684,7 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
priv->bytes_in += bytes_sent; priv->bytes_in += bytes_sent;
} }
/* Continue trying to always read */ /* Continue trying to always read */
usb_fill_bulk_urb(port->read_urb, port->serial->dev, usb_fill_bulk_urb(port->read_urb, port->serial->dev,
usb_rcvbulkpipe(port->serial->dev, usb_rcvbulkpipe(port->serial->dev,
port->bulk_in_endpointAddress), port->bulk_in_endpointAddress),
port->read_urb->transfer_buffer, port->read_urb->transfer_buffer,
...@@ -703,13 +693,14 @@ static void klsi_105_read_bulk_callback (struct urb *urb) ...@@ -703,13 +693,14 @@ static void klsi_105_read_bulk_callback (struct urb *urb)
port); port);
rc = usb_submit_urb(port->read_urb, GFP_ATOMIC); rc = usb_submit_urb(port->read_urb, GFP_ATOMIC);
if (rc) if (rc)
err("%s - failed resubmitting read urb, error %d", __func__, rc); err("%s - failed resubmitting read urb, error %d",
__func__, rc);
} /* klsi_105_read_bulk_callback */ } /* klsi_105_read_bulk_callback */
static void klsi_105_set_termios (struct tty_struct *tty, static void klsi_105_set_termios(struct tty_struct *tty,
struct usb_serial_port *port, struct usb_serial_port *port,
struct ktermios *old_termios) struct ktermios *old_termios)
{ {
struct klsi_105_private *priv = usb_get_serial_port_data(port); struct klsi_105_private *priv = usb_get_serial_port_data(port);
unsigned int iflag = tty->termios->c_iflag; unsigned int iflag = tty->termios->c_iflag;
...@@ -719,65 +710,63 @@ static void klsi_105_set_termios (struct tty_struct *tty, ...@@ -719,65 +710,63 @@ static void klsi_105_set_termios (struct tty_struct *tty,
struct klsi_105_port_settings cfg; struct klsi_105_port_settings cfg;
unsigned long flags; unsigned long flags;
speed_t baud; speed_t baud;
/* lock while we are modifying the settings */ /* lock while we are modifying the settings */
spin_lock_irqsave (&priv->lock, flags); spin_lock_irqsave(&priv->lock, flags);
/* /*
* Update baud rate * Update baud rate
*/ */
baud = tty_get_baud_rate(tty); baud = tty_get_baud_rate(tty);
if( (cflag & CBAUD) != (old_cflag & CBAUD) ) { if ((cflag & CBAUD) != (old_cflag & CBAUD)) {
/* reassert DTR and (maybe) RTS on transition from B0 */ /* reassert DTR and (maybe) RTS on transition from B0 */
if( (old_cflag & CBAUD) == B0 ) { if ((old_cflag & CBAUD) == B0) {
dbg("%s: baud was B0", __func__); dbg("%s: baud was B0", __func__);
#if 0 #if 0
priv->control_state |= TIOCM_DTR; priv->control_state |= TIOCM_DTR;
/* don't set RTS if using hardware flow control */ /* don't set RTS if using hardware flow control */
if (!(old_cflag & CRTSCTS)) { if (!(old_cflag & CRTSCTS))
priv->control_state |= TIOCM_RTS; priv->control_state |= TIOCM_RTS;
}
mct_u232_set_modem_ctrl(serial, priv->control_state); mct_u232_set_modem_ctrl(serial, priv->control_state);
#endif #endif
} }
} }
switch(baud) { switch (baud) {
case 0: /* handled below */ case 0: /* handled below */
break; break;
case 1200: case 1200:
priv->cfg.baudrate = kl5kusb105a_sio_b1200; priv->cfg.baudrate = kl5kusb105a_sio_b1200;
break; break;
case 2400: case 2400:
priv->cfg.baudrate = kl5kusb105a_sio_b2400; priv->cfg.baudrate = kl5kusb105a_sio_b2400;
break; break;
case 4800: case 4800:
priv->cfg.baudrate = kl5kusb105a_sio_b4800; priv->cfg.baudrate = kl5kusb105a_sio_b4800;
break; break;
case 9600: case 9600:
priv->cfg.baudrate = kl5kusb105a_sio_b9600;
break;
case 19200:
priv->cfg.baudrate = kl5kusb105a_sio_b19200;
break;
case 38400:
priv->cfg.baudrate = kl5kusb105a_sio_b38400;
break;
case 57600:
priv->cfg.baudrate = kl5kusb105a_sio_b57600;
break;
case 115200:
priv->cfg.baudrate = kl5kusb105a_sio_b115200;
break;
default:
dbg("KLSI USB->Serial converter:"
" unsupported baudrate request, using default of 9600");
priv->cfg.baudrate = kl5kusb105a_sio_b9600; priv->cfg.baudrate = kl5kusb105a_sio_b9600;
break; baud = 9600;
case 19200: break;
priv->cfg.baudrate = kl5kusb105a_sio_b19200;
break;
case 38400:
priv->cfg.baudrate = kl5kusb105a_sio_b38400;
break;
case 57600:
priv->cfg.baudrate = kl5kusb105a_sio_b57600;
break;
case 115200:
priv->cfg.baudrate = kl5kusb105a_sio_b115200;
break;
default:
dbg("KLSI USB->Serial converter:"
" unsupported baudrate request, using default"
" of 9600");
priv->cfg.baudrate = kl5kusb105a_sio_b9600;
baud = 9600;
break;
} }
if ((cflag & CBAUD) == B0 ) { if ((cflag & CBAUD) == B0) {
dbg("%s: baud is B0", __func__); dbg("%s: baud is B0", __func__);
/* Drop RTS and DTR */ /* Drop RTS and DTR */
/* maybe this should be simulated by sending read /* maybe this should be simulated by sending read
...@@ -786,7 +775,7 @@ static void klsi_105_set_termios (struct tty_struct *tty, ...@@ -786,7 +775,7 @@ static void klsi_105_set_termios (struct tty_struct *tty,
; ;
#if 0 #if 0
priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
mct_u232_set_modem_ctrl(serial, priv->control_state); mct_u232_set_modem_ctrl(serial, priv->control_state);
#endif #endif
} }
tty_encode_baud_rate(tty, baud, baud); tty_encode_baud_rate(tty, baud, baud);
...@@ -796,11 +785,11 @@ static void klsi_105_set_termios (struct tty_struct *tty, ...@@ -796,11 +785,11 @@ static void klsi_105_set_termios (struct tty_struct *tty,
switch (cflag & CSIZE) { switch (cflag & CSIZE) {
case CS5: case CS5:
dbg("%s - 5 bits/byte not supported", __func__); dbg("%s - 5 bits/byte not supported", __func__);
spin_unlock_irqrestore (&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
return ; return ;
case CS6: case CS6:
dbg("%s - 6 bits/byte not supported", __func__); dbg("%s - 6 bits/byte not supported", __func__);
spin_unlock_irqrestore (&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
return ; return ;
case CS7: case CS7:
priv->cfg.databits = kl5kusb105a_dtb_7; priv->cfg.databits = kl5kusb105a_dtb_7;
...@@ -819,8 +808,7 @@ static void klsi_105_set_termios (struct tty_struct *tty, ...@@ -819,8 +808,7 @@ static void klsi_105_set_termios (struct tty_struct *tty,
* Update line control register (LCR) * Update line control register (LCR)
*/ */
if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD)) if ((cflag & (PARENB|PARODD)) != (old_cflag & (PARENB|PARODD))
|| (cflag & CSTOPB) != (old_cflag & CSTOPB) ) { || (cflag & CSTOPB) != (old_cflag & CSTOPB)) {
/* Not currently supported */ /* Not currently supported */
tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB); tty->termios->c_cflag &= ~(PARENB|PARODD|CSTOPB);
#if 0 #if 0
...@@ -841,20 +829,18 @@ static void klsi_105_set_termios (struct tty_struct *tty, ...@@ -841,20 +829,18 @@ static void klsi_105_set_termios (struct tty_struct *tty,
#endif #endif
; ;
} }
/* /*
* Set flow control: well, I do not really now how to handle DTR/RTS. * Set flow control: well, I do not really now how to handle DTR/RTS.
* Just do what we have seen with SniffUSB on Win98. * Just do what we have seen with SniffUSB on Win98.
*/ */
if( (iflag & IXOFF) != (old_iflag & IXOFF) if ((iflag & IXOFF) != (old_iflag & IXOFF)
|| (iflag & IXON) != (old_iflag & IXON) || (iflag & IXON) != (old_iflag & IXON)
|| (cflag & CRTSCTS) != (old_cflag & CRTSCTS) ) { || (cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
/* Not currently supported */ /* Not currently supported */
tty->termios->c_cflag &= ~CRTSCTS; tty->termios->c_cflag &= ~CRTSCTS;
/* Drop DTR/RTS if no flow control otherwise assert */ /* Drop DTR/RTS if no flow control otherwise assert */
#if 0 #if 0
if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS) ) if ((iflag & IXOFF) || (iflag & IXON) || (cflag & CRTSCTS))
priv->control_state |= TIOCM_DTR | TIOCM_RTS; priv->control_state |= TIOCM_DTR | TIOCM_RTS;
else else
priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS); priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
...@@ -862,20 +848,21 @@ static void klsi_105_set_termios (struct tty_struct *tty, ...@@ -862,20 +848,21 @@ static void klsi_105_set_termios (struct tty_struct *tty,
#endif #endif
; ;
} }
memcpy (&cfg, &priv->cfg, sizeof(cfg)); memcpy(&cfg, &priv->cfg, sizeof(cfg));
spin_unlock_irqrestore (&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
/* now commit changes to device */ /* now commit changes to device */
klsi_105_chg_port_settings(port, &cfg); klsi_105_chg_port_settings(port, &cfg);
} /* klsi_105_set_termios */ } /* klsi_105_set_termios */
#if 0 #if 0
static void mct_u232_break_ctl( struct tty_struct *tty, int break_state ) static void mct_u232_break_ctl(struct tty_struct *tty, int break_state)
{ {
struct usb_serial_port *port = tty->driver_data; struct usb_serial_port *port = tty->driver_data;
struct usb_serial *serial = port->serial; struct usb_serial *serial = port->serial;
struct mct_u232_private *priv = (struct mct_u232_private *)port->private; struct mct_u232_private *priv =
(struct mct_u232_private *)port->private;
unsigned char lcr = priv->last_lcr; unsigned char lcr = priv->last_lcr;
dbg("%sstate=%d", __func__, break_state); dbg("%sstate=%d", __func__, break_state);
...@@ -887,7 +874,7 @@ static void mct_u232_break_ctl( struct tty_struct *tty, int break_state ) ...@@ -887,7 +874,7 @@ static void mct_u232_break_ctl( struct tty_struct *tty, int break_state )
} /* mct_u232_break_ctl */ } /* mct_u232_break_ctl */
#endif #endif
static int klsi_105_tiocmget (struct tty_struct *tty, struct file *file) static int klsi_105_tiocmget(struct tty_struct *tty, struct file *file)
{ {
struct usb_serial_port *port = tty->driver_data; struct usb_serial_port *port = tty->driver_data;
struct klsi_105_private *priv = usb_get_serial_port_data(port); struct klsi_105_private *priv = usb_get_serial_port_data(port);
...@@ -903,18 +890,18 @@ static int klsi_105_tiocmget (struct tty_struct *tty, struct file *file) ...@@ -903,18 +890,18 @@ static int klsi_105_tiocmget (struct tty_struct *tty, struct file *file)
return rc; return rc;
} }
spin_lock_irqsave (&priv->lock, flags); spin_lock_irqsave(&priv->lock, flags);
priv->line_state = line_state; priv->line_state = line_state;
spin_unlock_irqrestore (&priv->lock, flags); spin_unlock_irqrestore(&priv->lock, flags);
dbg("%s - read line state 0x%lx", __func__, line_state); dbg("%s - read line state 0x%lx", __func__, line_state);
return (int)line_state; return (int)line_state;
} }
static int klsi_105_tiocmset (struct tty_struct *tty, struct file *file, static int klsi_105_tiocmset(struct tty_struct *tty, struct file *file,
unsigned int set, unsigned int clear) unsigned int set, unsigned int clear)
{ {
int retval = -EINVAL; int retval = -EINVAL;
dbg("%s", __func__); dbg("%s", __func__);
/* if this ever gets implemented, it should be done something like this: /* if this ever gets implemented, it should be done something like this:
...@@ -939,14 +926,14 @@ static int klsi_105_tiocmset (struct tty_struct *tty, struct file *file, ...@@ -939,14 +926,14 @@ static int klsi_105_tiocmset (struct tty_struct *tty, struct file *file,
return retval; return retval;
} }
static void klsi_105_throttle (struct tty_struct *tty) static void klsi_105_throttle(struct tty_struct *tty)
{ {
struct usb_serial_port *port = tty->driver_data; struct usb_serial_port *port = tty->driver_data;
dbg("%s - port %d", __func__, port->number); dbg("%s - port %d", __func__, port->number);
usb_kill_urb(port->read_urb); usb_kill_urb(port->read_urb);
} }
static void klsi_105_unthrottle (struct tty_struct *tty) static void klsi_105_unthrottle(struct tty_struct *tty)
{ {
struct usb_serial_port *port = tty->driver_data; struct usb_serial_port *port = tty->driver_data;
int result; int result;
...@@ -962,7 +949,7 @@ static void klsi_105_unthrottle (struct tty_struct *tty) ...@@ -962,7 +949,7 @@ static void klsi_105_unthrottle (struct tty_struct *tty)
static int __init klsi_105_init (void) static int __init klsi_105_init(void)
{ {
int retval; int retval;
retval = usb_serial_register(&kl5kusb105d_device); retval = usb_serial_register(&kl5kusb105d_device);
...@@ -981,19 +968,19 @@ failed_usb_serial_register: ...@@ -981,19 +968,19 @@ failed_usb_serial_register:
} }
static void __exit klsi_105_exit (void) static void __exit klsi_105_exit(void)
{ {
usb_deregister (&kl5kusb105d_driver); usb_deregister(&kl5kusb105d_driver);
usb_serial_deregister (&kl5kusb105d_device); usb_serial_deregister(&kl5kusb105d_device);
} }
module_init (klsi_105_init); module_init(klsi_105_init);
module_exit (klsi_105_exit); module_exit(klsi_105_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);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment