[PATCH] hwmon: w83792d fix unused fan pins

1. This patch add check for fan4,5,6,7 and do not create device file
if their pins are not configured as fan.
2. Fix the issue that can not set fan divisor to 128.
3. Fix the index out of bounds bug in w83792d_detect function.

Signed-off-by: Yuan Mu <ymu@winbond.com.tw>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

authored by Jean Delvare and committed by Greg Kroah-Hartman 96320519 d2ef5ebb

+18 -7
+18 -7
drivers/hwmon/w83792d.c
··· 193 193 0xE2 } /* (bit3-0) SmartFanII: Fan3 Level 3 */ 194 194 }; 195 195 196 + #define W83792D_REG_GPIO_EN 0x1A 196 197 #define W83792D_REG_CONFIG 0x40 197 198 #define W83792D_REG_VID_FANDIV 0x47 198 199 #define W83792D_REG_CHIPID 0x49 ··· 258 257 { 259 258 int i; 260 259 val = SENSORS_LIMIT(val, 1, 128) >> 1; 261 - for (i = 0; i < 6; i++) { 260 + for (i = 0; i < 7; i++) { 262 261 if (val == 0) 263 262 break; 264 263 val >>= 1; ··· 1283 1282 w83792d_init_client(new_client); 1284 1283 1285 1284 /* A few vars need to be filled upon startup */ 1286 - for (i = 1; i <= 7; i++) { 1287 - data->fan_min[i - 1] = w83792d_read_value(new_client, 1285 + for (i = 0; i < 7; i++) { 1286 + data->fan_min[i] = w83792d_read_value(new_client, 1288 1287 W83792D_REG_FAN_MIN[i]); 1289 1288 } 1290 1289 ··· 1307 1306 device_create_file_fan(new_client, 1); 1308 1307 device_create_file_fan(new_client, 2); 1309 1308 device_create_file_fan(new_client, 3); 1310 - device_create_file_fan(new_client, 4); 1311 - device_create_file_fan(new_client, 5); 1312 - device_create_file_fan(new_client, 6); 1313 - device_create_file_fan(new_client, 7); 1309 + 1310 + /* Read GPIO enable register to check if pins for fan 4,5 are used as 1311 + GPIO */ 1312 + val1 = w83792d_read_value(new_client, W83792D_REG_GPIO_EN); 1313 + if (!(val1 & 0x40)) 1314 + device_create_file_fan(new_client, 4); 1315 + if (!(val1 & 0x20)) 1316 + device_create_file_fan(new_client, 5); 1317 + 1318 + val1 = w83792d_read_value(new_client, W83792D_REG_PIN); 1319 + if (val1 & 0x40) 1320 + device_create_file_fan(new_client, 6); 1321 + if (val1 & 0x04) 1322 + device_create_file_fan(new_client, 7); 1314 1323 1315 1324 device_create_file_temp1(new_client); /* Temp1 */ 1316 1325 device_create_file_temp_add(new_client, 2); /* Temp2 */