USB: ftdi_sio.c: Use ftdi async_icount structure for TIOCMIWAIT, as in other drivers
[linux-flexiantxendom0.git] / drivers / usb / serial / ftdi_sio.c
index 4cfc4cd..8fe034d 100644 (file)
@@ -1918,6 +1918,7 @@ static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
                        c = kfifo_out(&port->write_fifo, &buffer[i + 1], len);
                        if (!c)
                                break;
+                       priv->icount.tx += c;
                        buffer[i] = (c << 2) + 1;
                        count += c + 1;
                }
@@ -1925,6 +1926,7 @@ static int ftdi_prepare_write_buffer(struct usb_serial_port *port,
        } else {
                count = kfifo_out_locked(&port->write_fifo, dest, size,
                                                                &port->lock);
+               priv->icount.tx += count;
        }
 
        return count;
@@ -1952,6 +1954,14 @@ static int ftdi_process_packet(struct tty_struct *tty,
           N.B. packet may be processed more than once, but differences
           are only processed once.  */
        status = packet[0] & FTDI_STATUS_B0_MASK;
+       if (status & FTDI_RS0_CTS)
+               priv->icount.cts++;
+       if (status & FTDI_RS0_DSR)
+               priv->icount.dsr++;
+       if (status & FTDI_RS0_RI)
+               priv->icount.rng++;
+       if (status & FTDI_RS0_RLSD)
+               priv->icount.dcd++;
        if (status != priv->prev_status) {
                priv->diff_status |= status ^ priv->prev_status;
                wake_up_interruptible(&priv->delta_msr_wait);
@@ -1964,15 +1974,20 @@ static int ftdi_process_packet(struct tty_struct *tty,
                 * over framing errors */
                if (packet[1] & FTDI_RS_BI) {
                        flag = TTY_BREAK;
+                       priv->icount.brk++;
                        usb_serial_handle_break(port);
                } else if (packet[1] & FTDI_RS_PE) {
                        flag = TTY_PARITY;
+                       priv->icount.parity++;
                } else if (packet[1] & FTDI_RS_FE) {
                        flag = TTY_FRAME;
+                       priv->icount.frame++;
                }
                /* Overrun is special, not associated with a char */
-               if (packet[1] & FTDI_RS_OE)
+               if (packet[1] & FTDI_RS_OE) {
+                       priv->icount.overrun++;
                        tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+               }
        }
 
        /* save if the transmitter is empty or not */
@@ -1984,6 +1999,7 @@ static int ftdi_process_packet(struct tty_struct *tty,
        len -= 2;
        if (!len)
                return 0;       /* status only */
+       priv->icount.rx += len;
        ch = packet + 2;
 
        if (port->port.console && port->sysrq) {
@@ -2312,6 +2328,8 @@ static int ftdi_ioctl(struct tty_struct *tty,
 {
        struct usb_serial_port *port = tty->driver_data;
        struct ftdi_private *priv = usb_get_serial_port_data(port);
+       struct async_icount cnow;
+       struct async_icount cprev;
 
        dbg("%s cmd 0x%04x", __func__, cmd);
 
@@ -2331,41 +2349,30 @@ static int ftdi_ioctl(struct tty_struct *tty,
         * - mask passed in arg for lines of interest
         *   (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
         * Caller should use TIOCGICOUNT to see which one it was.
-        * (except that the driver doesn't support it !)
         *
         * This code is borrowed from linux/drivers/char/serial.c
         */
        case TIOCMIWAIT:
-               while (priv != NULL) {
+               cprev = priv->icount;
+               while (1) {
                        interruptible_sleep_on(&priv->delta_msr_wait);
                        /* see if a signal did it */
                        if (signal_pending(current))
                                return -ERESTARTSYS;
-                       else {
-                               char diff = priv->diff_status;
-
-                               if (diff == 0)
-                                       return -EIO; /* no change => error */
-
-                               /* Consume all events */
-                               priv->diff_status = 0;
-
-                               /* Return 0 if caller wanted to know about
-                                  these bits */
-                               if (((arg & TIOCM_RNG) && (diff & FTDI_RS0_RI)) ||
-                                   ((arg & TIOCM_DSR) && (diff & FTDI_RS0_DSR)) ||
-                                   ((arg & TIOCM_CD)  && (diff & FTDI_RS0_RLSD)) ||
-                                   ((arg & TIOCM_CTS) && (diff & FTDI_RS0_CTS))) {
-                                       return 0;
-                               }
-                               /*
-                                * Otherwise caller can't care less about what
-                                * happened,and so we continue to wait for more
-                                * events.
-                                */
+                       cnow = priv->icount;
+                       if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
+                           cnow.dcd == cprev.dcd && cnow.cts == cprev.cts)
+                               return -EIO; /* no change => error */
+                       if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
+                           ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
+                           ((arg & TIOCM_CD)  && (cnow.dcd != cprev.dcd)) ||
+                           ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
+                               return 0;
                        }
+                       cprev = cnow;
                }
-               return 0;
+               /* not reached */
+               break;
        case TIOCSERGETLSR:
                return get_lsr_info(port, (struct serial_struct __user *)arg);
                break;