From patchwork Fri Feb 3 10:38:18 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 9553859 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 4B409604E2 for ; Fri, 3 Feb 2017 10:38:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3A4D52831C for ; Fri, 3 Feb 2017 10:38:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EFD628515; Fri, 3 Feb 2017 10:38:40 +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 7AE992831C for ; Fri, 3 Feb 2017 10:38:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752253AbdBCKih (ORCPT ); Fri, 3 Feb 2017 05:38:37 -0500 Received: from mail-wj0-f196.google.com ([209.85.210.196]:33035 "EHLO mail-wj0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752219AbdBCKig (ORCPT ); Fri, 3 Feb 2017 05:38:36 -0500 Received: by mail-wj0-f196.google.com with SMTP id le4so432255wjb.0; Fri, 03 Feb 2017 02:38:34 -0800 (PST) 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=X31MftoLcHPx0P9Fw8A5UZ3A4C+EjM+NQA0rr0l160o=; b=RPcNlAb2A5emzVO37HEAVYDrffMT1wH/gc7zcUnCCkwD5yHNSsvl7dMUyPy9DUfzx/ KK9MSl7nJ/2BYNLsGNo25cRfelHw5Q/8TtyZgnkDtfZQPTRuW8fqdQiEnkMToOqOOlsI A4IpH1w2JHuWPOhvzi1WpyIvzuAv3fEF0RdWH/NHi+EWDSwArtv8hQ9yTkjVLMp5h4yW +PkANclfHTW0nbq8N0lSBLC0jggNgt4E14qE+G9LtcFnTcN7vRewLIDGNhYHguZJ9TDf joQOd2GUxXV/b44Aar1eC2S3mWALLSVj3KqInENorrg5QR6bXg9znOnw741ec9zojRMQ g6PQ== 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=X31MftoLcHPx0P9Fw8A5UZ3A4C+EjM+NQA0rr0l160o=; b=VokvcaoNSeUbJjPMcQoqFXA9zIk6fs6Ilu5HOsfJ2prhcsVJ0gnasNgyyvcorYwnTN 7y7yZxMtELjS+6H+jACo4g2+RipzoEcge9TUvWuxGyyGJg96c+eFwXiMSgubkrQfjun6 87sZuHRsbbmCDj1ZwoeRJaSAnjcZ2kfFIhnV5h1p2OvQxwGNwVO8ePJTKQ2SMU25TG+m il3eeo1pO6uw/65niJ7Ehl0YA1sNjPbUI6GUandKiV6GsHZE4w0E4llKn3kB400c/Jif zQ6z5tHOSAm+E6trsFS7XBhUR5dQdCT/5iuBb7W0+MXs4qzv3/gVbJwXy1t9YCxx4L6C cvZQ== X-Gm-Message-State: AIkVDXIQSY2xRjIF7Epf2PH9HT7vM2knigM7yt6PnziMhprIcw/7JbWkQ3ETIqBHCB0Mvg== X-Received: by 10.223.128.5 with SMTP id 5mr11581907wrk.163.1486118313717; Fri, 03 Feb 2017 02:38:33 -0800 (PST) Received: from groucho.site (ipbcc0353e.dynamic.kabel-deutschland.de. [188.192.53.62]) by smtp.gmail.com with ESMTPSA id 186sm2278913wmw.24.2017.02.03.02.38.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Feb 2017 02:38:33 -0800 (PST) From: Ulrich Hecht To: linux-renesas-soc@vger.kernel.org, geert@linux-m68k.org, gregkh@linuxfoundation.org Cc: wsa@the-dreams.de, linux-serial@vger.kernel.org, magnus.damm@gmail.com, sergei.shtylyov@cogentembedded.com, Ulrich Hecht Subject: [PATCH v4 2/4] serial: sh-sci: SCIFA/B RX FIFO software timeout Date: Fri, 3 Feb 2017 11:38:18 +0100 Message-Id: <1486118300-12633-3-git-send-email-ulrich.hecht+renesas@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1486118300-12633-1-git-send-email-ulrich.hecht+renesas@gmail.com> References: <1486118300-12633-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 Implements support for FIFO fill thresholds greater than one with software timeout. This mechanism is not possible (or at least not useful) on SCIF family hardware other than SCIFA and SCIFB because they do not support turning off the DR hardware timeout interrupt separately from the RI interrupt. Signed-off-by: Ulrich Hecht --- drivers/tty/serial/sh-sci.c | 101 +++++++++++++++++++++++++++++--------------- 1 file changed, 68 insertions(+), 33 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 520e344..4a165ed 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -148,7 +148,10 @@ struct sci_port { struct timer_list rx_timer; unsigned int rx_timeout; #endif + unsigned int rx_frame; int rx_trigger; + struct timer_list rx_fifo_timer; + int rx_fifo_timeout; bool has_rtscts; bool autorts; @@ -1034,6 +1037,24 @@ static int scif_set_rtrg(struct uart_port *port, int rx_trig) return rx_trig; } +static int scif_rtrg_enabled(struct uart_port *port) +{ + if (sci_getreg(port, HSRTRGR)->size) + return serial_port_in(port, HSRTRGR) != 0; + else + return (serial_port_in(port, SCFCR) & + (SCFCR_RTRG0 | SCFCR_RTRG1)) != 0; +} + +static void rx_fifo_timer_fn(unsigned long arg) +{ + struct sci_port *s = (struct sci_port *)arg; + struct uart_port *port = &s->port; + + dev_dbg(port->dev, "Rx timed out\n"); + scif_set_rtrg(port, 1); +} + #ifdef CONFIG_SERIAL_SH_SCI_DMA static void sci_dma_tx_complete(void *arg) { @@ -1473,10 +1494,10 @@ static inline void sci_free_dma(struct uart_port *port) static irqreturn_t sci_rx_interrupt(int irq, void *ptr) { -#ifdef CONFIG_SERIAL_SH_SCI_DMA struct uart_port *port = ptr; struct sci_port *s = to_sci_port(port); +#ifdef CONFIG_SERIAL_SH_SCI_DMA if (s->chan_rx) { u16 scr = serial_port_in(port, SCSCR); u16 ssr = serial_port_in(port, SCxSR); @@ -1501,6 +1522,14 @@ static irqreturn_t sci_rx_interrupt(int irq, void *ptr) } #endif + if (s->rx_trigger > 1 && s->rx_fifo_timeout > 0) { + if (!scif_rtrg_enabled(port)) + scif_set_rtrg(port, s->rx_trigger); + + mod_timer(&s->rx_fifo_timer, jiffies + DIV_ROUND_UP( + s->rx_frame * s->rx_fifo_timeout, 1000)); + } + /* I think sci_receive_chars has to be called irrespective * of whether the I_IXOFF is set, otherwise, how is the interrupt * to be disabled? @@ -2084,14 +2113,21 @@ static void sci_reset(struct uart_port *port) serial_port_out(port, SCLSR, status); } - if (s->rx_trigger > 1) - scif_set_rtrg(port, s->rx_trigger); + if (s->rx_trigger > 1) { + if (s->rx_fifo_timeout) { + scif_set_rtrg(port, 1); + setup_timer(&s->rx_fifo_timer, rx_fifo_timer_fn, + (unsigned long)s); + } else { + scif_set_rtrg(port, s->rx_trigger); + } + } } static void sci_set_termios(struct uart_port *port, struct ktermios *termios, struct ktermios *old) { - unsigned int baud, smr_val = SCSMR_ASYNC, scr_val = 0, i; + unsigned int baud, smr_val = SCSMR_ASYNC, scr_val = 0, i, bits; unsigned int brr = 255, cks = 0, srr = 15, dl = 0, sccks = 0; unsigned int brr1 = 255, cks1 = 0, srr1 = 15, dl1 = 0; struct sci_port *s = to_sci_port(port); @@ -2287,7 +2323,6 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, udelay(DIV_ROUND_UP(10 * 1000000, baud)); } -#ifdef CONFIG_SERIAL_SH_SCI_DMA /* * Calculate delay for 2 DMA buffers (4 FIFO). * See serial_core.c::uart_update_timeout(). @@ -2298,36 +2333,34 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, * value obtained by this formula is too small. Therefore, if the value * is smaller than 20ms, use 20ms as the timeout value for DMA. */ - if (s->chan_rx) { - unsigned int bits; + /* byte size and parity */ + switch (termios->c_cflag & CSIZE) { + case CS5: + bits = 7; + break; + case CS6: + bits = 8; + break; + case CS7: + bits = 9; + break; + default: + bits = 10; + break; + } - /* byte size and parity */ - switch (termios->c_cflag & CSIZE) { - case CS5: - bits = 7; - break; - case CS6: - bits = 8; - break; - case CS7: - bits = 9; - break; - default: - bits = 10; - break; - } + if (termios->c_cflag & CSTOPB) + bits++; + if (termios->c_cflag & PARENB) + bits++; - if (termios->c_cflag & CSTOPB) - bits++; - if (termios->c_cflag & PARENB) - bits++; - s->rx_timeout = DIV_ROUND_UP((s->buf_len_rx * 2 * bits * HZ) / - (baud / 10), 10); - dev_dbg(port->dev, "DMA Rx t-out %ums, tty t-out %u jiffies\n", - s->rx_timeout * 1000 / HZ, port->timeout); - if (s->rx_timeout < msecs_to_jiffies(20)) - s->rx_timeout = msecs_to_jiffies(20); - } + s->rx_frame = (100 * bits * HZ) / (baud / 10); +#ifdef CONFIG_SERIAL_SH_SCI_DMA + s->rx_timeout = DIV_ROUND_UP(s->buf_len_rx * 2 * s->rx_frame, 1000); + dev_dbg(port->dev, "DMA Rx t-out %ums, tty t-out %u jiffies\n", + s->rx_timeout * 1000 / HZ, port->timeout); + if (s->rx_timeout < msecs_to_jiffies(20)) + s->rx_timeout = msecs_to_jiffies(20); #endif if ((termios->c_cflag & CREAD) != 0) @@ -2642,6 +2675,8 @@ static int sci_init_single(struct platform_device *dev, break; } + sci_port->rx_fifo_timeout = 0; + /* SCIFA on sh7723 and sh7724 need a custom sampling rate that doesn't * match the SoC datasheet, this should be investigated. Let platform * data override the sampling rate for now.