From patchwork Fri Sep 12 08:51:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 4892791 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 44CD39F40F for ; Fri, 12 Sep 2014 08:47:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3AE852012E for ; Fri, 12 Sep 2014 08:52:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C40502024F for ; Fri, 12 Sep 2014 08:52:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753068AbaILIwF (ORCPT ); Fri, 12 Sep 2014 04:52:05 -0400 Received: from mail-la0-f44.google.com ([209.85.215.44]:33971 "EHLO mail-la0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753002AbaILIwD (ORCPT ); Fri, 12 Sep 2014 04:52:03 -0400 Received: by mail-la0-f44.google.com with SMTP id mc6so501740lab.31 for ; Fri, 12 Sep 2014 01:52:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=XzKd+0T9+UJCPBZBgnkrcUL7BoTU2T6ISrGj5T36OBM=; b=Ko1nFBWKB840dgsDhx9Ck4+Ge539hAteRsgSGYH3alcaYIhiqersp/ISFbtV2AD/qh QepvT7OH5yPwjVjHJFp2JDjdDIIsMukBYfGf2+fRYpwwA9gjrdJRtBJ4mUReHxk8qcIj AMda0wN3qRl6s0xe75KbHn8e7d4qzeIN/jLL9eWwSKhRIHtGPfeQegh2l7NRMkvkxZGs 8AQtkWO1JSuf6F9bqp9AgX5YlU97Tpu+1gL2oNPxYCB5otyc1fy9XJeap7BEzqST550i j2XP2OpYYzQxxITJu7v3qpJtvBnsaaTuBA0d3URu/n9JhYksJ1CouilsQnR4JLlBSGCK jJ1A== X-Received: by 10.112.17.2 with SMTP id k2mr6946807lbd.28.1410511921600; Fri, 12 Sep 2014 01:52:01 -0700 (PDT) Received: from groucho.site ([185.3.135.58]) by mx.google.com with ESMTPSA id cm9sm1107745lbb.39.2014.09.12.01.51.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Sep 2014 01:52:00 -0700 (PDT) From: Ulrich Hecht To: linux-sh@vger.kernel.org, linux-serial@vger.kernel.org Cc: horms@verge.net.au, magnus.damm@gmail.com, Ulrich Hecht Subject: [RFC 2/3] serial: sh-sci: exploit RX FIFOs better Date: Fri, 12 Sep 2014 10:51:47 +0200 Message-Id: <1410511908-9282-3-git-send-email-ulrich.hecht+renesas@gmail.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1410511908-9282-1-git-send-email-ulrich.hecht+renesas@gmail.com> References: <1410511908-9282-1-git-send-email-ulrich.hecht+renesas@gmail.com> Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-8.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SBL, RP_MATCHES_RCVD, T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Trigger interrupts at higher FIFO fill levels to reduce load. Signed-off-by: Ulrich Hecht --- drivers/tty/serial/sh-sci.c | 68 +++++++++++++++++++++++++++++++++++++++++++++ drivers/tty/serial/sh-sci.h | 4 +++ include/linux/serial_sci.h | 2 ++ 3 files changed, 74 insertions(+) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index f0ff8a7..78aeec1 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -120,6 +120,7 @@ struct sci_port { #endif struct notifier_block freq_transition; + int rx_trigger; }; /* Function prototypes */ @@ -303,6 +304,8 @@ static struct plat_sci_reg sci_regmap[SCIx_NR_REGTYPES][SCIx_NR_REGS] = { [SCSPTR] = { 0x20, 16 }, [SCLSR] = { 0x24, 16 }, [HSSRR] = { 0x40, 16 }, + [HSRTRGR] = { 0x54, 16 }, + [HSTTRGR] = { 0x58, 16 }, }, /* @@ -1854,6 +1857,62 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, } } +/* Set Rx FIFO interrupt trigger level after clamping it to a supported + * value. + */ +static void scif_set_rtrg(struct uart_port *port) +{ + unsigned int bits; + struct sci_port *sci = to_sci_port(port); + + if (sci->rx_trigger < 1) + sci->rx_trigger = 1; + if (sci->rx_trigger >= port->fifosize) + sci->rx_trigger = port->fifosize; + + /* HSCIF can be set to an arbitrary level. */ + if (sci_getreg(port, HSRTRGR)->size) { + serial_port_out(port, HSRTRGR, sci->rx_trigger); + return; + } + + if (port->fifosize == 16) { + /* SCIF */ + if (sci->rx_trigger < 4) { + bits = 0; + sci->rx_trigger = 1; + } else if (sci->rx_trigger < 8) { + bits = SCFCR_RTRG0; + sci->rx_trigger = 4; + } else if (sci->rx_trigger < 14) { + bits = SCFCR_RTRG1; + sci->rx_trigger = 8; + } else { + bits = SCFCR_RTRG0 | SCFCR_RTRG1; + sci->rx_trigger = 14; + } + } else if (port->fifosize == 64 || port->fifosize == 256) { + /* SCIFA/B */ + if (sci->rx_trigger < 16) { + bits = 0; + sci->rx_trigger = 1; + } else if (sci->rx_trigger < 32) { + bits = SCFCR_RTRG0; + sci->rx_trigger = 16; + } else if (sci->rx_trigger < 48) { + bits = SCFCR_RTRG1; + sci->rx_trigger = 32; + } else { + bits = SCFCR_RTRG0 | SCFCR_RTRG1; + sci->rx_trigger = 48; + } + } else { + BUG(); + } + + serial_port_out(port, SCFCR, serial_port_in(port, SCFCR) | bits); +} + static void sci_reset(struct uart_port *port) { struct plat_sci_reg *reg; @@ -1868,6 +1927,10 @@ static void sci_reset(struct uart_port *port) reg = sci_getreg(port, SCFCR); if (reg->size) serial_port_out(port, SCFCR, SCFCR_RFRST | SCFCR_TFRST); + + if (port->fifosize > 1) { + scif_set_rtrg(port); + } } static void sci_set_termios(struct uart_port *port, struct ktermios *termios, @@ -2180,21 +2243,25 @@ static int sci_init_single(struct platform_device *dev, switch (p->type) { case PORT_SCIFB: port->fifosize = 256; + sci_port->rx_trigger = 48; sci_port->overrun_bit = 9; sampling_rate = 16; break; case PORT_HSCIF: port->fifosize = 128; sampling_rate = 0; + sci_port->rx_trigger = 64; sci_port->overrun_bit = 0; break; case PORT_SCIFA: port->fifosize = 64; + sci_port->rx_trigger = 32; sci_port->overrun_bit = 9; sampling_rate = 16; break; case PORT_SCIF: port->fifosize = 16; + sci_port->rx_trigger = 8; if (p->regtype == SCIx_SH7705_SCIF_REGTYPE) { sci_port->overrun_bit = 9; sampling_rate = 16; @@ -2205,6 +2272,7 @@ static int sci_init_single(struct platform_device *dev, break; default: port->fifosize = 1; + sci_port->rx_trigger = 1; sci_port->overrun_bit = 5; sampling_rate = 32; break; diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h index 9c4598d..db89635 100644 --- a/drivers/tty/serial/sh-sci.h +++ b/drivers/tty/serial/sh-sci.h @@ -34,6 +34,10 @@ #define SCFCR_RFRST 0x0002 #define SCFCR_TFRST 0x0004 #define SCFCR_MCE 0x0008 +#define SCFCR_TTRG0 0x0010 +#define SCFCR_TTRG1 0x0020 +#define SCFCR_RTRG0 0x0040 +#define SCFCR_RTRG1 0x0080 #define SCI_MAJOR 204 #define SCI_MINOR_START 8 diff --git a/include/linux/serial_sci.h b/include/linux/serial_sci.h index 6c5e3bb..95f3a04 100644 --- a/include/linux/serial_sci.h +++ b/include/linux/serial_sci.h @@ -100,6 +100,8 @@ enum { SCRFDR, /* Receive FIFO Data Count Register */ SCSPTR, /* Serial Port Register */ HSSRR, /* Sampling Rate Register */ + HSRTRGR, /* Receive FIFO data count trigger */ + HSTTRGR, /* Transmit FIFO data count trigger */ SCIx_NR_REGS, };