Skip to content

Commit 9632051

Browse files
Jean Delvaregregkh
authored andcommitted
[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 <[email protected]> Signed-off-by: Jean Delvare <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d2ef5eb commit 9632051

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

drivers/hwmon/w83792d.c

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ static const u8 W83792D_REG_LEVELS[3][4] = {
193193
0xE2 } /* (bit3-0) SmartFanII: Fan3 Level 3 */
194194
};
195195

196+
#define W83792D_REG_GPIO_EN 0x1A
196197
#define W83792D_REG_CONFIG 0x40
197198
#define W83792D_REG_VID_FANDIV 0x47
198199
#define W83792D_REG_CHIPID 0x49
@@ -257,7 +258,7 @@ DIV_TO_REG(long val)
257258
{
258259
int i;
259260
val = SENSORS_LIMIT(val, 1, 128) >> 1;
260-
for (i = 0; i < 6; i++) {
261+
for (i = 0; i < 7; i++) {
261262
if (val == 0)
262263
break;
263264
val >>= 1;
@@ -1282,8 +1283,8 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
12821283
w83792d_init_client(new_client);
12831284

12841285
/* A few vars need to be filled upon startup */
1285-
for (i = 1; i <= 7; i++) {
1286-
data->fan_min[i - 1] = w83792d_read_value(new_client,
1286+
for (i = 0; i < 7; i++) {
1287+
data->fan_min[i] = w83792d_read_value(new_client,
12871288
W83792D_REG_FAN_MIN[i]);
12881289
}
12891290

@@ -1306,10 +1307,20 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
13061307
device_create_file_fan(new_client, 1);
13071308
device_create_file_fan(new_client, 2);
13081309
device_create_file_fan(new_client, 3);
1309-
device_create_file_fan(new_client, 4);
1310-
device_create_file_fan(new_client, 5);
1311-
device_create_file_fan(new_client, 6);
1312-
device_create_file_fan(new_client, 7);
1310+
1311+
/* Read GPIO enable register to check if pins for fan 4,5 are used as
1312+
GPIO */
1313+
val1 = w83792d_read_value(new_client, W83792D_REG_GPIO_EN);
1314+
if (!(val1 & 0x40))
1315+
device_create_file_fan(new_client, 4);
1316+
if (!(val1 & 0x20))
1317+
device_create_file_fan(new_client, 5);
1318+
1319+
val1 = w83792d_read_value(new_client, W83792D_REG_PIN);
1320+
if (val1 & 0x40)
1321+
device_create_file_fan(new_client, 6);
1322+
if (val1 & 0x04)
1323+
device_create_file_fan(new_client, 7);
13131324

13141325
device_create_file_temp1(new_client); /* Temp1 */
13151326
device_create_file_temp_add(new_client, 2); /* Temp2 */

0 commit comments

Comments
 (0)