From: Nguyen An Hoan <na-hoan@jinso.co.jp> 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 [thread overview] Message-ID: <1535596744-16598-2-git-send-email-na-hoan@jinso.co.jp> (raw) In-Reply-To: <1535596744-16598-1-git-send-email-na-hoan@jinso.co.jp> From: Hoan Nguyen An <na-hoan@jinso.co.jp> 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 <na-hoan@jinso.co.jp> --- 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); } -- 2.7.4
next prev parent reply other threads:[~2018-08-30 6:39 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-08-30 2:39 [PATCH] thermal: rcar: reduce inaccuracy in the calculate rounding for temperature conversion Nguyen An Hoan 2018-08-30 2:39 ` Nguyen An Hoan [this message] 2018-08-30 7:48 ` [PATCH] thermal: rcar: reduce inaccuracy in calculate rounding Geert Uytterhoeven 2018-08-30 9:39 ` Sergei Shtylyov
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1535596744-16598-2-git-send-email-na-hoan@jinso.co.jp \ --to=na-hoan@jinso.co.jp \ --cc=broonie@kernel.org \ --cc=cv-dong@jinso.co.jp \ --cc=geert+renesas@glider.be \ --cc=h-inayoshi@jinso.co.jp \ --cc=kuninori.morimoto.gx@renesas.com \ --cc=linux-renesas-soc@vger.kernel.org \ --cc=magnus.damm@gmail.com \ --cc=niklas.soderlund+renesas@ragnatech.se \ --cc=nv-dung@jinso.co.jp \ --cc=wsa@sang-engineering.com \ --cc=yoshihiro.shimoda.uh@renesas.com \ --subject='Re: [PATCH] thermal: rcar: reduce inaccuracy in calculate rounding' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.