armada thermal issues with negative temperatures
Damien Thébault
damien.thebault at vitec.com
Mon May 23 07:07:49 PDT 2016
Hello,
I've been using an armada 370 SoC, and the thermal driver is reporting
erroneous values at negative temperatures.
After looking at what happened, in the armada_get_temp() function,
after applying shift and mask, we get the following values around 0°C:
- 315 (just above 0)
- 316 (just below 0)
If the code after /* Get formula coeficients */ is executed with those
two values, the first one gives the proper value of 216, but the second
one gives 310160 instead of the proper value of -506.
To have the proper final value, a signed division must be performed,
which will only be done if both operands are signed according to the C
standard, otherwise an unsigned division is done, which will provide
wrong results.
As the current coefficients are just fitting in unsigned long values,
the best fix I could find was to just cast each operand to (signed)
long.
With this fix, the temperature is the proper one, even for negative
values.
Best Regards
---
drivers/thermal/armada_thermal.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/thermal/armada_thermal.c
b/drivers/thermal/armada_thermal.c
index ae75328..ad8b88c 100644
--- a/drivers/thermal/armada_thermal.c
+++ b/drivers/thermal/armada_thermal.c
@@ -177,9 +177,9 @@ static int armada_get_temp(struct
thermal_zone_device *thermal,
div = priv->data->coef_div;
if (priv->data->inverted)
- *temp = ((m * reg) - b) / div;
+ *temp = (long)((m * reg) - b) / (long)div;
else
- *temp = (b - (m * reg)) / div;
+ *temp = (long)(b - (m * reg)) / (long)div;
return 0;
}
--
2.8.2
--
Damien Thébault
More information about the linux-arm-kernel
mailing list