Skip to contentSkip to conversation

touchscreen: sun4i-ts: Really fix A10 temperature reporting

PATCH New Hans de Goede 5 participants 11 messages Mar 9, 2015 – Jun 24, 2015 1 message not in the archive

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 touchscreen: sun4i-ts: Really fix A10 temperature reporting

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.

---
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(-)
drivers/input/touchscreen/sun4i-ts.c +7 -7
index 66ccd5a..178d2ef 100644
@@ -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;
 	}
 
Signature · 1 line
2.3.1
maintainer
#1 lore raw

PATCH 1/1 touchscreen: sun4i-ts: Really fix A10 temperature reporting

Quoted 10 lines · Hans de Goede

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.

Quoted 8 lines

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

---
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.

It's a bit too late, I do not like rewinding my 'next' branch unless it is a compile error caught recently. So applied as a separate commit.

Thanks.

Quoted 58 lines
---
 drivers/input/touchscreen/sun4i-ts.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/input/touchscreen/sun4i-ts.c +7 -7
index 66ccd5a..178d2ef 100644
@@ -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;
 	}
 
Signature · 1 line
2.3.1
Signature · 1 line
Dmitry
#2 lore raw

PATCH 1/1 touchscreen: sun4i-ts: Really fix A10 temperature reporting

In reply to Hans de Goede

Hi Hans,

is it possible that this patch (and the parent commit "Input: sun4i-ts - allow controlling filter and sensitivity via DT") has quite an adversial effect on other boards than the ones tested?

On my Lemaker Bananapi the temperature is now being reported as somwhere between -15?C to -10?C with the latest Kernel 4.1.0. These negative values are obviously way off. On Kernel 4.0.5 the temperature reading was usually around 40?C. While that might not have been accurate either, it was at least plausible.

Given that there is no Documentation and things seem quite board-specific, I really don't know how this could be improved, so I can merely report my observation.

Kind regards,

Timo

Am Montag, 9. M?rz 2015 10:38:02 UTC+1 schrieb Hans de Goede:

Quoted 75 lines

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.

---
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(-)
drivers/input/touchscreen/sun4i-ts.c +7 -7
index 66ccd5a..178d2ef 100644
@@ -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;
 	}
 
Signature · 1 line
2.3.1
#3 lore raw

PATCH 1/1 touchscreen: sun4i-ts: Really fix A10 temperature reporting

Hi,

Quoted 5 lines · m.silentcreek at gmail.com

Hi Hans,

is it possible that this patch (and the parent commit "Input: sun4i-ts - allow controlling filter and sensitivity via DT") has quite an adversial effect on other boards than the ones tested?

On my Lemaker Bananapi the temperature is now being reported as somwhere between -15?C to -10?C with the latest Kernel 4.1.0. These negative values are obviously way off. On Kernel 4.0.5 the temperature reading was usually around 40?C. While that might not have been accurate either, it was at least plausible.

The temperature curve for the A20 SoC was not changed, if it did change then you're using an old dtb file with a new kernel, you must always update your dtb file together with the kernel.

Quoted 82 lines

Given that there is no Documentation and things seem quite board-specific, I really don't know how this could be improved, so I can merely report my observation.

Kind regards,

Timo

Am Montag, 9. M?rz 2015 10:38:02 UTC+1 schrieb Hans de Goede:

Quoted 73 lines

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.

---
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(-)
drivers/input/touchscreen/sun4i-ts.c +7 -7
index 66ccd5a..178d2ef 100644
@@ -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;
  	}
 
Quoted 3 lines
Quoted 2 lines

--
2.3.1

Regards,

Hans

maintainer
#4 lore raw

PATCH 1/1 touchscreen: sun4i-ts: Really fix A10 temperature reporting

Quoted 5 lines · Hans de Goede

Hi,

Quoted 2 lines · m.silentcreek at gmail.com

Hi Hans,

Quoted 7 lines
Quoted 3 lines

is it possible that this patch (and the parent commit "Input: sun4i-ts - allow controlling filter and sensitivity via DT") has quite an adversial effect on other boards than the ones tested?

On my Lemaker Bananapi the temperature is now being reported as somwhere between -15?C to -10?C with the latest Kernel 4.1.0. These negative values are obviously way off. On Kernel 4.0.5 the temperature reading was usually around 40?C. While that might not have been accurate either, it was at least plausible.

The temperature curve for the A20 SoC was not changed, if it did change then you're using an old dtb file with a new kernel, you must always update your dtb file together with the kernel.

Umm, we should keep compatibility with old DTS...

Quoted 92 lines
Quoted 85 lines

Given that there is no Documentation and things seem quite board-specific, I really don't know how this could be improved, so I can merely report my observation.

Kind regards,

Timo

Am Montag, 9. M?rz 2015 10:38:02 UTC+1 schrieb Hans de Goede:

Quoted 73 lines

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.

---
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(-)
drivers/input/touchscreen/sun4i-ts.c +7 -7
index 66ccd5a..178d2ef 100644
@@ -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;
 	}
 
Quoted 3 lines
Quoted 2 lines

--
2.3.1

Regards,

Hans

Signature · 1 line
Dmitry
#5 lore raw

PATCH 1/1 touchscreen: sun4i-ts: Really fix A10 temperature reporting

Hi,

Quoted 8 lines · Dmitry Torokhov
Quoted 7 lines · Hans de Goede

Hi,

Quoted 4 lines · m.silentcreek at gmail.com

Hi Hans,

is it possible that this patch (and the parent commit "Input: sun4i-ts - allow controlling filter and sensitivity via DT") has quite an adversial effect on other boards than the ones tested?

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

On my Lemaker Bananapi the temperature is now being reported as somwhere between -15?C to -10?C with the latest Kernel 4.1.0. These negative values are obviously way off. On Kernel 4.0.5 the temperature reading was usually around 40?C. While that might not have been accurate either, it was at least plausible.

The temperature curve for the A20 SoC was not changed, if it did change then you're using an old dtb file with a new kernel, you must always update your dtb file together with the kernel.

Umm, we should keep compatibility with old DTS...

Right, unfortunately that is not always possible, and with sunxi boards the dtb is always shipped together with the kernel, and the dtb as ABI rule really is intended for the case where the dtb ships with the board/firmware.

That does not mean that we can go and break it every other day, but the problem in this case is that we shipped a dts for all boards with a compatible of allwinner,sun4i-a10-ts, and then later on we found out that the temperature curve for the build in temp sensor is different for the A10 compared to the A13/A20, so we adjusted the kernel driver to have 2 temperature curves, 1 for the A10 and one for the later models, and adjusted the compatible in the dts for later models to allwinner,sun5i-a13-ts, note that the actual touchscreen functionality is unchanged and works fine with both compatibles, the only thing which is happening now is that Timo is seeing a different temperature because he is using the new A10 temperature curve on his A20, other then that everything still works 100%, and there really was no other way to deal with this.

Let me also reply to one of Timo's later mails here, as that explains the real problem:

On 23-06-15 23:06, m.silentcreek at gmail.com wrote:> Hi again,

Quoted 2 lines

Am Dienstag, 23. Juni 2015 21:46:25 UTC+2 schrieb Hans de Goede:

<snip>

Quoted 9 lines
Quoted 5 lines
Quoted 1 line

On my Lemaker Bananapi the temperature is now being reported as somwhere between -15?C to -10?C with the latest Kernel 4.1.0. These negative values are obviously way off. On Kernel 4.0.5 the temperature reading was usually around 40?C. While that might not have been accurate either, it was at least plausible.

The temperature curve for the A20 SoC was not changed, if it did change then you're using an old dtb file with a new kernel, you must always update your dtb file together with the kernel.

I just checked the diff for Linux 4.0 and 4.1 and noticed that sun7i-a20.dtsi in fact has not changed. Is it possible that something that should have been merged got delayed?

I looked in Maxime's tree "dt-for-4.2" and found this patch that looks like it could be related: https://git.kernel.org/cgit/linux/kernel/git/mripard/linux.git/commit/?h=sunxi/dt-for-4.2&id=8bf1b9b3d90194a174493febc731f7783f2adf1a

Ah yes, something went wrong during the 4.1 cycle wrt merging ARM patches which have caused almost all ARM patches intended for 4.1 to get delayed to 4.2, including that one, that is the problem.

We did our best to update the driver and the dts in lockstep, and you should have never seen this problem, but the missing of the merge window for all ARM patches during the 4.1 cycle has caused our carefully planned lock-step update to fail, sorry about that.

Maxime I think we should send the mentioned dts patch to stable for 4.1 , do you agree ?

Regards,

Hans

#6 lore raw

PATCH 1/1 touchscreen: sun4i-ts: Really fix A10 temperature reporting

Hi,

Quoted 2 lines · Hans de Goede

Maxime I think we should send the mentioned dts patch to stable for 4.1 , do you agree ?

Yep. We should definitely do that. You take care of this?

Maxime

Signature · 10 lines
Maxime Ripard, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150624/69db289c/attachment.sig>
#7 lore raw

PATCH 1/1 touchscreen: sun4i-ts: Really fix A10 temperature reporting

Hi,

Quoted 7 lines · Maxime Ripard

Hi,

Quoted 2 lines · Hans de Goede

Maxime I think we should send the mentioned dts patch to stable for 4.1 , do you agree ?

Yep. We should definitely do that. You take care of this?

Yes I'll try to do so later today.

Regards,

Hans

A message that is not in the archive (sent off-list or not yet received): [email protected]

#9 lore raw

Hi Hans,

On Wed, Jun 24, 2015 at 9:16 AM, Hans de Goede <[email protected]> wrote:

Ah yes, something went wrong during the 4.1 cycle wrt merging ARM patches

Quoted 9 lines

which have caused almost all ARM patches intended for 4.1 to get delayed to 4.2, including that one, that is the problem.

We did our best to update the driver and the dts in lockstep, and you should
have never seen this problem, but the missing of the merge window for all ARM patches during the 4.1 cycle has caused our carefully planned lock-step update to fail, sorry about that.

No need to apologize. Things happen. Glad to see this cleared up so quickly.

Thanks for the help (and all the other work you do ;)).

Kind regards,

Timo

Signature · 3 lines
You received this message because you are subscribed to the Google Groups "linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to linux-sunxi+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected]
For more options, visit https://groups.google.com/d/optout.
#10 lore raw

PATCH 1/1 touchscreen: sun4i-ts: Really fix A10 temperature reporting

In reply to Hans de Goede

Hi,

Am Dienstag, 23. Juni 2015 21:46:25 UTC+2 schrieb Hans de Goede:

Quoted 5 lines

Hi,

Quoted 2 lines · m.silentcreek at gmail.com

Hi Hans,

Quoted 7 lines
Quoted 3 lines

is it possible that this patch (and the parent commit "Input: sun4i-ts - allow controlling filter and sensitivity via DT") has quite an adversial effect on other boards than the ones tested?

On my Lemaker Bananapi the temperature is now being reported as somwhere between -15?C to -10?C with the latest Kernel 4.1.0. These negative values are obviously way off. On Kernel 4.0.5 the temperature reading was usually around 40?C. While that might not have been accurate either, it was at least plausible.

The temperature curve for the A20 SoC was not changed, if it did change then you're using an old dtb file with a new kernel, you must always update your dtb file together with the kernel.

I always compile the dts that comes with the kernel tree from scratch. So this is up to date. I guess I have to dig in deeper then what caused that change. Any other hint where to look for?

Quoted 85 lines
Quoted 85 lines

Given that there is no Documentation and things seem quite board-specific, I really don't know how this could be improved, so I can merely report my observation.

Kind regards,

Timo

Am Montag, 9. M?rz 2015 10:38:02 UTC+1 schrieb Hans de Goede:

Quoted 73 lines

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.

---
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(-)
drivers/input/touchscreen/sun4i-ts.c +7 -7
index 66ccd5a..178d2ef 100644
@@ -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;
  	}
 
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

--
2.3.1

Regards,

Hans

Thanks,

Timo

#11 lore raw

PATCH 1/1 touchscreen: sun4i-ts: Really fix A10 temperature reporting

In reply to Hans de Goede

Hi again,

Am Dienstag, 23. Juni 2015 21:46:25 UTC+2 schrieb Hans de Goede:

Quoted 5 lines

Hi,

Quoted 2 lines · m.silentcreek at gmail.com

Hi Hans,

Quoted 7 lines
Quoted 3 lines

is it possible that this patch (and the parent commit "Input: sun4i-ts - allow controlling filter and sensitivity via DT") has quite an adversial effect on other boards than the ones tested?

On my Lemaker Bananapi the temperature is now being reported as somwhere between -15?C to -10?C with the latest Kernel 4.1.0. These negative values are obviously way off. On Kernel 4.0.5 the temperature reading was usually around 40?C. While that might not have been accurate either, it was at least plausible.

The temperature curve for the A20 SoC was not changed, if it did change then you're using an old dtb file with a new kernel, you must always update your dtb file together with the kernel.

I just checked the diff for Linux 4.0 and 4.1 and noticed that sun7i-a20.dtsi in fact has not changed. Is it possible that something that should have been merged got delayed?

I looked in Maxime's tree "dt-for-4.2" and found this patch that looks like it could be related: https://git.kernel.org/cgit/linux/kernel/git/mripard/linux.git/commit/?h=sunxi/dt-for-4.2&id=8bf1b9b3d90194a174493febc731f7783f2adf1a

Quoted 85 lines
Quoted 85 lines

Given that there is no Documentation and things seem quite board-specific, I really don't know how this could be improved, so I can merely report my observation.

Kind regards,

Timo

Am Montag, 9. M?rz 2015 10:38:02 UTC+1 schrieb Hans de Goede:

Quoted 73 lines

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.

---
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(-)
drivers/input/touchscreen/sun4i-ts.c +7 -7
index 66ccd5a..178d2ef 100644
@@ -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;
  	}
 
Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

--
2.3.1

Regards,

Hans

Regards,

Timo