From patchwork Fri Sep 29 13:08:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 9978011 X-Patchwork-Delegate: geert@linux-m68k.org Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9DC4160329 for ; Fri, 29 Sep 2017 13:09:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8CC39297D5 for ; Fri, 29 Sep 2017 13:09:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 81A82297FF; Fri, 29 Sep 2017 13:09:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 687FD297D5 for ; Fri, 29 Sep 2017 13:09:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752162AbdI2NJG (ORCPT ); Fri, 29 Sep 2017 09:09:06 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:37984 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751964AbdI2NJF (ORCPT ); Fri, 29 Sep 2017 09:09:05 -0400 Received: by mail-wr0-f194.google.com with SMTP id 45so1241597wry.5; Fri, 29 Sep 2017 06:09:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=a8PgHmPdEOCbjtWxSOgz2O1WbXBvJyGb8gZ6jRuz/R0=; b=qxCiUoUiEnoOkcyWPA4Zb54/UWE8wLCEz8L1/sEuszGxmLvwYGIQek53+dKA6DJV3W 8taVgHaMANDJu15NKAub/JAEVN9LCOTKyjWuLllLY0VyDYTPWkrM3VdYSLY8TBj0kimN oeMyouIxzxcdbf7R9hi1XPl70VwYlfTd3f0q0uXYUyJTeCrDxYgMe6TmUEb23iumxVDq p7mBjpd/RD86sihSO2jFgvlVGT7DXRqRLl4OWmri5GZo2C4olyuBQKb+l8jKgX/FxkDJ 9zCNmT9ciMEL1IPaszR79ksgwX4s91q421e/l7VHDp/Jgkf65wTSPvHU1kkh9w+Dg7az M7zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=a8PgHmPdEOCbjtWxSOgz2O1WbXBvJyGb8gZ6jRuz/R0=; b=iSXeca0LBCaT+4n6V1lyqIFx2VaEcfkhz1NEqJsZ6Lq1wIuTcXhp+NmQ4racSYyH1b hOfXbDF0y/JLO3zlml1uPPDGM0f4Hm5x3n5JTvPySVNEYsRog1qUsOZNPPkRk2yUBY8K lmg2B+n/0yS+qcvIizZvIIJ1/UWka1ZzSBCVHz/OhXi4DdFiV0dehMp3X2YEIpMWIUp5 SjPA8BwsZkIv+EBvJ56xK2Jip7xmfdBXtsXR7m4zE8jgr6LzVRPhnj0TrBNvQMcNn2/F UJL/D9Ph1hcFwL+uRudh8/gB/6dqCYKV0ZUx+TheCh1wSXmllblo+rmQas/Y+Gu4TAOw BwFw== X-Gm-Message-State: AHPjjUjIo8lUI8O3aCMql4hox1t+EfbaEcovJsERKM7SekrLkKzTSc3N GrCGHHBrG8iPh3xbhOzt1lmAT1k= X-Google-Smtp-Source: AOwi7QA4CtFHbVUW15yLEyUOfBNv2DkTLXc39TMp6poCEZoZM3XLcGBryqjs4YtHvw5P55Di1AUwvQ== X-Received: by 10.223.199.15 with SMTP id k15mr6536992wrg.111.1506690543522; Fri, 29 Sep 2017 06:09:03 -0700 (PDT) Received: from groucho.site (ipbcc0ce42.dynamic.kabel-deutschland.de. [188.192.206.66]) by smtp.gmail.com with ESMTPSA id 6sm4551044wru.33.2017.09.29.06.09.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Sep 2017 06:09:02 -0700 (PDT) From: Ulrich Hecht To: linux-renesas-soc@vger.kernel.org, geert@linux-m68k.org Cc: wsa@the-dreams.de, linux-serial@vger.kernel.org, magnus.damm@gmail.com, Ulrich Hecht Subject: [PATCH 1/2] serial: sh-sci: Support for variable HSCIF hardware RX timeout Date: Fri, 29 Sep 2017 15:08:53 +0200 Message-Id: <1506690534-27302-2-git-send-email-ulrich.hecht+renesas@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506690534-27302-1-git-send-email-ulrich.hecht+renesas@gmail.com> References: <1506690534-27302-1-git-send-email-ulrich.hecht+renesas@gmail.com> Sender: linux-renesas-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP HSCIF has facilities that allow changing the timeout after which an RX interrupt is triggered even if the FIFO is not filled. This patch allows changing the default (15 bits of silence) using the existing sysfs attribute "rx_fifo_timeout". Signed-off-by: Ulrich Hecht Reviewed-by: Geert Uytterhoeven --- drivers/tty/serial/sh-sci.c | 52 ++++++++++++++++++++++++++++++++------------- drivers/tty/serial/sh-sci.h | 3 +++ 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 784dd42..41bf910 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -152,6 +152,7 @@ struct sci_port { int rx_trigger; struct timer_list rx_fifo_timer; int rx_fifo_timeout; + u16 hscif_tot; bool has_rtscts; bool autorts; @@ -1107,8 +1108,14 @@ static ssize_t rx_fifo_timeout_show(struct device *dev, { struct uart_port *port = dev_get_drvdata(dev); struct sci_port *sci = to_sci_port(port); + int v; - return sprintf(buf, "%d\n", sci->rx_fifo_timeout); + if (port->type == PORT_HSCIF) + v = sci->hscif_tot >> HSSCR_TOT_SHIFT; + else + v = sci->rx_fifo_timeout; + + return sprintf(buf, "%d\n", v); } static ssize_t rx_fifo_timeout_store(struct device *dev, @@ -1124,11 +1131,19 @@ static ssize_t rx_fifo_timeout_store(struct device *dev, ret = kstrtol(buf, 0, &r); if (ret) return ret; - sci->rx_fifo_timeout = r; - scif_set_rtrg(port, 1); - if (r > 0) - setup_timer(&sci->rx_fifo_timer, rx_fifo_timer_fn, - (unsigned long)sci); + + if (port->type == PORT_HSCIF) { + if (r < 0 || r > 3) + return -EINVAL; + sci->hscif_tot = r << HSSCR_TOT_SHIFT; + } else { + sci->rx_fifo_timeout = r; + scif_set_rtrg(port, 1); + if (r > 0) + setup_timer(&sci->rx_fifo_timer, rx_fifo_timer_fn, + (unsigned long)sci); + } + return count; } @@ -2037,9 +2052,13 @@ static void sci_shutdown(struct uart_port *port) spin_lock_irqsave(&port->lock, flags); sci_stop_rx(port); sci_stop_tx(port); - /* Stop RX and TX, disable related interrupts, keep clock source */ + /* + * Stop RX and TX, disable related interrupts, keep clock source + * and HSCIF TOT bits + */ scr = serial_port_in(port, SCSCR); - serial_port_out(port, SCSCR, scr & (SCSCR_CKE1 | SCSCR_CKE0)); + serial_port_out(port, SCSCR, scr & + (SCSCR_CKE1 | SCSCR_CKE0 | s->hscif_tot)); spin_unlock_irqrestore(&port->lock, flags); #ifdef CONFIG_SERIAL_SH_SCI_DMA @@ -2186,7 +2205,7 @@ static void sci_reset(struct uart_port *port) unsigned int status; struct sci_port *s = to_sci_port(port); - serial_port_out(port, SCSCR, 0x00); /* TE=0, RE=0, CKE1=0 */ + serial_port_out(port, SCSCR, s->hscif_tot); /* TE=0, RE=0, CKE1=0 */ reg = sci_getreg(port, SCFCR); if (reg->size) @@ -2356,7 +2375,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, dev_dbg(port->dev, "SCR 0x%x SMR 0x%x BRR %u CKS 0x%x DL %u SRR %u\n", scr_val, smr_val, brr, sccks, dl, srr); - serial_port_out(port, SCSCR, scr_val); + serial_port_out(port, SCSCR, scr_val | s->hscif_tot); serial_port_out(port, SCSMR, smr_val); serial_port_out(port, SCBRR, brr); if (sci_getreg(port, HSSRR)->size) @@ -2370,7 +2389,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, smr_val |= serial_port_in(port, SCSMR) & (SCSMR_CKEDG | SCSMR_SRC_MASK | SCSMR_CKS); dev_dbg(port->dev, "SCR 0x%x SMR 0x%x\n", scr_val, smr_val); - serial_port_out(port, SCSCR, scr_val); + serial_port_out(port, SCSCR, scr_val | s->hscif_tot); serial_port_out(port, SCSMR, smr_val); } @@ -2407,7 +2426,7 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, scr_val |= SCSCR_RE | SCSCR_TE | (s->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)); dev_dbg(port->dev, "SCSCR 0x%x\n", scr_val); - serial_port_out(port, SCSCR, scr_val); + serial_port_out(port, SCSCR, scr_val | s->hscif_tot); if ((srr + 1 == 5) && (port->type == PORT_SCIFA || port->type == PORT_SCIFB)) { /* @@ -2773,6 +2792,7 @@ static int sci_init_single(struct platform_device *dev, } sci_port->rx_fifo_timeout = 0; + sci_port->hscif_tot = 0; /* SCIFA on sh7723 and sh7724 need a custom sampling rate that doesn't * match the SoC datasheet, this should be investigated. Let platform @@ -2860,7 +2880,7 @@ static void serial_console_write(struct console *co, const char *s, ctrl_temp = SCSCR_RE | SCSCR_TE | (sci_port->cfg->scscr & ~(SCSCR_CKE1 | SCSCR_CKE0)) | (ctrl & (SCSCR_CKE1 | SCSCR_CKE0)); - serial_port_out(port, SCSCR, ctrl_temp); + serial_port_out(port, SCSCR, ctrl_temp | sci_port->hscif_tot); uart_console_write(port, s, count, serial_console_putchar); @@ -2988,7 +3008,8 @@ static int sci_remove(struct platform_device *dev) sysfs_remove_file(&dev->dev.kobj, &dev_attr_rx_fifo_trigger.attr); } - if (port->port.type == PORT_SCIFA || port->port.type == PORT_SCIFB) { + if (port->port.type == PORT_SCIFA || port->port.type == PORT_SCIFB || + port->port.type == PORT_HSCIF) { sysfs_remove_file(&dev->dev.kobj, &dev_attr_rx_fifo_timeout.attr); } @@ -3173,7 +3194,8 @@ static int sci_probe(struct platform_device *dev) if (ret) return ret; } - if (sp->port.type == PORT_SCIFA || sp->port.type == PORT_SCIFB) { + if (sp->port.type == PORT_SCIFA || sp->port.type == PORT_SCIFB || + sp->port.type == PORT_HSCIF) { ret = sysfs_create_file(&dev->dev.kobj, &dev_attr_rx_fifo_timeout.attr); if (ret) { diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h index 971b2ab..2b708cc 100644 --- a/drivers/tty/serial/sh-sci.h +++ b/drivers/tty/serial/sh-sci.h @@ -62,6 +62,9 @@ enum { #define SCSCR_TDRQE BIT(15) /* Tx Data Transfer Request Enable */ #define SCSCR_RDRQE BIT(14) /* Rx Data Transfer Request Enable */ +/* Serial Control Register, HSCIF-only bits */ +#define HSSCR_TOT_SHIFT 14 + /* SCxSR (Serial Status Register) on SCI */ #define SCI_TDRE BIT(7) /* Transmit Data Register Empty */ #define SCI_RDRF BIT(6) /* Receive Data Register Full */