Commit ec38fa2b authored by Jean Delvare's avatar Jean Delvare

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: default avatarJean Delvare <khali@linux-fr.org>
Cc: Ben Hutchings <bhutchings@solarflare.com>
Cc: Nate Case <ncase@xes-inc.com>
parent 1b871826
...@@ -461,6 +461,8 @@ static ssize_t show_temphyst(struct device *dev, struct device_attribute *devatt ...@@ -461,6 +461,8 @@ static ssize_t show_temphyst(struct device *dev, struct device_attribute *devatt
if (data->kind == adt7461) if (data->kind == adt7461)
temp = temp_from_u8_adt7461(data, data->temp8[attr->index]); temp = temp_from_u8_adt7461(data, data->temp8[attr->index]);
else if (data->kind == max6646)
temp = temp_from_u8(data->temp8[attr->index]);
else else
temp = temp_from_s8(data->temp8[attr->index]); temp = temp_from_s8(data->temp8[attr->index]);
...@@ -473,12 +475,19 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy, ...@@ -473,12 +475,19 @@ static ssize_t set_temphyst(struct device *dev, struct device_attribute *dummy,
struct i2c_client *client = to_i2c_client(dev); struct i2c_client *client = to_i2c_client(dev);
struct lm90_data *data = i2c_get_clientdata(client); struct lm90_data *data = i2c_get_clientdata(client);
long val = simple_strtol(buf, NULL, 10); long val = simple_strtol(buf, NULL, 10);
long hyst; int temp;
mutex_lock(&data->update_lock); mutex_lock(&data->update_lock);
hyst = temp_from_s8(data->temp8[2]) - val; if (data->kind == adt7461)
temp = temp_from_u8_adt7461(data, data->temp8[2]);
else if (data->kind == max6646)
temp = temp_from_u8(data->temp8[2]);
else
temp = temp_from_s8(data->temp8[2]);
data->temp_hyst = hyst_to_reg(temp - val);
i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST, i2c_smbus_write_byte_data(client, LM90_REG_W_TCRIT_HYST,
hyst_to_reg(hyst)); data->temp_hyst);
mutex_unlock(&data->update_lock); mutex_unlock(&data->update_lock);
return count; return count;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment