From patchwork Fri Sep 29 13:08:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulrich Hecht X-Patchwork-Id: 9978013 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 35A1260329 for ; Fri, 29 Sep 2017 13:09:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2522C297D5 for ; Fri, 29 Sep 2017 13:09:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19D4B297FF; Fri, 29 Sep 2017 13:09:09 +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 A9874297D5 for ; Fri, 29 Sep 2017 13:09:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752161AbdI2NJI (ORCPT ); Fri, 29 Sep 2017 09:09:08 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:55777 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751456AbdI2NJG (ORCPT ); Fri, 29 Sep 2017 09:09:06 -0400 Received: by mail-wm0-f65.google.com with SMTP id u138so3154925wmu.4; Fri, 29 Sep 2017 06:09:06 -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=iN5IGMOLRPo6POE2De0e45NOb+gN2b2wmniGDH4l6fI=; b=FRiUhzEQw329mkKOT0ejvnfxd9RgQ7gfKfWzceIeNTvfYsGyskSEitYf+/eKQS26L/ 3rsG76ypWFYVwWjavRCAdRuy01iGTgQSA+tQWvqt2cTeQQrOt0Z94Yfdiz5NS8KtsuFT Cs8hpTozs0jOTDS5XWvF0cdCXSmUkMwW4SC0BDZ37pRqL84v7MMhGG0giAygXkzb3w0J HVmzYqZE+PYjgIkpKOwLQb4n9tGg3vIHxzO1BMq04lO3tRjstzlWmzJ/8WSeKAoRuW1d he2HNRAxRmu/3r8Ir5Jn9bGSm58nZjdGUMLapPTB/uzUYycokh7i3Z8ufA5UTJc40yi/ 6aVA== 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=iN5IGMOLRPo6POE2De0e45NOb+gN2b2wmniGDH4l6fI=; b=QFFp+n0UpaVuD9rJnDJgZOqBlUCuHSaMMLWhZWuO/dfd8BwyZsKVkPTs9KfvfPDUDP ggoAO5dSG2+4BSc9H+k21LbGpEpZv/3aWjBUakuZV+Z3F18n4tWMr1I7yvE7/o3DcpnX I1sOXQsx9IzajFlOHraCLsJgSOxSgzQnX0eK6/L7tBW/rRk2p/hqqizotiej8hAfQyjh t09fCq8NcGmUKK4ykTjudDoQejvZV0hpAxum8MCvzRBI40JaxcWXyTvJFwOarTWTIcQy FiVQNUaklrQ2BJBFkjMAohnb3dqVmrlhg/MBQZPppQYs5BwkcIsrX4qyFnpaq0+ZMwRY 4kLQ== X-Gm-Message-State: AMCzsaUmY7Ruw+1qHB+4mtwc0dRvHClDwzM+yOPbcNtJQfCJrvUpvakO qc50ZcnvNjyLhDnExOoZomMCgZo= X-Google-Smtp-Source: AOwi7QCyhSYmRrTg1YDud0dJ2P/tijzSNDAewp++XueZcHX9RjwSARhU4wp40a1PxGRHR2Qsqm6fKA== X-Received: by 10.28.74.80 with SMTP id x77mr3803733wma.79.1506690544999; Fri, 29 Sep 2017 06:09:04 -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.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 29 Sep 2017 06:09:04 -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 2/2] serial: sh-sci: Support for HSCIF RX sampling point adjustment Date: Fri, 29 Sep 2017 15:08:54 +0200 Message-Id: <1506690534-27302-3-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 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 allows changing the default (0, meaning center) using the sysfs attribute "rx_sampling_point". Signed-off-by: Ulrich Hecht --- drivers/tty/serial/sh-sci.c | 62 +++++++++++++++++++++++++++++++++++++++++++-- drivers/tty/serial/sh-sci.h | 4 +++ 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 41bf910..924a393 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -153,6 +153,7 @@ struct sci_port { struct timer_list rx_fifo_timer; int rx_fifo_timeout; u16 hscif_tot; + u16 hscif_srhp; bool has_rtscts; bool autorts; @@ -992,6 +993,42 @@ static int sci_handle_breaks(struct uart_port *port) return copied; } +static ssize_t rx_sampling_point_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct uart_port *port = dev_get_drvdata(dev); + struct sci_port *sci = to_sci_port(port); + + return sprintf(buf, "%d\n", sci->hscif_srhp); +} + +static ssize_t rx_sampling_point_store(struct device *dev, + struct device_attribute *attr, + const char *buf, + size_t count) +{ + struct uart_port *port = dev_get_drvdata(dev); + struct sci_port *sci = to_sci_port(port); + int ret; + long r; + + ret = kstrtol(buf, 0, &r); + if (ret) + return ret; + + if (r < -8 || r > 7) + return -EINVAL; + + sci->hscif_srhp = r; + + return count; +} + +static DEVICE_ATTR(rx_sampling_point, 0644, + rx_sampling_point_show, + rx_sampling_point_store); + static int scif_set_rtrg(struct uart_port *port, int rx_trig) { unsigned int bits; @@ -2378,8 +2415,6 @@ 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); /* Wait one bit interval */ udelay((1000000 + (baud - 1)) / baud); @@ -2393,6 +2428,18 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, serial_port_out(port, SCSMR, smr_val); } + if (sci_getreg(port, HSSRR)->size) { + u16 hssrr = srr | HSCIF_SRE; + + if (s->hscif_srhp) { + u16 srhp = (s->hscif_srhp << HSCIF_SRHP_SHIFT) & + HSCIF_SRHP_MASK; + + hssrr |= HSCIF_SRDE | srhp; + } + serial_port_out(port, HSSRR, hssrr); + } + sci_init_pins(port, termios->c_cflag); port->status &= ~UPSTAT_AUTOCTS; @@ -2793,6 +2840,7 @@ static int sci_init_single(struct platform_device *dev, sci_port->rx_fifo_timeout = 0; sci_port->hscif_tot = 0; + sci_port->hscif_shrp = 0; /* SCIFA on sh7723 and sh7724 need a custom sampling rate that doesn't * match the SoC datasheet, this should be investigated. Let platform @@ -3013,6 +3061,10 @@ static int sci_remove(struct platform_device *dev) sysfs_remove_file(&dev->dev.kobj, &dev_attr_rx_fifo_timeout.attr); } + if (port->port.type == PORT_HSCIF) { + sysfs_remove_file(&dev->dev.kobj, + &dev_attr_rx_sampling_point.attr); + } return 0; } @@ -3206,6 +3258,12 @@ static int sci_probe(struct platform_device *dev) return ret; } } + if (sp->port.type == PORT_HSCIF) { + ret = sysfs_create_file(&dev->dev.kobj, + &dev_attr_rx_sampling_point.attr); + if (ret) + return ret; + } #ifdef CONFIG_SH_STANDARD_BIOS sh_bios_gdb_detach(); diff --git a/drivers/tty/serial/sh-sci.h b/drivers/tty/serial/sh-sci.h index 2b708cc..80958b2 100644 --- a/drivers/tty/serial/sh-sci.h +++ b/drivers/tty/serial/sh-sci.h @@ -129,6 +129,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 */