From patchwork Wed Apr 4 15:48:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 10322809 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 905F76053F for ; Wed, 4 Apr 2018 15:48:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80A5128DF7 for ; Wed, 4 Apr 2018 15:48:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7553128EBA; Wed, 4 Apr 2018 15:48:58 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, 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 060D128EB3 for ; Wed, 4 Apr 2018 15:48:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752014AbeDDPs5 (ORCPT ); Wed, 4 Apr 2018 11:48:57 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:33661 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752013AbeDDPs4 (ORCPT ); Wed, 4 Apr 2018 11:48:56 -0400 Received: by mail-wm0-f67.google.com with SMTP id o23so22142334wmf.0; Wed, 04 Apr 2018 08:48:55 -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; bh=2pjLdUX/wKmUGymE2WnYQRwzNnC/wb1OJCQONZVVL2Q=; b=eFsCEg6BuXa2EqnIw0+tHpPgajzVVQV0PWuw6EIjf55sD9UuFs+MJuGE9TEdRcJg3S 4n46MJ1sCe7AgvtA9LZWPuFSs69s964e02Rs+/FlEeHdtf5+wBqvzbTulQDIwSQGr5TT cjhU/O0tF9WC3mX3jTIMdBEzG8Qihj7M0APoXLMazyTRPh2iFRvG9Se3k7CFbADpoSh4 Azs3Co11xn7TowtQM/A/RLwELhEYeEGVIxuaIqwTWaGlf0ngnsqPA3QJmB0LkkSCH8rq BtEv+v9AM+Gm3OBbJJWPFBWRou7HaOCQ57qN3M5pZQPF6IPhpNe7ZwpHdad7es8j9cUw F2UQ== 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; bh=2pjLdUX/wKmUGymE2WnYQRwzNnC/wb1OJCQONZVVL2Q=; b=lBdwgiczzs3Lv9bEpu+dg5kwN9MtGzn73g3PRj1NSSTY+yLR+ZMLQjJhL0SNF57f1O oJXQeM96Ie2k/eUyVUutNoje+4Yfkzu/JYbdshCw/UELQNUZDJ65PCr4SbMv4hPIJjZU XQuo7PF18XLJMybzaDkdnOiV/Y/xo2k0LIzzNF8qN3/gzP/t5hIbXdLwv42y5/E/o+dF wN3GfcAOxQuQjMD2piM2JXHtdRPBmlj6fegVmKV0xjd6eg98u2sm9m/4NoE92bTuUwNA PTcth46vyGbFPlHSlBjMnUDDUVyTC+0wgPhilA/lWdy7ia3u7D0Elc2Rv2ZhsBeV9ooY fbdw== X-Gm-Message-State: ALQs6tB18is3Ly/u7fBFvfhY2n5SdL2h7SNjVZrua4V27kgUdYDVeLqH A/Xrlfeu0qXbULeFk42HMyMKltg= X-Google-Smtp-Source: AIpwx48D4hwgqcFwHn3aqnw54XGLtV2s9FtyvvIsqUu6XCLMQXxDPWg/2lyRMNir9u0VfU6glQDeVg== X-Received: by 10.28.190.3 with SMTP id o3mr856662wmf.57.1522856934681; Wed, 04 Apr 2018 08:48:54 -0700 (PDT) Received: from groucho.site (ipbcc0ce2f.dynamic.kabel-deutschland.de. [188.192.206.47]) by smtp.gmail.com with ESMTPSA id f84sm5960747wmh.44.2018.04.04.08.48.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 04 Apr 2018 08:48:53 -0700 (PDT) From: Ulrich Hecht To: linux-renesas-soc@vger.kernel.org, wsa@the-dreams.de, geert@linux-m68k.org Cc: linux-serial@vger.kernel.org, magnus.damm@gmail.com, greg@kroah.com, Ulrich Hecht Subject: [PATCH v2] serial: sh-sci: Support for HSCIF RX sampling point adjustment Date: Wed, 4 Apr 2018 17:48:51 +0200 Message-Id: <1522856931-6225-1-git-send-email-ulrich.hecht+renesas@gmail.com> X-Mailer: git-send-email 2.7.4 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 moving the RX sampling point by between -8 and 7 sampling cycles (one sampling cycles equals 1/15 of a bit by default) to improve the error margin in case of slightly mismatched bit rates between sender and receiver. This patch tries to determine if shifting the sampling point can improve the error margin and will enable it if so. Signed-off-by: Ulrich Hecht Reviewed-by: Geert Uytterhoeven Signed-off-by: Geert Uytterhoeven Signed-off-by: Dirk Behme Signed-off-by: Dirk Behme Signed-off-by: Geert Uytterhoeven --- This revision dumps the sysfs interface and works out the optimal shift on its own. It also moves setting of the HSSRR register back to its original location. CU Uli drivers/tty/serial/sh-sci.c | 65 +++++++++++++++++++++++++++++---------------- drivers/tty/serial/sh-sci.h | 4 +++ 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index fdbbff5..5d61654 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -2390,6 +2390,27 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, uart_update_timeout(port, termios->c_cflag, baud); + /* 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 (best_clk >= 0) { if (port->type == PORT_SCIFA || port->type == PORT_SCIFB) switch (srr + 1) { @@ -2406,8 +2427,27 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, 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) - serial_port_out(port, HSSRR, srr | HSCIF_SRE); + if (sci_getreg(port, HSSRR)->size) { + unsigned int hssrr = srr | HSCIF_SRE; + /* Calculate deviation from intended rate at the + * center of the last stop bit in sampling clocks. + */ + int last_stop = bits * 2 - 1; + int deviation = min_err * srr * last_stop / 2 / baud; + + if (abs(deviation) >= 2) { + /* At least two sampling clocks off at the + * last stop bit; we can increase the error + * margin by shifting the sampling point. + */ + int shift = min(-8, max(7, deviation / 2)); + + hssrr |= (shift << HSCIF_SRHP_SHIFT) & + HSCIF_SRHP_MASK; + hssrr |= HSCIF_SRDE; + } + serial_port_out(port, HSSRR, hssrr); + } /* Wait one bit interval */ udelay((1000000 + (baud - 1)) / baud); @@ -2474,27 +2514,6 @@ 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. */ - /* 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++; - s->rx_frame = (10000 * bits) / (baud / 100); #ifdef CONFIG_SERIAL_SH_SCI_DMA s->rx_timeout = s->buf_len_rx * 2 * s->rx_frame; diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h index a5f792f..0b9e804 100644 --- a/drivers/tty/serial/sh-sci.h +++ b/drivers/tty/serial/sh-sci.h @@ -130,6 +130,10 @@ enum { /* HSSRR HSCIF */ #define HSCIF_SRE BIT(15) /* Sampling Rate Register Enable */ +#define HSCIF_SRDE BIT(14) /* Sampling Point Register Enable */ + +#define HSCIF_SRHP_SHIFT 8 +#define HSCIF_SRHP_MASK 0x0f00 /* SCPCR (Serial Port Control Register), SCIFA/SCIFB only */ #define SCPCR_RTSC BIT(4) /* Serial Port RTS# Pin / Output Pin */