aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm95245.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lm95245.c')
-rw-r--r--drivers/hwmon/lm95245.c31
1 files changed, 21 insertions, 10 deletions
diff --git a/drivers/hwmon/lm95245.c b/drivers/hwmon/lm95245.c
index 3f0956e18a23..a400d4c4416b 100644
--- a/drivers/hwmon/lm95245.c
+++ b/drivers/hwmon/lm95245.c
@@ -272,27 +272,38 @@ static ssize_t set_limit(struct device *dev, struct device_attribute *attr,
272 return count; 272 return count;
273} 273}
274 274
275static ssize_t show_crit_hyst(struct device *dev, struct device_attribute *attr,
276 char *buf)
277{
278 struct lm95245_data *data = lm95245_update_device(dev);
279 int index = to_sensor_dev_attr(attr)->index;
280 int hyst = data->regs[index] - data->regs[8];
281
282 return snprintf(buf, PAGE_SIZE - 1, "%d\n", hyst * 1000);
283}
284
275static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr, 285static ssize_t set_crit_hyst(struct device *dev, struct device_attribute *attr,
276 const char *buf, size_t count) 286 const char *buf, size_t count)
277{ 287{
278 struct i2c_client *client = to_i2c_client(dev); 288 struct i2c_client *client = to_i2c_client(dev);
279 struct lm95245_data *data = i2c_get_clientdata(client); 289 struct lm95245_data *data = i2c_get_clientdata(client);
290 int index = to_sensor_dev_attr(attr)->index;
280 unsigned long val; 291 unsigned long val;
292 int hyst, limit;
281 293
282 if (kstrtoul(buf, 10, &val) < 0) 294 if (kstrtoul(buf, 10, &val) < 0)
283 return -EINVAL; 295 return -EINVAL;
284 296
285 val /= 1000;
286
287 val = clamp_val(val, 0, 31);
288
289 mutex_lock(&data->update_lock); 297 mutex_lock(&data->update_lock);
290 298
291 data->valid = 0; 299 limit = i2c_smbus_read_byte_data(client, lm95245_reg_address[index]);
300 hyst = limit - val / 1000;
301 hyst = clamp_val(hyst, 0, 31);
302 data->regs[8] = hyst;
292 303
293 /* shared crit hysteresis */ 304 /* shared crit hysteresis */
294 i2c_smbus_write_byte_data(client, LM95245_REG_RW_COMMON_HYSTERESIS, 305 i2c_smbus_write_byte_data(client, LM95245_REG_RW_COMMON_HYSTERESIS,
295 val); 306 hyst);
296 307
297 mutex_unlock(&data->update_lock); 308 mutex_unlock(&data->update_lock);
298 309
@@ -378,16 +389,16 @@ static ssize_t set_interval(struct device *dev, struct device_attribute *attr,
378static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0); 389static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_input, NULL, 0);
379static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_limit, 390static SENSOR_DEVICE_ATTR(temp1_crit, S_IWUSR | S_IRUGO, show_limit,
380 set_limit, 6); 391 set_limit, 6);
381static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_limit, 392static SENSOR_DEVICE_ATTR(temp1_crit_hyst, S_IWUSR | S_IRUGO, show_crit_hyst,
382 set_crit_hyst, 8); 393 set_crit_hyst, 6);
383static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL, 394static SENSOR_DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL,
384 STATUS1_LOC); 395 STATUS1_LOC);
385 396
386static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2); 397static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_input, NULL, 2);
387static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_limit, 398static SENSOR_DEVICE_ATTR(temp2_crit, S_IWUSR | S_IRUGO, show_limit,
388 set_limit, 7); 399 set_limit, 7);
389static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_limit, 400static SENSOR_DEVICE_ATTR(temp2_crit_hyst, S_IWUSR | S_IRUGO, show_crit_hyst,
390 set_crit_hyst, 8); 401 set_crit_hyst, 7);
391static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL, 402static SENSOR_DEVICE_ATTR(temp2_crit_alarm, S_IRUGO, show_alarm, NULL,
392 STATUS1_RTCRIT); 403 STATUS1_RTCRIT);
393static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type, 404static SENSOR_DEVICE_ATTR(temp2_type, S_IWUSR | S_IRUGO, show_type,