aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/it87.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/it87.c')
-rw-r--r--drivers/hwmon/it87.c469
1 files changed, 363 insertions, 106 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index b0ee57492228..323ef06719c1 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -4,10 +4,12 @@
4 4
5 Supports: IT8705F Super I/O chip w/LPC interface 5 Supports: IT8705F Super I/O chip w/LPC interface
6 IT8712F Super I/O chip w/LPC interface & SMBus 6 IT8712F Super I/O chip w/LPC interface & SMBus
7 IT8716F Super I/O chip w/LPC interface
8 IT8718F Super I/O chip w/LPC interface
7 Sis950 A clone of the IT8705F 9 Sis950 A clone of the IT8705F
8 10
9 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> 11 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com>
10 Largely inspired by lm78.c of the same package 12 Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
11 13
12 This program is free software; you can redistribute it and/or modify 14 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by 15 it under the terms of the GNU General Public License as published by
@@ -24,13 +26,6 @@
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25*/ 27*/
26 28
27/*
28 djg@pdp8.net David Gesswein 7/18/01
29 Modified to fix bug with not all alarms enabled.
30 Added ability to read battery voltage and select temperature sensor
31 type at module load time.
32*/
33
34#include <linux/module.h> 29#include <linux/module.h>
35#include <linux/init.h> 30#include <linux/init.h>
36#include <linux/slab.h> 31#include <linux/slab.h>
@@ -42,6 +37,7 @@
42#include <linux/hwmon-vid.h> 37#include <linux/hwmon-vid.h>
43#include <linux/err.h> 38#include <linux/err.h>
44#include <linux/mutex.h> 39#include <linux/mutex.h>
40#include <linux/sysfs.h>
45#include <asm/io.h> 41#include <asm/io.h>
46 42
47 43
@@ -50,12 +46,13 @@ static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
50static unsigned short isa_address; 46static unsigned short isa_address;
51 47
52/* Insmod parameters */ 48/* Insmod parameters */
53I2C_CLIENT_INSMOD_2(it87, it8712); 49I2C_CLIENT_INSMOD_4(it87, it8712, it8716, it8718);
54 50
55#define REG 0x2e /* The register to read/write */ 51#define REG 0x2e /* The register to read/write */
56#define DEV 0x07 /* Register: Logical device select */ 52#define DEV 0x07 /* Register: Logical device select */
57#define VAL 0x2f /* The value to read/write */ 53#define VAL 0x2f /* The value to read/write */
58#define PME 0x04 /* The device with the fan registers in it */ 54#define PME 0x04 /* The device with the fan registers in it */
55#define GPIO 0x07 /* The device with the IT8718F VID value in it */
59#define DEVID 0x20 /* Register: Device ID */ 56#define DEVID 0x20 /* Register: Device ID */
60#define DEVREV 0x22 /* Register: Device Revision */ 57#define DEVREV 0x22 /* Register: Device Revision */
61 58
@@ -77,10 +74,10 @@ static int superio_inw(int reg)
77} 74}
78 75
79static inline void 76static inline void
80superio_select(void) 77superio_select(int ldn)
81{ 78{
82 outb(DEV, REG); 79 outb(DEV, REG);
83 outb(PME, VAL); 80 outb(ldn, VAL);
84} 81}
85 82
86static inline void 83static inline void
@@ -99,20 +96,27 @@ superio_exit(void)
99 outb(0x02, VAL); 96 outb(0x02, VAL);
100} 97}
101 98
99/* Logical device 4 registers */
102#define IT8712F_DEVID 0x8712 100#define IT8712F_DEVID 0x8712
103#define IT8705F_DEVID 0x8705 101#define IT8705F_DEVID 0x8705
102#define IT8716F_DEVID 0x8716
103#define IT8718F_DEVID 0x8718
104#define IT87_ACT_REG 0x30 104#define IT87_ACT_REG 0x30
105#define IT87_BASE_REG 0x60 105#define IT87_BASE_REG 0x60
106 106
107/* Logical device 7 registers (IT8712F and later) */
108#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
109#define IT87_SIO_VID_REG 0xfc /* VID value */
110
107/* Update battery voltage after every reading if true */ 111/* Update battery voltage after every reading if true */
108static int update_vbat; 112static int update_vbat;
109 113
110/* Not all BIOSes properly configure the PWM registers */ 114/* Not all BIOSes properly configure the PWM registers */
111static int fix_pwm_polarity; 115static int fix_pwm_polarity;
112 116
113/* Chip Type */ 117/* Values read from Super-I/O config space */
114
115static u16 chip_type; 118static u16 chip_type;
119static u8 vid_value;
116 120
117/* Many IT87 constants specified below */ 121/* Many IT87 constants specified below */
118 122
@@ -131,13 +135,21 @@ static u16 chip_type;
131#define IT87_REG_ALARM2 0x02 135#define IT87_REG_ALARM2 0x02
132#define IT87_REG_ALARM3 0x03 136#define IT87_REG_ALARM3 0x03
133 137
138/* The IT8718F has the VID value in a different register, in Super-I/O
139 configuration space. */
134#define IT87_REG_VID 0x0a 140#define IT87_REG_VID 0x0a
141/* Warning: register 0x0b is used for something completely different in
142 new chips/revisions. I suspect only 16-bit tachometer mode will work
143 for these. */
135#define IT87_REG_FAN_DIV 0x0b 144#define IT87_REG_FAN_DIV 0x0b
145#define IT87_REG_FAN_16BIT 0x0c
136 146
137/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */ 147/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
138 148
139#define IT87_REG_FAN(nr) (0x0d + (nr)) 149#define IT87_REG_FAN(nr) (0x0d + (nr))
140#define IT87_REG_FAN_MIN(nr) (0x10 + (nr)) 150#define IT87_REG_FAN_MIN(nr) (0x10 + (nr))
151#define IT87_REG_FANX(nr) (0x18 + (nr))
152#define IT87_REG_FANX_MIN(nr) (0x1b + (nr))
141#define IT87_REG_FAN_MAIN_CTRL 0x13 153#define IT87_REG_FAN_MAIN_CTRL 0x13
142#define IT87_REG_FAN_CTL 0x14 154#define IT87_REG_FAN_CTL 0x14
143#define IT87_REG_PWM(nr) (0x15 + (nr)) 155#define IT87_REG_PWM(nr) (0x15 + (nr))
@@ -169,7 +181,16 @@ static inline u8 FAN_TO_REG(long rpm, int div)
169 254); 181 254);
170} 182}
171 183
184static inline u16 FAN16_TO_REG(long rpm)
185{
186 if (rpm == 0)
187 return 0xffff;
188 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
189}
190
172#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) 191#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
192/* The divider is fixed to 2 in 16-bit mode */
193#define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
173 194
174#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\ 195#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
175 ((val)+500)/1000),-128,127)) 196 ((val)+500)/1000),-128,127))
@@ -181,7 +202,7 @@ static inline u8 FAN_TO_REG(long rpm, int div)
181static int DIV_TO_REG(int val) 202static int DIV_TO_REG(int val)
182{ 203{
183 int answer = 0; 204 int answer = 0;
184 while ((val >>= 1) != 0) 205 while (answer < 7 && (val >>= 1))
185 answer++; 206 answer++;
186 return answer; 207 return answer;
187} 208}
@@ -203,10 +224,11 @@ struct it87_data {
203 unsigned long last_updated; /* In jiffies */ 224 unsigned long last_updated; /* In jiffies */
204 225
205 u8 in[9]; /* Register value */ 226 u8 in[9]; /* Register value */
206 u8 in_max[9]; /* Register value */ 227 u8 in_max[8]; /* Register value */
207 u8 in_min[9]; /* Register value */ 228 u8 in_min[8]; /* Register value */
208 u8 fan[3]; /* Register value */ 229 u8 has_fan; /* Bitfield, fans enabled */
209 u8 fan_min[3]; /* Register value */ 230 u16 fan[3]; /* Register values, possibly combined */
231 u16 fan_min[3]; /* Register values, possibly combined */
210 u8 temp[3]; /* Register value */ 232 u8 temp[3]; /* Register value */
211 u8 temp_high[3]; /* Register value */ 233 u8 temp_high[3]; /* Register value */
212 u8 temp_low[3]; /* Register value */ 234 u8 temp_low[3]; /* Register value */
@@ -545,15 +567,15 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
545 567
546 struct i2c_client *client = to_i2c_client(dev); 568 struct i2c_client *client = to_i2c_client(dev);
547 struct it87_data *data = i2c_get_clientdata(client); 569 struct it87_data *data = i2c_get_clientdata(client);
548 int val = simple_strtol(buf, NULL, 10); 570 unsigned long val = simple_strtoul(buf, NULL, 10);
549 int i, min[3]; 571 int min;
550 u8 old; 572 u8 old;
551 573
552 mutex_lock(&data->update_lock); 574 mutex_lock(&data->update_lock);
553 old = it87_read_value(client, IT87_REG_FAN_DIV); 575 old = it87_read_value(client, IT87_REG_FAN_DIV);
554 576
555 for (i = 0; i < 3; i++) 577 /* Save fan min limit */
556 min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i])); 578 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
557 579
558 switch (nr) { 580 switch (nr) {
559 case 0: 581 case 0:
@@ -573,10 +595,10 @@ static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
573 val |= 0x1 << 6; 595 val |= 0x1 << 6;
574 it87_write_value(client, IT87_REG_FAN_DIV, val); 596 it87_write_value(client, IT87_REG_FAN_DIV, val);
575 597
576 for (i = 0; i < 3; i++) { 598 /* Restore fan min limit */
577 data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); 599 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
578 it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]); 600 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
579 } 601
580 mutex_unlock(&data->update_lock); 602 mutex_unlock(&data->update_lock);
581 return count; 603 return count;
582} 604}
@@ -657,6 +679,59 @@ show_pwm_offset(1);
657show_pwm_offset(2); 679show_pwm_offset(2);
658show_pwm_offset(3); 680show_pwm_offset(3);
659 681
682/* A different set of callbacks for 16-bit fans */
683static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
684 char *buf)
685{
686 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
687 int nr = sensor_attr->index;
688 struct it87_data *data = it87_update_device(dev);
689 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
690}
691
692static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
693 char *buf)
694{
695 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
696 int nr = sensor_attr->index;
697 struct it87_data *data = it87_update_device(dev);
698 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
699}
700
701static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
702 const char *buf, size_t count)
703{
704 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
705 int nr = sensor_attr->index;
706 struct i2c_client *client = to_i2c_client(dev);
707 struct it87_data *data = i2c_get_clientdata(client);
708 int val = simple_strtol(buf, NULL, 10);
709
710 mutex_lock(&data->update_lock);
711 data->fan_min[nr] = FAN16_TO_REG(val);
712 it87_write_value(client, IT87_REG_FAN_MIN(nr),
713 data->fan_min[nr] & 0xff);
714 it87_write_value(client, IT87_REG_FANX_MIN(nr),
715 data->fan_min[nr] >> 8);
716 mutex_unlock(&data->update_lock);
717 return count;
718}
719
720/* We want to use the same sysfs file names as 8-bit fans, but we need
721 different variable names, so we have to use SENSOR_ATTR instead of
722 SENSOR_DEVICE_ATTR. */
723#define show_fan16_offset(offset) \
724static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
725 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
726 show_fan16, NULL, offset - 1); \
727static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
728 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
729 show_fan16_min, set_fan16_min, offset - 1)
730
731show_fan16_offset(1);
732show_fan16_offset(2);
733show_fan16_offset(3);
734
660/* Alarms */ 735/* Alarms */
661static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) 736static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
662{ 737{
@@ -684,8 +759,6 @@ store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf
684 return count; 759 return count;
685} 760}
686static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); 761static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
687#define device_create_file_vrm(client) \
688device_create_file(&client->dev, &dev_attr_vrm)
689 762
690static ssize_t 763static ssize_t
691show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) 764show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
@@ -694,8 +767,88 @@ show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
694 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); 767 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
695} 768}
696static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); 769static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
697#define device_create_file_vid(client) \ 770
698device_create_file(&client->dev, &dev_attr_cpu0_vid) 771static struct attribute *it87_attributes[] = {
772 &sensor_dev_attr_in0_input.dev_attr.attr,
773 &sensor_dev_attr_in1_input.dev_attr.attr,
774 &sensor_dev_attr_in2_input.dev_attr.attr,
775 &sensor_dev_attr_in3_input.dev_attr.attr,
776 &sensor_dev_attr_in4_input.dev_attr.attr,
777 &sensor_dev_attr_in5_input.dev_attr.attr,
778 &sensor_dev_attr_in6_input.dev_attr.attr,
779 &sensor_dev_attr_in7_input.dev_attr.attr,
780 &sensor_dev_attr_in8_input.dev_attr.attr,
781 &sensor_dev_attr_in0_min.dev_attr.attr,
782 &sensor_dev_attr_in1_min.dev_attr.attr,
783 &sensor_dev_attr_in2_min.dev_attr.attr,
784 &sensor_dev_attr_in3_min.dev_attr.attr,
785 &sensor_dev_attr_in4_min.dev_attr.attr,
786 &sensor_dev_attr_in5_min.dev_attr.attr,
787 &sensor_dev_attr_in6_min.dev_attr.attr,
788 &sensor_dev_attr_in7_min.dev_attr.attr,
789 &sensor_dev_attr_in0_max.dev_attr.attr,
790 &sensor_dev_attr_in1_max.dev_attr.attr,
791 &sensor_dev_attr_in2_max.dev_attr.attr,
792 &sensor_dev_attr_in3_max.dev_attr.attr,
793 &sensor_dev_attr_in4_max.dev_attr.attr,
794 &sensor_dev_attr_in5_max.dev_attr.attr,
795 &sensor_dev_attr_in6_max.dev_attr.attr,
796 &sensor_dev_attr_in7_max.dev_attr.attr,
797
798 &sensor_dev_attr_temp1_input.dev_attr.attr,
799 &sensor_dev_attr_temp2_input.dev_attr.attr,
800 &sensor_dev_attr_temp3_input.dev_attr.attr,
801 &sensor_dev_attr_temp1_max.dev_attr.attr,
802 &sensor_dev_attr_temp2_max.dev_attr.attr,
803 &sensor_dev_attr_temp3_max.dev_attr.attr,
804 &sensor_dev_attr_temp1_min.dev_attr.attr,
805 &sensor_dev_attr_temp2_min.dev_attr.attr,
806 &sensor_dev_attr_temp3_min.dev_attr.attr,
807 &sensor_dev_attr_temp1_type.dev_attr.attr,
808 &sensor_dev_attr_temp2_type.dev_attr.attr,
809 &sensor_dev_attr_temp3_type.dev_attr.attr,
810
811 &dev_attr_alarms.attr,
812 NULL
813};
814
815static const struct attribute_group it87_group = {
816 .attrs = it87_attributes,
817};
818
819static struct attribute *it87_attributes_opt[] = {
820 &sensor_dev_attr_fan1_input16.dev_attr.attr,
821 &sensor_dev_attr_fan1_min16.dev_attr.attr,
822 &sensor_dev_attr_fan2_input16.dev_attr.attr,
823 &sensor_dev_attr_fan2_min16.dev_attr.attr,
824 &sensor_dev_attr_fan3_input16.dev_attr.attr,
825 &sensor_dev_attr_fan3_min16.dev_attr.attr,
826
827 &sensor_dev_attr_fan1_input.dev_attr.attr,
828 &sensor_dev_attr_fan1_min.dev_attr.attr,
829 &sensor_dev_attr_fan1_div.dev_attr.attr,
830 &sensor_dev_attr_fan2_input.dev_attr.attr,
831 &sensor_dev_attr_fan2_min.dev_attr.attr,
832 &sensor_dev_attr_fan2_div.dev_attr.attr,
833 &sensor_dev_attr_fan3_input.dev_attr.attr,
834 &sensor_dev_attr_fan3_min.dev_attr.attr,
835 &sensor_dev_attr_fan3_div.dev_attr.attr,
836
837 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
838 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
839 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
840 &sensor_dev_attr_pwm1.dev_attr.attr,
841 &sensor_dev_attr_pwm2.dev_attr.attr,
842 &sensor_dev_attr_pwm3.dev_attr.attr,
843
844 &dev_attr_vrm.attr,
845 &dev_attr_cpu0_vid.attr,
846 NULL
847};
848
849static const struct attribute_group it87_group_opt = {
850 .attrs = it87_attributes_opt,
851};
699 852
700/* This function is called when: 853/* This function is called when:
701 * it87_driver is inserted (when this module is loaded), for each 854 * it87_driver is inserted (when this module is loaded), for each
@@ -721,10 +874,12 @@ static int __init it87_find(unsigned short *address)
721 superio_enter(); 874 superio_enter();
722 chip_type = superio_inw(DEVID); 875 chip_type = superio_inw(DEVID);
723 if (chip_type != IT8712F_DEVID 876 if (chip_type != IT8712F_DEVID
877 && chip_type != IT8716F_DEVID
878 && chip_type != IT8718F_DEVID
724 && chip_type != IT8705F_DEVID) 879 && chip_type != IT8705F_DEVID)
725 goto exit; 880 goto exit;
726 881
727 superio_select(); 882 superio_select(PME);
728 if (!(superio_inb(IT87_ACT_REG) & 0x01)) { 883 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
729 pr_info("it87: Device not activated, skipping\n"); 884 pr_info("it87: Device not activated, skipping\n");
730 goto exit; 885 goto exit;
@@ -740,6 +895,21 @@ static int __init it87_find(unsigned short *address)
740 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", 895 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
741 chip_type, *address, superio_inb(DEVREV) & 0x0f); 896 chip_type, *address, superio_inb(DEVREV) & 0x0f);
742 897
898 /* Read GPIO config and VID value from LDN 7 (GPIO) */
899 if (chip_type != IT8705F_DEVID) {
900 int reg;
901
902 superio_select(GPIO);
903 if (chip_type == it8718)
904 vid_value = superio_inb(IT87_SIO_VID_REG);
905
906 reg = superio_inb(IT87_SIO_PINX2_REG);
907 if (reg & (1 << 0))
908 pr_info("it87: in3 is VCC (+5V)\n");
909 if (reg & (1 << 1))
910 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
911 }
912
743exit: 913exit:
744 superio_exit(); 914 superio_exit();
745 return err; 915 return err;
@@ -800,8 +970,19 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
800 i = it87_read_value(new_client, IT87_REG_CHIPID); 970 i = it87_read_value(new_client, IT87_REG_CHIPID);
801 if (i == 0x90) { 971 if (i == 0x90) {
802 kind = it87; 972 kind = it87;
803 if ((is_isa) && (chip_type == IT8712F_DEVID)) 973 if (is_isa) {
804 kind = it8712; 974 switch (chip_type) {
975 case IT8712F_DEVID:
976 kind = it8712;
977 break;
978 case IT8716F_DEVID:
979 kind = it8716;
980 break;
981 case IT8718F_DEVID:
982 kind = it8718;
983 break;
984 }
985 }
805 } 986 }
806 else { 987 else {
807 if (kind == 0) 988 if (kind == 0)
@@ -818,6 +999,10 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
818 name = "it87"; 999 name = "it87";
819 } else if (kind == it8712) { 1000 } else if (kind == it8712) {
820 name = "it8712"; 1001 name = "it8712";
1002 } else if (kind == it8716) {
1003 name = "it8716";
1004 } else if (kind == it8718) {
1005 name = "it8718";
821 } 1006 }
822 1007
823 /* Fill in the remaining client fields and put it into the global list */ 1008 /* Fill in the remaining client fields and put it into the global list */
@@ -842,76 +1027,103 @@ static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
842 it87_init_client(new_client, data); 1027 it87_init_client(new_client, data);
843 1028
844 /* Register sysfs hooks */ 1029 /* Register sysfs hooks */
845 data->class_dev = hwmon_device_register(&new_client->dev); 1030 if ((err = sysfs_create_group(&new_client->dev.kobj, &it87_group)))
846 if (IS_ERR(data->class_dev)) {
847 err = PTR_ERR(data->class_dev);
848 goto ERROR3; 1031 goto ERROR3;
1032
1033 /* Do not create fan files for disabled fans */
1034 if (data->type == it8716 || data->type == it8718) {
1035 /* 16-bit tachometers */
1036 if (data->has_fan & (1 << 0)) {
1037 if ((err = device_create_file(&new_client->dev,
1038 &sensor_dev_attr_fan1_input16.dev_attr))
1039 || (err = device_create_file(&new_client->dev,
1040 &sensor_dev_attr_fan1_min16.dev_attr)))
1041 goto ERROR4;
1042 }
1043 if (data->has_fan & (1 << 1)) {
1044 if ((err = device_create_file(&new_client->dev,
1045 &sensor_dev_attr_fan2_input16.dev_attr))
1046 || (err = device_create_file(&new_client->dev,
1047 &sensor_dev_attr_fan2_min16.dev_attr)))
1048 goto ERROR4;
1049 }
1050 if (data->has_fan & (1 << 2)) {
1051 if ((err = device_create_file(&new_client->dev,
1052 &sensor_dev_attr_fan3_input16.dev_attr))
1053 || (err = device_create_file(&new_client->dev,
1054 &sensor_dev_attr_fan3_min16.dev_attr)))
1055 goto ERROR4;
1056 }
1057 } else {
1058 /* 8-bit tachometers with clock divider */
1059 if (data->has_fan & (1 << 0)) {
1060 if ((err = device_create_file(&new_client->dev,
1061 &sensor_dev_attr_fan1_input.dev_attr))
1062 || (err = device_create_file(&new_client->dev,
1063 &sensor_dev_attr_fan1_min.dev_attr))
1064 || (err = device_create_file(&new_client->dev,
1065 &sensor_dev_attr_fan1_div.dev_attr)))
1066 goto ERROR4;
1067 }
1068 if (data->has_fan & (1 << 1)) {
1069 if ((err = device_create_file(&new_client->dev,
1070 &sensor_dev_attr_fan2_input.dev_attr))
1071 || (err = device_create_file(&new_client->dev,
1072 &sensor_dev_attr_fan2_min.dev_attr))
1073 || (err = device_create_file(&new_client->dev,
1074 &sensor_dev_attr_fan2_div.dev_attr)))
1075 goto ERROR4;
1076 }
1077 if (data->has_fan & (1 << 2)) {
1078 if ((err = device_create_file(&new_client->dev,
1079 &sensor_dev_attr_fan3_input.dev_attr))
1080 || (err = device_create_file(&new_client->dev,
1081 &sensor_dev_attr_fan3_min.dev_attr))
1082 || (err = device_create_file(&new_client->dev,
1083 &sensor_dev_attr_fan3_div.dev_attr)))
1084 goto ERROR4;
1085 }
849 } 1086 }
850 1087
851 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
852 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
853 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
854 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr);
855 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr);
856 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr);
857 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr);
858 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr);
859 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr);
860 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
861 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
862 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
863 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
864 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
865 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
866 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
867 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
868 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
869 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
870 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
871 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
872 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
873 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
874 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
875 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
876 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr);
877 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr);
878 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
879 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr);
880 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr);
881 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
882 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr);
883 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr);
884 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
885 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_type.dev_attr);
886 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_type.dev_attr);
887 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_type.dev_attr);
888 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr);
889 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_input.dev_attr);
890 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_input.dev_attr);
891 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_min.dev_attr);
892 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_min.dev_attr);
893 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_min.dev_attr);
894 device_create_file(&new_client->dev, &sensor_dev_attr_fan1_div.dev_attr);
895 device_create_file(&new_client->dev, &sensor_dev_attr_fan2_div.dev_attr);
896 device_create_file(&new_client->dev, &sensor_dev_attr_fan3_div.dev_attr);
897 device_create_file(&new_client->dev, &dev_attr_alarms);
898 if (enable_pwm_interface) { 1088 if (enable_pwm_interface) {
899 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1_enable.dev_attr); 1089 if ((err = device_create_file(&new_client->dev,
900 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2_enable.dev_attr); 1090 &sensor_dev_attr_pwm1_enable.dev_attr))
901 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3_enable.dev_attr); 1091 || (err = device_create_file(&new_client->dev,
902 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr); 1092 &sensor_dev_attr_pwm2_enable.dev_attr))
903 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr); 1093 || (err = device_create_file(&new_client->dev,
904 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr); 1094 &sensor_dev_attr_pwm3_enable.dev_attr))
1095 || (err = device_create_file(&new_client->dev,
1096 &sensor_dev_attr_pwm1.dev_attr))
1097 || (err = device_create_file(&new_client->dev,
1098 &sensor_dev_attr_pwm2.dev_attr))
1099 || (err = device_create_file(&new_client->dev,
1100 &sensor_dev_attr_pwm3.dev_attr)))
1101 goto ERROR4;
905 } 1102 }
906 1103
907 if (data->type == it8712) { 1104 if (data->type == it8712 || data->type == it8716
1105 || data->type == it8718) {
908 data->vrm = vid_which_vrm(); 1106 data->vrm = vid_which_vrm();
909 device_create_file_vrm(new_client); 1107 /* VID reading from Super-I/O config space if available */
910 device_create_file_vid(new_client); 1108 data->vid = vid_value;
1109 if ((err = device_create_file(&new_client->dev,
1110 &dev_attr_vrm))
1111 || (err = device_create_file(&new_client->dev,
1112 &dev_attr_cpu0_vid)))
1113 goto ERROR4;
1114 }
1115
1116 data->class_dev = hwmon_device_register(&new_client->dev);
1117 if (IS_ERR(data->class_dev)) {
1118 err = PTR_ERR(data->class_dev);
1119 goto ERROR4;
911 } 1120 }
912 1121
913 return 0; 1122 return 0;
914 1123
1124ERROR4:
1125 sysfs_remove_group(&new_client->dev.kobj, &it87_group);
1126 sysfs_remove_group(&new_client->dev.kobj, &it87_group_opt);
915ERROR3: 1127ERROR3:
916 i2c_detach_client(new_client); 1128 i2c_detach_client(new_client);
917ERROR2: 1129ERROR2:
@@ -929,6 +1141,8 @@ static int it87_detach_client(struct i2c_client *client)
929 int err; 1141 int err;
930 1142
931 hwmon_device_unregister(data->class_dev); 1143 hwmon_device_unregister(data->class_dev);
1144 sysfs_remove_group(&client->dev.kobj, &it87_group);
1145 sysfs_remove_group(&client->dev.kobj, &it87_group_opt);
932 1146
933 if ((err = i2c_detach_client(client))) 1147 if ((err = i2c_detach_client(client)))
934 return err; 1148 return err;
@@ -1045,6 +1259,22 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1045 data->manual_pwm_ctl[i] = 0xff; 1259 data->manual_pwm_ctl[i] = 0xff;
1046 } 1260 }
1047 1261
1262 /* Some chips seem to have default value 0xff for all limit
1263 * registers. For low voltage limits it makes no sense and triggers
1264 * alarms, so change to 0 instead. For high temperature limits, it
1265 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1266 * but is still confusing, so change to 127 degrees C. */
1267 for (i = 0; i < 8; i++) {
1268 tmp = it87_read_value(client, IT87_REG_VIN_MIN(i));
1269 if (tmp == 0xff)
1270 it87_write_value(client, IT87_REG_VIN_MIN(i), 0);
1271 }
1272 for (i = 0; i < 3; i++) {
1273 tmp = it87_read_value(client, IT87_REG_TEMP_HIGH(i));
1274 if (tmp == 0xff)
1275 it87_write_value(client, IT87_REG_TEMP_HIGH(i), 127);
1276 }
1277
1048 /* Check if temperature channnels are reset manually or by some reason */ 1278 /* Check if temperature channnels are reset manually or by some reason */
1049 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1279 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1050 if ((tmp & 0x3f) == 0) { 1280 if ((tmp & 0x3f) == 0) {
@@ -1068,6 +1298,18 @@ static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1068 data->fan_main_ctrl |= 0x70; 1298 data->fan_main_ctrl |= 0x70;
1069 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); 1299 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
1070 } 1300 }
1301 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
1302
1303 /* Set tachometers to 16-bit mode if needed */
1304 if (data->type == it8716 || data->type == it8718) {
1305 tmp = it87_read_value(client, IT87_REG_FAN_16BIT);
1306 if (~tmp & 0x07 & data->has_fan) {
1307 dev_dbg(&client->dev,
1308 "Setting fan1-3 to 16-bit mode\n");
1309 it87_write_value(client, IT87_REG_FAN_16BIT,
1310 tmp | 0x07);
1311 }
1312 }
1071 1313
1072 /* Set current fan mode registers and the default settings for the 1314 /* Set current fan mode registers and the default settings for the
1073 * other mode registers */ 1315 * other mode registers */
@@ -1118,18 +1360,26 @@ static struct it87_data *it87_update_device(struct device *dev)
1118 data->in_max[i] = 1360 data->in_max[i] =
1119 it87_read_value(client, IT87_REG_VIN_MAX(i)); 1361 it87_read_value(client, IT87_REG_VIN_MAX(i));
1120 } 1362 }
1363 /* in8 (battery) has no limit registers */
1121 data->in[8] = 1364 data->in[8] =
1122 it87_read_value(client, IT87_REG_VIN(8)); 1365 it87_read_value(client, IT87_REG_VIN(8));
1123 /* Temperature sensor doesn't have limit registers, set
1124 to min and max value */
1125 data->in_min[8] = 0;
1126 data->in_max[8] = 255;
1127 1366
1128 for (i = 0; i < 3; i++) { 1367 for (i = 0; i < 3; i++) {
1129 data->fan[i] = 1368 /* Skip disabled fans */
1130 it87_read_value(client, IT87_REG_FAN(i)); 1369 if (!(data->has_fan & (1 << i)))
1370 continue;
1371
1131 data->fan_min[i] = 1372 data->fan_min[i] =
1132 it87_read_value(client, IT87_REG_FAN_MIN(i)); 1373 it87_read_value(client, IT87_REG_FAN_MIN(i));
1374 data->fan[i] = it87_read_value(client,
1375 IT87_REG_FAN(i));
1376 /* Add high byte if in 16-bit mode */
1377 if (data->type == it8716 || data->type == it8718) {
1378 data->fan[i] |= it87_read_value(client,
1379 IT87_REG_FANX(i)) << 8;
1380 data->fan_min[i] |= it87_read_value(client,
1381 IT87_REG_FANX_MIN(i)) << 8;
1382 }
1133 } 1383 }
1134 for (i = 0; i < 3; i++) { 1384 for (i = 0; i < 3; i++) {
1135 data->temp[i] = 1385 data->temp[i] =
@@ -1140,10 +1390,14 @@ static struct it87_data *it87_update_device(struct device *dev)
1140 it87_read_value(client, IT87_REG_TEMP_LOW(i)); 1390 it87_read_value(client, IT87_REG_TEMP_LOW(i));
1141 } 1391 }
1142 1392
1143 i = it87_read_value(client, IT87_REG_FAN_DIV); 1393 /* Newer chips don't have clock dividers */
1144 data->fan_div[0] = i & 0x07; 1394 if ((data->has_fan & 0x07) && data->type != it8716
1145 data->fan_div[1] = (i >> 3) & 0x07; 1395 && data->type != it8718) {
1146 data->fan_div[2] = (i & 0x40) ? 3 : 1; 1396 i = it87_read_value(client, IT87_REG_FAN_DIV);
1397 data->fan_div[0] = i & 0x07;
1398 data->fan_div[1] = (i >> 3) & 0x07;
1399 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1400 }
1147 1401
1148 data->alarms = 1402 data->alarms =
1149 it87_read_value(client, IT87_REG_ALARM1) | 1403 it87_read_value(client, IT87_REG_ALARM1) |
@@ -1153,9 +1407,11 @@ static struct it87_data *it87_update_device(struct device *dev)
1153 1407
1154 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); 1408 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1155 /* The 8705 does not have VID capability */ 1409 /* The 8705 does not have VID capability */
1156 if (data->type == it8712) { 1410 if (data->type == it8712 || data->type == it8716) {
1157 data->vid = it87_read_value(client, IT87_REG_VID); 1411 data->vid = it87_read_value(client, IT87_REG_VID);
1158 data->vid &= 0x1f; 1412 /* The older IT8712F revisions had only 5 VID pins,
1413 but we assume it is always safe to read 6 bits. */
1414 data->vid &= 0x3f;
1159 } 1415 }
1160 data->last_updated = jiffies; 1416 data->last_updated = jiffies;
1161 data->valid = 1; 1417 data->valid = 1;
@@ -1193,8 +1449,9 @@ static void __exit sm_it87_exit(void)
1193} 1449}
1194 1450
1195 1451
1196MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>"); 1452MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, "
1197MODULE_DESCRIPTION("IT8705F, IT8712F, Sis950 driver"); 1453 "Jean Delvare <khali@linux-fr.org>");
1454MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F, SiS950 driver");
1198module_param(update_vbat, bool, 0); 1455module_param(update_vbat, bool, 0);
1199MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); 1456MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1200module_param(fix_pwm_polarity, bool, 0); 1457module_param(fix_pwm_polarity, bool, 0);