hwmon: (lm85) Make the pwmN_enable files writable

Make the pwmN_enable files writable. This makes it possible to use
standard fan speed control tools (pwmconfig, fancontrol) with the lm85
driver.

I left the non-standard pwmN_auto_channels files in place, as they
give additional control for the automatic mode, and some users might
be used to them by now.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>

authored by Jean Delvare and committed by Mark M. Hoffman 455f791e 4b4df95d

+38 -2
+38 -2
drivers/hwmon/lm85.c
··· 536 536 return sprintf(buf, "%d\n", enable); 537 537 } 538 538 539 + static ssize_t set_pwm_enable(struct device *dev, struct device_attribute 540 + *attr, const char *buf, size_t count) 541 + { 542 + int nr = to_sensor_dev_attr(attr)->index; 543 + struct i2c_client *client = to_i2c_client(dev); 544 + struct lm85_data *data = i2c_get_clientdata(client); 545 + long val = simple_strtol(buf, NULL, 10); 546 + u8 config; 547 + 548 + switch (val) { 549 + case 0: 550 + config = 3; 551 + break; 552 + case 1: 553 + config = 7; 554 + break; 555 + case 2: 556 + /* Here we have to choose arbitrarily one of the 5 possible 557 + configurations; I go for the safest */ 558 + config = 6; 559 + break; 560 + default: 561 + return -EINVAL; 562 + } 563 + 564 + mutex_lock(&data->update_lock); 565 + data->autofan[nr].config = lm85_read_value(client, 566 + LM85_REG_AFAN_CONFIG(nr)); 567 + data->autofan[nr].config = (data->autofan[nr].config & ~0xe0) 568 + | (config << 5); 569 + lm85_write_value(client, LM85_REG_AFAN_CONFIG(nr), 570 + data->autofan[nr].config); 571 + mutex_unlock(&data->update_lock); 572 + return count; 573 + } 574 + 539 575 #define show_pwm_reg(offset) \ 540 576 static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ 541 577 show_pwm, set_pwm, offset - 1); \ 542 - static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO, \ 543 - show_pwm_enable, NULL, offset - 1) 578 + static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ 579 + show_pwm_enable, set_pwm_enable, offset - 1) 544 580 545 581 show_pwm_reg(1); 546 582 show_pwm_reg(2);