tty-usb-keyspan: 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:
parent
9e8e2d2ab5
commit
deb9168578
1 changed files with 415 additions and 404 deletions
|
@ -107,7 +107,7 @@
|
|||
#include <linux/spinlock.h>
|
||||
#include <linux/firmware.h>
|
||||
#include <linux/ihex.h>
|
||||
#include <asm/uaccess.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/usb.h>
|
||||
#include <linux/usb/serial.h>
|
||||
#include "keyspan.h"
|
||||
|
@ -132,15 +132,15 @@ struct keyspan_serial_private {
|
|||
struct urb *instat_urb;
|
||||
char instat_buf[INSTAT_BUFLEN];
|
||||
|
||||
/* added to support 49wg, where data from all 4 ports comes in on 1 EP */
|
||||
/* and high-speed supported */
|
||||
/* added to support 49wg, where data from all 4 ports comes in
|
||||
on 1 EP and high-speed supported */
|
||||
struct urb *indat_urb;
|
||||
char indat_buf[INDAT49W_BUFLEN];
|
||||
|
||||
/* XXX this one probably will need a lock */
|
||||
struct urb *glocont_urb;
|
||||
char glocont_buf[GLOCONT_BUFLEN];
|
||||
char ctrl_buf[8]; // for EP0 control message
|
||||
char ctrl_buf[8]; /* for EP0 control message */
|
||||
};
|
||||
|
||||
struct keyspan_port_private {
|
||||
|
@ -186,10 +186,10 @@ struct keyspan_port_private {
|
|||
int resend_cont; /* need to resend control packet */
|
||||
};
|
||||
|
||||
|
||||
/* Include Keyspan message headers. All current Keyspan Adapters
|
||||
make use of one of five message formats which are referred
|
||||
to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and within this driver. */
|
||||
to as USA-26, USA-28, USA-49, USA-90, USA-67 by Keyspan and
|
||||
within this driver. */
|
||||
#include "keyspan_usa26msg.h"
|
||||
#include "keyspan_usa28msg.h"
|
||||
#include "keyspan_usa49msg.h"
|
||||
|
@ -368,23 +368,26 @@ static int keyspan_write(struct tty_struct *tty,
|
|||
flip = p_priv->out_flip;
|
||||
|
||||
/* Check we have a valid urb/endpoint before we use it... */
|
||||
if ((this_urb = p_priv->out_urbs[flip]) == NULL) {
|
||||
this_urb = p_priv->out_urbs[flip];
|
||||
if (this_urb == NULL) {
|
||||
/* no bulk out, so return 0 bytes written */
|
||||
dbg("%s - no output urb :(", __func__);
|
||||
return count;
|
||||
}
|
||||
|
||||
dbg("%s - endpoint %d flip %d", __func__, usb_pipeendpoint(this_urb->pipe), flip);
|
||||
dbg("%s - endpoint %d flip %d",
|
||||
__func__, usb_pipeendpoint(this_urb->pipe), flip);
|
||||
|
||||
if (this_urb->status == -EINPROGRESS) {
|
||||
if (time_before(jiffies, p_priv->tx_start_time[flip] + 10 * HZ))
|
||||
if (time_before(jiffies,
|
||||
p_priv->tx_start_time[flip] + 10 * HZ))
|
||||
break;
|
||||
usb_unlink_urb(this_urb);
|
||||
break;
|
||||
}
|
||||
|
||||
/* First byte in buffer is "last flag" (except for usa19hx) - unused so
|
||||
for now so set to zero */
|
||||
/* First byte in buffer is "last flag" (except for usa19hx)
|
||||
- unused so for now so set to zero */
|
||||
((char *)this_urb->transfer_buffer)[0] = 0;
|
||||
|
||||
memcpy(this_urb->transfer_buffer + dataOffset, buf, todo);
|
||||
|
@ -394,9 +397,9 @@ static int keyspan_write(struct tty_struct *tty,
|
|||
this_urb->transfer_buffer_length = todo + dataOffset;
|
||||
|
||||
this_urb->dev = port->serial->dev;
|
||||
if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
|
||||
err = usb_submit_urb(this_urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("usb_submit_urb(write bulk) failed (%d)", err);
|
||||
}
|
||||
p_priv->tx_start_time[flip] = jiffies;
|
||||
|
||||
/* Flip for next time if usa26 or usa28 interface
|
||||
|
@ -431,13 +434,14 @@ static void usa26_indat_callback(struct urb *urb)
|
|||
if (tty && urb->actual_length) {
|
||||
/* 0x80 bit is error flag */
|
||||
if ((data[0] & 0x80) == 0) {
|
||||
/* no errors on individual bytes, only possible overrun err*/
|
||||
/* no errors on individual bytes, only
|
||||
possible overrun err */
|
||||
if (data[0] & RXERROR_OVERRUN)
|
||||
err = TTY_OVERRUN;
|
||||
else err = 0;
|
||||
for (i = 1; i < urb->actual_length ; ++i) {
|
||||
else
|
||||
err = 0;
|
||||
for (i = 1; i < urb->actual_length ; ++i)
|
||||
tty_insert_flip_char(tty, data[i], err);
|
||||
}
|
||||
} else {
|
||||
/* some bytes had errors, every byte has status */
|
||||
dbg("%s - RX error!!!!", __func__);
|
||||
|
@ -458,9 +462,11 @@ static void usa26_indat_callback(struct urb *urb)
|
|||
|
||||
/* Resubmit urb so we continue receiving */
|
||||
urb->dev = port->serial->dev;
|
||||
if (port->port.count)
|
||||
if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
|
||||
dbg("%s - resubmit read urb failed. (%d)", __func__, err);
|
||||
if (port->port.count) {
|
||||
err = usb_submit_urb(urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - resubmit read urb failed. (%d)",
|
||||
__func__, err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -495,7 +501,8 @@ static void usa26_outcont_callback(struct urb *urb)
|
|||
|
||||
if (p_priv->resend_cont) {
|
||||
dbg("%s - sending setup", __func__);
|
||||
keyspan_usa26_send_setup(port->serial, port, p_priv->resend_cont - 1);
|
||||
keyspan_usa26_send_setup(port->serial, port,
|
||||
p_priv->resend_cont - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -556,16 +563,15 @@ static void usa26_instat_callback(struct urb *urb)
|
|||
|
||||
/* Resubmit urb so we continue receiving */
|
||||
urb->dev = serial->dev;
|
||||
if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
|
||||
err = usb_submit_urb(urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - resubmit read urb failed. (%d)", __func__, err);
|
||||
}
|
||||
exit: ;
|
||||
}
|
||||
|
||||
static void usa26_glocont_callback(struct urb *urb)
|
||||
{
|
||||
dbg("%s", __func__);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -600,17 +606,18 @@ static void usa28_indat_callback(struct urb *urb)
|
|||
|
||||
tty = port->port.tty;
|
||||
if (urb->actual_length) {
|
||||
for (i = 0; i < urb->actual_length ; ++i) {
|
||||
for (i = 0; i < urb->actual_length ; ++i)
|
||||
tty_insert_flip_char(tty, data[i], 0);
|
||||
}
|
||||
tty_flip_buffer_push(tty);
|
||||
}
|
||||
|
||||
/* Resubmit urb so we continue receiving */
|
||||
urb->dev = port->serial->dev;
|
||||
if (port->port.count)
|
||||
if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
|
||||
dbg("%s - resubmit read urb failed. (%d)", __func__, err);
|
||||
if (port->port.count) {
|
||||
err = usb_submit_urb(urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - resubmit read urb failed. (%d)",
|
||||
__func__, err);
|
||||
}
|
||||
p_priv->in_flip ^= 1;
|
||||
|
||||
|
@ -633,7 +640,8 @@ static void usa28_outcont_callback(struct urb *urb)
|
|||
|
||||
if (p_priv->resend_cont) {
|
||||
dbg("%s - sending setup", __func__);
|
||||
keyspan_usa28_send_setup(port->serial, port, p_priv->resend_cont - 1);
|
||||
keyspan_usa28_send_setup(port->serial, port,
|
||||
p_priv->resend_cont - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -667,7 +675,6 @@ static void usa28_instat_callback(struct urb *urb)
|
|||
/* Now do something useful with the data */
|
||||
msg = (struct keyspan_usa28_portStatusMessage *)data;
|
||||
|
||||
|
||||
/* Check port number from message and retrieve private data */
|
||||
if (msg->port >= serial->num_ports) {
|
||||
dbg("%s - Unexpected port number %d", __func__, msg->port);
|
||||
|
@ -693,9 +700,9 @@ static void usa28_instat_callback(struct urb *urb)
|
|||
|
||||
/* Resubmit urb so we continue receiving */
|
||||
urb->dev = serial->dev;
|
||||
if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
|
||||
err = usb_submit_urb(urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - resubmit read urb failed. (%d)", __func__, err);
|
||||
}
|
||||
exit: ;
|
||||
}
|
||||
|
||||
|
@ -721,7 +728,8 @@ static void usa49_glocont_callback(struct urb *urb)
|
|||
|
||||
if (p_priv->resend_cont) {
|
||||
dbg("%s - sending setup", __func__);
|
||||
keyspan_usa49_send_setup(serial, port, p_priv->resend_cont - 1);
|
||||
keyspan_usa49_send_setup(serial, port,
|
||||
p_priv->resend_cont - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -749,7 +757,8 @@ static void usa49_instat_callback(struct urb *urb)
|
|||
return;
|
||||
}
|
||||
|
||||
if (urb->actual_length != sizeof(struct keyspan_usa49_portStatusMessage)) {
|
||||
if (urb->actual_length !=
|
||||
sizeof(struct keyspan_usa49_portStatusMessage)) {
|
||||
dbg("%s - bad length %d", __func__, urb->actual_length);
|
||||
goto exit;
|
||||
}
|
||||
|
@ -763,7 +772,8 @@ static void usa49_instat_callback(struct urb *urb)
|
|||
|
||||
/* Check port number from message and retrieve private data */
|
||||
if (msg->portNumber >= serial->num_ports) {
|
||||
dbg ("%s - Unexpected port number %d", __func__, msg->portNumber);
|
||||
dbg("%s - Unexpected port number %d",
|
||||
__func__, msg->portNumber);
|
||||
goto exit;
|
||||
}
|
||||
port = serial->port[msg->portNumber];
|
||||
|
@ -787,9 +797,9 @@ static void usa49_instat_callback(struct urb *urb)
|
|||
/* Resubmit urb so we continue receiving */
|
||||
urb->dev = serial->dev;
|
||||
|
||||
if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
|
||||
err = usb_submit_urb(urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - resubmit read urb failed. (%d)", __func__, err);
|
||||
}
|
||||
exit: ;
|
||||
}
|
||||
|
||||
|
@ -823,9 +833,8 @@ static void usa49_indat_callback(struct urb *urb)
|
|||
/* 0x80 bit is error flag */
|
||||
if ((data[0] & 0x80) == 0) {
|
||||
/* no error on any byte */
|
||||
for (i = 1; i < urb->actual_length ; ++i) {
|
||||
for (i = 1; i < urb->actual_length ; ++i)
|
||||
tty_insert_flip_char(tty, data[i], 0);
|
||||
}
|
||||
} else {
|
||||
/* some bytes had errors, every byte has status */
|
||||
for (i = 0; i + 1 < urb->actual_length; i += 2) {
|
||||
|
@ -845,9 +854,11 @@ static void usa49_indat_callback(struct urb *urb)
|
|||
|
||||
/* Resubmit urb so we continue receiving */
|
||||
urb->dev = port->serial->dev;
|
||||
if (port->port.count)
|
||||
if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
|
||||
dbg("%s - resubmit read urb failed. (%d)", __func__, err);
|
||||
if (port->port.count) {
|
||||
err = usb_submit_urb(urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - resubmit read urb failed. (%d)",
|
||||
__func__, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -959,27 +970,25 @@ static void usa90_indat_callback(struct urb *urb)
|
|||
|
||||
tty = port->port.tty;
|
||||
if (urb->actual_length) {
|
||||
|
||||
/* if current mode is DMA, looks like usa28 format
|
||||
otherwise looks like usa26 data format */
|
||||
|
||||
if (p_priv->baud > 57600) {
|
||||
for (i = 0; i < urb->actual_length ; ++i)
|
||||
tty_insert_flip_char(tty, data[i], 0);
|
||||
}
|
||||
else {
|
||||
|
||||
} else {
|
||||
/* 0x80 bit is error flag */
|
||||
if ((data[0] & 0x80) == 0) {
|
||||
/* no errors on individual bytes, only possible overrun err*/
|
||||
/* no errors on individual bytes, only
|
||||
possible overrun err*/
|
||||
if (data[0] & RXERROR_OVERRUN)
|
||||
err = TTY_OVERRUN;
|
||||
else err = 0;
|
||||
else
|
||||
err = 0;
|
||||
for (i = 1; i < urb->actual_length ; ++i)
|
||||
tty_insert_flip_char(tty, data[i], err);
|
||||
|
||||
}
|
||||
else {
|
||||
tty_insert_flip_char(tty, data[i],
|
||||
err);
|
||||
} else {
|
||||
/* some bytes had errors, every byte has status */
|
||||
dbg("%s - RX error!!!!", __func__);
|
||||
for (i = 0; i + 1 < urb->actual_length; i += 2) {
|
||||
|
@ -991,7 +1000,8 @@ static void usa90_indat_callback(struct urb *urb)
|
|||
if (stat & RXERROR_PARITY)
|
||||
flag |= TTY_PARITY;
|
||||
/* XXX should handle break (0x10) */
|
||||
tty_insert_flip_char(tty, data[i+1], flag);
|
||||
tty_insert_flip_char(tty, data[i+1],
|
||||
flag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1000,9 +1010,11 @@ static void usa90_indat_callback(struct urb *urb)
|
|||
|
||||
/* Resubmit urb so we continue receiving */
|
||||
urb->dev = port->serial->dev;
|
||||
if (port->port.count)
|
||||
if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
|
||||
dbg("%s - resubmit read urb failed. (%d)", __func__, err);
|
||||
if (port->port.count) {
|
||||
err = usb_submit_urb(urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - resubmit read urb failed. (%d)",
|
||||
__func__, err);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
@ -1053,9 +1065,9 @@ static void usa90_instat_callback(struct urb *urb)
|
|||
|
||||
/* Resubmit urb so we continue receiving */
|
||||
urb->dev = serial->dev;
|
||||
if ((err = usb_submit_urb(urb, GFP_ATOMIC)) != 0) {
|
||||
err = usb_submit_urb(urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - resubmit read urb failed. (%d)", __func__, err);
|
||||
}
|
||||
exit:
|
||||
;
|
||||
}
|
||||
|
@ -1070,7 +1082,8 @@ static void usa90_outcont_callback(struct urb *urb)
|
|||
|
||||
if (p_priv->resend_cont) {
|
||||
dbg("%s - sending setup", __func__);
|
||||
keyspan_usa90_send_setup(port->serial, port, p_priv->resend_cont - 1);
|
||||
keyspan_usa90_send_setup(port->serial, port,
|
||||
p_priv->resend_cont - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1095,7 +1108,8 @@ static void usa67_instat_callback(struct urb *urb)
|
|||
return;
|
||||
}
|
||||
|
||||
if (urb->actual_length != sizeof(struct keyspan_usa67_portStatusMessage)) {
|
||||
if (urb->actual_length !=
|
||||
sizeof(struct keyspan_usa67_portStatusMessage)) {
|
||||
dbg("%s - bad length %d", __func__, urb->actual_length);
|
||||
return;
|
||||
}
|
||||
|
@ -1178,13 +1192,16 @@ static int keyspan_write_room(struct tty_struct *tty)
|
|||
flip = p_priv->out_flip;
|
||||
|
||||
/* Check both endpoints to see if any are available. */
|
||||
if ((this_urb = p_priv->out_urbs[flip]) != NULL) {
|
||||
this_urb = p_priv->out_urbs[flip];
|
||||
if (this_urb != NULL) {
|
||||
if (this_urb->status != -EINPROGRESS)
|
||||
return (data_len);
|
||||
return data_len;
|
||||
flip = (flip + 1) & d_details->outdat_endp_flip;
|
||||
if ((this_urb = p_priv->out_urbs[flip]) != NULL)
|
||||
this_urb = p_priv->out_urbs[flip];
|
||||
if (this_urb != NULL) {
|
||||
if (this_urb->status != -EINPROGRESS)
|
||||
return (data_len);
|
||||
return data_len;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -1222,25 +1239,28 @@ static int keyspan_open(struct tty_struct *tty,
|
|||
|
||||
/* Reset low level data toggle and start reading from endpoints */
|
||||
for (i = 0; i < 2; i++) {
|
||||
if ((urb = p_priv->in_urbs[i]) == NULL)
|
||||
urb = p_priv->in_urbs[i];
|
||||
if (urb == NULL)
|
||||
continue;
|
||||
urb->dev = serial->dev;
|
||||
|
||||
/* make sure endpoint data toggle is synchronized with the device */
|
||||
|
||||
/* make sure endpoint data toggle is synchronized
|
||||
with the device */
|
||||
usb_clear_halt(urb->dev, urb->pipe);
|
||||
|
||||
if ((err = usb_submit_urb(urb, GFP_KERNEL)) != 0) {
|
||||
dbg("%s - submit urb %d failed (%d)", __func__, i, err);
|
||||
}
|
||||
err = usb_submit_urb(urb, GFP_KERNEL);
|
||||
if (err != 0)
|
||||
dbg("%s - submit urb %d failed (%d)",
|
||||
__func__, i, err);
|
||||
}
|
||||
|
||||
/* Reset low level data toggle on out endpoints */
|
||||
for (i = 0; i < 2; i++) {
|
||||
if ((urb = p_priv->out_urbs[i]) == NULL)
|
||||
urb = p_priv->out_urbs[i];
|
||||
if (urb == NULL)
|
||||
continue;
|
||||
urb->dev = serial->dev;
|
||||
/* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe), usb_pipeout(urb->pipe), 0); */
|
||||
/* usb_settoggle(urb->dev, usb_pipeendpoint(urb->pipe),
|
||||
usb_pipeout(urb->pipe), 0); */
|
||||
}
|
||||
|
||||
/* get the terminal config for the setup message now so we don't
|
||||
|
@ -1264,8 +1284,8 @@ static int keyspan_open(struct tty_struct *tty,
|
|||
p_priv->flow_control = (cflag & CRTSCTS)? flow_cts: flow_none;
|
||||
|
||||
keyspan_send_setup(port, 1);
|
||||
//mdelay(100);
|
||||
//keyspan_set_termios(port, NULL);
|
||||
/* mdelay(100); */
|
||||
/* keyspan_set_termios(port, NULL); */
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1295,7 +1315,7 @@ static void keyspan_close(struct tty_struct *tty,
|
|||
keyspan_send_setup(port, 2);
|
||||
/* pilot-xfer seems to work best with this delay */
|
||||
mdelay(100);
|
||||
// keyspan_set_termios(port, NULL);
|
||||
/* keyspan_set_termios(port, NULL); */
|
||||
}
|
||||
|
||||
/*while (p_priv->outcont_urb->status == -EINPROGRESS) {
|
||||
|
@ -1329,9 +1349,10 @@ static int keyspan_fake_startup (struct usb_serial *serial)
|
|||
le16_to_cpu(serial->dev->descriptor.bcdDevice),
|
||||
le16_to_cpu(serial->dev->descriptor.idProduct));
|
||||
|
||||
if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000) != 0x8000) {
|
||||
if ((le16_to_cpu(serial->dev->descriptor.bcdDevice) & 0x8000)
|
||||
!= 0x8000) {
|
||||
dbg("Firmware already loaded. Quitting.");
|
||||
return(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Select firmware image on the basis of idProduct */
|
||||
|
@ -1407,8 +1428,7 @@ static int keyspan_fake_startup (struct usb_serial *serial)
|
|||
(unsigned char *)record->data,
|
||||
be16_to_cpu(record->len), 0xa0);
|
||||
if (response < 0) {
|
||||
dev_err(&serial->dev->dev, "ezusb_writememory failed for Keyspan"
|
||||
"firmware (%d %04X %p %d)\n",
|
||||
dev_err(&serial->dev->dev, "ezusb_writememory failed for Keyspan firmware (%d %04X %p %d)\n",
|
||||
response, be32_to_cpu(record->addr),
|
||||
record->data, be16_to_cpu(record->len));
|
||||
break;
|
||||
|
@ -1421,7 +1441,7 @@ static int keyspan_fake_startup (struct usb_serial *serial)
|
|||
response = ezusb_set_reset(serial, 0);
|
||||
|
||||
/* we don't want this device to have a driver assigned to it. */
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Helper functions used by keyspan_setup_urbs */
|
||||
|
@ -1621,7 +1641,6 @@ static void keyspan_setup_urbs(struct usb_serial *serial)
|
|||
port, p_priv->outcont_buffer, 64,
|
||||
cback->outcont_callback);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* usa19 function doesn't require prescaler */
|
||||
|
@ -1635,40 +1654,33 @@ static int keyspan_usa19_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
|
|||
dbg("%s - %d.", __func__, baud_rate);
|
||||
|
||||
/* prevent divide by zero... */
|
||||
if( (b16 = (baud_rate * 16L)) == 0) {
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
}
|
||||
|
||||
b16 = baud_rate * 16L;
|
||||
if (b16 == 0)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
/* Any "standard" rate over 57k6 is marginal on the USA-19
|
||||
as we run out of divisor resolution. */
|
||||
if (baud_rate > 57600) {
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
}
|
||||
if (baud_rate > 57600)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
|
||||
/* calculate the divisor and the counter (its inverse) */
|
||||
if( (div = (baudclk / b16)) == 0) {
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
}
|
||||
else {
|
||||
div = baudclk / b16;
|
||||
if (div == 0)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
else
|
||||
cnt = 0 - div;
|
||||
}
|
||||
|
||||
if(div > 0xffff) {
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
}
|
||||
if (div > 0xffff)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
|
||||
/* return the counter values if non-null */
|
||||
if (rate_low) {
|
||||
if (rate_low)
|
||||
*rate_low = (u8) (cnt & 0xff);
|
||||
}
|
||||
if (rate_hi) {
|
||||
if (rate_hi)
|
||||
*rate_hi = (u8) ((cnt >> 8) & 0xff);
|
||||
}
|
||||
if (rate_low && rate_hi) {
|
||||
dbg ("%s - %d %02x %02x.", __func__, baud_rate, *rate_hi, *rate_low);
|
||||
}
|
||||
|
||||
return (KEYSPAN_BAUD_RATE_OK);
|
||||
if (rate_low && rate_hi)
|
||||
dbg("%s - %d %02x %02x.",
|
||||
__func__, baud_rate, *rate_hi, *rate_low);
|
||||
return KEYSPAN_BAUD_RATE_OK;
|
||||
}
|
||||
|
||||
/* usa19hs function doesn't require prescaler */
|
||||
|
@ -1681,17 +1693,17 @@ static int keyspan_usa19hs_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
|
|||
dbg("%s - %d.", __func__, baud_rate);
|
||||
|
||||
/* prevent divide by zero... */
|
||||
if( (b16 = (baud_rate * 16L)) == 0)
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
|
||||
|
||||
b16 = baud_rate * 16L;
|
||||
if (b16 == 0)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
|
||||
/* calculate the divisor */
|
||||
if( (div = (baudclk / b16)) == 0)
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
div = baudclk / b16;
|
||||
if (div == 0)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
|
||||
if (div > 0xffff)
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
|
||||
/* return the counter values if non-null */
|
||||
if (rate_low)
|
||||
|
@ -1701,9 +1713,10 @@ static int keyspan_usa19hs_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
|
|||
*rate_hi = (u8) ((div >> 8) & 0xff);
|
||||
|
||||
if (rate_low && rate_hi)
|
||||
dbg ("%s - %d %02x %02x.", __func__, baud_rate, *rate_hi, *rate_low);
|
||||
dbg("%s - %d %02x %02x.",
|
||||
__func__, baud_rate, *rate_hi, *rate_low);
|
||||
|
||||
return (KEYSPAN_BAUD_RATE_OK);
|
||||
return KEYSPAN_BAUD_RATE_OK;
|
||||
}
|
||||
|
||||
static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
|
||||
|
@ -1721,9 +1734,9 @@ static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
|
|||
dbg("%s - %d.", __func__, baud_rate);
|
||||
|
||||
/* prevent divide by zero */
|
||||
if( (b16 = baud_rate * 16L) == 0) {
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
}
|
||||
b16 = baud_rate * 16L;
|
||||
if (b16 == 0)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
|
||||
/* Calculate prescaler by trying them all and looking
|
||||
for best fit */
|
||||
|
@ -1737,9 +1750,9 @@ static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
|
|||
for (i = 8; i <= 0xff; ++i) {
|
||||
clk = (baudclk * 8) / (u32) i;
|
||||
|
||||
if( (div = clk / b16) == 0) {
|
||||
div = clk / b16;
|
||||
if (div == 0)
|
||||
continue;
|
||||
}
|
||||
|
||||
res = clk / div;
|
||||
diff = (res > b16) ? (res-b16) : (b16-res);
|
||||
|
@ -1750,25 +1763,22 @@ static int keyspan_usa19w_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
|
|||
}
|
||||
}
|
||||
|
||||
if(best_prescaler == 0) {
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
}
|
||||
if (best_prescaler == 0)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
|
||||
clk = (baudclk * 8) / (u32) best_prescaler;
|
||||
div = clk / b16;
|
||||
|
||||
/* return the divisor and prescaler if non-null */
|
||||
if (rate_low) {
|
||||
if (rate_low)
|
||||
*rate_low = (u8) (div & 0xff);
|
||||
}
|
||||
if (rate_hi) {
|
||||
if (rate_hi)
|
||||
*rate_hi = (u8) ((div >> 8) & 0xff);
|
||||
}
|
||||
if (prescaler) {
|
||||
*prescaler = best_prescaler;
|
||||
/* dbg("%s - %d %d", __func__, *prescaler, div); */
|
||||
}
|
||||
return (KEYSPAN_BAUD_RATE_OK);
|
||||
return KEYSPAN_BAUD_RATE_OK;
|
||||
}
|
||||
|
||||
/* USA-28 supports different maximum baud rates on each port */
|
||||
|
@ -1782,44 +1792,38 @@ static int keyspan_usa28_calc_baud(u32 baud_rate, u32 baudclk, u8 *rate_hi,
|
|||
dbg("%s - %d.", __func__, baud_rate);
|
||||
|
||||
/* prevent divide by zero */
|
||||
if ((b16 = baud_rate * 16L) == 0)
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
b16 = baud_rate * 16L;
|
||||
if (b16 == 0)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
|
||||
/* calculate the divisor and the counter (its inverse) */
|
||||
if ((div = (KEYSPAN_USA28_BAUDCLK / b16)) == 0) {
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
}
|
||||
else {
|
||||
div = KEYSPAN_USA28_BAUDCLK / b16;
|
||||
if (div == 0)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
else
|
||||
cnt = 0 - div;
|
||||
}
|
||||
|
||||
/* check for out of range, based on portnum,
|
||||
and return result */
|
||||
if (portnum == 0) {
|
||||
if (div > 0xffff)
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
}
|
||||
else {
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
} else {
|
||||
if (portnum == 1) {
|
||||
if(div > 0xff) {
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return (KEYSPAN_INVALID_BAUD_RATE);
|
||||
}
|
||||
if (div > 0xff)
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
} else
|
||||
return KEYSPAN_INVALID_BAUD_RATE;
|
||||
}
|
||||
|
||||
/* return the counter values if not NULL
|
||||
(port 1 will ignore retHi) */
|
||||
if (rate_low) {
|
||||
if (rate_low)
|
||||
*rate_low = (u8) (cnt & 0xff);
|
||||
}
|
||||
if (rate_hi) {
|
||||
if (rate_hi)
|
||||
*rate_hi = (u8) ((cnt >> 8) & 0xff);
|
||||
}
|
||||
dbg("%s - %d OK.", __func__, baud_rate);
|
||||
return (KEYSPAN_BAUD_RATE_OK);
|
||||
return KEYSPAN_BAUD_RATE_OK;
|
||||
}
|
||||
|
||||
static int keyspan_usa26_send_setup(struct usb_serial *serial,
|
||||
|
@ -1859,7 +1863,7 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
|
|||
if (this_urb->status == -EINPROGRESS) {
|
||||
/* dbg("%s - already writing", __func__); */
|
||||
mdelay(5);
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&msg, 0, sizeof(struct keyspan_usa26_portControlMessage));
|
||||
|
@ -1871,8 +1875,8 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
|
|||
if (d_details->calculate_baud_rate
|
||||
(p_priv->baud, d_details->baudclk, &msg.baudHi,
|
||||
&msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
|
||||
dbg("%s - Invalid baud rate %d requested, using 9600.", __func__,
|
||||
p_priv->baud);
|
||||
dbg("%s - Invalid baud rate %d requested, using 9600.",
|
||||
__func__, p_priv->baud);
|
||||
msg.baudLo = 0;
|
||||
msg.baudHi = 125; /* Values for 9600 baud */
|
||||
msg.prescaler = 10;
|
||||
|
@ -1965,9 +1969,9 @@ static int keyspan_usa26_send_setup(struct usb_serial *serial,
|
|||
this_urb->transfer_buffer_length = sizeof(msg);
|
||||
|
||||
this_urb->dev = serial->dev;
|
||||
if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
|
||||
err = usb_submit_urb(this_urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
|
||||
}
|
||||
#if 0
|
||||
else {
|
||||
dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__
|
||||
|
@ -1998,7 +2002,8 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
|
|||
device_port = port->number - port->serial->minor;
|
||||
|
||||
/* only do something if we have a bulk out endpoint */
|
||||
if ((this_urb = p_priv->outcont_urb) == NULL) {
|
||||
this_urb = p_priv->outcont_urb;
|
||||
if (this_urb == NULL) {
|
||||
dbg("%s - oops no urb.", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
@ -2010,7 +2015,7 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
|
|||
if (this_urb->status == -EINPROGRESS) {
|
||||
dbg("%s already writing", __func__);
|
||||
mdelay(5);
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&msg, 0, sizeof(struct keyspan_usa28_portControlMessage));
|
||||
|
@ -2018,7 +2023,8 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
|
|||
msg.setBaudRate = 1;
|
||||
if (d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk,
|
||||
&msg.baudHi, &msg.baudLo, NULL, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
|
||||
dbg("%s - Invalid baud rate requested %d.", __func__, p_priv->baud);
|
||||
dbg("%s - Invalid baud rate requested %d.",
|
||||
__func__, p_priv->baud);
|
||||
msg.baudLo = 0xff;
|
||||
msg.baudHi = 0xb2; /* Values for 9600 baud */
|
||||
}
|
||||
|
@ -2091,9 +2097,9 @@ static int keyspan_usa28_send_setup(struct usb_serial *serial,
|
|||
this_urb->transfer_buffer_length = sizeof(msg);
|
||||
|
||||
this_urb->dev = serial->dev;
|
||||
if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
|
||||
err = usb_submit_urb(this_urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - usb_submit_urb(setup) failed", __func__);
|
||||
}
|
||||
#if 0
|
||||
else {
|
||||
dbg("%s - usb_submit_urb(setup) OK %d bytes", __func__,
|
||||
|
@ -2127,7 +2133,9 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
|
|||
/* Work out which port within the device is being setup */
|
||||
device_port = port->number - port->serial->minor;
|
||||
|
||||
dbg("%s - endpoint %d port %d (%d)",__func__, usb_pipeendpoint(this_urb->pipe), port->number, device_port);
|
||||
dbg("%s - endpoint %d port %d (%d)",
|
||||
__func__, usb_pipeendpoint(this_urb->pipe),
|
||||
port->number, device_port);
|
||||
|
||||
/* Make sure we have an urb then send the message */
|
||||
if (this_urb == NULL) {
|
||||
|
@ -2143,7 +2151,7 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
|
|||
if (this_urb->status == -EINPROGRESS) {
|
||||
/* dbg("%s - already writing", __func__); */
|
||||
mdelay(5);
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&msg, 0, sizeof(struct keyspan_usa49_portControlMessage));
|
||||
|
@ -2158,13 +2166,13 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
|
|||
if (d_details->calculate_baud_rate
|
||||
(p_priv->baud, d_details->baudclk, &msg.baudHi,
|
||||
&msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
|
||||
dbg("%s - Invalid baud rate %d requested, using 9600.", __func__,
|
||||
p_priv->baud);
|
||||
dbg("%s - Invalid baud rate %d requested, using 9600.",
|
||||
__func__, p_priv->baud);
|
||||
msg.baudLo = 0;
|
||||
msg.baudHi = 125; /* Values for 9600 baud */
|
||||
msg.prescaler = 10;
|
||||
}
|
||||
//msg.setPrescaler = 0xff;
|
||||
/* msg.setPrescaler = 0xff; */
|
||||
}
|
||||
|
||||
msg.lcr = (p_priv->cflag & CSTOPB)? STOPBITS_678_2: STOPBITS_5678_1;
|
||||
|
@ -2252,7 +2260,8 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
|
|||
|
||||
p_priv->resend_cont = 0;
|
||||
|
||||
/* if the device is a 49wg, we send control message on usb control EP 0 */
|
||||
/* if the device is a 49wg, we send control message on usb
|
||||
control EP 0 */
|
||||
|
||||
if (d_details->product_id == keyspan_usa49wg_product_id) {
|
||||
dr = (void *)(s_priv->ctrl_buf);
|
||||
|
@ -2264,9 +2273,10 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
|
|||
|
||||
memcpy(s_priv->glocont_buf, &msg, sizeof(msg));
|
||||
|
||||
usb_fill_control_urb(this_urb, serial->dev, usb_sndctrlpipe(serial->dev, 0),
|
||||
(unsigned char *)dr, s_priv->glocont_buf, sizeof(msg),
|
||||
usa49_glocont_callback, serial);
|
||||
usb_fill_control_urb(this_urb, serial->dev,
|
||||
usb_sndctrlpipe(serial->dev, 0),
|
||||
(unsigned char *)dr, s_priv->glocont_buf,
|
||||
sizeof(msg), usa49_glocont_callback, serial);
|
||||
|
||||
} else {
|
||||
memcpy(this_urb->transfer_buffer, &msg, sizeof(msg));
|
||||
|
@ -2276,9 +2286,9 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
|
|||
|
||||
this_urb->dev = serial->dev;
|
||||
}
|
||||
if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
|
||||
err = usb_submit_urb(this_urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
|
||||
}
|
||||
#if 0
|
||||
else {
|
||||
dbg("%s - usb_submit_urb(%d) OK %d bytes (end %d)", __func__,
|
||||
|
@ -2309,7 +2319,8 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
|
|||
d_details = s_priv->device_details;
|
||||
|
||||
/* only do something if we have a bulk out endpoint */
|
||||
if ((this_urb = p_priv->outcont_urb) == NULL) {
|
||||
this_urb = p_priv->outcont_urb;
|
||||
if (this_urb == NULL) {
|
||||
dbg("%s - oops no urb.", __func__);
|
||||
return -1;
|
||||
}
|
||||
|
@ -2321,7 +2332,7 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
|
|||
if (this_urb->status == -EINPROGRESS) {
|
||||
dbg("%s already writing", __func__);
|
||||
mdelay(5);
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&msg, 0, sizeof(struct keyspan_usa90_portControlMessage));
|
||||
|
@ -2333,8 +2344,8 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
|
|||
if (d_details->calculate_baud_rate
|
||||
(p_priv->baud, d_details->baudclk, &msg.baudHi,
|
||||
&msg.baudLo, &prescaler, 0) == KEYSPAN_INVALID_BAUD_RATE) {
|
||||
dbg("%s - Invalid baud rate %d requested, using 9600.", __func__,
|
||||
p_priv->baud);
|
||||
dbg("%s - Invalid baud rate %d requested, using 9600.",
|
||||
__func__, p_priv->baud);
|
||||
p_priv->baud = 9600;
|
||||
d_details->calculate_baud_rate(p_priv->baud, d_details->baudclk,
|
||||
&msg.baudHi, &msg.baudLo, &prescaler, 0);
|
||||
|
@ -2344,13 +2355,10 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
|
|||
}
|
||||
|
||||
/* modes must always be correctly specified */
|
||||
if (p_priv->baud > 57600)
|
||||
{
|
||||
if (p_priv->baud > 57600) {
|
||||
msg.rxMode = RXMODE_DMA;
|
||||
msg.txMode = TXMODE_DMA;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
msg.rxMode = RXMODE_BYHAND;
|
||||
msg.txMode = TXMODE_BYHAND;
|
||||
}
|
||||
|
@ -2398,9 +2406,8 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
|
|||
msg.txBreak = (p_priv->break_on);
|
||||
}
|
||||
/* Closing port */
|
||||
else if (reset_port == 2) {
|
||||
else if (reset_port == 2)
|
||||
msg.portEnabled = 0;
|
||||
}
|
||||
/* Sending intermediate configs */
|
||||
else {
|
||||
if (port->port.count)
|
||||
|
@ -2422,9 +2429,9 @@ static int keyspan_usa90_send_setup(struct usb_serial *serial,
|
|||
this_urb->transfer_buffer_length = sizeof(msg);
|
||||
|
||||
this_urb->dev = serial->dev;
|
||||
if ((err = usb_submit_urb(this_urb, GFP_ATOMIC)) != 0) {
|
||||
err = usb_submit_urb(this_urb, GFP_ATOMIC);
|
||||
if (err != 0)
|
||||
dbg("%s - usb_submit_urb(setup) failed (%d)", __func__, err);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -2464,7 +2471,7 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
|
|||
if (this_urb->status == -EINPROGRESS) {
|
||||
/* dbg("%s - already writing", __func__); */
|
||||
mdelay(5);
|
||||
return(-1);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&msg, 0, sizeof(struct keyspan_usa67_portControlMessage));
|
||||
|
@ -2478,8 +2485,8 @@ static int keyspan_usa67_send_setup(struct usb_serial *serial,
|
|||
if (d_details->calculate_baud_rate
|
||||
(p_priv->baud, d_details->baudclk, &msg.baudHi,
|
||||
&msg.baudLo, &msg.prescaler, device_port) == KEYSPAN_INVALID_BAUD_RATE) {
|
||||
dbg("%s - Invalid baud rate %d requested, using 9600.", __func__,
|
||||
p_priv->baud);
|
||||
dbg("%s - Invalid baud rate %d requested, using 9600.",
|
||||
__func__, p_priv->baud);
|
||||
msg.baudLo = 0;
|
||||
msg.baudHi = 125; /* Values for 9600 baud */
|
||||
msg.prescaler = 10;
|
||||
|
@ -2620,17 +2627,20 @@ static int keyspan_startup (struct usb_serial *serial)
|
|||
dbg("%s", __func__);
|
||||
|
||||
for (i = 0; (d_details = keyspan_devices[i]) != NULL; ++i)
|
||||
if (d_details->product_id == le16_to_cpu(serial->dev->descriptor.idProduct))
|
||||
if (d_details->product_id ==
|
||||
le16_to_cpu(serial->dev->descriptor.idProduct))
|
||||
break;
|
||||
if (d_details == NULL) {
|
||||
dev_err(&serial->dev->dev, "%s - unknown product id %x\n", __func__, le16_to_cpu(serial->dev->descriptor.idProduct));
|
||||
dev_err(&serial->dev->dev, "%s - unknown product id %x\n",
|
||||
__func__, le16_to_cpu(serial->dev->descriptor.idProduct));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Setup private data for serial driver */
|
||||
s_priv = kzalloc(sizeof(struct keyspan_serial_private), GFP_KERNEL);
|
||||
if (!s_priv) {
|
||||
dbg("%s - kmalloc for keyspan_serial_private failed.", __func__);
|
||||
dbg("%s - kmalloc for keyspan_serial_private failed.",
|
||||
__func__);
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
|
@ -2640,10 +2650,11 @@ static int keyspan_startup (struct usb_serial *serial)
|
|||
/* Now setup per port private data */
|
||||
for (i = 0; i < serial->num_ports; i++) {
|
||||
port = serial->port[i];
|
||||
p_priv = kzalloc(sizeof(struct keyspan_port_private), GFP_KERNEL);
|
||||
p_priv = kzalloc(sizeof(struct keyspan_port_private),
|
||||
GFP_KERNEL);
|
||||
if (!p_priv) {
|
||||
dbg("%s - kmalloc for keyspan_port_private (%d) failed!.", __func__, i);
|
||||
return (1);
|
||||
return 1;
|
||||
}
|
||||
p_priv->device_details = d_details;
|
||||
usb_set_serial_port_data(port, p_priv);
|
||||
|
|
Loading…
Reference in a new issue