Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1029122yba; Thu, 4 Apr 2019 02:47:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqyWv9zp/5vCvJceu1wTSnFsWYg9GAhqZQ6TtH5ItFbDBbt63crkynpow6kw4FqJ3D6sNKvj X-Received: by 2002:a17:902:2e83:: with SMTP id r3mr5341243plb.153.1554371277846; Thu, 04 Apr 2019 02:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554371277; cv=none; d=google.com; s=arc-20160816; b=JySfxN/omlupipN9PqvL0GvcW4bc0hFBKq7c06rw7eHnGkIelBKr9f8J4vIf4Y80QB UqneYif8+EBpUBUUABTKJ9JiyN7GwXweVnQduCxwEy6mPvLkbr0GJxOGUReV9oot2ryx /06sQKzMfkaFGiNYH/lGxBwldPyzubTfSmpyxEw/HnxF+1XwzVIpSuFQxXFJk3rOoY6e LLndvNQRBS3awaiUuMwryxIlS7+rCxscei9Q6jRHpZLjgdSAMaPI/8WGkXbArCH/MFC3 37nL+4c7lSwWWnhc6ChUWbGSLotHBcVJ5ivAQgNqQfNoSQNElE32a/qO8sVxb1rfCrmB LfOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=9se90roRHVjDQq7UYmHrTiaoPRE25Sy2smAlGDIOUFw=; b=Yo2ayJmxZJRo0PBcXIJLpFbresluBGmL/2mdnNxI0xGtFgX0W63YXd2HkVtMPkmHuI 1orWek6ysluMoYheUt5qe/9iYDJCzDXs2JP7T3gBWxQRGWpeJcoyuOjBirhczS+U8Qy3 ogZt3+BHyNENCVdqnfs0v8nyX/nZAv0leVjLehL3zR5ENYj5n5HbG+n+dm92XxqrS7cN 0uPa6WMFgqmNA1jAkiHUAGn7/uIAQIfSfui23DJRTINChc2tSPT/8hECBwgKm0/t5R+G cTBoFwxQ18IQMpo1yLT6HGED4st7l+WPNFQ6dEWDi1gyBJ8/MBHZKD99MZsaYXt+0Sxo PI9g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id cu15si16840607plb.83.2019.04.04.02.47.42; Thu, 04 Apr 2019 02:47:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731523AbfDDJpv (ORCPT + 99 others); Thu, 4 Apr 2019 05:45:51 -0400 Received: from smtp1.de.adit-jv.com ([93.241.18.167]:46720 "EHLO smtp1.de.adit-jv.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728594AbfDDJpo (ORCPT ); Thu, 4 Apr 2019 05:45:44 -0400 Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id E53883C013A; Thu, 4 Apr 2019 11:45:41 +0200 (CEST) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UD3h-i35fCq1; Thu, 4 Apr 2019 11:45:35 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 499F13C00C3; Thu, 4 Apr 2019 11:45:35 +0200 (CEST) Received: from vmlxhi-102.adit-jv.com (10.72.93.184) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.439.0; Thu, 4 Apr 2019 11:45:34 +0200 Date: Thu, 4 Apr 2019 11:45:31 +0200 From: Eugeniu Rosca To: Geert Uytterhoeven CC: Greg Kroah-Hartman , Jiri Slaby , Ulrich Hecht , Dirk Behme , , , Simon Herkenhoff , Eugeniu Rosca Subject: Re: [PATCH] serial: sh-sci: Fix HSCIF RX sampling point calculation Message-ID: <20190404094531.GA31244@vmlxhi-102.adit-jv.com> References: <20190401112510.23145-1-geert+renesas@glider.be> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Disposition: inline In-Reply-To: <20190401112510.23145-1-geert+renesas@glider.be> User-Agent: Mutt/1.5.24 (2015-08-30) X-Originating-IP: [10.72.93.184] Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Geert, On Mon, Apr 01, 2019 at 01:25:10PM +0200, Geert Uytterhoeven wrote: > There are several issues with the formula used for calculating the > deviation from the intended rate: > 1. While min_err and last_stop are signed, srr and baud are unsigned. > Hence the signed values are promoted to unsigned, which will lead > to a bogus value of deviation if min_err is negative, > 2. Srr is the register field value, which is one less than the actual > sampling rate factor, > 3. The divisions do not use rounding. > > Fix this by casting unsigned variables to int, adding one to srr, and > using a single DIV_ROUND_CLOSEST(). > > Fixes: 63ba1e00f178a448 ("serial: sh-sci: Support for HSCIF RX sampling point adjustment") > Signed-off-by: Geert Uytterhoeven > --- > Anyone with a good test setup for verifying this feature actually works > as advertised? > --- > drivers/tty/serial/sh-sci.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c > index 2bdaeba5d527a6ce..8dea59edde34c224 100644 > --- a/drivers/tty/serial/sh-sci.c > +++ b/drivers/tty/serial/sh-sci.c > @@ -2522,7 +2522,9 @@ static void sci_set_termios(struct uart_port *port, struct ktermios *termios, > * center of the last stop bit in sampling clocks. > */ > int last_stop = bits * 2 - 1; > - int deviation = min_err * srr * last_stop / 2 / baud; > + int deviation = DIV_ROUND_CLOSEST(min_err * last_stop * > + (int)(srr + 1), > + 2 * (int)baud); > > if (abs(deviation) >= 2) { > /* At least two sampling clocks off at the Just wanted to say thank you for your tremendous commitment and continuity in supporting the R-Car platform (and beyond that), which allowed us to gracefully overcome the problems encountered in the project in the best possible time, specifically thanks to this patch. Best regards, Eugeniu.