Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: sun4i-ts - really fix A10 temperature reporting

The commit titled: "Input: 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>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Hans de Goede and committed by
Dmitry Torokhov
877bef7d b6310aff

+7 -7
+7 -7
drivers/input/touchscreen/sun4i-ts.c
··· 193 193 if (ts->temp_data == -1) 194 194 return -EAGAIN; 195 195 196 - *temp = (ts->temp_data - ts->temp_offset) * ts->temp_step; 196 + *temp = ts->temp_data * ts->temp_step - ts->temp_offset; 197 197 198 198 return 0; 199 199 } ··· 255 255 ts->ignore_fifo_data = true; 256 256 ts->temp_data = -1; 257 257 if (of_device_is_compatible(np, "allwinner,sun6i-a31-ts")) { 258 - /* Allwinner SDK has temperature = -271 + (value / 6) (C) */ 259 - ts->temp_offset = 1626; 258 + /* Allwinner SDK has temperature (C) = (value / 6) - 271 */ 259 + ts->temp_offset = 271000; 260 260 ts->temp_step = 167; 261 261 } else if (of_device_is_compatible(np, "allwinner,sun4i-a10-ts")) { 262 262 /* 263 263 * The A10 temperature sensor has quite a wide spread, these 264 264 * parameters are based on the averaging of the calibration 265 265 * results of 4 completely different boards, with a spread of 266 - * temp_step from 96 - 170 and temp_offset from 1758 - 3310. 266 + * temp_step from 0.096 - 0.170 and temp_offset from 176 - 331. 267 267 */ 268 - ts->temp_offset = 2570; 268 + ts->temp_offset = 257000; 269 269 ts->temp_step = 133; 270 270 } else { 271 271 /* ··· 273 273 * the temperature. The formula used here is from the AXP209, 274 274 * which is designed by X-Powers, an affiliate of Allwinner: 275 275 * 276 - * temperature = -144.7 + (value * 0.1) 276 + * temperature (C) = (value * 0.1) - 144.7 277 277 * 278 278 * Allwinner does not have any documentation whatsoever for 279 279 * this hardware. Moreover, it is claimed that the sensor 280 280 * is inaccurate and cannot work properly. 281 281 */ 282 - ts->temp_offset = 1447; 282 + ts->temp_offset = 144700; 283 283 ts->temp_step = 100; 284 284 } 285 285