diff options
author | Johan Hovold <jhovold@gmail.com> | 2014-01-02 22:49:28 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2014-01-03 21:42:24 +0100 |
commit | ac035628a95f20ff4c53b80c4b80e12287231e1a (patch) | |
tree | 52ea124954a8515415f68890a2e6b267657c6f8a /drivers/usb/serial | |
parent | USB: cypress_m8: switch to generic TIOCMIWAIT implementation (diff) | |
download | linux-ac035628a95f20ff4c53b80c4b80e12287231e1a.tar.xz linux-ac035628a95f20ff4c53b80c4b80e12287231e1a.zip |
USB: ch341: refactor line-status handling
Refactor line-status handling.
Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/usb/serial')
-rw-r--r-- | drivers/usb/serial/ch341.c | 51 |
1 files changed, 28 insertions, 23 deletions
diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c index 8908760cca9f..f647dbdcb27d 100644 --- a/drivers/usb/serial/ch341.c +++ b/drivers/usb/serial/ch341.c @@ -440,6 +440,33 @@ static int ch341_tiocmset(struct tty_struct *tty, return ch341_set_handshake(port->serial->dev, control); } +static void ch341_update_line_status(struct usb_serial_port *port, + unsigned char *data, size_t len) +{ + struct ch341_private *priv = usb_get_serial_port_data(port); + unsigned long flags; + u8 prev_line_status = priv->line_status; + + if (len < 4) + return; + + spin_lock_irqsave(&priv->lock, flags); + priv->line_status = (~(data[2])) & CH341_BITS_MODEM_STAT; + if ((data[1] & CH341_MULT_STAT)) + priv->multi_status_change = 1; + spin_unlock_irqrestore(&priv->lock, flags); + + if ((priv->line_status ^ prev_line_status) & CH341_BIT_DCD) { + struct tty_struct *tty = tty_port_tty_get(&port->port); + if (tty) + usb_serial_handle_dcd_change(port, tty, + priv->line_status & CH341_BIT_DCD); + tty_kref_put(tty); + } + + wake_up_interruptible(&port->port.delta_msr_wait); +} + static void ch341_read_int_callback(struct urb *urb) { struct usb_serial_port *port = (struct usb_serial_port *) urb->context; @@ -466,29 +493,7 @@ static void ch341_read_int_callback(struct urb *urb) usb_serial_debug_data(&port->dev, __func__, urb->actual_length, urb->transfer_buffer); - - if (actual_length >= 4) { - struct ch341_private *priv = usb_get_serial_port_data(port); - unsigned long flags; - u8 prev_line_status = priv->line_status; - - spin_lock_irqsave(&priv->lock, flags); - priv->line_status = (~(data[2])) & CH341_BITS_MODEM_STAT; - if ((data[1] & CH341_MULT_STAT)) - priv->multi_status_change = 1; - spin_unlock_irqrestore(&priv->lock, flags); - - if ((priv->line_status ^ prev_line_status) & CH341_BIT_DCD) { - struct tty_struct *tty = tty_port_tty_get(&port->port); - if (tty) - usb_serial_handle_dcd_change(port, tty, - priv->line_status & CH341_BIT_DCD); - tty_kref_put(tty); - } - - wake_up_interruptible(&port->port.delta_msr_wait); - } - + ch341_update_line_status(port, data, actual_length); exit: status = usb_submit_urb(urb, GFP_ATOMIC); if (status) |