Commit a7be58a126d4cd9f0588df23f58796ed996c1835
Committed by
Greg Kroah-Hartman
1 parent
734a12a366
Exists in
master
and in
7 other branches
[PATCH] hwmon: it87 use u8 for vrm
VRM values fit in u8 by design now. Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Showing 1 changed file with 2 additions and 2 deletions Inline Diff
drivers/hwmon/it87.c
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 | 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 | Sis950 A clone of the IT8705F | 7 | Sis950 A clone of the IT8705F |
8 | 8 | ||
9 | Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> | 9 | Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> |
10 | Largely inspired by lm78.c of the same package | 10 | Largely inspired by lm78.c of the same package |
11 | 11 | ||
12 | This program is free software; you can redistribute it and/or modify | 12 | 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 | 13 | it under the terms of the GNU General Public License as published by |
14 | the Free Software Foundation; either version 2 of the License, or | 14 | the Free Software Foundation; either version 2 of the License, or |
15 | (at your option) any later version. | 15 | (at your option) any later version. |
16 | 16 | ||
17 | This program is distributed in the hope that it will be useful, | 17 | This program is distributed in the hope that it will be useful, |
18 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | GNU General Public License for more details. | 20 | GNU General Public License for more details. |
21 | 21 | ||
22 | You should have received a copy of the GNU General Public License | 22 | You should have received a copy of the GNU General Public License |
23 | along with this program; if not, write to the Free Software | 23 | along with this program; if not, write to the Free Software |
24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
25 | */ | 25 | */ |
26 | 26 | ||
27 | /* | 27 | /* |
28 | djg@pdp8.net David Gesswein 7/18/01 | 28 | djg@pdp8.net David Gesswein 7/18/01 |
29 | Modified to fix bug with not all alarms enabled. | 29 | Modified to fix bug with not all alarms enabled. |
30 | Added ability to read battery voltage and select temperature sensor | 30 | Added ability to read battery voltage and select temperature sensor |
31 | type at module load time. | 31 | type at module load time. |
32 | */ | 32 | */ |
33 | 33 | ||
34 | #include <linux/module.h> | 34 | #include <linux/module.h> |
35 | #include <linux/init.h> | 35 | #include <linux/init.h> |
36 | #include <linux/slab.h> | 36 | #include <linux/slab.h> |
37 | #include <linux/jiffies.h> | 37 | #include <linux/jiffies.h> |
38 | #include <linux/i2c.h> | 38 | #include <linux/i2c.h> |
39 | #include <linux/i2c-isa.h> | 39 | #include <linux/i2c-isa.h> |
40 | #include <linux/hwmon.h> | 40 | #include <linux/hwmon.h> |
41 | #include <linux/hwmon-sysfs.h> | 41 | #include <linux/hwmon-sysfs.h> |
42 | #include <linux/hwmon-vid.h> | 42 | #include <linux/hwmon-vid.h> |
43 | #include <linux/err.h> | 43 | #include <linux/err.h> |
44 | #include <asm/io.h> | 44 | #include <asm/io.h> |
45 | 45 | ||
46 | 46 | ||
47 | /* Addresses to scan */ | 47 | /* Addresses to scan */ |
48 | static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, | 48 | static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, |
49 | 0x2e, 0x2f, I2C_CLIENT_END }; | 49 | 0x2e, 0x2f, I2C_CLIENT_END }; |
50 | static unsigned short isa_address; | 50 | static unsigned short isa_address; |
51 | 51 | ||
52 | /* Insmod parameters */ | 52 | /* Insmod parameters */ |
53 | I2C_CLIENT_INSMOD_2(it87, it8712); | 53 | I2C_CLIENT_INSMOD_2(it87, it8712); |
54 | 54 | ||
55 | #define REG 0x2e /* The register to read/write */ | 55 | #define REG 0x2e /* The register to read/write */ |
56 | #define DEV 0x07 /* Register: Logical device select */ | 56 | #define DEV 0x07 /* Register: Logical device select */ |
57 | #define VAL 0x2f /* The value to read/write */ | 57 | #define VAL 0x2f /* The value to read/write */ |
58 | #define PME 0x04 /* The device with the fan registers in it */ | 58 | #define PME 0x04 /* The device with the fan registers in it */ |
59 | #define DEVID 0x20 /* Register: Device ID */ | 59 | #define DEVID 0x20 /* Register: Device ID */ |
60 | #define DEVREV 0x22 /* Register: Device Revision */ | 60 | #define DEVREV 0x22 /* Register: Device Revision */ |
61 | 61 | ||
62 | static inline int | 62 | static inline int |
63 | superio_inb(int reg) | 63 | superio_inb(int reg) |
64 | { | 64 | { |
65 | outb(reg, REG); | 65 | outb(reg, REG); |
66 | return inb(VAL); | 66 | return inb(VAL); |
67 | } | 67 | } |
68 | 68 | ||
69 | static int superio_inw(int reg) | 69 | static int superio_inw(int reg) |
70 | { | 70 | { |
71 | int val; | 71 | int val; |
72 | outb(reg++, REG); | 72 | outb(reg++, REG); |
73 | val = inb(VAL) << 8; | 73 | val = inb(VAL) << 8; |
74 | outb(reg, REG); | 74 | outb(reg, REG); |
75 | val |= inb(VAL); | 75 | val |= inb(VAL); |
76 | return val; | 76 | return val; |
77 | } | 77 | } |
78 | 78 | ||
79 | static inline void | 79 | static inline void |
80 | superio_select(void) | 80 | superio_select(void) |
81 | { | 81 | { |
82 | outb(DEV, REG); | 82 | outb(DEV, REG); |
83 | outb(PME, VAL); | 83 | outb(PME, VAL); |
84 | } | 84 | } |
85 | 85 | ||
86 | static inline void | 86 | static inline void |
87 | superio_enter(void) | 87 | superio_enter(void) |
88 | { | 88 | { |
89 | outb(0x87, REG); | 89 | outb(0x87, REG); |
90 | outb(0x01, REG); | 90 | outb(0x01, REG); |
91 | outb(0x55, REG); | 91 | outb(0x55, REG); |
92 | outb(0x55, REG); | 92 | outb(0x55, REG); |
93 | } | 93 | } |
94 | 94 | ||
95 | static inline void | 95 | static inline void |
96 | superio_exit(void) | 96 | superio_exit(void) |
97 | { | 97 | { |
98 | outb(0x02, REG); | 98 | outb(0x02, REG); |
99 | outb(0x02, VAL); | 99 | outb(0x02, VAL); |
100 | } | 100 | } |
101 | 101 | ||
102 | #define IT8712F_DEVID 0x8712 | 102 | #define IT8712F_DEVID 0x8712 |
103 | #define IT8705F_DEVID 0x8705 | 103 | #define IT8705F_DEVID 0x8705 |
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 | /* Update battery voltage after every reading if true */ | 107 | /* Update battery voltage after every reading if true */ |
108 | static int update_vbat; | 108 | static int update_vbat; |
109 | 109 | ||
110 | /* Not all BIOSes properly configure the PWM registers */ | 110 | /* Not all BIOSes properly configure the PWM registers */ |
111 | static int fix_pwm_polarity; | 111 | static int fix_pwm_polarity; |
112 | 112 | ||
113 | /* Chip Type */ | 113 | /* Chip Type */ |
114 | 114 | ||
115 | static u16 chip_type; | 115 | static u16 chip_type; |
116 | 116 | ||
117 | /* Many IT87 constants specified below */ | 117 | /* Many IT87 constants specified below */ |
118 | 118 | ||
119 | /* Length of ISA address segment */ | 119 | /* Length of ISA address segment */ |
120 | #define IT87_EXTENT 8 | 120 | #define IT87_EXTENT 8 |
121 | 121 | ||
122 | /* Where are the ISA address/data registers relative to the base address */ | 122 | /* Where are the ISA address/data registers relative to the base address */ |
123 | #define IT87_ADDR_REG_OFFSET 5 | 123 | #define IT87_ADDR_REG_OFFSET 5 |
124 | #define IT87_DATA_REG_OFFSET 6 | 124 | #define IT87_DATA_REG_OFFSET 6 |
125 | 125 | ||
126 | /*----- The IT87 registers -----*/ | 126 | /*----- The IT87 registers -----*/ |
127 | 127 | ||
128 | #define IT87_REG_CONFIG 0x00 | 128 | #define IT87_REG_CONFIG 0x00 |
129 | 129 | ||
130 | #define IT87_REG_ALARM1 0x01 | 130 | #define IT87_REG_ALARM1 0x01 |
131 | #define IT87_REG_ALARM2 0x02 | 131 | #define IT87_REG_ALARM2 0x02 |
132 | #define IT87_REG_ALARM3 0x03 | 132 | #define IT87_REG_ALARM3 0x03 |
133 | 133 | ||
134 | #define IT87_REG_VID 0x0a | 134 | #define IT87_REG_VID 0x0a |
135 | #define IT87_REG_FAN_DIV 0x0b | 135 | #define IT87_REG_FAN_DIV 0x0b |
136 | 136 | ||
137 | /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */ | 137 | /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */ |
138 | 138 | ||
139 | #define IT87_REG_FAN(nr) (0x0d + (nr)) | 139 | #define IT87_REG_FAN(nr) (0x0d + (nr)) |
140 | #define IT87_REG_FAN_MIN(nr) (0x10 + (nr)) | 140 | #define IT87_REG_FAN_MIN(nr) (0x10 + (nr)) |
141 | #define IT87_REG_FAN_MAIN_CTRL 0x13 | 141 | #define IT87_REG_FAN_MAIN_CTRL 0x13 |
142 | #define IT87_REG_FAN_CTL 0x14 | 142 | #define IT87_REG_FAN_CTL 0x14 |
143 | #define IT87_REG_PWM(nr) (0x15 + (nr)) | 143 | #define IT87_REG_PWM(nr) (0x15 + (nr)) |
144 | 144 | ||
145 | #define IT87_REG_VIN(nr) (0x20 + (nr)) | 145 | #define IT87_REG_VIN(nr) (0x20 + (nr)) |
146 | #define IT87_REG_TEMP(nr) (0x29 + (nr)) | 146 | #define IT87_REG_TEMP(nr) (0x29 + (nr)) |
147 | 147 | ||
148 | #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2) | 148 | #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2) |
149 | #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2) | 149 | #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2) |
150 | #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) | 150 | #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) |
151 | #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) | 151 | #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) |
152 | 152 | ||
153 | #define IT87_REG_I2C_ADDR 0x48 | 153 | #define IT87_REG_I2C_ADDR 0x48 |
154 | 154 | ||
155 | #define IT87_REG_VIN_ENABLE 0x50 | 155 | #define IT87_REG_VIN_ENABLE 0x50 |
156 | #define IT87_REG_TEMP_ENABLE 0x51 | 156 | #define IT87_REG_TEMP_ENABLE 0x51 |
157 | 157 | ||
158 | #define IT87_REG_CHIPID 0x58 | 158 | #define IT87_REG_CHIPID 0x58 |
159 | 159 | ||
160 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) | 160 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) |
161 | #define IN_FROM_REG(val) ((val) * 16) | 161 | #define IN_FROM_REG(val) ((val) * 16) |
162 | 162 | ||
163 | static inline u8 FAN_TO_REG(long rpm, int div) | 163 | static inline u8 FAN_TO_REG(long rpm, int div) |
164 | { | 164 | { |
165 | if (rpm == 0) | 165 | if (rpm == 0) |
166 | return 255; | 166 | return 255; |
167 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | 167 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
168 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, | 168 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, |
169 | 254); | 169 | 254); |
170 | } | 170 | } |
171 | 171 | ||
172 | #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) | 172 | #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) |
173 | 173 | ||
174 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\ | 174 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\ |
175 | ((val)+500)/1000),-128,127)) | 175 | ((val)+500)/1000),-128,127)) |
176 | #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000) | 176 | #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000) |
177 | 177 | ||
178 | #define PWM_TO_REG(val) ((val) >> 1) | 178 | #define PWM_TO_REG(val) ((val) >> 1) |
179 | #define PWM_FROM_REG(val) (((val)&0x7f) << 1) | 179 | #define PWM_FROM_REG(val) (((val)&0x7f) << 1) |
180 | 180 | ||
181 | static int DIV_TO_REG(int val) | 181 | static int DIV_TO_REG(int val) |
182 | { | 182 | { |
183 | int answer = 0; | 183 | int answer = 0; |
184 | while ((val >>= 1) != 0) | 184 | while ((val >>= 1) != 0) |
185 | answer++; | 185 | answer++; |
186 | return answer; | 186 | return answer; |
187 | } | 187 | } |
188 | #define DIV_FROM_REG(val) (1 << (val)) | 188 | #define DIV_FROM_REG(val) (1 << (val)) |
189 | 189 | ||
190 | 190 | ||
191 | /* For each registered IT87, we need to keep some data in memory. That | 191 | /* For each registered IT87, we need to keep some data in memory. That |
192 | data is pointed to by it87_list[NR]->data. The structure itself is | 192 | data is pointed to by it87_list[NR]->data. The structure itself is |
193 | dynamically allocated, at the same time when a new it87 client is | 193 | dynamically allocated, at the same time when a new it87 client is |
194 | allocated. */ | 194 | allocated. */ |
195 | struct it87_data { | 195 | struct it87_data { |
196 | struct i2c_client client; | 196 | struct i2c_client client; |
197 | struct class_device *class_dev; | 197 | struct class_device *class_dev; |
198 | struct semaphore lock; | 198 | struct semaphore lock; |
199 | enum chips type; | 199 | enum chips type; |
200 | 200 | ||
201 | struct semaphore update_lock; | 201 | struct semaphore update_lock; |
202 | char valid; /* !=0 if following fields are valid */ | 202 | char valid; /* !=0 if following fields are valid */ |
203 | unsigned long last_updated; /* In jiffies */ | 203 | unsigned long last_updated; /* In jiffies */ |
204 | 204 | ||
205 | u8 in[9]; /* Register value */ | 205 | u8 in[9]; /* Register value */ |
206 | u8 in_max[9]; /* Register value */ | 206 | u8 in_max[9]; /* Register value */ |
207 | u8 in_min[9]; /* Register value */ | 207 | u8 in_min[9]; /* Register value */ |
208 | u8 fan[3]; /* Register value */ | 208 | u8 fan[3]; /* Register value */ |
209 | u8 fan_min[3]; /* Register value */ | 209 | u8 fan_min[3]; /* Register value */ |
210 | u8 temp[3]; /* Register value */ | 210 | u8 temp[3]; /* Register value */ |
211 | u8 temp_high[3]; /* Register value */ | 211 | u8 temp_high[3]; /* Register value */ |
212 | u8 temp_low[3]; /* Register value */ | 212 | u8 temp_low[3]; /* Register value */ |
213 | u8 sensor; /* Register value */ | 213 | u8 sensor; /* Register value */ |
214 | u8 fan_div[3]; /* Register encoding, shifted right */ | 214 | u8 fan_div[3]; /* Register encoding, shifted right */ |
215 | u8 vid; /* Register encoding, combined */ | 215 | u8 vid; /* Register encoding, combined */ |
216 | int vrm; | 216 | u8 vrm; |
217 | u32 alarms; /* Register encoding, combined */ | 217 | u32 alarms; /* Register encoding, combined */ |
218 | u8 fan_main_ctrl; /* Register value */ | 218 | u8 fan_main_ctrl; /* Register value */ |
219 | u8 manual_pwm_ctl[3]; /* manual PWM value set by user */ | 219 | u8 manual_pwm_ctl[3]; /* manual PWM value set by user */ |
220 | }; | 220 | }; |
221 | 221 | ||
222 | 222 | ||
223 | static int it87_attach_adapter(struct i2c_adapter *adapter); | 223 | static int it87_attach_adapter(struct i2c_adapter *adapter); |
224 | static int it87_isa_attach_adapter(struct i2c_adapter *adapter); | 224 | static int it87_isa_attach_adapter(struct i2c_adapter *adapter); |
225 | static int it87_detect(struct i2c_adapter *adapter, int address, int kind); | 225 | static int it87_detect(struct i2c_adapter *adapter, int address, int kind); |
226 | static int it87_detach_client(struct i2c_client *client); | 226 | static int it87_detach_client(struct i2c_client *client); |
227 | 227 | ||
228 | static int it87_read_value(struct i2c_client *client, u8 register); | 228 | static int it87_read_value(struct i2c_client *client, u8 register); |
229 | static int it87_write_value(struct i2c_client *client, u8 register, | 229 | static int it87_write_value(struct i2c_client *client, u8 register, |
230 | u8 value); | 230 | u8 value); |
231 | static struct it87_data *it87_update_device(struct device *dev); | 231 | static struct it87_data *it87_update_device(struct device *dev); |
232 | static int it87_check_pwm(struct i2c_client *client); | 232 | static int it87_check_pwm(struct i2c_client *client); |
233 | static void it87_init_client(struct i2c_client *client, struct it87_data *data); | 233 | static void it87_init_client(struct i2c_client *client, struct it87_data *data); |
234 | 234 | ||
235 | 235 | ||
236 | static struct i2c_driver it87_driver = { | 236 | static struct i2c_driver it87_driver = { |
237 | .driver = { | 237 | .driver = { |
238 | .name = "it87", | 238 | .name = "it87", |
239 | }, | 239 | }, |
240 | .id = I2C_DRIVERID_IT87, | 240 | .id = I2C_DRIVERID_IT87, |
241 | .attach_adapter = it87_attach_adapter, | 241 | .attach_adapter = it87_attach_adapter, |
242 | .detach_client = it87_detach_client, | 242 | .detach_client = it87_detach_client, |
243 | }; | 243 | }; |
244 | 244 | ||
245 | static struct i2c_driver it87_isa_driver = { | 245 | static struct i2c_driver it87_isa_driver = { |
246 | .driver = { | 246 | .driver = { |
247 | .name = "it87-isa", | 247 | .name = "it87-isa", |
248 | }, | 248 | }, |
249 | .attach_adapter = it87_isa_attach_adapter, | 249 | .attach_adapter = it87_isa_attach_adapter, |
250 | .detach_client = it87_detach_client, | 250 | .detach_client = it87_detach_client, |
251 | }; | 251 | }; |
252 | 252 | ||
253 | 253 | ||
254 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, | 254 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
255 | char *buf) | 255 | char *buf) |
256 | { | 256 | { |
257 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 257 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
258 | int nr = sensor_attr->index; | 258 | int nr = sensor_attr->index; |
259 | 259 | ||
260 | struct it87_data *data = it87_update_device(dev); | 260 | struct it87_data *data = it87_update_device(dev); |
261 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); | 261 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); |
262 | } | 262 | } |
263 | 263 | ||
264 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, | 264 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
265 | char *buf) | 265 | char *buf) |
266 | { | 266 | { |
267 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 267 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
268 | int nr = sensor_attr->index; | 268 | int nr = sensor_attr->index; |
269 | 269 | ||
270 | struct it87_data *data = it87_update_device(dev); | 270 | struct it87_data *data = it87_update_device(dev); |
271 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); | 271 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); |
272 | } | 272 | } |
273 | 273 | ||
274 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, | 274 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, |
275 | char *buf) | 275 | char *buf) |
276 | { | 276 | { |
277 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 277 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
278 | int nr = sensor_attr->index; | 278 | int nr = sensor_attr->index; |
279 | 279 | ||
280 | struct it87_data *data = it87_update_device(dev); | 280 | struct it87_data *data = it87_update_device(dev); |
281 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); | 281 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); |
282 | } | 282 | } |
283 | 283 | ||
284 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, | 284 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
285 | const char *buf, size_t count) | 285 | const char *buf, size_t count) |
286 | { | 286 | { |
287 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 287 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
288 | int nr = sensor_attr->index; | 288 | int nr = sensor_attr->index; |
289 | 289 | ||
290 | struct i2c_client *client = to_i2c_client(dev); | 290 | struct i2c_client *client = to_i2c_client(dev); |
291 | struct it87_data *data = i2c_get_clientdata(client); | 291 | struct it87_data *data = i2c_get_clientdata(client); |
292 | unsigned long val = simple_strtoul(buf, NULL, 10); | 292 | unsigned long val = simple_strtoul(buf, NULL, 10); |
293 | 293 | ||
294 | down(&data->update_lock); | 294 | down(&data->update_lock); |
295 | data->in_min[nr] = IN_TO_REG(val); | 295 | data->in_min[nr] = IN_TO_REG(val); |
296 | it87_write_value(client, IT87_REG_VIN_MIN(nr), | 296 | it87_write_value(client, IT87_REG_VIN_MIN(nr), |
297 | data->in_min[nr]); | 297 | data->in_min[nr]); |
298 | up(&data->update_lock); | 298 | up(&data->update_lock); |
299 | return count; | 299 | return count; |
300 | } | 300 | } |
301 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, | 301 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
302 | const char *buf, size_t count) | 302 | const char *buf, size_t count) |
303 | { | 303 | { |
304 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 304 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
305 | int nr = sensor_attr->index; | 305 | int nr = sensor_attr->index; |
306 | 306 | ||
307 | struct i2c_client *client = to_i2c_client(dev); | 307 | struct i2c_client *client = to_i2c_client(dev); |
308 | struct it87_data *data = i2c_get_clientdata(client); | 308 | struct it87_data *data = i2c_get_clientdata(client); |
309 | unsigned long val = simple_strtoul(buf, NULL, 10); | 309 | unsigned long val = simple_strtoul(buf, NULL, 10); |
310 | 310 | ||
311 | down(&data->update_lock); | 311 | down(&data->update_lock); |
312 | data->in_max[nr] = IN_TO_REG(val); | 312 | data->in_max[nr] = IN_TO_REG(val); |
313 | it87_write_value(client, IT87_REG_VIN_MAX(nr), | 313 | it87_write_value(client, IT87_REG_VIN_MAX(nr), |
314 | data->in_max[nr]); | 314 | data->in_max[nr]); |
315 | up(&data->update_lock); | 315 | up(&data->update_lock); |
316 | return count; | 316 | return count; |
317 | } | 317 | } |
318 | 318 | ||
319 | #define show_in_offset(offset) \ | 319 | #define show_in_offset(offset) \ |
320 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ | 320 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
321 | show_in, NULL, offset); | 321 | show_in, NULL, offset); |
322 | 322 | ||
323 | #define limit_in_offset(offset) \ | 323 | #define limit_in_offset(offset) \ |
324 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ | 324 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
325 | show_in_min, set_in_min, offset); \ | 325 | show_in_min, set_in_min, offset); \ |
326 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | 326 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
327 | show_in_max, set_in_max, offset); | 327 | show_in_max, set_in_max, offset); |
328 | 328 | ||
329 | show_in_offset(0); | 329 | show_in_offset(0); |
330 | limit_in_offset(0); | 330 | limit_in_offset(0); |
331 | show_in_offset(1); | 331 | show_in_offset(1); |
332 | limit_in_offset(1); | 332 | limit_in_offset(1); |
333 | show_in_offset(2); | 333 | show_in_offset(2); |
334 | limit_in_offset(2); | 334 | limit_in_offset(2); |
335 | show_in_offset(3); | 335 | show_in_offset(3); |
336 | limit_in_offset(3); | 336 | limit_in_offset(3); |
337 | show_in_offset(4); | 337 | show_in_offset(4); |
338 | limit_in_offset(4); | 338 | limit_in_offset(4); |
339 | show_in_offset(5); | 339 | show_in_offset(5); |
340 | limit_in_offset(5); | 340 | limit_in_offset(5); |
341 | show_in_offset(6); | 341 | show_in_offset(6); |
342 | limit_in_offset(6); | 342 | limit_in_offset(6); |
343 | show_in_offset(7); | 343 | show_in_offset(7); |
344 | limit_in_offset(7); | 344 | limit_in_offset(7); |
345 | show_in_offset(8); | 345 | show_in_offset(8); |
346 | 346 | ||
347 | /* 3 temperatures */ | 347 | /* 3 temperatures */ |
348 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, | 348 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
349 | char *buf) | 349 | char *buf) |
350 | { | 350 | { |
351 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 351 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
352 | int nr = sensor_attr->index; | 352 | int nr = sensor_attr->index; |
353 | 353 | ||
354 | struct it87_data *data = it87_update_device(dev); | 354 | struct it87_data *data = it87_update_device(dev); |
355 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); | 355 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); |
356 | } | 356 | } |
357 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, | 357 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
358 | char *buf) | 358 | char *buf) |
359 | { | 359 | { |
360 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 360 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
361 | int nr = sensor_attr->index; | 361 | int nr = sensor_attr->index; |
362 | 362 | ||
363 | struct it87_data *data = it87_update_device(dev); | 363 | struct it87_data *data = it87_update_device(dev); |
364 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); | 364 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); |
365 | } | 365 | } |
366 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, | 366 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
367 | char *buf) | 367 | char *buf) |
368 | { | 368 | { |
369 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 369 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
370 | int nr = sensor_attr->index; | 370 | int nr = sensor_attr->index; |
371 | 371 | ||
372 | struct it87_data *data = it87_update_device(dev); | 372 | struct it87_data *data = it87_update_device(dev); |
373 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])); | 373 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])); |
374 | } | 374 | } |
375 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, | 375 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
376 | const char *buf, size_t count) | 376 | const char *buf, size_t count) |
377 | { | 377 | { |
378 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 378 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
379 | int nr = sensor_attr->index; | 379 | int nr = sensor_attr->index; |
380 | 380 | ||
381 | struct i2c_client *client = to_i2c_client(dev); | 381 | struct i2c_client *client = to_i2c_client(dev); |
382 | struct it87_data *data = i2c_get_clientdata(client); | 382 | struct it87_data *data = i2c_get_clientdata(client); |
383 | int val = simple_strtol(buf, NULL, 10); | 383 | int val = simple_strtol(buf, NULL, 10); |
384 | 384 | ||
385 | down(&data->update_lock); | 385 | down(&data->update_lock); |
386 | data->temp_high[nr] = TEMP_TO_REG(val); | 386 | data->temp_high[nr] = TEMP_TO_REG(val); |
387 | it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); | 387 | it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); |
388 | up(&data->update_lock); | 388 | up(&data->update_lock); |
389 | return count; | 389 | return count; |
390 | } | 390 | } |
391 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, | 391 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
392 | const char *buf, size_t count) | 392 | const char *buf, size_t count) |
393 | { | 393 | { |
394 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 394 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
395 | int nr = sensor_attr->index; | 395 | int nr = sensor_attr->index; |
396 | 396 | ||
397 | struct i2c_client *client = to_i2c_client(dev); | 397 | struct i2c_client *client = to_i2c_client(dev); |
398 | struct it87_data *data = i2c_get_clientdata(client); | 398 | struct it87_data *data = i2c_get_clientdata(client); |
399 | int val = simple_strtol(buf, NULL, 10); | 399 | int val = simple_strtol(buf, NULL, 10); |
400 | 400 | ||
401 | down(&data->update_lock); | 401 | down(&data->update_lock); |
402 | data->temp_low[nr] = TEMP_TO_REG(val); | 402 | data->temp_low[nr] = TEMP_TO_REG(val); |
403 | it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); | 403 | it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); |
404 | up(&data->update_lock); | 404 | up(&data->update_lock); |
405 | return count; | 405 | return count; |
406 | } | 406 | } |
407 | #define show_temp_offset(offset) \ | 407 | #define show_temp_offset(offset) \ |
408 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ | 408 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
409 | show_temp, NULL, offset - 1); \ | 409 | show_temp, NULL, offset - 1); \ |
410 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ | 410 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
411 | show_temp_max, set_temp_max, offset - 1); \ | 411 | show_temp_max, set_temp_max, offset - 1); \ |
412 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ | 412 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
413 | show_temp_min, set_temp_min, offset - 1); | 413 | show_temp_min, set_temp_min, offset - 1); |
414 | 414 | ||
415 | show_temp_offset(1); | 415 | show_temp_offset(1); |
416 | show_temp_offset(2); | 416 | show_temp_offset(2); |
417 | show_temp_offset(3); | 417 | show_temp_offset(3); |
418 | 418 | ||
419 | static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, | 419 | static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, |
420 | char *buf) | 420 | char *buf) |
421 | { | 421 | { |
422 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 422 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
423 | int nr = sensor_attr->index; | 423 | int nr = sensor_attr->index; |
424 | 424 | ||
425 | struct it87_data *data = it87_update_device(dev); | 425 | struct it87_data *data = it87_update_device(dev); |
426 | u8 reg = data->sensor; /* In case the value is updated while we use it */ | 426 | u8 reg = data->sensor; /* In case the value is updated while we use it */ |
427 | 427 | ||
428 | if (reg & (1 << nr)) | 428 | if (reg & (1 << nr)) |
429 | return sprintf(buf, "3\n"); /* thermal diode */ | 429 | return sprintf(buf, "3\n"); /* thermal diode */ |
430 | if (reg & (8 << nr)) | 430 | if (reg & (8 << nr)) |
431 | return sprintf(buf, "2\n"); /* thermistor */ | 431 | return sprintf(buf, "2\n"); /* thermistor */ |
432 | return sprintf(buf, "0\n"); /* disabled */ | 432 | return sprintf(buf, "0\n"); /* disabled */ |
433 | } | 433 | } |
434 | static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, | 434 | static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, |
435 | const char *buf, size_t count) | 435 | const char *buf, size_t count) |
436 | { | 436 | { |
437 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 437 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
438 | int nr = sensor_attr->index; | 438 | int nr = sensor_attr->index; |
439 | 439 | ||
440 | struct i2c_client *client = to_i2c_client(dev); | 440 | struct i2c_client *client = to_i2c_client(dev); |
441 | struct it87_data *data = i2c_get_clientdata(client); | 441 | struct it87_data *data = i2c_get_clientdata(client); |
442 | int val = simple_strtol(buf, NULL, 10); | 442 | int val = simple_strtol(buf, NULL, 10); |
443 | 443 | ||
444 | down(&data->update_lock); | 444 | down(&data->update_lock); |
445 | 445 | ||
446 | data->sensor &= ~(1 << nr); | 446 | data->sensor &= ~(1 << nr); |
447 | data->sensor &= ~(8 << nr); | 447 | data->sensor &= ~(8 << nr); |
448 | /* 3 = thermal diode; 2 = thermistor; 0 = disabled */ | 448 | /* 3 = thermal diode; 2 = thermistor; 0 = disabled */ |
449 | if (val == 3) | 449 | if (val == 3) |
450 | data->sensor |= 1 << nr; | 450 | data->sensor |= 1 << nr; |
451 | else if (val == 2) | 451 | else if (val == 2) |
452 | data->sensor |= 8 << nr; | 452 | data->sensor |= 8 << nr; |
453 | else if (val != 0) { | 453 | else if (val != 0) { |
454 | up(&data->update_lock); | 454 | up(&data->update_lock); |
455 | return -EINVAL; | 455 | return -EINVAL; |
456 | } | 456 | } |
457 | it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); | 457 | it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); |
458 | up(&data->update_lock); | 458 | up(&data->update_lock); |
459 | return count; | 459 | return count; |
460 | } | 460 | } |
461 | #define show_sensor_offset(offset) \ | 461 | #define show_sensor_offset(offset) \ |
462 | static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ | 462 | static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ |
463 | show_sensor, set_sensor, offset - 1); | 463 | show_sensor, set_sensor, offset - 1); |
464 | 464 | ||
465 | show_sensor_offset(1); | 465 | show_sensor_offset(1); |
466 | show_sensor_offset(2); | 466 | show_sensor_offset(2); |
467 | show_sensor_offset(3); | 467 | show_sensor_offset(3); |
468 | 468 | ||
469 | /* 3 Fans */ | 469 | /* 3 Fans */ |
470 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, | 470 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
471 | char *buf) | 471 | char *buf) |
472 | { | 472 | { |
473 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 473 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
474 | int nr = sensor_attr->index; | 474 | int nr = sensor_attr->index; |
475 | 475 | ||
476 | struct it87_data *data = it87_update_device(dev); | 476 | struct it87_data *data = it87_update_device(dev); |
477 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], | 477 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], |
478 | DIV_FROM_REG(data->fan_div[nr]))); | 478 | DIV_FROM_REG(data->fan_div[nr]))); |
479 | } | 479 | } |
480 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, | 480 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
481 | char *buf) | 481 | char *buf) |
482 | { | 482 | { |
483 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 483 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
484 | int nr = sensor_attr->index; | 484 | int nr = sensor_attr->index; |
485 | 485 | ||
486 | struct it87_data *data = it87_update_device(dev); | 486 | struct it87_data *data = it87_update_device(dev); |
487 | return sprintf(buf,"%d\n", | 487 | return sprintf(buf,"%d\n", |
488 | FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]))); | 488 | FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]))); |
489 | } | 489 | } |
490 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, | 490 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
491 | char *buf) | 491 | char *buf) |
492 | { | 492 | { |
493 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 493 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(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 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); | 497 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); |
498 | } | 498 | } |
499 | static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, | 499 | static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, |
500 | char *buf) | 500 | char *buf) |
501 | { | 501 | { |
502 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 502 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
503 | int nr = sensor_attr->index; | 503 | int nr = sensor_attr->index; |
504 | 504 | ||
505 | struct it87_data *data = it87_update_device(dev); | 505 | struct it87_data *data = it87_update_device(dev); |
506 | return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0); | 506 | return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0); |
507 | } | 507 | } |
508 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, | 508 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
509 | char *buf) | 509 | char *buf) |
510 | { | 510 | { |
511 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 511 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
512 | int nr = sensor_attr->index; | 512 | int nr = sensor_attr->index; |
513 | 513 | ||
514 | struct it87_data *data = it87_update_device(dev); | 514 | struct it87_data *data = it87_update_device(dev); |
515 | return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]); | 515 | return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]); |
516 | } | 516 | } |
517 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, | 517 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
518 | const char *buf, size_t count) | 518 | const char *buf, size_t count) |
519 | { | 519 | { |
520 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 520 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
521 | int nr = sensor_attr->index; | 521 | int nr = sensor_attr->index; |
522 | 522 | ||
523 | struct i2c_client *client = to_i2c_client(dev); | 523 | struct i2c_client *client = to_i2c_client(dev); |
524 | struct it87_data *data = i2c_get_clientdata(client); | 524 | struct it87_data *data = i2c_get_clientdata(client); |
525 | int val = simple_strtol(buf, NULL, 10); | 525 | int val = simple_strtol(buf, NULL, 10); |
526 | u8 reg = it87_read_value(client, IT87_REG_FAN_DIV); | 526 | u8 reg = it87_read_value(client, IT87_REG_FAN_DIV); |
527 | 527 | ||
528 | down(&data->update_lock); | 528 | down(&data->update_lock); |
529 | switch (nr) { | 529 | switch (nr) { |
530 | case 0: data->fan_div[nr] = reg & 0x07; break; | 530 | case 0: data->fan_div[nr] = reg & 0x07; break; |
531 | case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; | 531 | case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; |
532 | case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break; | 532 | case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break; |
533 | } | 533 | } |
534 | 534 | ||
535 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); | 535 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
536 | it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); | 536 | it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); |
537 | up(&data->update_lock); | 537 | up(&data->update_lock); |
538 | return count; | 538 | return count; |
539 | } | 539 | } |
540 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, | 540 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
541 | const char *buf, size_t count) | 541 | const char *buf, size_t count) |
542 | { | 542 | { |
543 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 543 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
544 | int nr = sensor_attr->index; | 544 | int nr = sensor_attr->index; |
545 | 545 | ||
546 | struct i2c_client *client = to_i2c_client(dev); | 546 | struct i2c_client *client = to_i2c_client(dev); |
547 | struct it87_data *data = i2c_get_clientdata(client); | 547 | struct it87_data *data = i2c_get_clientdata(client); |
548 | int val = simple_strtol(buf, NULL, 10); | 548 | int val = simple_strtol(buf, NULL, 10); |
549 | int i, min[3]; | 549 | int i, min[3]; |
550 | u8 old; | 550 | u8 old; |
551 | 551 | ||
552 | down(&data->update_lock); | 552 | down(&data->update_lock); |
553 | old = it87_read_value(client, IT87_REG_FAN_DIV); | 553 | old = it87_read_value(client, IT87_REG_FAN_DIV); |
554 | 554 | ||
555 | for (i = 0; i < 3; i++) | 555 | for (i = 0; i < 3; i++) |
556 | min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i])); | 556 | min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i])); |
557 | 557 | ||
558 | switch (nr) { | 558 | switch (nr) { |
559 | case 0: | 559 | case 0: |
560 | case 1: | 560 | case 1: |
561 | data->fan_div[nr] = DIV_TO_REG(val); | 561 | data->fan_div[nr] = DIV_TO_REG(val); |
562 | break; | 562 | break; |
563 | case 2: | 563 | case 2: |
564 | if (val < 8) | 564 | if (val < 8) |
565 | data->fan_div[nr] = 1; | 565 | data->fan_div[nr] = 1; |
566 | else | 566 | else |
567 | data->fan_div[nr] = 3; | 567 | data->fan_div[nr] = 3; |
568 | } | 568 | } |
569 | val = old & 0x80; | 569 | val = old & 0x80; |
570 | val |= (data->fan_div[0] & 0x07); | 570 | val |= (data->fan_div[0] & 0x07); |
571 | val |= (data->fan_div[1] & 0x07) << 3; | 571 | val |= (data->fan_div[1] & 0x07) << 3; |
572 | if (data->fan_div[2] == 3) | 572 | if (data->fan_div[2] == 3) |
573 | val |= 0x1 << 6; | 573 | val |= 0x1 << 6; |
574 | it87_write_value(client, IT87_REG_FAN_DIV, val); | 574 | it87_write_value(client, IT87_REG_FAN_DIV, val); |
575 | 575 | ||
576 | for (i = 0; i < 3; i++) { | 576 | for (i = 0; i < 3; i++) { |
577 | data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); | 577 | data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); |
578 | it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]); | 578 | it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]); |
579 | } | 579 | } |
580 | up(&data->update_lock); | 580 | up(&data->update_lock); |
581 | return count; | 581 | return count; |
582 | } | 582 | } |
583 | static ssize_t set_pwm_enable(struct device *dev, | 583 | static ssize_t set_pwm_enable(struct device *dev, |
584 | struct device_attribute *attr, const char *buf, size_t count) | 584 | struct device_attribute *attr, const char *buf, size_t count) |
585 | { | 585 | { |
586 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 586 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
587 | int nr = sensor_attr->index; | 587 | int nr = sensor_attr->index; |
588 | 588 | ||
589 | struct i2c_client *client = to_i2c_client(dev); | 589 | struct i2c_client *client = to_i2c_client(dev); |
590 | struct it87_data *data = i2c_get_clientdata(client); | 590 | struct it87_data *data = i2c_get_clientdata(client); |
591 | int val = simple_strtol(buf, NULL, 10); | 591 | int val = simple_strtol(buf, NULL, 10); |
592 | 592 | ||
593 | down(&data->update_lock); | 593 | down(&data->update_lock); |
594 | 594 | ||
595 | if (val == 0) { | 595 | if (val == 0) { |
596 | int tmp; | 596 | int tmp; |
597 | /* make sure the fan is on when in on/off mode */ | 597 | /* make sure the fan is on when in on/off mode */ |
598 | tmp = it87_read_value(client, IT87_REG_FAN_CTL); | 598 | tmp = it87_read_value(client, IT87_REG_FAN_CTL); |
599 | it87_write_value(client, IT87_REG_FAN_CTL, tmp | (1 << nr)); | 599 | it87_write_value(client, IT87_REG_FAN_CTL, tmp | (1 << nr)); |
600 | /* set on/off mode */ | 600 | /* set on/off mode */ |
601 | data->fan_main_ctrl &= ~(1 << nr); | 601 | data->fan_main_ctrl &= ~(1 << nr); |
602 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); | 602 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); |
603 | } else if (val == 1) { | 603 | } else if (val == 1) { |
604 | /* set SmartGuardian mode */ | 604 | /* set SmartGuardian mode */ |
605 | data->fan_main_ctrl |= (1 << nr); | 605 | data->fan_main_ctrl |= (1 << nr); |
606 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); | 606 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); |
607 | /* set saved pwm value, clear FAN_CTLX PWM mode bit */ | 607 | /* set saved pwm value, clear FAN_CTLX PWM mode bit */ |
608 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); | 608 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); |
609 | } else { | 609 | } else { |
610 | up(&data->update_lock); | 610 | up(&data->update_lock); |
611 | return -EINVAL; | 611 | return -EINVAL; |
612 | } | 612 | } |
613 | 613 | ||
614 | up(&data->update_lock); | 614 | up(&data->update_lock); |
615 | return count; | 615 | return count; |
616 | } | 616 | } |
617 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, | 617 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
618 | const char *buf, size_t count) | 618 | const char *buf, size_t count) |
619 | { | 619 | { |
620 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | 620 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
621 | int nr = sensor_attr->index; | 621 | int nr = sensor_attr->index; |
622 | 622 | ||
623 | struct i2c_client *client = to_i2c_client(dev); | 623 | struct i2c_client *client = to_i2c_client(dev); |
624 | struct it87_data *data = i2c_get_clientdata(client); | 624 | struct it87_data *data = i2c_get_clientdata(client); |
625 | int val = simple_strtol(buf, NULL, 10); | 625 | int val = simple_strtol(buf, NULL, 10); |
626 | 626 | ||
627 | if (val < 0 || val > 255) | 627 | if (val < 0 || val > 255) |
628 | return -EINVAL; | 628 | return -EINVAL; |
629 | 629 | ||
630 | down(&data->update_lock); | 630 | down(&data->update_lock); |
631 | data->manual_pwm_ctl[nr] = val; | 631 | data->manual_pwm_ctl[nr] = val; |
632 | if (data->fan_main_ctrl & (1 << nr)) | 632 | if (data->fan_main_ctrl & (1 << nr)) |
633 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); | 633 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); |
634 | up(&data->update_lock); | 634 | up(&data->update_lock); |
635 | return count; | 635 | return count; |
636 | } | 636 | } |
637 | 637 | ||
638 | #define show_fan_offset(offset) \ | 638 | #define show_fan_offset(offset) \ |
639 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ | 639 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
640 | show_fan, NULL, offset - 1); \ | 640 | show_fan, NULL, offset - 1); \ |
641 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | 641 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
642 | show_fan_min, set_fan_min, offset - 1); \ | 642 | show_fan_min, set_fan_min, offset - 1); \ |
643 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ | 643 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
644 | show_fan_div, set_fan_div, offset - 1); | 644 | show_fan_div, set_fan_div, offset - 1); |
645 | 645 | ||
646 | show_fan_offset(1); | 646 | show_fan_offset(1); |
647 | show_fan_offset(2); | 647 | show_fan_offset(2); |
648 | show_fan_offset(3); | 648 | show_fan_offset(3); |
649 | 649 | ||
650 | #define show_pwm_offset(offset) \ | 650 | #define show_pwm_offset(offset) \ |
651 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ | 651 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ |
652 | show_pwm_enable, set_pwm_enable, offset - 1); \ | 652 | show_pwm_enable, set_pwm_enable, offset - 1); \ |
653 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ | 653 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ |
654 | show_pwm, set_pwm, offset - 1); | 654 | show_pwm, set_pwm, offset - 1); |
655 | 655 | ||
656 | show_pwm_offset(1); | 656 | show_pwm_offset(1); |
657 | show_pwm_offset(2); | 657 | show_pwm_offset(2); |
658 | show_pwm_offset(3); | 658 | show_pwm_offset(3); |
659 | 659 | ||
660 | /* Alarms */ | 660 | /* Alarms */ |
661 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) | 661 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf) |
662 | { | 662 | { |
663 | struct it87_data *data = it87_update_device(dev); | 663 | struct it87_data *data = it87_update_device(dev); |
664 | return sprintf(buf, "%u\n", data->alarms); | 664 | return sprintf(buf, "%u\n", data->alarms); |
665 | } | 665 | } |
666 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); | 666 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
667 | 667 | ||
668 | static ssize_t | 668 | static ssize_t |
669 | show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) | 669 | show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) |
670 | { | 670 | { |
671 | struct it87_data *data = it87_update_device(dev); | 671 | struct it87_data *data = it87_update_device(dev); |
672 | return sprintf(buf, "%ld\n", (long) data->vrm); | 672 | return sprintf(buf, "%u\n", data->vrm); |
673 | } | 673 | } |
674 | static ssize_t | 674 | static ssize_t |
675 | store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) | 675 | store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) |
676 | { | 676 | { |
677 | struct i2c_client *client = to_i2c_client(dev); | 677 | struct i2c_client *client = to_i2c_client(dev); |
678 | struct it87_data *data = i2c_get_clientdata(client); | 678 | struct it87_data *data = i2c_get_clientdata(client); |
679 | u32 val; | 679 | u32 val; |
680 | 680 | ||
681 | val = simple_strtoul(buf, NULL, 10); | 681 | val = simple_strtoul(buf, NULL, 10); |
682 | data->vrm = val; | 682 | data->vrm = val; |
683 | 683 | ||
684 | return count; | 684 | return count; |
685 | } | 685 | } |
686 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); | 686 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); |
687 | #define device_create_file_vrm(client) \ | 687 | #define device_create_file_vrm(client) \ |
688 | device_create_file(&client->dev, &dev_attr_vrm) | 688 | device_create_file(&client->dev, &dev_attr_vrm) |
689 | 689 | ||
690 | static ssize_t | 690 | static ssize_t |
691 | show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) | 691 | show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) |
692 | { | 692 | { |
693 | struct it87_data *data = it87_update_device(dev); | 693 | struct it87_data *data = it87_update_device(dev); |
694 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); | 694 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); |
695 | } | 695 | } |
696 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); | 696 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
697 | #define device_create_file_vid(client) \ | 697 | #define device_create_file_vid(client) \ |
698 | device_create_file(&client->dev, &dev_attr_cpu0_vid) | 698 | device_create_file(&client->dev, &dev_attr_cpu0_vid) |
699 | 699 | ||
700 | /* This function is called when: | 700 | /* This function is called when: |
701 | * it87_driver is inserted (when this module is loaded), for each | 701 | * it87_driver is inserted (when this module is loaded), for each |
702 | available adapter | 702 | available adapter |
703 | * when a new adapter is inserted (and it87_driver is still present) */ | 703 | * when a new adapter is inserted (and it87_driver is still present) */ |
704 | static int it87_attach_adapter(struct i2c_adapter *adapter) | 704 | static int it87_attach_adapter(struct i2c_adapter *adapter) |
705 | { | 705 | { |
706 | if (!(adapter->class & I2C_CLASS_HWMON)) | 706 | if (!(adapter->class & I2C_CLASS_HWMON)) |
707 | return 0; | 707 | return 0; |
708 | return i2c_probe(adapter, &addr_data, it87_detect); | 708 | return i2c_probe(adapter, &addr_data, it87_detect); |
709 | } | 709 | } |
710 | 710 | ||
711 | static int it87_isa_attach_adapter(struct i2c_adapter *adapter) | 711 | static int it87_isa_attach_adapter(struct i2c_adapter *adapter) |
712 | { | 712 | { |
713 | return it87_detect(adapter, isa_address, -1); | 713 | return it87_detect(adapter, isa_address, -1); |
714 | } | 714 | } |
715 | 715 | ||
716 | /* SuperIO detection - will change isa_address if a chip is found */ | 716 | /* SuperIO detection - will change isa_address if a chip is found */ |
717 | static int __init it87_find(unsigned short *address) | 717 | static int __init it87_find(unsigned short *address) |
718 | { | 718 | { |
719 | int err = -ENODEV; | 719 | int err = -ENODEV; |
720 | 720 | ||
721 | superio_enter(); | 721 | superio_enter(); |
722 | chip_type = superio_inw(DEVID); | 722 | chip_type = superio_inw(DEVID); |
723 | if (chip_type != IT8712F_DEVID | 723 | if (chip_type != IT8712F_DEVID |
724 | && chip_type != IT8705F_DEVID) | 724 | && chip_type != IT8705F_DEVID) |
725 | goto exit; | 725 | goto exit; |
726 | 726 | ||
727 | superio_select(); | 727 | superio_select(); |
728 | if (!(superio_inb(IT87_ACT_REG) & 0x01)) { | 728 | if (!(superio_inb(IT87_ACT_REG) & 0x01)) { |
729 | pr_info("it87: Device not activated, skipping\n"); | 729 | pr_info("it87: Device not activated, skipping\n"); |
730 | goto exit; | 730 | goto exit; |
731 | } | 731 | } |
732 | 732 | ||
733 | *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1); | 733 | *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1); |
734 | if (*address == 0) { | 734 | if (*address == 0) { |
735 | pr_info("it87: Base address not set, skipping\n"); | 735 | pr_info("it87: Base address not set, skipping\n"); |
736 | goto exit; | 736 | goto exit; |
737 | } | 737 | } |
738 | 738 | ||
739 | err = 0; | 739 | err = 0; |
740 | pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", | 740 | pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", |
741 | chip_type, *address, superio_inb(DEVREV) & 0x0f); | 741 | chip_type, *address, superio_inb(DEVREV) & 0x0f); |
742 | 742 | ||
743 | exit: | 743 | exit: |
744 | superio_exit(); | 744 | superio_exit(); |
745 | return err; | 745 | return err; |
746 | } | 746 | } |
747 | 747 | ||
748 | /* This function is called by i2c_probe */ | 748 | /* This function is called by i2c_probe */ |
749 | static int it87_detect(struct i2c_adapter *adapter, int address, int kind) | 749 | static int it87_detect(struct i2c_adapter *adapter, int address, int kind) |
750 | { | 750 | { |
751 | int i; | 751 | int i; |
752 | struct i2c_client *new_client; | 752 | struct i2c_client *new_client; |
753 | struct it87_data *data; | 753 | struct it87_data *data; |
754 | int err = 0; | 754 | int err = 0; |
755 | const char *name = ""; | 755 | const char *name = ""; |
756 | int is_isa = i2c_is_isa_adapter(adapter); | 756 | int is_isa = i2c_is_isa_adapter(adapter); |
757 | int enable_pwm_interface; | 757 | int enable_pwm_interface; |
758 | 758 | ||
759 | if (!is_isa && | 759 | if (!is_isa && |
760 | !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 760 | !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
761 | goto ERROR0; | 761 | goto ERROR0; |
762 | 762 | ||
763 | /* Reserve the ISA region */ | 763 | /* Reserve the ISA region */ |
764 | if (is_isa) | 764 | if (is_isa) |
765 | if (!request_region(address, IT87_EXTENT, | 765 | if (!request_region(address, IT87_EXTENT, |
766 | it87_isa_driver.driver.name)) | 766 | it87_isa_driver.driver.name)) |
767 | goto ERROR0; | 767 | goto ERROR0; |
768 | 768 | ||
769 | /* For now, we presume we have a valid client. We create the | 769 | /* For now, we presume we have a valid client. We create the |
770 | client structure, even though we cannot fill it completely yet. | 770 | client structure, even though we cannot fill it completely yet. |
771 | But it allows us to access it87_{read,write}_value. */ | 771 | But it allows us to access it87_{read,write}_value. */ |
772 | 772 | ||
773 | if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) { | 773 | if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) { |
774 | err = -ENOMEM; | 774 | err = -ENOMEM; |
775 | goto ERROR1; | 775 | goto ERROR1; |
776 | } | 776 | } |
777 | 777 | ||
778 | new_client = &data->client; | 778 | new_client = &data->client; |
779 | if (is_isa) | 779 | if (is_isa) |
780 | init_MUTEX(&data->lock); | 780 | init_MUTEX(&data->lock); |
781 | i2c_set_clientdata(new_client, data); | 781 | i2c_set_clientdata(new_client, data); |
782 | new_client->addr = address; | 782 | new_client->addr = address; |
783 | new_client->adapter = adapter; | 783 | new_client->adapter = adapter; |
784 | new_client->driver = is_isa ? &it87_isa_driver : &it87_driver; | 784 | new_client->driver = is_isa ? &it87_isa_driver : &it87_driver; |
785 | new_client->flags = 0; | 785 | new_client->flags = 0; |
786 | 786 | ||
787 | /* Now, we do the remaining detection. */ | 787 | /* Now, we do the remaining detection. */ |
788 | 788 | ||
789 | if (kind < 0) { | 789 | if (kind < 0) { |
790 | if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80) | 790 | if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80) |
791 | || (!is_isa | 791 | || (!is_isa |
792 | && it87_read_value(new_client, IT87_REG_I2C_ADDR) != address)) { | 792 | && it87_read_value(new_client, IT87_REG_I2C_ADDR) != address)) { |
793 | err = -ENODEV; | 793 | err = -ENODEV; |
794 | goto ERROR2; | 794 | goto ERROR2; |
795 | } | 795 | } |
796 | } | 796 | } |
797 | 797 | ||
798 | /* Determine the chip type. */ | 798 | /* Determine the chip type. */ |
799 | if (kind <= 0) { | 799 | if (kind <= 0) { |
800 | i = it87_read_value(new_client, IT87_REG_CHIPID); | 800 | i = it87_read_value(new_client, IT87_REG_CHIPID); |
801 | if (i == 0x90) { | 801 | if (i == 0x90) { |
802 | kind = it87; | 802 | kind = it87; |
803 | if ((is_isa) && (chip_type == IT8712F_DEVID)) | 803 | if ((is_isa) && (chip_type == IT8712F_DEVID)) |
804 | kind = it8712; | 804 | kind = it8712; |
805 | } | 805 | } |
806 | else { | 806 | else { |
807 | if (kind == 0) | 807 | if (kind == 0) |
808 | dev_info(&adapter->dev, | 808 | dev_info(&adapter->dev, |
809 | "Ignoring 'force' parameter for unknown chip at " | 809 | "Ignoring 'force' parameter for unknown chip at " |
810 | "adapter %d, address 0x%02x\n", | 810 | "adapter %d, address 0x%02x\n", |
811 | i2c_adapter_id(adapter), address); | 811 | i2c_adapter_id(adapter), address); |
812 | err = -ENODEV; | 812 | err = -ENODEV; |
813 | goto ERROR2; | 813 | goto ERROR2; |
814 | } | 814 | } |
815 | } | 815 | } |
816 | 816 | ||
817 | if (kind == it87) { | 817 | if (kind == it87) { |
818 | name = "it87"; | 818 | name = "it87"; |
819 | } else if (kind == it8712) { | 819 | } else if (kind == it8712) { |
820 | name = "it8712"; | 820 | name = "it8712"; |
821 | } | 821 | } |
822 | 822 | ||
823 | /* Fill in the remaining client fields and put it into the global list */ | 823 | /* Fill in the remaining client fields and put it into the global list */ |
824 | strlcpy(new_client->name, name, I2C_NAME_SIZE); | 824 | strlcpy(new_client->name, name, I2C_NAME_SIZE); |
825 | data->type = kind; | 825 | data->type = kind; |
826 | data->valid = 0; | 826 | data->valid = 0; |
827 | init_MUTEX(&data->update_lock); | 827 | init_MUTEX(&data->update_lock); |
828 | 828 | ||
829 | /* Tell the I2C layer a new client has arrived */ | 829 | /* Tell the I2C layer a new client has arrived */ |
830 | if ((err = i2c_attach_client(new_client))) | 830 | if ((err = i2c_attach_client(new_client))) |
831 | goto ERROR2; | 831 | goto ERROR2; |
832 | 832 | ||
833 | /* Check PWM configuration */ | 833 | /* Check PWM configuration */ |
834 | enable_pwm_interface = it87_check_pwm(new_client); | 834 | enable_pwm_interface = it87_check_pwm(new_client); |
835 | 835 | ||
836 | /* Initialize the IT87 chip */ | 836 | /* Initialize the IT87 chip */ |
837 | it87_init_client(new_client, data); | 837 | it87_init_client(new_client, data); |
838 | 838 | ||
839 | /* Register sysfs hooks */ | 839 | /* Register sysfs hooks */ |
840 | data->class_dev = hwmon_device_register(&new_client->dev); | 840 | data->class_dev = hwmon_device_register(&new_client->dev); |
841 | if (IS_ERR(data->class_dev)) { | 841 | if (IS_ERR(data->class_dev)) { |
842 | err = PTR_ERR(data->class_dev); | 842 | err = PTR_ERR(data->class_dev); |
843 | goto ERROR3; | 843 | goto ERROR3; |
844 | } | 844 | } |
845 | 845 | ||
846 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); | 846 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); |
847 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr); | 847 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr); |
848 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr); | 848 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr); |
849 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr); | 849 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr); |
850 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr); | 850 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr); |
851 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr); | 851 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr); |
852 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr); | 852 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr); |
853 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr); | 853 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr); |
854 | device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr); | 854 | device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr); |
855 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr); | 855 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr); |
856 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr); | 856 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr); |
857 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr); | 857 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr); |
858 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr); | 858 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr); |
859 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr); | 859 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr); |
860 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr); | 860 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr); |
861 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr); | 861 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr); |
862 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr); | 862 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr); |
863 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr); | 863 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr); |
864 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr); | 864 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr); |
865 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr); | 865 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr); |
866 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr); | 866 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr); |
867 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr); | 867 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr); |
868 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr); | 868 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr); |
869 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr); | 869 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr); |
870 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr); | 870 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr); |
871 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr); | 871 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr); |
872 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr); | 872 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr); |
873 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr); | 873 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr); |
874 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr); | 874 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr); |
875 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr); | 875 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr); |
876 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr); | 876 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr); |
877 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr); | 877 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr); |
878 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr); | 878 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr); |
879 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr); | 879 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr); |
880 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_type.dev_attr); | 880 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_type.dev_attr); |
881 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_type.dev_attr); | 881 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_type.dev_attr); |
882 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_type.dev_attr); | 882 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_type.dev_attr); |
883 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr); | 883 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr); |
884 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_input.dev_attr); | 884 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_input.dev_attr); |
885 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_input.dev_attr); | 885 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_input.dev_attr); |
886 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_min.dev_attr); | 886 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_min.dev_attr); |
887 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_min.dev_attr); | 887 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_min.dev_attr); |
888 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_min.dev_attr); | 888 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_min.dev_attr); |
889 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_div.dev_attr); | 889 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_div.dev_attr); |
890 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_div.dev_attr); | 890 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_div.dev_attr); |
891 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_div.dev_attr); | 891 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_div.dev_attr); |
892 | device_create_file(&new_client->dev, &dev_attr_alarms); | 892 | device_create_file(&new_client->dev, &dev_attr_alarms); |
893 | if (enable_pwm_interface) { | 893 | if (enable_pwm_interface) { |
894 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm1_enable.dev_attr); | 894 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm1_enable.dev_attr); |
895 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm2_enable.dev_attr); | 895 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm2_enable.dev_attr); |
896 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm3_enable.dev_attr); | 896 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm3_enable.dev_attr); |
897 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr); | 897 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr); |
898 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr); | 898 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr); |
899 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr); | 899 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr); |
900 | } | 900 | } |
901 | 901 | ||
902 | if (data->type == it8712) { | 902 | if (data->type == it8712) { |
903 | data->vrm = vid_which_vrm(); | 903 | data->vrm = vid_which_vrm(); |
904 | device_create_file_vrm(new_client); | 904 | device_create_file_vrm(new_client); |
905 | device_create_file_vid(new_client); | 905 | device_create_file_vid(new_client); |
906 | } | 906 | } |
907 | 907 | ||
908 | return 0; | 908 | return 0; |
909 | 909 | ||
910 | ERROR3: | 910 | ERROR3: |
911 | i2c_detach_client(new_client); | 911 | i2c_detach_client(new_client); |
912 | ERROR2: | 912 | ERROR2: |
913 | kfree(data); | 913 | kfree(data); |
914 | ERROR1: | 914 | ERROR1: |
915 | if (is_isa) | 915 | if (is_isa) |
916 | release_region(address, IT87_EXTENT); | 916 | release_region(address, IT87_EXTENT); |
917 | ERROR0: | 917 | ERROR0: |
918 | return err; | 918 | return err; |
919 | } | 919 | } |
920 | 920 | ||
921 | static int it87_detach_client(struct i2c_client *client) | 921 | static int it87_detach_client(struct i2c_client *client) |
922 | { | 922 | { |
923 | struct it87_data *data = i2c_get_clientdata(client); | 923 | struct it87_data *data = i2c_get_clientdata(client); |
924 | int err; | 924 | int err; |
925 | 925 | ||
926 | hwmon_device_unregister(data->class_dev); | 926 | hwmon_device_unregister(data->class_dev); |
927 | 927 | ||
928 | if ((err = i2c_detach_client(client))) | 928 | if ((err = i2c_detach_client(client))) |
929 | return err; | 929 | return err; |
930 | 930 | ||
931 | if(i2c_is_isa_client(client)) | 931 | if(i2c_is_isa_client(client)) |
932 | release_region(client->addr, IT87_EXTENT); | 932 | release_region(client->addr, IT87_EXTENT); |
933 | kfree(data); | 933 | kfree(data); |
934 | 934 | ||
935 | return 0; | 935 | return 0; |
936 | } | 936 | } |
937 | 937 | ||
938 | /* The SMBus locks itself, but ISA access must be locked explicitly! | 938 | /* The SMBus locks itself, but ISA access must be locked explicitly! |
939 | We don't want to lock the whole ISA bus, so we lock each client | 939 | We don't want to lock the whole ISA bus, so we lock each client |
940 | separately. | 940 | separately. |
941 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, | 941 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
942 | would slow down the IT87 access and should not be necessary. */ | 942 | would slow down the IT87 access and should not be necessary. */ |
943 | static int it87_read_value(struct i2c_client *client, u8 reg) | 943 | static int it87_read_value(struct i2c_client *client, u8 reg) |
944 | { | 944 | { |
945 | struct it87_data *data = i2c_get_clientdata(client); | 945 | struct it87_data *data = i2c_get_clientdata(client); |
946 | 946 | ||
947 | int res; | 947 | int res; |
948 | if (i2c_is_isa_client(client)) { | 948 | if (i2c_is_isa_client(client)) { |
949 | down(&data->lock); | 949 | down(&data->lock); |
950 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); | 950 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); |
951 | res = inb_p(client->addr + IT87_DATA_REG_OFFSET); | 951 | res = inb_p(client->addr + IT87_DATA_REG_OFFSET); |
952 | up(&data->lock); | 952 | up(&data->lock); |
953 | return res; | 953 | return res; |
954 | } else | 954 | } else |
955 | return i2c_smbus_read_byte_data(client, reg); | 955 | return i2c_smbus_read_byte_data(client, reg); |
956 | } | 956 | } |
957 | 957 | ||
958 | /* The SMBus locks itself, but ISA access muse be locked explicitly! | 958 | /* The SMBus locks itself, but ISA access muse be locked explicitly! |
959 | We don't want to lock the whole ISA bus, so we lock each client | 959 | We don't want to lock the whole ISA bus, so we lock each client |
960 | separately. | 960 | separately. |
961 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, | 961 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
962 | would slow down the IT87 access and should not be necessary. */ | 962 | would slow down the IT87 access and should not be necessary. */ |
963 | static int it87_write_value(struct i2c_client *client, u8 reg, u8 value) | 963 | static int it87_write_value(struct i2c_client *client, u8 reg, u8 value) |
964 | { | 964 | { |
965 | struct it87_data *data = i2c_get_clientdata(client); | 965 | struct it87_data *data = i2c_get_clientdata(client); |
966 | 966 | ||
967 | if (i2c_is_isa_client(client)) { | 967 | if (i2c_is_isa_client(client)) { |
968 | down(&data->lock); | 968 | down(&data->lock); |
969 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); | 969 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); |
970 | outb_p(value, client->addr + IT87_DATA_REG_OFFSET); | 970 | outb_p(value, client->addr + IT87_DATA_REG_OFFSET); |
971 | up(&data->lock); | 971 | up(&data->lock); |
972 | return 0; | 972 | return 0; |
973 | } else | 973 | } else |
974 | return i2c_smbus_write_byte_data(client, reg, value); | 974 | return i2c_smbus_write_byte_data(client, reg, value); |
975 | } | 975 | } |
976 | 976 | ||
977 | /* Return 1 if and only if the PWM interface is safe to use */ | 977 | /* Return 1 if and only if the PWM interface is safe to use */ |
978 | static int it87_check_pwm(struct i2c_client *client) | 978 | static int it87_check_pwm(struct i2c_client *client) |
979 | { | 979 | { |
980 | /* Some BIOSes fail to correctly configure the IT87 fans. All fans off | 980 | /* Some BIOSes fail to correctly configure the IT87 fans. All fans off |
981 | * and polarity set to active low is sign that this is the case so we | 981 | * and polarity set to active low is sign that this is the case so we |
982 | * disable pwm control to protect the user. */ | 982 | * disable pwm control to protect the user. */ |
983 | int tmp = it87_read_value(client, IT87_REG_FAN_CTL); | 983 | int tmp = it87_read_value(client, IT87_REG_FAN_CTL); |
984 | if ((tmp & 0x87) == 0) { | 984 | if ((tmp & 0x87) == 0) { |
985 | if (fix_pwm_polarity) { | 985 | if (fix_pwm_polarity) { |
986 | /* The user asks us to attempt a chip reconfiguration. | 986 | /* The user asks us to attempt a chip reconfiguration. |
987 | * This means switching to active high polarity and | 987 | * This means switching to active high polarity and |
988 | * inverting all fan speed values. */ | 988 | * inverting all fan speed values. */ |
989 | int i; | 989 | int i; |
990 | u8 pwm[3]; | 990 | u8 pwm[3]; |
991 | 991 | ||
992 | for (i = 0; i < 3; i++) | 992 | for (i = 0; i < 3; i++) |
993 | pwm[i] = it87_read_value(client, | 993 | pwm[i] = it87_read_value(client, |
994 | IT87_REG_PWM(i)); | 994 | IT87_REG_PWM(i)); |
995 | 995 | ||
996 | /* If any fan is in automatic pwm mode, the polarity | 996 | /* If any fan is in automatic pwm mode, the polarity |
997 | * might be correct, as suspicious as it seems, so we | 997 | * might be correct, as suspicious as it seems, so we |
998 | * better don't change anything (but still disable the | 998 | * better don't change anything (but still disable the |
999 | * PWM interface). */ | 999 | * PWM interface). */ |
1000 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { | 1000 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { |
1001 | dev_info(&client->dev, "Reconfiguring PWM to " | 1001 | dev_info(&client->dev, "Reconfiguring PWM to " |
1002 | "active high polarity\n"); | 1002 | "active high polarity\n"); |
1003 | it87_write_value(client, IT87_REG_FAN_CTL, | 1003 | it87_write_value(client, IT87_REG_FAN_CTL, |
1004 | tmp | 0x87); | 1004 | tmp | 0x87); |
1005 | for (i = 0; i < 3; i++) | 1005 | for (i = 0; i < 3; i++) |
1006 | it87_write_value(client, | 1006 | it87_write_value(client, |
1007 | IT87_REG_PWM(i), | 1007 | IT87_REG_PWM(i), |
1008 | 0x7f & ~pwm[i]); | 1008 | 0x7f & ~pwm[i]); |
1009 | return 1; | 1009 | return 1; |
1010 | } | 1010 | } |
1011 | 1011 | ||
1012 | dev_info(&client->dev, "PWM configuration is " | 1012 | dev_info(&client->dev, "PWM configuration is " |
1013 | "too broken to be fixed\n"); | 1013 | "too broken to be fixed\n"); |
1014 | } | 1014 | } |
1015 | 1015 | ||
1016 | dev_info(&client->dev, "Detected broken BIOS " | 1016 | dev_info(&client->dev, "Detected broken BIOS " |
1017 | "defaults, disabling PWM interface\n"); | 1017 | "defaults, disabling PWM interface\n"); |
1018 | return 0; | 1018 | return 0; |
1019 | } else if (fix_pwm_polarity) { | 1019 | } else if (fix_pwm_polarity) { |
1020 | dev_info(&client->dev, "PWM configuration looks " | 1020 | dev_info(&client->dev, "PWM configuration looks " |
1021 | "sane, won't touch\n"); | 1021 | "sane, won't touch\n"); |
1022 | } | 1022 | } |
1023 | 1023 | ||
1024 | return 1; | 1024 | return 1; |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | /* Called when we have found a new IT87. */ | 1027 | /* Called when we have found a new IT87. */ |
1028 | static void it87_init_client(struct i2c_client *client, struct it87_data *data) | 1028 | static void it87_init_client(struct i2c_client *client, struct it87_data *data) |
1029 | { | 1029 | { |
1030 | int tmp, i; | 1030 | int tmp, i; |
1031 | 1031 | ||
1032 | /* initialize to sane defaults: | 1032 | /* initialize to sane defaults: |
1033 | * - if the chip is in manual pwm mode, this will be overwritten with | 1033 | * - if the chip is in manual pwm mode, this will be overwritten with |
1034 | * the actual settings on the chip (so in this case, initialization | 1034 | * the actual settings on the chip (so in this case, initialization |
1035 | * is not needed) | 1035 | * is not needed) |
1036 | * - if in automatic or on/off mode, we could switch to manual mode, | 1036 | * - if in automatic or on/off mode, we could switch to manual mode, |
1037 | * read the registers and set manual_pwm_ctl accordingly, but currently | 1037 | * read the registers and set manual_pwm_ctl accordingly, but currently |
1038 | * this is not implemented, so we initialize to something sane */ | 1038 | * this is not implemented, so we initialize to something sane */ |
1039 | for (i = 0; i < 3; i++) { | 1039 | for (i = 0; i < 3; i++) { |
1040 | data->manual_pwm_ctl[i] = 0xff; | 1040 | data->manual_pwm_ctl[i] = 0xff; |
1041 | } | 1041 | } |
1042 | 1042 | ||
1043 | /* Check if temperature channnels are reset manually or by some reason */ | 1043 | /* Check if temperature channnels are reset manually or by some reason */ |
1044 | tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE); | 1044 | tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE); |
1045 | if ((tmp & 0x3f) == 0) { | 1045 | if ((tmp & 0x3f) == 0) { |
1046 | /* Temp1,Temp3=thermistor; Temp2=thermal diode */ | 1046 | /* Temp1,Temp3=thermistor; Temp2=thermal diode */ |
1047 | tmp = (tmp & 0xc0) | 0x2a; | 1047 | tmp = (tmp & 0xc0) | 0x2a; |
1048 | it87_write_value(client, IT87_REG_TEMP_ENABLE, tmp); | 1048 | it87_write_value(client, IT87_REG_TEMP_ENABLE, tmp); |
1049 | } | 1049 | } |
1050 | data->sensor = tmp; | 1050 | data->sensor = tmp; |
1051 | 1051 | ||
1052 | /* Check if voltage monitors are reset manually or by some reason */ | 1052 | /* Check if voltage monitors are reset manually or by some reason */ |
1053 | tmp = it87_read_value(client, IT87_REG_VIN_ENABLE); | 1053 | tmp = it87_read_value(client, IT87_REG_VIN_ENABLE); |
1054 | if ((tmp & 0xff) == 0) { | 1054 | if ((tmp & 0xff) == 0) { |
1055 | /* Enable all voltage monitors */ | 1055 | /* Enable all voltage monitors */ |
1056 | it87_write_value(client, IT87_REG_VIN_ENABLE, 0xff); | 1056 | it87_write_value(client, IT87_REG_VIN_ENABLE, 0xff); |
1057 | } | 1057 | } |
1058 | 1058 | ||
1059 | /* Check if tachometers are reset manually or by some reason */ | 1059 | /* Check if tachometers are reset manually or by some reason */ |
1060 | data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); | 1060 | data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); |
1061 | if ((data->fan_main_ctrl & 0x70) == 0) { | 1061 | if ((data->fan_main_ctrl & 0x70) == 0) { |
1062 | /* Enable all fan tachometers */ | 1062 | /* Enable all fan tachometers */ |
1063 | data->fan_main_ctrl |= 0x70; | 1063 | data->fan_main_ctrl |= 0x70; |
1064 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); | 1064 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); |
1065 | } | 1065 | } |
1066 | 1066 | ||
1067 | /* Set current fan mode registers and the default settings for the | 1067 | /* Set current fan mode registers and the default settings for the |
1068 | * other mode registers */ | 1068 | * other mode registers */ |
1069 | for (i = 0; i < 3; i++) { | 1069 | for (i = 0; i < 3; i++) { |
1070 | if (data->fan_main_ctrl & (1 << i)) { | 1070 | if (data->fan_main_ctrl & (1 << i)) { |
1071 | /* pwm mode */ | 1071 | /* pwm mode */ |
1072 | tmp = it87_read_value(client, IT87_REG_PWM(i)); | 1072 | tmp = it87_read_value(client, IT87_REG_PWM(i)); |
1073 | if (tmp & 0x80) { | 1073 | if (tmp & 0x80) { |
1074 | /* automatic pwm - not yet implemented, but | 1074 | /* automatic pwm - not yet implemented, but |
1075 | * leave the settings made by the BIOS alone | 1075 | * leave the settings made by the BIOS alone |
1076 | * until a change is requested via the sysfs | 1076 | * until a change is requested via the sysfs |
1077 | * interface */ | 1077 | * interface */ |
1078 | } else { | 1078 | } else { |
1079 | /* manual pwm */ | 1079 | /* manual pwm */ |
1080 | data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp); | 1080 | data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp); |
1081 | } | 1081 | } |
1082 | } | 1082 | } |
1083 | } | 1083 | } |
1084 | 1084 | ||
1085 | /* Start monitoring */ | 1085 | /* Start monitoring */ |
1086 | it87_write_value(client, IT87_REG_CONFIG, | 1086 | it87_write_value(client, IT87_REG_CONFIG, |
1087 | (it87_read_value(client, IT87_REG_CONFIG) & 0x36) | 1087 | (it87_read_value(client, IT87_REG_CONFIG) & 0x36) |
1088 | | (update_vbat ? 0x41 : 0x01)); | 1088 | | (update_vbat ? 0x41 : 0x01)); |
1089 | } | 1089 | } |
1090 | 1090 | ||
1091 | static struct it87_data *it87_update_device(struct device *dev) | 1091 | static struct it87_data *it87_update_device(struct device *dev) |
1092 | { | 1092 | { |
1093 | struct i2c_client *client = to_i2c_client(dev); | 1093 | struct i2c_client *client = to_i2c_client(dev); |
1094 | struct it87_data *data = i2c_get_clientdata(client); | 1094 | struct it87_data *data = i2c_get_clientdata(client); |
1095 | int i; | 1095 | int i; |
1096 | 1096 | ||
1097 | down(&data->update_lock); | 1097 | down(&data->update_lock); |
1098 | 1098 | ||
1099 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 1099 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
1100 | || !data->valid) { | 1100 | || !data->valid) { |
1101 | 1101 | ||
1102 | if (update_vbat) { | 1102 | if (update_vbat) { |
1103 | /* Cleared after each update, so reenable. Value | 1103 | /* Cleared after each update, so reenable. Value |
1104 | returned by this read will be previous value */ | 1104 | returned by this read will be previous value */ |
1105 | it87_write_value(client, IT87_REG_CONFIG, | 1105 | it87_write_value(client, IT87_REG_CONFIG, |
1106 | it87_read_value(client, IT87_REG_CONFIG) | 0x40); | 1106 | it87_read_value(client, IT87_REG_CONFIG) | 0x40); |
1107 | } | 1107 | } |
1108 | for (i = 0; i <= 7; i++) { | 1108 | for (i = 0; i <= 7; i++) { |
1109 | data->in[i] = | 1109 | data->in[i] = |
1110 | it87_read_value(client, IT87_REG_VIN(i)); | 1110 | it87_read_value(client, IT87_REG_VIN(i)); |
1111 | data->in_min[i] = | 1111 | data->in_min[i] = |
1112 | it87_read_value(client, IT87_REG_VIN_MIN(i)); | 1112 | it87_read_value(client, IT87_REG_VIN_MIN(i)); |
1113 | data->in_max[i] = | 1113 | data->in_max[i] = |
1114 | it87_read_value(client, IT87_REG_VIN_MAX(i)); | 1114 | it87_read_value(client, IT87_REG_VIN_MAX(i)); |
1115 | } | 1115 | } |
1116 | data->in[8] = | 1116 | data->in[8] = |
1117 | it87_read_value(client, IT87_REG_VIN(8)); | 1117 | it87_read_value(client, IT87_REG_VIN(8)); |
1118 | /* Temperature sensor doesn't have limit registers, set | 1118 | /* Temperature sensor doesn't have limit registers, set |
1119 | to min and max value */ | 1119 | to min and max value */ |
1120 | data->in_min[8] = 0; | 1120 | data->in_min[8] = 0; |
1121 | data->in_max[8] = 255; | 1121 | data->in_max[8] = 255; |
1122 | 1122 | ||
1123 | for (i = 0; i < 3; i++) { | 1123 | for (i = 0; i < 3; i++) { |
1124 | data->fan[i] = | 1124 | data->fan[i] = |
1125 | it87_read_value(client, IT87_REG_FAN(i)); | 1125 | it87_read_value(client, IT87_REG_FAN(i)); |
1126 | data->fan_min[i] = | 1126 | data->fan_min[i] = |
1127 | it87_read_value(client, IT87_REG_FAN_MIN(i)); | 1127 | it87_read_value(client, IT87_REG_FAN_MIN(i)); |
1128 | } | 1128 | } |
1129 | for (i = 0; i < 3; i++) { | 1129 | for (i = 0; i < 3; i++) { |
1130 | data->temp[i] = | 1130 | data->temp[i] = |
1131 | it87_read_value(client, IT87_REG_TEMP(i)); | 1131 | it87_read_value(client, IT87_REG_TEMP(i)); |
1132 | data->temp_high[i] = | 1132 | data->temp_high[i] = |
1133 | it87_read_value(client, IT87_REG_TEMP_HIGH(i)); | 1133 | it87_read_value(client, IT87_REG_TEMP_HIGH(i)); |
1134 | data->temp_low[i] = | 1134 | data->temp_low[i] = |
1135 | it87_read_value(client, IT87_REG_TEMP_LOW(i)); | 1135 | it87_read_value(client, IT87_REG_TEMP_LOW(i)); |
1136 | } | 1136 | } |
1137 | 1137 | ||
1138 | i = it87_read_value(client, IT87_REG_FAN_DIV); | 1138 | i = it87_read_value(client, IT87_REG_FAN_DIV); |
1139 | data->fan_div[0] = i & 0x07; | 1139 | data->fan_div[0] = i & 0x07; |
1140 | data->fan_div[1] = (i >> 3) & 0x07; | 1140 | data->fan_div[1] = (i >> 3) & 0x07; |
1141 | data->fan_div[2] = (i & 0x40) ? 3 : 1; | 1141 | data->fan_div[2] = (i & 0x40) ? 3 : 1; |
1142 | 1142 | ||
1143 | data->alarms = | 1143 | data->alarms = |
1144 | it87_read_value(client, IT87_REG_ALARM1) | | 1144 | it87_read_value(client, IT87_REG_ALARM1) | |
1145 | (it87_read_value(client, IT87_REG_ALARM2) << 8) | | 1145 | (it87_read_value(client, IT87_REG_ALARM2) << 8) | |
1146 | (it87_read_value(client, IT87_REG_ALARM3) << 16); | 1146 | (it87_read_value(client, IT87_REG_ALARM3) << 16); |
1147 | data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); | 1147 | data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); |
1148 | 1148 | ||
1149 | data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); | 1149 | data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); |
1150 | /* The 8705 does not have VID capability */ | 1150 | /* The 8705 does not have VID capability */ |
1151 | if (data->type == it8712) { | 1151 | if (data->type == it8712) { |
1152 | data->vid = it87_read_value(client, IT87_REG_VID); | 1152 | data->vid = it87_read_value(client, IT87_REG_VID); |
1153 | data->vid &= 0x1f; | 1153 | data->vid &= 0x1f; |
1154 | } | 1154 | } |
1155 | data->last_updated = jiffies; | 1155 | data->last_updated = jiffies; |
1156 | data->valid = 1; | 1156 | data->valid = 1; |
1157 | } | 1157 | } |
1158 | 1158 | ||
1159 | up(&data->update_lock); | 1159 | up(&data->update_lock); |
1160 | 1160 | ||
1161 | return data; | 1161 | return data; |
1162 | } | 1162 | } |
1163 | 1163 | ||
1164 | static int __init sm_it87_init(void) | 1164 | static int __init sm_it87_init(void) |
1165 | { | 1165 | { |
1166 | int res; | 1166 | int res; |
1167 | 1167 | ||
1168 | res = i2c_add_driver(&it87_driver); | 1168 | res = i2c_add_driver(&it87_driver); |
1169 | if (res) | 1169 | if (res) |
1170 | return res; | 1170 | return res; |
1171 | 1171 | ||
1172 | if (!it87_find(&isa_address)) { | 1172 | if (!it87_find(&isa_address)) { |
1173 | res = i2c_isa_add_driver(&it87_isa_driver); | 1173 | res = i2c_isa_add_driver(&it87_isa_driver); |
1174 | if (res) { | 1174 | if (res) { |
1175 | i2c_del_driver(&it87_driver); | 1175 | i2c_del_driver(&it87_driver); |
1176 | return res; | 1176 | return res; |
1177 | } | 1177 | } |
1178 | } | 1178 | } |
1179 | 1179 | ||
1180 | return 0; | 1180 | return 0; |
1181 | } | 1181 | } |
1182 | 1182 | ||
1183 | static void __exit sm_it87_exit(void) | 1183 | static void __exit sm_it87_exit(void) |
1184 | { | 1184 | { |
1185 | i2c_isa_del_driver(&it87_isa_driver); | 1185 | i2c_isa_del_driver(&it87_isa_driver); |
1186 | i2c_del_driver(&it87_driver); | 1186 | i2c_del_driver(&it87_driver); |
1187 | } | 1187 | } |
1188 | 1188 | ||
1189 | 1189 | ||
1190 | MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>"); | 1190 | MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>"); |
1191 | MODULE_DESCRIPTION("IT8705F, IT8712F, Sis950 driver"); | 1191 | MODULE_DESCRIPTION("IT8705F, IT8712F, Sis950 driver"); |
1192 | module_param(update_vbat, bool, 0); | 1192 | module_param(update_vbat, bool, 0); |
1193 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); | 1193 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); |
1194 | module_param(fix_pwm_polarity, bool, 0); | 1194 | module_param(fix_pwm_polarity, bool, 0); |
1195 | MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)"); | 1195 | MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)"); |
1196 | MODULE_LICENSE("GPL"); | 1196 | MODULE_LICENSE("GPL"); |
1197 | 1197 | ||
1198 | module_init(sm_it87_init); | 1198 | module_init(sm_it87_init); |
1199 | module_exit(sm_it87_exit); | 1199 | module_exit(sm_it87_exit); |
1200 | 1200 |