aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark M. Hoffman <mhoffman@lightlink.com>2007-10-10 22:32:50 -0400
committerMark M. Hoffman <mhoffman@lightlink.com>2007-10-10 22:45:54 -0400
commit62ee3e10d3ea11f50bcec8dffb46555fa16d417b (patch)
tree4d0718131216c190bc1ed765ac43409f5ece8405
parent57c7c3a0fdea95eddcaeba31e7ca7dfc917682ab (diff)
parent67e2f3285ecff8ceaa555e7614d1603b76e09b95 (diff)
hwmon: (dme1737) Fix some merge conflicts
class_dev -> hwmon_dev Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
-rw-r--r--drivers/hwmon/dme1737.c589
1 files changed, 312 insertions, 277 deletions
diff --git a/drivers/hwmon/dme1737.c b/drivers/hwmon/dme1737.c
index 14ebbfb3b14b..ec8edd2a8cbd 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
494static struct dme1737_data *dme1737_update_device(struct device *dev) 494static 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,
683static ssize_t set_in(struct device *dev, struct device_attribute *attr, 683static 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,
763static ssize_t set_temp(struct device *dev, struct device_attribute *attr, 763static 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,
852static ssize_t set_zone(struct device *dev, struct device_attribute *attr, 852static 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,
959static ssize_t set_fan(struct device *dev, struct device_attribute *attr, 959static 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 }
1011exit: 1011exit:
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
1095static struct attribute *dme1737_attr_pwm[]; 1095static struct attribute *dme1737_attr_pwm[];
1096static void dme1737_chmod_file(struct i2c_client*, struct attribute*, mode_t); 1096static void dme1737_chmod_file(struct device*, struct attribute*, mode_t);
1097 1097
1098static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, 1098static 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 }
1279exit: 1277exit:
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,
1298static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, 1296static 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) \
1324static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \ 1321static 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); \
1326static SENSOR_DEVICE_ATTR_2(in##ix##_min, S_IRUGO | S_IWUSR, \ 1323static 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); \
1328static SENSOR_DEVICE_ATTR_2(in##ix##_max, S_IRUGO | S_IWUSR, \ 1325static 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); \
1330static SENSOR_DEVICE_ATTR_2(in##ix##_alarm, S_IRUGO, \ 1327static 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
1333SENSOR_DEVICE_ATTR_IN(0); 1330SENSOR_DEVICE_ATTR_IN(0);
1334SENSOR_DEVICE_ATTR_IN(1); 1331SENSOR_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) \
1344static SENSOR_DEVICE_ATTR_2(temp##ix##_input, S_IRUGO, \ 1341static 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); \
1346static SENSOR_DEVICE_ATTR_2(temp##ix##_min, S_IRUGO | S_IWUSR, \ 1343static 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); \
1348static SENSOR_DEVICE_ATTR_2(temp##ix##_max, S_IRUGO | S_IWUSR, \ 1345static 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); \
1350static SENSOR_DEVICE_ATTR_2(temp##ix##_offset, S_IRUGO, \ 1347static 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); \
1352static SENSOR_DEVICE_ATTR_2(temp##ix##_alarm, S_IRUGO, \ 1349static 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); \
1354static SENSOR_DEVICE_ATTR_2(temp##ix##_fault, S_IRUGO, \ 1351static 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
1357SENSOR_DEVICE_ATTR_TEMP(1); 1354SENSOR_DEVICE_ATTR_TEMP(1);
1358SENSOR_DEVICE_ATTR_TEMP(2); 1355SENSOR_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) \
1364static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_channels_temp, S_IRUGO, \ 1361static 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); \
1366static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp_hyst, S_IRUGO, \ 1363static 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); \
1368static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point1_temp, S_IRUGO, \ 1365static 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); \
1370static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point2_temp, S_IRUGO, \ 1367static 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); \
1372static SENSOR_DEVICE_ATTR_2(zone##ix##_auto_point3_temp, S_IRUGO, \ 1369static 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
1375SENSOR_DEVICE_ATTR_ZONE(1); 1372SENSOR_DEVICE_ATTR_ZONE(1);
1376SENSOR_DEVICE_ATTR_ZONE(2); 1373SENSOR_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) \
1382static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ 1379static 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); \
1384static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ 1381static 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); \
1386static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ 1383static 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); \
1388static SENSOR_DEVICE_ATTR_2(fan##ix##_type, S_IRUGO | S_IWUSR, \ 1385static 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
1391SENSOR_DEVICE_ATTR_FAN_1TO4(1); 1388SENSOR_DEVICE_ATTR_FAN_1TO4(1);
1392SENSOR_DEVICE_ATTR_FAN_1TO4(2); 1389SENSOR_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) \
1399static SENSOR_DEVICE_ATTR_2(fan##ix##_input, S_IRUGO, \ 1396static 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); \
1401static SENSOR_DEVICE_ATTR_2(fan##ix##_min, S_IRUGO | S_IWUSR, \ 1398static 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); \
1403static SENSOR_DEVICE_ATTR_2(fan##ix##_alarm, S_IRUGO, \ 1400static 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); \
1405static SENSOR_DEVICE_ATTR_2(fan##ix##_max, S_IRUGO | S_IWUSR, \ 1402static 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
1408SENSOR_DEVICE_ATTR_FAN_5TO6(5); 1405SENSOR_DEVICE_ATTR_FAN_5TO6(5);
1409SENSOR_DEVICE_ATTR_FAN_5TO6(6); 1406SENSOR_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) \
1414static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO, \ 1411static 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); \
1416static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO, \ 1413static 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); \
1418static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ 1415static 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); \
1420static SENSOR_DEVICE_ATTR_2(pwm##ix##_ramp_rate, S_IRUGO, \ 1417static 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); \
1422static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_channels_zone, S_IRUGO, \ 1419static 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); \
1424static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_pwm_min, S_IRUGO, \ 1421static 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); \
1426static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point1_pwm, S_IRUGO, \ 1423static 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); \
1428static SENSOR_DEVICE_ATTR_2(pwm##ix##_auto_point2_pwm, S_IRUGO, \ 1425static 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
1431SENSOR_DEVICE_ATTR_PWM_1TO3(1); 1428SENSOR_DEVICE_ATTR_PWM_1TO3(1);
1432SENSOR_DEVICE_ATTR_PWM_1TO3(2); 1429SENSOR_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) \
1438static SENSOR_DEVICE_ATTR_2(pwm##ix, S_IRUGO | S_IWUSR, \ 1435static 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); \
1440static SENSOR_DEVICE_ATTR_2(pwm##ix##_freq, S_IRUGO | S_IWUSR, \ 1437static 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); \
1442static SENSOR_DEVICE_ATTR_2(pwm##ix##_enable, S_IRUGO, \ 1439static 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
1445SENSOR_DEVICE_ATTR_PWM_5TO6(5); 1442SENSOR_DEVICE_ATTR_PWM_5TO6(5);
1446SENSOR_DEVICE_ATTR_PWM_5TO6(6); 1443SENSOR_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 */
1521static struct attribute *dme1737_attr[] ={ 1518static 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
1544static const struct attribute_group dme1737_group = { 1541static 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. */
1551static struct attribute *dme1737_attr_pwm1[] = { 1548static 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};
1555static struct attribute *dme1737_attr_pwm2[] = { 1552static 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};
1559static struct attribute *dme1737_attr_pwm3[] = { 1556static 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};
1563static struct attribute *dme1737_attr_pwm5[] = { 1560static 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};
1567static struct attribute *dme1737_attr_pwm6[] = { 1564static 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. */
1584static struct attribute *dme1737_attr_fan1[] = { 1581static 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};
1588static struct attribute *dme1737_attr_fan2[] = { 1585static 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};
1592static struct attribute *dme1737_attr_fan3[] = { 1589static 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};
1596static struct attribute *dme1737_attr_fan4[] = { 1593static 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};
1600static struct attribute *dme1737_attr_fan5[] = { 1597static 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};
1604static struct attribute *dme1737_attr_fan6[] = { 1601static 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. */
1639static struct attribute *dme1737_attr_pwm1_lock[] = { 1636static 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};
1643static struct attribute *dme1737_attr_pwm2_lock[] = { 1640static 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};
1647static struct attribute *dme1737_attr_pwm3_lock[] = { 1644static 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};
1651static struct attribute *dme1737_attr_pwm5_lock[] = { 1648static 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};
1655static struct attribute *dme1737_attr_pwm6_lock[] = { 1652static 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
1678static inline void dme1737_sio_enter(int sio_cip)
1679{
1680 outb(0x55, sio_cip);
1681}
1682
1683static inline void dme1737_sio_exit(int sio_cip)
1684{
1685 outb(0xaa, sio_cip);
1686}
1687
1681static inline int dme1737_sio_inb(int sio_cip, int reg) 1688static inline int dme1737_sio_inb(int sio_cip, int reg)
1682{ 1689{
1683 outb(reg, sio_cip); 1690 outb(reg, sio_cip);
@@ -1690,105 +1697,146 @@ 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
1693static int dme1737_sio_get_features(int sio_cip, struct i2c_client *client)
1694{
1695 struct dme1737_data *data = i2c_get_clientdata(client);
1696 int err = 0, reg;
1697 u16 addr;
1698
1699 /* Enter configuration mode */
1700 outb(0x55, sio_cip);
1701
1702 /* Check device ID
1703 * The DME1737 can return either 0x78 or 0x77 as its device ID. */
1704 reg = dme1737_sio_inb(sio_cip, 0x20);
1705 if (!(reg == 0x77 || reg == 0x78)) {
1706 err = -ENODEV;
1707 goto exit;
1708 }
1709
1710 /* Select logical device A (runtime registers) */
1711 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
1712
1713 /* Get the base address of the runtime registers */
1714 if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
1715 dme1737_sio_inb(sio_cip, 0x61))) {
1716 err = -ENODEV;
1717 goto exit;
1718 }
1719
1720 /* Read the runtime registers to determine which optional features
1721 * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set
1722 * to '10' if the respective feature is enabled. */
1723 if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */
1724 data->has_fan |= (1 << 5);
1725 }
1726 if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */
1727 data->has_pwm |= (1 << 5);
1728 }
1729 if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */
1730 data->has_fan |= (1 << 4);
1731 }
1732 if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */
1733 data->has_pwm |= (1 << 4);
1734 }
1735
1736exit:
1737 /* Exit configuration mode */
1738 outb(0xaa, sio_cip);
1739
1740 return err;
1741}
1742
1743/* --------------------------------------------------------------------- 1700/* ---------------------------------------------------------------------
1744 * Device detection, registration and initialization 1701 * Device detection, registration and initialization
1745 * --------------------------------------------------------------------- */ 1702 * --------------------------------------------------------------------- */
1746 1703
1747static struct i2c_driver dme1737_driver; 1704static int dme1737_i2c_get_features(int, struct dme1737_data*);
1748 1705
1749static void dme1737_chmod_file(struct i2c_client *client, 1706static void dme1737_chmod_file(struct device *dev,
1750 struct attribute *attr, mode_t mode) 1707 struct attribute *attr, mode_t mode)
1751{ 1708{
1752 if (sysfs_chmod_file(&client->dev.kobj, attr, mode)) { 1709 if (sysfs_chmod_file(&dev->kobj, attr, mode)) {
1753 dev_warn(&client->dev, "Failed to change permissions of %s.\n", 1710 dev_warn(dev, "Failed to change permissions of %s.\n",
1754 attr->name); 1711 attr->name);
1755 } 1712 }
1756} 1713}
1757 1714
1758static void dme1737_chmod_group(struct i2c_client *client, 1715static void dme1737_chmod_group(struct device *dev,
1759 const struct attribute_group *group, 1716 const struct attribute_group *group,
1760 mode_t mode) 1717 mode_t mode)
1761{ 1718{
1762 struct attribute **attr; 1719 struct attribute **attr;
1763 1720
1764 for (attr = group->attrs; *attr; attr++) { 1721 for (attr = group->attrs; *attr; attr++) {
1765 dme1737_chmod_file(client, *attr, mode); 1722 dme1737_chmod_file(dev, *attr, mode);
1766 } 1723 }
1767} 1724}
1768 1725
1769static int dme1737_init_client(struct i2c_client *client) 1726static void dme1737_remove_files(struct device *dev)
1770{ 1727{
1771 struct dme1737_data *data = i2c_get_clientdata(client); 1728 struct dme1737_data *data = dev_get_drvdata(dev);
1729 int ix;
1730
1731 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
1732 if (data->has_fan & (1 << ix)) {
1733 sysfs_remove_group(&dev->kobj,
1734 &dme1737_fan_group[ix]);
1735 }
1736 }
1737
1738 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
1739 if (data->has_pwm & (1 << ix)) {
1740 sysfs_remove_group(&dev->kobj,
1741 &dme1737_pwm_group[ix]);
1742 }
1743 }
1744
1745 sysfs_remove_group(&dev->kobj, &dme1737_group);
1746}
1747
1748static int dme1737_create_files(struct device *dev)
1749{
1750 struct dme1737_data *data = dev_get_drvdata(dev);
1751 int err, ix;
1752
1753 /* Create standard sysfs attributes */
1754 if ((err = sysfs_create_group(&dev->kobj, &dme1737_group))) {
1755 goto exit;
1756 }
1757
1758 /* Create fan sysfs attributes */
1759 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
1760 if (data->has_fan & (1 << ix)) {
1761 if ((err = sysfs_create_group(&dev->kobj,
1762 &dme1737_fan_group[ix]))) {
1763 goto exit_remove;
1764 }
1765 }
1766 }
1767
1768 /* Create PWM sysfs attributes */
1769 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
1770 if (data->has_pwm & (1 << ix)) {
1771 if ((err = sysfs_create_group(&dev->kobj,
1772 &dme1737_pwm_group[ix]))) {
1773 goto exit_remove;
1774 }
1775 }
1776 }
1777
1778 /* Inform if the device is locked. Otherwise change the permissions of
1779 * selected attributes from read-only to read-writeable. */
1780 if (data->config & 0x02) {
1781 dev_info(dev, "Device is locked. Some attributes "
1782 "will be read-only.\n");
1783 } else {
1784 /* Change permissions of standard attributes */
1785 dme1737_chmod_group(dev, &dme1737_lock_group,
1786 S_IRUGO | S_IWUSR);
1787
1788 /* Change permissions of PWM attributes */
1789 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_lock_group); ix++) {
1790 if (data->has_pwm & (1 << ix)) {
1791 dme1737_chmod_group(dev,
1792 &dme1737_pwm_lock_group[ix],
1793 S_IRUGO | S_IWUSR);
1794 }
1795 }
1796
1797 /* Change permissions of pwm[1-3] if in manual mode */
1798 for (ix = 0; ix < 3; ix++) {
1799 if ((data->has_pwm & (1 << ix)) &&
1800 (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) {
1801 dme1737_chmod_file(dev,
1802 dme1737_attr_pwm[ix],
1803 S_IRUGO | S_IWUSR);
1804 }
1805 }
1806 }
1807
1808 return 0;
1809
1810exit_remove:
1811 dme1737_remove_files(dev);
1812exit:
1813 return err;
1814}
1815
1816static int dme1737_init_device(struct device *dev)
1817{
1818 struct dme1737_data *data = dev_get_drvdata(dev);
1819 struct i2c_client *client = &data->client;
1772 int ix; 1820 int ix;
1773 u8 reg; 1821 u8 reg;
1774 1822
1775 data->config = dme1737_read(client, DME1737_REG_CONFIG); 1823 data->config = dme1737_read(client, DME1737_REG_CONFIG);
1776 /* Inform if part is not monitoring/started */ 1824 /* Inform if part is not monitoring/started */
1777 if (!(data->config & 0x01)) { 1825 if (!(data->config & 0x01)) {
1778 if (!force_start) { 1826 if (!force_start) {
1779 dev_err(&client->dev, "Device is not monitoring. " 1827 dev_err(dev, "Device is not monitoring. "
1780 "Use the force_start load parameter to " 1828 "Use the force_start load parameter to "
1781 "override.\n"); 1829 "override.\n");
1782 return -EFAULT; 1830 return -EFAULT;
1783 } 1831 }
1784 1832
1785 /* Force monitoring */ 1833 /* Force monitoring */
1786 data->config |= 0x01; 1834 data->config |= 0x01;
1787 dme1737_write(client, DME1737_REG_CONFIG, data->config); 1835 dme1737_write(client, DME1737_REG_CONFIG, data->config);
1788 } 1836 }
1789 /* Inform if part is not ready */ 1837 /* Inform if part is not ready */
1790 if (!(data->config & 0x04)) { 1838 if (!(data->config & 0x04)) {
1791 dev_err(&client->dev, "Device is not ready.\n"); 1839 dev_err(dev, "Device is not ready.\n");
1792 return -EFAULT; 1840 return -EFAULT;
1793 } 1841 }
1794 1842
@@ -1809,9 +1857,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. 1857 /* 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 1858 * For this, we need to query the runtime registers through the
1811 * Super-IO LPC interface. Try both config ports 0x2e and 0x4e. */ 1859 * Super-IO LPC interface. Try both config ports 0x2e and 0x4e. */
1812 if (dme1737_sio_get_features(0x2e, client) && 1860 if (dme1737_i2c_get_features(0x2e, data) &&
1813 dme1737_sio_get_features(0x4e, client)) { 1861 dme1737_i2c_get_features(0x4e, data)) {
1814 dev_warn(&client->dev, "Failed to query Super-IO for optional " 1862 dev_warn(dev, "Failed to query Super-IO for optional "
1815 "features.\n"); 1863 "features.\n");
1816 } 1864 }
1817 1865
@@ -1819,7 +1867,7 @@ static int dme1737_init_client(struct i2c_client *client)
1819 data->has_fan |= 0x03; 1867 data->has_fan |= 0x03;
1820 data->has_pwm |= 0x03; 1868 data->has_pwm |= 0x03;
1821 1869
1822 dev_info(&client->dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " 1870 dev_info(dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, "
1823 "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", 1871 "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n",
1824 (data->has_pwm & (1 << 2)) ? "yes" : "no", 1872 (data->has_pwm & (1 << 2)) ? "yes" : "no",
1825 (data->has_pwm & (1 << 4)) ? "yes" : "no", 1873 (data->has_pwm & (1 << 4)) ? "yes" : "no",
@@ -1832,7 +1880,7 @@ static int dme1737_init_client(struct i2c_client *client)
1832 reg = dme1737_read(client, DME1737_REG_TACH_PWM); 1880 reg = dme1737_read(client, DME1737_REG_TACH_PWM);
1833 /* Inform if fan-to-pwm mapping differs from the default */ 1881 /* Inform if fan-to-pwm mapping differs from the default */
1834 if (reg != 0xa4) { 1882 if (reg != 0xa4) {
1835 dev_warn(&client->dev, "Non-standard fan to pwm mapping: " 1883 dev_warn(dev, "Non-standard fan to pwm mapping: "
1836 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, " 1884 "fan1->pwm%d, fan2->pwm%d, fan3->pwm%d, "
1837 "fan4->pwm%d. Please report to the driver " 1885 "fan4->pwm%d. Please report to the driver "
1838 "maintainer.\n", 1886 "maintainer.\n",
@@ -1849,7 +1897,7 @@ static int dme1737_init_client(struct i2c_client *client)
1849 DME1737_REG_PWM_CONFIG(ix)); 1897 DME1737_REG_PWM_CONFIG(ix));
1850 if ((data->has_pwm & (1 << ix)) && 1898 if ((data->has_pwm & (1 << ix)) &&
1851 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { 1899 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) {
1852 dev_info(&client->dev, "Switching pwm%d to " 1900 dev_info(dev, "Switching pwm%d to "
1853 "manual mode.\n", ix + 1); 1901 "manual mode.\n", ix + 1);
1854 data->pwm_config[ix] = PWM_EN_TO_REG(1, 1902 data->pwm_config[ix] = PWM_EN_TO_REG(1,
1855 data->pwm_config[ix]); 1903 data->pwm_config[ix]);
@@ -1872,13 +1920,67 @@ static int dme1737_init_client(struct i2c_client *client)
1872 return 0; 1920 return 0;
1873} 1921}
1874 1922
1875static int dme1737_detect(struct i2c_adapter *adapter, int address, 1923/* ---------------------------------------------------------------------
1876 int kind) 1924 * I2C device detection and registration
1925 * --------------------------------------------------------------------- */
1926
1927static struct i2c_driver dme1737_i2c_driver;
1928
1929static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
1930{
1931 int err = 0, reg;
1932 u16 addr;
1933
1934 dme1737_sio_enter(sio_cip);
1935
1936 /* Check device ID
1937 * The DME1737 can return either 0x78 or 0x77 as its device ID. */
1938 reg = dme1737_sio_inb(sio_cip, 0x20);
1939 if (!(reg == 0x77 || reg == 0x78)) {
1940 err = -ENODEV;
1941 goto exit;
1942 }
1943
1944 /* Select logical device A (runtime registers) */
1945 dme1737_sio_outb(sio_cip, 0x07, 0x0a);
1946
1947 /* Get the base address of the runtime registers */
1948 if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
1949 dme1737_sio_inb(sio_cip, 0x61))) {
1950 err = -ENODEV;
1951 goto exit;
1952 }
1953
1954 /* Read the runtime registers to determine which optional features
1955 * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set
1956 * to '10' if the respective feature is enabled. */
1957 if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */
1958 data->has_fan |= (1 << 5);
1959 }
1960 if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */
1961 data->has_pwm |= (1 << 5);
1962 }
1963 if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */
1964 data->has_fan |= (1 << 4);
1965 }
1966 if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */
1967 data->has_pwm |= (1 << 4);
1968 }
1969
1970exit:
1971 dme1737_sio_exit(sio_cip);
1972
1973 return err;
1974}
1975
1976static int dme1737_i2c_detect(struct i2c_adapter *adapter, int address,
1977 int kind)
1877{ 1978{
1878 u8 company, verstep = 0; 1979 u8 company, verstep = 0;
1879 struct i2c_client *client; 1980 struct i2c_client *client;
1880 struct dme1737_data *data; 1981 struct dme1737_data *data;
1881 int ix, err = 0; 1982 struct device *dev;
1983 int err = 0;
1882 const char *name; 1984 const char *name;
1883 1985
1884 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { 1986 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) {
@@ -1894,7 +1996,8 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address,
1894 i2c_set_clientdata(client, data); 1996 i2c_set_clientdata(client, data);
1895 client->addr = address; 1997 client->addr = address;
1896 client->adapter = adapter; 1998 client->adapter = adapter;
1897 client->driver = &dme1737_driver; 1999 client->driver = &dme1737_i2c_driver;
2000 dev = &client->dev;
1898 2001
1899 /* A negative kind means that the driver was loaded with no force 2002 /* A negative kind means that the driver was loaded with no force
1900 * parameter (default), so we must identify the chip. */ 2003 * parameter (default), so we must identify the chip. */
@@ -1922,92 +2025,33 @@ static int dme1737_detect(struct i2c_adapter *adapter, int address,
1922 goto exit_kfree; 2025 goto exit_kfree;
1923 } 2026 }
1924 2027
2028 dev_info(dev, "Found a DME1737 chip at 0x%02x (rev 0x%02x).\n",
2029 client->addr, verstep);
2030
1925 /* Initialize the DME1737 chip */ 2031 /* Initialize the DME1737 chip */
1926 if ((err = dme1737_init_client(client))) { 2032 if ((err = dme1737_init_device(dev))) {
2033 dev_err(dev, "Failed to initialize device.\n");
1927 goto exit_detach; 2034 goto exit_detach;
1928 } 2035 }
1929 2036
1930 /* Create standard sysfs attributes */ 2037 /* Create sysfs files */
1931 if ((err = sysfs_create_group(&client->dev.kobj, &dme1737_group))) { 2038 if ((err = dme1737_create_files(dev))) {
1932 goto exit_detach; 2039 dev_err(dev, "Failed to create sysfs files.\n");
1933 } 2040 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 } 2041 }
1984 2042
1985 /* Register device */ 2043 /* Register device */
1986 data->hwmon_dev = hwmon_device_register(&client->dev); 2044 data->hwmon_dev = hwmon_device_register(dev);
1987 if (IS_ERR(data->hwmon_dev)) { 2045 if (IS_ERR(data->hwmon_dev)) {
2046 dev_err(dev, "Failed to register device.\n");
1988 err = PTR_ERR(data->hwmon_dev); 2047 err = PTR_ERR(data->hwmon_dev);
1989 goto exit_remove; 2048 goto exit_remove;
1990 } 2049 }
1991 2050
1992 dev_info(&adapter->dev, "Found a DME1737 chip at 0x%02x "
1993 "(rev 0x%02x)\n", client->addr, verstep);
1994
1995 return 0; 2051 return 0;
1996 2052
1997exit_remove: 2053exit_remove:
1998 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { 2054 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);
2011exit_detach: 2055exit_detach:
2012 i2c_detach_client(client); 2056 i2c_detach_client(client);
2013exit_kfree: 2057exit_kfree:
@@ -2016,35 +2060,22 @@ exit:
2016 return err; 2060 return err;
2017} 2061}
2018 2062
2019static int dme1737_attach_adapter(struct i2c_adapter *adapter) 2063static int dme1737_i2c_attach_adapter(struct i2c_adapter *adapter)
2020{ 2064{
2021 if (!(adapter->class & I2C_CLASS_HWMON)) { 2065 if (!(adapter->class & I2C_CLASS_HWMON)) {
2022 return 0; 2066 return 0;
2023 } 2067 }
2024 2068
2025 return i2c_probe(adapter, &addr_data, dme1737_detect); 2069 return i2c_probe(adapter, &addr_data, dme1737_i2c_detect);
2026} 2070}
2027 2071
2028static int dme1737_detach_client(struct i2c_client *client) 2072static int dme1737_i2c_detach_client(struct i2c_client *client)
2029{ 2073{
2030 struct dme1737_data *data = i2c_get_clientdata(client); 2074 struct dme1737_data *data = i2c_get_clientdata(client);
2031 int ix, err; 2075 int err;
2032 2076
2033 hwmon_device_unregister(data->hwmon_dev); 2077 hwmon_device_unregister(data->hwmon_dev);
2034 2078 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 2079
2049 if ((err = i2c_detach_client(client))) { 2080 if ((err = i2c_detach_client(client))) {
2050 return err; 2081 return err;
@@ -2054,22 +2085,26 @@ static int dme1737_detach_client(struct i2c_client *client)
2054 return 0; 2085 return 0;
2055} 2086}
2056 2087
2057static struct i2c_driver dme1737_driver = { 2088static struct i2c_driver dme1737_i2c_driver = {
2058 .driver = { 2089 .driver = {
2059 .name = "dme1737", 2090 .name = "dme1737",
2060 }, 2091 },
2061 .attach_adapter = dme1737_attach_adapter, 2092 .attach_adapter = dme1737_i2c_attach_adapter,
2062 .detach_client = dme1737_detach_client, 2093 .detach_client = dme1737_i2c_detach_client,
2063}; 2094};
2064 2095
2096/* ---------------------------------------------------------------------
2097 * Module initialization and cleanup
2098 * --------------------------------------------------------------------- */
2099
2065static int __init dme1737_init(void) 2100static int __init dme1737_init(void)
2066{ 2101{
2067 return i2c_add_driver(&dme1737_driver); 2102 return i2c_add_driver(&dme1737_i2c_driver);
2068} 2103}
2069 2104
2070static void __exit dme1737_exit(void) 2105static void __exit dme1737_exit(void)
2071{ 2106{
2072 i2c_del_driver(&dme1737_driver); 2107 i2c_del_driver(&dme1737_i2c_driver);
2073} 2108}
2074 2109
2075MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>"); 2110MODULE_AUTHOR("Juerg Haefliger <juergh@gmail.com>");