[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 0xE2 } /* (bit3-0) SmartFanII: Fan3 Level 3 */ 194 }; 195 196 #define W83792D_REG_CONFIG 0x40 197 #define W83792D_REG_VID_FANDIV 0x47 198 #define W83792D_REG_CHIPID 0x49 ··· 258 { 259 int i; 260 val = SENSORS_LIMIT(val, 1, 128) >> 1; 261 - for (i = 0; i < 6; i++) { 262 if (val == 0) 263 break; 264 val >>= 1; ··· 1283 w83792d_init_client(new_client); 1284 1285 /* 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, 1288 W83792D_REG_FAN_MIN[i]); 1289 } 1290 ··· 1307 device_create_file_fan(new_client, 1); 1308 device_create_file_fan(new_client, 2); 1309 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); 1314 1315 device_create_file_temp1(new_client); /* Temp1 */ 1316 device_create_file_temp_add(new_client, 2); /* Temp2 */
··· 193 0xE2 } /* (bit3-0) SmartFanII: Fan3 Level 3 */ 194 }; 195 196 + #define W83792D_REG_GPIO_EN 0x1A 197 #define W83792D_REG_CONFIG 0x40 198 #define W83792D_REG_VID_FANDIV 0x47 199 #define W83792D_REG_CHIPID 0x49 ··· 257 { 258 int i; 259 val = SENSORS_LIMIT(val, 1, 128) >> 1; 260 + for (i = 0; i < 7; i++) { 261 if (val == 0) 262 break; 263 val >>= 1; ··· 1282 w83792d_init_client(new_client); 1283 1284 /* A few vars need to be filled upon startup */ 1285 + for (i = 0; i < 7; i++) { 1286 + data->fan_min[i] = w83792d_read_value(new_client, 1287 W83792D_REG_FAN_MIN[i]); 1288 } 1289 ··· 1306 device_create_file_fan(new_client, 1); 1307 device_create_file_fan(new_client, 2); 1308 device_create_file_fan(new_client, 3); 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); 1323 1324 device_create_file_temp1(new_client); /* Temp1 */ 1325 device_create_file_temp_add(new_client, 2); /* Temp2 */