adt7475.c (0ea5c948cb64bab5bc7a5516774eb8536f05aa0d) adt7475.c (732d2624cf9015988c152cb2758ec807907e7d1a)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * adt7475 - Thermal sensor driver for the ADT7475 chip and derivatives
4 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc.
5 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
6 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com>
7 * Copyright (C) 2009 Jean Delvare <jdelvare@suse.de>
8 *

--- 1662 unchanged lines hidden (view full) ---

1671 [adt7476] = "ADT7476",
1672 [adt7490] = "ADT7490",
1673 };
1674
1675 struct adt7475_data *data;
1676 struct device *hwmon_dev;
1677 int i, ret = 0, revision, group_num = 0;
1678 u8 config3;
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * adt7475 - Thermal sensor driver for the ADT7475 chip and derivatives
4 * Copyright (C) 2007-2008, Advanced Micro Devices, Inc.
5 * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net>
6 * Copyright (C) 2008 Hans de Goede <hdegoede@redhat.com>
7 * Copyright (C) 2009 Jean Delvare <jdelvare@suse.de>
8 *

--- 1662 unchanged lines hidden (view full) ---

1671 [adt7476] = "ADT7476",
1672 [adt7490] = "ADT7490",
1673 };
1674
1675 struct adt7475_data *data;
1676 struct device *hwmon_dev;
1677 int i, ret = 0, revision, group_num = 0;
1678 u8 config3;
1679 const struct i2c_device_id *id = i2c_match_id(adt7475_id, client);
1680
1681 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
1682 if (data == NULL)
1683 return -ENOMEM;
1684
1685 mutex_init(&data->lock);
1686 data->client = client;
1687 i2c_set_clientdata(client, data);
1688
1679
1680 data = devm_kzalloc(&client->dev, sizeof(*data), GFP_KERNEL);
1681 if (data == NULL)
1682 return -ENOMEM;
1683
1684 mutex_init(&data->lock);
1685 data->client = client;
1686 i2c_set_clientdata(client, data);
1687
1689 if (client->dev.of_node)
1690 chip = (uintptr_t)of_device_get_match_data(&client->dev);
1691 else
1692 chip = id->driver_data;
1688 chip = (uintptr_t)i2c_get_match_data(client);
1693
1694 /* Initialize device-specific values */
1695 switch (chip) {
1696 case adt7476:
1697 data->has_voltage = 0x0e; /* in1 to in3 */
1698 revision = adt7475_read(REG_DEVID2) & 0x07;
1699 break;
1700 case adt7490:

--- 11 unchanged lines hidden (view full) ---

1712 if (ret)
1713 return ret;
1714
1715 config3 = adt7475_read(REG_CONFIG3);
1716 /* Pin PWM2 may alternatively be used for ALERT output */
1717 if (!(config3 & CONFIG3_SMBALERT))
1718 data->has_pwm2 = 1;
1719 /* Meaning of this bit is inverted for the ADT7473-1 */
1689
1690 /* Initialize device-specific values */
1691 switch (chip) {
1692 case adt7476:
1693 data->has_voltage = 0x0e; /* in1 to in3 */
1694 revision = adt7475_read(REG_DEVID2) & 0x07;
1695 break;
1696 case adt7490:

--- 11 unchanged lines hidden (view full) ---

1708 if (ret)
1709 return ret;
1710
1711 config3 = adt7475_read(REG_CONFIG3);
1712 /* Pin PWM2 may alternatively be used for ALERT output */
1713 if (!(config3 & CONFIG3_SMBALERT))
1714 data->has_pwm2 = 1;
1715 /* Meaning of this bit is inverted for the ADT7473-1 */
1720 if (id->driver_data == adt7473 && revision >= 1)
1716 if (chip == adt7473 && revision >= 1)
1721 data->has_pwm2 = !data->has_pwm2;
1722
1723 data->config4 = adt7475_read(REG_CONFIG4);
1724 /* Pin TACH4 may alternatively be used for THERM */
1725 if ((data->config4 & CONFIG4_PINFUNC) == 0x0)
1726 data->has_fan4 = 1;
1727
1728 /*
1729 * THERM configuration is more complex on the ADT7476 and ADT7490,
1730 * because 2 different pins (TACH4 and +2.5 Vin) can be used for
1731 * this function
1732 */
1717 data->has_pwm2 = !data->has_pwm2;
1718
1719 data->config4 = adt7475_read(REG_CONFIG4);
1720 /* Pin TACH4 may alternatively be used for THERM */
1721 if ((data->config4 & CONFIG4_PINFUNC) == 0x0)
1722 data->has_fan4 = 1;
1723
1724 /*
1725 * THERM configuration is more complex on the ADT7476 and ADT7490,
1726 * because 2 different pins (TACH4 and +2.5 Vin) can be used for
1727 * this function
1728 */
1733 if (id->driver_data == adt7490) {
1729 if (chip == adt7490) {
1734 if ((data->config4 & CONFIG4_PINFUNC) == 0x1 &&
1735 !(config3 & CONFIG3_THERM))
1736 data->has_fan4 = 1;
1737 }
1730 if ((data->config4 & CONFIG4_PINFUNC) == 0x1 &&
1731 !(config3 & CONFIG3_THERM))
1732 data->has_fan4 = 1;
1733 }
1738 if (id->driver_data == adt7476 || id->driver_data == adt7490) {
1734 if (chip == adt7476 || chip == adt7490) {
1739 if (!(config3 & CONFIG3_THERM) ||
1740 (data->config4 & CONFIG4_PINFUNC) == 0x1)
1741 data->has_voltage |= (1 << 0); /* in0 */
1742 }
1743
1744 /*
1745 * On the ADT7476, the +12V input pin may instead be used as VID5,
1746 * and VID pins may alternatively be used as GPIO
1747 */
1735 if (!(config3 & CONFIG3_THERM) ||
1736 (data->config4 & CONFIG4_PINFUNC) == 0x1)
1737 data->has_voltage |= (1 << 0); /* in0 */
1738 }
1739
1740 /*
1741 * On the ADT7476, the +12V input pin may instead be used as VID5,
1742 * and VID pins may alternatively be used as GPIO
1743 */
1748 if (id->driver_data == adt7476) {
1744 if (chip == adt7476) {
1749 u8 vid = adt7475_read(REG_VID);
1750 if (!(vid & VID_VIDSEL))
1751 data->has_voltage |= (1 << 4); /* in4 */
1752
1753 data->has_vid = !(adt7475_read(REG_CONFIG5) & CONFIG5_VIDGPIO);
1754 }
1755
1756 /* Voltage attenuators can be bypassed, globally or individually */

--- 67 unchanged lines hidden (view full) ---

1824 data->groups);
1825
1826 if (IS_ERR(hwmon_dev)) {
1827 ret = PTR_ERR(hwmon_dev);
1828 return ret;
1829 }
1830
1831 dev_info(&client->dev, "%s device, revision %d\n",
1745 u8 vid = adt7475_read(REG_VID);
1746 if (!(vid & VID_VIDSEL))
1747 data->has_voltage |= (1 << 4); /* in4 */
1748
1749 data->has_vid = !(adt7475_read(REG_CONFIG5) & CONFIG5_VIDGPIO);
1750 }
1751
1752 /* Voltage attenuators can be bypassed, globally or individually */

--- 67 unchanged lines hidden (view full) ---

1820 data->groups);
1821
1822 if (IS_ERR(hwmon_dev)) {
1823 ret = PTR_ERR(hwmon_dev);
1824 return ret;
1825 }
1826
1827 dev_info(&client->dev, "%s device, revision %d\n",
1832 names[id->driver_data], revision);
1828 names[chip], revision);
1833 if ((data->has_voltage & 0x11) || data->has_fan4 || data->has_pwm2)
1834 dev_info(&client->dev, "Optional features:%s%s%s%s%s\n",
1835 (data->has_voltage & (1 << 0)) ? " in0" : "",
1836 (data->has_voltage & (1 << 4)) ? " in4" : "",
1837 data->has_fan4 ? " fan4" : "",
1838 data->has_pwm2 ? " pwm2" : "",
1839 data->has_vid ? " vid" : "");
1840 if (data->bypass_attn)

--- 237 unchanged lines hidden ---
1829 if ((data->has_voltage & 0x11) || data->has_fan4 || data->has_pwm2)
1830 dev_info(&client->dev, "Optional features:%s%s%s%s%s\n",
1831 (data->has_voltage & (1 << 0)) ? " in0" : "",
1832 (data->has_voltage & (1 << 4)) ? " in4" : "",
1833 data->has_fan4 ? " fan4" : "",
1834 data->has_pwm2 ? " pwm2" : "",
1835 data->has_vid ? " vid" : "");
1836 if (data->bypass_attn)

--- 237 unchanged lines hidden ---