From patchwork Thu Nov 30 09:17:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= X-Patchwork-Id: 10084457 X-Patchwork-Delegate: eduardo.valentin@ti.com 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 CEEE56035E for ; Thu, 30 Nov 2017 09:17:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D55D429F0D for ; Thu, 30 Nov 2017 09:17:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CA1B029F17; Thu, 30 Nov 2017 09:17:54 +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.9 required=2.0 tests=BAYES_00,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 7127F29F0D for ; Thu, 30 Nov 2017 09:17:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752255AbdK3JRv (ORCPT ); Thu, 30 Nov 2017 04:17:51 -0500 Received: from antares.kleine-koenig.org ([94.130.110.236]:36750 "EHLO antares.kleine-koenig.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752312AbdK3JRq (ORCPT ); Thu, 30 Nov 2017 04:17:46 -0500 Received: by antares.kleine-koenig.org (Postfix, from userid 1000) id 07F913674E; Thu, 30 Nov 2017 10:17:46 +0100 (CET) From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= To: Leonard Crestez , Shawn Guo , Zhang Rui , Eduardo Valentin Cc: kernel@pengutronix.de, linux-pm@vger.kernel.org Subject: [PATCH v2 4/4] thermal: imx: update to new formula according to NXP AN5215 Date: Thu, 30 Nov 2017 10:17:38 +0100 Message-Id: <20171130091738.8901-5-u.kleine-koenig@pengutronix.de> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130091738.8901-1-u.kleine-koenig@pengutronix.de> References: <20171130091738.8901-1-u.kleine-koenig@pengutronix.de> MIME-Version: 1.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP According to an application note from 03/2017 there is an updated formula to calculate the temperature that better matches reality. This is implemented here. While updating move the magic constants from cpp defines which are far above the explaining formula to constants in the code just under the explaining comment. Reviewed-by: Leonard Crestez Signed-off-by: Uwe Kleine-König --- Changes since (implicit) v1, sent with Message-ID: 20171121200225.23316-5-u.kleine-koenig@pengutronix.de - Add Reviewed-by: Leonard Crestez --- drivers/thermal/imx_thermal.c | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 41e15cf5ffd7..a67781b7a0b2 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -70,10 +70,6 @@ enum imx_thermal_trip { #define IMX_POLLING_DELAY 2000 /* millisecond */ #define IMX_PASSIVE_DELAY 1000 -#define FACTOR0 10000000 -#define FACTOR1 15976 -#define FACTOR2 4297157 - #define TEMPMON_IMX6Q 1 #define TEMPMON_IMX6SX 2 @@ -350,7 +346,7 @@ static struct thermal_zone_device_ops imx_tz_ops = { static int imx_init_calib(struct platform_device *pdev, u32 ocotp_ana1) { struct imx_thermal_data *data = platform_get_drvdata(pdev); - int t1, n1; + int n1; u64 temp64; if (ocotp_ana1 == 0 || ocotp_ana1 == ~0) { @@ -365,25 +361,25 @@ static int imx_init_calib(struct platform_device *pdev, u32 ocotp_ana1) * To find the actual temperature T, the following formula has to be used * when reading value n from the sensor: * - * T = T1 + (N - N1) / (0.4297157 - 0.0015976 * N1) °C - * = [T1 - N1 / (0.4297157 - 0.0015976 * N1) °C] + N / (0.4297157 - 0.0015976 * N1) °C - * = [T1 + N1 / (0.0015976 * N1 - 0.4297157) °C] - N / (0.0015976 * N1 - 0.4297157) °C + * T = T1 + (N - N1) / (0.4148468 - 0.0015423 * N1) °C + 3.580661 °C + * = [T1' - N1 / (0.4148468 - 0.0015423 * N1) °C] + N / (0.4148468 - 0.0015423 * N1) °C + * = [T1' + N1 / (0.0015423 * N1 - 0.4148468) °C] - N / (0.0015423 * N1 - 0.4148468) °C * = c2 - c1 * N * * with * - * c1 = 1 / (0.0015976 * N1 - 0.4297157) °C - * c2 = T1 + N1 / (0.0015976 * N1 - 0.4297157) °C - * = T1 + N1 * C1 + * T1' = 28.580661 °C + * c1 = 1 / (0.0015423 * N1 - 0.4297157) °C + * c2 = T1' + N1 / (0.0015423 * N1 - 0.4148468) °C + * = T1' + N1 * c1 */ n1 = ocotp_ana1 >> 20; - t1 = 25; /* °C */ - temp64 = FACTOR0; /* 10^7 for FACTOR1 and FACTOR2 */ + temp64 = 10000000; /* use 10^7 as fixed point constant for values in formula */ temp64 *= 1000; /* to get result in °mC */ - do_div(temp64, FACTOR1 * n1 - FACTOR2); + do_div(temp64, 15423 * n1 - 4148468); data->c1 = temp64; - data->c2 = n1 * data->c1 + 1000 * t1; + data->c2 = n1 * data->c1 + 28581; return 0; }