[RFC/PATCH 08/13] serial: omap: refactor receive_chars() into rdi/rlsi handlers

2012-08-21 Thread Felipe Balbi
receive_chars() was getting too big and too difficult
to follow. By splitting it into separate RDI and RSLI
handlers, we have smaller functions which are easy
to understand and only touch the pieces which they need
to touch.

Signed-off-by: Felipe Balbi 
---
 drivers/tty/serial/omap-serial.c | 203 +++
 1 file changed, 100 insertions(+), 103 deletions(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 1ca08b8..74a4f0a 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -195,74 +195,6 @@ static void serial_omap_stop_rx(struct uart_port *port)
pm_runtime_put_autosuspend(up->dev);
 }
 
-static inline void receive_chars(struct uart_omap_port *up,
-   unsigned int *status)
-{
-   struct tty_struct *tty = up->port.state->port.tty;
-   unsigned int flag, lsr = *status;
-   unsigned char ch = 0;
-   int max_count = 256;
-
-   do {
-   if (likely(lsr & UART_LSR_DR))
-   ch = serial_in(up, UART_RX);
-   flag = TTY_NORMAL;
-   up->port.icount.rx++;
-
-   if (unlikely(lsr & UART_LSR_BRK_ERROR_BITS)) {
-   /*
-* For statistics only
-*/
-   if (lsr & UART_LSR_BI) {
-   lsr &= ~(UART_LSR_FE | UART_LSR_PE);
-   up->port.icount.brk++;
-   /*
-* We do the SysRQ and SAK checking
-* here because otherwise the break
-* may get masked by ignore_status_mask
-* or read_status_mask.
-*/
-   if (uart_handle_break(>port))
-   goto ignore_char;
-   } else if (lsr & UART_LSR_PE) {
-   up->port.icount.parity++;
-   } else if (lsr & UART_LSR_FE) {
-   up->port.icount.frame++;
-   }
-
-   if (lsr & UART_LSR_OE)
-   up->port.icount.overrun++;
-
-   /*
-* Mask off conditions which should be ignored.
-*/
-   lsr &= up->port.read_status_mask;
-
-#ifdef CONFIG_SERIAL_OMAP_CONSOLE
-   if (up->port.line == up->port.cons->index) {
-   /* Recover the break flag from console xmit */
-   lsr |= up->lsr_break_flag;
-   }
-#endif
-   if (lsr & UART_LSR_BI)
-   flag = TTY_BREAK;
-   else if (lsr & UART_LSR_PE)
-   flag = TTY_PARITY;
-   else if (lsr & UART_LSR_FE)
-   flag = TTY_FRAME;
-   }
-
-   if (uart_handle_sysrq_char(>port, ch))
-   goto ignore_char;
-   uart_insert_char(>port, lsr, UART_LSR_OE, ch, flag);
-ignore_char:
-   lsr = serial_in(up, UART_LSR);
-   } while ((lsr & (UART_LSR_DR | UART_LSR_BI)) && (max_count-- > 0));
-   spin_unlock(>port.lock);
-   tty_flip_buffer_push(tty);
-   spin_lock(>port.lock);
-}
-
 static void transmit_chars(struct uart_omap_port *up)
 {
struct circ_buf *xmit = >port.state->xmit;
@@ -341,6 +273,68 @@ static unsigned int check_modem_status(struct 
uart_omap_port *up)
return status;
 }
 
+static void serial_omap_rlsi(struct uart_omap_port *up, unsigned int lsr)
+{
+   unsigned int flag;
+
+   up->port.icount.rx++;
+   flag = TTY_NORMAL;
+
+   if (lsr & UART_LSR_BI) {
+   flag = TTY_BREAK;
+   lsr &= ~(UART_LSR_FE | UART_LSR_PE);
+   up->port.icount.brk++;
+   /*
+* We do the SysRQ and SAK checking
+* here because otherwise the break
+* may get masked by ignore_status_mask
+* or read_status_mask.
+*/
+   if (uart_handle_break(>port))
+   return;
+
+   }
+
+   if (lsr & UART_LSR_PE) {
+   flag = TTY_PARITY;
+   up->port.icount.parity++;
+   }
+
+   if (lsr & UART_LSR_FE) {
+   flag = TTY_FRAME;
+   up->port.icount.frame++;
+   }
+
+   if (lsr & UART_LSR_OE)
+   up->port.icount.overrun++;
+
+#ifdef CONFIG_SERIAL_OMAP_CONSOLE
+   if (up->port.line == up->port.cons->index) {
+   /* Recover the break flag from console xmit */
+   lsr |= up->lsr_break_flag;
+   }
+#endif
+   uart_insert_char(>port, lsr, UART_LSR_OE, 0, flag);
+}
+
+static void 

[RFC/PATCH 08/13] serial: omap: refactor receive_chars() into rdi/rlsi handlers

2012-08-21 Thread Felipe Balbi
receive_chars() was getting too big and too difficult
to follow. By splitting it into separate RDI and RSLI
handlers, we have smaller functions which are easy
to understand and only touch the pieces which they need
to touch.

Signed-off-by: Felipe Balbi ba...@ti.com
---
 drivers/tty/serial/omap-serial.c | 203 +++
 1 file changed, 100 insertions(+), 103 deletions(-)

diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index 1ca08b8..74a4f0a 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -195,74 +195,6 @@ static void serial_omap_stop_rx(struct uart_port *port)
pm_runtime_put_autosuspend(up-dev);
 }
 
-static inline void receive_chars(struct uart_omap_port *up,
-   unsigned int *status)
-{
-   struct tty_struct *tty = up-port.state-port.tty;
-   unsigned int flag, lsr = *status;
-   unsigned char ch = 0;
-   int max_count = 256;
-
-   do {
-   if (likely(lsr  UART_LSR_DR))
-   ch = serial_in(up, UART_RX);
-   flag = TTY_NORMAL;
-   up-port.icount.rx++;
-
-   if (unlikely(lsr  UART_LSR_BRK_ERROR_BITS)) {
-   /*
-* For statistics only
-*/
-   if (lsr  UART_LSR_BI) {
-   lsr = ~(UART_LSR_FE | UART_LSR_PE);
-   up-port.icount.brk++;
-   /*
-* We do the SysRQ and SAK checking
-* here because otherwise the break
-* may get masked by ignore_status_mask
-* or read_status_mask.
-*/
-   if (uart_handle_break(up-port))
-   goto ignore_char;
-   } else if (lsr  UART_LSR_PE) {
-   up-port.icount.parity++;
-   } else if (lsr  UART_LSR_FE) {
-   up-port.icount.frame++;
-   }
-
-   if (lsr  UART_LSR_OE)
-   up-port.icount.overrun++;
-
-   /*
-* Mask off conditions which should be ignored.
-*/
-   lsr = up-port.read_status_mask;
-
-#ifdef CONFIG_SERIAL_OMAP_CONSOLE
-   if (up-port.line == up-port.cons-index) {
-   /* Recover the break flag from console xmit */
-   lsr |= up-lsr_break_flag;
-   }
-#endif
-   if (lsr  UART_LSR_BI)
-   flag = TTY_BREAK;
-   else if (lsr  UART_LSR_PE)
-   flag = TTY_PARITY;
-   else if (lsr  UART_LSR_FE)
-   flag = TTY_FRAME;
-   }
-
-   if (uart_handle_sysrq_char(up-port, ch))
-   goto ignore_char;
-   uart_insert_char(up-port, lsr, UART_LSR_OE, ch, flag);
-ignore_char:
-   lsr = serial_in(up, UART_LSR);
-   } while ((lsr  (UART_LSR_DR | UART_LSR_BI))  (max_count--  0));
-   spin_unlock(up-port.lock);
-   tty_flip_buffer_push(tty);
-   spin_lock(up-port.lock);
-}
-
 static void transmit_chars(struct uart_omap_port *up)
 {
struct circ_buf *xmit = up-port.state-xmit;
@@ -341,6 +273,68 @@ static unsigned int check_modem_status(struct 
uart_omap_port *up)
return status;
 }
 
+static void serial_omap_rlsi(struct uart_omap_port *up, unsigned int lsr)
+{
+   unsigned int flag;
+
+   up-port.icount.rx++;
+   flag = TTY_NORMAL;
+
+   if (lsr  UART_LSR_BI) {
+   flag = TTY_BREAK;
+   lsr = ~(UART_LSR_FE | UART_LSR_PE);
+   up-port.icount.brk++;
+   /*
+* We do the SysRQ and SAK checking
+* here because otherwise the break
+* may get masked by ignore_status_mask
+* or read_status_mask.
+*/
+   if (uart_handle_break(up-port))
+   return;
+
+   }
+
+   if (lsr  UART_LSR_PE) {
+   flag = TTY_PARITY;
+   up-port.icount.parity++;
+   }
+
+   if (lsr  UART_LSR_FE) {
+   flag = TTY_FRAME;
+   up-port.icount.frame++;
+   }
+
+   if (lsr  UART_LSR_OE)
+   up-port.icount.overrun++;
+
+#ifdef CONFIG_SERIAL_OMAP_CONSOLE
+   if (up-port.line == up-port.cons-index) {
+   /* Recover the break flag from console xmit */
+   lsr |= up-lsr_break_flag;
+   }
+#endif
+   uart_insert_char(up-port, lsr, UART_LSR_OE, 0, flag);
+}
+
+static void