aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83791d.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/w83791d.c')
-rw-r--r--drivers/hwmon/w83791d.c134
1 files changed, 124 insertions, 10 deletions
diff --git a/drivers/hwmon/w83791d.c b/drivers/hwmon/w83791d.c
index 9e5f885368b4..b6f2ebf9f9cf 100644
--- a/drivers/hwmon/w83791d.c
+++ b/drivers/hwmon/w83791d.c
@@ -2,7 +2,7 @@
2 w83791d.c - Part of lm_sensors, Linux kernel modules for hardware 2 w83791d.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 monitoring
4 4
5 Copyright (C) 2006 Charles Spirakis <bezaur@gmail.com> 5 Copyright (C) 2006-2007 Charles Spirakis <bezaur@gmail.com>
6 6
7 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
@@ -247,7 +247,7 @@ static u8 div_to_reg(int nr, long val)
247 247
248struct w83791d_data { 248struct w83791d_data {
249 struct i2c_client client; 249 struct i2c_client client;
250 struct class_device *class_dev; 250 struct device *hwmon_dev;
251 struct mutex update_lock; 251 struct mutex update_lock;
252 252
253 char valid; /* !=0 if following fields are valid */ 253 char valid; /* !=0 if following fields are valid */
@@ -384,6 +384,85 @@ static struct sensor_device_attribute sda_in_max[] = {
384 SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9), 384 SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9),
385}; 385};
386 386
387
388static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
389 char *buf)
390{
391 struct sensor_device_attribute *sensor_attr =
392 to_sensor_dev_attr(attr);
393 struct w83791d_data *data = w83791d_update_device(dev);
394 int bitnr = sensor_attr->index;
395
396 return sprintf(buf, "%d\n", (data->beep_mask >> bitnr) & 1);
397}
398
399static ssize_t store_beep(struct device *dev, struct device_attribute *attr,
400 const char *buf, size_t count)
401{
402 struct sensor_device_attribute *sensor_attr =
403 to_sensor_dev_attr(attr);
404 struct i2c_client *client = to_i2c_client(dev);
405 struct w83791d_data *data = i2c_get_clientdata(client);
406 int bitnr = sensor_attr->index;
407 int bytenr = bitnr / 8;
408 long val = simple_strtol(buf, NULL, 10) ? 1 : 0;
409
410 mutex_lock(&data->update_lock);
411
412 data->beep_mask &= ~(0xff << (bytenr * 8));
413 data->beep_mask |= w83791d_read(client, W83791D_REG_BEEP_CTRL[bytenr])
414 << (bytenr * 8);
415
416 data->beep_mask &= ~(1 << bitnr);
417 data->beep_mask |= val << bitnr;
418
419 w83791d_write(client, W83791D_REG_BEEP_CTRL[bytenr],
420 (data->beep_mask >> (bytenr * 8)) & 0xff);
421
422 mutex_unlock(&data->update_lock);
423
424 return count;
425}
426
427static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
428 char *buf)
429{
430 struct sensor_device_attribute *sensor_attr =
431 to_sensor_dev_attr(attr);
432 struct w83791d_data *data = w83791d_update_device(dev);
433 int bitnr = sensor_attr->index;
434
435 return sprintf(buf, "%d\n", (data->alarms >> bitnr) & 1);
436}
437
438/* Note: The bitmask for the beep enable/disable is different than
439 the bitmask for the alarm. */
440static struct sensor_device_attribute sda_in_beep[] = {
441 SENSOR_ATTR(in0_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 0),
442 SENSOR_ATTR(in1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 13),
443 SENSOR_ATTR(in2_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 2),
444 SENSOR_ATTR(in3_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 3),
445 SENSOR_ATTR(in4_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 8),
446 SENSOR_ATTR(in5_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 9),
447 SENSOR_ATTR(in6_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 10),
448 SENSOR_ATTR(in7_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 16),
449 SENSOR_ATTR(in8_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 17),
450 SENSOR_ATTR(in9_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 14),
451};
452
453static struct sensor_device_attribute sda_in_alarm[] = {
454 SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0),
455 SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1),
456 SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2),
457 SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3),
458 SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8),
459 SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9),
460 SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 10),
461 SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 19),
462 SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 20),
463 SENSOR_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 14),
464};
465
387#define show_fan_reg(reg) \ 466#define show_fan_reg(reg) \
388static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ 467static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \
389 char *buf) \ 468 char *buf) \
@@ -536,6 +615,22 @@ static struct sensor_device_attribute sda_fan_div[] = {
536 show_fan_div, store_fan_div, 4), 615 show_fan_div, store_fan_div, 4),
537}; 616};
538 617
618static struct sensor_device_attribute sda_fan_beep[] = {
619 SENSOR_ATTR(fan1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 6),
620 SENSOR_ATTR(fan2_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 7),
621 SENSOR_ATTR(fan3_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 11),
622 SENSOR_ATTR(fan4_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 21),
623 SENSOR_ATTR(fan5_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 22),
624};
625
626static struct sensor_device_attribute sda_fan_alarm[] = {
627 SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6),
628 SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7),
629 SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11),
630 SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 21),
631 SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 22),
632};
633
539/* read/write the temperature1, includes measured value and limits */ 634/* read/write the temperature1, includes measured value and limits */
540static ssize_t show_temp1(struct device *dev, struct device_attribute *devattr, 635static ssize_t show_temp1(struct device *dev, struct device_attribute *devattr,
541 char *buf) 636 char *buf)
@@ -618,6 +713,19 @@ static struct sensor_device_attribute_2 sda_temp_max_hyst[] = {
618 show_temp23, store_temp23, 1, 2), 713 show_temp23, store_temp23, 1, 2),
619}; 714};
620 715
716/* Note: The bitmask for the beep enable/disable is different than
717 the bitmask for the alarm. */
718static struct sensor_device_attribute sda_temp_beep[] = {
719 SENSOR_ATTR(temp1_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 4),
720 SENSOR_ATTR(temp2_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 5),
721 SENSOR_ATTR(temp3_beep, S_IWUSR | S_IRUGO, show_beep, store_beep, 1),
722};
723
724static struct sensor_device_attribute sda_temp_alarm[] = {
725 SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4),
726 SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5),
727 SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13),
728};
621 729
622/* get reatime status of all sensors items: voltage, temp, fan */ 730/* get reatime status of all sensors items: voltage, temp, fan */
623static ssize_t show_alarms_reg(struct device *dev, 731static ssize_t show_alarms_reg(struct device *dev,
@@ -724,7 +832,7 @@ static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
724static ssize_t show_vrm_reg(struct device *dev, 832static ssize_t show_vrm_reg(struct device *dev,
725 struct device_attribute *attr, char *buf) 833 struct device_attribute *attr, char *buf)
726{ 834{
727 struct w83791d_data *data = w83791d_update_device(dev); 835 struct w83791d_data *data = dev_get_drvdata(dev);
728 return sprintf(buf, "%d\n", data->vrm); 836 return sprintf(buf, "%d\n", data->vrm);
729} 837}
730 838
@@ -749,17 +857,23 @@ static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
749#define IN_UNIT_ATTRS(X) \ 857#define IN_UNIT_ATTRS(X) \
750 &sda_in_input[X].dev_attr.attr, \ 858 &sda_in_input[X].dev_attr.attr, \
751 &sda_in_min[X].dev_attr.attr, \ 859 &sda_in_min[X].dev_attr.attr, \
752 &sda_in_max[X].dev_attr.attr 860 &sda_in_max[X].dev_attr.attr, \
861 &sda_in_beep[X].dev_attr.attr, \
862 &sda_in_alarm[X].dev_attr.attr
753 863
754#define FAN_UNIT_ATTRS(X) \ 864#define FAN_UNIT_ATTRS(X) \
755 &sda_fan_input[X].dev_attr.attr, \ 865 &sda_fan_input[X].dev_attr.attr, \
756 &sda_fan_min[X].dev_attr.attr, \ 866 &sda_fan_min[X].dev_attr.attr, \
757 &sda_fan_div[X].dev_attr.attr 867 &sda_fan_div[X].dev_attr.attr, \
868 &sda_fan_beep[X].dev_attr.attr, \
869 &sda_fan_alarm[X].dev_attr.attr
758 870
759#define TEMP_UNIT_ATTRS(X) \ 871#define TEMP_UNIT_ATTRS(X) \
760 &sda_temp_input[X].dev_attr.attr, \ 872 &sda_temp_input[X].dev_attr.attr, \
761 &sda_temp_max[X].dev_attr.attr, \ 873 &sda_temp_max[X].dev_attr.attr, \
762 &sda_temp_max_hyst[X].dev_attr.attr 874 &sda_temp_max_hyst[X].dev_attr.attr, \
875 &sda_temp_beep[X].dev_attr.attr, \
876 &sda_temp_alarm[X].dev_attr.attr
763 877
764static struct attribute *w83791d_attributes[] = { 878static struct attribute *w83791d_attributes[] = {
765 IN_UNIT_ATTRS(0), 879 IN_UNIT_ATTRS(0),
@@ -1017,9 +1131,9 @@ static int w83791d_detect(struct i2c_adapter *adapter, int address, int kind)
1017 goto error3; 1131 goto error3;
1018 1132
1019 /* Everything is ready, now register the working device */ 1133 /* Everything is ready, now register the working device */
1020 data->class_dev = hwmon_device_register(dev); 1134 data->hwmon_dev = hwmon_device_register(dev);
1021 if (IS_ERR(data->class_dev)) { 1135 if (IS_ERR(data->hwmon_dev)) {
1022 err = PTR_ERR(data->class_dev); 1136 err = PTR_ERR(data->hwmon_dev);
1023 goto error4; 1137 goto error4;
1024 } 1138 }
1025 1139
@@ -1051,7 +1165,7 @@ static int w83791d_detach_client(struct i2c_client *client)
1051 1165
1052 /* main client */ 1166 /* main client */
1053 if (data) { 1167 if (data) {
1054 hwmon_device_unregister(data->class_dev); 1168 hwmon_device_unregister(data->hwmon_dev);
1055 sysfs_remove_group(&client->dev.kobj, &w83791d_group); 1169 sysfs_remove_group(&client->dev.kobj, &w83791d_group);
1056 } 1170 }
1057 1171