aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-07-23 00:27:39 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-08-04 10:01:40 -0400
commit6fd5dd58371fb3cad5aedf64e30bef3ca54b3d6c (patch)
tree8d3ce634c92680fa9c9318005ff5ce3bb8ab3302 /drivers/hwmon
parent8eb406100c9da01ebe983702aae6d479c882d5cb (diff)
hwmon: (lm85) Avoid forward declaration
Reorder functions to avoid forward declaration. Signed-off-by: Axel Lin <axel.lin@ingics.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/lm85.c513
1 files changed, 250 insertions, 263 deletions
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c
index ef627ea71cc8..9fdf1c021007 100644
--- a/drivers/hwmon/lm85.c
+++ b/drivers/hwmon/lm85.c
@@ -121,7 +121,6 @@ enum chips {
121#define EMC6D102_REG_EXTEND_ADC3 0x87 121#define EMC6D102_REG_EXTEND_ADC3 0x87
122#define EMC6D102_REG_EXTEND_ADC4 0x88 122#define EMC6D102_REG_EXTEND_ADC4 0x88
123 123
124
125/* 124/*
126 * Conversions. Rounding and limit checking is only done on the TO_REG 125 * Conversions. Rounding and limit checking is only done on the TO_REG
127 * variants. Note that you should be a bit careful with which arguments 126 * variants. Note that you should be a bit careful with which arguments
@@ -334,44 +333,235 @@ struct lm85_data {
334 struct lm85_zone zone[3]; 333 struct lm85_zone zone[3];
335}; 334};
336 335
337static int lm85_detect(struct i2c_client *client, struct i2c_board_info *info); 336static int lm85_read_value(struct i2c_client *client, u8 reg)
338static int lm85_probe(struct i2c_client *client, 337{
339 const struct i2c_device_id *id); 338 int res;
340static int lm85_remove(struct i2c_client *client);
341 339
342static int lm85_read_value(struct i2c_client *client, u8 reg); 340 /* What size location is it? */
343static void lm85_write_value(struct i2c_client *client, u8 reg, int value); 341 switch (reg) {
344static struct lm85_data *lm85_update_device(struct device *dev); 342 case LM85_REG_FAN(0): /* Read WORD data */
343 case LM85_REG_FAN(1):
344 case LM85_REG_FAN(2):
345 case LM85_REG_FAN(3):
346 case LM85_REG_FAN_MIN(0):
347 case LM85_REG_FAN_MIN(1):
348 case LM85_REG_FAN_MIN(2):
349 case LM85_REG_FAN_MIN(3):
350 case LM85_REG_ALARM1: /* Read both bytes at once */
351 res = i2c_smbus_read_byte_data(client, reg) & 0xff;
352 res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
353 break;
354 default: /* Read BYTE data */
355 res = i2c_smbus_read_byte_data(client, reg);
356 break;
357 }
345 358
359 return res;
360}
346 361
347static const struct i2c_device_id lm85_id[] = { 362static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
348 { "adm1027", adm1027 }, 363{
349 { "adt7463", adt7463 }, 364 switch (reg) {
350 { "adt7468", adt7468 }, 365 case LM85_REG_FAN(0): /* Write WORD data */
351 { "lm85", lm85 }, 366 case LM85_REG_FAN(1):
352 { "lm85b", lm85 }, 367 case LM85_REG_FAN(2):
353 { "lm85c", lm85 }, 368 case LM85_REG_FAN(3):
354 { "emc6d100", emc6d100 }, 369 case LM85_REG_FAN_MIN(0):
355 { "emc6d101", emc6d100 }, 370 case LM85_REG_FAN_MIN(1):
356 { "emc6d102", emc6d102 }, 371 case LM85_REG_FAN_MIN(2):
357 { "emc6d103", emc6d103 }, 372 case LM85_REG_FAN_MIN(3):
358 { "emc6d103s", emc6d103s }, 373 /* NOTE: ALARM is read only, so not included here */
359 { } 374 i2c_smbus_write_byte_data(client, reg, value & 0xff);
360}; 375 i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
361MODULE_DEVICE_TABLE(i2c, lm85_id); 376 break;
377 default: /* Write BYTE data */
378 i2c_smbus_write_byte_data(client, reg, value);
379 break;
380 }
381}
362 382
363static struct i2c_driver lm85_driver = { 383static struct lm85_data *lm85_update_device(struct device *dev)
364 .class = I2C_CLASS_HWMON, 384{
365 .driver = { 385 struct i2c_client *client = to_i2c_client(dev);
366 .name = "lm85", 386 struct lm85_data *data = i2c_get_clientdata(client);
367 }, 387 int i;
368 .probe = lm85_probe, 388
369 .remove = lm85_remove, 389 mutex_lock(&data->update_lock);
370 .id_table = lm85_id, 390
371 .detect = lm85_detect, 391 if (!data->valid ||
372 .address_list = normal_i2c, 392 time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) {
373}; 393 /* Things that change quickly */
394 dev_dbg(&client->dev, "Reading sensor values\n");
395
396 /*
397 * Have to read extended bits first to "freeze" the
398 * more significant bits that are read later.
399 * There are 2 additional resolution bits per channel and we
400 * have room for 4, so we shift them to the left.
401 */
402 if (data->type == adm1027 || data->type == adt7463 ||
403 data->type == adt7468) {
404 int ext1 = lm85_read_value(client,
405 ADM1027_REG_EXTEND_ADC1);
406 int ext2 = lm85_read_value(client,
407 ADM1027_REG_EXTEND_ADC2);
408 int val = (ext1 << 8) + ext2;
409
410 for (i = 0; i <= 4; i++)
411 data->in_ext[i] =
412 ((val >> (i * 2)) & 0x03) << 2;
413
414 for (i = 0; i <= 2; i++)
415 data->temp_ext[i] =
416 (val >> ((i + 4) * 2)) & 0x0c;
417 }
418
419 data->vid = lm85_read_value(client, LM85_REG_VID);
420
421 for (i = 0; i <= 3; ++i) {
422 data->in[i] =
423 lm85_read_value(client, LM85_REG_IN(i));
424 data->fan[i] =
425 lm85_read_value(client, LM85_REG_FAN(i));
426 }
427
428 if (!data->has_vid5)
429 data->in[4] = lm85_read_value(client, LM85_REG_IN(4));
430
431 if (data->type == adt7468)
432 data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5);
433
434 for (i = 0; i <= 2; ++i) {
435 data->temp[i] =
436 lm85_read_value(client, LM85_REG_TEMP(i));
437 data->pwm[i] =
438 lm85_read_value(client, LM85_REG_PWM(i));
374 439
440 if (IS_ADT7468_OFF64(data))
441 data->temp[i] -= 64;
442 }
443
444 data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
445
446 if (data->type == emc6d100) {
447 /* Three more voltage sensors */
448 for (i = 5; i <= 7; ++i) {
449 data->in[i] = lm85_read_value(client,
450 EMC6D100_REG_IN(i));
451 }
452 /* More alarm bits */
453 data->alarms |= lm85_read_value(client,
454 EMC6D100_REG_ALARM3) << 16;
455 } else if (data->type == emc6d102 || data->type == emc6d103 ||
456 data->type == emc6d103s) {
457 /*
458 * Have to read LSB bits after the MSB ones because
459 * the reading of the MSB bits has frozen the
460 * LSBs (backward from the ADM1027).
461 */
462 int ext1 = lm85_read_value(client,
463 EMC6D102_REG_EXTEND_ADC1);
464 int ext2 = lm85_read_value(client,
465 EMC6D102_REG_EXTEND_ADC2);
466 int ext3 = lm85_read_value(client,
467 EMC6D102_REG_EXTEND_ADC3);
468 int ext4 = lm85_read_value(client,
469 EMC6D102_REG_EXTEND_ADC4);
470 data->in_ext[0] = ext3 & 0x0f;
471 data->in_ext[1] = ext4 & 0x0f;
472 data->in_ext[2] = ext4 >> 4;
473 data->in_ext[3] = ext3 >> 4;
474 data->in_ext[4] = ext2 >> 4;
475
476 data->temp_ext[0] = ext1 & 0x0f;
477 data->temp_ext[1] = ext2 & 0x0f;
478 data->temp_ext[2] = ext1 >> 4;
479 }
480
481 data->last_reading = jiffies;
482 } /* last_reading */
483
484 if (!data->valid ||
485 time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) {
486 /* Things that don't change often */
487 dev_dbg(&client->dev, "Reading config values\n");
488
489 for (i = 0; i <= 3; ++i) {
490 data->in_min[i] =
491 lm85_read_value(client, LM85_REG_IN_MIN(i));
492 data->in_max[i] =
493 lm85_read_value(client, LM85_REG_IN_MAX(i));
494 data->fan_min[i] =
495 lm85_read_value(client, LM85_REG_FAN_MIN(i));
496 }
497
498 if (!data->has_vid5) {
499 data->in_min[4] = lm85_read_value(client,
500 LM85_REG_IN_MIN(4));
501 data->in_max[4] = lm85_read_value(client,
502 LM85_REG_IN_MAX(4));
503 }
504
505 if (data->type == emc6d100) {
506 for (i = 5; i <= 7; ++i) {
507 data->in_min[i] = lm85_read_value(client,
508 EMC6D100_REG_IN_MIN(i));
509 data->in_max[i] = lm85_read_value(client,
510 EMC6D100_REG_IN_MAX(i));
511 }
512 }
513
514 for (i = 0; i <= 2; ++i) {
515 int val;
516
517 data->temp_min[i] =
518 lm85_read_value(client, LM85_REG_TEMP_MIN(i));
519 data->temp_max[i] =
520 lm85_read_value(client, LM85_REG_TEMP_MAX(i));
521
522 data->autofan[i].config =
523 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
524 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
525 data->pwm_freq[i] = val & 0x07;
526 data->zone[i].range = val >> 4;
527 data->autofan[i].min_pwm =
528 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
529 data->zone[i].limit =
530 lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
531 data->zone[i].critical =
532 lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
533
534 if (IS_ADT7468_OFF64(data)) {
535 data->temp_min[i] -= 64;
536 data->temp_max[i] -= 64;
537 data->zone[i].limit -= 64;
538 data->zone[i].critical -= 64;
539 }
540 }
541
542 if (data->type != emc6d103s) {
543 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
544 data->autofan[0].min_off = (i & 0x20) != 0;
545 data->autofan[1].min_off = (i & 0x40) != 0;
546 data->autofan[2].min_off = (i & 0x80) != 0;
547
548 i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
549 data->zone[0].hyst = i >> 4;
550 data->zone[1].hyst = i & 0x0f;
551
552 i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
553 data->zone[2].hyst = i >> 4;
554 }
555
556 data->last_config = jiffies;
557 } /* last_config */
558
559 data->valid = 1;
560
561 mutex_unlock(&data->update_lock);
562
563 return data;
564}
375 565
376/* 4 Fans */ 566/* 4 Fans */
377static ssize_t show_fan(struct device *dev, struct device_attribute *attr, 567static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
@@ -1467,236 +1657,33 @@ static int lm85_remove(struct i2c_client *client)
1467 return 0; 1657 return 0;
1468} 1658}
1469 1659
1660static const struct i2c_device_id lm85_id[] = {
1661 { "adm1027", adm1027 },
1662 { "adt7463", adt7463 },
1663 { "adt7468", adt7468 },
1664 { "lm85", lm85 },
1665 { "lm85b", lm85 },
1666 { "lm85c", lm85 },
1667 { "emc6d100", emc6d100 },
1668 { "emc6d101", emc6d100 },
1669 { "emc6d102", emc6d102 },
1670 { "emc6d103", emc6d103 },
1671 { "emc6d103s", emc6d103s },
1672 { }
1673};
1674MODULE_DEVICE_TABLE(i2c, lm85_id);
1470 1675
1471static int lm85_read_value(struct i2c_client *client, u8 reg) 1676static struct i2c_driver lm85_driver = {
1472{ 1677 .class = I2C_CLASS_HWMON,
1473 int res; 1678 .driver = {
1474 1679 .name = "lm85",
1475 /* What size location is it? */ 1680 },
1476 switch (reg) { 1681 .probe = lm85_probe,
1477 case LM85_REG_FAN(0): /* Read WORD data */ 1682 .remove = lm85_remove,
1478 case LM85_REG_FAN(1): 1683 .id_table = lm85_id,
1479 case LM85_REG_FAN(2): 1684 .detect = lm85_detect,
1480 case LM85_REG_FAN(3): 1685 .address_list = normal_i2c,
1481 case LM85_REG_FAN_MIN(0): 1686};
1482 case LM85_REG_FAN_MIN(1):
1483 case LM85_REG_FAN_MIN(2):
1484 case LM85_REG_FAN_MIN(3):
1485 case LM85_REG_ALARM1: /* Read both bytes at once */
1486 res = i2c_smbus_read_byte_data(client, reg) & 0xff;
1487 res |= i2c_smbus_read_byte_data(client, reg + 1) << 8;
1488 break;
1489 default: /* Read BYTE data */
1490 res = i2c_smbus_read_byte_data(client, reg);
1491 break;
1492 }
1493
1494 return res;
1495}
1496
1497static void lm85_write_value(struct i2c_client *client, u8 reg, int value)
1498{
1499 switch (reg) {
1500 case LM85_REG_FAN(0): /* Write WORD data */
1501 case LM85_REG_FAN(1):
1502 case LM85_REG_FAN(2):
1503 case LM85_REG_FAN(3):
1504 case LM85_REG_FAN_MIN(0):
1505 case LM85_REG_FAN_MIN(1):
1506 case LM85_REG_FAN_MIN(2):
1507 case LM85_REG_FAN_MIN(3):
1508 /* NOTE: ALARM is read only, so not included here */
1509 i2c_smbus_write_byte_data(client, reg, value & 0xff);
1510 i2c_smbus_write_byte_data(client, reg + 1, value >> 8);
1511 break;
1512 default: /* Write BYTE data */
1513 i2c_smbus_write_byte_data(client, reg, value);
1514 break;
1515 }
1516}
1517
1518static struct lm85_data *lm85_update_device(struct device *dev)
1519{
1520 struct i2c_client *client = to_i2c_client(dev);
1521 struct lm85_data *data = i2c_get_clientdata(client);
1522 int i;
1523
1524 mutex_lock(&data->update_lock);
1525
1526 if (!data->valid ||
1527 time_after(jiffies, data->last_reading + LM85_DATA_INTERVAL)) {
1528 /* Things that change quickly */
1529 dev_dbg(&client->dev, "Reading sensor values\n");
1530
1531 /*
1532 * Have to read extended bits first to "freeze" the
1533 * more significant bits that are read later.
1534 * There are 2 additional resolution bits per channel and we
1535 * have room for 4, so we shift them to the left.
1536 */
1537 if (data->type == adm1027 || data->type == adt7463 ||
1538 data->type == adt7468) {
1539 int ext1 = lm85_read_value(client,
1540 ADM1027_REG_EXTEND_ADC1);
1541 int ext2 = lm85_read_value(client,
1542 ADM1027_REG_EXTEND_ADC2);
1543 int val = (ext1 << 8) + ext2;
1544
1545 for (i = 0; i <= 4; i++)
1546 data->in_ext[i] =
1547 ((val >> (i * 2)) & 0x03) << 2;
1548
1549 for (i = 0; i <= 2; i++)
1550 data->temp_ext[i] =
1551 (val >> ((i + 4) * 2)) & 0x0c;
1552 }
1553
1554 data->vid = lm85_read_value(client, LM85_REG_VID);
1555
1556 for (i = 0; i <= 3; ++i) {
1557 data->in[i] =
1558 lm85_read_value(client, LM85_REG_IN(i));
1559 data->fan[i] =
1560 lm85_read_value(client, LM85_REG_FAN(i));
1561 }
1562
1563 if (!data->has_vid5)
1564 data->in[4] = lm85_read_value(client, LM85_REG_IN(4));
1565
1566 if (data->type == adt7468)
1567 data->cfg5 = lm85_read_value(client, ADT7468_REG_CFG5);
1568
1569 for (i = 0; i <= 2; ++i) {
1570 data->temp[i] =
1571 lm85_read_value(client, LM85_REG_TEMP(i));
1572 data->pwm[i] =
1573 lm85_read_value(client, LM85_REG_PWM(i));
1574
1575 if (IS_ADT7468_OFF64(data))
1576 data->temp[i] -= 64;
1577 }
1578
1579 data->alarms = lm85_read_value(client, LM85_REG_ALARM1);
1580
1581 if (data->type == emc6d100) {
1582 /* Three more voltage sensors */
1583 for (i = 5; i <= 7; ++i) {
1584 data->in[i] = lm85_read_value(client,
1585 EMC6D100_REG_IN(i));
1586 }
1587 /* More alarm bits */
1588 data->alarms |= lm85_read_value(client,
1589 EMC6D100_REG_ALARM3) << 16;
1590 } else if (data->type == emc6d102 || data->type == emc6d103 ||
1591 data->type == emc6d103s) {
1592 /*
1593 * Have to read LSB bits after the MSB ones because
1594 * the reading of the MSB bits has frozen the
1595 * LSBs (backward from the ADM1027).
1596 */
1597 int ext1 = lm85_read_value(client,
1598 EMC6D102_REG_EXTEND_ADC1);
1599 int ext2 = lm85_read_value(client,
1600 EMC6D102_REG_EXTEND_ADC2);
1601 int ext3 = lm85_read_value(client,
1602 EMC6D102_REG_EXTEND_ADC3);
1603 int ext4 = lm85_read_value(client,
1604 EMC6D102_REG_EXTEND_ADC4);
1605 data->in_ext[0] = ext3 & 0x0f;
1606 data->in_ext[1] = ext4 & 0x0f;
1607 data->in_ext[2] = ext4 >> 4;
1608 data->in_ext[3] = ext3 >> 4;
1609 data->in_ext[4] = ext2 >> 4;
1610
1611 data->temp_ext[0] = ext1 & 0x0f;
1612 data->temp_ext[1] = ext2 & 0x0f;
1613 data->temp_ext[2] = ext1 >> 4;
1614 }
1615
1616 data->last_reading = jiffies;
1617 } /* last_reading */
1618
1619 if (!data->valid ||
1620 time_after(jiffies, data->last_config + LM85_CONFIG_INTERVAL)) {
1621 /* Things that don't change often */
1622 dev_dbg(&client->dev, "Reading config values\n");
1623
1624 for (i = 0; i <= 3; ++i) {
1625 data->in_min[i] =
1626 lm85_read_value(client, LM85_REG_IN_MIN(i));
1627 data->in_max[i] =
1628 lm85_read_value(client, LM85_REG_IN_MAX(i));
1629 data->fan_min[i] =
1630 lm85_read_value(client, LM85_REG_FAN_MIN(i));
1631 }
1632
1633 if (!data->has_vid5) {
1634 data->in_min[4] = lm85_read_value(client,
1635 LM85_REG_IN_MIN(4));
1636 data->in_max[4] = lm85_read_value(client,
1637 LM85_REG_IN_MAX(4));
1638 }
1639
1640 if (data->type == emc6d100) {
1641 for (i = 5; i <= 7; ++i) {
1642 data->in_min[i] = lm85_read_value(client,
1643 EMC6D100_REG_IN_MIN(i));
1644 data->in_max[i] = lm85_read_value(client,
1645 EMC6D100_REG_IN_MAX(i));
1646 }
1647 }
1648
1649 for (i = 0; i <= 2; ++i) {
1650 int val;
1651
1652 data->temp_min[i] =
1653 lm85_read_value(client, LM85_REG_TEMP_MIN(i));
1654 data->temp_max[i] =
1655 lm85_read_value(client, LM85_REG_TEMP_MAX(i));
1656
1657 data->autofan[i].config =
1658 lm85_read_value(client, LM85_REG_AFAN_CONFIG(i));
1659 val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i));
1660 data->pwm_freq[i] = val & 0x07;
1661 data->zone[i].range = val >> 4;
1662 data->autofan[i].min_pwm =
1663 lm85_read_value(client, LM85_REG_AFAN_MINPWM(i));
1664 data->zone[i].limit =
1665 lm85_read_value(client, LM85_REG_AFAN_LIMIT(i));
1666 data->zone[i].critical =
1667 lm85_read_value(client, LM85_REG_AFAN_CRITICAL(i));
1668
1669 if (IS_ADT7468_OFF64(data)) {
1670 data->temp_min[i] -= 64;
1671 data->temp_max[i] -= 64;
1672 data->zone[i].limit -= 64;
1673 data->zone[i].critical -= 64;
1674 }
1675 }
1676
1677 if (data->type != emc6d103s) {
1678 i = lm85_read_value(client, LM85_REG_AFAN_SPIKE1);
1679 data->autofan[0].min_off = (i & 0x20) != 0;
1680 data->autofan[1].min_off = (i & 0x40) != 0;
1681 data->autofan[2].min_off = (i & 0x80) != 0;
1682
1683 i = lm85_read_value(client, LM85_REG_AFAN_HYST1);
1684 data->zone[0].hyst = i >> 4;
1685 data->zone[1].hyst = i & 0x0f;
1686
1687 i = lm85_read_value(client, LM85_REG_AFAN_HYST2);
1688 data->zone[2].hyst = i >> 4;
1689 }
1690
1691 data->last_config = jiffies;
1692 } /* last_config */
1693
1694 data->valid = 1;
1695
1696 mutex_unlock(&data->update_lock);
1697
1698 return data;
1699}
1700 1687
1701module_i2c_driver(lm85_driver); 1688module_i2c_driver(lm85_driver);
1702 1689