Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] hwmon: w83792d simplify in low bits handling

Simplify the way the w83792d driver handles the extra resolution
bits of voltage input channels.

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

authored by

Jean Delvare and committed by
Greg Kroah-Hartman
99d85560 c9152dea

+10 -38
+10 -38
drivers/hwmon/w83792d.c
··· 281 281 u8 in[9]; /* Register value */ 282 282 u8 in_max[9]; /* Register value */ 283 283 u8 in_min[9]; /* Register value */ 284 - u8 low_bits[2]; /* Additional resolution to voltage in0-6 */ 284 + u16 low_bits; /* Additional resolution to voltage in6-0 */ 285 285 u8 fan[7]; /* Register value */ 286 286 u8 fan_min[7]; /* Register value */ 287 287 u8 temp1[3]; /* current, over, thyst */ ··· 323 323 .detach_client = w83792d_detach_client, 324 324 }; 325 325 326 - static long in_count_from_reg(int nr, struct w83792d_data *data) 326 + static inline long in_count_from_reg(int nr, struct w83792d_data *data) 327 327 { 328 - u16 vol_count = data->in[nr]; 329 - u16 low_bits = 0; 330 - vol_count = (vol_count << 2); 331 - switch (nr) 332 - { 333 - case 0: /* vin0 */ 334 - low_bits = (data->low_bits[0]) & 0x03; 335 - break; 336 - case 1: /* vin1 */ 337 - low_bits = ((data->low_bits[0]) & 0x0c) >> 2; 338 - break; 339 - case 2: /* vin2 */ 340 - low_bits = ((data->low_bits[0]) & 0x30) >> 4; 341 - break; 342 - case 3: /* vin3 */ 343 - low_bits = ((data->low_bits[0]) & 0xc0) >> 6; 344 - break; 345 - case 4: /* vin4 */ 346 - low_bits = (data->low_bits[1]) & 0x03; 347 - break; 348 - case 5: /* vin5 */ 349 - low_bits = ((data->low_bits[1]) & 0x0c) >> 2; 350 - break; 351 - case 6: /* vin6 */ 352 - low_bits = ((data->low_bits[1]) & 0x30) >> 4; 353 - default: 354 - break; 355 - } 356 - vol_count = vol_count | low_bits; 357 - return vol_count; 328 + /* in7 and in8 do not have low bits, but the formula still works */ 329 + return ((data->in[nr] << 2) | ((data->low_bits >> (2 * nr)) & 0x03)); 358 330 } 359 331 360 332 /* following are the sysfs callback functions */ ··· 1453 1481 data->in_min[i] = w83792d_read_value(client, 1454 1482 W83792D_REG_IN_MIN[i]); 1455 1483 } 1456 - data->low_bits[0] = w83792d_read_value(client, 1457 - W83792D_REG_LOW_BITS1); 1458 - data->low_bits[1] = w83792d_read_value(client, 1459 - W83792D_REG_LOW_BITS2); 1484 + data->low_bits = w83792d_read_value(client, 1485 + W83792D_REG_LOW_BITS1) + 1486 + (w83792d_read_value(client, 1487 + W83792D_REG_LOW_BITS2) << 8); 1460 1488 for (i = 0; i < 7; i++) { 1461 1489 /* Update the Fan measured value and limits */ 1462 1490 data->fan[i] = w83792d_read_value(client, ··· 1568 1596 dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]); 1569 1597 dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]); 1570 1598 } 1571 - dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits[0]); 1572 - dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits[1]); 1599 + dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits & 0xff); 1600 + dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits >> 8); 1573 1601 dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n"); 1574 1602 for (i=0; i<7; i++) { 1575 1603 dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]);