Skip to content

Commit

Permalink
hwmon: (sht15) Fix sht15_calc_temp interpolation function
Browse files Browse the repository at this point in the history
I discovered two issues.
First the previous sht15_calc_temp() loop did not iterate through the
temppoints array since the (data->supply_uV > temppoints[i - 1].vdd)
test is always true in this direction.

Also the two-points linear interpolation function was returning biased
values due to a stray division by 1000 which shouldn't be there.

[JD: Also change the default value for d1 from 0 to something saner.]

Signed-off-by: Jerome Oufella <jerome.oufella@savoirfairelinux.com>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: stable@kernel.org
  • Loading branch information
joufellasfl authored and Jean Delvare committed Apr 14, 2010
1 parent 2ba3abd commit 328a2c2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/hwmon/sht15.c
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ static int sht15_update_vals(struct sht15_data *data)
**/
static inline int sht15_calc_temp(struct sht15_data *data)
{
int d1 = 0;
int d1 = temppoints[0].d1;
int i;

for (i = 1; i < ARRAY_SIZE(temppoints); i++)
for (i = ARRAY_SIZE(temppoints) - 1; i > 0; i--)
/* Find pointer to interpolate */
if (data->supply_uV > temppoints[i - 1].vdd) {
d1 = (data->supply_uV/1000 - temppoints[i - 1].vdd)
d1 = (data->supply_uV - temppoints[i - 1].vdd)
* (temppoints[i].d1 - temppoints[i - 1].d1)
/ (temppoints[i].vdd - temppoints[i - 1].vdd)
+ temppoints[i - 1].d1;
Expand Down

0 comments on commit 328a2c2

Please sign in to comment.