aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/w83627ehf.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/w83627ehf.c')
-rw-r--r--drivers/hwmon/w83627ehf.c238
1 files changed, 159 insertions, 79 deletions
diff --git a/drivers/hwmon/w83627ehf.c b/drivers/hwmon/w83627ehf.c
index 36d7f270b14d..98aab4bea342 100644
--- a/drivers/hwmon/w83627ehf.c
+++ b/drivers/hwmon/w83627ehf.c
@@ -197,6 +197,9 @@ static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0, 0x152, 0x252, 0 };
197#define W83627EHF_REG_ALARM2 0x45A 197#define W83627EHF_REG_ALARM2 0x45A
198#define W83627EHF_REG_ALARM3 0x45B 198#define W83627EHF_REG_ALARM3 0x45B
199 199
200#define W83627EHF_REG_CASEOPEN_DET 0x42 /* SMI STATUS #2 */
201#define W83627EHF_REG_CASEOPEN_CLR 0x46 /* SMI MASK #3 */
202
200/* SmartFan registers */ 203/* SmartFan registers */
201#define W83627EHF_REG_FAN_STEPUP_TIME 0x0f 204#define W83627EHF_REG_FAN_STEPUP_TIME 0x0f
202#define W83627EHF_REG_FAN_STEPDOWN_TIME 0x0e 205#define W83627EHF_REG_FAN_STEPDOWN_TIME 0x0e
@@ -316,7 +319,7 @@ static const char *const nct6776_temp_label[] = {
316 319
317#define NUM_REG_TEMP ARRAY_SIZE(NCT6775_REG_TEMP) 320#define NUM_REG_TEMP ARRAY_SIZE(NCT6775_REG_TEMP)
318 321
319static inline int is_word_sized(u16 reg) 322static int is_word_sized(u16 reg)
320{ 323{
321 return ((((reg & 0xff00) == 0x100 324 return ((((reg & 0xff00) == 0x100
322 || (reg & 0xff00) == 0x200) 325 || (reg & 0xff00) == 0x200)
@@ -385,23 +388,6 @@ div_from_reg(u8 reg)
385 return 1 << reg; 388 return 1 << reg;
386} 389}
387 390
388static inline int
389temp_from_reg(u16 reg, s16 regval)
390{
391 if (is_word_sized(reg))
392 return LM75_TEMP_FROM_REG(regval);
393 return ((s8)regval) * 1000;
394}
395
396static inline u16
397temp_to_reg(u16 reg, long temp)
398{
399 if (is_word_sized(reg))
400 return LM75_TEMP_TO_REG(temp);
401 return (s8)DIV_ROUND_CLOSEST(SENSORS_LIMIT(temp, -127000, 128000),
402 1000);
403}
404
405/* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */ 391/* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */
406 392
407static u8 scale_in[10] = { 8, 8, 16, 16, 8, 8, 8, 16, 16, 8 }; 393static u8 scale_in[10] = { 8, 8, 16, 16, 8, 8, 8, 16, 16, 8 };
@@ -469,6 +455,7 @@ struct w83627ehf_data {
469 s16 temp_max[9]; 455 s16 temp_max[9];
470 s16 temp_max_hyst[9]; 456 s16 temp_max_hyst[9];
471 u32 alarms; 457 u32 alarms;
458 u8 caseopen;
472 459
473 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */ 460 u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */
474 u8 pwm_enable[4]; /* 1->manual 461 u8 pwm_enable[4]; /* 1->manual
@@ -557,6 +544,26 @@ static int w83627ehf_write_value(struct w83627ehf_data *data, u16 reg,
557 return 0; 544 return 0;
558} 545}
559 546
547/* We left-align 8-bit temperature values to make the code simpler */
548static u16 w83627ehf_read_temp(struct w83627ehf_data *data, u16 reg)
549{
550 u16 res;
551
552 res = w83627ehf_read_value(data, reg);
553 if (!is_word_sized(reg))
554 res <<= 8;
555
556 return res;
557}
558
559static int w83627ehf_write_temp(struct w83627ehf_data *data, u16 reg,
560 u16 value)
561{
562 if (!is_word_sized(reg))
563 value >>= 8;
564 return w83627ehf_write_value(data, reg, value);
565}
566
560/* This function assumes that the caller holds data->update_lock */ 567/* This function assumes that the caller holds data->update_lock */
561static void nct6775_write_fan_div(struct w83627ehf_data *data, int nr) 568static void nct6775_write_fan_div(struct w83627ehf_data *data, int nr)
562{ 569{
@@ -771,6 +778,9 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
771 778
772 /* Measured voltages and limits */ 779 /* Measured voltages and limits */
773 for (i = 0; i < data->in_num; i++) { 780 for (i = 0; i < data->in_num; i++) {
781 if ((i == 6) && data->in6_skip)
782 continue;
783
774 data->in[i] = w83627ehf_read_value(data, 784 data->in[i] = w83627ehf_read_value(data,
775 W83627EHF_REG_IN(i)); 785 W83627EHF_REG_IN(i));
776 data->in_min[i] = w83627ehf_read_value(data, 786 data->in_min[i] = w83627ehf_read_value(data,
@@ -855,15 +865,15 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
855 for (i = 0; i < NUM_REG_TEMP; i++) { 865 for (i = 0; i < NUM_REG_TEMP; i++) {
856 if (!(data->have_temp & (1 << i))) 866 if (!(data->have_temp & (1 << i)))
857 continue; 867 continue;
858 data->temp[i] = w83627ehf_read_value(data, 868 data->temp[i] = w83627ehf_read_temp(data,
859 data->reg_temp[i]); 869 data->reg_temp[i]);
860 if (data->reg_temp_over[i]) 870 if (data->reg_temp_over[i])
861 data->temp_max[i] 871 data->temp_max[i]
862 = w83627ehf_read_value(data, 872 = w83627ehf_read_temp(data,
863 data->reg_temp_over[i]); 873 data->reg_temp_over[i]);
864 if (data->reg_temp_hyst[i]) 874 if (data->reg_temp_hyst[i])
865 data->temp_max_hyst[i] 875 data->temp_max_hyst[i]
866 = w83627ehf_read_value(data, 876 = w83627ehf_read_temp(data,
867 data->reg_temp_hyst[i]); 877 data->reg_temp_hyst[i]);
868 } 878 }
869 879
@@ -874,6 +884,9 @@ static struct w83627ehf_data *w83627ehf_update_device(struct device *dev)
874 (w83627ehf_read_value(data, 884 (w83627ehf_read_value(data,
875 W83627EHF_REG_ALARM3) << 16); 885 W83627EHF_REG_ALARM3) << 16);
876 886
887 data->caseopen = w83627ehf_read_value(data,
888 W83627EHF_REG_CASEOPEN_DET);
889
877 data->last_updated = jiffies; 890 data->last_updated = jiffies;
878 data->valid = 1; 891 data->valid = 1;
879 } 892 }
@@ -1156,8 +1169,7 @@ show_##reg(struct device *dev, struct device_attribute *attr, \
1156 struct sensor_device_attribute *sensor_attr = \ 1169 struct sensor_device_attribute *sensor_attr = \
1157 to_sensor_dev_attr(attr); \ 1170 to_sensor_dev_attr(attr); \
1158 int nr = sensor_attr->index; \ 1171 int nr = sensor_attr->index; \
1159 return sprintf(buf, "%d\n", \ 1172 return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->reg[nr])); \
1160 temp_from_reg(data->addr[nr], data->reg[nr])); \
1161} 1173}
1162show_temp_reg(reg_temp, temp); 1174show_temp_reg(reg_temp, temp);
1163show_temp_reg(reg_temp_over, temp_max); 1175show_temp_reg(reg_temp_over, temp_max);
@@ -1178,9 +1190,8 @@ store_##reg(struct device *dev, struct device_attribute *attr, \
1178 if (err < 0) \ 1190 if (err < 0) \
1179 return err; \ 1191 return err; \
1180 mutex_lock(&data->update_lock); \ 1192 mutex_lock(&data->update_lock); \
1181 data->reg[nr] = temp_to_reg(data->addr[nr], val); \ 1193 data->reg[nr] = LM75_TEMP_TO_REG(val); \
1182 w83627ehf_write_value(data, data->addr[nr], \ 1194 w83627ehf_write_temp(data, data->addr[nr], data->reg[nr]); \
1183 data->reg[nr]); \
1184 mutex_unlock(&data->update_lock); \ 1195 mutex_unlock(&data->update_lock); \
1185 return count; \ 1196 return count; \
1186} 1197}
@@ -1655,6 +1666,48 @@ show_vid(struct device *dev, struct device_attribute *attr, char *buf)
1655} 1666}
1656static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); 1667static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
1657 1668
1669
1670/* Case open detection */
1671
1672static ssize_t
1673show_caseopen(struct device *dev, struct device_attribute *attr, char *buf)
1674{
1675 struct w83627ehf_data *data = w83627ehf_update_device(dev);
1676
1677 return sprintf(buf, "%d\n",
1678 !!(data->caseopen & to_sensor_dev_attr_2(attr)->index));
1679}
1680
1681static ssize_t
1682clear_caseopen(struct device *dev, struct device_attribute *attr,
1683 const char *buf, size_t count)
1684{
1685 struct w83627ehf_data *data = dev_get_drvdata(dev);
1686 unsigned long val;
1687 u16 reg, mask;
1688
1689 if (strict_strtoul(buf, 10, &val) || val != 0)
1690 return -EINVAL;
1691
1692 mask = to_sensor_dev_attr_2(attr)->nr;
1693
1694 mutex_lock(&data->update_lock);
1695 reg = w83627ehf_read_value(data, W83627EHF_REG_CASEOPEN_CLR);
1696 w83627ehf_write_value(data, W83627EHF_REG_CASEOPEN_CLR, reg | mask);
1697 w83627ehf_write_value(data, W83627EHF_REG_CASEOPEN_CLR, reg & ~mask);
1698 data->valid = 0; /* Force cache refresh */
1699 mutex_unlock(&data->update_lock);
1700
1701 return count;
1702}
1703
1704static struct sensor_device_attribute_2 sda_caseopen[] = {
1705 SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_caseopen,
1706 clear_caseopen, 0x80, 0x10),
1707 SENSOR_ATTR_2(intrusion1_alarm, S_IWUSR | S_IRUGO, show_caseopen,
1708 clear_caseopen, 0x40, 0x40),
1709};
1710
1658/* 1711/*
1659 * Driver and device management 1712 * Driver and device management
1660 */ 1713 */
@@ -1711,6 +1764,9 @@ static void w83627ehf_device_remove_files(struct device *dev)
1711 device_remove_file(dev, &sda_temp_type[i].dev_attr); 1764 device_remove_file(dev, &sda_temp_type[i].dev_attr);
1712 } 1765 }
1713 1766
1767 device_remove_file(dev, &sda_caseopen[0].dev_attr);
1768 device_remove_file(dev, &sda_caseopen[1].dev_attr);
1769
1714 device_remove_file(dev, &dev_attr_name); 1770 device_remove_file(dev, &dev_attr_name);
1715 device_remove_file(dev, &dev_attr_cpu0_vid); 1771 device_remove_file(dev, &dev_attr_cpu0_vid);
1716} 1772}
@@ -1789,13 +1845,78 @@ static void w82627ehf_swap_tempreg(struct w83627ehf_data *data,
1789 data->reg_temp_config[r2] = tmp; 1845 data->reg_temp_config[r2] = tmp;
1790} 1846}
1791 1847
1848static void __devinit
1849w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data,
1850 struct w83627ehf_data *data)
1851{
1852 int fan3pin, fan4pin, fan4min, fan5pin, regval;
1853
1854 superio_enter(sio_data->sioreg);
1855
1856 /* fan4 and fan5 share some pins with the GPIO and serial flash */
1857 if (sio_data->kind == nct6775) {
1858 /* On NCT6775, fan4 shares pins with the fdc interface */
1859 fan3pin = 1;
1860 fan4pin = !(superio_inb(sio_data->sioreg, 0x2A) & 0x80);
1861 fan4min = 0;
1862 fan5pin = 0;
1863 } else if (sio_data->kind == nct6776) {
1864 fan3pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x40);
1865 fan4pin = !!(superio_inb(sio_data->sioreg, 0x1C) & 0x01);
1866 fan5pin = !!(superio_inb(sio_data->sioreg, 0x1C) & 0x02);
1867 fan4min = fan4pin;
1868 } else if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
1869 fan3pin = 1;
1870 fan4pin = superio_inb(sio_data->sioreg, 0x27) & 0x40;
1871 fan5pin = superio_inb(sio_data->sioreg, 0x27) & 0x20;
1872 fan4min = fan4pin;
1873 } else {
1874 fan3pin = 1;
1875 fan4pin = !(superio_inb(sio_data->sioreg, 0x29) & 0x06);
1876 fan5pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x02);
1877 fan4min = fan4pin;
1878 }
1879
1880 superio_exit(sio_data->sioreg);
1881
1882 data->has_fan = data->has_fan_min = 0x03; /* fan1 and fan2 */
1883 data->has_fan |= (fan3pin << 2);
1884 data->has_fan_min |= (fan3pin << 2);
1885
1886 if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
1887 /*
1888 * NCT6775F and NCT6776F don't have the W83627EHF_REG_FANDIV1
1889 * register
1890 */
1891 data->has_fan |= (fan4pin << 3) | (fan5pin << 4);
1892 data->has_fan_min |= (fan4min << 3) | (fan5pin << 4);
1893 } else {
1894 /*
1895 * It looks like fan4 and fan5 pins can be alternatively used
1896 * as fan on/off switches, but fan5 control is write only :/
1897 * We assume that if the serial interface is disabled, designers
1898 * connected fan5 as input unless they are emitting log 1, which
1899 * is not the default.
1900 */
1901 regval = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1);
1902 if ((regval & (1 << 2)) && fan4pin) {
1903 data->has_fan |= (1 << 3);
1904 data->has_fan_min |= (1 << 3);
1905 }
1906 if (!(regval & (1 << 1)) && fan5pin) {
1907 data->has_fan |= (1 << 4);
1908 data->has_fan_min |= (1 << 4);
1909 }
1910 }
1911}
1912
1792static int __devinit w83627ehf_probe(struct platform_device *pdev) 1913static int __devinit w83627ehf_probe(struct platform_device *pdev)
1793{ 1914{
1794 struct device *dev = &pdev->dev; 1915 struct device *dev = &pdev->dev;
1795 struct w83627ehf_sio_data *sio_data = dev->platform_data; 1916 struct w83627ehf_sio_data *sio_data = dev->platform_data;
1796 struct w83627ehf_data *data; 1917 struct w83627ehf_data *data;
1797 struct resource *res; 1918 struct resource *res;
1798 u8 fan3pin, fan4pin, fan4min, fan5pin, en_vrm10; 1919 u8 en_vrm10;
1799 int i, err = 0; 1920 int i, err = 0;
1800 1921
1801 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 1922 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
@@ -2080,30 +2201,6 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2080 } 2201 }
2081 } 2202 }
2082 2203
2083 /* fan4 and fan5 share some pins with the GPIO and serial flash */
2084 if (sio_data->kind == nct6775) {
2085 /* On NCT6775, fan4 shares pins with the fdc interface */
2086 fan3pin = 1;
2087 fan4pin = !(superio_inb(sio_data->sioreg, 0x2A) & 0x80);
2088 fan4min = 0;
2089 fan5pin = 0;
2090 } else if (sio_data->kind == nct6776) {
2091 fan3pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x40);
2092 fan4pin = !!(superio_inb(sio_data->sioreg, 0x1C) & 0x01);
2093 fan5pin = !!(superio_inb(sio_data->sioreg, 0x1C) & 0x02);
2094 fan4min = fan4pin;
2095 } else if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) {
2096 fan3pin = 1;
2097 fan4pin = superio_inb(sio_data->sioreg, 0x27) & 0x40;
2098 fan5pin = superio_inb(sio_data->sioreg, 0x27) & 0x20;
2099 fan4min = fan4pin;
2100 } else {
2101 fan3pin = 1;
2102 fan4pin = !(superio_inb(sio_data->sioreg, 0x29) & 0x06);
2103 fan5pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x02);
2104 fan4min = fan4pin;
2105 }
2106
2107 if (fan_debounce && 2204 if (fan_debounce &&
2108 (sio_data->kind == nct6775 || sio_data->kind == nct6776)) { 2205 (sio_data->kind == nct6775 || sio_data->kind == nct6776)) {
2109 u8 tmp; 2206 u8 tmp;
@@ -2121,34 +2218,7 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2121 2218
2122 superio_exit(sio_data->sioreg); 2219 superio_exit(sio_data->sioreg);
2123 2220
2124 /* It looks like fan4 and fan5 pins can be alternatively used 2221 w83627ehf_check_fan_inputs(sio_data, data);
2125 as fan on/off switches, but fan5 control is write only :/
2126 We assume that if the serial interface is disabled, designers
2127 connected fan5 as input unless they are emitting log 1, which
2128 is not the default. */
2129
2130 data->has_fan = data->has_fan_min = 0x03; /* fan1 and fan2 */
2131
2132 data->has_fan |= (fan3pin << 2);
2133 data->has_fan_min |= (fan3pin << 2);
2134
2135 /*
2136 * NCT6775F and NCT6776F don't have the W83627EHF_REG_FANDIV1 register
2137 */
2138 if (sio_data->kind == nct6775 || sio_data->kind == nct6776) {
2139 data->has_fan |= (fan4pin << 3) | (fan5pin << 4);
2140 data->has_fan_min |= (fan4min << 3) | (fan5pin << 4);
2141 } else {
2142 i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1);
2143 if ((i & (1 << 2)) && fan4pin) {
2144 data->has_fan |= (1 << 3);
2145 data->has_fan_min |= (1 << 3);
2146 }
2147 if (!(i & (1 << 1)) && fan5pin) {
2148 data->has_fan |= (1 << 4);
2149 data->has_fan_min |= (1 << 4);
2150 }
2151 }
2152 2222
2153 /* Read fan clock dividers immediately */ 2223 /* Read fan clock dividers immediately */
2154 w83627ehf_update_fan_div_common(dev, data); 2224 w83627ehf_update_fan_div_common(dev, data);
@@ -2269,6 +2339,16 @@ static int __devinit w83627ehf_probe(struct platform_device *pdev)
2269 goto exit_remove; 2339 goto exit_remove;
2270 } 2340 }
2271 2341
2342 err = device_create_file(dev, &sda_caseopen[0].dev_attr);
2343 if (err)
2344 goto exit_remove;
2345
2346 if (sio_data->kind == nct6776) {
2347 err = device_create_file(dev, &sda_caseopen[1].dev_attr);
2348 if (err)
2349 goto exit_remove;
2350 }
2351
2272 err = device_create_file(dev, &dev_attr_name); 2352 err = device_create_file(dev, &dev_attr_name);
2273 if (err) 2353 if (err)
2274 goto exit_remove; 2354 goto exit_remove;