From: Felipe Balbi <balbi@ti.com>
To: Greg KH <gregkh@linuxfoundation.org>
Cc: alan@linux.intel.com, Tony Lindgren <tony@atomide.com>,
Kevin Hilman <khilman@ti.com>,
Linux OMAP Mailing List <linux-omap@vger.kernel.org>,
Linux ARM Kernel Mailing List
<linux-arm-kernel@lists.infradead.org>,
linux-serial@vger.kernel.org,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Santosh Shilimkar <santosh.shilimkar@ti.com>,
Shubhrajyoti Datta <shubhrajyoti@ti.com>,
Sourav Poddar <sourav.poddar@ti.com>, Felipe Balbi <balbi@ti.com>
Subject: [PATCH v4 05/21] serial: omap: refactor receive_chars() into rdi/rlsi handlers
Date: Thu, 6 Sep 2012 15:45:24 +0300 [thread overview]
Message-ID: <1346935540-1792-6-git-send-email-balbi@ti.com> (raw)
In-Reply-To: <1346935540-1792-1-git-send-email-balbi@ti.com>
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.
Tested-by: Shubhrajyoti D <shubhrajyoti@ti.com>
Acked-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>
---
drivers/tty/serial/omap-serial.c | 205 +++++++++++++++++++--------------------
1 file changed, 101 insertions(+), 104 deletions(-)
diff --git a/drivers/tty/serial/omap-serial.c b/drivers/tty/serial/omap-serial.c
index d5a08cb..9c0a4ae 100644
--- a/drivers/tty/serial/omap-serial.c
+++ b/drivers/tty/serial/omap-serial.c
@@ -196,74 +196,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;
@@ -342,6 +274,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 serial_omap_rdi(struct uart_omap_port *up, unsigned int lsr)
+{
+ unsigned char ch = 0;
+ unsigned int flag;
+
+ if (!(lsr & UART_LSR_DR))
+ return;
+
+ ch = serial_in(up, UART_RX);
+ flag = TTY_NORMAL;
+ up->port.icount.rx++;
+
+ if (uart_handle_sysrq_char(&up->port, ch))
+ return;
+
+ uart_insert_char(&up->port, lsr, UART_LSR_OE, ch, flag);
+}
+
/**
* serial_omap_irq() - This handles the interrupt from one port
* @irq: uart port irq number
@@ -350,54 +344,57 @@ static unsigned int check_modem_status(struct uart_omap_port *up)
static inline irqreturn_t serial_omap_irq(int irq, void *dev_id)
{
struct uart_omap_port *up = dev_id;
+ struct tty_struct *tty = up->port.state->port.tty;
unsigned int iir, lsr;
unsigned int type;
unsigned long flags;
irqreturn_t ret = IRQ_NONE;
+ int max_count = 256;
spin_lock_irqsave(&up->port.lock, flags);
pm_runtime_get_sync(up->dev);
- iir = serial_in(up, UART_IIR);
-again:
- if (iir & UART_IIR_NO_INT)
- goto out;
- ret = IRQ_HANDLED;
- lsr = serial_in(up, UART_LSR);
+ do {
+ iir = serial_in(up, UART_IIR);
+ if (iir & UART_IIR_NO_INT)
+ break;
- /* extract IRQ type from IIR register */
- type = iir & 0x3e;
+ ret = IRQ_HANDLED;
+ lsr = serial_in(up, UART_LSR);
- switch (type) {
- case UART_IIR_MSI:
- check_modem_status(up);
- break;
- case UART_IIR_THRI:
- if (lsr & UART_LSR_THRE)
- transmit_chars(up);
- break;
- case UART_IIR_RDI:
- if (lsr & UART_LSR_DR)
- receive_chars(up, &lsr);
- break;
- case UART_IIR_RLSI:
- if (lsr & UART_LSR_BRK_ERROR_BITS)
- receive_chars(up, &lsr);
- break;
- case UART_IIR_RX_TIMEOUT:
- receive_chars(up, &lsr);
- break;
- case UART_IIR_CTS_RTS_DSR:
- iir = serial_in(up, UART_IIR);
- goto again;
- case UART_IIR_XOFF:
- /* FALLTHROUGH */
- default:
- break;
- }
+ /* extract IRQ type from IIR register */
+ type = iir & 0x3e;
+
+ switch (type) {
+ case UART_IIR_MSI:
+ check_modem_status(up);
+ break;
+ case UART_IIR_THRI:
+ if (lsr & UART_LSR_THRE)
+ transmit_chars(up);
+ break;
+ case UART_IIR_RX_TIMEOUT:
+ /* FALLTHROUGH */
+ case UART_IIR_RDI:
+ serial_omap_rdi(up, lsr);
+ break;
+ case UART_IIR_RLSI:
+ serial_omap_rlsi(up, lsr);
+ break;
+ case UART_IIR_CTS_RTS_DSR:
+ /* simply try again */
+ break;
+ case UART_IIR_XOFF:
+ /* FALLTHROUGH */
+ default:
+ break;
+ }
+ } while (!(iir & UART_IIR_NO_INT) && max_count--);
-out:
spin_unlock_irqrestore(&up->port.lock, flags);
+
+ tty_flip_buffer_push(tty);
+
pm_runtime_mark_last_busy(up->dev);
pm_runtime_put_autosuspend(up->dev);
up->port_activity = jiffies;
--
1.7.12.rc3
next prev parent reply other threads:[~2012-09-06 12:45 UTC|newest]
Thread overview: 73+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-23 10:32 [PATCH v3 00/23] OMAP UART patches Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 01/23] serial: omap: define and use to_uart_omap_port() Felipe Balbi
2012-08-24 19:07 ` Tony Lindgren
2012-08-23 10:32 ` [PATCH v3 02/23] serial: omap: define helpers for pdata function pointers Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 03/23] serial: omap: don't access the platform_device Felipe Balbi
2012-08-24 19:07 ` Tony Lindgren
2012-09-05 20:27 ` Greg KH
2012-09-06 12:29 ` Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 00/21] OMAP UART Patches Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 01/21] serial: omap: don't access the platform_device Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 02/21] serial: omap: drop DMA support Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 03/21] serial: add OMAP-specific defines Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 04/21] serial: omap: simplify IRQ handling Felipe Balbi
2012-09-06 12:45 ` Felipe Balbi [this message]
2012-09-06 12:45 ` [PATCH v4 06/21] serial: omap: move THRE check to transmit_chars() Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 07/21] serial: omap: stick to put_autosuspend Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 08/21] serial: omap: set dev->drvdata before enabling pm_runtime Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 09/21] serial: omap: drop unnecessary check from remove Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 10/21] serial: omap: make sure to suspend device before remove Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 11/21] serial: omap: don't save IRQ flags on hardirq Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 12/21] serial: omap: fix sequence of pm_runtime_* calls Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 13/21] serial: omap: optimization with section annotations Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 14/21] serial: omap: drop "inline" from IRQ handler prototype Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 15/21] serial: omap: unlock the port lock Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 16/21] serial: omap: implement set_wake Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 17/21] serial: omap: make sure to put() on poll_get_char Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 18/21] serial: omap: fix software flow control Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 19/21] serial: omap: remove unnecessary header and add a missing one Felipe Balbi
2012-09-06 12:45 ` [PATCH v4 20/21] serial: omap: move uart_omap_port definition to C file Felipe Balbi
2012-09-06 21:58 ` Kevin Hilman
2012-09-06 12:45 ` [PATCH v4 21/21] serial: omap: enable RX and TX FIFO usage Felipe Balbi
2012-09-06 16:18 ` [PATCH v4 00/21] OMAP UART Patches Greg KH
2012-09-06 17:25 ` Felipe Balbi
2012-09-06 21:37 ` Paul Walmsley
2012-09-11 22:02 ` Paul Walmsley
2012-09-12 6:23 ` Felipe Balbi
2012-09-12 20:25 ` Paul Walmsley
2012-09-13 5:01 ` Felipe Balbi
2012-09-16 1:22 ` Paul Walmsley
2012-09-16 18:36 ` Felipe Balbi
2012-09-06 22:44 ` Kevin Hilman
2012-09-07 5:49 ` Felipe Balbi
2012-09-07 20:53 ` Kevin Hilman
2012-09-08 19:04 ` Felipe Balbi
2012-09-11 11:31 ` Shubhrajyoti
2012-09-11 11:54 ` Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 04/23] serial: omap: drop DMA support Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 05/23] serial: add OMAP-specific defines Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 06/23] serial: omap: simplify IRQ handling Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 07/23] serial: omap: refactor receive_chars() into rdi/rlsi handlers Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 08/23] serial: omap: move THRE check to transmit_chars() Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 09/23] serial: omap: stick to put_autosuspend Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 10/23] serial: omap: set dev->drvdata before enabling pm_runtime Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 11/23] serial: omap: drop unnecessary check from remove Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 12/23] serial: omap: make sure to suspend device before remove Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 13/23] serial: omap: don't save IRQ flags on hardirq Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 14/23] serial: omap: fix sequence of pm_runtime_* calls Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 15/23] serial: omap: optimization with section annotations Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 16/23] serial: omap: drop "inline" from IRQ handler prototype Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 17/23] serial: omap: unlock the port lock Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 18/23] serial: omap: implement set_wake Felipe Balbi
2012-08-23 10:32 ` [PATCH v3 19/23] serial: omap: make sure to put() on poll_get_char Felipe Balbi
2012-08-23 10:33 ` [PATCH v3 20/23] serial: omap: fix software flow control Felipe Balbi
2012-08-24 19:08 ` Tony Lindgren
2012-09-05 20:27 ` Greg KH
2012-09-06 12:31 ` Felipe Balbi
2012-08-23 10:33 ` [PATCH v3 21/23] serial: omap: remove unnecessary header and add a missing one Felipe Balbi
2012-08-23 10:33 ` [PATCH v3 22/23] serial: omap: move uart_omap_port definition to C file Felipe Balbi
2012-08-24 19:08 ` Tony Lindgren
2012-08-23 10:33 ` [PATCH v3 23/23] serial: omap: enable RX and TX FIFO usage Felipe Balbi
2012-08-24 10:40 ` [PATCH v3 00/23] OMAP UART patches Felipe Balbi
2012-09-04 11:45 ` Felipe Balbi
2012-09-05 20:18 ` Greg KH
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1346935540-1792-6-git-send-email-balbi@ti.com \
--to=balbi@ti.com \
--cc=alan@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=khilman@ti.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=santosh.shilimkar@ti.com \
--cc=shubhrajyoti@ti.com \
--cc=sourav.poddar@ti.com \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).