hwmon: (w83627hf) Add individual alarm and beep files

The new libsensors needs these individual alarm and beep files. The
code was copied from the w83781d driver. I've tested the alarm files
on a W83627THF. I couldn't test the beep files as the system in
question doesn't have a speaker.

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 e3604c62 ef878b11

+139 -3
+139 -3
drivers/hwmon/w83627hf.c
··· 717 717 } 718 718 static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 719 719 720 + static ssize_t 721 + show_alarm(struct device *dev, struct device_attribute *attr, char *buf) 722 + { 723 + struct w83627hf_data *data = w83627hf_update_device(dev); 724 + int bitnr = to_sensor_dev_attr(attr)->index; 725 + return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); 726 + } 727 + static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); 728 + static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); 729 + static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); 730 + static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); 731 + static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8); 732 + static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9); 733 + static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 10); 734 + static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16); 735 + static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17); 736 + static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); 737 + static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); 738 + static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11); 739 + static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); 740 + static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); 741 + static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13); 742 + 720 743 #define show_beep_reg(REG, reg) \ 721 744 static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ 722 745 { \ ··· 799 776 800 777 sysfs_beep(ENABLE, enable); 801 778 sysfs_beep(MASK, mask); 779 + 780 + static ssize_t 781 + show_beep(struct device *dev, struct device_attribute *attr, char *buf) 782 + { 783 + struct w83627hf_data *data = w83627hf_update_device(dev); 784 + int bitnr = to_sensor_dev_attr(attr)->index; 785 + return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1); 786 + } 787 + 788 + static ssize_t 789 + store_beep(struct device *dev, struct device_attribute *attr, 790 + const char *buf, size_t count) 791 + { 792 + struct w83627hf_data *data = dev_get_drvdata(dev); 793 + int bitnr = to_sensor_dev_attr(attr)->index; 794 + unsigned long bit; 795 + u8 reg; 796 + 797 + bit = simple_strtoul(buf, NULL, 10); 798 + if (bit & ~1) 799 + return -EINVAL; 800 + 801 + mutex_lock(&data->update_lock); 802 + if (bit) 803 + data->beep_mask |= (1 << bitnr); 804 + else 805 + data->beep_mask &= ~(1 << bitnr); 806 + 807 + if (bitnr < 8) { 808 + reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS1); 809 + if (bit) 810 + reg |= (1 << bitnr); 811 + else 812 + reg &= ~(1 << bitnr); 813 + w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, reg); 814 + } else if (bitnr < 16) { 815 + reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2); 816 + if (bit) 817 + reg |= (1 << (bitnr - 8)); 818 + else 819 + reg &= ~(1 << (bitnr - 8)); 820 + w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, reg); 821 + } else { 822 + reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS3); 823 + if (bit) 824 + reg |= (1 << (bitnr - 16)); 825 + else 826 + reg &= ~(1 << (bitnr - 16)); 827 + w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, reg); 828 + } 829 + mutex_unlock(&data->update_lock); 830 + 831 + return count; 832 + } 833 + 834 + static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, 835 + show_beep, store_beep, 0); 836 + static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR, 837 + show_beep, store_beep, 1); 838 + static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR, 839 + show_beep, store_beep, 2); 840 + static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR, 841 + show_beep, store_beep, 3); 842 + static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR, 843 + show_beep, store_beep, 8); 844 + static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO | S_IWUSR, 845 + show_beep, store_beep, 9); 846 + static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO | S_IWUSR, 847 + show_beep, store_beep, 10); 848 + static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO | S_IWUSR, 849 + show_beep, store_beep, 16); 850 + static SENSOR_DEVICE_ATTR(in8_beep, S_IRUGO | S_IWUSR, 851 + show_beep, store_beep, 17); 852 + static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR, 853 + show_beep, store_beep, 6); 854 + static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR, 855 + show_beep, store_beep, 7); 856 + static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO | S_IWUSR, 857 + show_beep, store_beep, 11); 858 + static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, 859 + show_beep, store_beep, 4); 860 + static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR, 861 + show_beep, store_beep, 5); 862 + static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO | S_IWUSR, 863 + show_beep, store_beep, 13); 802 864 803 865 static ssize_t 804 866 show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) ··· 1185 1077 #define VIN_UNIT_ATTRS(_X_) \ 1186 1078 &sensor_dev_attr_in##_X_##_input.dev_attr.attr, \ 1187 1079 &sensor_dev_attr_in##_X_##_min.dev_attr.attr, \ 1188 - &sensor_dev_attr_in##_X_##_max.dev_attr.attr 1080 + &sensor_dev_attr_in##_X_##_max.dev_attr.attr, \ 1081 + &sensor_dev_attr_in##_X_##_alarm.dev_attr.attr, \ 1082 + &sensor_dev_attr_in##_X_##_beep.dev_attr.attr 1189 1083 1190 1084 #define FAN_UNIT_ATTRS(_X_) \ 1191 1085 &sensor_dev_attr_fan##_X_##_input.dev_attr.attr, \ 1192 1086 &sensor_dev_attr_fan##_X_##_min.dev_attr.attr, \ 1193 - &sensor_dev_attr_fan##_X_##_div.dev_attr.attr 1087 + &sensor_dev_attr_fan##_X_##_div.dev_attr.attr, \ 1088 + &sensor_dev_attr_fan##_X_##_alarm.dev_attr.attr, \ 1089 + &sensor_dev_attr_fan##_X_##_beep.dev_attr.attr 1194 1090 1195 1091 #define TEMP_UNIT_ATTRS(_X_) \ 1196 1092 &sensor_dev_attr_temp##_X_##_input.dev_attr.attr, \ 1197 1093 &sensor_dev_attr_temp##_X_##_max.dev_attr.attr, \ 1198 1094 &sensor_dev_attr_temp##_X_##_max_hyst.dev_attr.attr, \ 1199 - &sensor_dev_attr_temp##_X_##_type.dev_attr.attr 1095 + &sensor_dev_attr_temp##_X_##_type.dev_attr.attr, \ 1096 + &sensor_dev_attr_temp##_X_##_alarm.dev_attr.attr, \ 1097 + &sensor_dev_attr_temp##_X_##_beep.dev_attr.attr 1200 1098 1201 1099 static struct attribute *w83627hf_attributes[] = { 1202 1100 &dev_attr_in0_input.attr, 1203 1101 &dev_attr_in0_min.attr, 1204 1102 &dev_attr_in0_max.attr, 1103 + &sensor_dev_attr_in0_alarm.dev_attr.attr, 1104 + &sensor_dev_attr_in0_beep.dev_attr.attr, 1205 1105 VIN_UNIT_ATTRS(2), 1206 1106 VIN_UNIT_ATTRS(3), 1207 1107 VIN_UNIT_ATTRS(4), ··· 1313 1197 || (err = device_create_file(dev, 1314 1198 &sensor_dev_attr_in5_max.dev_attr)) 1315 1199 || (err = device_create_file(dev, 1200 + &sensor_dev_attr_in5_alarm.dev_attr)) 1201 + || (err = device_create_file(dev, 1202 + &sensor_dev_attr_in5_beep.dev_attr)) 1203 + || (err = device_create_file(dev, 1316 1204 &sensor_dev_attr_in6_input.dev_attr)) 1317 1205 || (err = device_create_file(dev, 1318 1206 &sensor_dev_attr_in6_min.dev_attr)) 1319 1207 || (err = device_create_file(dev, 1320 1208 &sensor_dev_attr_in6_max.dev_attr)) 1209 + || (err = device_create_file(dev, 1210 + &sensor_dev_attr_in6_alarm.dev_attr)) 1211 + || (err = device_create_file(dev, 1212 + &sensor_dev_attr_in6_beep.dev_attr)) 1321 1213 || (err = device_create_file(dev, 1322 1214 &sensor_dev_attr_pwm1_freq.dev_attr)) 1323 1215 || (err = device_create_file(dev, ··· 1340 1216 || (err = device_create_file(dev, 1341 1217 &sensor_dev_attr_in1_max.dev_attr)) 1342 1218 || (err = device_create_file(dev, 1219 + &sensor_dev_attr_in1_alarm.dev_attr)) 1220 + || (err = device_create_file(dev, 1221 + &sensor_dev_attr_in1_beep.dev_attr)) 1222 + || (err = device_create_file(dev, 1343 1223 &sensor_dev_attr_fan3_input.dev_attr)) 1344 1224 || (err = device_create_file(dev, 1345 1225 &sensor_dev_attr_fan3_min.dev_attr)) 1346 1226 || (err = device_create_file(dev, 1347 1227 &sensor_dev_attr_fan3_div.dev_attr)) 1348 1228 || (err = device_create_file(dev, 1229 + &sensor_dev_attr_fan3_alarm.dev_attr)) 1230 + || (err = device_create_file(dev, 1231 + &sensor_dev_attr_fan3_beep.dev_attr)) 1232 + || (err = device_create_file(dev, 1349 1233 &sensor_dev_attr_temp3_input.dev_attr)) 1350 1234 || (err = device_create_file(dev, 1351 1235 &sensor_dev_attr_temp3_max.dev_attr)) 1352 1236 || (err = device_create_file(dev, 1353 1237 &sensor_dev_attr_temp3_max_hyst.dev_attr)) 1238 + || (err = device_create_file(dev, 1239 + &sensor_dev_attr_temp3_alarm.dev_attr)) 1240 + || (err = device_create_file(dev, 1241 + &sensor_dev_attr_temp3_beep.dev_attr)) 1354 1242 || (err = device_create_file(dev, 1355 1243 &sensor_dev_attr_temp3_type.dev_attr))) 1356 1244 goto ERROR4;