From patchwork Thu Aug 30 02:39:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?44Kw44Kn44Oz44O744Ki44Oz44O744Ob44Kh44Oz?= X-Patchwork-Id: 10581163 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-2.web.codeaurora.org (Postfix) with ESMTP id A9D4C920 for ; Thu, 30 Aug 2018 02:39:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 98DB62BCD8 for ; Thu, 30 Aug 2018 02:39:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8CB1F2BD23; Thu, 30 Aug 2018 02:39:18 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI 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 255D62BCD8 for ; Thu, 30 Aug 2018 02:39:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727012AbeH3GjI (ORCPT ); Thu, 30 Aug 2018 02:39:08 -0400 Received: from www3345.sakura.ne.jp ([49.212.235.55]:28548 "EHLO www3345.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbeH3GjI (ORCPT ); Thu, 30 Aug 2018 02:39:08 -0400 Received: from fsav302.sakura.ne.jp (fsav302.sakura.ne.jp [153.120.85.133]) by www3345.sakura.ne.jp (8.15.2/8.15.2) with ESMTP id w7U2dFxr087559; Thu, 30 Aug 2018 11:39:15 +0900 (JST) (envelope-from na-hoan@jinso.co.jp) Received: from www3345.sakura.ne.jp (49.212.235.55) by fsav302.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav302.sakura.ne.jp); Thu, 30 Aug 2018 11:39:15 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav302.sakura.ne.jp) Received: from localhost (p14010-ipadfx41marunouchi.tokyo.ocn.ne.jp [61.118.107.10]) (authenticated bits=0) by www3345.sakura.ne.jp (8.15.2/8.15.2) with ESMTPSA id w7U2dAZQ087534 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 30 Aug 2018 11:39:15 +0900 (JST) (envelope-from na-hoan@jinso.co.jp) From: Nguyen An Hoan To: broonie@kernel.org, linux-renesas-soc@vger.kernel.org, geert+renesas@glider.be Cc: wsa@sang-engineering.com, niklas.soderlund+renesas@ragnatech.se, kuninori.morimoto.gx@renesas.com, yoshihiro.shimoda.uh@renesas.com, magnus.damm@gmail.com, h-inayoshi@jinso.co.jp, nv-dung@jinso.co.jp, cv-dong@jinso.co.jp, na-hoan@jinso.co.jp Subject: [PATCH] thermal: rcar: reduce inaccuracy in calculate rounding Date: Thu, 30 Aug 2018 11:39:04 +0900 Message-Id: <1535596744-16598-2-git-send-email-na-hoan@jinso.co.jp> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1535596744-16598-1-git-send-email-na-hoan@jinso.co.jp> References: <1535596744-16598-1-git-send-email-na-hoan@jinso.co.jp> 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 From: Hoan Nguyen An About the formula for temperature calculation [reg] = [temp] * a + b <=> [temp] = ([reg] - b) / a Using "(mcelsius * tsc-> coef.aX) / 1000" instead of "DIV_ROUND_CLOSEST(mcelsius, 1000) * tsc-> coef.aX" to avoid and reduce inaccuracy due to rounding the integer division. Signed-off-by: Hoan Nguyen An --- drivers/thermal/rcar_gen3_thermal.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index 7aed533..dbb31b8 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c @@ -185,11 +185,10 @@ static int rcar_gen3_thermal_get_temp(void *devdata, int *temp) static int rcar_gen3_thermal_mcelsius_to_temp(struct rcar_gen3_thermal_tsc *tsc, int mcelsius) { - int celsius, val1, val2; + int val1, val2; - celsius = DIV_ROUND_CLOSEST(mcelsius, 1000); - val1 = celsius * tsc->coef.a1 + tsc->coef.b1; - val2 = celsius * tsc->coef.a2 + tsc->coef.b2; + val1 = (mcelsius * tsc->coef.a1)/1000 + tsc->coef.b1; + val2 = (mcelsius * tsc->coef.a2)/1000 + tsc->coef.b2; return INT_FIXPT((val1 + val2) / 2); }