diff options
-rw-r--r-- | drivers/hwmon/dme1737.c | 491 |
1 files changed, 258 insertions, 233 deletions
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c index e9cbc727664d..cef662c6af9d 100644 --- a/drivers/hwmon/dme1737.c +++ b/drivers/hwmon/dme1737.c | |||
@@ -493,8 +493,8 @@ static s32 dme1737_write(struct i2c_client *client, u8 reg, u8 value) | |||
493 | 493 | ||
494 | static struct dme1737_data *dme1737_update_device(struct device *dev) | 494 | static struct dme1737_data *dme1737_update_device(struct device *dev) |
495 | { | 495 | { |
496 | struct i2c_client *client = to_i2c_client(dev); | 496 | struct dme1737_data *data = dev_get_drvdata(dev); |
497 | struct dme1737_data *data = i2c_get_clientdata(client); | 497 | struct i2c_client *client = &data->client; |
498 | int ix; | 498 | int ix; |
499 | u8 lsb[5]; | 499 | u8 lsb[5]; |
500 | 500 | ||
@@ -674,7 +674,7 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr, | |||
674 | break; | 674 | break; |
675 | default: | 675 | default: |
676 | res = 0; | 676 | res = 0; |
677 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | 677 | dev_dbg(dev, "Unknown function %d.\n", fn); |
678 | } | 678 | } |
679 | 679 | ||
680 | return sprintf(buf, "%d\n", res); | 680 | return sprintf(buf, "%d\n", res); |
@@ -683,8 +683,8 @@ static ssize_t show_in(struct device *dev, struct device_attribute *attr, | |||
683 | static ssize_t set_in(struct device *dev, struct device_attribute *attr, | 683 | static ssize_t set_in(struct device *dev, struct device_attribute *attr, |
684 | const char *buf, size_t count) | 684 | const char *buf, size_t count) |
685 | { | 685 | { |
686 | struct i2c_client *client = to_i2c_client(dev); | 686 | struct dme1737_data *data = dev_get_drvdata(dev); |
687 | struct dme1737_data *data = i2c_get_clientdata(client); | 687 | struct i2c_client *client = &data->client; |
688 | struct sensor_device_attribute_2 | 688 | struct sensor_device_attribute_2 |
689 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | 689 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
690 | int ix = sensor_attr_2->index; | 690 | int ix = sensor_attr_2->index; |
@@ -704,7 +704,7 @@ static ssize_t set_in(struct device *dev, struct device_attribute *attr, | |||
704 | data->in_max[ix]); | 704 | data->in_max[ix]); |
705 | break; | 705 | break; |
706 | default: | 706 | default: |
707 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | 707 | dev_dbg(dev, "Unknown function %d.\n", fn); |
708 | } | 708 | } |
709 | mutex_unlock(&data->update_lock); | 709 | mutex_unlock(&data->update_lock); |
710 | 710 | ||
@@ -754,7 +754,7 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | |||
754 | break; | 754 | break; |
755 | default: | 755 | default: |
756 | res = 0; | 756 | res = 0; |
757 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | 757 | dev_dbg(dev, "Unknown function %d.\n", fn); |
758 | } | 758 | } |
759 | 759 | ||
760 | return sprintf(buf, "%d\n", res); | 760 | return sprintf(buf, "%d\n", res); |
@@ -763,8 +763,8 @@ static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | |||
763 | static ssize_t set_temp(struct device *dev, struct device_attribute *attr, | 763 | static ssize_t set_temp(struct device *dev, struct device_attribute *attr, |
764 | const char *buf, size_t count) | 764 | const char *buf, size_t count) |
765 | { | 765 | { |
766 | struct i2c_client *client = to_i2c_client(dev); | 766 | struct dme1737_data *data = dev_get_drvdata(dev); |
767 | struct dme1737_data *data = i2c_get_clientdata(client); | 767 | struct i2c_client *client = &data->client; |
768 | struct sensor_device_attribute_2 | 768 | struct sensor_device_attribute_2 |
769 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | 769 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
770 | int ix = sensor_attr_2->index; | 770 | int ix = sensor_attr_2->index; |
@@ -789,7 +789,7 @@ static ssize_t set_temp(struct device *dev, struct device_attribute *attr, | |||
789 | data->temp_offset[ix]); | 789 | data->temp_offset[ix]); |
790 | break; | 790 | break; |
791 | default: | 791 | default: |
792 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | 792 | dev_dbg(dev, "Unknown function %d.\n", fn); |
793 | } | 793 | } |
794 | mutex_unlock(&data->update_lock); | 794 | mutex_unlock(&data->update_lock); |
795 | 795 | ||
@@ -843,7 +843,7 @@ static ssize_t show_zone(struct device *dev, struct device_attribute *attr, | |||
843 | break; | 843 | break; |
844 | default: | 844 | default: |
845 | res = 0; | 845 | res = 0; |
846 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | 846 | dev_dbg(dev, "Unknown function %d.\n", fn); |
847 | } | 847 | } |
848 | 848 | ||
849 | return sprintf(buf, "%d\n", res); | 849 | return sprintf(buf, "%d\n", res); |
@@ -852,8 +852,8 @@ static ssize_t show_zone(struct device *dev, struct device_attribute *attr, | |||
852 | static ssize_t set_zone(struct device *dev, struct device_attribute *attr, | 852 | static ssize_t set_zone(struct device *dev, struct device_attribute *attr, |
853 | const char *buf, size_t count) | 853 | const char *buf, size_t count) |
854 | { | 854 | { |
855 | struct i2c_client *client = to_i2c_client(dev); | 855 | struct dme1737_data *data = dev_get_drvdata(dev); |
856 | struct dme1737_data *data = i2c_get_clientdata(client); | 856 | struct i2c_client *client = &data->client; |
857 | struct sensor_device_attribute_2 | 857 | struct sensor_device_attribute_2 |
858 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | 858 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
859 | int ix = sensor_attr_2->index; | 859 | int ix = sensor_attr_2->index; |
@@ -898,7 +898,7 @@ static ssize_t set_zone(struct device *dev, struct device_attribute *attr, | |||
898 | data->zone_abs[ix]); | 898 | data->zone_abs[ix]); |
899 | break; | 899 | break; |
900 | default: | 900 | default: |
901 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | 901 | dev_dbg(dev, "Unknown function %d.\n", fn); |
902 | } | 902 | } |
903 | mutex_unlock(&data->update_lock); | 903 | mutex_unlock(&data->update_lock); |
904 | 904 | ||
@@ -950,7 +950,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr, | |||
950 | break; | 950 | break; |
951 | default: | 951 | default: |
952 | res = 0; | 952 | res = 0; |
953 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | 953 | dev_dbg(dev, "Unknown function %d.\n", fn); |
954 | } | 954 | } |
955 | 955 | ||
956 | return sprintf(buf, "%d\n", res); | 956 | return sprintf(buf, "%d\n", res); |
@@ -959,8 +959,8 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr, | |||
959 | static ssize_t set_fan(struct device *dev, struct device_attribute *attr, | 959 | static ssize_t set_fan(struct device *dev, struct device_attribute *attr, |
960 | const char *buf, size_t count) | 960 | const char *buf, size_t count) |
961 | { | 961 | { |
962 | struct i2c_client *client = to_i2c_client(dev); | 962 | struct dme1737_data *data = dev_get_drvdata(dev); |
963 | struct dme1737_data *data = i2c_get_clientdata(client); | 963 | struct i2c_client *client = &data->client; |
964 | struct sensor_device_attribute_2 | 964 | struct sensor_device_attribute_2 |
965 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | 965 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
966 | int ix = sensor_attr_2->index; | 966 | int ix = sensor_attr_2->index; |
@@ -1006,7 +1006,7 @@ static ssize_t set_fan(struct device *dev, struct device_attribute *attr, | |||
1006 | data->fan_opt[ix]); | 1006 | data->fan_opt[ix]); |
1007 | break; | 1007 | break; |
1008 | default: | 1008 | default: |
1009 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | 1009 | dev_dbg(dev, "Unknown function %d.\n", fn); |
1010 | } | 1010 | } |
1011 | exit: | 1011 | exit: |
1012 | mutex_unlock(&data->update_lock); | 1012 | mutex_unlock(&data->update_lock); |
@@ -1086,20 +1086,20 @@ static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, | |||
1086 | break; | 1086 | break; |
1087 | default: | 1087 | default: |
1088 | res = 0; | 1088 | res = 0; |
1089 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | 1089 | dev_dbg(dev, "Unknown function %d.\n", fn); |
1090 | } | 1090 | } |
1091 | 1091 | ||
1092 | return sprintf(buf, "%d\n", res); | 1092 | return sprintf(buf, "%d\n", res); |
1093 | } | 1093 | } |
1094 | 1094 | ||
1095 | static struct attribute *dme1737_attr_pwm[]; | 1095 | static struct attribute *dme1737_attr_pwm[]; |
1096 | static void dme1737_chmod_file(struct i2c_client*, struct attribute*, mode_t); | 1096 | static void dme1737_chmod_file(struct device*, struct attribute*, mode_t); |
1097 | 1097 | ||
1098 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | 1098 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
1099 | const char *buf, size_t count) | 1099 | const char *buf, size_t count) |
1100 | { | 1100 | { |
1101 | struct i2c_client *client = to_i2c_client(dev); | 1101 | struct dme1737_data *data = dev_get_drvdata(dev); |
1102 | struct dme1737_data *data = i2c_get_clientdata(client); | 1102 | struct i2c_client *client = &data->client; |
1103 | struct sensor_device_attribute_2 | 1103 | struct sensor_device_attribute_2 |
1104 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); | 1104 | *sensor_attr_2 = to_sensor_dev_attr_2(attr); |
1105 | int ix = sensor_attr_2->index; | 1105 | int ix = sensor_attr_2->index; |
@@ -1156,7 +1156,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
1156 | switch (val) { | 1156 | switch (val) { |
1157 | case 0: | 1157 | case 0: |
1158 | /* Change permissions of pwm[ix] to read-only */ | 1158 | /* Change permissions of pwm[ix] to read-only */ |
1159 | dme1737_chmod_file(client, dme1737_attr_pwm[ix], | 1159 | dme1737_chmod_file(dev, dme1737_attr_pwm[ix], |
1160 | S_IRUGO); | 1160 | S_IRUGO); |
1161 | /* Turn fan fully on */ | 1161 | /* Turn fan fully on */ |
1162 | data->pwm_config[ix] = PWM_EN_TO_REG(0, | 1162 | data->pwm_config[ix] = PWM_EN_TO_REG(0, |
@@ -1171,12 +1171,12 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
1171 | dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), | 1171 | dme1737_write(client, DME1737_REG_PWM_CONFIG(ix), |
1172 | data->pwm_config[ix]); | 1172 | data->pwm_config[ix]); |
1173 | /* Change permissions of pwm[ix] to read-writeable */ | 1173 | /* Change permissions of pwm[ix] to read-writeable */ |
1174 | dme1737_chmod_file(client, dme1737_attr_pwm[ix], | 1174 | dme1737_chmod_file(dev, dme1737_attr_pwm[ix], |
1175 | S_IRUGO | S_IWUSR); | 1175 | S_IRUGO | S_IWUSR); |
1176 | break; | 1176 | break; |
1177 | case 2: | 1177 | case 2: |
1178 | /* Change permissions of pwm[ix] to read-only */ | 1178 | /* Change permissions of pwm[ix] to read-only */ |
1179 | dme1737_chmod_file(client, dme1737_attr_pwm[ix], | 1179 | dme1737_chmod_file(dev, dme1737_attr_pwm[ix], |
1180 | S_IRUGO); | 1180 | S_IRUGO); |
1181 | /* Turn on auto mode using the saved zone channel | 1181 | /* Turn on auto mode using the saved zone channel |
1182 | * assignment */ | 1182 | * assignment */ |
@@ -1257,12 +1257,10 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
1257 | data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, | 1257 | data->pwm_rr[0] = PWM_OFF_TO_REG(1, ix, |
1258 | dme1737_read(client, | 1258 | dme1737_read(client, |
1259 | DME1737_REG_PWM_RR(0))); | 1259 | DME1737_REG_PWM_RR(0))); |
1260 | |||
1261 | } else { | 1260 | } else { |
1262 | data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, | 1261 | data->pwm_rr[0] = PWM_OFF_TO_REG(0, ix, |
1263 | dme1737_read(client, | 1262 | dme1737_read(client, |
1264 | DME1737_REG_PWM_RR(0))); | 1263 | DME1737_REG_PWM_RR(0))); |
1265 | |||
1266 | } | 1264 | } |
1267 | dme1737_write(client, DME1737_REG_PWM_RR(0), | 1265 | dme1737_write(client, DME1737_REG_PWM_RR(0), |
1268 | data->pwm_rr[0]); | 1266 | data->pwm_rr[0]); |
@@ -1274,7 +1272,7 @@ static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | |||
1274 | data->pwm_min[ix]); | 1272 | data->pwm_min[ix]); |
1275 | break; | 1273 | break; |
1276 | default: | 1274 | default: |
1277 | dev_dbg(dev, "Unknown attr fetch (%d)\n", fn); | 1275 | dev_dbg(dev, "Unknown function %d.\n", fn); |
1278 | } | 1276 | } |
1279 | exit: | 1277 | exit: |
1280 | mutex_unlock(&data->update_lock); | 1278 | mutex_unlock(&data->update_lock); |
@@ -1298,8 +1296,7 @@ static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, | |||
1298 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, | 1296 | static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, |
1299 | const char *buf, size_t count) | 1297 | const char *buf, size_t count) |
1300 | { | 1298 | { |
1301 | struct i2c_client *client = to_i2c_client(dev); | 1299 | struct dme1737_data *data = dev_get_drvdata(dev); |
1302 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
1303 | long val = simple_strtol(buf, NULL, 10); | 1300 | long val = simple_strtol(buf, NULL, 10); |
1304 | 1301 | ||
1305 | data->vrm = val; | 1302 | data->vrm = val; |
@@ -1322,13 +1319,13 @@ static ssize_t show_vid(struct device *dev, struct device_attribute *attr, | |||
1322 | 1319 | ||
1323 | #define SENSOR_DEVICE_ATTR_IN(ix) \ | 1320 | #define SENSOR_DEVICE_ATTR_IN(ix) \ |
1324 | static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \ | 1321 | static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \ |
1325 | show_in, NULL, SYS_IN_INPUT, ix); \ | 1322 | show_in, NULL, SYS_IN_INPUT, ix); \ |
1326 | static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \ | 1323 | static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \ |
1327 | show_in, set_in, SYS_IN_MIN, ix); \ | 1324 | show_in, set_in, SYS_IN_MIN, ix); \ |
1328 | static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \ | 1325 | static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \ |
1329 | show_in, set_in, SYS_IN_MAX, ix); \ | 1326 | show_in, set_in, SYS_IN_MAX, ix); \ |
1330 | static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \ | 1327 | static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \ |
1331 | show_in, NULL, SYS_IN_ALARM, ix) | 1328 | show_in, NULL, SYS_IN_ALARM, ix) |
1332 | 1329 | ||
1333 | SENSOR_DEVICE_ATTR_IN(0); | 1330 | SENSOR_DEVICE_ATTR_IN(0); |
1334 | SENSOR_DEVICE_ATTR_IN(1); | 1331 | SENSOR_DEVICE_ATTR_IN(1); |
@@ -1342,17 +1339,17 @@ SENSOR_DEVICE_ATTR_IN(6); | |||
1342 | 1339 | ||
1343 | #define SENSOR_DEVICE_ATTR_TEMP(ix) \ | 1340 | #define SENSOR_DEVICE_ATTR_TEMP(ix) \ |
1344 | static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \ | 1341 | static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \ |
1345 | show_temp, NULL, SYS_TEMP_INPUT, ix-1); \ | 1342 | show_temp, NULL, SYS_TEMP_INPUT, ix-1); \ |
1346 | static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \ | 1343 | static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \ |
1347 | show_temp, set_temp, SYS_TEMP_MIN, ix-1); \ | 1344 | show_temp, set_temp, SYS_TEMP_MIN, ix-1); \ |
1348 | static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \ | 1345 | static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \ |
1349 | show_temp, set_temp, SYS_TEMP_MAX, ix-1); \ | 1346 | show_temp, set_temp, SYS_TEMP_MAX, ix-1); \ |
1350 | static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \ | 1347 | static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \ |
1351 | show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \ | 1348 | show_temp, set_temp, SYS_TEMP_OFFSET, ix-1); \ |
1352 | static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \ | 1349 | static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \ |
1353 | show_temp, NULL, SYS_TEMP_ALARM, ix-1); \ | 1350 | show_temp, NULL, SYS_TEMP_ALARM, ix-1); \ |
1354 | static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \ | 1351 | static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \ |
1355 | show_temp, NULL, SYS_TEMP_FAULT, ix-1) | 1352 | show_temp, NULL, SYS_TEMP_FAULT, ix-1) |
1356 | 1353 | ||
1357 | SENSOR_DEVICE_ATTR_TEMP(1); | 1354 | SENSOR_DEVICE_ATTR_TEMP(1); |
1358 | SENSOR_DEVICE_ATTR_TEMP(2); | 1355 | SENSOR_DEVICE_ATTR_TEMP(2); |
@@ -1362,15 +1359,15 @@ SENSOR_DEVICE_ATTR_TEMP(3); | |||
1362 | 1359 | ||
1363 | #define SENSOR_DEVICE_ATTR_ZONE(ix) \ | 1360 | #define SENSOR_DEVICE_ATTR_ZONE(ix) \ |
1364 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \ | 1361 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \ |
1365 | show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \ | 1362 | show_zone, NULL, SYS_ZONE_AUTO_CHANNELS_TEMP, ix-1); \ |
1366 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \ | 1363 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \ |
1367 | show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \ | 1364 | show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP_HYST, ix-1); \ |
1368 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \ | 1365 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \ |
1369 | show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \ | 1366 | show_zone, set_zone, SYS_ZONE_AUTO_POINT1_TEMP, ix-1); \ |
1370 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \ | 1367 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \ |
1371 | show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \ | 1368 | show_zone, set_zone, SYS_ZONE_AUTO_POINT2_TEMP, ix-1); \ |
1372 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \ | 1369 | static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \ |
1373 | show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1) | 1370 | show_zone, set_zone, SYS_ZONE_AUTO_POINT3_TEMP, ix-1) |
1374 | 1371 | ||
1375 | SENSOR_DEVICE_ATTR_ZONE(1); | 1372 | SENSOR_DEVICE_ATTR_ZONE(1); |
1376 | SENSOR_DEVICE_ATTR_ZONE(2); | 1373 | SENSOR_DEVICE_ATTR_ZONE(2); |
@@ -1380,13 +1377,13 @@ SENSOR_DEVICE_ATTR_ZONE(3); | |||
1380 | 1377 | ||
1381 | #define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \ | 1378 | #define SENSOR_DEVICE_ATTR_FAN_1TO4(ix) \ |
1382 | static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ | 1379 | static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ |
1383 | show_fan, NULL, SYS_FAN_INPUT, ix-1); \ | 1380 | show_fan, NULL, SYS_FAN_INPUT, ix-1); \ |
1384 | static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ | 1381 | static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ |
1385 | show_fan, set_fan, SYS_FAN_MIN, ix-1); \ | 1382 | show_fan, set_fan, SYS_FAN_MIN, ix-1); \ |
1386 | static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ | 1383 | static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ |
1387 | show_fan, NULL, SYS_FAN_ALARM, ix-1); \ | 1384 | show_fan, NULL, SYS_FAN_ALARM, ix-1); \ |
1388 | static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \ | 1385 | static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \ |
1389 | show_fan, set_fan, SYS_FAN_TYPE, ix-1) | 1386 | show_fan, set_fan, SYS_FAN_TYPE, ix-1) |
1390 | 1387 | ||
1391 | SENSOR_DEVICE_ATTR_FAN_1TO4(1); | 1388 | SENSOR_DEVICE_ATTR_FAN_1TO4(1); |
1392 | SENSOR_DEVICE_ATTR_FAN_1TO4(2); | 1389 | SENSOR_DEVICE_ATTR_FAN_1TO4(2); |
@@ -1397,13 +1394,13 @@ SENSOR_DEVICE_ATTR_FAN_1TO4(4); | |||
1397 | 1394 | ||
1398 | #define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \ | 1395 | #define SENSOR_DEVICE_ATTR_FAN_5TO6(ix) \ |
1399 | static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ | 1396 | static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ |
1400 | show_fan, NULL, SYS_FAN_INPUT, ix-1); \ | 1397 | show_fan, NULL, SYS_FAN_INPUT, ix-1); \ |
1401 | static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ | 1398 | static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ |
1402 | show_fan, set_fan, SYS_FAN_MIN, ix-1); \ | 1399 | show_fan, set_fan, SYS_FAN_MIN, ix-1); \ |
1403 | static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ | 1400 | static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ |
1404 | show_fan, NULL, SYS_FAN_ALARM, ix-1); \ | 1401 | show_fan, NULL, SYS_FAN_ALARM, ix-1); \ |
1405 | static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \ | 1402 | static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \ |
1406 | show_fan, set_fan, SYS_FAN_MAX, ix-1) | 1403 | show_fan, set_fan, SYS_FAN_MAX, ix-1) |
1407 | 1404 | ||
1408 | SENSOR_DEVICE_ATTR_FAN_5TO6(5); | 1405 | SENSOR_DEVICE_ATTR_FAN_5TO6(5); |
1409 | SENSOR_DEVICE_ATTR_FAN_5TO6(6); | 1406 | SENSOR_DEVICE_ATTR_FAN_5TO6(6); |
@@ -1412,21 +1409,21 @@ SENSOR_DEVICE_ATTR_FAN_5TO6(6); | |||
1412 | 1409 | ||
1413 | #define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \ | 1410 | #define SENSOR_DEVICE_ATTR_PWM_1TO3(ix) \ |
1414 | static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \ | 1411 | static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \ |
1415 | show_pwm, set_pwm, SYS_PWM, ix-1); \ | 1412 | show_pwm, set_pwm, SYS_PWM, ix-1); \ |
1416 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \ | 1413 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \ |
1417 | show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ | 1414 | show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ |
1418 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ | 1415 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ |
1419 | show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \ | 1416 | show_pwm, set_pwm, SYS_PWM_ENABLE, ix-1); \ |
1420 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \ | 1417 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \ |
1421 | show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \ | 1418 | show_pwm, set_pwm, SYS_PWM_RAMP_RATE, ix-1); \ |
1422 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \ | 1419 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \ |
1423 | show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \ | 1420 | show_pwm, set_pwm, SYS_PWM_AUTO_CHANNELS_ZONE, ix-1); \ |
1424 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \ | 1421 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \ |
1425 | show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \ | 1422 | show_pwm, set_pwm, SYS_PWM_AUTO_PWM_MIN, ix-1); \ |
1426 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \ | 1423 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \ |
1427 | show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \ | 1424 | show_pwm, set_pwm, SYS_PWM_AUTO_POINT1_PWM, ix-1); \ |
1428 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \ | 1425 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \ |
1429 | show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1) | 1426 | show_pwm, NULL, SYS_PWM_AUTO_POINT2_PWM, ix-1) |
1430 | 1427 | ||
1431 | SENSOR_DEVICE_ATTR_PWM_1TO3(1); | 1428 | SENSOR_DEVICE_ATTR_PWM_1TO3(1); |
1432 | SENSOR_DEVICE_ATTR_PWM_1TO3(2); | 1429 | SENSOR_DEVICE_ATTR_PWM_1TO3(2); |
@@ -1436,11 +1433,11 @@ SENSOR_DEVICE_ATTR_PWM_1TO3(3); | |||
1436 | 1433 | ||
1437 | #define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \ | 1434 | #define SENSOR_DEVICE_ATTR_PWM_5TO6(ix) \ |
1438 | static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \ | 1435 | static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \ |
1439 | show_pwm, set_pwm, SYS_PWM, ix-1); \ | 1436 | show_pwm, set_pwm, SYS_PWM, ix-1); \ |
1440 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \ | 1437 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \ |
1441 | show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ | 1438 | show_pwm, set_pwm, SYS_PWM_FREQ, ix-1); \ |
1442 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ | 1439 | static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ |
1443 | show_pwm, NULL, SYS_PWM_ENABLE, ix-1) | 1440 | show_pwm, NULL, SYS_PWM_ENABLE, ix-1) |
1444 | 1441 | ||
1445 | SENSOR_DEVICE_ATTR_PWM_5TO6(5); | 1442 | SENSOR_DEVICE_ATTR_PWM_5TO6(5); |
1446 | SENSOR_DEVICE_ATTR_PWM_5TO6(6); | 1443 | SENSOR_DEVICE_ATTR_PWM_5TO6(6); |
@@ -1519,53 +1516,53 @@ SENSOR_DEV_ATTR_PWM_5TO6_LOCK(ix), \ | |||
1519 | * permissions are created read-only and write permissions are added or removed | 1516 | * permissions are created read-only and write permissions are added or removed |
1520 | * on the fly when required */ | 1517 | * on the fly when required */ |
1521 | static struct attribute *dme1737_attr[] ={ | 1518 | static struct attribute *dme1737_attr[] ={ |
1522 | /* Voltages */ | 1519 | /* Voltages */ |
1523 | SENSOR_DEV_ATTR_IN(0), | 1520 | SENSOR_DEV_ATTR_IN(0), |
1524 | SENSOR_DEV_ATTR_IN(1), | 1521 | SENSOR_DEV_ATTR_IN(1), |
1525 | SENSOR_DEV_ATTR_IN(2), | 1522 | SENSOR_DEV_ATTR_IN(2), |
1526 | SENSOR_DEV_ATTR_IN(3), | 1523 | SENSOR_DEV_ATTR_IN(3), |
1527 | SENSOR_DEV_ATTR_IN(4), | 1524 | SENSOR_DEV_ATTR_IN(4), |
1528 | SENSOR_DEV_ATTR_IN(5), | 1525 | SENSOR_DEV_ATTR_IN(5), |
1529 | SENSOR_DEV_ATTR_IN(6), | 1526 | SENSOR_DEV_ATTR_IN(6), |
1530 | /* Temperatures */ | 1527 | /* Temperatures */ |
1531 | SENSOR_DEV_ATTR_TEMP(1), | 1528 | SENSOR_DEV_ATTR_TEMP(1), |
1532 | SENSOR_DEV_ATTR_TEMP(2), | 1529 | SENSOR_DEV_ATTR_TEMP(2), |
1533 | SENSOR_DEV_ATTR_TEMP(3), | 1530 | SENSOR_DEV_ATTR_TEMP(3), |
1534 | /* Zones */ | 1531 | /* Zones */ |
1535 | SENSOR_DEV_ATTR_ZONE(1), | 1532 | SENSOR_DEV_ATTR_ZONE(1), |
1536 | SENSOR_DEV_ATTR_ZONE(2), | 1533 | SENSOR_DEV_ATTR_ZONE(2), |
1537 | SENSOR_DEV_ATTR_ZONE(3), | 1534 | SENSOR_DEV_ATTR_ZONE(3), |
1538 | /* Misc */ | 1535 | /* Misc */ |
1539 | &dev_attr_vrm.attr, | 1536 | &dev_attr_vrm.attr, |
1540 | &dev_attr_cpu0_vid.attr, | 1537 | &dev_attr_cpu0_vid.attr, |
1541 | NULL | 1538 | NULL |
1542 | }; | 1539 | }; |
1543 | 1540 | ||
1544 | static const struct attribute_group dme1737_group = { | 1541 | static const struct attribute_group dme1737_group = { |
1545 | .attrs = dme1737_attr, | 1542 | .attrs = dme1737_attr, |
1546 | }; | 1543 | }; |
1547 | 1544 | ||
1548 | /* The following structs hold the PWM attributes, some of which are optional. | 1545 | /* The following structs hold the PWM attributes, some of which are optional. |
1549 | * Their creation depends on the chip configuration which is determined during | 1546 | * Their creation depends on the chip configuration which is determined during |
1550 | * module load. */ | 1547 | * module load. */ |
1551 | static struct attribute *dme1737_attr_pwm1[] = { | 1548 | static struct attribute *dme1737_attr_pwm1[] = { |
1552 | SENSOR_DEV_ATTR_PWM_1TO3(1), | 1549 | SENSOR_DEV_ATTR_PWM_1TO3(1), |
1553 | NULL | 1550 | NULL |
1554 | }; | 1551 | }; |
1555 | static struct attribute *dme1737_attr_pwm2[] = { | 1552 | static struct attribute *dme1737_attr_pwm2[] = { |
1556 | SENSOR_DEV_ATTR_PWM_1TO3(2), | 1553 | SENSOR_DEV_ATTR_PWM_1TO3(2), |
1557 | NULL | 1554 | NULL |
1558 | }; | 1555 | }; |
1559 | static struct attribute *dme1737_attr_pwm3[] = { | 1556 | static struct attribute *dme1737_attr_pwm3[] = { |
1560 | SENSOR_DEV_ATTR_PWM_1TO3(3), | 1557 | SENSOR_DEV_ATTR_PWM_1TO3(3), |
1561 | NULL | 1558 | NULL |
1562 | }; | 1559 | }; |
1563 | static struct attribute *dme1737_attr_pwm5[] = { | 1560 | static struct attribute *dme1737_attr_pwm5[] = { |
1564 | SENSOR_DEV_ATTR_PWM_5TO6(5), | 1561 | SENSOR_DEV_ATTR_PWM_5TO6(5), |
1565 | NULL | 1562 | NULL |
1566 | }; | 1563 | }; |
1567 | static struct attribute *dme1737_attr_pwm6[] = { | 1564 | static struct attribute *dme1737_attr_pwm6[] = { |
1568 | SENSOR_DEV_ATTR_PWM_5TO6(6), | 1565 | SENSOR_DEV_ATTR_PWM_5TO6(6), |
1569 | NULL | 1566 | NULL |
1570 | }; | 1567 | }; |
1571 | 1568 | ||
@@ -1582,27 +1579,27 @@ static const struct attribute_group dme1737_pwm_group[] = { | |||
1582 | * Their creation depends on the chip configuration which is determined during | 1579 | * Their creation depends on the chip configuration which is determined during |
1583 | * module load. */ | 1580 | * module load. */ |
1584 | static struct attribute *dme1737_attr_fan1[] = { | 1581 | static struct attribute *dme1737_attr_fan1[] = { |
1585 | SENSOR_DEV_ATTR_FAN_1TO4(1), | 1582 | SENSOR_DEV_ATTR_FAN_1TO4(1), |
1586 | NULL | 1583 | NULL |
1587 | }; | 1584 | }; |
1588 | static struct attribute *dme1737_attr_fan2[] = { | 1585 | static struct attribute *dme1737_attr_fan2[] = { |
1589 | SENSOR_DEV_ATTR_FAN_1TO4(2), | 1586 | SENSOR_DEV_ATTR_FAN_1TO4(2), |
1590 | NULL | 1587 | NULL |
1591 | }; | 1588 | }; |
1592 | static struct attribute *dme1737_attr_fan3[] = { | 1589 | static struct attribute *dme1737_attr_fan3[] = { |
1593 | SENSOR_DEV_ATTR_FAN_1TO4(3), | 1590 | SENSOR_DEV_ATTR_FAN_1TO4(3), |
1594 | NULL | 1591 | NULL |
1595 | }; | 1592 | }; |
1596 | static struct attribute *dme1737_attr_fan4[] = { | 1593 | static struct attribute *dme1737_attr_fan4[] = { |
1597 | SENSOR_DEV_ATTR_FAN_1TO4(4), | 1594 | SENSOR_DEV_ATTR_FAN_1TO4(4), |
1598 | NULL | 1595 | NULL |
1599 | }; | 1596 | }; |
1600 | static struct attribute *dme1737_attr_fan5[] = { | 1597 | static struct attribute *dme1737_attr_fan5[] = { |
1601 | SENSOR_DEV_ATTR_FAN_5TO6(5), | 1598 | SENSOR_DEV_ATTR_FAN_5TO6(5), |
1602 | NULL | 1599 | NULL |
1603 | }; | 1600 | }; |
1604 | static struct attribute *dme1737_attr_fan6[] = { | 1601 | static struct attribute *dme1737_attr_fan6[] = { |
1605 | SENSOR_DEV_ATTR_FAN_5TO6(6), | 1602 | SENSOR_DEV_ATTR_FAN_5TO6(6), |
1606 | NULL | 1603 | NULL |
1607 | }; | 1604 | }; |
1608 | 1605 | ||
@@ -1637,23 +1634,23 @@ static const struct attribute_group dme1737_lock_group = { | |||
1637 | * writeable if the chip is *not* locked and the respective PWM is available. | 1634 | * writeable if the chip is *not* locked and the respective PWM is available. |
1638 | * Otherwise they stay read-only. */ | 1635 | * Otherwise they stay read-only. */ |
1639 | static struct attribute *dme1737_attr_pwm1_lock[] = { | 1636 | static struct attribute *dme1737_attr_pwm1_lock[] = { |
1640 | SENSOR_DEV_ATTR_PWM_1TO3_LOCK(1), | 1637 | SENSOR_DEV_ATTR_PWM_1TO3_LOCK(1), |
1641 | NULL | 1638 | NULL |
1642 | }; | 1639 | }; |
1643 | static struct attribute *dme1737_attr_pwm2_lock[] = { | 1640 | static struct attribute *dme1737_attr_pwm2_lock[] = { |
1644 | SENSOR_DEV_ATTR_PWM_1TO3_LOCK(2), | 1641 | SENSOR_DEV_ATTR_PWM_1TO3_LOCK(2), |
1645 | NULL | 1642 | NULL |
1646 | }; | 1643 | }; |
1647 | static struct attribute *dme1737_attr_pwm3_lock[] = { | 1644 | static struct attribute *dme1737_attr_pwm3_lock[] = { |
1648 | SENSOR_DEV_ATTR_PWM_1TO3_LOCK(3), | 1645 | SENSOR_DEV_ATTR_PWM_1TO3_LOCK(3), |
1649 | NULL | 1646 | NULL |
1650 | }; | 1647 | }; |
1651 | static struct attribute *dme1737_attr_pwm5_lock[] = { | 1648 | static struct attribute *dme1737_attr_pwm5_lock[] = { |
1652 | SENSOR_DEV_ATTR_PWM_5TO6_LOCK(5), | 1649 | SENSOR_DEV_ATTR_PWM_5TO6_LOCK(5), |
1653 | NULL | 1650 | NULL |
1654 | }; | 1651 | }; |
1655 | static struct attribute *dme1737_attr_pwm6_lock[] = { | 1652 | static struct attribute *dme1737_attr_pwm6_lock[] = { |
1656 | SENSOR_DEV_ATTR_PWM_5TO6_LOCK(6), | 1653 | SENSOR_DEV_ATTR_PWM_5TO6_LOCK(6), |
1657 | NULL | 1654 | NULL |
1658 | }; | 1655 | }; |
1659 | 1656 | ||
@@ -1678,6 +1675,16 @@ static struct attribute *dme1737_attr_pwm[] = { | |||
1678 | * Super-IO functions | 1675 | * Super-IO functions |
1679 | * --------------------------------------------------------------------- */ | 1676 | * --------------------------------------------------------------------- */ |
1680 | 1677 | ||
1678 | static inline void dme1737_sio_enter(int sio_cip) | ||
1679 | { | ||
1680 | outb(0x55, sio_cip); | ||
1681 | } | ||
1682 | |||
1683 | static inline void dme1737_sio_exit(int sio_cip) | ||
1684 | { | ||
1685 | outb(0xaa, sio_cip); | ||
1686 | } | ||
1687 | |||
1681 | static inline int dme1737_sio_inb(int sio_cip, int reg) | 1688 | static inline int dme1737_sio_inb(int sio_cip, int reg) |
1682 | { | 1689 | { |
1683 | outb(reg, sio_cip); | 1690 | outb(reg, sio_cip); |
@@ -1690,14 +1697,12 @@ static inline void dme1737_sio_outb(int sio_cip, int reg, int val) | |||
1690 | outb(val, sio_cip + 1); | 1697 | outb(val, sio_cip + 1); |
1691 | } | 1698 | } |
1692 | 1699 | ||
1693 | static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client) | 1700 | static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data) |
1694 | { | 1701 | { |
1695 | struct dme1737_data *data = i2c_get_clientdata(client); | ||
1696 | int err = 0, reg; | 1702 | int err = 0, reg; |
1697 | u16 addr; | 1703 | u16 addr; |
1698 | 1704 | ||
1699 | /* Enter configuration mode */ | 1705 | dme1737_sio_enter(sio_cip); |
1700 | outb(0x55, sio_cip); | ||
1701 | 1706 | ||
1702 | /* Check device ID | 1707 | /* Check device ID |
1703 | * The DME1737 can return either 0x78 or 0x77 as its device ID. */ | 1708 | * The DME1737 can return either 0x78 or 0x77 as its device ID. */ |
@@ -1734,8 +1739,7 @@ static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client) | |||
1734 | } | 1739 | } |
1735 | 1740 | ||
1736 | exit: | 1741 | exit: |
1737 | /* Exit configuration mode */ | 1742 | dme1737_sio_exit(sio_cip); |
1738 | outb(0xaa, sio_cip); | ||
1739 | 1743 | ||
1740 | return err; | 1744 | return err; |
1741 | } | 1745 | } |
@@ -1744,51 +1748,142 @@ exit: | |||
1744 | * Device detection, registration and initialization | 1748 | * Device detection, registration and initialization |
1745 | * --------------------------------------------------------------------- */ | 1749 | * --------------------------------------------------------------------- */ |
1746 | 1750 | ||
1747 | static struct i2c_driver dme1737_driver; | 1751 | static struct i2c_driver dme1737_i2c_driver; |
1748 | 1752 | ||
1749 | static void dme1737_chmod_file(struct i2c_client *client, | 1753 | static void dme1737_chmod_file(struct device *dev, |
1750 | struct attribute *attr, mode_t mode) | 1754 | struct attribute *attr, mode_t mode) |
1751 | { | 1755 | { |
1752 | if (sysfs_chmod_file(&client->dev.kobj, attr, mode)) { | 1756 | if (sysfs_chmod_file(&dev->kobj, attr, mode)) { |
1753 | dev_warn(&client->dev, "Failed to change permissions of %s.\n", | 1757 | dev_warn(dev, "Failed to change permissions of %s.\n", |
1754 | attr->name); | 1758 | attr->name); |
1755 | } | 1759 | } |
1756 | } | 1760 | } |
1757 | 1761 | ||
1758 | static void dme1737_chmod_group(struct i2c_client *client, | 1762 | static void dme1737_chmod_group(struct device *dev, |
1759 | const struct attribute_group *group, | 1763 | const struct attribute_group *group, |
1760 | mode_t mode) | 1764 | mode_t mode) |
1761 | { | 1765 | { |
1762 | struct attribute **attr; | 1766 | struct attribute **attr; |
1763 | 1767 | ||
1764 | for (attr = group->attrs; *attr; attr++) { | 1768 | for (attr = group->attrs; *attr; attr++) { |
1765 | dme1737_chmod_file(client, *attr, mode); | 1769 | dme1737_chmod_file(dev, *attr, mode); |
1766 | } | 1770 | } |
1767 | } | 1771 | } |
1768 | 1772 | ||
1769 | static int dme1737_init_client(struct i2c_client *client) | 1773 | static void dme1737_remove_files(struct device *dev) |
1770 | { | 1774 | { |
1771 | struct dme1737_data *data = i2c_get_clientdata(client); | 1775 | struct dme1737_data *data = dev_get_drvdata(dev); |
1776 | int ix; | ||
1777 | |||
1778 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { | ||
1779 | if (data->has_fan & (1 << ix)) { | ||
1780 | sysfs_remove_group(&dev->kobj, | ||
1781 | &dme1737_fan_group[ix]); | ||
1782 | } | ||
1783 | } | ||
1784 | |||
1785 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { | ||
1786 | if (data->has_pwm & (1 << ix)) { | ||
1787 | sysfs_remove_group(&dev->kobj, | ||
1788 | &dme1737_pwm_group[ix]); | ||
1789 | } | ||
1790 | } | ||
1791 | |||
1792 | sysfs_remove_group(&dev->kobj, &dme1737_group); | ||
1793 | } | ||
1794 | |||
1795 | static int dme1737_create_files(struct device *dev) | ||
1796 | { | ||
1797 | struct dme1737_data *data = dev_get_drvdata(dev); | ||
1798 | int err, ix; | ||
1799 | |||
1800 | /* Create standard sysfs attributes */ | ||
1801 | if ((err = sysfs_create_group(&dev->kobj, &dme1737_group))) { | ||
1802 | goto exit; | ||
1803 | } | ||
1804 | |||
1805 | /* Create fan sysfs attributes */ | ||
1806 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { | ||
1807 | if (data->has_fan & (1 << ix)) { | ||
1808 | if ((err = sysfs_create_group(&dev->kobj, | ||
1809 | &dme1737_fan_group[ix]))) { | ||
1810 | goto exit_remove; | ||
1811 | } | ||
1812 | } | ||
1813 | } | ||
1814 | |||
1815 | /* Create PWM sysfs attributes */ | ||
1816 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { | ||
1817 | if (data->has_pwm & (1 << ix)) { | ||
1818 | if ((err = sysfs_create_group(&dev->kobj, | ||
1819 | &dme1737_pwm_group[ix]))) { | ||
1820 | goto exit_remove; | ||
1821 | } | ||
1822 | } | ||
1823 | } | ||
1824 | |||
1825 | /* Inform if the device is locked. Otherwise change the permissions of | ||
1826 | * selected attributes from read-only to read-writeable. */ | ||
1827 | if (data->config & 0x02) { | ||
1828 | dev_info(dev, "Device is locked. Some attributes " | ||
1829 | "will be read-only.\n"); | ||
1830 | } else { | ||
1831 | /* Change permissions of standard attributes */ | ||
1832 | dme1737_chmod_group(dev, &dme1737_lock_group, | ||
1833 | S_IRUGO | S_IWUSR); | ||
1834 | |||
1835 | /* Change permissions of PWM attributes */ | ||
1836 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_lock_group); ix++) { | ||
1837 | if (data->has_pwm & (1 << ix)) { | ||
1838 | dme1737_chmod_group(dev, | ||
1839 | &dme1737_pwm_lock_group[ix], | ||
1840 | S_IRUGO | S_IWUSR); | ||
1841 | } | ||
1842 | } | ||
1843 | |||
1844 | /* Change permissions of pwm[1-3] if in manual mode */ | ||
1845 | for (ix = 0; ix < 3; ix++) { | ||
1846 | if ((data->has_pwm & (1 << ix)) && | ||
1847 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) { | ||
1848 | dme1737_chmod_file(dev, | ||
1849 | dme1737_attr_pwm[ix], | ||
1850 | S_IRUGO | S_IWUSR); | ||
1851 | } | ||
1852 | } | ||
1853 | } | ||
1854 | |||
1855 | return 0; | ||
1856 | |||
1857 | exit_remove: | ||
1858 | dme1737_remove_files(dev); | ||
1859 | exit: | ||
1860 | return err; | ||
1861 | } | ||
1862 | |||
1863 | static int dme1737_init_device(struct device *dev) | ||
1864 | { | ||
1865 | struct dme1737_data *data = dev_get_drvdata(dev); | ||
1866 | struct i2c_client *client = &data->client; | ||
1772 | int ix; | 1867 | int ix; |
1773 | u8 reg; | 1868 | u8 reg; |
1774 | 1869 | ||
1775 | data->config = dme1737_read(client, DME1737_REG_CONFIG); | 1870 | data->config = dme1737_read(client, DME1737_REG_CONFIG); |
1776 | /* Inform if part is not monitoring/started */ | 1871 | /* Inform if part is not monitoring/started */ |
1777 | if (!(data->config & 0x01)) { | 1872 | if (!(data->config & 0x01)) { |
1778 | if (!force_start) { | 1873 | if (!force_start) { |
1779 | dev_err(&client->dev, "Device is not monitoring. " | 1874 | dev_err(dev, "Device is not monitoring. " |
1780 | "Use the force_start load parameter to " | 1875 | "Use the force_start load parameter to " |
1781 | "override.\n"); | 1876 | "override.\n"); |
1782 | return -EFAULT; | 1877 | return -EFAULT; |
1783 | } | 1878 | } |
1784 | 1879 | ||
1785 | /* Force monitoring */ | 1880 | /* Force monitoring */ |
1786 | data->config |= 0x01; | 1881 | data->config |= 0x01; |
1787 | dme1737_write(client, DME1737_REG_CONFIG, data->config); | 1882 | dme1737_write(client, DME1737_REG_CONFIG, data->config); |
1788 | } | 1883 | } |
1789 | /* Inform if part is not ready */ | 1884 | /* Inform if part is not ready */ |
1790 | if (!(data->config & 0x04)) { | 1885 | if (!(data->config & 0x04)) { |
1791 | dev_err(&client->dev, "Device is not ready.\n"); | 1886 | dev_err(dev, "Device is not ready.\n"); |
1792 | return -EFAULT; | 1887 | return -EFAULT; |
1793 | } | 1888 | } |
1794 | 1889 | ||
@@ -1809,9 +1904,9 @@ static int dme1737_init_client(struct i2c_client *client) | |||
1809 | /* Determine if the optional fan[5-6] and/or pwm[5-6] are enabled. | 1904 | /* Determine if the optional fan[5-6] and/or pwm[5-6] are enabled. |
1810 | * For this, we need to query the runtime registers through the | 1905 | * For this, we need to query the runtime registers through the |
1811 | * Super-IO LPC interface. Try both config ports 0x2e and 0x4e. */ | 1906 | * Super-IO LPC interface. Try both config ports 0x2e and 0x4e. */ |
1812 | if (dme1737_sio_get_features(0x2e, client) && | 1907 | if (dme1737_i2c_get_features(0x2e, data) && |
1813 | dme1737_sio_get_features(0x4e, client)) { | 1908 | dme1737_i2c_get_features(0x4e, data)) { |
1814 | dev_warn(&client->dev, "Failed to query Super-IO for optional " | 1909 | dev_warn(dev, "Failed to query Super-IO for optional " |
1815 | "features.\n"); | 1910 | "features.\n"); |
1816 | } | 1911 | } |
1817 | 1912 | ||
@@ -1819,7 +1914,7 @@ static int dme1737_init_client(struct i2c_client *client) | |||
1819 | data->has_fan |= 0x03; | 1914 | data->has_fan |= 0x03; |
1820 | data->has_pwm |= 0x03; | 1915 | data->has_pwm |= 0x03; |
1821 | 1916 | ||
1822 | dev_info(&client->dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " | 1917 | dev_info(dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " |
1823 | "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", | 1918 | "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", |
1824 | (data->has_pwm & (1 << 2)) ? "yes" : "no", | 1919 | (data->has_pwm & (1 << 2)) ? "yes" : "no", |
1825 | (data->has_pwm & (1 << 4)) ? "yes" : "no", | 1920 | (data->has_pwm & (1 << 4)) ? "yes" : "no", |
@@ -1832,7 +1927,7 @@ static int dme1737_init_client(struct i2c_client *client) | |||
1832 | reg = dme1737_read(client, DME1737_REG_TACH_PWM); | 1927 | reg = dme1737_read(client, DME1737_REG_TACH_PWM); |
1833 | /* Inform if fan-to-pwm mapping differs from the default */ | 1928 | /* Inform if fan-to-pwm mapping differs from the default */ |
1834 | if (reg != 0xa4) { | 1929 | if (reg != 0xa4) { |
1835 | dev_warn(&client->dev, "Non-standard fan to pwm mapping: " | 1930 | dev_warn(dev, "Non-standard fan to pwm mapping: " |
1836 | "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " | 1931 | "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " |
1837 | "fan4->pwm%d. Please report to the driver " | 1932 | "fan4->pwm%d. Please report to the driver " |
1838 | "maintainer.\n", | 1933 | "maintainer.\n", |
@@ -1849,7 +1944,7 @@ static int dme1737_init_client(struct i2c_client *client) | |||
1849 | DME1737_REG_PWM_CONFIG(ix)); | 1944 | DME1737_REG_PWM_CONFIG(ix)); |
1850 | if ((data->has_pwm & (1 << ix)) && | 1945 | if ((data->has_pwm & (1 << ix)) && |
1851 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { | 1946 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { |
1852 | dev_info(&client->dev, "Switching pwm%d to " | 1947 | dev_info(dev, "Switching pwm%d to " |
1853 | "manual mode.\n", ix + 1); | 1948 | "manual mode.\n", ix + 1); |
1854 | data->pwm_config[ix] = PWM_EN_TO_REG(1, | 1949 | data->pwm_config[ix] = PWM_EN_TO_REG(1, |
1855 | data->pwm_config[ix]); | 1950 | data->pwm_config[ix]); |
@@ -1872,13 +1967,14 @@ static int dme1737_init_client(struct i2c_client *client) | |||
1872 | return 0; | 1967 | return 0; |
1873 | } | 1968 | } |
1874 | 1969 | ||
1875 | static int dme1737_detect(struct i2c_adapter *adapter, int address, | 1970 | static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address, |
1876 | int kind) | 1971 | int kind) |
1877 | { | 1972 | { |
1878 | u8 company, verstep = 0; | 1973 | u8 company, verstep = 0; |
1879 | struct i2c_client *client; | 1974 | struct i2c_client *client; |
1880 | struct dme1737_data *data; | 1975 | struct dme1737_data *data; |
1881 | int ix, err = 0; | 1976 | struct device *dev; |
1977 | int err = 0; | ||
1882 | const char *name; | 1978 | const char *name; |
1883 | 1979 | ||
1884 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | 1980 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { |
@@ -1894,7 +1990,8 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address, | |||
1894 | i2c_set_clientdata(client, data); | 1990 | i2c_set_clientdata(client, data); |
1895 | client->addr = address; | 1991 | client->addr = address; |
1896 | client->adapter = adapter; | 1992 | client->adapter = adapter; |
1897 | client->driver = &dme1737_driver; | 1993 | client->driver = &dme1737_i2c_driver; |
1994 | dev = &client->dev; | ||
1898 | 1995 | ||
1899 | /* A negative kind means that the driver was loaded with no force | 1996 | /* A negative kind means that the driver was loaded with no force |
1900 | * parameter (default), so we must identify the chip. */ | 1997 | * parameter (default), so we must identify the chip. */ |
@@ -1922,92 +2019,33 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address, | |||
1922 | goto exit_kfree; | 2019 | goto exit_kfree; |
1923 | } | 2020 | } |
1924 | 2021 | ||
2022 | dev_info(dev, "Found a DME1737 chip at 0x%02x (rev 0x%02x).\n", | ||
2023 | client->addr, verstep); | ||
2024 | |||
1925 | /* Initialize the DME1737 chip */ | 2025 | /* Initialize the DME1737 chip */ |
1926 | if ((err = dme1737_init_client(client))) { | 2026 | if ((err = dme1737_init_device(dev))) { |
2027 | dev_err(dev, "Failed to initialize device.\n"); | ||
1927 | goto exit_detach; | 2028 | goto exit_detach; |
1928 | } | 2029 | } |
1929 | 2030 | ||
1930 | /* Create standard sysfs attributes */ | 2031 | /* Create sysfs files */ |
1931 | if ((err = sysfs_create_group(&client->dev.kobj, &dme1737_group))) { | 2032 | if ((err = dme1737_create_files(dev))) { |
1932 | goto exit_detach; | 2033 | dev_err(dev, "Failed to create sysfs files.\n"); |
1933 | } | 2034 | goto exit_detach; |
1934 | |||
1935 | /* Create fan sysfs attributes */ | ||
1936 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { | ||
1937 | if (data->has_fan & (1 << ix)) { | ||
1938 | if ((err = sysfs_create_group(&client->dev.kobj, | ||
1939 | &dme1737_fan_group[ix]))) { | ||
1940 | goto exit_remove; | ||
1941 | } | ||
1942 | } | ||
1943 | } | ||
1944 | |||
1945 | /* Create PWM sysfs attributes */ | ||
1946 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { | ||
1947 | if (data->has_pwm & (1 << ix)) { | ||
1948 | if ((err = sysfs_create_group(&client->dev.kobj, | ||
1949 | &dme1737_pwm_group[ix]))) { | ||
1950 | goto exit_remove; | ||
1951 | } | ||
1952 | } | ||
1953 | } | ||
1954 | |||
1955 | /* Inform if the device is locked. Otherwise change the permissions of | ||
1956 | * selected attributes from read-only to read-writeable. */ | ||
1957 | if (data->config & 0x02) { | ||
1958 | dev_info(&client->dev, "Device is locked. Some attributes " | ||
1959 | "will be read-only.\n"); | ||
1960 | } else { | ||
1961 | /* Change permissions of standard attributes */ | ||
1962 | dme1737_chmod_group(client, &dme1737_lock_group, | ||
1963 | S_IRUGO | S_IWUSR); | ||
1964 | |||
1965 | /* Change permissions of PWM attributes */ | ||
1966 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_lock_group); ix++) { | ||
1967 | if (data->has_pwm & (1 << ix)) { | ||
1968 | dme1737_chmod_group(client, | ||
1969 | &dme1737_pwm_lock_group[ix], | ||
1970 | S_IRUGO | S_IWUSR); | ||
1971 | } | ||
1972 | } | ||
1973 | |||
1974 | /* Change permissions of pwm[1-3] if in manual mode */ | ||
1975 | for (ix = 0; ix < 3; ix++) { | ||
1976 | if ((data->has_pwm & (1 << ix)) && | ||
1977 | (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) { | ||
1978 | dme1737_chmod_file(client, | ||
1979 | dme1737_attr_pwm[ix], | ||
1980 | S_IRUGO | S_IWUSR); | ||
1981 | } | ||
1982 | } | ||
1983 | } | 2035 | } |
1984 | 2036 | ||
1985 | /* Register device */ | 2037 | /* Register device */ |
1986 | data->class_dev = hwmon_device_register(&client->dev); | 2038 | data->class_dev = hwmon_device_register(dev); |
1987 | if (IS_ERR(data->class_dev)) { | 2039 | if (IS_ERR(data->class_dev)) { |
2040 | dev_err(dev, "Failed to register device.\n"); | ||
1988 | err = PTR_ERR(data->class_dev); | 2041 | err = PTR_ERR(data->class_dev); |
1989 | goto exit_remove; | 2042 | goto exit_remove; |
1990 | } | 2043 | } |
1991 | 2044 | ||
1992 | dev_info(&adapter->dev, "Found a DME1737 chip at 0x%02x " | ||
1993 | "(rev 0x%02x)\n", client->addr, verstep); | ||
1994 | |||
1995 | return 0; | 2045 | return 0; |
1996 | 2046 | ||
1997 | exit_remove: | 2047 | exit_remove: |
1998 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { | 2048 | dme1737_remove_files(dev); |
1999 | if (data->has_fan & (1 << ix)) { | ||
2000 | sysfs_remove_group(&client->dev.kobj, | ||
2001 | &dme1737_fan_group[ix]); | ||
2002 | } | ||
2003 | } | ||
2004 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { | ||
2005 | if (data->has_pwm & (1 << ix)) { | ||
2006 | sysfs_remove_group(&client->dev.kobj, | ||
2007 | &dme1737_pwm_group[ix]); | ||
2008 | } | ||
2009 | } | ||
2010 | sysfs_remove_group(&client->dev.kobj, &dme1737_group); | ||
2011 | exit_detach: | 2049 | exit_detach: |
2012 | i2c_detach_client(client); | 2050 | i2c_detach_client(client); |
2013 | exit_kfree: | 2051 | exit_kfree: |
@@ -2016,35 +2054,22 @@ exit: | |||
2016 | return err; | 2054 | return err; |
2017 | } | 2055 | } |
2018 | 2056 | ||
2019 | static int dme1737_attach_adapter(struct i2c_adapter *adapter) | 2057 | static int dme1737_i2c_attach_adapter(struct i2c_adapter *adapter) |
2020 | { | 2058 | { |
2021 | if (!(adapter->class & I2C_CLASS_HWMON)) { | 2059 | if (!(adapter->class & I2C_CLASS_HWMON)) { |
2022 | return 0; | 2060 | return 0; |
2023 | } | 2061 | } |
2024 | 2062 | ||
2025 | return i2c_probe(adapter, &addr_data, dme1737_detect); | 2063 | return i2c_probe(adapter, &addr_data, dme1737_i2c_detect); |
2026 | } | 2064 | } |
2027 | 2065 | ||
2028 | static int dme1737_detach_client(struct i2c_client *client) | 2066 | static int dme1737_i2c_detach_client(struct i2c_client *client) |
2029 | { | 2067 | { |
2030 | struct dme1737_data *data = i2c_get_clientdata(client); | 2068 | struct dme1737_data *data = i2c_get_clientdata(client); |
2031 | int ix, err; | 2069 | int err; |
2032 | 2070 | ||
2033 | hwmon_device_unregister(data->class_dev); | 2071 | hwmon_device_unregister(data->class_dev); |
2034 | 2072 | dme1737_remove_files(&client->dev); | |
2035 | for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { | ||
2036 | if (data->has_fan & (1 << ix)) { | ||
2037 | sysfs_remove_group(&client->dev.kobj, | ||
2038 | &dme1737_fan_group[ix]); | ||
2039 | } | ||
2040 | } | ||
2041 | for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { | ||
2042 | if (data->has_pwm & (1 << ix)) { | ||
2043 | sysfs_remove_group(&client->dev.kobj, | ||
2044 | &dme1737_pwm_group[ix]); | ||
2045 | } | ||
2046 | } | ||
2047 | sysfs_remove_group(&client->dev.kobj, &dme1737_group); | ||
2048 | 2073 | ||
2049 | if ((err = i2c_detach_client(client))) { | 2074 | if ((err = i2c_detach_client(client))) { |
2050 | return err; | 2075 | return err; |
@@ -2054,22 +2079,22 @@ static int dme1737_detach_client(struct i2c_client *client) | |||
2054 | return 0; | 2079 | return 0; |
2055 | } | 2080 | } |
2056 | 2081 | ||
2057 | static struct i2c_driver dme1737_driver = { | 2082 | static struct i2c_driver dme1737_i2c_driver = { |
2058 | .driver = { | 2083 | .driver = { |
2059 | .name = "dme1737", | 2084 | .name = "dme1737", |
2060 | }, | 2085 | }, |
2061 | .attach_adapter = dme1737_attach_adapter, | 2086 | .attach_adapter = dme1737_i2c_attach_adapter, |
2062 | .detach_client = dme1737_detach_client, | 2087 | .detach_client = dme1737_i2c_detach_client, |
2063 | }; | 2088 | }; |
2064 | 2089 | ||
2065 | static int __init dme1737_init(void) | 2090 | static int __init dme1737_init(void) |
2066 | { | 2091 | { |
2067 | return i2c_add_driver(&dme1737_driver); | 2092 | return i2c_add_driver(&dme1737_i2c_driver); |
2068 | } | 2093 | } |
2069 | 2094 | ||
2070 | static void __exit dme1737_exit(void) | 2095 | static void __exit dme1737_exit(void) |
2071 | { | 2096 | { |
2072 | i2c_del_driver(&dme1737_driver); | 2097 | i2c_del_driver(&dme1737_i2c_driver); |
2073 | } | 2098 | } |
2074 | 2099 | ||
2075 | MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>"); | 2100 | MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>"); |