linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] touchscreen: sun4i-ts: Really fix A10 temperature reporting
@ 2015-03-09  9:37 Hans de Goede
  2015-03-12 21:54 ` Dmitry Torokhov
  2015-06-23 15:06 ` m.silentcreek at gmail.com
  0 siblings, 2 replies; 10+ messages in thread
From: Hans de Goede @ 2015-03-09  9:37 UTC (permalink / raw)
  To: linux-arm-kernel

The commit titled:
"touchscreen: sun4i-ts: A10 (sun4i) has a different temperature curve"
contains a math error, the offset it uses is in degrees, but the actual code
applies the offset before multiplying by stepsize :|

Given that this is rather backwards (every math course ever thought applies
the multiplication before the offset for linear functions), this commit
fixes things by changing the code applying the offset to do the logical
thing, adjusting the offset for the other models accordingly.

This has been tested on an A10, A13, A20 and A31 to make sure everything really
is correct now.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
Note if possible this commit should be squashed into the original
"touchscreen: sun4i-ts: A10 (sun4i) has a different temperature curve"
commit as a fixup.
---
 drivers/input/touchscreen/sun4i-ts.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/input/touchscreen/sun4i-ts.c b/drivers/input/touchscreen/sun4i-ts.c
index 66ccd5a..178d2ef 100644
--- a/drivers/input/touchscreen/sun4i-ts.c
+++ b/drivers/input/touchscreen/sun4i-ts.c
@@ -193,7 +193,7 @@ static int sun4i_get_temp(const struct sun4i_ts_data *ts, long *temp)
 	if (ts->temp_data == -1)
 		return -EAGAIN;
 
-	*temp = (ts->temp_data - ts->temp_offset) * ts->temp_step;
+	*temp = ts->temp_data * ts->temp_step - ts->temp_offset;
 
 	return 0;
 }
@@ -255,17 +255,17 @@ static int sun4i_ts_probe(struct platform_device *pdev)
 	ts->ignore_fifo_data = true;
 	ts->temp_data = -1;
 	if (of_device_is_compatible(np, "allwinner,sun6i-a31-ts")) {
-		/* Allwinner SDK has temperature = -271 + (value / 6) (C) */
-		ts->temp_offset = 1626;
+		/* Allwinner SDK has temperature (C) = (value / 6) - 271 */
+		ts->temp_offset = 271000;
 		ts->temp_step = 167;
 	} else if (of_device_is_compatible(np, "allwinner,sun4i-a10-ts")) {
 		/*
 		 * The A10 temperature sensor has quite a wide spread, these
 		 * parameters are based on the averaging of the calibration
 		 * results of 4 completely different boards, with a spread of
-		 * temp_step from 96 - 170 and temp_offset from 1758 - 3310.
+		 * temp_step from 0.096 - 0.170 and temp_offset from 176 - 331.
 		 */
-		ts->temp_offset = 2570;
+		ts->temp_offset = 257000;
 		ts->temp_step = 133;
 	} else {
 		/*
@@ -273,13 +273,13 @@ static int sun4i_ts_probe(struct platform_device *pdev)
 		 * the temperature. The formula used here is from the AXP209,
 		 * which is designed by X-Powers, an affiliate of Allwinner:
 		 *
-		 *     temperature = -144.7 + (value * 0.1)
+		 *     temperature (C) = (value * 0.1) - 144.7
 		 *
 		 * Allwinner does not have any documentation whatsoever for
 		 * this hardware. Moreover, it is claimed that the sensor
 		 * is inaccurate and cannot work properly.
 		 */
-		ts->temp_offset = 1447;
+		ts->temp_offset = 144700;
 		ts->temp_step = 100;
 	}
 
-- 
2.3.1

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

end of thread, other threads:[~2015-06-24  7:31 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-03-09  9:37 [PATCH] touchscreen: sun4i-ts: Really fix A10 temperature reporting Hans de Goede
2015-03-12 21:54 ` Dmitry Torokhov
2015-06-23 15:06 ` m.silentcreek at gmail.com
2015-06-23 19:46   ` Hans de Goede
2015-06-23 19:54     ` Dmitry Torokhov
2015-06-24  7:16       ` Hans de Goede
2015-06-24  7:28         ` Maxime Ripard
2015-06-24  7:31           ` Hans de Goede
2015-06-23 20:39     ` m.silentcreek at gmail.com
2015-06-23 21:06     ` m.silentcreek at gmail.com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).