summaryrefslogtreecommitdiff
path: root/drivers/hwmon
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/ntc_thermistor.c20
1 files changed, 11 insertions, 9 deletions
diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index 18fd6f12ca16..cf26c44f2b88 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -13,6 +13,7 @@
#include <linux/err.h>
#include <linux/of.h>
#include <linux/of_device.h>
+#include <linux/fixp-arith.h>
#include <linux/platform_data/ntc_thermistor.h>
@@ -549,15 +550,16 @@ static int get_temp_mc(struct ntc_data *data, unsigned int ohm)
int temp;
lookup_comp(data, ohm, &low, &high);
- if (low == high) {
- /* Unable to use linear approximation */
- temp = data->comp[low].temp_c * 1000;
- } else {
- temp = data->comp[low].temp_c * 1000 +
- ((data->comp[high].temp_c - data->comp[low].temp_c) *
- 1000 * ((int)ohm - (int)data->comp[low].ohm)) /
- ((int)data->comp[high].ohm - (int)data->comp[low].ohm);
- }
+ /*
+ * First multiplying the table temperatures with 1000 to get to
+ * millicentigrades (which is what we want) and then interpolating
+ * will give the best precision.
+ */
+ temp = fixp_linear_interpolate(data->comp[low].ohm,
+ data->comp[low].temp_c * 1000,
+ data->comp[high].ohm,
+ data->comp[high].temp_c * 1000,
+ ohm);
return temp;
}