diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2017-11-30 04:17:36 -0500 |
---|---|---|
committer | Eduardo Valentin <edubezval@gmail.com> | 2018-01-01 14:45:55 -0500 |
commit | c5bbdb4ba30977a30f485e66c8af9b4c44f3798e (patch) | |
tree | d7bdf167a1b7267b4507d05ec9416ec4185b631f /drivers/thermal/imx_thermal.c | |
parent | e4bb2240d4db6188f2e88610a68bda12e2bc98e1 (diff) |
thermal: imx: improve comments describing algorithm for temp calculation
The description of the implemented algorithm is hardly understandable
without having the right application note side-by-side to the code.
Fix this by using shorter and more intuitive variable names, describe
their meaning and transform a single formula instead of first talking about
slope and then about "milli_Tmeas".
There are no code changes.
Reviewed-by: Leonard Crestez <leonard.crestez@nxp.com>
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Eduardo Valentin <edubezval@gmail.com>
Diffstat (limited to 'drivers/thermal/imx_thermal.c')
-rw-r--r-- | drivers/thermal/imx_thermal.c | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index 21b8c4c4da3c..c08883dff2cb 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c | |||
@@ -359,32 +359,28 @@ static int imx_init_calib(struct platform_device *pdev, u32 ocotp_ana1) | |||
359 | } | 359 | } |
360 | 360 | ||
361 | /* | 361 | /* |
362 | * Sensor data layout: | 362 | * The sensor is calibrated at 25 °C (aka T1) and the value measured |
363 | * [31:20] - sensor value @ 25C | 363 | * (aka N1) at this temperature is provided in bits [31:20] in the |
364 | * Use universal formula now and only need sensor value @ 25C | 364 | * i.MX's OCOTP value ANA1. |
365 | * slope = 0.4297157 - (0.0015976 * 25C fuse) | 365 | * To find the actual temperature T, the following formula has to be used |
366 | * when reading value n from the sensor: | ||
367 | * | ||
368 | * T = T1 + (N - N1) / (0.4297157 - 0.0015976 * N1) °C | ||
369 | * = [T1 - N1 / (0.4297157 - 0.0015976 * N1) °C] + N / (0.4297157 - 0.0015976 * N1) °C | ||
370 | * = [T1 + N1 / (0.0015976 * N1 - 0.4297157) °C] - N / (0.0015976 * N1 - 0.4297157) °C | ||
371 | * = c2 - c1 * N | ||
372 | * | ||
373 | * with | ||
374 | * | ||
375 | * c1 = 1 / (0.0015976 * N1 - 0.4297157) °C | ||
376 | * c2 = T1 + N1 / (0.0015976 * N1 - 0.4297157) °C | ||
377 | * = T1 + N1 * C1 | ||
366 | */ | 378 | */ |
367 | n1 = ocotp_ana1 >> 20; | 379 | n1 = ocotp_ana1 >> 20; |
368 | t1 = 25; /* t1 always 25C */ | 380 | t1 = 25; /* °C */ |
369 | 381 | ||
370 | /* | 382 | temp64 = FACTOR0; /* 10^7 for FACTOR1 and FACTOR2 */ |
371 | * Derived from linear interpolation: | 383 | temp64 *= 1000; /* to get result in °mC */ |
372 | * slope = 0.4297157 - (0.0015976 * 25C fuse) | ||
373 | * slope = (FACTOR2 - FACTOR1 * n1) / FACTOR0 | ||
374 | * (Nmeas - n1) / (Tmeas - t1) = slope | ||
375 | * We want to reduce this down to the minimum computation necessary | ||
376 | * for each temperature read. Also, we want Tmeas in millicelsius | ||
377 | * and we don't want to lose precision from integer division. So... | ||
378 | * Tmeas = (Nmeas - n1) / slope + t1 | ||
379 | * milli_Tmeas = 1000 * (Nmeas - n1) / slope + 1000 * t1 | ||
380 | * milli_Tmeas = -1000 * (n1 - Nmeas) / slope + 1000 * t1 | ||
381 | * Let constant c1 = (-1000 / slope) | ||
382 | * milli_Tmeas = (n1 - Nmeas) * c1 + 1000 * t1 | ||
383 | * Let constant c2 = n1 *c1 + 1000 * t1 | ||
384 | * milli_Tmeas = c2 - Nmeas * c1 | ||
385 | */ | ||
386 | temp64 = FACTOR0; | ||
387 | temp64 *= 1000; | ||
388 | do_div(temp64, FACTOR1 * n1 - FACTOR2); | 384 | do_div(temp64, FACTOR1 * n1 - FACTOR2); |
389 | data->c1 = temp64; | 385 | data->c1 = temp64; |
390 | data->c2 = n1 * data->c1 + 1000 * t1; | 386 | data->c2 = n1 * data->c1 + 1000 * t1; |