linux-serial.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@suse.de>
To: linux-serial@vger.kernel.org
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Alan Cox <alan@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [PATCH 40/79] max3110: add sysrq support
Date: Wed, 26 Oct 2011 14:12:45 +0200	[thread overview]
Message-ID: <1319631204-23262-40-git-send-email-gregkh@suse.de> (raw)
In-Reply-To: <1319631204-23262-1-git-send-email-gregkh@suse.de>

From: Alexander Shishkin <alexander.shishkin@linux.intel.com>

This patch moves several occurences of similar code inside receive_chars(),
which now also takes care of checking for break and calling sysrq handling
code.

Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Alan Cox <alan@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
---
 drivers/tty/serial/mrst_max3110.c |   99 ++++++++++++++++---------------------
 drivers/tty/serial/mrst_max3110.h |    1 +
 2 files changed, 44 insertions(+), 56 deletions(-)

diff --git a/drivers/tty/serial/mrst_max3110.c b/drivers/tty/serial/mrst_max3110.c
index c8f9868..42aa439 100644
--- a/drivers/tty/serial/mrst_max3110.c
+++ b/drivers/tty/serial/mrst_max3110.c
@@ -27,6 +27,10 @@
  *    interrupt for a low speed UART device
  */
 
+#ifdef CONFIG_MAGIC_SYSRQ
+#define SUPPORT_SYSRQ
+#endif
+
 #include <linux/module.h>
 #include <linux/ioport.h>
 #include <linux/irq.h>
@@ -73,9 +77,9 @@ struct uart_max3110 {
 /* global data structure, may need be removed */
 static struct uart_max3110 *pmax;
 
-static void receive_chars(struct uart_max3110 *max,
-				unsigned char *str, int len);
-static int max3110_read_multi(struct uart_max3110 *max, u8 *buf);
+static int receive_chars(struct uart_max3110 *max,
+				unsigned short *str, int len);
+static int max3110_read_multi(struct uart_max3110 *max);
 static void max3110_con_receive(struct uart_max3110 *max);
 
 static int max3110_write_then_read(struct uart_max3110 *max,
@@ -108,7 +112,6 @@ static int max3110_out(struct uart_max3110 *max, const u16 out)
 {
 	void *buf;
 	u16 *obuf, *ibuf;
-	u8  ch;
 	int ret;
 
 	buf = kzalloc(8, GFP_KERNEL | GFP_DMA);
@@ -125,11 +128,7 @@ static int max3110_out(struct uart_max3110 *max, const u16 out)
 		goto exit;
 	}
 
-	/* If some valid data is read back */
-	if (*ibuf & MAX3110_READ_DATA_AVAILABLE) {
-		ch = *ibuf & 0xff;
-		receive_chars(max, &ch, 1);
-	}
+	receive_chars(max, ibuf, 1);
 
 exit:
 	kfree(buf);
@@ -142,12 +141,11 @@ exit:
  *
  * Return how many valide bytes are read back
  */
-static int max3110_read_multi(struct uart_max3110 *max, u8 *rxbuf)
+static int max3110_read_multi(struct uart_max3110 *max)
 {
 	void *buf;
 	u16 *obuf, *ibuf;
-	u8 *pbuf, valid_str[M3110_RX_FIFO_DEPTH];
-	int i, j, blen;
+	int ret, blen;
 
 	blen = M3110_RX_FIFO_DEPTH * sizeof(u16);
 	buf = kzalloc(blen * 2, GFP_KERNEL | GFP_DMA);
@@ -165,19 +163,10 @@ static int max3110_read_multi(struct uart_max3110 *max, u8 *rxbuf)
 		return 0;
 	}
 
-	/* If caller doesn't provide a buffer, then handle received char */
-	pbuf = rxbuf ? rxbuf : valid_str;
-
-	for (i = 0, j = 0; i < M3110_RX_FIFO_DEPTH; i++) {
-		if (ibuf[i] & MAX3110_READ_DATA_AVAILABLE)
-			pbuf[j++] = ibuf[i] & 0xff;
-	}
-
-	if (j && (pbuf == valid_str))
-		receive_chars(max, valid_str, j);
+	ret = receive_chars(max, ibuf, M3110_RX_FIFO_DEPTH);
 
 	kfree(buf);
-	return j;
+	return ret;
 }
 
 static void serial_m3110_con_putchar(struct uart_port *port, int ch)
@@ -276,8 +265,7 @@ static void send_circ_buf(struct uart_max3110 *max,
 {
 	void *buf;
 	u16 *obuf, *ibuf;
-	u8 valid_str[WORDS_PER_XFER];
-	int i, j, len, blen, dma_size, left, ret = 0;
+	int i, len, blen, dma_size, left, ret = 0;
 
 
 	dma_size = WORDS_PER_XFER * sizeof(u16) * 2;
@@ -307,13 +295,7 @@ static void send_circ_buf(struct uart_max3110 *max,
 				pr_warning(PR_FMT "%s(): get err msg %d\n",
 						__func__, ret);
 
-			for (i = 0, j = 0; i < len; i++) {
-				if (ibuf[i] & MAX3110_READ_DATA_AVAILABLE)
-					valid_str[j++] = ibuf[i] & 0xff;
-			}
-
-			if (j)
-				receive_chars(max, valid_str, j);
+			receive_chars(max, ibuf, len);
 
 			max->port.icount.tx += len;
 			left -= len;
@@ -353,30 +335,48 @@ static void serial_m3110_start_tx(struct uart_port *port)
 		wake_up(&max->wq);
 }
 
-static void receive_chars(struct uart_max3110 *max, unsigned char *str, int len)
+static int
+receive_chars(struct uart_max3110 *max, unsigned short *str, int len)
 {
 	struct uart_port *port = &max->port;
 	struct tty_struct *tty;
-	int usable;
+	char buf[M3110_RX_FIFO_DEPTH];
+	int r, w, usable;
 
 	/* If uart is not opened, just return */
 	if (!port->state)
-		return;
+		return 0;
 
 	tty = port->state->port.tty;
 	if (!tty)
-		return;
+		return 0;
+
+	for (r = 0, w = 0; r < len; r++) {
+		if (str[r] & MAX3110_BREAK &&
+		    uart_handle_break(port))
+			continue;
+
+		if (str[r] & MAX3110_READ_DATA_AVAILABLE) {
+			if (uart_handle_sysrq_char(port, str[r] & 0xff))
+				continue;
+
+			buf[w++] = str[r] & 0xff;
+		}
+	}
 
-	while (len) {
-		usable = tty_buffer_request_room(tty, len);
+	if (!w)
+		return 0;
+
+	for (r = 0; w; r += usable, w -= usable) {
+		usable = tty_buffer_request_room(tty, w);
 		if (usable) {
-			tty_insert_flip_string(tty, str, usable);
-			str += usable;
+			tty_insert_flip_string(tty, buf + r, usable);
 			port->icount.rx += usable;
 		}
-		len -= usable;
 	}
 	tty_flip_buffer_push(tty);
+
+	return r;
 }
 
 /*
@@ -391,28 +391,15 @@ static void receive_chars(struct uart_max3110 *max, unsigned char *str, int len)
  */
 static void max3110_con_receive(struct uart_max3110 *max)
 {
-	int loop = 1, num, total = 0;
-	u8 recv_buf[512], *pbuf;
+	int loop = 1, num;
 
-	pbuf = recv_buf;
 	do {
-		num = max3110_read_multi(max, pbuf);
+		num = max3110_read_multi(max);
 
 		if (num) {
 			loop = 5;
-			pbuf += num;
-			total += num;
-
-			if (total >= 504) {
-				receive_chars(max, recv_buf, total);
-				pbuf = recv_buf;
-				total = 0;
-			}
 		}
 	} while (--loop);
-
-	if (total)
-		receive_chars(max, recv_buf, total);
 }
 
 static int max3110_main_thread(void *_max)
diff --git a/drivers/tty/serial/mrst_max3110.h b/drivers/tty/serial/mrst_max3110.h
index c37ea48..35af073 100644
--- a/drivers/tty/serial/mrst_max3110.h
+++ b/drivers/tty/serial/mrst_max3110.h
@@ -7,6 +7,7 @@
 /* status bits for all 4 MAX3110 operate modes */
 #define MAX3110_READ_DATA_AVAILABLE	(1 << 15)
 #define MAX3110_WRITE_BUF_EMPTY		(1 << 14)
+#define MAX3110_BREAK			(1 << 10)
 
 #define WC_TAG			(3 << 14)
 #define RC_TAG			(1 << 14)
-- 
1.7.7


  parent reply	other threads:[~2011-10-26 12:13 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-26 11:42 [GIT PATCH] TTY/serial driver patches for 3.2 Greg KH
2011-10-26 12:12 ` [PATCH 01/79] tty/powerpc: introduce the ePAPR embedded hypervisor byte channel driver Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 02/79] drivers/tty/synclink: remove double comment Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 03/79] TTY: serial, remove BTM from wait_until_sent Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 04/79] TTY: msm_serial, remove unneeded console set Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 05/79] TTY: serial, remove tasklet for tty_wakeup Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 06/79] TTY: ami_serial, remove BTM from wait_until_sent Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 07/79] TTY: remove tty_locked Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 08/79] TTY: mxser+cyclades remove wait_until_sent debug code Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 09/79] serial:blackfin: Correct coding style in bfin serial driver Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 10/79] serial:blackfin: rename Blackfin serial driver to bfin_uart.c Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 11/79] tty: clearify structure initializer in notify_write() Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 12/79] serial:bfin_uart: Put TX IRQ in individual platform resource Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 13/79] serial: samsung: Add unified interrupt handler for s3c64xx and later SoC's Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 14/79] ARM: SAMSUNG: Remove uart irq handling from plaform code Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 15/79] tty: serial: allow ports to override the irq handler Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 16/79] tty: serial8250: allow platforms to override " Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 17/79] mips: msp71xx/serial: convert to pr_foo() helpers Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 18/79] mips: msp71xx/serial: add workaround for DW UART Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 19/79] tty: serial8250: remove UPIO_DWAPB{,32} Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 20/79] tty: serial8250: add helpers for the DesignWare 8250 Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 21/79] tty: of_serial: add support " Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 22/79] Revert "tty: of_serial: add support for the DesignWare 8250" Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 23/79] Revert "tty: serial8250: add helpers " Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 24/79] serial/imx: support to handle break character Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 25/79] atmel_serial: RS485: receiving enabled when sending data Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 26/79] tty: Add support serial for EXYNOS4212 SoC Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 27/79] jsm: remove remaining flip buffer code Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 28/79] jsm: remove buggy write queue Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 29/79] jsm: print byte we are dequeing Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 30/79] TTY: serial, use ASYNCB_CLOSING in uart_close Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 31/79] TTY: serial, move locking " Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 32/79] TTY: define tty_wait_until_sent_from_close Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 33/79] TTY: use tty_wait_until_sent_from_close in tty_port_close_start Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 34/79] TTY: use tty_wait_until_sent_from_close in other drivers Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 35/79] hsu: add runtime pm support Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 36/79] n_gsm: update TODO list Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 37/79] n_gsm: Send CLD command on exit Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 38/79] max3110: wake up fixes Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 39/79] x86/mrst: Add platform data for Max3110 devices Greg Kroah-Hartman
2011-10-26 12:12   ` Greg Kroah-Hartman [this message]
2011-10-26 12:12   ` [PATCH 41/79] max3110: Fix up port->tty backreferencing Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 42/79] tty/powerpc: fix build break with ehv_bytechan.c on allyesconfig Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 43/79] tty: 8250: export serial8250_handle_irq Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 44/79] tty: add a DesignWare 8250 driver Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 45/79] serial: pxa: work around for errata #20 Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 46/79] TTY: serial: Move mutex_unlock in uart_close function Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 47/79] TTY: serial, remove dead code from 68328 Greg Kroah-Hartman
2011-10-26 12:26     ` Geert Uytterhoeven
2011-10-26 12:12   ` [PATCH 48/79] TTY: serial, fix includes in some drivers Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 49/79] cris: fix a build error in drivers/tty/serial/crisv10.c Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 50/79] serial: Support the EFR-register of XR1715x uarts Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 51/79] cris: lower the printk level in cris serial driver Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 52/79] TTY: serial, move 68360 driver to staging Greg Kroah-Hartman
2011-10-26 12:27     ` Geert Uytterhoeven
2011-10-26 12:12   ` [PATCH 53/79] keyboard: Do not include <linux/irq.> Greg Kroah-Hartman
2011-10-26 12:12   ` [PATCH 54/79] serial: mfd: Initconst section fixes Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 55/79] serial-core: power up uart port early before we do set_termios when resuming Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 56/79] TTY: irq: Remove IRQF_DISABLED Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 57/79] drivers/tty: don't use the byte channel handle as a parameter in ehv_bytechan.c Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 58/79] tty/n_gsm: fix bug in tiocmset Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 59/79] 8250: ratelimit LSR safety check engaged warning Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 60/79] tty/n_gsm: fix a bug in gsm_dlci_data_output (adaption = 2 case) Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 61/79] tty/n_gsm: avoid fifo overflow in gsm_dlci_data_output Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 62/79] TTY: snyclinkmp: forever loop in tx_load_dma_buffer() Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 63/79] hvc_console: display printk messages on console Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 64/79] tty: Support compat_ioctl get/set termios_locked Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 65/79] parport_pc: release IO region properly if unsupported ITE887x card is found Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 66/79] h8300: drivers/serial/Kconfig was moved Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 67/79] 8250_pci: Fix kernel panic when pch_uart is disabled Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 68/79] TTY: drop driver reference in tty_open fail path Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 69/79] TTY: make tty_add_file non-failing Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 70/79] TTY: pty, release tty in all ptmx_open fail paths Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 71/79] TTY: call tty_driver_lookup_tty unconditionally Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 72/79] tty/serial: RS485 bindings for device tree Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 73/79] tty/serial: atmel_serial: change platform_data variable name Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 74/79] tty/serial: atmel_serial: whitespace and braces modifications Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 75/79] tty/serial: atmel_serial: auto-enumerate ports Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 76/79] tty/serial: atmel_serial: add device tree support Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 77/79] Revert "TTY: call tty_driver_lookup_tty unconditionally" Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 78/79] tty/serial: atmel_serial: bootconsole removed from auto-enumerates Greg Kroah-Hartman
2011-10-26 12:13   ` [PATCH 79/79] TTY: serial_core: Fix crash if DCD drop during suspend Greg Kroah-Hartman
2011-10-26 13:18 ` [GIT PATCH] TTY/serial driver patches for 3.2 Linus Torvalds
2011-10-26 13:34   ` Greg KH
2011-10-26 14:16     ` Domenico Andreoli
2011-10-26 21:38       ` Jiri Kosina
2011-10-26 15:01     ` Nicolas Ferre

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=1319631204-23262-40-git-send-email-gregkh@suse.de \
    --to=gregkh@suse.de \
    --cc=alan@linux.intel.com \
    --cc=alexander.shishkin@linux.intel.com \
    --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;
as well as URLs for NNTP newsgroup(s).