From: Leonard Crestez <leonard.crestez@nxp.com>
To: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Shawn Guo" <shawnguo@kernel.org>,
"Zhang Rui" <rui.zhang@intel.com>,
"Eduardo Valentin" <edubezval@gmail.com>
Cc: linux-pm@vger.kernel.org, kernel@pengutronix.de,
Dong Aisheng <aisheng.dong@nxp.com>, Bai Ping <ping.bai@nxp.com>
Subject: Re: [PATCH 4/4] thermal: imx: update to new formula according to NXP AN5215
Date: Mon, 27 Nov 2017 20:41:13 +0200 [thread overview]
Message-ID: <1511808073.20123.33.camel@nxp.com> (raw)
In-Reply-To: <20171121200225.23316-5-u.kleine-koenig@pengutronix.de>
On Tue, 2017-11-21 at 21:02 +0100, Uwe Kleine-König wrote:
> 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.
>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> 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 b24aa6cfebbf..95116475ac98 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;
The freescale tree contains a slightly modified version of this driver
which already includes the new formula. Source here:
http://git.freescale.com/git/cgit.cgi/imx/linux-imx.git/tree/drivers/thermal/imx_thermal.c?h=imx_4.9.11_1.0.0_ga#n540
Your code looks different (and nicer!) but the math seems the same.
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
prev parent reply other threads:[~2017-11-27 18:41 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-11-21 20:02 [PATCH 0/4] thermal: imx: cleanup and new formula Uwe Kleine-König
2017-11-21 20:02 ` [PATCH 1/4] thermal: imx: Use better parameter names than "val" Uwe Kleine-König
2017-11-27 18:39 ` Leonard Crestez
2017-11-27 19:50 ` Uwe Kleine-König
2017-11-28 13:20 ` Leonard Crestez
2017-11-21 20:02 ` [PATCH 2/4] thermal: imx: improve comments describing algorithm for temp calculation Uwe Kleine-König
2017-11-27 18:39 ` Leonard Crestez
2017-11-27 19:52 ` Uwe Kleine-König
2017-11-21 20:02 ` [PATCH 3/4] thermal: imx: use consistent style to write temperatures Uwe Kleine-König
2017-11-27 18:40 ` Leonard Crestez
2017-11-27 19:45 ` Uwe Kleine-König
2017-11-21 20:02 ` [PATCH 4/4] thermal: imx: update to new formula according to NXP AN5215 Uwe Kleine-König
2017-11-27 18:41 ` Leonard Crestez [this message]
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=1511808073.20123.33.camel@nxp.com \
--to=leonard.crestez@nxp.com \
--cc=aisheng.dong@nxp.com \
--cc=edubezval@gmail.com \
--cc=kernel@pengutronix.de \
--cc=linux-pm@vger.kernel.org \
--cc=ping.bai@nxp.com \
--cc=rui.zhang@intel.com \
--cc=shawnguo@kernel.org \
--cc=u.kleine-koenig@pengutronix.de \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.