aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83627hf.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/w83627hf.c')
-rw-r--r--drivers/hwmon/w83627hf.c232
1 files changed, 138 insertions, 94 deletions
diff --git a/drivers/hwmon/w83627hf.c b/drivers/hwmon/w83627hf.c
index 30295028ea99..dfdc29c77123 100644
--- a/drivers/hwmon/w83627hf.c
+++ b/drivers/hwmon/w83627hf.c
@@ -512,13 +512,6 @@ static DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR,
512static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, 512static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR,
513 show_regs_in_max0, store_regs_in_max0); 513 show_regs_in_max0, store_regs_in_max0);
514 514
515#define device_create_file_in(client, offset) \
516do { \
517device_create_file(&client->dev, &dev_attr_in##offset##_input); \
518device_create_file(&client->dev, &dev_attr_in##offset##_min); \
519device_create_file(&client->dev, &dev_attr_in##offset##_max); \
520} while (0)
521
522#define show_fan_reg(reg) \ 515#define show_fan_reg(reg) \
523static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 516static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
524{ \ 517{ \
@@ -576,12 +569,6 @@ sysfs_fan_min_offset(2);
576sysfs_fan_offset(3); 569sysfs_fan_offset(3);
577sysfs_fan_min_offset(3); 570sysfs_fan_min_offset(3);
578 571
579#define device_create_file_fan(client, offset) \
580do { \
581device_create_file(&client->dev, &dev_attr_fan##offset##_input); \
582device_create_file(&client->dev, &dev_attr_fan##offset##_min); \
583} while (0)
584
585#define show_temp_reg(reg) \ 572#define show_temp_reg(reg) \
586static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ 573static ssize_t show_##reg (struct device *dev, char *buf, int nr) \
587{ \ 574{ \
@@ -656,13 +643,6 @@ sysfs_temp_offsets(1);
656sysfs_temp_offsets(2); 643sysfs_temp_offsets(2);
657sysfs_temp_offsets(3); 644sysfs_temp_offsets(3);
658 645
659#define device_create_file_temp(client, offset) \
660do { \
661device_create_file(&client->dev, &dev_attr_temp##offset##_input); \
662device_create_file(&client->dev, &dev_attr_temp##offset##_max); \
663device_create_file(&client->dev, &dev_attr_temp##offset##_max_hyst); \
664} while (0)
665
666static ssize_t 646static ssize_t
667show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 647show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
668{ 648{
@@ -670,8 +650,6 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
670 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 650 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
671} 651}
672static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 652static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
673#define device_create_file_vid(client) \
674device_create_file(&client->dev, &dev_attr_cpu0_vid)
675 653
676static ssize_t 654static ssize_t
677show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) 655show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -692,8 +670,6 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
692 return count; 670 return count;
693} 671}
694static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 672static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
695#define device_create_file_vrm(client) \
696device_create_file(&client->dev, &dev_attr_vrm)
697 673
698static ssize_t 674static ssize_t
699show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) 675show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -702,8 +678,6 @@ show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf)
702 return sprintf(buf, "%ld\n", (long) data->alarms); 678 return sprintf(buf, "%ld\n", (long) data->alarms);
703} 679}
704static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); 680static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL);
705#define device_create_file_alarms(client) \
706device_create_file(&client->dev, &dev_attr_alarms)
707 681
708#define show_beep_reg(REG, reg) \ 682#define show_beep_reg(REG, reg) \
709static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ 683static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \
@@ -766,12 +740,6 @@ static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, \
766sysfs_beep(ENABLE, enable); 740sysfs_beep(ENABLE, enable);
767sysfs_beep(MASK, mask); 741sysfs_beep(MASK, mask);
768 742
769#define device_create_file_beep(client) \
770do { \
771device_create_file(&client->dev, &dev_attr_beep_enable); \
772device_create_file(&client->dev, &dev_attr_beep_mask); \
773} while (0)
774
775static ssize_t 743static ssize_t
776show_fan_div_reg(struct device *dev, char *buf, int nr) 744show_fan_div_reg(struct device *dev, char *buf, int nr)
777{ 745{
@@ -837,11 +805,6 @@ sysfs_fan_div(1);
837sysfs_fan_div(2); 805sysfs_fan_div(2);
838sysfs_fan_div(3); 806sysfs_fan_div(3);
839 807
840#define device_create_file_fan_div(client, offset) \
841do { \
842device_create_file(&client->dev, &dev_attr_fan##offset##_div); \
843} while (0)
844
845static ssize_t 808static ssize_t
846show_pwm_reg(struct device *dev, char *buf, int nr) 809show_pwm_reg(struct device *dev, char *buf, int nr)
847{ 810{
@@ -896,11 +859,6 @@ sysfs_pwm(1);
896sysfs_pwm(2); 859sysfs_pwm(2);
897sysfs_pwm(3); 860sysfs_pwm(3);
898 861
899#define device_create_file_pwm(client, offset) \
900do { \
901device_create_file(&client->dev, &dev_attr_pwm##offset); \
902} while (0)
903
904static ssize_t 862static ssize_t
905show_sensor_reg(struct device *dev, char *buf, int nr) 863show_sensor_reg(struct device *dev, char *buf, int nr)
906{ 864{
@@ -972,12 +930,6 @@ sysfs_sensor(1);
972sysfs_sensor(2); 930sysfs_sensor(2);
973sysfs_sensor(3); 931sysfs_sensor(3);
974 932
975#define device_create_file_sensor(client, offset) \
976do { \
977device_create_file(&client->dev, &dev_attr_temp##offset##_type); \
978} while (0)
979
980
981static int __init w83627hf_find(int sioaddr, unsigned short *addr) 933static int __init w83627hf_find(int sioaddr, unsigned short *addr)
982{ 934{
983 u16 val; 935 u16 val;
@@ -1009,6 +961,85 @@ static int __init w83627hf_find(int sioaddr, unsigned short *addr)
1009 return 0; 961 return 0;
1010} 962}
1011 963
964static struct attribute *w83627hf_attributes[] = {
965 &dev_attr_in0_input.attr,
966 &dev_attr_in0_min.attr,
967 &dev_attr_in0_max.attr,
968 &dev_attr_in2_input.attr,
969 &dev_attr_in2_min.attr,
970 &dev_attr_in2_max.attr,
971 &dev_attr_in3_input.attr,
972 &dev_attr_in3_min.attr,
973 &dev_attr_in3_max.attr,
974 &dev_attr_in4_input.attr,
975 &dev_attr_in4_min.attr,
976 &dev_attr_in4_max.attr,
977 &dev_attr_in7_input.attr,
978 &dev_attr_in7_min.attr,
979 &dev_attr_in7_max.attr,
980 &dev_attr_in8_input.attr,
981 &dev_attr_in8_min.attr,
982 &dev_attr_in8_max.attr,
983
984 &dev_attr_fan1_input.attr,
985 &dev_attr_fan1_min.attr,
986 &dev_attr_fan1_div.attr,
987 &dev_attr_fan2_input.attr,
988 &dev_attr_fan2_min.attr,
989 &dev_attr_fan2_div.attr,
990
991 &dev_attr_temp1_input.attr,
992 &dev_attr_temp1_max.attr,
993 &dev_attr_temp1_max_hyst.attr,
994 &dev_attr_temp1_type.attr,
995 &dev_attr_temp2_input.attr,
996 &dev_attr_temp2_max.attr,
997 &dev_attr_temp2_max_hyst.attr,
998 &dev_attr_temp2_type.attr,
999
1000 &dev_attr_alarms.attr,
1001 &dev_attr_beep_enable.attr,
1002 &dev_attr_beep_mask.attr,
1003
1004 &dev_attr_pwm1.attr,
1005 &dev_attr_pwm2.attr,
1006
1007 NULL
1008};
1009
1010static const struct attribute_group w83627hf_group = {
1011 .attrs = w83627hf_attributes,
1012};
1013
1014static struct attribute *w83627hf_attributes_opt[] = {
1015 &dev_attr_in1_input.attr,
1016 &dev_attr_in1_min.attr,
1017 &dev_attr_in1_max.attr,
1018 &dev_attr_in5_input.attr,
1019 &dev_attr_in5_min.attr,
1020 &dev_attr_in5_max.attr,
1021 &dev_attr_in6_input.attr,
1022 &dev_attr_in6_min.attr,
1023 &dev_attr_in6_max.attr,
1024
1025 &dev_attr_fan3_input.attr,
1026 &dev_attr_fan3_min.attr,
1027 &dev_attr_fan3_div.attr,
1028
1029 &dev_attr_temp3_input.attr,
1030 &dev_attr_temp3_max.attr,
1031 &dev_attr_temp3_max_hyst.attr,
1032 &dev_attr_temp3_type.attr,
1033
1034 &dev_attr_pwm3.attr,
1035
1036 NULL
1037};
1038
1039static const struct attribute_group w83627hf_group_opt = {
1040 .attrs = w83627hf_attributes_opt,
1041};
1042
1012static int w83627hf_detect(struct i2c_adapter *adapter) 1043static int w83627hf_detect(struct i2c_adapter *adapter)
1013{ 1044{
1014 int val, kind; 1045 int val, kind;
@@ -1108,62 +1139,72 @@ static int w83627hf_detect(struct i2c_adapter *adapter)
1108 data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2)); 1139 data->fan_min[1] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(2));
1109 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3)); 1140 data->fan_min[2] = w83627hf_read_value(new_client, W83781D_REG_FAN_MIN(3));
1110 1141
1111 /* Register sysfs hooks */ 1142 /* Register common device attributes */
1112 data->class_dev = hwmon_device_register(&new_client->dev); 1143 if ((err = sysfs_create_group(&new_client->dev.kobj, &w83627hf_group)))
1113 if (IS_ERR(data->class_dev)) {
1114 err = PTR_ERR(data->class_dev);
1115 goto ERROR3; 1144 goto ERROR3;
1116 }
1117
1118 device_create_file_in(new_client, 0);
1119 if (kind != w83697hf)
1120 device_create_file_in(new_client, 1);
1121 device_create_file_in(new_client, 2);
1122 device_create_file_in(new_client, 3);
1123 device_create_file_in(new_client, 4);
1124 if (kind == w83627hf || kind == w83697hf) {
1125 device_create_file_in(new_client, 5);
1126 device_create_file_in(new_client, 6);
1127 }
1128 device_create_file_in(new_client, 7);
1129 device_create_file_in(new_client, 8);
1130
1131 device_create_file_fan(new_client, 1);
1132 device_create_file_fan(new_client, 2);
1133 if (kind != w83697hf)
1134 device_create_file_fan(new_client, 3);
1135
1136 device_create_file_temp(new_client, 1);
1137 device_create_file_temp(new_client, 2);
1138 if (kind != w83697hf)
1139 device_create_file_temp(new_client, 3);
1140 1145
1141 if (kind != w83697hf && data->vid != 0xff) { 1146 /* Register chip-specific device attributes */
1142 device_create_file_vid(new_client); 1147 if (kind == w83627hf || kind == w83697hf)
1143 device_create_file_vrm(new_client); 1148 if ((err = device_create_file(&new_client->dev,
1144 } 1149 &dev_attr_in5_input))
1150 || (err = device_create_file(&new_client->dev,
1151 &dev_attr_in5_min))
1152 || (err = device_create_file(&new_client->dev,
1153 &dev_attr_in5_max))
1154 || (err = device_create_file(&new_client->dev,
1155 &dev_attr_in6_input))
1156 || (err = device_create_file(&new_client->dev,
1157 &dev_attr_in6_min))
1158 || (err = device_create_file(&new_client->dev,
1159 &dev_attr_in6_max)))
1160 goto ERROR4;
1145 1161
1146 device_create_file_fan_div(new_client, 1);
1147 device_create_file_fan_div(new_client, 2);
1148 if (kind != w83697hf) 1162 if (kind != w83697hf)
1149 device_create_file_fan_div(new_client, 3); 1163 if ((err = device_create_file(&new_client->dev,
1150 1164 &dev_attr_in1_input))
1151 device_create_file_alarms(new_client); 1165 || (err = device_create_file(&new_client->dev,
1152 1166 &dev_attr_in1_min))
1153 device_create_file_beep(new_client); 1167 || (err = device_create_file(&new_client->dev,
1168 &dev_attr_in1_max))
1169 || (err = device_create_file(&new_client->dev,
1170 &dev_attr_fan3_input))
1171 || (err = device_create_file(&new_client->dev,
1172 &dev_attr_fan3_min))
1173 || (err = device_create_file(&new_client->dev,
1174 &dev_attr_fan3_div))
1175 || (err = device_create_file(&new_client->dev,
1176 &dev_attr_temp3_input))
1177 || (err = device_create_file(&new_client->dev,
1178 &dev_attr_temp3_max))
1179 || (err = device_create_file(&new_client->dev,
1180 &dev_attr_temp3_max_hyst))
1181 || (err = device_create_file(&new_client->dev,
1182 &dev_attr_temp3_type)))
1183 goto ERROR4;
1184
1185 if (kind != w83697hf && data->vid != 0xff)
1186 if ((err = device_create_file(&new_client->dev,
1187 &dev_attr_cpu0_vid))
1188 || (err = device_create_file(&new_client->dev,
1189 &dev_attr_vrm)))
1190 goto ERROR4;
1154 1191
1155 device_create_file_pwm(new_client, 1);
1156 device_create_file_pwm(new_client, 2);
1157 if (kind == w83627thf || kind == w83637hf || kind == w83687thf) 1192 if (kind == w83627thf || kind == w83637hf || kind == w83687thf)
1158 device_create_file_pwm(new_client, 3); 1193 if ((err = device_create_file(&new_client->dev,
1194 &dev_attr_pwm3)))
1195 goto ERROR4;
1159 1196
1160 device_create_file_sensor(new_client, 1); 1197 data->class_dev = hwmon_device_register(&new_client->dev);
1161 device_create_file_sensor(new_client, 2); 1198 if (IS_ERR(data->class_dev)) {
1162 if (kind != w83697hf) 1199 err = PTR_ERR(data->class_dev);
1163 device_create_file_sensor(new_client, 3); 1200 goto ERROR4;
1201 }
1164 1202
1165 return 0; 1203 return 0;
1166 1204
1205 ERROR4:
1206 sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group);
1207 sysfs_remove_group(&new_client->dev.kobj, &w83627hf_group_opt);
1167 ERROR3: 1208 ERROR3:
1168 i2c_detach_client(new_client); 1209 i2c_detach_client(new_client);
1169 ERROR2: 1210 ERROR2:
@@ -1181,6 +1222,9 @@ static int w83627hf_detach_client(struct i2c_client *client)
1181 1222
1182 hwmon_device_unregister(data->class_dev); 1223 hwmon_device_unregister(data->class_dev);
1183 1224
1225 sysfs_remove_group(&client->dev.kobj, &w83627hf_group);
1226 sysfs_remove_group(&client->dev.kobj, &w83627hf_group_opt);
1227
1184 if ((err = i2c_detach_client(client))) 1228 if ((err = i2c_detach_client(client)))
1185 return err; 1229 return err;
1186 1230