hwmon: (lm90) Fix handling of hysteresis value

There are several problems in the way the hysteresis value is handled
by the lm90 driver:

* In show_temphyst(), specific handling of the MAX6646 is missing, so
the hysteresis is reported incorrectly if the critical temperature
is over 127 degrees C.
* In set_temphyst(), the new hysteresis register value is written to
the chip but data->temp_hyst isn't updated accordingly, so there is
a short period of time (up to 2 seconds) where the old hystereris
value will be returned while the new one is already active.
* In set_temphyst(), the critical temperature which is used as a base
to compute the value of the hysteresis register lacks
device-specific handling. As a result, the value of the hysteresis
register might be incorrect for the ADT7461 and MAX6646 chips.

Fix these 3 bugs.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Ben Hutchings <bhutchings@solarflare.com>
Cc: Nate Case <ncase@xes-inc.com>

+12 -3
+12 -3
drivers/hwmon/lm90.c
··· 461 461 462 462 if (data->kind == adt7461) 463 463 temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); 464 + else if (data->kind == max6646) 465 + temp = temp_from_u8(data->temp8[attr->index]); 464 466 else 465 467 temp = temp_from_s8(data->temp8[attr->index]); 466 468 ··· 475 473 struct i2c_client *client = to_i2c_client(dev); 476 474 struct lm90_data *data = i2c_get_clientdata(client); 477 475 long val = simple_strtol(buf, NULL, 10); 478 - long hyst; 476 + int temp; 479 477 480 478 mutex_lock(&data->update_lock); 481 - hyst = temp_from_s8(data->temp8[2]) - val; 479 + if (data->kind == adt7461) 480 + temp = temp_from_u8_adt7461(data, data->temp8[2]); 481 + else if (data->kind == max6646) 482 + temp = temp_from_u8(data->temp8[2]); 483 + else 484 + temp = temp_from_s8(data->temp8[2]); 485 + 486 + data->temp_hyst = hyst_to_reg(temp - val); 482 487 i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST, 483 - hyst_to_reg(hyst)); 488 + data->temp_hyst); 484 489 mutex_unlock(&data->update_lock); 485 490 return count; 486 491 }