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

hwmon: (dme1737) Add SCH5127 support

Add support for the hardware monitoring capabilities of the SCH5127
chip to the dme1737 driver.

Signed-off-by: Juerg Haefliger <juergh@gmail.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Tested-by: Jeff Rickman <jrickman@myamigos.us>

authored by

Juerg Haefliger and committed by
Jean Delvare
ea694431 38806bda

+266 -113
+41 -10
Documentation/hwmon/dme1737
··· 9 9 * SMSC SCH3112, SCH3114, SCH3116 10 10 Prefix: 'sch311x' 11 11 Addresses scanned: none, address read from Super-I/O config space 12 - Datasheet: http://www.nuhorizons.com/FeaturedProducts/Volume1/SMSC/311x.pdf 12 + Datasheet: Available on the Internet 13 13 * SMSC SCH5027 14 14 Prefix: 'sch5027' 15 15 Addresses scanned: I2C 0x2c, 0x2d, 0x2e 16 + Datasheet: Provided by SMSC upon request and under NDA 17 + * SMSC SCH5127 18 + Prefix: 'sch5127' 19 + Addresses scanned: none, address read from Super-I/O config space 16 20 Datasheet: Provided by SMSC upon request and under NDA 17 21 18 22 Authors: ··· 40 36 ----------- 41 37 42 38 This driver implements support for the hardware monitoring capabilities of the 43 - SMSC DME1737 and Asus A8000 (which are the same), SMSC SCH5027, and SMSC 44 - SCH311x Super-I/O chips. These chips feature monitoring of 3 temp sensors 39 + SMSC DME1737 and Asus A8000 (which are the same), SMSC SCH5027, SCH311x, 40 + and SCH5127 Super-I/O chips. These chips feature monitoring of 3 temp sensors 45 41 temp[1-3] (2 remote diodes and 1 internal), 7 voltages in[0-6] (6 external and 46 42 1 internal) and up to 6 fan speeds fan[1-6]. Additionally, the chips implement 47 43 up to 5 PWM outputs pwm[1-3,5-6] for controlling fan speeds both manually and ··· 52 48 the configuration of the chip. The driver will detect which features are 53 49 present during initialization and create the sysfs attributes accordingly. 54 50 55 - For the SCH311x, fan[1-3] and pwm[1-3] are always present and fan[4-6] and 56 - pwm[5-6] don't exist. 51 + For the SCH311x and SCH5127, fan[1-3] and pwm[1-3] are always present and 52 + fan[4-6] and pwm[5-6] don't exist. 57 53 58 54 The hardware monitoring features of the DME1737, A8000, and SCH5027 are only 59 - accessible via SMBus, while the SCH311x only provides access via the ISA bus. 60 - The driver will therefore register itself as an I2C client driver if it detects 61 - a DME1737, A8000, or SCH5027 and as a platform driver if it detects a SCH311x 62 - chip. 55 + accessible via SMBus, while the SCH311x and SCH5127 only provide access via 56 + the ISA bus. The driver will therefore register itself as an I2C client driver 57 + if it detects a DME1737, A8000, or SCH5027 and as a platform driver if it 58 + detects a SCH311x or SCH5127 chip. 63 59 64 60 65 61 Voltage Monitoring ··· 80 76 in6: Vbat (+3.0V) 0V - 4.38V 81 77 82 78 SCH311x: 83 - in0: +2.5V 0V - 6.64V 79 + in0: +2.5V 0V - 3.32V 84 80 in1: Vccp (processor core) 0V - 2V 85 81 in2: VCC (internal +3.3V) 0V - 4.38V 86 82 in3: +5V 0V - 6.64V ··· 90 86 91 87 SCH5027: 92 88 in0: +5VTR (+5V standby) 0V - 6.64V 89 + in1: Vccp (processor core) 0V - 3V 90 + in2: VCC (internal +3.3V) 0V - 4.38V 91 + in3: V2_IN 0V - 1.5V 92 + in4: V1_IN 0V - 1.5V 93 + in5: VTR (+3.3V standby) 0V - 4.38V 94 + in6: Vbat (+3.0V) 0V - 4.38V 95 + 96 + SCH5127: 97 + in0: +2.5 0V - 3.32V 93 98 in1: Vccp (processor core) 0V - 3V 94 99 in2: VCC (internal +3.3V) 0V - 4.38V 95 100 in3: V2_IN 0V - 1.5V ··· 306 293 pwm[1-3]_auto_point2_pwm RO Auto PWM pwm point. Auto_point2 is the 307 294 full-speed duty-cycle which is hard- 308 295 wired to 255 (100% duty-cycle). 296 + 297 + Chip Differences 298 + ---------------- 299 + 300 + Feature dme1737 sch311x sch5027 sch5127 301 + ------------------------------------------------------- 302 + temp[1-3]_offset yes yes 303 + vid yes 304 + zone3 yes yes yes 305 + zone[1-3]_hyst yes yes 306 + pwm min/off yes yes 307 + fan3 opt yes opt yes 308 + pwm3 opt yes opt yes 309 + fan4 opt opt 310 + fan5 opt opt 311 + pwm5 opt opt 312 + fan6 opt opt 313 + pwm6 opt opt
+225 -103
drivers/hwmon/dme1737.c
··· 1 1 /* 2 - * dme1737.c - Driver for the SMSC DME1737, Asus A8000, SMSC SCH311x and 3 - * SCH5027 Super-I/O chips integrated hardware monitoring features. 4 - * Copyright (c) 2007, 2008 Juerg Haefliger <juergh@gmail.com> 2 + * dme1737.c - Driver for the SMSC DME1737, Asus A8000, SMSC SCH311x, SCH5027, 3 + * and SCH5127 Super-I/O chips integrated hardware monitoring 4 + * features. 5 + * Copyright (c) 2007, 2008, 2009, 2010 Juerg Haefliger <juergh@gmail.com> 5 6 * 6 7 * This driver is an I2C/ISA hybrid, meaning that it uses the I2C bus to access 7 8 * the chip registers if a DME1737, A8000, or SCH5027 is found and the ISA bus 8 - * if a SCH311x chip is found. Both types of chips have very similar hardware 9 - * monitoring capabilities but differ in the way they can be accessed. 9 + * if a SCH311x or SCH5127 chip is found. Both types of chips have very 10 + * similar hardware monitoring capabilities but differ in the way they can be 11 + * accessed. 10 12 * 11 13 * This program is free software; you can redistribute it and/or modify 12 14 * it under the terms of the GNU General Public License as published by ··· 59 57 /* Addresses to scan */ 60 58 static const unsigned short normal_i2c[] = {0x2c, 0x2d, 0x2e, I2C_CLIENT_END}; 61 59 62 - enum chips { dme1737, sch5027, sch311x }; 60 + enum chips { dme1737, sch5027, sch311x, sch5127 }; 63 61 64 62 /* --------------------------------------------------------------------- 65 63 * Registers ··· 166 164 #define DME1737_VERSTEP_MASK 0xf8 167 165 #define SCH311X_DEVICE 0x8c 168 166 #define SCH5027_VERSTEP 0x69 167 + #define SCH5127_DEVICE 0x8e 168 + 169 + /* Device ID values (global configuration register index 0x20) */ 170 + #define DME1737_ID_1 0x77 171 + #define DME1737_ID_2 0x78 172 + #define SCH3112_ID 0x7c 173 + #define SCH3114_ID 0x7d 174 + #define SCH3116_ID 0x7f 175 + #define SCH5027_ID 0x89 176 + #define SCH5127_ID 0x86 169 177 170 178 /* Length of ISA address segment */ 171 179 #define DME1737_EXTENT 2 180 + 181 + /* chip-dependent features */ 182 + #define HAS_TEMP_OFFSET (1 << 0) /* bit 0 */ 183 + #define HAS_VID (1 << 1) /* bit 1 */ 184 + #define HAS_ZONE3 (1 << 2) /* bit 2 */ 185 + #define HAS_ZONE_HYST (1 << 3) /* bit 3 */ 186 + #define HAS_PWM_MIN (1 << 4) /* bit 4 */ 187 + #define HAS_FAN(ix) (1 << ((ix) + 5)) /* bits 5-10 */ 188 + #define HAS_PWM(ix) (1 << ((ix) + 11)) /* bits 11-16 */ 172 189 173 190 /* --------------------------------------------------------------------- 174 191 * Data structures and manipulation thereof ··· 208 187 209 188 u8 vid; 210 189 u8 pwm_rr_en; 211 - u8 has_pwm; 212 - u8 has_fan; 190 + u32 has_features; 213 191 214 192 /* Register values */ 215 193 u16 in[7]; ··· 244 224 3300}; 245 225 static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300, 246 226 3300}; 227 + static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300, 228 + 3300}; 247 229 #define IN_NOMINAL(type) ((type) == sch311x ? IN_NOMINAL_SCH311x : \ 248 230 (type) == sch5027 ? IN_NOMINAL_SCH5027 : \ 231 + (type) == sch5127 ? IN_NOMINAL_SCH5127 : \ 249 232 IN_NOMINAL_DME1737) 250 233 251 234 /* Voltage input ··· 591 568 592 569 /* Sample register contents every 1 sec */ 593 570 if (time_after(jiffies, data->last_update + HZ) || !data->valid) { 594 - if (data->type == dme1737) { 571 + if (data->has_features & HAS_VID) { 595 572 data->vid = dme1737_read(data, DME1737_REG_VID) & 596 573 0x3f; 597 574 } ··· 622 599 DME1737_REG_TEMP_MIN(ix)); 623 600 data->temp_max[ix] = dme1737_read(data, 624 601 DME1737_REG_TEMP_MAX(ix)); 625 - if (data->type != sch5027) { 602 + if (data->has_features & HAS_TEMP_OFFSET) { 626 603 data->temp_offset[ix] = dme1737_read(data, 627 604 DME1737_REG_TEMP_OFFSET(ix)); 628 605 } ··· 649 626 for (ix = 0; ix < ARRAY_SIZE(data->fan); ix++) { 650 627 /* Skip reading registers if optional fans are not 651 628 * present */ 652 - if (!(data->has_fan & (1 << ix))) { 629 + if (!(data->has_features & HAS_FAN(ix))) { 653 630 continue; 654 631 } 655 632 data->fan[ix] = dme1737_read(data, ··· 673 650 for (ix = 0; ix < ARRAY_SIZE(data->pwm); ix++) { 674 651 /* Skip reading registers if optional PWMs are not 675 652 * present */ 676 - if (!(data->has_pwm & (1 << ix))) { 653 + if (!(data->has_features & HAS_PWM(ix))) { 677 654 continue; 678 655 } 679 656 data->pwm[ix] = dme1737_read(data, ··· 695 672 696 673 /* Thermal zone registers */ 697 674 for (ix = 0; ix < ARRAY_SIZE(data->zone_low); ix++) { 698 - data->zone_low[ix] = dme1737_read(data, 699 - DME1737_REG_ZONE_LOW(ix)); 700 - data->zone_abs[ix] = dme1737_read(data, 701 - DME1737_REG_ZONE_ABS(ix)); 675 + /* Skip reading registers if zone3 is not present */ 676 + if ((ix == 2) && !(data->has_features & HAS_ZONE3)) { 677 + continue; 678 + } 679 + /* sch5127 zone2 registers are special */ 680 + if ((ix == 1) && (data->type == sch5127)) { 681 + data->zone_low[1] = dme1737_read(data, 682 + DME1737_REG_ZONE_LOW(2)); 683 + data->zone_abs[1] = dme1737_read(data, 684 + DME1737_REG_ZONE_ABS(2)); 685 + } else { 686 + data->zone_low[ix] = dme1737_read(data, 687 + DME1737_REG_ZONE_LOW(ix)); 688 + data->zone_abs[ix] = dme1737_read(data, 689 + DME1737_REG_ZONE_ABS(ix)); 690 + } 702 691 } 703 - if (data->type != sch5027) { 692 + if (data->has_features & HAS_ZONE_HYST) { 704 693 for (ix = 0; ix < ARRAY_SIZE(data->zone_hyst); ix++) { 705 694 data->zone_hyst[ix] = dme1737_read(data, 706 695 DME1737_REG_ZONE_HYST(ix)); ··· 1629 1594 &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr, 1630 1595 &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr, 1631 1596 &sensor_dev_attr_zone2_auto_channels_temp.dev_attr.attr, 1632 - &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, 1633 - &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, 1634 - &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr, 1635 - &sensor_dev_attr_zone3_auto_channels_temp.dev_attr.attr, 1636 1597 NULL 1637 1598 }; 1638 1599 ··· 1636 1605 .attrs = dme1737_attr, 1637 1606 }; 1638 1607 1639 - /* The following struct holds misc attributes, which are not available in all 1640 - * chips. Their creation depends on the chip type which is determined during 1641 - * module load. */ 1642 - static struct attribute *dme1737_misc_attr[] = { 1643 - /* Temperatures */ 1608 + /* The following struct holds temp offset attributes, which are not available 1609 + * in all chips. The following chips support them: 1610 + * DME1737, SCH311x */ 1611 + static struct attribute *dme1737_temp_offset_attr[] = { 1644 1612 &sensor_dev_attr_temp1_offset.dev_attr.attr, 1645 1613 &sensor_dev_attr_temp2_offset.dev_attr.attr, 1646 1614 &sensor_dev_attr_temp3_offset.dev_attr.attr, 1647 - /* Zones */ 1648 - &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr, 1649 - &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr, 1650 - &sensor_dev_attr_zone3_auto_point1_temp_hyst.dev_attr.attr, 1651 1615 NULL 1652 1616 }; 1653 1617 1654 - static const struct attribute_group dme1737_misc_group = { 1655 - .attrs = dme1737_misc_attr, 1618 + static const struct attribute_group dme1737_temp_offset_group = { 1619 + .attrs = dme1737_temp_offset_attr, 1656 1620 }; 1657 1621 1658 - /* The following struct holds VID-related attributes. Their creation 1659 - depends on the chip type which is determined during module load. */ 1622 + /* The following struct holds VID related attributes, which are not available 1623 + * in all chips. The following chips support them: 1624 + * DME1737 */ 1660 1625 static struct attribute *dme1737_vid_attr[] = { 1661 1626 &dev_attr_vrm.attr, 1662 1627 &dev_attr_cpu0_vid.attr, ··· 1661 1634 1662 1635 static const struct attribute_group dme1737_vid_group = { 1663 1636 .attrs = dme1737_vid_attr, 1637 + }; 1638 + 1639 + /* The following struct holds temp zone 3 related attributes, which are not 1640 + * available in all chips. The following chips support them: 1641 + * DME1737, SCH311x, SCH5027 */ 1642 + static struct attribute *dme1737_zone3_attr[] = { 1643 + &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, 1644 + &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, 1645 + &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr, 1646 + &sensor_dev_attr_zone3_auto_channels_temp.dev_attr.attr, 1647 + NULL 1648 + }; 1649 + 1650 + static const struct attribute_group dme1737_zone3_group = { 1651 + .attrs = dme1737_zone3_attr, 1652 + }; 1653 + 1654 + 1655 + /* The following struct holds temp zone hysteresis related attributes, which 1656 + * are not available in all chips. The following chips support them: 1657 + * DME1737, SCH311x */ 1658 + static struct attribute *dme1737_zone_hyst_attr[] = { 1659 + &sensor_dev_attr_zone1_auto_point1_temp_hyst.dev_attr.attr, 1660 + &sensor_dev_attr_zone2_auto_point1_temp_hyst.dev_attr.attr, 1661 + &sensor_dev_attr_zone3_auto_point1_temp_hyst.dev_attr.attr, 1662 + NULL 1663 + }; 1664 + 1665 + static const struct attribute_group dme1737_zone_hyst_group = { 1666 + .attrs = dme1737_zone_hyst_attr, 1664 1667 }; 1665 1668 1666 1669 /* The following structs hold the PWM attributes, some of which are optional. ··· 1748 1691 { .attrs = dme1737_pwm6_attr }, 1749 1692 }; 1750 1693 1751 - /* The following struct holds misc PWM attributes, which are not available in 1752 - * all chips. Their creation depends on the chip type which is determined 1694 + /* The following struct holds auto PWM min attributes, which are not available 1695 + * in all chips. Their creation depends on the chip type which is determined 1753 1696 * during module load. */ 1754 - static struct attribute *dme1737_pwm_misc_attr[] = { 1697 + static struct attribute *dme1737_auto_pwm_min_attr[] = { 1755 1698 &sensor_dev_attr_pwm1_auto_pwm_min.dev_attr.attr, 1756 1699 &sensor_dev_attr_pwm2_auto_pwm_min.dev_attr.attr, 1757 1700 &sensor_dev_attr_pwm3_auto_pwm_min.dev_attr.attr, ··· 1821 1764 &sensor_dev_attr_zone2_auto_point1_temp.dev_attr.attr, 1822 1765 &sensor_dev_attr_zone2_auto_point2_temp.dev_attr.attr, 1823 1766 &sensor_dev_attr_zone2_auto_point3_temp.dev_attr.attr, 1767 + NULL 1768 + }; 1769 + 1770 + static const struct attribute_group dme1737_zone_chmod_group = { 1771 + .attrs = dme1737_zone_chmod_attr, 1772 + }; 1773 + 1774 + 1775 + /* The permissions of the following zone 3 attributes are changed to read- 1776 + * writeable if the chip is *not* locked. Otherwise they stay read-only. */ 1777 + static struct attribute *dme1737_zone3_chmod_attr[] = { 1824 1778 &sensor_dev_attr_zone3_auto_point1_temp.dev_attr.attr, 1825 1779 &sensor_dev_attr_zone3_auto_point2_temp.dev_attr.attr, 1826 1780 &sensor_dev_attr_zone3_auto_point3_temp.dev_attr.attr, 1827 1781 NULL 1828 1782 }; 1829 1783 1830 - static const struct attribute_group dme1737_zone_chmod_group = { 1831 - .attrs = dme1737_zone_chmod_attr, 1784 + static const struct attribute_group dme1737_zone3_chmod_group = { 1785 + .attrs = dme1737_zone3_chmod_attr, 1832 1786 }; 1833 1787 1834 1788 /* The permissions of the following PWM attributes are changed to read- ··· 1955 1887 int ix; 1956 1888 1957 1889 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { 1958 - if (data->has_fan & (1 << ix)) { 1890 + if (data->has_features & HAS_FAN(ix)) { 1959 1891 sysfs_remove_group(&dev->kobj, 1960 1892 &dme1737_fan_group[ix]); 1961 1893 } 1962 1894 } 1963 1895 1964 1896 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { 1965 - if (data->has_pwm & (1 << ix)) { 1897 + if (data->has_features & HAS_PWM(ix)) { 1966 1898 sysfs_remove_group(&dev->kobj, 1967 1899 &dme1737_pwm_group[ix]); 1968 - if (data->type != sch5027 && ix < 3) { 1900 + if ((data->has_features & HAS_PWM_MIN) && ix < 3) { 1969 1901 sysfs_remove_file(&dev->kobj, 1970 - dme1737_pwm_misc_attr[ix]); 1902 + dme1737_auto_pwm_min_attr[ix]); 1971 1903 } 1972 1904 } 1973 1905 } 1974 1906 1975 - if (data->type != sch5027) { 1976 - sysfs_remove_group(&dev->kobj, &dme1737_misc_group); 1907 + if (data->has_features & HAS_TEMP_OFFSET) { 1908 + sysfs_remove_group(&dev->kobj, &dme1737_temp_offset_group); 1977 1909 } 1978 - if (data->type == dme1737) { 1910 + if (data->has_features & HAS_VID) { 1979 1911 sysfs_remove_group(&dev->kobj, &dme1737_vid_group); 1980 1912 } 1981 - 1913 + if (data->has_features & HAS_ZONE3) { 1914 + sysfs_remove_group(&dev->kobj, &dme1737_zone3_group); 1915 + } 1916 + if (data->has_features & HAS_ZONE_HYST) { 1917 + sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group); 1918 + } 1982 1919 sysfs_remove_group(&dev->kobj, &dme1737_group); 1983 1920 1984 1921 if (!data->client) { ··· 2007 1934 goto exit_remove; 2008 1935 } 2009 1936 2010 - /* Create misc sysfs attributes */ 2011 - if ((data->type != sch5027) && 1937 + /* Create chip-dependent sysfs attributes */ 1938 + if ((data->has_features & HAS_TEMP_OFFSET) && 2012 1939 (err = sysfs_create_group(&dev->kobj, 2013 - &dme1737_misc_group))) { 1940 + &dme1737_temp_offset_group))) { 2014 1941 goto exit_remove; 2015 1942 } 2016 - 2017 - /* Create VID-related sysfs attributes */ 2018 - if ((data->type == dme1737) && 1943 + if ((data->has_features & HAS_VID) && 2019 1944 (err = sysfs_create_group(&dev->kobj, 2020 1945 &dme1737_vid_group))) { 1946 + goto exit_remove; 1947 + } 1948 + if ((data->has_features & HAS_ZONE3) && 1949 + (err = sysfs_create_group(&dev->kobj, 1950 + &dme1737_zone3_group))) { 1951 + goto exit_remove; 1952 + } 1953 + if ((data->has_features & HAS_ZONE_HYST) && 1954 + (err = sysfs_create_group(&dev->kobj, 1955 + &dme1737_zone_hyst_group))) { 2021 1956 goto exit_remove; 2022 1957 } 2023 1958 2024 1959 /* Create fan sysfs attributes */ 2025 1960 for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) { 2026 - if (data->has_fan & (1 << ix)) { 1961 + if (data->has_features & HAS_FAN(ix)) { 2027 1962 if ((err = sysfs_create_group(&dev->kobj, 2028 1963 &dme1737_fan_group[ix]))) { 2029 1964 goto exit_remove; ··· 2041 1960 2042 1961 /* Create PWM sysfs attributes */ 2043 1962 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) { 2044 - if (data->has_pwm & (1 << ix)) { 1963 + if (data->has_features & HAS_PWM(ix)) { 2045 1964 if ((err = sysfs_create_group(&dev->kobj, 2046 1965 &dme1737_pwm_group[ix]))) { 2047 1966 goto exit_remove; 2048 1967 } 2049 - if (data->type != sch5027 && ix < 3 && 1968 + if ((data->has_features & HAS_PWM_MIN) && ix < 3 && 2050 1969 (err = sysfs_create_file(&dev->kobj, 2051 - dme1737_pwm_misc_attr[ix]))) { 1970 + dme1737_auto_pwm_min_attr[ix]))) { 2052 1971 goto exit_remove; 2053 1972 } 2054 1973 } ··· 2064 1983 dme1737_chmod_group(dev, &dme1737_zone_chmod_group, 2065 1984 S_IRUGO | S_IWUSR); 2066 1985 2067 - /* Change permissions of misc sysfs attributes */ 2068 - if (data->type != sch5027) { 2069 - dme1737_chmod_group(dev, &dme1737_misc_group, 1986 + /* Change permissions of chip-dependent sysfs attributes */ 1987 + if (data->has_features & HAS_TEMP_OFFSET) { 1988 + dme1737_chmod_group(dev, &dme1737_temp_offset_group, 1989 + S_IRUGO | S_IWUSR); 1990 + } 1991 + if (data->has_features & HAS_ZONE3) { 1992 + dme1737_chmod_group(dev, &dme1737_zone3_chmod_group, 1993 + S_IRUGO | S_IWUSR); 1994 + } 1995 + if (data->has_features & HAS_ZONE_HYST) { 1996 + dme1737_chmod_group(dev, &dme1737_zone_hyst_group, 2070 1997 S_IRUGO | S_IWUSR); 2071 1998 } 2072 1999 2073 2000 /* Change permissions of PWM sysfs attributes */ 2074 2001 for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_chmod_group); ix++) { 2075 - if (data->has_pwm & (1 << ix)) { 2002 + if (data->has_features & HAS_PWM(ix)) { 2076 2003 dme1737_chmod_group(dev, 2077 2004 &dme1737_pwm_chmod_group[ix], 2078 2005 S_IRUGO | S_IWUSR); 2079 - if (data->type != sch5027 && ix < 3) { 2006 + if ((data->has_features & HAS_PWM_MIN) && 2007 + ix < 3) { 2080 2008 dme1737_chmod_file(dev, 2081 - dme1737_pwm_misc_attr[ix], 2009 + dme1737_auto_pwm_min_attr[ix], 2082 2010 S_IRUGO | S_IWUSR); 2083 2011 } 2084 2012 } ··· 2095 2005 2096 2006 /* Change permissions of pwm[1-3] if in manual mode */ 2097 2007 for (ix = 0; ix < 3; ix++) { 2098 - if ((data->has_pwm & (1 << ix)) && 2008 + if ((data->has_features & HAS_PWM(ix)) && 2099 2009 (PWM_EN_FROM_REG(data->pwm_config[ix]) == 1)) { 2100 2010 dme1737_chmod_file(dev, 2101 2011 dme1737_pwm_chmod_attr[ix], ··· 2142 2052 return -EFAULT; 2143 2053 } 2144 2054 2145 - /* Determine which optional fan and pwm features are enabled/present */ 2055 + /* Determine which optional fan and pwm features are enabled (only 2056 + * valid for I2C devices) */ 2146 2057 if (client) { /* I2C chip */ 2147 2058 data->config2 = dme1737_read(data, DME1737_REG_CONFIG2); 2148 2059 /* Check if optional fan3 input is enabled */ 2149 2060 if (data->config2 & 0x04) { 2150 - data->has_fan |= (1 << 2); 2061 + data->has_features |= HAS_FAN(2); 2151 2062 } 2152 2063 2153 2064 /* Fan4 and pwm3 are only available if the client's I2C address 2154 2065 * is the default 0x2e. Otherwise the I/Os associated with 2155 2066 * these functions are used for addr enable/select. */ 2156 2067 if (client->addr == 0x2e) { 2157 - data->has_fan |= (1 << 3); 2158 - data->has_pwm |= (1 << 2); 2068 + data->has_features |= HAS_FAN(3) | HAS_PWM(2); 2159 2069 } 2160 2070 2161 2071 /* Determine which of the optional fan[5-6] and pwm[5-6] ··· 2167 2077 dev_warn(dev, "Failed to query Super-IO for optional " 2168 2078 "features.\n"); 2169 2079 } 2170 - } else { /* ISA chip */ 2171 - /* Fan3 and pwm3 are always available. Fan[4-5] and pwm[5-6] 2172 - * don't exist in the ISA chip. */ 2173 - data->has_fan |= (1 << 2); 2174 - data->has_pwm |= (1 << 2); 2175 2080 } 2176 2081 2177 - /* Fan1, fan2, pwm1, and pwm2 are always present */ 2178 - data->has_fan |= 0x03; 2179 - data->has_pwm |= 0x03; 2082 + /* Fan[1-2] and pwm[1-2] are present in all chips */ 2083 + data->has_features |= HAS_FAN(0) | HAS_FAN(1) | HAS_PWM(0) | HAS_PWM(1); 2084 + 2085 + /* Chip-dependent features */ 2086 + switch (data->type) { 2087 + case dme1737: 2088 + data->has_features |= HAS_TEMP_OFFSET | HAS_VID | HAS_ZONE3 | 2089 + HAS_ZONE_HYST | HAS_PWM_MIN; 2090 + break; 2091 + case sch311x: 2092 + data->has_features |= HAS_TEMP_OFFSET | HAS_ZONE3 | 2093 + HAS_ZONE_HYST | HAS_PWM_MIN | HAS_FAN(2) | HAS_PWM(2); 2094 + break; 2095 + case sch5027: 2096 + data->has_features |= HAS_ZONE3; 2097 + break; 2098 + case sch5127: 2099 + data->has_features |= HAS_FAN(2) | HAS_PWM(2); 2100 + break; 2101 + default: 2102 + break; 2103 + } 2180 2104 2181 2105 dev_info(dev, "Optional features: pwm3=%s, pwm5=%s, pwm6=%s, " 2182 2106 "fan3=%s, fan4=%s, fan5=%s, fan6=%s.\n", 2183 - (data->has_pwm & (1 << 2)) ? "yes" : "no", 2184 - (data->has_pwm & (1 << 4)) ? "yes" : "no", 2185 - (data->has_pwm & (1 << 5)) ? "yes" : "no", 2186 - (data->has_fan & (1 << 2)) ? "yes" : "no", 2187 - (data->has_fan & (1 << 3)) ? "yes" : "no", 2188 - (data->has_fan & (1 << 4)) ? "yes" : "no", 2189 - (data->has_fan & (1 << 5)) ? "yes" : "no"); 2107 + (data->has_features & HAS_PWM(2)) ? "yes" : "no", 2108 + (data->has_features & HAS_PWM(4)) ? "yes" : "no", 2109 + (data->has_features & HAS_PWM(5)) ? "yes" : "no", 2110 + (data->has_features & HAS_FAN(2)) ? "yes" : "no", 2111 + (data->has_features & HAS_FAN(3)) ? "yes" : "no", 2112 + (data->has_features & HAS_FAN(4)) ? "yes" : "no", 2113 + (data->has_features & HAS_FAN(5)) ? "yes" : "no"); 2190 2114 2191 2115 reg = dme1737_read(data, DME1737_REG_TACH_PWM); 2192 2116 /* Inform if fan-to-pwm mapping differs from the default */ ··· 2226 2122 for (ix = 0; ix < 3; ix++) { 2227 2123 data->pwm_config[ix] = dme1737_read(data, 2228 2124 DME1737_REG_PWM_CONFIG(ix)); 2229 - if ((data->has_pwm & (1 << ix)) && 2125 + if ((data->has_features & HAS_PWM(ix)) && 2230 2126 (PWM_EN_FROM_REG(data->pwm_config[ix]) == -1)) { 2231 2127 dev_info(dev, "Switching pwm%d to " 2232 2128 "manual mode.\n", ix + 1); ··· 2246 2142 data->pwm_acz[2] = 4; /* pwm3 -> zone3 */ 2247 2143 2248 2144 /* Set VRM */ 2249 - if (data->type == dme1737) { 2145 + if (data->has_features & HAS_VID) { 2250 2146 data->vrm = vid_which_vrm(); 2251 2147 } 2252 2148 ··· 2267 2163 dme1737_sio_enter(sio_cip); 2268 2164 2269 2165 /* Check device ID 2270 - * The DME1737 can return either 0x78 or 0x77 as its device ID. 2271 - * The SCH5027 returns 0x89 as its device ID. */ 2166 + * We currently know about two kinds of DME1737 and SCH5027. */ 2272 2167 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20); 2273 - if (!(reg == 0x77 || reg == 0x78 || reg == 0x89)) { 2168 + if (!(reg == DME1737_ID_1 || reg == DME1737_ID_2 || 2169 + reg == SCH5027_ID)) { 2274 2170 err = -ENODEV; 2275 2171 goto exit; 2276 2172 } ··· 2289 2185 * are enabled and available. Bits [3:2] of registers 0x43-0x46 are set 2290 2186 * to '10' if the respective feature is enabled. */ 2291 2187 if ((inb(addr + 0x43) & 0x0c) == 0x08) { /* fan6 */ 2292 - data->has_fan |= (1 << 5); 2188 + data->has_features |= HAS_FAN(5); 2293 2189 } 2294 2190 if ((inb(addr + 0x44) & 0x0c) == 0x08) { /* pwm6 */ 2295 - data->has_pwm |= (1 << 5); 2191 + data->has_features |= HAS_PWM(5); 2296 2192 } 2297 2193 if ((inb(addr + 0x45) & 0x0c) == 0x08) { /* fan5 */ 2298 - data->has_fan |= (1 << 4); 2194 + data->has_features |= HAS_FAN(4); 2299 2195 } 2300 2196 if ((inb(addr + 0x46) & 0x0c) == 0x08) { /* pwm5 */ 2301 - data->has_pwm |= (1 << 4); 2197 + data->has_features |= HAS_PWM(4); 2302 2198 } 2303 2199 2304 2200 exit: ··· 2326 2222 if (company == DME1737_COMPANY_SMSC && 2327 2223 verstep == SCH5027_VERSTEP) { 2328 2224 name = "sch5027"; 2329 - 2330 2225 } else if (company == DME1737_COMPANY_SMSC && 2331 2226 (verstep & DME1737_VERSTEP_MASK) == DME1737_VERSTEP) { 2332 2227 name = "dme1737"; ··· 2432 2329 dme1737_sio_enter(sio_cip); 2433 2330 2434 2331 /* Check device ID 2435 - * We currently know about SCH3112 (0x7c), SCH3114 (0x7d), and 2436 - * SCH3116 (0x7f). */ 2332 + * We currently know about SCH3112, SCH3114, SCH3116, and SCH5127 */ 2437 2333 reg = force_id ? force_id : dme1737_sio_inb(sio_cip, 0x20); 2438 - if (!(reg == 0x7c || reg == 0x7d || reg == 0x7f)) { 2334 + if (!(reg == SCH3112_ID || reg == SCH3114_ID || reg == SCH3116_ID || 2335 + reg == SCH5127_ID)) { 2439 2336 err = -ENODEV; 2440 2337 goto exit; 2441 2338 } ··· 2527 2424 platform_set_drvdata(pdev, data); 2528 2425 2529 2426 /* Skip chip detection if module is loaded with force_id parameter */ 2530 - if (!force_id) { 2427 + switch (force_id) { 2428 + case SCH3112_ID: 2429 + case SCH3114_ID: 2430 + case SCH3116_ID: 2431 + data->type = sch311x; 2432 + break; 2433 + case SCH5127_ID: 2434 + data->type = sch5127; 2435 + break; 2436 + default: 2531 2437 company = dme1737_read(data, DME1737_REG_COMPANY); 2532 2438 device = dme1737_read(data, DME1737_REG_DEVICE); 2533 2439 2534 - if (!((company == DME1737_COMPANY_SMSC) && 2535 - (device == SCH311X_DEVICE))) { 2440 + if ((company == DME1737_COMPANY_SMSC) && 2441 + (device == SCH311X_DEVICE)) { 2442 + data->type = sch311x; 2443 + } else if ((company == DME1737_COMPANY_SMSC) && 2444 + (device == SCH5127_DEVICE)) { 2445 + data->type = sch5127; 2446 + } else { 2536 2447 err = -ENODEV; 2537 2448 goto exit_kfree; 2538 2449 } 2539 2450 } 2540 - data->type = sch311x; 2541 2451 2542 - /* Fill in the remaining client fields and initialize the mutex */ 2543 - data->name = "sch311x"; 2452 + if (data->type == sch5127) { 2453 + data->name = "sch5127"; 2454 + } else { 2455 + data->name = "sch311x"; 2456 + } 2457 + 2458 + /* Initialize the mutex */ 2544 2459 mutex_init(&data->update_lock); 2545 2460 2546 - dev_info(dev, "Found a SCH311x chip at 0x%04x\n", data->addr); 2461 + dev_info(dev, "Found a %s chip at 0x%04x\n", 2462 + data->type == sch5127 ? "SCH5127" : "SCH311x", data->addr); 2547 2463 2548 2464 /* Initialize the chip */ 2549 2465 if ((err = dme1737_init_device(dev))) {