diff options
-rw-r--r-- | drivers/hwmon/it87.c | 162 |
1 files changed, 87 insertions, 75 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index d70c6ec31725..96306a6f844e 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -1,40 +1,40 @@ | |||
1 | /* | 1 | /* |
2 | it87.c - Part of lm_sensors, Linux kernel modules for hardware | 2 | * it87.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | monitoring. | 3 | * monitoring. |
4 | 4 | * | |
5 | The IT8705F is an LPC-based Super I/O part that contains UARTs, a | 5 | * The IT8705F is an LPC-based Super I/O part that contains UARTs, a |
6 | parallel port, an IR port, a MIDI port, a floppy controller, etc., in | 6 | * parallel port, an IR port, a MIDI port, a floppy controller, etc., in |
7 | addition to an Environment Controller (Enhanced Hardware Monitor and | 7 | * addition to an Environment Controller (Enhanced Hardware Monitor and |
8 | Fan Controller) | 8 | * Fan Controller) |
9 | 9 | * | |
10 | This driver supports only the Environment Controller in the IT8705F and | 10 | * This driver supports only the Environment Controller in the IT8705F and |
11 | similar parts. The other devices are supported by different drivers. | 11 | * similar parts. The other devices are supported by different drivers. |
12 | 12 | * | |
13 | Supports: IT8705F Super I/O chip w/LPC interface | 13 | * Supports: IT8705F Super I/O chip w/LPC interface |
14 | IT8712F Super I/O chip w/LPC interface | 14 | * IT8712F Super I/O chip w/LPC interface |
15 | IT8716F Super I/O chip w/LPC interface | 15 | * IT8716F Super I/O chip w/LPC interface |
16 | IT8718F Super I/O chip w/LPC interface | 16 | * IT8718F Super I/O chip w/LPC interface |
17 | IT8720F Super I/O chip w/LPC interface | 17 | * IT8720F Super I/O chip w/LPC interface |
18 | IT8726F Super I/O chip w/LPC interface | 18 | * IT8726F Super I/O chip w/LPC interface |
19 | Sis950 A clone of the IT8705F | 19 | * Sis950 A clone of the IT8705F |
20 | 20 | * | |
21 | Copyright (C) 2001 Chris Gauthron | 21 | * Copyright (C) 2001 Chris Gauthron |
22 | Copyright (C) 2005-2007 Jean Delvare <khali@linux-fr.org> | 22 | * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org> |
23 | 23 | * | |
24 | This program is free software; you can redistribute it and/or modify | 24 | * This program is free software; you can redistribute it and/or modify |
25 | it under the terms of the GNU General Public License as published by | 25 | * it under the terms of the GNU General Public License as published by |
26 | the Free Software Foundation; either version 2 of the License, or | 26 | * the Free Software Foundation; either version 2 of the License, or |
27 | (at your option) any later version. | 27 | * (at your option) any later version. |
28 | 28 | * | |
29 | This program is distributed in the hope that it will be useful, | 29 | * This program is distributed in the hope that it will be useful, |
30 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
31 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
32 | GNU General Public License for more details. | 32 | * GNU General Public License for more details. |
33 | 33 | * | |
34 | You should have received a copy of the GNU General Public License | 34 | * You should have received a copy of the GNU General Public License |
35 | along with this program; if not, write to the Free Software | 35 | * along with this program; if not, write to the Free Software |
36 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 36 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
37 | */ | 37 | */ |
38 | 38 | ||
39 | #include <linux/module.h> | 39 | #include <linux/module.h> |
40 | #include <linux/init.h> | 40 | #include <linux/init.h> |
@@ -494,8 +494,9 @@ static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, | |||
494 | int nr = sensor_attr->index; | 494 | int nr = sensor_attr->index; |
495 | 495 | ||
496 | struct it87_data *data = it87_update_device(dev); | 496 | struct it87_data *data = it87_update_device(dev); |
497 | u8 reg = data->sensor; /* In case the value is updated while we use it */ | 497 | u8 reg = data->sensor; /* In case the value is updated while |
498 | 498 | we use it */ | |
499 | |||
499 | if (reg & (1 << nr)) | 500 | if (reg & (1 << nr)) |
500 | return sprintf(buf, "3\n"); /* thermal diode */ | 501 | return sprintf(buf, "3\n"); /* thermal diode */ |
501 | if (reg & (8 << nr)) | 502 | if (reg & (8 << nr)) |
@@ -522,9 +523,9 @@ static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, | |||
522 | } | 523 | } |
523 | /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ | 524 | /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ |
524 | if (val == 3) | 525 | if (val == 3) |
525 | data->sensor |= 1 << nr; | 526 | data->sensor |= 1 << nr; |
526 | else if (val == 4) | 527 | else if (val == 4) |
527 | data->sensor |= 8 << nr; | 528 | data->sensor |= 8 << nr; |
528 | else if (val != 0) { | 529 | else if (val != 0) { |
529 | mutex_unlock(&data->update_lock); | 530 | mutex_unlock(&data->update_lock); |
530 | return -EINVAL; | 531 | return -EINVAL; |
@@ -562,7 +563,7 @@ static ssize_t show_fan(struct device *dev, struct device_attribute *attr, | |||
562 | int nr = sensor_attr->index; | 563 | int nr = sensor_attr->index; |
563 | 564 | ||
564 | struct it87_data *data = it87_update_device(dev); | 565 | struct it87_data *data = it87_update_device(dev); |
565 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], | 566 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
566 | DIV_FROM_REG(data->fan_div[nr]))); | 567 | DIV_FROM_REG(data->fan_div[nr]))); |
567 | } | 568 | } |
568 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, | 569 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
@@ -572,8 +573,8 @@ static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, | |||
572 | int nr = sensor_attr->index; | 573 | int nr = sensor_attr->index; |
573 | 574 | ||
574 | struct it87_data *data = it87_update_device(dev); | 575 | struct it87_data *data = it87_update_device(dev); |
575 | return sprintf(buf,"%d\n", | 576 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], |
576 | FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]))); | 577 | DIV_FROM_REG(data->fan_div[nr]))); |
577 | } | 578 | } |
578 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, | 579 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
579 | char *buf) | 580 | char *buf) |
@@ -584,8 +585,8 @@ static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, | |||
584 | struct it87_data *data = it87_update_device(dev); | 585 | struct it87_data *data = it87_update_device(dev); |
585 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); | 586 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); |
586 | } | 587 | } |
587 | static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, | 588 | static ssize_t show_pwm_enable(struct device *dev, |
588 | char *buf) | 589 | struct device_attribute *attr, char *buf) |
589 | { | 590 | { |
590 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 591 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
591 | int nr = sensor_attr->index; | 592 | int nr = sensor_attr->index; |
@@ -623,9 +624,15 @@ static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | |||
623 | mutex_lock(&data->update_lock); | 624 | mutex_lock(&data->update_lock); |
624 | reg = it87_read_value(data, IT87_REG_FAN_DIV); | 625 | reg = it87_read_value(data, IT87_REG_FAN_DIV); |
625 | switch (nr) { | 626 | switch (nr) { |
626 | case 0: data->fan_div[nr] = reg & 0x07; break; | 627 | case 0: |
627 | case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; | 628 | data->fan_div[nr] = reg & 0x07; |
628 | case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break; | 629 | break; |
630 | case 1: | ||
631 | data->fan_div[nr] = (reg >> 3) & 0x07; | ||
632 | break; | ||
633 | case 2: | ||
634 | data->fan_div[nr] = (reg & 0x40) ? 3 : 1; | ||
635 | break; | ||
629 | } | 636 | } |
630 | 637 | ||
631 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 638 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
@@ -696,7 +703,8 @@ static ssize_t set_pwm_enable(struct device *dev, | |||
696 | it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); | 703 | it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); |
697 | /* set on/off mode */ | 704 | /* set on/off mode */ |
698 | data->fan_main_ctrl &= ~(1 << nr); | 705 | data->fan_main_ctrl &= ~(1 << nr); |
699 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); | 706 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
707 | data->fan_main_ctrl); | ||
700 | } else { | 708 | } else { |
701 | if (val == 1) /* Manual mode */ | 709 | if (val == 1) /* Manual mode */ |
702 | data->pwm_ctrl[nr] = data->pwm_duty[nr]; | 710 | data->pwm_ctrl[nr] = data->pwm_duty[nr]; |
@@ -705,7 +713,8 @@ static ssize_t set_pwm_enable(struct device *dev, | |||
705 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); | 713 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); |
706 | /* set SmartGuardian mode */ | 714 | /* set SmartGuardian mode */ |
707 | data->fan_main_ctrl |= (1 << nr); | 715 | data->fan_main_ctrl |= (1 << nr); |
708 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); | 716 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
717 | data->fan_main_ctrl); | ||
709 | } | 718 | } |
710 | 719 | ||
711 | mutex_unlock(&data->update_lock); | 720 | mutex_unlock(&data->update_lock); |
@@ -892,7 +901,8 @@ show_fan16_offset(4); | |||
892 | show_fan16_offset(5); | 901 | show_fan16_offset(5); |
893 | 902 | ||
894 | /* Alarms */ | 903 | /* Alarms */ |
895 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 904 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, |
905 | char *buf) | ||
896 | { | 906 | { |
897 | struct it87_data *data = it87_update_device(dev); | 907 | struct it87_data *data = it87_update_device(dev); |
898 | return sprintf(buf, "%u\n", data->alarms); | 908 | return sprintf(buf, "%u\n", data->alarms); |
@@ -972,14 +982,14 @@ static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, | |||
972 | static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2); | 982 | static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2); |
973 | static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2); | 983 | static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2); |
974 | 984 | ||
975 | static ssize_t | 985 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, |
976 | show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) | 986 | char *buf) |
977 | { | 987 | { |
978 | struct it87_data *data = dev_get_drvdata(dev); | 988 | struct it87_data *data = dev_get_drvdata(dev); |
979 | return sprintf(buf, "%u\n", data->vrm); | 989 | return sprintf(buf, "%u\n", data->vrm); |
980 | } | 990 | } |
981 | static ssize_t | 991 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, |
982 | store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 992 | const char *buf, size_t count) |
983 | { | 993 | { |
984 | struct it87_data *data = dev_get_drvdata(dev); | 994 | struct it87_data *data = dev_get_drvdata(dev); |
985 | u32 val; | 995 | u32 val; |
@@ -991,8 +1001,8 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf | |||
991 | } | 1001 | } |
992 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); | 1002 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); |
993 | 1003 | ||
994 | static ssize_t | 1004 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, |
995 | show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) | 1005 | char *buf) |
996 | { | 1006 | { |
997 | struct it87_data *data = it87_update_device(dev); | 1007 | struct it87_data *data = it87_update_device(dev); |
998 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); | 1008 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); |
@@ -1375,7 +1385,8 @@ static int __devinit it87_probe(struct platform_device *pdev) | |||
1375 | goto ERROR0; | 1385 | goto ERROR0; |
1376 | } | 1386 | } |
1377 | 1387 | ||
1378 | if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) { | 1388 | data = kzalloc(sizeof(struct it87_data), GFP_KERNEL); |
1389 | if (!data) { | ||
1379 | err = -ENOMEM; | 1390 | err = -ENOMEM; |
1380 | goto ERROR1; | 1391 | goto ERROR1; |
1381 | } | 1392 | } |
@@ -1403,7 +1414,8 @@ static int __devinit it87_probe(struct platform_device *pdev) | |||
1403 | it87_init_device(pdev); | 1414 | it87_init_device(pdev); |
1404 | 1415 | ||
1405 | /* Register sysfs hooks */ | 1416 | /* Register sysfs hooks */ |
1406 | if ((err = sysfs_create_group(&dev->kobj, &it87_group))) | 1417 | err = sysfs_create_group(&dev->kobj, &it87_group); |
1418 | if (err) | ||
1407 | goto ERROR2; | 1419 | goto ERROR2; |
1408 | 1420 | ||
1409 | if (sio_data->beep_pin) { | 1421 | if (sio_data->beep_pin) { |
@@ -1623,7 +1635,8 @@ static void __devinit it87_init_device(struct platform_device *pdev) | |||
1623 | if ((data->fan_main_ctrl & mask) == 0) { | 1635 | if ((data->fan_main_ctrl & mask) == 0) { |
1624 | /* Enable all fan tachometers */ | 1636 | /* Enable all fan tachometers */ |
1625 | data->fan_main_ctrl |= mask; | 1637 | data->fan_main_ctrl |= mask; |
1626 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); | 1638 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
1639 | data->fan_main_ctrl); | ||
1627 | } | 1640 | } |
1628 | data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; | 1641 | data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; |
1629 | 1642 | ||
@@ -1672,24 +1685,22 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
1672 | 1685 | ||
1673 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 1686 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
1674 | || !data->valid) { | 1687 | || !data->valid) { |
1675 | |||
1676 | if (update_vbat) { | 1688 | if (update_vbat) { |
1677 | /* Cleared after each update, so reenable. Value | 1689 | /* Cleared after each update, so reenable. Value |
1678 | returned by this read will be previous value */ | 1690 | returned by this read will be previous value */ |
1679 | it87_write_value(data, IT87_REG_CONFIG, | 1691 | it87_write_value(data, IT87_REG_CONFIG, |
1680 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); | 1692 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); |
1681 | } | 1693 | } |
1682 | for (i = 0; i <= 7; i++) { | 1694 | for (i = 0; i <= 7; i++) { |
1683 | data->in[i] = | 1695 | data->in[i] = |
1684 | it87_read_value(data, IT87_REG_VIN(i)); | 1696 | it87_read_value(data, IT87_REG_VIN(i)); |
1685 | data->in_min[i] = | 1697 | data->in_min[i] = |
1686 | it87_read_value(data, IT87_REG_VIN_MIN(i)); | 1698 | it87_read_value(data, IT87_REG_VIN_MIN(i)); |
1687 | data->in_max[i] = | 1699 | data->in_max[i] = |
1688 | it87_read_value(data, IT87_REG_VIN_MAX(i)); | 1700 | it87_read_value(data, IT87_REG_VIN_MAX(i)); |
1689 | } | 1701 | } |
1690 | /* in8 (battery) has no limit registers */ | 1702 | /* in8 (battery) has no limit registers */ |
1691 | data->in[8] = | 1703 | data->in[8] = it87_read_value(data, IT87_REG_VIN(8)); |
1692 | it87_read_value(data, IT87_REG_VIN(8)); | ||
1693 | 1704 | ||
1694 | for (i = 0; i < 5; i++) { | 1705 | for (i = 0; i < 5; i++) { |
1695 | /* Skip disabled fans */ | 1706 | /* Skip disabled fans */ |
@@ -1697,7 +1708,7 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
1697 | continue; | 1708 | continue; |
1698 | 1709 | ||
1699 | data->fan_min[i] = | 1710 | data->fan_min[i] = |
1700 | it87_read_value(data, IT87_REG_FAN_MIN[i]); | 1711 | it87_read_value(data, IT87_REG_FAN_MIN[i]); |
1701 | data->fan[i] = it87_read_value(data, | 1712 | data->fan[i] = it87_read_value(data, |
1702 | IT87_REG_FAN[i]); | 1713 | IT87_REG_FAN[i]); |
1703 | /* Add high byte if in 16-bit mode */ | 1714 | /* Add high byte if in 16-bit mode */ |
@@ -1710,11 +1721,11 @@ static struct it87_data *it87_update_device(struct device *dev) | |||
1710 | } | 1721 | } |
1711 | for (i = 0; i < 3; i++) { | 1722 | for (i = 0; i < 3; i++) { |
1712 | data->temp[i] = | 1723 | data->temp[i] = |
1713 | it87_read_value(data, IT87_REG_TEMP(i)); | 1724 | it87_read_value(data, IT87_REG_TEMP(i)); |
1714 | data->temp_high[i] = | 1725 | data->temp_high[i] = |
1715 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); | 1726 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
1716 | data->temp_low[i] = | 1727 | data->temp_low[i] = |
1717 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); | 1728 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); |
1718 | } | 1729 | } |
1719 | 1730 | ||
1720 | /* Newer chips don't have clock dividers */ | 1731 | /* Newer chips don't have clock dividers */ |
@@ -1810,7 +1821,7 @@ exit: | |||
1810 | static int __init sm_it87_init(void) | 1821 | static int __init sm_it87_init(void) |
1811 | { | 1822 | { |
1812 | int err; | 1823 | int err; |
1813 | unsigned short isa_address=0; | 1824 | unsigned short isa_address = 0; |
1814 | struct it87_sio_data sio_data; | 1825 | struct it87_sio_data sio_data; |
1815 | 1826 | ||
1816 | memset(&sio_data, 0, sizeof(struct it87_sio_data)); | 1827 | memset(&sio_data, 0, sizeof(struct it87_sio_data)); |
@@ -1822,7 +1833,7 @@ static int __init sm_it87_init(void) | |||
1822 | return err; | 1833 | return err; |
1823 | 1834 | ||
1824 | err = it87_device_add(isa_address, &sio_data); | 1835 | err = it87_device_add(isa_address, &sio_data); |
1825 | if (err){ | 1836 | if (err) { |
1826 | platform_driver_unregister(&it87_driver); | 1837 | platform_driver_unregister(&it87_driver); |
1827 | return err; | 1838 | return err; |
1828 | } | 1839 | } |
@@ -1843,7 +1854,8 @@ MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver"); | |||
1843 | module_param(update_vbat, bool, 0); | 1854 | module_param(update_vbat, bool, 0); |
1844 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); | 1855 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); |
1845 | module_param(fix_pwm_polarity, bool, 0); | 1856 | module_param(fix_pwm_polarity, bool, 0); |
1846 | MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)"); | 1857 | MODULE_PARM_DESC(fix_pwm_polarity, |
1858 | "Force PWM polarity to active high (DANGEROUS)"); | ||
1847 | MODULE_LICENSE("GPL"); | 1859 | MODULE_LICENSE("GPL"); |
1848 | 1860 | ||
1849 | module_init(sm_it87_init); | 1861 | module_init(sm_it87_init); |