hwmon: (lm90) Add support for unsigned and signed temperatures
authorGuenter Roeck <linux@roeck-us.net>
Sat, 4 Dec 2021 15:53:00 +0000 (07:53 -0800)
committerGuenter Roeck <linux@roeck-us.net>
Wed, 13 Jul 2022 15:38:17 +0000 (08:38 -0700)
commitb2644494a4c7145a05af01bee1df8549a71efc20
tree5bd3cddca1bc5cbf92ddc5966a51db9b9bd86a1c
parentd70fa73d84337e7197336e137e221d93792844f7
hwmon: (lm90) Add support for unsigned and signed temperatures

ADT7461 and TMP451 temperature sensors support extended temperature ranges.
If standard temperature range is selected, the temperature range is
unsigned and limited to 0 .. 127 degrees C. For TMP461, the standard
temperature range is -128000 ... 127000 degrees C. Distinguish between
the two chips by introducing a feature flag indicating if the standard
temperature range is signed or unsigned. Use the same flag for MAX6646/
MAX6647 as well since those chips also support unsigned temperatures.

Note that while the datasheet for ADT7461 suggests that the default
temperature range is unsigned, tests with a real chip suggest that this
is not the case: If the temperature offset is set to a value << 0,
the temperature register does report negative values.

Tests with real chips show that MAX6680/MAX6681 and SA56004 report
temperatures of 128 degrees C and higher as negative temperatures.
Add respective comments to the code.

Also use clamp_val() and DIV_ROUND_CLOSEST where appropriate in
calculations.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
drivers/hwmon/lm90.c