aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83792d.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/w83792d.c')
-rw-r--r--drivers/hwmon/w83792d.c83
1 files changed, 22 insertions, 61 deletions
diff --git a/drivers/hwmon/w83792d.c b/drivers/hwmon/w83792d.c
index 1ba072630361..b176bf0c4c7b 100644
--- a/drivers/hwmon/w83792d.c
+++ b/drivers/hwmon/w83792d.c
@@ -269,7 +269,6 @@ DIV_TO_REG(long val)
269struct w83792d_data { 269struct w83792d_data {
270 struct i2c_client client; 270 struct i2c_client client;
271 struct class_device *class_dev; 271 struct class_device *class_dev;
272 struct semaphore lock;
273 enum chips type; 272 enum chips type;
274 273
275 struct semaphore update_lock; 274 struct semaphore update_lock;
@@ -282,7 +281,7 @@ struct w83792d_data {
282 u8 in[9]; /* Register value */ 281 u8 in[9]; /* Register value */
283 u8 in_max[9]; /* Register value */ 282 u8 in_max[9]; /* Register value */
284 u8 in_min[9]; /* Register value */ 283 u8 in_min[9]; /* Register value */
285 u8 low_bits[2]; /* Additional resolution to voltage in0-6 */ 284 u16 low_bits; /* Additional resolution to voltage in6-0 */
286 u8 fan[7]; /* Register value */ 285 u8 fan[7]; /* Register value */
287 u8 fan_min[7]; /* Register value */ 286 u8 fan_min[7]; /* Register value */
288 u8 temp1[3]; /* current, over, thyst */ 287 u8 temp1[3]; /* current, over, thyst */
@@ -317,45 +316,17 @@ static void w83792d_print_debug(struct w83792d_data *data, struct device *dev);
317static void w83792d_init_client(struct i2c_client *client); 316static void w83792d_init_client(struct i2c_client *client);
318 317
319static struct i2c_driver w83792d_driver = { 318static struct i2c_driver w83792d_driver = {
320 .owner = THIS_MODULE, 319 .driver = {
321 .name = "w83792d", 320 .name = "w83792d",
322 .flags = I2C_DF_NOTIFY, 321 },
323 .attach_adapter = w83792d_attach_adapter, 322 .attach_adapter = w83792d_attach_adapter,
324 .detach_client = w83792d_detach_client, 323 .detach_client = w83792d_detach_client,
325}; 324};
326 325
327static long in_count_from_reg(int nr, struct w83792d_data *data) 326static inline long in_count_from_reg(int nr, struct w83792d_data *data)
328{ 327{
329 u16 vol_count = data->in[nr]; 328 /* in7 and in8 do not have low bits, but the formula still works */
330 u16 low_bits = 0; 329 return ((data->in[nr] << 2) | ((data->low_bits >> (2 * nr)) & 0x03));
331 vol_count = (vol_count << 2);
332 switch (nr)
333 {
334 case 0: /* vin0 */
335 low_bits = (data->low_bits[0]) & 0x03;
336 break;
337 case 1: /* vin1 */
338 low_bits = ((data->low_bits[0]) & 0x0c) >> 2;
339 break;
340 case 2: /* vin2 */
341 low_bits = ((data->low_bits[0]) & 0x30) >> 4;
342 break;
343 case 3: /* vin3 */
344 low_bits = ((data->low_bits[0]) & 0xc0) >> 6;
345 break;
346 case 4: /* vin4 */
347 low_bits = (data->low_bits[1]) & 0x03;
348 break;
349 case 5: /* vin5 */
350 low_bits = ((data->low_bits[1]) & 0x0c) >> 2;
351 break;
352 case 6: /* vin6 */
353 low_bits = ((data->low_bits[1]) & 0x30) >> 4;
354 default:
355 break;
356 }
357 vol_count = vol_count | low_bits;
358 return vol_count;
359} 330}
360 331
361/* following are the sysfs callback functions */ 332/* following are the sysfs callback functions */
@@ -1192,7 +1163,6 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1192 new_client = &data->client; 1163 new_client = &data->client;
1193 i2c_set_clientdata(new_client, data); 1164 i2c_set_clientdata(new_client, data);
1194 new_client->addr = address; 1165 new_client->addr = address;
1195 init_MUTEX(&data->lock);
1196 new_client->adapter = adapter; 1166 new_client->adapter = adapter;
1197 new_client->driver = &w83792d_driver; 1167 new_client->driver = &w83792d_driver;
1198 new_client->flags = 0; 1168 new_client->flags = 0;
@@ -1243,7 +1213,7 @@ w83792d_detect(struct i2c_adapter *adapter, int address, int kind)
1243 goto ERROR1; 1213 goto ERROR1;
1244 } 1214 }
1245 val1 = w83792d_read_value(new_client, W83792D_REG_WCHIPID); 1215 val1 = w83792d_read_value(new_client, W83792D_REG_WCHIPID);
1246 if (val1 == 0x7a && address >= 0x2c) { 1216 if (val1 == 0x7a) {
1247 kind = w83792d; 1217 kind = w83792d;
1248 } else { 1218 } else {
1249 if (kind == 0) 1219 if (kind == 0)
@@ -1416,26 +1386,17 @@ w83792d_detach_client(struct i2c_client *client)
1416 return 0; 1386 return 0;
1417} 1387}
1418 1388
1419/* The SMBus locks itself, usually, but nothing may access the Winbond between 1389/* The SMBus locks itself. The Winbond W83792D chip has a bank register,
1420 bank switches. ISA access must always be locked explicitly! 1390 but the driver only accesses registers in bank 0, so we don't have
1421 We ignore the W83792D BUSY flag at this moment - it could lead to deadlocks, 1391 to switch banks and lock access between switches. */
1422 would slow down the W83792D access and should not be necessary. 1392static int w83792d_read_value(struct i2c_client *client, u8 reg)
1423 There are some ugly typecasts here, but the good news is - they should
1424 nowhere else be necessary! */
1425static int
1426w83792d_read_value(struct i2c_client *client, u8 reg)
1427{ 1393{
1428 int res=0; 1394 return i2c_smbus_read_byte_data(client, reg);
1429 res = i2c_smbus_read_byte_data(client, reg);
1430
1431 return res;
1432} 1395}
1433 1396
1434static int 1397static int w83792d_write_value(struct i2c_client *client, u8 reg, u8 value)
1435w83792d_write_value(struct i2c_client *client, u8 reg, u8 value)
1436{ 1398{
1437 i2c_smbus_write_byte_data(client, reg, value); 1399 return i2c_smbus_write_byte_data(client, reg, value);
1438 return 0;
1439} 1400}
1440 1401
1441static void 1402static void
@@ -1492,10 +1453,10 @@ static struct w83792d_data *w83792d_update_device(struct device *dev)
1492 data->in_min[i] = w83792d_read_value(client, 1453 data->in_min[i] = w83792d_read_value(client,
1493 W83792D_REG_IN_MIN[i]); 1454 W83792D_REG_IN_MIN[i]);
1494 } 1455 }
1495 data->low_bits[0] = w83792d_read_value(client, 1456 data->low_bits = w83792d_read_value(client,
1496 W83792D_REG_LOW_BITS1); 1457 W83792D_REG_LOW_BITS1) +
1497 data->low_bits[1] = w83792d_read_value(client, 1458 (w83792d_read_value(client,
1498 W83792D_REG_LOW_BITS2); 1459 W83792D_REG_LOW_BITS2) << 8);
1499 for (i = 0; i < 7; i++) { 1460 for (i = 0; i < 7; i++) {
1500 /* Update the Fan measured value and limits */ 1461 /* Update the Fan measured value and limits */
1501 data->fan[i] = w83792d_read_value(client, 1462 data->fan[i] = w83792d_read_value(client,
@@ -1506,7 +1467,7 @@ static struct w83792d_data *w83792d_update_device(struct device *dev)
1506 pwm_array_tmp[i] = w83792d_read_value(client, 1467 pwm_array_tmp[i] = w83792d_read_value(client,
1507 W83792D_REG_PWM[i]); 1468 W83792D_REG_PWM[i]);
1508 data->pwm[i] = pwm_array_tmp[i] & 0x0f; 1469 data->pwm[i] = pwm_array_tmp[i] & 0x0f;
1509 data->pwm_mode[i] = (pwm_array_tmp[i] >> 7) & 0x01; 1470 data->pwm_mode[i] = pwm_array_tmp[i] >> 7;
1510 } 1471 }
1511 1472
1512 reg_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG); 1473 reg_tmp = w83792d_read_value(client, W83792D_REG_FAN_CFG);
@@ -1607,8 +1568,8 @@ static void w83792d_print_debug(struct w83792d_data *data, struct device *dev)
1607 dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]); 1568 dev_dbg(dev, "vin[%d] max is: 0x%x\n", i, data->in_max[i]);
1608 dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]); 1569 dev_dbg(dev, "vin[%d] min is: 0x%x\n", i, data->in_min[i]);
1609 } 1570 }
1610 dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits[0]); 1571 dev_dbg(dev, "Low Bit1 is: 0x%x\n", data->low_bits & 0xff);
1611 dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits[1]); 1572 dev_dbg(dev, "Low Bit2 is: 0x%x\n", data->low_bits >> 8);
1612 dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n"); 1573 dev_dbg(dev, "7 set of Fan Counts and Duty Cycles: =====>\n");
1613 for (i=0; i<7; i++) { 1574 for (i=0; i<7; i++) {
1614 dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]); 1575 dev_dbg(dev, "fan[%d] is: 0x%x\n", i, data->fan[i]);