armada thermal issues with negative temperatures
Subsystems (2)
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(-)
(quoted diff) +0 -0
b/drivers/thermal/armada_thermal.c
index ae75328..ad8b88c 100644
drivers/thermal/armada_thermal.c +0 -0
@@ -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
Signature · 1 line
Damien Th?bault