aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2007-10-08 12:29:43 -0400
committerMark M. Hoffman <mhoffman@lightlink.com>2007-10-09 22:56:32 -0400
commit7d4a137491d96927ffca5e8557c328902a2d4de9 (patch)
tree74fa2cd8439ae4d8dd46f2692bfcf22b2d274194 /drivers/hwmon
parent90d6619a916062cb75a176aacb318d108758b4a5 (diff)
hwmon: (w83781d) Add individual alarm and beep files
The upcoming libsensors 3 needs these individual alarm and beep files. For the W83781D, this is quirky because this chip has a single alarm bit for both temp2 and temp3. Signed-off-by: Jean Delvare <khali@linux-fr.org> Acked-by: Hans de Goede <j.w.r.degoede@hhs.nl> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/w83781d.c168
1 files changed, 162 insertions, 6 deletions
diff --git a/drivers/hwmon/w83781d.c b/drivers/hwmon/w83781d.c
index d2cb9978a2a2..a6a1edfe7614 100644
--- a/drivers/hwmon/w83781d.c
+++ b/drivers/hwmon/w83781d.c
@@ -481,6 +481,39 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
481 481
482static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 482static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
483 483
484static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
485 char *buf)
486{
487 struct w83781d_data *data = w83781d_update_device(dev);
488 int bitnr = to_sensor_dev_attr(attr)->index;
489 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
490}
491
492/* The W83781D has a single alarm bit for temp2 and temp3 */
493static ssize_t show_temp3_alarm(struct device *dev,
494 struct device_attribute *attr, char *buf)
495{
496 struct w83781d_data *data = w83781d_update_device(dev);
497 int bitnr = (data->type == w83781d) ? 5 : 13;
498 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
499}
500
501static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
502static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
503static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
504static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
505static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
506static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
507static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 10);
508static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16);
509static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17);
510static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
511static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
512static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11);
513static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
514static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
515static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_temp3_alarm, NULL, 0);
516
484static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf) 517static ssize_t show_beep_mask (struct device *dev, struct device_attribute *attr, char *buf)
485{ 518{
486 struct w83781d_data *data = w83781d_update_device(dev); 519 struct w83781d_data *data = w83781d_update_device(dev);
@@ -544,6 +577,100 @@ static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR,
544static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR, 577static DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR,
545 show_beep_enable, store_beep_enable); 578 show_beep_enable, store_beep_enable);
546 579
580static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
581 char *buf)
582{
583 struct w83781d_data *data = w83781d_update_device(dev);
584 int bitnr = to_sensor_dev_attr(attr)->index;
585 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
586}
587
588static ssize_t
589store_beep(struct device *dev, struct device_attribute *attr,
590 const char *buf, size_t count)
591{
592 struct w83781d_data *data = dev_get_drvdata(dev);
593 int bitnr = to_sensor_dev_attr(attr)->index;
594 unsigned long bit;
595 u8 reg;
596
597 bit = simple_strtoul(buf, NULL, 10);
598 if (bit & ~1)
599 return -EINVAL;
600
601 mutex_lock(&data->update_lock);
602 if (bit)
603 data->beep_mask |= (1 << bitnr);
604 else
605 data->beep_mask &= ~(1 << bitnr);
606
607 if (bitnr < 8) {
608 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS1);
609 if (bit)
610 reg |= (1 << bitnr);
611 else
612 reg &= ~(1 << bitnr);
613 w83781d_write_value(data, W83781D_REG_BEEP_INTS1, reg);
614 } else if (bitnr < 16) {
615 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS2);
616 if (bit)
617 reg |= (1 << (bitnr - 8));
618 else
619 reg &= ~(1 << (bitnr - 8));
620 w83781d_write_value(data, W83781D_REG_BEEP_INTS2, reg);
621 } else {
622 reg = w83781d_read_value(data, W83781D_REG_BEEP_INTS3);
623 if (bit)
624 reg |= (1 << (bitnr - 16));
625 else
626 reg &= ~(1 << (bitnr - 16));
627 w83781d_write_value(data, W83781D_REG_BEEP_INTS3, reg);
628 }
629 mutex_unlock(&data->update_lock);
630
631 return count;
632}
633
634/* The W83781D has a single beep bit for temp2 and temp3 */
635static ssize_t show_temp3_beep(struct device *dev,
636 struct device_attribute *attr, char *buf)
637{
638 struct w83781d_data *data = w83781d_update_device(dev);
639 int bitnr = (data->type == w83781d) ? 5 : 13;
640 return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1);
641}
642
643static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
644 show_beep, store_beep, 0);
645static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR,
646 show_beep, store_beep, 1);
647static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR,
648 show_beep, store_beep, 2);
649static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR,
650 show_beep, store_beep, 3);
651static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR,
652 show_beep, store_beep, 8);
653static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO | S_IWUSR,
654 show_beep, store_beep, 9);
655static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO | S_IWUSR,
656 show_beep, store_beep, 10);
657static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO | S_IWUSR,
658 show_beep, store_beep, 16);
659static SENSOR_DEVICE_ATTR(in8_beep, S_IRUGO | S_IWUSR,
660 show_beep, store_beep, 17);
661static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR,
662 show_beep, store_beep, 6);
663static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR,
664 show_beep, store_beep, 7);
665static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO | S_IWUSR,
666 show_beep, store_beep, 11);
667static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
668 show_beep, store_beep, 4);
669static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR,
670 show_beep, store_beep, 5);
671static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO,
672 show_temp3_beep, store_beep, 13);
673
547static ssize_t 674static ssize_t
548show_fan_div(struct device *dev, struct device_attribute *da, char *buf) 675show_fan_div(struct device *dev, struct device_attribute *da, char *buf)
549{ 676{
@@ -877,17 +1004,23 @@ ERROR_SC_0:
877#define IN_UNIT_ATTRS(X) \ 1004#define IN_UNIT_ATTRS(X) \
878 &sensor_dev_attr_in##X##_input.dev_attr.attr, \ 1005 &sensor_dev_attr_in##X##_input.dev_attr.attr, \
879 &sensor_dev_attr_in##X##_min.dev_attr.attr, \ 1006 &sensor_dev_attr_in##X##_min.dev_attr.attr, \
880 &sensor_dev_attr_in##X##_max.dev_attr.attr 1007 &sensor_dev_attr_in##X##_max.dev_attr.attr, \
1008 &sensor_dev_attr_in##X##_alarm.dev_attr.attr, \
1009 &sensor_dev_attr_in##X##_beep.dev_attr.attr
881 1010
882#define FAN_UNIT_ATTRS(X) \ 1011#define FAN_UNIT_ATTRS(X) \
883 &sensor_dev_attr_fan##X##_input.dev_attr.attr, \ 1012 &sensor_dev_attr_fan##X##_input.dev_attr.attr, \
884 &sensor_dev_attr_fan##X##_min.dev_attr.attr, \ 1013 &sensor_dev_attr_fan##X##_min.dev_attr.attr, \
885 &sensor_dev_attr_fan##X##_div.dev_attr.attr 1014 &sensor_dev_attr_fan##X##_div.dev_attr.attr, \
1015 &sensor_dev_attr_fan##X##_alarm.dev_attr.attr, \
1016 &sensor_dev_attr_fan##X##_beep.dev_attr.attr
886 1017
887#define TEMP_UNIT_ATTRS(X) \ 1018#define TEMP_UNIT_ATTRS(X) \
888 &sensor_dev_attr_temp##X##_input.dev_attr.attr, \ 1019 &sensor_dev_attr_temp##X##_input.dev_attr.attr, \
889 &sensor_dev_attr_temp##X##_max.dev_attr.attr, \ 1020 &sensor_dev_attr_temp##X##_max.dev_attr.attr, \
890 &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr 1021 &sensor_dev_attr_temp##X##_max_hyst.dev_attr.attr, \
1022 &sensor_dev_attr_temp##X##_alarm.dev_attr.attr, \
1023 &sensor_dev_attr_temp##X##_beep.dev_attr.attr
891 1024
892static struct attribute* w83781d_attributes[] = { 1025static struct attribute* w83781d_attributes[] = {
893 IN_UNIT_ATTRS(0), 1026 IN_UNIT_ATTRS(0),
@@ -946,7 +1079,11 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
946 || (err = device_create_file(dev, 1079 || (err = device_create_file(dev,
947 &sensor_dev_attr_in1_min.dev_attr)) 1080 &sensor_dev_attr_in1_min.dev_attr))
948 || (err = device_create_file(dev, 1081 || (err = device_create_file(dev,
949 &sensor_dev_attr_in1_max.dev_attr))) 1082 &sensor_dev_attr_in1_max.dev_attr))
1083 || (err = device_create_file(dev,
1084 &sensor_dev_attr_in1_alarm.dev_attr))
1085 || (err = device_create_file(dev,
1086 &sensor_dev_attr_in1_beep.dev_attr)))
950 return err; 1087 return err;
951 } 1088 }
952 if (kind != as99127f && kind != w83781d && kind != w83783s) { 1089 if (kind != as99127f && kind != w83781d && kind != w83783s) {
@@ -957,11 +1094,19 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
957 || (err = device_create_file(dev, 1094 || (err = device_create_file(dev,
958 &sensor_dev_attr_in7_max.dev_attr)) 1095 &sensor_dev_attr_in7_max.dev_attr))
959 || (err = device_create_file(dev, 1096 || (err = device_create_file(dev,
1097 &sensor_dev_attr_in7_alarm.dev_attr))
1098 || (err = device_create_file(dev,
1099 &sensor_dev_attr_in7_beep.dev_attr))
1100 || (err = device_create_file(dev,
960 &sensor_dev_attr_in8_input.dev_attr)) 1101 &sensor_dev_attr_in8_input.dev_attr))
961 || (err = device_create_file(dev, 1102 || (err = device_create_file(dev,
962 &sensor_dev_attr_in8_min.dev_attr)) 1103 &sensor_dev_attr_in8_min.dev_attr))
963 || (err = device_create_file(dev, 1104 || (err = device_create_file(dev,
964 &sensor_dev_attr_in8_max.dev_attr))) 1105 &sensor_dev_attr_in8_max.dev_attr))
1106 || (err = device_create_file(dev,
1107 &sensor_dev_attr_in8_alarm.dev_attr))
1108 || (err = device_create_file(dev,
1109 &sensor_dev_attr_in8_beep.dev_attr)))
965 return err; 1110 return err;
966 } 1111 }
967 if (kind != w83783s) { 1112 if (kind != w83783s) {
@@ -970,8 +1115,19 @@ w83781d_create_files(struct device *dev, int kind, int is_isa)
970 || (err = device_create_file(dev, 1115 || (err = device_create_file(dev,
971 &sensor_dev_attr_temp3_max.dev_attr)) 1116 &sensor_dev_attr_temp3_max.dev_attr))
972 || (err = device_create_file(dev, 1117 || (err = device_create_file(dev,
973 &sensor_dev_attr_temp3_max_hyst.dev_attr))) 1118 &sensor_dev_attr_temp3_max_hyst.dev_attr))
1119 || (err = device_create_file(dev,
1120 &sensor_dev_attr_temp3_alarm.dev_attr))
1121 || (err = device_create_file(dev,
1122 &sensor_dev_attr_temp3_beep.dev_attr)))
974 return err; 1123 return err;
1124
1125 if (kind != w83781d)
1126 err = sysfs_chmod_file(&dev->kobj,
1127 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
1128 S_IRUGO | S_IWUSR);
1129 if (err)
1130 return err;
975 } 1131 }
976 1132
977 if (kind != w83781d && kind != as99127f) { 1133 if (kind != w83781d && kind != as99127f) {