aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/f71882fg.c
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2009-01-07 10:37:29 -0500
committerJean Delvare <khali@linux-fr.org>2009-01-07 10:37:29 -0500
commitbc27490f9164281b9e1768a5df8e0951541f90a1 (patch)
tree286bef2b3932f9df3b153572d017c128a50683ca /drivers/hwmon/f71882fg.c
parentce0bfa5ee25ddbe4072b16054e809f552bf72320 (diff)
hwmon: (f71882fg) Cleanup fan and temp hyst functions
Simplify fan and temp hyst. handling by treating the registers as an array of nibbles instead of using switch cases. Also unify the way hysts are handled between temp and fans, the temp code was storing the actual per temp hyst values in 4 u8's, where as the fan code was storing actual register values. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon/f71882fg.c')
-rw-r--r--drivers/hwmon/f71882fg.c121
1 files changed, 43 insertions, 78 deletions
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c
index 345f465aa288..de559923454c 100644
--- a/drivers/hwmon/f71882fg.c
+++ b/drivers/hwmon/f71882fg.c
@@ -68,8 +68,7 @@
68#define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr)) 68#define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
69#define F71882FG_REG_TEMP_STATUS 0x62 69#define F71882FG_REG_TEMP_STATUS 0x62
70#define F71882FG_REG_TEMP_BEEP 0x63 70#define F71882FG_REG_TEMP_BEEP 0x63
71#define F71882FG_REG_TEMP_HYST1 0x6C 71#define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
72#define F71882FG_REG_TEMP_HYST23 0x6D
73#define F71882FG_REG_TEMP_TYPE 0x6B 72#define F71882FG_REG_TEMP_TYPE 0x6B
74#define F71882FG_REG_TEMP_DIODE_OPEN 0x6F 73#define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
75 74
@@ -77,8 +76,7 @@
77#define F71882FG_REG_PWM_TYPE 0x94 76#define F71882FG_REG_PWM_TYPE 0x94
78#define F71882FG_REG_PWM_ENABLE 0x96 77#define F71882FG_REG_PWM_ENABLE 0x96
79 78
80#define F71882FG_REG_FAN_HYST0 0x98 79#define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
81#define F71882FG_REG_FAN_HYST1 0x99
82 80
83#define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm))) 81#define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
84#define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm))) 82#define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
@@ -144,7 +142,7 @@ struct f71882fg_data {
144 u8 temp[4]; 142 u8 temp[4];
145 u8 temp_ovt[4]; 143 u8 temp_ovt[4];
146 u8 temp_high[4]; 144 u8 temp_high[4];
147 u8 temp_hyst[4]; 145 u8 temp_hyst[2]; /* 2 hysts stored per reg */
148 u8 temp_type[4]; 146 u8 temp_type[4];
149 u8 temp_status; 147 u8 temp_status;
150 u8 temp_beep; 148 u8 temp_beep;
@@ -688,13 +686,11 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
688 F71882FG_REG_TEMP_HIGH(nr)); 686 F71882FG_REG_TEMP_HIGH(nr));
689 } 687 }
690 688
691 /* Have to hardcode hyst*/ 689 /* hyst */
692 data->temp_hyst[1] = f71882fg_read8(data, 690 data->temp_hyst[0] =
693 F71882FG_REG_TEMP_HYST1) >> 4; 691 f71882fg_read8(data, F71882FG_REG_TEMP_HYST(0));
694 /* Hyst temps 2 & 3 stored in same register */ 692 data->temp_hyst[1] =
695 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST23); 693 f71882fg_read8(data, F71882FG_REG_TEMP_HYST(1));
696 data->temp_hyst[2] = reg & 0x0F;
697 data->temp_hyst[3] = reg >> 4;
698 694
699 /* Have to hardcode type, because temp1 is special */ 695 /* Have to hardcode type, because temp1 is special */
700 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE); 696 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
@@ -715,10 +711,11 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
715 711
716 data->pwm_enable = f71882fg_read8(data, 712 data->pwm_enable = f71882fg_read8(data,
717 F71882FG_REG_PWM_ENABLE); 713 F71882FG_REG_PWM_ENABLE);
718 data->pwm_auto_point_hyst[0] = f71882fg_read8(data, 714 data->pwm_auto_point_hyst[0] =
719 F71882FG_REG_FAN_HYST0); 715 f71882fg_read8(data, F71882FG_REG_FAN_HYST(0));
720 data->pwm_auto_point_hyst[1] = f71882fg_read8(data, 716 data->pwm_auto_point_hyst[1] =
721 F71882FG_REG_FAN_HYST1); 717 f71882fg_read8(data, F71882FG_REG_FAN_HYST(1));
718
722 for (nr = 0; nr < nr_fans; nr++) { 719 for (nr = 0; nr < nr_fans; nr++) {
723 data->pwm_auto_point_mapping[nr] = 720 data->pwm_auto_point_mapping[nr] =
724 f71882fg_read8(data, 721 f71882fg_read8(data,
@@ -1011,7 +1008,11 @@ static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
1011 int temp_max_hyst; 1008 int temp_max_hyst;
1012 1009
1013 mutex_lock(&data->update_lock); 1010 mutex_lock(&data->update_lock);
1014 temp_max_hyst = (data->temp_high[nr] - data->temp_hyst[nr]) * 1000; 1011 if (nr & 1)
1012 temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
1013 else
1014 temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
1015 temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
1015 mutex_unlock(&data->update_lock); 1016 mutex_unlock(&data->update_lock);
1016 1017
1017 return sprintf(buf, "%d\n", temp_max_hyst); 1018 return sprintf(buf, "%d\n", temp_max_hyst);
@@ -1033,26 +1034,15 @@ static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
1033 val = SENSORS_LIMIT(val, data->temp_high[nr] - 15, 1034 val = SENSORS_LIMIT(val, data->temp_high[nr] - 15,
1034 data->temp_high[nr]); 1035 data->temp_high[nr]);
1035 val = data->temp_high[nr] - val; 1036 val = data->temp_high[nr] - val;
1036 data->temp_hyst[nr] = val;
1037 1037
1038 /* convert value to register contents */ 1038 /* convert value to register contents */
1039 switch (nr) { 1039 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
1040 case 1: 1040 if (nr & 1)
1041 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST1); 1041 reg = (reg & 0x0f) | (val << 4);
1042 reg = (reg & 0x0f) | (val << 4); 1042 else
1043 break; 1043 reg = (reg & 0xf0) | val;
1044 case 2: 1044 f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
1045 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST23); 1045 data->temp_hyst[nr / 2] = reg;
1046 reg = (reg & 0xf0) | val;
1047 break;
1048 case 3:
1049 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST23);
1050 reg = (reg & 0x0f) | (val << 4);
1051 break;
1052 }
1053
1054 f71882fg_write8(data, (nr <= 1) ? F71882FG_REG_TEMP_HYST1 :
1055 F71882FG_REG_TEMP_HYST23, reg);
1056 1046
1057 mutex_unlock(&data->update_lock); 1047 mutex_unlock(&data->update_lock);
1058 return ret; 1048 return ret;
@@ -1091,7 +1081,11 @@ static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
1091 int temp_crit_hyst; 1081 int temp_crit_hyst;
1092 1082
1093 mutex_lock(&data->update_lock); 1083 mutex_lock(&data->update_lock);
1094 temp_crit_hyst = (data->temp_ovt[nr] - data->temp_hyst[nr]) * 1000; 1084 if (nr & 1)
1085 temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
1086 else
1087 temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
1088 temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
1095 mutex_unlock(&data->update_lock); 1089 mutex_unlock(&data->update_lock);
1096 1090
1097 return sprintf(buf, "%d\n", temp_crit_hyst); 1091 return sprintf(buf, "%d\n", temp_crit_hyst);
@@ -1320,20 +1314,10 @@ static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
1320 int point = to_sensor_dev_attr_2(devattr)->nr; 1314 int point = to_sensor_dev_attr_2(devattr)->nr;
1321 1315
1322 mutex_lock(&data->update_lock); 1316 mutex_lock(&data->update_lock);
1323 switch (nr) { 1317 if (nr & 1)
1324 case 0: 1318 result = data->pwm_auto_point_hyst[nr / 2] >> 4;
1325 result = data->pwm_auto_point_hyst[0] & 0x0f; 1319 else
1326 break; 1320 result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
1327 case 1:
1328 result = data->pwm_auto_point_hyst[0] >> 4;
1329 break;
1330 case 2:
1331 result = data->pwm_auto_point_hyst[1] & 0x0f;
1332 break;
1333 case 3:
1334 result = data->pwm_auto_point_hyst[1] >> 4;
1335 break;
1336 }
1337 result = 1000 * (data->pwm_auto_point_temp[nr][point] - result); 1321 result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
1338 mutex_unlock(&data->update_lock); 1322 mutex_unlock(&data->update_lock);
1339 1323
@@ -1348,6 +1332,7 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
1348 int nr = to_sensor_dev_attr_2(devattr)->index; 1332 int nr = to_sensor_dev_attr_2(devattr)->index;
1349 int point = to_sensor_dev_attr_2(devattr)->nr; 1333 int point = to_sensor_dev_attr_2(devattr)->nr;
1350 long val = simple_strtol(buf, NULL, 10) / 1000; 1334 long val = simple_strtol(buf, NULL, 10) / 1000;
1335 u8 reg;
1351 1336
1352 mutex_lock(&data->update_lock); 1337 mutex_lock(&data->update_lock);
1353 data->pwm_auto_point_temp[nr][point] = 1338 data->pwm_auto_point_temp[nr][point] =
@@ -1356,34 +1341,14 @@ static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
1356 data->pwm_auto_point_temp[nr][point]); 1341 data->pwm_auto_point_temp[nr][point]);
1357 val = data->pwm_auto_point_temp[nr][point] - val; 1342 val = data->pwm_auto_point_temp[nr][point] - val;
1358 1343
1359 if (nr == 0 || nr == 1) { 1344 reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
1360 data->pwm_auto_point_hyst[0] = 1345 if (nr & 1)
1361 f71882fg_read8(data, F71882FG_REG_FAN_HYST0); 1346 reg = (reg & 0x0f) | (val << 4);
1362 } else { 1347 else
1363 data->pwm_auto_point_hyst[1] = 1348 reg = (reg & 0xf0) | val;
1364 f71882fg_read8(data, F71882FG_REG_FAN_HYST1); 1349
1365 } 1350 f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
1366 switch (nr) { 1351 data->pwm_auto_point_hyst[nr / 2] = reg;
1367 case 0:
1368 val = (data->pwm_auto_point_hyst[0] & 0xf0) | val;
1369 break;
1370 case 1:
1371 val = (data->pwm_auto_point_hyst[0] & 0x0f) | (val << 4);
1372 break;
1373 case 2:
1374 val = (data->pwm_auto_point_hyst[1] & 0xf0) | val;
1375 break;
1376 case 3:
1377 val = (data->pwm_auto_point_hyst[1] & 0x0f) | (val << 4);
1378 break;
1379 }
1380 if (nr == 0 || nr == 1) {
1381 f71882fg_write8(data, F71882FG_REG_FAN_HYST0, val);
1382 data->pwm_auto_point_hyst[0] = val;
1383 } else {
1384 f71882fg_write8(data, F71882FG_REG_FAN_HYST1, val);
1385 data->pwm_auto_point_hyst[1] = val;
1386 }
1387 mutex_unlock(&data->update_lock); 1352 mutex_unlock(&data->update_lock);
1388 1353
1389 return count; 1354 return count;