USB-serial updates for v4.6-rc1

Here are some cp210x register-accessor updates and general usb-serial
 code clean ups.
 
 Signed-off-by: Johan Hovold <johan@kernel.org>
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABCAAGBQJW3xXLAAoJEEEN5E/e4bSV1kwP/jusuRMH1iZSLpm5OcQMNGNn
 ucY6w1tDoOheK6+ORJ54Gyxcxi6F5JjC16oN68vOUJN51zJFR0sTe7dW62Ih6BLn
 z1M/yJJ4Bj8QNHHak4JW7p/qdGcFy+6vGwyuzF36xMwChpiKt3CK/OEWU03n8phn
 tyqCDBMotLkkiY4ogAsWUt4Q6VOKkOiU0FKwpT9WZ+9vFdI4qV77NOAt2ghGqVq3
 KQXkWhHqldL/JPq06Zbh+5ZEHeD3Lsc9i6wKtQFiT2ezHa9HnxyO4dx3VThVP/fP
 M63o4cZIHW81z49A7V6tCWQe+pDbXiRKgNP2NPyRwtYa9vvdXKip+mklL784MIR4
 qdtMBmiSWOJjSJC4I5LKDMjhRyoIro0dD5nDqPYiuBJ8oHfT57BjWqHEUWOIzWDr
 23udT7F2a17KNedyLSlosWJljWRqCH4vmUU33NdaGlpNr5ia5oO38kP1RLT+SNDr
 72TjhBN1bqdbJXBk99j9cuA3DzPFrSxEbivk0bsmUlbvVEXUOpWU16SRqcuUEdVi
 vB9YchmrjB1nL8ORHQXo4yn4RO8tqlnkeaTYY4ibwuHDEnxWeMN3JNnun9LWJcaO
 8dFa6Xxe6vWAAHUOa2vl7PPi+1iRg7mrfCfO73ZIlESMcsrBT14B58xeJV6nt1g5
 Oi/RkV1UtOowsTAMu16M
 =9QeZ
 -----END PGP SIGNATURE-----

Merge tag 'usb-serial-4.6-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial into usb-next

Johan writes:

USB-serial updates for v4.6-rc1

Here are some cp210x register-accessor updates and general usb-serial
code clean ups.

Signed-off-by: Johan Hovold <johan@kernel.org>
This commit is contained in:
Greg Kroah-Hartman 2016-03-08 20:28:19 -08:00
commit ce53bfc437
12 changed files with 237 additions and 187 deletions

View File

@ -370,7 +370,7 @@ static void ch341_set_termios(struct tty_struct *tty,
static void ch341_break_ctl(struct tty_struct *tty, int break_state)
{
const uint16_t ch341_break_reg =
CH341_REG_BREAK1 | ((uint16_t) CH341_REG_BREAK2 << 8);
((uint16_t) CH341_REG_BREAK2 << 8) | CH341_REG_BREAK1;
struct usb_serial_port *port = tty->driver_data;
int r;
uint16_t reg_contents;

View File

@ -326,113 +326,169 @@ struct cp210x_comm_status {
#define PURGE_ALL 0x000f
/*
* cp210x_get_config
* Reads from the CP210x configuration registers
* 'size' is specified in bytes.
* 'data' is a pointer to a pre-allocated array of integers large
* enough to hold 'size' bytes (with 4 bytes to each integer)
* Reads a variable-sized block of CP210X_ registers, identified by req.
* Returns data into buf in native USB byte order.
*/
static int cp210x_get_config(struct usb_serial_port *port, u8 request,
unsigned int *data, int size)
static int cp210x_read_reg_block(struct usb_serial_port *port, u8 req,
void *buf, int bufsize)
{
struct usb_serial *serial = port->serial;
struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
__le32 *buf;
int result, i, length;
void *dmabuf;
int result;
/* Number of integers required to contain the array */
length = (((size - 1) | 3) + 1) / 4;
buf = kcalloc(length, sizeof(__le32), GFP_KERNEL);
if (!buf)
dmabuf = kmalloc(bufsize, GFP_KERNEL);
if (!dmabuf) {
/*
* FIXME Some callers don't bother to check for error,
* at least give them consistent junk until they are fixed
*/
memset(buf, 0, bufsize);
return -ENOMEM;
}
/* Issue the request, attempting to read 'size' bytes */
result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
request, REQTYPE_INTERFACE_TO_HOST, 0x0000,
port_priv->bInterfaceNumber, buf, size,
USB_CTRL_GET_TIMEOUT);
/* Convert data into an array of integers */
for (i = 0; i < length; i++)
data[i] = le32_to_cpu(buf[i]);
kfree(buf);
if (result != size) {
dev_dbg(&port->dev, "%s - Unable to send config request, request=0x%x size=%d result=%d\n",
__func__, request, size, result);
if (result > 0)
req, REQTYPE_INTERFACE_TO_HOST, 0,
port_priv->bInterfaceNumber, dmabuf, bufsize,
USB_CTRL_SET_TIMEOUT);
if (result == bufsize) {
memcpy(buf, dmabuf, bufsize);
result = 0;
} else {
dev_err(&port->dev, "failed get req 0x%x size %d status: %d\n",
req, bufsize, result);
if (result >= 0)
result = -EPROTO;
return result;
/*
* FIXME Some callers don't bother to check for error,
* at least give them consistent junk until they are fixed
*/
memset(buf, 0, bufsize);
}
kfree(dmabuf);
return result;
}
/*
* Reads any 32-bit CP210X_ register identified by req.
*/
static int cp210x_read_u32_reg(struct usb_serial_port *port, u8 req, u32 *val)
{
__le32 le32_val;
int err;
err = cp210x_read_reg_block(port, req, &le32_val, sizeof(le32_val));
if (err) {
/*
* FIXME Some callers don't bother to check for error,
* at least give them consistent junk until they are fixed
*/
*val = 0;
return err;
}
*val = le32_to_cpu(le32_val);
return 0;
}
/*
* cp210x_set_config
* Writes to the CP210x configuration registers
* Values less than 16 bits wide are sent directly
* 'size' is specified in bytes.
* Reads any 16-bit CP210X_ register identified by req.
*/
static int cp210x_set_config(struct usb_serial_port *port, u8 request,
unsigned int *data, int size)
static int cp210x_read_u16_reg(struct usb_serial_port *port, u8 req, u16 *val)
{
__le16 le16_val;
int err;
err = cp210x_read_reg_block(port, req, &le16_val, sizeof(le16_val));
if (err)
return err;
*val = le16_to_cpu(le16_val);
return 0;
}
/*
* Reads any 8-bit CP210X_ register identified by req.
*/
static int cp210x_read_u8_reg(struct usb_serial_port *port, u8 req, u8 *val)
{
return cp210x_read_reg_block(port, req, val, sizeof(*val));
}
/*
* Writes any 16-bit CP210X_ register (req) whose value is passed
* entirely in the wValue field of the USB request.
*/
static int cp210x_write_u16_reg(struct usb_serial_port *port, u8 req, u16 val)
{
struct usb_serial *serial = port->serial;
struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
__le32 *buf;
int result, i, length;
int result;
/* Number of integers required to contain the array */
length = (((size - 1) | 3) + 1) / 4;
buf = kmalloc(length * sizeof(__le32), GFP_KERNEL);
if (!buf)
return -ENOMEM;
/* Array of integers into bytes */
for (i = 0; i < length; i++)
buf[i] = cpu_to_le32(data[i]);
if (size > 2) {
result = usb_control_msg(serial->dev,
usb_sndctrlpipe(serial->dev, 0),
request, REQTYPE_HOST_TO_INTERFACE, 0x0000,
port_priv->bInterfaceNumber, buf, size,
USB_CTRL_SET_TIMEOUT);
} else {
result = usb_control_msg(serial->dev,
usb_sndctrlpipe(serial->dev, 0),
request, REQTYPE_HOST_TO_INTERFACE, data[0],
port_priv->bInterfaceNumber, NULL, 0,
USB_CTRL_SET_TIMEOUT);
result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
req, REQTYPE_HOST_TO_INTERFACE, val,
port_priv->bInterfaceNumber, NULL, 0,
USB_CTRL_SET_TIMEOUT);
if (result < 0) {
dev_err(&port->dev, "failed set request 0x%x status: %d\n",
req, result);
}
kfree(buf);
if ((size > 2 && result != size) || result < 0) {
dev_dbg(&port->dev, "%s - Unable to send request, request=0x%x size=%d result=%d\n",
__func__, request, size, result);
if (result > 0)
result = -EPROTO;
return result;
}
return 0;
return result;
}
/*
* cp210x_set_config_single
* Convenience function for calling cp210x_set_config on single data values
* without requiring an integer pointer
* Writes a variable-sized block of CP210X_ registers, identified by req.
* Data in buf must be in native USB byte order.
*/
static inline int cp210x_set_config_single(struct usb_serial_port *port,
u8 request, unsigned int data)
static int cp210x_write_reg_block(struct usb_serial_port *port, u8 req,
void *buf, int bufsize)
{
return cp210x_set_config(port, request, &data, 2);
struct usb_serial *serial = port->serial;
struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
void *dmabuf;
int result;
dmabuf = kmalloc(bufsize, GFP_KERNEL);
if (!dmabuf)
return -ENOMEM;
memcpy(dmabuf, buf, bufsize);
result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
req, REQTYPE_HOST_TO_INTERFACE, 0,
port_priv->bInterfaceNumber, dmabuf, bufsize,
USB_CTRL_SET_TIMEOUT);
kfree(dmabuf);
if (result == bufsize) {
result = 0;
} else {
dev_err(&port->dev, "failed set req 0x%x size %d status: %d\n",
req, bufsize, result);
if (result >= 0)
result = -EPROTO;
}
return result;
}
/*
* Writes any 32-bit CP210X_ register identified by req.
*/
static int cp210x_write_u32_reg(struct usb_serial_port *port, u8 req, u32 val)
{
__le32 le32_val;
le32_val = cpu_to_le32(val);
return cp210x_write_reg_block(port, req, &le32_val, sizeof(le32_val));
}
/*
@ -444,47 +500,46 @@ static inline int cp210x_set_config_single(struct usb_serial_port *port,
static int cp210x_detect_swapped_line_ctl(struct usb_serial_port *port)
{
struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
unsigned int line_ctl_save;
unsigned int line_ctl_test;
u16 line_ctl_save;
u16 line_ctl_test;
int err;
err = cp210x_get_config(port, CP210X_GET_LINE_CTL, &line_ctl_save, 2);
err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, &line_ctl_save);
if (err)
return err;
line_ctl_test = 0x800;
err = cp210x_set_config(port, CP210X_SET_LINE_CTL, &line_ctl_test, 2);
err = cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, 0x800);
if (err)
return err;
err = cp210x_get_config(port, CP210X_GET_LINE_CTL, &line_ctl_test, 2);
err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, &line_ctl_test);
if (err)
return err;
if (line_ctl_test == 8) {
port_priv->has_swapped_line_ctl = true;
line_ctl_save = swab16((u16)line_ctl_save);
line_ctl_save = swab16(line_ctl_save);
}
return cp210x_set_config(port, CP210X_SET_LINE_CTL, &line_ctl_save, 2);
return cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, line_ctl_save);
}
/*
* Must always be called instead of cp210x_get_config(CP210X_GET_LINE_CTL)
* Must always be called instead of cp210x_read_u16_reg(CP210X_GET_LINE_CTL)
* to workaround cp2108 bug and get correct value.
*/
static int cp210x_get_line_ctl(struct usb_serial_port *port, unsigned int *ctl)
static int cp210x_get_line_ctl(struct usb_serial_port *port, u16 *ctl)
{
struct cp210x_port_private *port_priv = usb_get_serial_port_data(port);
int err;
err = cp210x_get_config(port, CP210X_GET_LINE_CTL, ctl, 2);
err = cp210x_read_u16_reg(port, CP210X_GET_LINE_CTL, ctl);
if (err)
return err;
/* Workaround swapped bytes in 16-bit value from CP210X_GET_LINE_CTL */
if (port_priv->has_swapped_line_ctl)
*ctl = swab16((u16)(*ctl));
*ctl = swab16(*ctl);
return 0;
}
@ -535,8 +590,7 @@ static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port)
{
int result;
result = cp210x_set_config_single(port, CP210X_IFC_ENABLE,
UART_ENABLE);
result = cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_ENABLE);
if (result) {
dev_err(&port->dev, "%s - Unable to enable UART\n", __func__);
return result;
@ -554,15 +608,12 @@ static int cp210x_open(struct tty_struct *tty, struct usb_serial_port *port)
static void cp210x_close(struct usb_serial_port *port)
{
unsigned int purge_ctl;
usb_serial_generic_close(port);
/* Clear both queues; cp2108 needs this to avoid an occasional hang */
purge_ctl = PURGE_ALL;
cp210x_set_config(port, CP210X_PURGE, &purge_ctl, 2);
cp210x_write_u16_reg(port, CP210X_PURGE, PURGE_ALL);
cp210x_set_config_single(port, CP210X_IFC_ENABLE, UART_DISABLE);
cp210x_write_u16_reg(port, CP210X_IFC_ENABLE, UART_DISABLE);
}
/*
@ -640,11 +691,12 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
unsigned int *cflagp, unsigned int *baudp)
{
struct device *dev = &port->dev;
unsigned int cflag, modem_ctl[4];
unsigned int baud;
unsigned int bits;
unsigned int cflag;
u8 modem_ctl[16];
u32 baud;
u16 bits;
cp210x_get_config(port, CP210X_GET_BAUDRATE, &baud, 4);
cp210x_read_u32_reg(port, CP210X_GET_BAUDRATE, &baud);
dev_dbg(dev, "%s - baud rate = %d\n", __func__, baud);
*baudp = baud;
@ -675,14 +727,14 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
cflag |= CS8;
bits &= ~BITS_DATA_MASK;
bits |= BITS_DATA_8;
cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
break;
default:
dev_dbg(dev, "%s - Unknown number of data bits, using 8\n", __func__);
cflag |= CS8;
bits &= ~BITS_DATA_MASK;
bits |= BITS_DATA_8;
cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
break;
}
@ -713,7 +765,7 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
dev_dbg(dev, "%s - Unknown parity mode, disabling parity\n", __func__);
cflag &= ~PARENB;
bits &= ~BITS_PARITY_MASK;
cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
break;
}
@ -725,7 +777,7 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
case BITS_STOP_1_5:
dev_dbg(dev, "%s - stop bits = 1.5 (not supported, using 1 stop bit)\n", __func__);
bits &= ~BITS_STOP_MASK;
cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
break;
case BITS_STOP_2:
dev_dbg(dev, "%s - stop bits = 2\n", __func__);
@ -734,12 +786,13 @@ static void cp210x_get_termios_port(struct usb_serial_port *port,
default:
dev_dbg(dev, "%s - Unknown number of stop bits, using 1 stop bit\n", __func__);
bits &= ~BITS_STOP_MASK;
cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2);
cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits);
break;
}
cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16);
if (modem_ctl[0] & 0x0008) {
cp210x_read_reg_block(port, CP210X_GET_FLOW, modem_ctl,
sizeof(modem_ctl));
if (modem_ctl[0] & 0x08) {
dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
cflag |= CRTSCTS;
} else {
@ -791,8 +844,7 @@ static void cp210x_change_speed(struct tty_struct *tty,
baud = cp210x_quantise_baudrate(baud);
dev_dbg(&port->dev, "%s - setting baud rate to %u\n", __func__, baud);
if (cp210x_set_config(port, CP210X_SET_BAUDRATE, &baud,
sizeof(baud))) {
if (cp210x_write_u32_reg(port, CP210X_SET_BAUDRATE, baud)) {
dev_warn(&port->dev, "failed to set baud rate to %u\n", baud);
if (old_termios)
baud = old_termios->c_ospeed;
@ -808,8 +860,8 @@ static void cp210x_set_termios(struct tty_struct *tty,
{
struct device *dev = &port->dev;
unsigned int cflag, old_cflag;
unsigned int bits;
unsigned int modem_ctl[4];
u16 bits;
u8 modem_ctl[16];
cflag = tty->termios.c_cflag;
old_cflag = old_termios->c_cflag;
@ -847,7 +899,7 @@ static void cp210x_set_termios(struct tty_struct *tty,
bits |= BITS_DATA_8;
break;
}
if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2))
if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
dev_dbg(dev, "Number of data bits requested not supported by device\n");
}
@ -874,7 +926,7 @@ static void cp210x_set_termios(struct tty_struct *tty,
}
}
}
if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2))
if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
dev_dbg(dev, "Parity mode not supported by device\n");
}
@ -888,32 +940,40 @@ static void cp210x_set_termios(struct tty_struct *tty,
bits |= BITS_STOP_1;
dev_dbg(dev, "%s - stop bits = 1\n", __func__);
}
if (cp210x_set_config(port, CP210X_SET_LINE_CTL, &bits, 2))
if (cp210x_write_u16_reg(port, CP210X_SET_LINE_CTL, bits))
dev_dbg(dev, "Number of stop bits requested not supported by device\n");
}
if ((cflag & CRTSCTS) != (old_cflag & CRTSCTS)) {
cp210x_get_config(port, CP210X_GET_FLOW, modem_ctl, 16);
dev_dbg(dev, "%s - read modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x\n",
__func__, modem_ctl[0], modem_ctl[1],
modem_ctl[2], modem_ctl[3]);
/* Only bytes 0, 4 and 7 out of first 8 have functional bits */
cp210x_read_reg_block(port, CP210X_GET_FLOW, modem_ctl,
sizeof(modem_ctl));
dev_dbg(dev, "%s - read modem controls = %02x .. .. .. %02x .. .. %02x\n",
__func__, modem_ctl[0], modem_ctl[4], modem_ctl[7]);
if (cflag & CRTSCTS) {
modem_ctl[0] &= ~0x7B;
modem_ctl[0] |= 0x09;
modem_ctl[1] = 0x80;
modem_ctl[4] = 0x80;
/* FIXME - why clear reserved bits just read? */
modem_ctl[5] = 0;
modem_ctl[6] = 0;
modem_ctl[7] = 0;
dev_dbg(dev, "%s - flow control = CRTSCTS\n", __func__);
} else {
modem_ctl[0] &= ~0x7B;
modem_ctl[0] |= 0x01;
modem_ctl[1] |= 0x40;
/* FIXME - OR here instead of assignment looks wrong */
modem_ctl[4] |= 0x40;
dev_dbg(dev, "%s - flow control = NONE\n", __func__);
}
dev_dbg(dev, "%s - write modem controls = 0x%.4x 0x%.4x 0x%.4x 0x%.4x\n",
__func__, modem_ctl[0], modem_ctl[1],
modem_ctl[2], modem_ctl[3]);
cp210x_set_config(port, CP210X_SET_FLOW, modem_ctl, 16);
dev_dbg(dev, "%s - write modem controls = %02x .. .. .. %02x .. .. %02x\n",
__func__, modem_ctl[0], modem_ctl[4], modem_ctl[7]);
cp210x_write_reg_block(port, CP210X_SET_FLOW, modem_ctl,
sizeof(modem_ctl));
}
}
@ -928,7 +988,7 @@ static int cp210x_tiocmset(struct tty_struct *tty,
static int cp210x_tiocmset_port(struct usb_serial_port *port,
unsigned int set, unsigned int clear)
{
unsigned int control = 0;
u16 control = 0;
if (set & TIOCM_RTS) {
control |= CONTROL_RTS;
@ -949,7 +1009,7 @@ static int cp210x_tiocmset_port(struct usb_serial_port *port,
dev_dbg(&port->dev, "%s - control = 0x%.4x\n", __func__, control);
return cp210x_set_config(port, CP210X_SET_MHS, &control, 2);
return cp210x_write_u16_reg(port, CP210X_SET_MHS, control);
}
static void cp210x_dtr_rts(struct usb_serial_port *p, int on)
@ -963,10 +1023,10 @@ static void cp210x_dtr_rts(struct usb_serial_port *p, int on)
static int cp210x_tiocmget(struct tty_struct *tty)
{
struct usb_serial_port *port = tty->driver_data;
unsigned int control;
u8 control;
int result;
cp210x_get_config(port, CP210X_GET_MDMSTS, &control, 1);
cp210x_read_u8_reg(port, CP210X_GET_MDMSTS, &control);
result = ((control & CONTROL_DTR) ? TIOCM_DTR : 0)
|((control & CONTROL_RTS) ? TIOCM_RTS : 0)
@ -983,7 +1043,7 @@ static int cp210x_tiocmget(struct tty_struct *tty)
static void cp210x_break_ctl(struct tty_struct *tty, int break_state)
{
struct usb_serial_port *port = tty->driver_data;
unsigned int state;
u16 state;
if (break_state == 0)
state = BREAK_OFF;
@ -991,7 +1051,7 @@ static void cp210x_break_ctl(struct tty_struct *tty, int break_state)
state = BREAK_ON;
dev_dbg(&port->dev, "%s - turning break %s\n", __func__,
state == BREAK_OFF ? "off" : "on");
cp210x_set_config(port, CP210X_SET_BREAK, &state, 2);
cp210x_write_u16_reg(port, CP210X_SET_BREAK, state);
}
static int cp210x_port_probe(struct usb_serial_port *port)

View File

@ -140,7 +140,6 @@ static int cyberjack_open(struct tty_struct *tty,
{
struct cyberjack_private *priv;
unsigned long flags;
int result = 0;
dev_dbg(&port->dev, "%s - usb_clear_halt\n", __func__);
usb_clear_halt(port->serial->dev, port->write_urb->pipe);
@ -152,7 +151,7 @@ static int cyberjack_open(struct tty_struct *tty,
priv->wrsent = 0;
spin_unlock_irqrestore(&priv->lock, flags);
return result;
return 0;
}
static void cyberjack_close(struct usb_serial_port *port)

View File

@ -1320,11 +1320,11 @@ static __u32 get_ftdi_divisor(struct tty_struct *tty,
if (baud <= 3000000) {
__u16 product_id = le16_to_cpu(
port->serial->dev->descriptor.idProduct);
if (((FTDI_NDI_HUC_PID == product_id) ||
(FTDI_NDI_SPECTRA_SCU_PID == product_id) ||
(FTDI_NDI_FUTURE_2_PID == product_id) ||
(FTDI_NDI_FUTURE_3_PID == product_id) ||
(FTDI_NDI_AURORA_SCU_PID == product_id)) &&
if (((product_id == FTDI_NDI_HUC_PID) ||
(product_id == FTDI_NDI_SPECTRA_SCU_PID) ||
(product_id == FTDI_NDI_FUTURE_2_PID) ||
(product_id == FTDI_NDI_FUTURE_3_PID) ||
(product_id == FTDI_NDI_AURORA_SCU_PID)) &&
(baud == 19200)) {
baud = 1200000;
}

View File

@ -239,11 +239,11 @@ enum ftdi_sio_baudrate {
*/
#define FTDI_SIO_SET_DTR_MASK 0x1
#define FTDI_SIO_SET_DTR_HIGH (1 | (FTDI_SIO_SET_DTR_MASK << 8))
#define FTDI_SIO_SET_DTR_LOW (0 | (FTDI_SIO_SET_DTR_MASK << 8))
#define FTDI_SIO_SET_DTR_HIGH ((FTDI_SIO_SET_DTR_MASK << 8) | 1)
#define FTDI_SIO_SET_DTR_LOW ((FTDI_SIO_SET_DTR_MASK << 8) | 0)
#define FTDI_SIO_SET_RTS_MASK 0x2
#define FTDI_SIO_SET_RTS_HIGH (2 | (FTDI_SIO_SET_RTS_MASK << 8))
#define FTDI_SIO_SET_RTS_LOW (0 | (FTDI_SIO_SET_RTS_MASK << 8))
#define FTDI_SIO_SET_RTS_HIGH ((FTDI_SIO_SET_RTS_MASK << 8) | 2)
#define FTDI_SIO_SET_RTS_LOW ((FTDI_SIO_SET_RTS_MASK << 8) | 0)
/*
* ControlValue

View File

@ -237,10 +237,10 @@ static inline int getDataLength(const __u8 *usbPacket)
*/
static inline int isAbortTrfCmnd(const unsigned char *buf)
{
if (0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ,
sizeof(GARMIN_STOP_TRANSFER_REQ)) ||
0 == memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2,
sizeof(GARMIN_STOP_TRANSFER_REQ_V2)))
if (memcmp(buf, GARMIN_STOP_TRANSFER_REQ,
sizeof(GARMIN_STOP_TRANSFER_REQ)) == 0 ||
memcmp(buf, GARMIN_STOP_TRANSFER_REQ_V2,
sizeof(GARMIN_STOP_TRANSFER_REQ_V2)) == 0)
return 1;
else
return 0;
@ -350,7 +350,7 @@ static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id)
unsigned l = 0;
dev_dbg(&garmin_data_p->port->dev, "%s - pkt-id: 0x%X.\n", __func__,
0xFF & pkt_id);
pkt_id);
*ptr++ = DLE;
*ptr++ = ACK;
@ -366,7 +366,7 @@ static int gsp_send_ack(struct garmin_data *garmin_data_p, __u8 pkt_id)
*ptr++ = DLE;
*ptr++ = 0;
*ptr++ = 0xFF & (-cksum);
*ptr++ = (-cksum) & 0xFF;
*ptr++ = DLE;
*ptr++ = ETX;
@ -423,9 +423,9 @@ static int gsp_rec_packet(struct garmin_data *garmin_data_p, int count)
n++;
}
if ((0xff & (cksum + *recpkt)) != 0) {
if (((cksum + *recpkt) & 0xff) != 0) {
dev_dbg(dev, "%s - invalid checksum, expected %02x, got %02x\n",
__func__, 0xff & -cksum, 0xff & *recpkt);
__func__, -cksum & 0xff, *recpkt);
return -EINVPKT;
}
@ -528,7 +528,7 @@ static int gsp_receive(struct garmin_data *garmin_data_p,
dev_dbg(dev, "NAK packet complete.\n");
} else {
dev_dbg(dev, "packet complete - id=0x%X.\n",
0xFF & data);
data);
gsp_rec_packet(garmin_data_p, size);
}
@ -636,7 +636,7 @@ static int gsp_send(struct garmin_data *garmin_data_p,
garmin_data_p->outsize = 0;
if (GARMIN_LAYERID_APPL != getLayerId(garmin_data_p->outbuffer)) {
if (getLayerId(garmin_data_p->outbuffer) != GARMIN_LAYERID_APPL) {
dev_dbg(dev, "not an application packet (%d)\n",
getLayerId(garmin_data_p->outbuffer));
return -1;
@ -688,7 +688,7 @@ static int gsp_send(struct garmin_data *garmin_data_p,
*dst++ = DLE;
}
cksum = 0xFF & -cksum;
cksum = -cksum & 0xFF;
*dst++ = cksum;
if (cksum == DLE)
*dst++ = DLE;
@ -860,7 +860,6 @@ static int process_resetdev_request(struct usb_serial_port *port)
static int garmin_clear(struct garmin_data *garmin_data_p)
{
unsigned long flags;
int status = 0;
/* flush all queued data */
pkt_clear(garmin_data_p);
@ -870,7 +869,7 @@ static int garmin_clear(struct garmin_data *garmin_data_p)
garmin_data_p->outsize = 0;
spin_unlock_irqrestore(&garmin_data_p->lock, flags);
return status;
return 0;
}
@ -970,7 +969,7 @@ static void garmin_write_bulk_callback(struct urb *urb)
struct garmin_data *garmin_data_p =
usb_get_serial_port_data(port);
if (GARMIN_LAYERID_APPL == getLayerId(urb->transfer_buffer)) {
if (getLayerId(urb->transfer_buffer) == GARMIN_LAYERID_APPL) {
if (garmin_data_p->mode == MODE_GARMIN_SERIAL) {
gsp_send_ack(garmin_data_p,
@ -1025,7 +1024,7 @@ static int garmin_write_bulk(struct usb_serial_port *port,
dismiss_ack ? NULL : port);
urb->transfer_flags |= URB_ZERO_PACKET;
if (GARMIN_LAYERID_APPL == getLayerId(buffer)) {
if (getLayerId(buffer) == GARMIN_LAYERID_APPL) {
spin_lock_irqsave(&garmin_data_p->lock, flags);
garmin_data_p->flags |= APP_REQ_SEEN;
@ -1077,9 +1076,9 @@ static int garmin_write(struct tty_struct *tty, struct usb_serial_port *port,
pktsiz = getDataLength(garmin_data_p->privpkt);
pktid = getPacketId(garmin_data_p->privpkt);
if (count == (GARMIN_PKTHDR_LENGTH+pktsiz)
&& GARMIN_LAYERID_PRIVATE ==
getLayerId(garmin_data_p->privpkt)) {
if (count == (GARMIN_PKTHDR_LENGTH + pktsiz) &&
getLayerId(garmin_data_p->privpkt) ==
GARMIN_LAYERID_PRIVATE) {
dev_dbg(dev, "%s - processing private request %d\n",
__func__, pktid);
@ -1192,7 +1191,7 @@ static void garmin_read_bulk_callback(struct urb *urb)
garmin_read_process(garmin_data_p, data, urb->actual_length, 1);
if (urb->actual_length == 0 &&
0 != (garmin_data_p->flags & FLAGS_BULK_IN_RESTART)) {
(garmin_data_p->flags & FLAGS_BULK_IN_RESTART) != 0) {
spin_lock_irqsave(&garmin_data_p->lock, flags);
garmin_data_p->flags &= ~FLAGS_BULK_IN_RESTART;
spin_unlock_irqrestore(&garmin_data_p->lock, flags);
@ -1203,7 +1202,7 @@ static void garmin_read_bulk_callback(struct urb *urb)
__func__, retval);
} else if (urb->actual_length > 0) {
/* Continue trying to read until nothing more is received */
if (0 == (garmin_data_p->flags & FLAGS_THROTTLED)) {
if ((garmin_data_p->flags & FLAGS_THROTTLED) == 0) {
retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
if (retval)
dev_err(&port->dev,
@ -1249,12 +1248,12 @@ static void garmin_read_int_callback(struct urb *urb)
urb->transfer_buffer);
if (urb->actual_length == sizeof(GARMIN_BULK_IN_AVAIL_REPLY) &&
0 == memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY,
sizeof(GARMIN_BULK_IN_AVAIL_REPLY))) {
memcmp(data, GARMIN_BULK_IN_AVAIL_REPLY,
sizeof(GARMIN_BULK_IN_AVAIL_REPLY)) == 0) {
dev_dbg(&port->dev, "%s - bulk data available.\n", __func__);
if (0 == (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) {
if ((garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE) == 0) {
/* bulk data available */
retval = usb_submit_urb(port->read_urb, GFP_ATOMIC);
@ -1276,8 +1275,8 @@ static void garmin_read_int_callback(struct urb *urb)
}
} else if (urb->actual_length == (4+sizeof(GARMIN_START_SESSION_REPLY))
&& 0 == memcmp(data, GARMIN_START_SESSION_REPLY,
sizeof(GARMIN_START_SESSION_REPLY))) {
&& memcmp(data, GARMIN_START_SESSION_REPLY,
sizeof(GARMIN_START_SESSION_REPLY)) == 0) {
spin_lock_irqsave(&garmin_data_p->lock, flags);
garmin_data_p->flags |= FLAGS_SESSION_REPLY1_SEEN;
@ -1356,7 +1355,7 @@ static void garmin_unthrottle(struct tty_struct *tty)
if (garmin_data_p->mode == MODE_NATIVE)
garmin_flush_queue(garmin_data_p);
if (0 != (garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE)) {
if ((garmin_data_p->flags & FLAGS_BULK_IN_ACTIVE) != 0) {
status = usb_submit_urb(port->read_urb, GFP_KERNEL);
if (status)
dev_err(&port->dev,

View File

@ -360,7 +360,7 @@ static void iuu_led_activity_on(struct urb *urb)
int result;
char *buf_ptr = port->write_urb->transfer_buffer;
*buf_ptr++ = IUU_SET_LED;
if (xmas == 1) {
if (xmas) {
get_random_bytes(buf_ptr, 6);
*(buf_ptr+7) = 1;
} else {
@ -380,7 +380,7 @@ static void iuu_led_activity_off(struct urb *urb)
struct usb_serial_port *port = urb->context;
int result;
char *buf_ptr = port->write_urb->transfer_buffer;
if (xmas == 1) {
if (xmas) {
iuu_rxcmd(urb);
return;
} else {

View File

@ -1963,7 +1963,7 @@ static int keyspan_usa49_send_setup(struct usb_serial *serial,
if (d_details->product_id == keyspan_usa49wg_product_id) {
dr = (void *)(s_priv->ctrl_buf);
dr->bRequestType = USB_TYPE_VENDOR | USB_DIR_OUT;
dr->bRequest = 0xB0; /* 49wg control message */;
dr->bRequest = 0xB0; /* 49wg control message */
dr->wValue = 0;
dr->wIndex = 0;
dr->wLength = cpu_to_le16(sizeof(msg));

View File

@ -472,7 +472,6 @@ static void klsi_105_set_termios(struct tty_struct *tty,
/* maybe this should be simulated by sending read
* disable and read enable messages?
*/
;
#if 0
priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
mct_u232_set_modem_ctrl(serial, priv->control_state);
@ -527,7 +526,6 @@ static void klsi_105_set_termios(struct tty_struct *tty,
mct_u232_set_line_ctrl(serial, priv->last_lcr);
#endif
;
}
/*
* Set flow control: well, I do not really now how to handle DTR/RTS.
@ -546,7 +544,6 @@ static void klsi_105_set_termios(struct tty_struct *tty,
priv->control_state &= ~(TIOCM_DTR | TIOCM_RTS);
mct_u232_set_modem_ctrl(serial, priv->control_state);
#endif
;
}
memcpy(cfg, &priv->cfg, sizeof(*cfg));
spin_unlock_irqrestore(&priv->lock, flags);

View File

@ -1842,7 +1842,7 @@ static void mos7840_change_port_settings(struct tty_struct *tty,
Data = 0x0c;
mos7840_set_uart_reg(port, INTERRUPT_ENABLE_REGISTER, Data);
if (mos7840_port->read_urb_busy == false) {
if (!mos7840_port->read_urb_busy) {
mos7840_port->read_urb_busy = true;
status = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL);
if (status) {
@ -1906,7 +1906,7 @@ static void mos7840_set_termios(struct tty_struct *tty,
return;
}
if (mos7840_port->read_urb_busy == false) {
if (!mos7840_port->read_urb_busy) {
mos7840_port->read_urb_busy = true;
status = usb_submit_urb(mos7840_port->read_urb, GFP_KERNEL);
if (status) {

View File

@ -973,7 +973,7 @@ static int qt2_write(struct tty_struct *tty,
data = write_urb->transfer_buffer;
spin_lock_irqsave(&port_priv->urb_lock, flags);
if (port_priv->urb_in_use == true) {
if (port_priv->urb_in_use) {
dev_err(&port->dev, "qt2_write - urb is in use\n");
goto write_out;
}

View File

@ -76,13 +76,8 @@
#include <linux/usb.h>
#include <linux/usb/serial.h>
#ifndef CONFIG_USB_SERIAL_SAFE_PADDED
#define CONFIG_USB_SERIAL_SAFE_PADDED 0
#endif
static bool safe = 1;
static bool padded = CONFIG_USB_SERIAL_SAFE_PADDED;
static bool safe = true;
static bool padded = IS_ENABLED(CONFIG_USB_SERIAL_SAFE_PADDED);
#define DRIVER_AUTHOR "sl@lineo.com, tbr@lineo.com, Johan Hovold <jhovold@gmail.com>"
#define DRIVER_DESC "USB Safe Encapsulated Serial"
@ -278,7 +273,7 @@ static int safe_startup(struct usb_serial *serial)
case LINEO_SAFESERIAL_CRC:
break;
case LINEO_SAFESERIAL_CRC_PADDED:
padded = 1;
padded = true;
break;
default:
return -EINVAL;