[PATCH] Serial: Add uart_insert_char()
authorRussell King <rmk@dyn-67.arm.linux.org.uk>
Mon, 9 May 2005 22:21:59 +0000 (23:21 +0100)
committerRussell King <rmk@dyn-67.arm.linux.org.uk>
Mon, 9 May 2005 22:21:59 +0000 (23:21 +0100)
Add uart_insert_char(), which handles inserting characters into the
flip buffer.  This helper function handles the correct semantics
for handling overrun in addition to inserting normal characters.

Signed-off-by: Russell King <rmk@arm.linux.org.uk>
12 files changed:
drivers/serial/21285.c
drivers/serial/8250.c
drivers/serial/amba-pl010.c
drivers/serial/amba-pl011.c
drivers/serial/clps711x.c
drivers/serial/pxa.c
drivers/serial/s3c2410.c
drivers/serial/sa1100.c
drivers/serial/serial_lh7a40x.c
drivers/serial/serial_txx9.c
drivers/serial/vr41xx_siu.c
include/linux/serial_core.h

index 33fbda79f3507f83f00ca3b9c8f9167f6500c136..0b10169961ebfe2898efecb192a00c5a47c4b1df 100644 (file)
@@ -126,18 +126,8 @@ static irqreturn_t serial21285_rx_chars(int irq, void *dev_id, struct pt_regs *r
                                flag = TTY_FRAME;
                }
 
-               if ((rxs & port->ignore_status_mask) == 0) {
-                       tty_insert_flip_char(tty, ch, flag);
-               }
-               if ((rxs & RXSTAT_OVERRUN) &&
-                   tty->flip.count < TTY_FLIPBUF_SIZE) {
-                       /*
-                        * Overrun is special, since it's reported
-                        * immediately, and doesn't affect the current
-                        * character.
-                        */
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
-               }
+               uart_insert_char(port, rxs, RXSTAT_OVERRUN, ch, flag);
+
                status = *CSR_UARTFLG;
        }
        tty_flip_buffer_push(tty);
index 0d9358608fdfdc8c6d53824dfc9f11a4d1fe38f9..3bbf0cc6e53f9989fd52630432570cd2152e8cf8 100644 (file)
@@ -1122,18 +1122,9 @@ receive_chars(struct uart_8250_port *up, int *status, struct pt_regs *regs)
                }
                if (uart_handle_sysrq_char(&up->port, ch, regs))
                        goto ignore_char;
-               if ((lsr & up->port.ignore_status_mask) == 0) {
-                       tty_insert_flip_char(tty, ch, flag);
-               }
-               if ((lsr & UART_LSR_OE) &&
-                   tty->flip.count < TTY_FLIPBUF_SIZE) {
-                       /*
-                        * Overrun is special, since it's reported
-                        * immediately, and doesn't affect the current
-                        * character.
-                        */
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
-               }
+
+               uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);
+
        ignore_char:
                lsr = serial_inp(up, UART_LSR);
        } while ((lsr & UART_LSR_DR) && (max_count-- > 0));
index f2a5e2933c4709b2b56fc4167e041b0e366e5782..2884b310e54d2d01f50d012d4394343b08b5717a 100644 (file)
@@ -198,18 +198,8 @@ pl010_rx_chars(struct uart_port *port)
                if (uart_handle_sysrq_char(port, ch, regs))
                        goto ignore_char;
 
-               if ((rsr & port->ignore_status_mask) == 0) {
-                       tty_insert_flip_char(tty, ch, flag);
-               }
-               if ((rsr & UART01x_RSR_OE) &&
-                   tty->flip.count < TTY_FLIPBUF_SIZE) {
-                       /*
-                        * Overrun is special, since it's reported
-                        * immediately, and doesn't affect the current
-                        * character
-                        */
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
-               }
+               uart_insert_char(port, rsr, UART01x_RSR_OE, ch, flag);
+
        ignore_char:
                status = UART_GET_FR(port);
        }
index d5cbef3fe8b6adb42cf900aaffbec87494c8fdf8..7db88ee18f75fb1f138f71921c05d833aa935a51 100644 (file)
@@ -163,18 +163,8 @@ pl011_rx_chars(struct uart_amba_port *uap)
                if (uart_handle_sysrq_char(&uap->port, ch, regs))
                        goto ignore_char;
 
-               if ((rsr & uap->port.ignore_status_mask) == 0) {
-                       tty_insert_flip_char(tty, ch, flag);
-               }
-               if ((rsr & UART01x_RSR_OE) &&
-                   tty->flip.count < TTY_FLIPBUF_SIZE) {
-                       /*
-                        * Overrun is special, since it's reported
-                        * immediately, and doesn't affect the current
-                        * character
-                        */
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
-               }
+               uart_insert_char(&uap->port, rsr, UART01x_RSR_OE, ch, flag);
+
        ignore_char:
                status = readw(uap->port.membase + UART01x_FR);
        }
index 6242f3090a96f76372ad8e35367bbbc790e68cf0..e92522b33c48e9e4e283b8fbd498d4e8b7e45c12 100644 (file)
@@ -143,10 +143,7 @@ static irqreturn_t clps711xuart_int_rx(int irq, void *dev_id, struct pt_regs *re
                 * CHECK: does overrun affect the current character?
                 * ASSUMPTION: it does not.
                 */
-               if ((ch & port->ignore_status_mask & ~RXSTAT_OVERRUN) == 0)
-                       tty_insert_flip_char(tty, ch, flg);
-               if ((ch & ~port->ignore_status_mask & RXSTAT_OVERRUN) == 0)
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+               uart_insert_char(port, ch, UARTDR_OVERR, ch, flg);
 
        ignore_char:
                status = clps_readl(SYSFLG(port));
index 51d8a49f4477bb6f23048b361e4ad367ecdb9758..9dc151d8fa612bb16554f6d4d15382a5d4eaf7ab 100644 (file)
@@ -161,20 +161,12 @@ receive_chars(struct uart_pxa_port *up, int *status, struct pt_regs *regs)
                        else if (*status & UART_LSR_FE)
                                flag = TTY_FRAME;
                }
+
                if (uart_handle_sysrq_char(&up->port, ch, regs))
                        goto ignore_char;
-               if ((*status & up->port.ignore_status_mask) == 0) {
-                       tty_insert_flip_char(tty, ch, flag);
-               }
-               if ((*status & UART_LSR_OE) &&
-                   tty->flip.count < TTY_FLIPBUF_SIZE) {
-                       /*
-                        * Overrun is special, since it's reported
-                        * immediately, and doesn't affect the current
-                        * character.
-                        */
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
-               }
+
+               uart_insert_char(&up->port, *status, UART_LSR_OE, ch, flag);
+
        ignore_char:
                *status = serial_in(up, UART_LSR);
        } while ((*status & UART_LSR_DR) && (max_count-- > 0));
index 435750d40a471001c860ba0b21b0443901534eab..2a9f7ade2c9d58faa134e84d698d9025af5365b1 100644 (file)
@@ -394,20 +394,7 @@ s3c24xx_serial_rx_chars(int irq, void *dev_id, struct pt_regs *regs)
                if (uart_handle_sysrq_char(port, ch, regs))
                        goto ignore_char;
 
-               if ((uerstat & port->ignore_status_mask) == 0) {
-                       tty_insert_flip_char(tty, ch, flag);
-               }
-
-               if ((uerstat & S3C2410_UERSTAT_OVERRUN) &&
-                   tty->flip.count < TTY_FLIPBUF_SIZE) {
-                       /*
-                        * Overrun is special, since it's reported
-                        * immediately, and doesn't affect the current
-                        * character.
-                        */
-
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
-               }
+               uart_insert_char(port, uerstat, S3C2410_UERSTAT_OVERRUN, ch, flag);
 
        ignore_char:
                continue;
index 157218bc6c6fba4ddbce2e2294d381903a620eb5..22565a67a57cd0e6e63a85540addbcbbe2ec5321 100644 (file)
@@ -237,10 +237,7 @@ sa1100_rx_chars(struct sa1100_port *sport, struct pt_regs *regs)
                if (uart_handle_sysrq_char(&sport->port, ch, regs))
                        goto ignore_char;
 
-               if ((status & port->ignore_status_mask & ~UTSR1_TO_SM(UTSR1_ROR)) == 0)
-                       tty_insert_flip_char(tty, ch, flg);
-               if (status & ~port->ignore_status_mask & UTSR1_TO_SM(UTSR1_ROR))
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+               uart_insert_char(&sport->port, status, UTSR1_TO_SM(UTSR1_ROR), ch, flg);
 
        ignore_char:
                status = UTSR1_TO_SM(UART_GET_UTSR1(sport)) |
index 85cfa08d3bad7955bb79279f73be920e332fb03f..56f269b6bfb12c53fb323c66dcab126010888bee 100644 (file)
@@ -190,18 +190,7 @@ lh7a40xuart_rx_chars (struct uart_port* port)
                if (uart_handle_sysrq_char (port, (unsigned char) data, regs))
                        continue;
 
-               if ((data & port->ignore_status_mask) == 0) {
-                       tty_insert_flip_char(tty, data, flag);
-               }
-               if ((data & RxOverrunError)
-                   && tty->flip.count < TTY_FLIPBUF_SIZE) {
-                       /*
-                        * Overrun is special, since it's reported
-                        * immediately, and doesn't affect the current
-                        * character
-                        */
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
-               }
+               uart_insert_char(port, data, RxOverrunError, data, flag);
        }
        tty_flip_buffer_push (tty);
        return;
index 37b2ef297cbec3816b06d2a30ad588a80abbfdd1..3f1051a4a13f8f51cab2efa2783f287e734c8ecb 100644 (file)
@@ -350,18 +350,9 @@ receive_chars(struct uart_txx9_port *up, unsigned int *status, struct pt_regs *r
                }
                if (uart_handle_sysrq_char(&up->port, ch, regs))
                        goto ignore_char;
-               if ((disr & up->port.ignore_status_mask) == 0) {
-                       tty_insert_flip_char(tty, ch, flag);
-               }
-               if ((disr & TXX9_SIDISR_UOER) &&
-                   tty->flip.count < TTY_FLIPBUF_SIZE) {
-                       /*
-                        * Overrun is special, since it's reported
-                        * immediately, and doesn't affect the current
-                        * character.
-                        */
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
-               }
+
+               uart_insert_char(&up->port, disr, TXX9_SIDISR_UOER, ch, flag);
+
        ignore_char:
                disr = sio_in(up, TXX9_SIDISR);
        } while (!(disr & TXX9_SIDISR_UVALID) && (max_count-- > 0));
index 307886199f2f6f1301d6aa240b1f3263e9ec8a90..5d2ceb623e6fcebe34319cac6c4bcd72d2c78739 100644 (file)
@@ -412,10 +412,8 @@ static inline void receive_chars(struct uart_port *port, uint8_t *status,
 
                if (uart_handle_sysrq_char(port, ch, regs))
                        goto ignore_char;
-               if ((lsr & port->ignore_status_mask) == 0)
-                       tty_insert_flip_char(tty, ch, flag);
-               if ((lsr & UART_LSR_OE) && (tty->flip.count < TTY_FLIPBUF_SIZE))
-                       tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+
+               uart_insert_char(port, lsr, UART_LSR_OE, ch, flag);
 
        ignore_char:
                lsr = siu_read(port, UART_LSR);
index c3fb5984f250a19e5f45ff23551fc7d148e9790e..d6025af7efac39154d65c90f447b54f79a43ac37 100644 (file)
@@ -479,6 +479,25 @@ uart_handle_cts_change(struct uart_port *port, unsigned int status)
        }
 }
 
+#include <linux/tty_flip.h>
+
+static inline void
+uart_insert_char(struct uart_port *port, unsigned int status,
+                unsigned int overrun, unsigned int ch, unsigned int flag)
+{
+       struct tty_struct *tty = port->info->tty;
+
+       if ((status & port->ignore_status_mask & ~overrun) == 0)
+               tty_insert_flip_char(tty, ch, flag);
+
+       /*
+        * Overrun is special.  Since it's reported immediately,
+        * it doesn't affect the current character.
+        */
+       if (status & ~port->ignore_status_mask & overrun)
+               tty_insert_flip_char(tty, 0, TTY_OVERRUN);
+}
+
 /*
  *     UART_ENABLE_MS - determine if port should enable modem status irqs
  */