adt7475.c (cf40a76e7d5874bb25f4404eecc58a2e033af885) | adt7475.c (5cf943ede4af95313665ea81f224533d2aa272bb) |
---|---|
1/* 2 * adt7475 - Thermal sensor driver for the ADT7475 chip and derivatives 3 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc. 4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net> 5 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com> 6 * Copyright (C) 2009 Jean Delvare <jdelvare@suse.de> 7 * 8 * Derived from the lm83 driver by Jean Delvare --- 180 unchanged lines hidden (view full) --- 189}; 190MODULE_DEVICE_TABLE(of, adt7475_of_match); 191 192struct adt7475_data { 193 struct device *hwmon_dev; 194 struct mutex lock; 195 196 unsigned long measure_updated; | 1/* 2 * adt7475 - Thermal sensor driver for the ADT7475 chip and derivatives 3 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc. 4 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net> 5 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com> 6 * Copyright (C) 2009 Jean Delvare <jdelvare@suse.de> 7 * 8 * Derived from the lm83 driver by Jean Delvare --- 180 unchanged lines hidden (view full) --- 189}; 190MODULE_DEVICE_TABLE(of, adt7475_of_match); 191 192struct adt7475_data { 193 struct device *hwmon_dev; 194 struct mutex lock; 195 196 unsigned long measure_updated; |
197 unsigned long limits_updated; | |
198 char valid; 199 200 u8 config4; 201 u8 config5; 202 u8 has_voltage; 203 u8 bypass_attn; /* Bypass voltage attenuator */ 204 u8 has_pwm2:1; 205 u8 has_fan4:1; --- 1174 unchanged lines hidden (view full) --- 1380 if (data->has_voltage & (1 << 4)) 1381 sysfs_remove_group(&client->dev.kobj, &in4_attr_group); 1382 if (data->has_voltage & (1 << 5)) 1383 sysfs_remove_group(&client->dev.kobj, &in5_attr_group); 1384 if (data->has_vid) 1385 sysfs_remove_group(&client->dev.kobj, &vid_attr_group); 1386} 1387 | 197 char valid; 198 199 u8 config4; 200 u8 config5; 201 u8 has_voltage; 202 u8 bypass_attn; /* Bypass voltage attenuator */ 203 u8 has_pwm2:1; 204 u8 has_fan4:1; --- 1174 unchanged lines hidden (view full) --- 1379 if (data->has_voltage & (1 << 4)) 1380 sysfs_remove_group(&client->dev.kobj, &in4_attr_group); 1381 if (data->has_voltage & (1 << 5)) 1382 sysfs_remove_group(&client->dev.kobj, &in5_attr_group); 1383 if (data->has_vid) 1384 sysfs_remove_group(&client->dev.kobj, &vid_attr_group); 1385} 1386 |
1387static void adt7475_update_limits(struct i2c_client *client) 1388{ 1389 struct adt7475_data *data = i2c_get_clientdata(client); 1390 int i; 1391 1392 data->config4 = adt7475_read(REG_CONFIG4); 1393 data->config5 = adt7475_read(REG_CONFIG5); 1394 1395 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { 1396 if (!(data->has_voltage & (1 << i))) 1397 continue; 1398 /* Adjust values so they match the input precision */ 1399 data->voltage[MIN][i] = 1400 adt7475_read(VOLTAGE_MIN_REG(i)) << 2; 1401 data->voltage[MAX][i] = 1402 adt7475_read(VOLTAGE_MAX_REG(i)) << 2; 1403 } 1404 1405 if (data->has_voltage & (1 << 5)) { 1406 data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2; 1407 data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2; 1408 } 1409 1410 for (i = 0; i < ADT7475_TEMP_COUNT; i++) { 1411 /* Adjust values so they match the input precision */ 1412 data->temp[MIN][i] = 1413 adt7475_read(TEMP_MIN_REG(i)) << 2; 1414 data->temp[MAX][i] = 1415 adt7475_read(TEMP_MAX_REG(i)) << 2; 1416 data->temp[AUTOMIN][i] = 1417 adt7475_read(TEMP_TMIN_REG(i)) << 2; 1418 data->temp[THERM][i] = 1419 adt7475_read(TEMP_THERM_REG(i)) << 2; 1420 data->temp[OFFSET][i] = 1421 adt7475_read(TEMP_OFFSET_REG(i)); 1422 } 1423 adt7475_read_hystersis(client); 1424 1425 for (i = 0; i < ADT7475_TACH_COUNT; i++) { 1426 if (i == 3 && !data->has_fan4) 1427 continue; 1428 data->tach[MIN][i] = 1429 adt7475_read_word(client, TACH_MIN_REG(i)); 1430 } 1431 1432 for (i = 0; i < ADT7475_PWM_COUNT; i++) { 1433 if (i == 1 && !data->has_pwm2) 1434 continue; 1435 data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i)); 1436 data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i)); 1437 /* Set the channel and control information */ 1438 adt7475_read_pwm(client, i); 1439 } 1440 1441 data->range[0] = adt7475_read(TEMP_TRANGE_REG(0)); 1442 data->range[1] = adt7475_read(TEMP_TRANGE_REG(1)); 1443 data->range[2] = adt7475_read(TEMP_TRANGE_REG(2)); 1444} 1445 |
|
1388static int adt7475_probe(struct i2c_client *client, 1389 const struct i2c_device_id *id) 1390{ 1391 enum chips chip; 1392 static const char * const names[] = { 1393 [adt7473] = "ADT7473", 1394 [adt7475] = "ADT7475", 1395 [adt7476] = "ADT7476", --- 161 unchanged lines hidden (view full) --- 1557 data->has_vid ? " vid" : ""); 1558 if (data->bypass_attn) 1559 dev_info(&client->dev, "Bypassing attenuators on:%s%s%s%s\n", 1560 (data->bypass_attn & (1 << 0)) ? " in0" : "", 1561 (data->bypass_attn & (1 << 1)) ? " in1" : "", 1562 (data->bypass_attn & (1 << 3)) ? " in3" : "", 1563 (data->bypass_attn & (1 << 4)) ? " in4" : ""); 1564 | 1446static int adt7475_probe(struct i2c_client *client, 1447 const struct i2c_device_id *id) 1448{ 1449 enum chips chip; 1450 static const char * const names[] = { 1451 [adt7473] = "ADT7473", 1452 [adt7475] = "ADT7475", 1453 [adt7476] = "ADT7476", --- 161 unchanged lines hidden (view full) --- 1615 data->has_vid ? " vid" : ""); 1616 if (data->bypass_attn) 1617 dev_info(&client->dev, "Bypassing attenuators on:%s%s%s%s\n", 1618 (data->bypass_attn & (1 << 0)) ? " in0" : "", 1619 (data->bypass_attn & (1 << 1)) ? " in1" : "", 1620 (data->bypass_attn & (1 << 3)) ? " in3" : "", 1621 (data->bypass_attn & (1 << 4)) ? " in4" : ""); 1622 |
1623 /* Limits and settings, should never change update more than once */ 1624 adt7475_update_limits(client); 1625 |
|
1565 return 0; 1566 1567eremove: 1568 adt7475_remove_files(client, data); 1569 return ret; 1570} 1571 1572static int adt7475_remove(struct i2c_client *client) --- 80 unchanged lines hidden (view full) --- 1653 break; 1654 case 6: 1655 data->pwmchan[index] = 7; 1656 break; 1657 } 1658 } 1659} 1660 | 1626 return 0; 1627 1628eremove: 1629 adt7475_remove_files(client, data); 1630 return ret; 1631} 1632 1633static int adt7475_remove(struct i2c_client *client) --- 80 unchanged lines hidden (view full) --- 1714 break; 1715 case 6: 1716 data->pwmchan[index] = 7; 1717 break; 1718 } 1719 } 1720} 1721 |
1661static struct adt7475_data *adt7475_update_device(struct device *dev) | 1722static void adt7475_update_measure(struct device *dev) |
1662{ 1663 struct i2c_client *client = to_i2c_client(dev); 1664 struct adt7475_data *data = i2c_get_clientdata(client); 1665 u16 ext; 1666 int i; 1667 | 1723{ 1724 struct i2c_client *client = to_i2c_client(dev); 1725 struct adt7475_data *data = i2c_get_clientdata(client); 1726 u16 ext; 1727 int i; 1728 |
1668 mutex_lock(&data->lock); | 1729 data->alarms = adt7475_read(REG_STATUS2) << 8; 1730 data->alarms |= adt7475_read(REG_STATUS1); |
1669 | 1731 |
1670 /* Measurement values update every 2 seconds */ 1671 if (time_after(jiffies, data->measure_updated + HZ * 2) || 1672 !data->valid) { 1673 data->alarms = adt7475_read(REG_STATUS2) << 8; 1674 data->alarms |= adt7475_read(REG_STATUS1); | 1732 ext = (adt7475_read(REG_EXTEND2) << 8) | 1733 adt7475_read(REG_EXTEND1); 1734 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { 1735 if (!(data->has_voltage & (1 << i))) 1736 continue; 1737 data->voltage[INPUT][i] = 1738 (adt7475_read(VOLTAGE_REG(i)) << 2) | 1739 ((ext >> (i * 2)) & 3); 1740 } |
1675 | 1741 |
1676 ext = (adt7475_read(REG_EXTEND2) << 8) | 1677 adt7475_read(REG_EXTEND1); 1678 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { 1679 if (!(data->has_voltage & (1 << i))) 1680 continue; 1681 data->voltage[INPUT][i] = 1682 (adt7475_read(VOLTAGE_REG(i)) << 2) | 1683 ((ext >> (i * 2)) & 3); 1684 } | 1742 for (i = 0; i < ADT7475_TEMP_COUNT; i++) 1743 data->temp[INPUT][i] = 1744 (adt7475_read(TEMP_REG(i)) << 2) | 1745 ((ext >> ((i + 5) * 2)) & 3); |
1685 | 1746 |
1686 for (i = 0; i < ADT7475_TEMP_COUNT; i++) 1687 data->temp[INPUT][i] = 1688 (adt7475_read(TEMP_REG(i)) << 2) | 1689 ((ext >> ((i + 5) * 2)) & 3); | 1747 if (data->has_voltage & (1 << 5)) { 1748 data->alarms |= adt7475_read(REG_STATUS4) << 24; 1749 ext = adt7475_read(REG_EXTEND3); 1750 data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 | 1751 ((ext >> 4) & 3); 1752 } |
1690 | 1753 |
1691 if (data->has_voltage & (1 << 5)) { 1692 data->alarms |= adt7475_read(REG_STATUS4) << 24; 1693 ext = adt7475_read(REG_EXTEND3); 1694 data->voltage[INPUT][5] = adt7475_read(REG_VTT) << 2 | 1695 ((ext >> 4) & 3); 1696 } | 1754 for (i = 0; i < ADT7475_TACH_COUNT; i++) { 1755 if (i == 3 && !data->has_fan4) 1756 continue; 1757 data->tach[INPUT][i] = 1758 adt7475_read_word(client, TACH_REG(i)); 1759 } |
1697 | 1760 |
1698 for (i = 0; i < ADT7475_TACH_COUNT; i++) { 1699 if (i == 3 && !data->has_fan4) 1700 continue; 1701 data->tach[INPUT][i] = 1702 adt7475_read_word(client, TACH_REG(i)); 1703 } 1704 1705 /* Updated by hw when in auto mode */ 1706 for (i = 0; i < ADT7475_PWM_COUNT; i++) { 1707 if (i == 1 && !data->has_pwm2) 1708 continue; 1709 data->pwm[INPUT][i] = adt7475_read(PWM_REG(i)); 1710 } 1711 1712 if (data->has_vid) 1713 data->vid = adt7475_read(REG_VID) & 0x3f; 1714 1715 data->measure_updated = jiffies; | 1761 /* Updated by hw when in auto mode */ 1762 for (i = 0; i < ADT7475_PWM_COUNT; i++) { 1763 if (i == 1 && !data->has_pwm2) 1764 continue; 1765 data->pwm[INPUT][i] = adt7475_read(PWM_REG(i)); |
1716 } 1717 | 1766 } 1767 |
1718 /* Limits and settings, should never change update every 60 seconds */ 1719 if (time_after(jiffies, data->limits_updated + HZ * 60) || 1720 !data->valid) { 1721 data->config4 = adt7475_read(REG_CONFIG4); 1722 data->config5 = adt7475_read(REG_CONFIG5); | 1768 if (data->has_vid) 1769 data->vid = adt7475_read(REG_VID) & 0x3f; 1770} |
1723 | 1771 |
1724 for (i = 0; i < ADT7475_VOLTAGE_COUNT; i++) { 1725 if (!(data->has_voltage & (1 << i))) 1726 continue; 1727 /* Adjust values so they match the input precision */ 1728 data->voltage[MIN][i] = 1729 adt7475_read(VOLTAGE_MIN_REG(i)) << 2; 1730 data->voltage[MAX][i] = 1731 adt7475_read(VOLTAGE_MAX_REG(i)) << 2; 1732 } | 1772static struct adt7475_data *adt7475_update_device(struct device *dev) 1773{ 1774 struct i2c_client *client = to_i2c_client(dev); 1775 struct adt7475_data *data = i2c_get_clientdata(client); |
1733 | 1776 |
1734 if (data->has_voltage & (1 << 5)) { 1735 data->voltage[MIN][5] = adt7475_read(REG_VTT_MIN) << 2; 1736 data->voltage[MAX][5] = adt7475_read(REG_VTT_MAX) << 2; 1737 } | 1777 mutex_lock(&data->lock); |
1738 | 1778 |
1739 for (i = 0; i < ADT7475_TEMP_COUNT; i++) { 1740 /* Adjust values so they match the input precision */ 1741 data->temp[MIN][i] = 1742 adt7475_read(TEMP_MIN_REG(i)) << 2; 1743 data->temp[MAX][i] = 1744 adt7475_read(TEMP_MAX_REG(i)) << 2; 1745 data->temp[AUTOMIN][i] = 1746 adt7475_read(TEMP_TMIN_REG(i)) << 2; 1747 data->temp[THERM][i] = 1748 adt7475_read(TEMP_THERM_REG(i)) << 2; 1749 data->temp[OFFSET][i] = 1750 adt7475_read(TEMP_OFFSET_REG(i)); 1751 } 1752 adt7475_read_hystersis(client); 1753 1754 for (i = 0; i < ADT7475_TACH_COUNT; i++) { 1755 if (i == 3 && !data->has_fan4) 1756 continue; 1757 data->tach[MIN][i] = 1758 adt7475_read_word(client, TACH_MIN_REG(i)); 1759 } 1760 1761 for (i = 0; i < ADT7475_PWM_COUNT; i++) { 1762 if (i == 1 && !data->has_pwm2) 1763 continue; 1764 data->pwm[MAX][i] = adt7475_read(PWM_MAX_REG(i)); 1765 data->pwm[MIN][i] = adt7475_read(PWM_MIN_REG(i)); 1766 /* Set the channel and control information */ 1767 adt7475_read_pwm(client, i); 1768 } 1769 1770 data->range[0] = adt7475_read(TEMP_TRANGE_REG(0)); 1771 data->range[1] = adt7475_read(TEMP_TRANGE_REG(1)); 1772 data->range[2] = adt7475_read(TEMP_TRANGE_REG(2)); 1773 1774 data->limits_updated = jiffies; 1775 data->valid = 1; | 1779 /* Measurement values update every 2 seconds */ 1780 if (time_after(jiffies, data->measure_updated + HZ * 2) || 1781 !data->valid) { 1782 adt7475_update_measure(dev); 1783 data->measure_updated = jiffies; |
1776 } 1777 1778 mutex_unlock(&data->lock); 1779 1780 return data; 1781} 1782 1783module_i2c_driver(adt7475_driver); 1784 1785MODULE_AUTHOR("Advanced Micro Devices, Inc"); 1786MODULE_DESCRIPTION("adt7475 driver"); 1787MODULE_LICENSE("GPL"); | 1784 } 1785 1786 mutex_unlock(&data->lock); 1787 1788 return data; 1789} 1790 1791module_i2c_driver(adt7475_driver); 1792 1793MODULE_AUTHOR("Advanced Micro Devices, Inc"); 1794MODULE_DESCRIPTION("adt7475 driver"); 1795MODULE_LICENSE("GPL"); |