From patchwork Mon Jul 14 07:09:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nobuhiro Iwamatsu X-Patchwork-Id: 4542941 Return-Path: X-Original-To: patchwork-linux-sh@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id BD8B99F295 for ; Mon, 14 Jul 2014 07:10:18 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F0B3120136 for ; Mon, 14 Jul 2014 07:10:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AC89820131 for ; Mon, 14 Jul 2014 07:10:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752549AbaGNHKQ (ORCPT ); Mon, 14 Jul 2014 03:10:16 -0400 Received: from mail-pa0-f49.google.com ([209.85.220.49]:56987 "EHLO mail-pa0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751709AbaGNHKP (ORCPT ); Mon, 14 Jul 2014 03:10:15 -0400 Received: by mail-pa0-f49.google.com with SMTP id hz1so929331pad.8 for ; Mon, 14 Jul 2014 00:10:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=kiYSg3KRfAqOGwMxxRHgWBooybh0dfcanGwcPEntHyo=; b=TgRYITk+M3Am/992dJLRLXeW7NreKysqCfTaj/XZGn41wx2eQap+nV99jOqDxwbd1d RTAUx536v1PzX8qRwkKREkC9g8VgMGC16R/RQt+4G7gBar2h/TWVQ+o0fpoZBavFC+vR L0bsGvKJqtViL+mKicr5HuBExozMIlm10vKmU/D6jHx02J1hb5IJXoXPqlo/UXloOFTr Wy4iYiLY+wITAfO6osn96IwYi0xC2Mp7PIuik6RkWmdlY3eldvEJM/RLT9/K2HqwG4KM miTLqZ2VwYSkGrL7aM2lpXlOyLPm3rzqtw1DyRSMJEGQSTyu2O/Y9cCgdH5vANXQrD6u PXnQ== X-Gm-Message-State: ALoCoQnrk6Jm8R1fgktoYFY+kpZT7k1ZnRtMuXA4tAceUd68R/BBPG7o2qwl/DlC8KetTtJlESAy X-Received: by 10.66.117.38 with SMTP id kb6mr15039695pab.37.1405321814369; Mon, 14 Jul 2014 00:10:14 -0700 (PDT) Received: from xps-iwamatsu.renesas.com (49.14.32.202.bf.2iij.net. [202.32.14.49]) by mx.google.com with ESMTPSA id gi1sm9792864pbd.15.2014.07.14.00.10.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 14 Jul 2014 00:10:12 -0700 (PDT) From: Nobuhiro Iwamatsu To: linux-sh@vger.kernel.org Cc: gregkh@linuxfoundation.org, linux-serial@vger.kernel.org, horms+renesas@verge.net.au, magnus.damm@gmail.com, Nobuhiro Iwamatsu Subject: [PATCH 1/3] serial: sh-sci: Updated calculation of bit error rate and bit rate Date: Mon, 14 Jul 2014 16:09:58 +0900 Message-Id: <1405321800-18114-1-git-send-email-nobuhiro.iwamatsu.yj@renesas.com> X-Mailer: git-send-email 2.0.0 Sender: linux-sh-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sh@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, the decimal point is discarded calculation of BRR. Therefore, it can not calculate a value close to the correct value. This patch fixes this problem by using DIV_ROUND_CLOSEST. Signed-off-by: Nobuhiro Iwamatsu Acked-by: Simon Horman --- drivers/tty/serial/sh-sci.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c index 88236da..ce80137 100644 --- a/drivers/tty/serial/sh-sci.c +++ b/drivers/tty/serial/sh-sci.c @@ -1796,11 +1796,13 @@ static void sci_baud_calc_hscif(unsigned int bps, unsigned long freq, for (sr = 8; sr <= 32; sr++) { for (c = 0; c <= 3; c++) { /* integerized formulas from HSCIF documentation */ - br = freq / (sr * (1 << (2 * c + 1)) * bps) - 1; + br = DIV_ROUND_CLOSEST(freq, (sr * + (1 << (2 * c + 1)) * bps)) - 1; if (br < 0 || br > 255) continue; - err = freq / ((br + 1) * bps * sr * - (1 << (2 * c + 1)) / 1000) - 1000; + err = DIV_ROUND_CLOSEST(freq, ((br + 1) * bps * sr * + (1 << (2 * c + 1)) / 1000)) - + 1000; if (min_err > err) { min_err = err; *brr = br;