USB: serial: add generic get_icount implementation
authorJohan Hovold <jhovold@gmail.com>
Thu, 21 Mar 2013 11:36:54 +0000 (12:36 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 25 Mar 2013 20:50:51 +0000 (13:50 -0700)
Add generic get_icount implementation that subdrivers relying on the
port interrupt counters can use.

Signed-off-by: Johan Hovold <jhovold@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/serial/generic.c
include/linux/usb/serial.h

index 18bc74e20fe1561e94d1c0e53420bfc7697d093d..5e55761b2cb8934c09365aecb5329311d60859b5 100644 (file)
@@ -476,6 +476,33 @@ int usb_serial_generic_tiocmiwait(struct tty_struct *tty, unsigned long arg)
 }
 EXPORT_SYMBOL_GPL(usb_serial_generic_tiocmiwait);
 
+int usb_serial_generic_get_icount(struct tty_struct *tty,
+                                       struct serial_icounter_struct *icount)
+{
+       struct usb_serial_port *port = tty->driver_data;
+       struct async_icount cnow;
+       unsigned long flags;
+
+       spin_lock_irqsave(&port->lock, flags);
+       cnow = port->icount;                            /* atomic copy */
+       spin_unlock_irqrestore(&port->lock, flags);
+
+       icount->cts = cnow.cts;
+       icount->dsr = cnow.dsr;
+       icount->rng = cnow.rng;
+       icount->dcd = cnow.dcd;
+       icount->tx = cnow.tx;
+       icount->rx = cnow.rx;
+       icount->frame = cnow.frame;
+       icount->parity = cnow.parity;
+       icount->overrun = cnow.overrun;
+       icount->brk = cnow.brk;
+       icount->buf_overrun = cnow.buf_overrun;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(usb_serial_generic_get_icount);
+
 #ifdef CONFIG_MAGIC_SYSRQ
 int usb_serial_handle_sysrq_char(struct usb_serial_port *port, unsigned int ch)
 {
index 47c8d2c506c8fd2709fdb01815b8b832b88be0b9..c786ee7fca8f553ccc6e71149b990a3ab8fc5b38 100644 (file)
@@ -335,6 +335,8 @@ extern void usb_serial_generic_throttle(struct tty_struct *tty);
 extern void usb_serial_generic_unthrottle(struct tty_struct *tty);
 extern int usb_serial_generic_tiocmiwait(struct tty_struct *tty,
                                                        unsigned long arg);
+extern int usb_serial_generic_get_icount(struct tty_struct *tty,
+                                       struct serial_icounter_struct *icount);
 extern int usb_serial_generic_register(void);
 extern void usb_serial_generic_deregister(void);
 extern int usb_serial_generic_submit_read_urbs(struct usb_serial_port *port,