All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] thermal: generic-adc: Fix linear temperature approximation
@ 2016-10-18 19:31 Paweł Jarosz
  2016-10-20 12:40 ` Laxman Dewangan
  0 siblings, 1 reply; 11+ messages in thread
From: Paweł Jarosz @ 2016-10-18 19:31 UTC (permalink / raw)
  To: paweljarosz3691; +Cc: linux-iio, ldewangan, rui.zhang, edubezval

In current version of the driver there is error in temperature
calculation.

So lets fix it using proper linear function.

Signed-off-by: Paweł Jarosz <paweljarosz3691@gmail.com>
---
 drivers/thermal/thermal-generic-adc.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c
index 73f55d6..1190aee 100644
--- a/drivers/thermal/thermal-generic-adc.c
+++ b/drivers/thermal/thermal-generic-adc.c
@@ -26,7 +26,7 @@ struct gadc_thermal_info {
 
 static int gadc_thermal_adc_to_temp(struct gadc_thermal_info *gti, int val)
 {
-	int temp, adc_hi, adc_lo;
+	int temp, adc1, adc2, temp1, temp2;
 	int i;
 
 	for (i = 0; i < gti->nlookup_table; i++) {
@@ -39,10 +39,13 @@ static int gadc_thermal_adc_to_temp(struct gadc_thermal_info *gti, int val)
 	} else if (i >= (gti->nlookup_table - 1)) {
 		temp = gti->lookup_table[2 * (gti->nlookup_table - 1)];
 	} else {
-		adc_hi = gti->lookup_table[2 * i - 1];
-		adc_lo = gti->lookup_table[2 * i + 1];
-		temp = gti->lookup_table[2 * i];
-		temp -= ((val - adc_lo) * 1000) / (adc_hi - adc_lo);
+		adc1 = gti->lookup_table[2 * i - 1];
+		adc2 = gti->lookup_table[2 * i + 1];
+
+		temp1 = gti->lookup_table[2 * i - 2];
+		temp2 = gti->lookup_table[2 * i];
+
+		temp = (val - adc1) * (temp2 - temp1) / (adc2 - adc1) + temp1;
 	}
 
 	return temp;
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-10-21  6:58 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-10-18 19:31 [PATCH] thermal: generic-adc: Fix linear temperature approximation Paweł Jarosz
2016-10-20 12:40 ` Laxman Dewangan
2016-10-20 14:56   ` Paweł Jarosz
2016-10-20 15:49     ` Laxman Dewangan
2016-10-20 16:14       ` Paweł Jarosz
2016-10-20 16:01         ` Laxman Dewangan
2016-10-20 17:10       ` Paweł Jarosz
2016-10-20 17:01         ` Laxman Dewangan
2016-10-20 17:26           ` Paweł Jarosz
2016-10-21  6:18             ` Laxman Dewangan
2016-10-21  7:00               ` Paweł Jarosz

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.