Linux Samsung SOC development
 help / color / mirror / Atom feed
From: Youngmin Nam <ym0914@gmail.com>
To: gregkh@linuxfoundation.org, k.kozlowski@samsung.com
Cc: linux-serial@vger.kernel.org, linux-samsung-soc@vger.kernel.org,
	Youngmin Nam <ym0914@gmail.com>
Subject: [PATCH] serial: samsung: optimize UART rx fifo access routine
Date: Sat,  5 Mar 2016 19:36:32 +0900	[thread overview]
Message-ID: <1457174192-20956-1-git-send-email-ym0914@gmail.com> (raw)

This patch optimizes UART rx fifo access routine by reading UART SFR
when necessary. At first, the "fifocnt" variable will be initialized
as Rx FIFO count. So we don't need to access UFSTAT(FIFO status) register
every time to check FIFO count because we know that count with "fifocnt".
After all data were read out from Rx FIFO, the "fifocnt" will be set as 0.
Lastly, UFSTAT will be accessed again to check whether the data remains
by any chance.

Signed-off-by: Youngmin Nam <ym0914@gmail.com>
Reviewed-by: Jung-Ick Guack <ji.guack@samsung.com>
---
 drivers/tty/serial/samsung.c | 18 +++++++++++++-----
 1 file changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
index d72cd73..1fd09c0 100644
--- a/drivers/tty/serial/samsung.c
+++ b/drivers/tty/serial/samsung.c
@@ -601,14 +601,21 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport)
 {
 	struct uart_port *port = &ourport->port;
 	unsigned int ufcon, ch, flag, ufstat, uerstat;
+	unsigned int fifocnt = 0;
 	int max_count = port->fifosize;
 
 	while (max_count-- > 0) {
-		ufcon = rd_regl(port, S3C2410_UFCON);
-		ufstat = rd_regl(port, S3C2410_UFSTAT);
-
-		if (s3c24xx_serial_rx_fifocnt(ourport, ufstat) == 0)
-			break;
+		/*
+		 * Receive all characters known to be in FIFO
+		 * before reading FIFO level again
+		 */
+		if (fifocnt == 0) {
+			ufstat = rd_regl(port, S3C2410_UFSTAT);
+			fifocnt = s3c24xx_serial_rx_fifocnt(ourport, ufstat);
+			if (fifocnt == 0)
+				break;
+		}
+		fifocnt--;
 
 		uerstat = rd_regl(port, S3C2410_UERSTAT);
 		ch = rd_regb(port, S3C2410_URXH);
@@ -623,6 +630,7 @@ static void s3c24xx_serial_rx_drain_fifo(struct s3c24xx_uart_port *ourport)
 				}
 			} else {
 				if (txe) {
+					ufcon = rd_regl(port, S3C2410_UFCON);
 					ufcon |= S3C2410_UFCON_RESETRX;
 					wr_regl(port, S3C2410_UFCON, ufcon);
 					rx_enabled(port) = 1;
-- 
2.7.1

                 reply	other threads:[~2016-03-05 10:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1457174192-20956-1-git-send-email-ym0914@gmail.com \
    --to=ym0914@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=k.kozlowski@samsung.com \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /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