All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Paweł Jarosz" <paweljarosz3691@gmail.com>
To: paweljarosz3691@gmail.com
Cc: linux-iio@vger.kernel.org, ldewangan@nvidia.com,
	rui.zhang@intel.com, edubezval@gmail.com
Subject: [PATCH] thermal: generic-adc: Fix linear temperature approximation
Date: Tue, 18 Oct 2016 21:31:47 +0200	[thread overview]
Message-ID: <20161018193147.GA14745@vaio-ubuntu> (raw)

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


             reply	other threads:[~2016-10-18 19:30 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-18 19:31 Paweł Jarosz [this message]
2016-10-20 12:40 ` [PATCH] thermal: generic-adc: Fix linear temperature approximation 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

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=20161018193147.GA14745@vaio-ubuntu \
    --to=paweljarosz3691@gmail.com \
    --cc=edubezval@gmail.com \
    --cc=ldewangan@nvidia.com \
    --cc=linux-iio@vger.kernel.org \
    --cc=rui.zhang@intel.com \
    /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.