]>
Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
5f2dc798 JD |
2 | * it87.c - Part of lm_sensors, Linux kernel modules for hardware |
3 | * monitoring. | |
4 | * | |
5 | * The IT8705F is an LPC-based Super I/O part that contains UARTs, a | |
6 | * parallel port, an IR port, a MIDI port, a floppy controller, etc., in | |
7 | * addition to an Environment Controller (Enhanced Hardware Monitor and | |
8 | * Fan Controller) | |
9 | * | |
10 | * This driver supports only the Environment Controller in the IT8705F and | |
11 | * similar parts. The other devices are supported by different drivers. | |
12 | * | |
13 | * Supports: IT8705F Super I/O chip w/LPC interface | |
14 | * IT8712F Super I/O chip w/LPC interface | |
15 | * IT8716F Super I/O chip w/LPC interface | |
16 | * IT8718F Super I/O chip w/LPC interface | |
17 | * IT8720F Super I/O chip w/LPC interface | |
18 | * IT8726F Super I/O chip w/LPC interface | |
19 | * Sis950 A clone of the IT8705F | |
20 | * | |
21 | * Copyright (C) 2001 Chris Gauthron | |
22 | * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org> | |
23 | * | |
24 | * This program is free software; you can redistribute it and/or modify | |
25 | * it under the terms of the GNU General Public License as published by | |
26 | * the Free Software Foundation; either version 2 of the License, or | |
27 | * (at your option) any later version. | |
28 | * | |
29 | * This program is distributed in the hope that it will be useful, | |
30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
32 | * GNU General Public License for more details. | |
33 | * | |
34 | * You should have received a copy of the GNU General Public License | |
35 | * along with this program; if not, write to the Free Software | |
36 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
37 | */ | |
1da177e4 | 38 | |
1da177e4 LT |
39 | #include <linux/module.h> |
40 | #include <linux/init.h> | |
41 | #include <linux/slab.h> | |
42 | #include <linux/jiffies.h> | |
b74f3fdd | 43 | #include <linux/platform_device.h> |
943b0830 | 44 | #include <linux/hwmon.h> |
303760b4 JD |
45 | #include <linux/hwmon-sysfs.h> |
46 | #include <linux/hwmon-vid.h> | |
943b0830 | 47 | #include <linux/err.h> |
9a61bf63 | 48 | #include <linux/mutex.h> |
87808be4 | 49 | #include <linux/sysfs.h> |
98dd22c3 JD |
50 | #include <linux/string.h> |
51 | #include <linux/dmi.h> | |
b9acb64a | 52 | #include <linux/acpi.h> |
6055fae8 | 53 | #include <linux/io.h> |
1da177e4 | 54 | |
b74f3fdd | 55 | #define DRVNAME "it87" |
1da177e4 | 56 | |
b4da93e4 | 57 | enum chips { it87, it8712, it8716, it8718, it8720 }; |
1da177e4 | 58 | |
67b671bc JD |
59 | static unsigned short force_id; |
60 | module_param(force_id, ushort, 0); | |
61 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); | |
62 | ||
b74f3fdd | 63 | static struct platform_device *pdev; |
64 | ||
1da177e4 LT |
65 | #define REG 0x2e /* The register to read/write */ |
66 | #define DEV 0x07 /* Register: Logical device select */ | |
67 | #define VAL 0x2f /* The value to read/write */ | |
68 | #define PME 0x04 /* The device with the fan registers in it */ | |
b4da93e4 JMS |
69 | |
70 | /* The device with the IT8718F/IT8720F VID value in it */ | |
71 | #define GPIO 0x07 | |
72 | ||
1da177e4 LT |
73 | #define DEVID 0x20 /* Register: Device ID */ |
74 | #define DEVREV 0x22 /* Register: Device Revision */ | |
75 | ||
76 | static inline int | |
77 | superio_inb(int reg) | |
78 | { | |
79 | outb(reg, REG); | |
80 | return inb(VAL); | |
81 | } | |
82 | ||
436cad2a JD |
83 | static inline void |
84 | superio_outb(int reg, int val) | |
85 | { | |
86 | outb(reg, REG); | |
87 | outb(val, VAL); | |
88 | } | |
89 | ||
1da177e4 LT |
90 | static int superio_inw(int reg) |
91 | { | |
92 | int val; | |
93 | outb(reg++, REG); | |
94 | val = inb(VAL) << 8; | |
95 | outb(reg, REG); | |
96 | val |= inb(VAL); | |
97 | return val; | |
98 | } | |
99 | ||
100 | static inline void | |
87673dd7 | 101 | superio_select(int ldn) |
1da177e4 LT |
102 | { |
103 | outb(DEV, REG); | |
87673dd7 | 104 | outb(ldn, VAL); |
1da177e4 LT |
105 | } |
106 | ||
107 | static inline void | |
108 | superio_enter(void) | |
109 | { | |
110 | outb(0x87, REG); | |
111 | outb(0x01, REG); | |
112 | outb(0x55, REG); | |
113 | outb(0x55, REG); | |
114 | } | |
115 | ||
116 | static inline void | |
117 | superio_exit(void) | |
118 | { | |
119 | outb(0x02, REG); | |
120 | outb(0x02, VAL); | |
121 | } | |
122 | ||
87673dd7 | 123 | /* Logical device 4 registers */ |
1da177e4 LT |
124 | #define IT8712F_DEVID 0x8712 |
125 | #define IT8705F_DEVID 0x8705 | |
17d648bf | 126 | #define IT8716F_DEVID 0x8716 |
87673dd7 | 127 | #define IT8718F_DEVID 0x8718 |
b4da93e4 | 128 | #define IT8720F_DEVID 0x8720 |
08a8f6e9 | 129 | #define IT8726F_DEVID 0x8726 |
1da177e4 LT |
130 | #define IT87_ACT_REG 0x30 |
131 | #define IT87_BASE_REG 0x60 | |
132 | ||
87673dd7 | 133 | /* Logical device 7 registers (IT8712F and later) */ |
895ff267 | 134 | #define IT87_SIO_GPIO3_REG 0x27 |
591ec650 | 135 | #define IT87_SIO_GPIO5_REG 0x29 |
87673dd7 JD |
136 | #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */ |
137 | #define IT87_SIO_VID_REG 0xfc /* VID value */ | |
d9b327c3 | 138 | #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */ |
87673dd7 | 139 | |
1da177e4 LT |
140 | /* Update battery voltage after every reading if true */ |
141 | static int update_vbat; | |
142 | ||
143 | /* Not all BIOSes properly configure the PWM registers */ | |
144 | static int fix_pwm_polarity; | |
145 | ||
1da177e4 LT |
146 | /* Many IT87 constants specified below */ |
147 | ||
148 | /* Length of ISA address segment */ | |
149 | #define IT87_EXTENT 8 | |
150 | ||
87b4b663 BH |
151 | /* Length of ISA address segment for Environmental Controller */ |
152 | #define IT87_EC_EXTENT 2 | |
153 | ||
154 | /* Offset of EC registers from ISA base address */ | |
155 | #define IT87_EC_OFFSET 5 | |
156 | ||
157 | /* Where are the ISA address/data registers relative to the EC base address */ | |
158 | #define IT87_ADDR_REG_OFFSET 0 | |
159 | #define IT87_DATA_REG_OFFSET 1 | |
1da177e4 LT |
160 | |
161 | /*----- The IT87 registers -----*/ | |
162 | ||
163 | #define IT87_REG_CONFIG 0x00 | |
164 | ||
165 | #define IT87_REG_ALARM1 0x01 | |
166 | #define IT87_REG_ALARM2 0x02 | |
167 | #define IT87_REG_ALARM3 0x03 | |
168 | ||
b4da93e4 JMS |
169 | /* The IT8718F and IT8720F have the VID value in a different register, in |
170 | Super-I/O configuration space. */ | |
1da177e4 | 171 | #define IT87_REG_VID 0x0a |
0475169c AP |
172 | /* The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b |
173 | for fan divisors. Later IT8712F revisions must use 16-bit tachometer | |
174 | mode. */ | |
1da177e4 | 175 | #define IT87_REG_FAN_DIV 0x0b |
17d648bf | 176 | #define IT87_REG_FAN_16BIT 0x0c |
1da177e4 LT |
177 | |
178 | /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */ | |
179 | ||
c7f1f716 JD |
180 | static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 }; |
181 | static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 }; | |
182 | static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 }; | |
183 | static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 }; | |
1da177e4 LT |
184 | #define IT87_REG_FAN_MAIN_CTRL 0x13 |
185 | #define IT87_REG_FAN_CTL 0x14 | |
186 | #define IT87_REG_PWM(nr) (0x15 + (nr)) | |
187 | ||
188 | #define IT87_REG_VIN(nr) (0x20 + (nr)) | |
189 | #define IT87_REG_TEMP(nr) (0x29 + (nr)) | |
190 | ||
191 | #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2) | |
192 | #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2) | |
193 | #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) | |
194 | #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) | |
195 | ||
1da177e4 LT |
196 | #define IT87_REG_VIN_ENABLE 0x50 |
197 | #define IT87_REG_TEMP_ENABLE 0x51 | |
d9b327c3 | 198 | #define IT87_REG_BEEP_ENABLE 0x5c |
1da177e4 LT |
199 | |
200 | #define IT87_REG_CHIPID 0x58 | |
201 | ||
4f3f51bc JD |
202 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) |
203 | #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) | |
204 | ||
1da177e4 | 205 | |
b74f3fdd | 206 | struct it87_sio_data { |
207 | enum chips type; | |
208 | /* Values read from Super-I/O config space */ | |
0475169c | 209 | u8 revision; |
b74f3fdd | 210 | u8 vid_value; |
d9b327c3 | 211 | u8 beep_pin; |
738e5e05 | 212 | u8 internal; /* Internal sensors can be labeled */ |
591ec650 | 213 | /* Features skipped based on config or DMI */ |
895ff267 | 214 | u8 skip_vid; |
591ec650 | 215 | u8 skip_fan; |
98dd22c3 | 216 | u8 skip_pwm; |
b74f3fdd | 217 | }; |
218 | ||
ed6bafbf JD |
219 | /* For each registered chip, we need to keep some data in memory. |
220 | The structure is dynamically allocated. */ | |
1da177e4 | 221 | struct it87_data { |
1beeffe4 | 222 | struct device *hwmon_dev; |
1da177e4 | 223 | enum chips type; |
0475169c | 224 | u8 revision; |
1da177e4 | 225 | |
b74f3fdd | 226 | unsigned short addr; |
227 | const char *name; | |
9a61bf63 | 228 | struct mutex update_lock; |
1da177e4 LT |
229 | char valid; /* !=0 if following fields are valid */ |
230 | unsigned long last_updated; /* In jiffies */ | |
231 | ||
232 | u8 in[9]; /* Register value */ | |
3543a53f JD |
233 | u8 in_max[8]; /* Register value */ |
234 | u8 in_min[8]; /* Register value */ | |
9060f8bd | 235 | u8 has_fan; /* Bitfield, fans enabled */ |
c7f1f716 JD |
236 | u16 fan[5]; /* Register values, possibly combined */ |
237 | u16 fan_min[5]; /* Register values, possibly combined */ | |
e267d250 JD |
238 | s8 temp[3]; /* Register value */ |
239 | s8 temp_high[3]; /* Register value */ | |
240 | s8 temp_low[3]; /* Register value */ | |
1da177e4 LT |
241 | u8 sensor; /* Register value */ |
242 | u8 fan_div[3]; /* Register encoding, shifted right */ | |
243 | u8 vid; /* Register encoding, combined */ | |
a7be58a1 | 244 | u8 vrm; |
1da177e4 | 245 | u32 alarms; /* Register encoding, combined */ |
d9b327c3 | 246 | u8 beeps; /* Register encoding */ |
1da177e4 | 247 | u8 fan_main_ctrl; /* Register value */ |
f8d0c19a | 248 | u8 fan_ctl; /* Register value */ |
b99883dc JD |
249 | |
250 | /* The following 3 arrays correspond to the same registers. The | |
251 | * meaning of bits 6-0 depends on the value of bit 7, and we want | |
252 | * to preserve settings on mode changes, so we have to track all | |
253 | * values separately. */ | |
254 | u8 pwm_ctrl[3]; /* Register value */ | |
255 | u8 pwm_duty[3]; /* Manual PWM value set by user (bit 6-0) */ | |
256 | u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */ | |
4f3f51bc JD |
257 | |
258 | /* Automatic fan speed control registers */ | |
259 | u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */ | |
260 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ | |
1da177e4 | 261 | }; |
0df6454d JD |
262 | |
263 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255)) | |
264 | #define IN_FROM_REG(val) ((val) * 16) | |
265 | ||
266 | static inline u8 FAN_TO_REG(long rpm, int div) | |
267 | { | |
268 | if (rpm == 0) | |
269 | return 255; | |
270 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | |
271 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, | |
272 | 254); | |
273 | } | |
274 | ||
275 | static inline u16 FAN16_TO_REG(long rpm) | |
276 | { | |
277 | if (rpm == 0) | |
278 | return 0xffff; | |
279 | return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe); | |
280 | } | |
281 | ||
282 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \ | |
283 | 1350000 / ((val) * (div))) | |
284 | /* The divider is fixed to 2 in 16-bit mode */ | |
285 | #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ | |
286 | 1350000 / ((val) * 2)) | |
287 | ||
288 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \ | |
289 | ((val) + 500) / 1000), -128, 127)) | |
290 | #define TEMP_FROM_REG(val) ((val) * 1000) | |
291 | ||
292 | #define PWM_TO_REG(val) ((val) >> 1) | |
293 | #define PWM_FROM_REG(val) (((val) & 0x7f) << 1) | |
294 | ||
295 | static int DIV_TO_REG(int val) | |
296 | { | |
297 | int answer = 0; | |
298 | while (answer < 7 && (val >>= 1)) | |
299 | answer++; | |
300 | return answer; | |
301 | } | |
302 | #define DIV_FROM_REG(val) (1 << (val)) | |
303 | ||
304 | static const unsigned int pwm_freq[8] = { | |
305 | 48000000 / 128, | |
306 | 24000000 / 128, | |
307 | 12000000 / 128, | |
308 | 8000000 / 128, | |
309 | 6000000 / 128, | |
310 | 3000000 / 128, | |
311 | 1500000 / 128, | |
312 | 750000 / 128, | |
313 | }; | |
1da177e4 | 314 | |
0475169c AP |
315 | static inline int has_16bit_fans(const struct it87_data *data) |
316 | { | |
816d8c6a | 317 | /* IT8705F Datasheet 0.4.1, 3h == Version G. |
859b9ef3 | 318 | IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J. |
816d8c6a AP |
319 | These are the first revisions with 16bit tachometer support. */ |
320 | return (data->type == it87 && data->revision >= 0x03) | |
859b9ef3 | 321 | || (data->type == it8712 && data->revision >= 0x08) |
0475169c | 322 | || data->type == it8716 |
b4da93e4 JMS |
323 | || data->type == it8718 |
324 | || data->type == it8720; | |
0475169c | 325 | } |
1da177e4 | 326 | |
4f3f51bc JD |
327 | static inline int has_old_autopwm(const struct it87_data *data) |
328 | { | |
329 | /* The old automatic fan speed control interface is implemented | |
330 | by IT8705F chips up to revision F and IT8712F chips up to | |
331 | revision G. */ | |
332 | return (data->type == it87 && data->revision < 0x03) | |
333 | || (data->type == it8712 && data->revision < 0x08); | |
334 | } | |
335 | ||
b74f3fdd | 336 | static int it87_probe(struct platform_device *pdev); |
d0546128 | 337 | static int __devexit it87_remove(struct platform_device *pdev); |
1da177e4 | 338 | |
b74f3fdd | 339 | static int it87_read_value(struct it87_data *data, u8 reg); |
340 | static void it87_write_value(struct it87_data *data, u8 reg, u8 value); | |
1da177e4 | 341 | static struct it87_data *it87_update_device(struct device *dev); |
b74f3fdd | 342 | static int it87_check_pwm(struct device *dev); |
343 | static void it87_init_device(struct platform_device *pdev); | |
1da177e4 LT |
344 | |
345 | ||
b74f3fdd | 346 | static struct platform_driver it87_driver = { |
cdaf7934 | 347 | .driver = { |
87218842 | 348 | .owner = THIS_MODULE, |
b74f3fdd | 349 | .name = DRVNAME, |
cdaf7934 | 350 | }, |
b74f3fdd | 351 | .probe = it87_probe, |
352 | .remove = __devexit_p(it87_remove), | |
fde09509 JD |
353 | }; |
354 | ||
20ad93d4 JD |
355 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
356 | char *buf) | |
1da177e4 | 357 | { |
20ad93d4 JD |
358 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
359 | int nr = sensor_attr->index; | |
360 | ||
1da177e4 LT |
361 | struct it87_data *data = it87_update_device(dev); |
362 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); | |
363 | } | |
364 | ||
20ad93d4 JD |
365 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
366 | char *buf) | |
1da177e4 | 367 | { |
20ad93d4 JD |
368 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
369 | int nr = sensor_attr->index; | |
370 | ||
1da177e4 LT |
371 | struct it87_data *data = it87_update_device(dev); |
372 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); | |
373 | } | |
374 | ||
20ad93d4 JD |
375 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, |
376 | char *buf) | |
1da177e4 | 377 | { |
20ad93d4 JD |
378 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
379 | int nr = sensor_attr->index; | |
380 | ||
1da177e4 LT |
381 | struct it87_data *data = it87_update_device(dev); |
382 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); | |
383 | } | |
384 | ||
20ad93d4 JD |
385 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
386 | const char *buf, size_t count) | |
1da177e4 | 387 | { |
20ad93d4 JD |
388 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
389 | int nr = sensor_attr->index; | |
390 | ||
b74f3fdd | 391 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 JD |
392 | unsigned long val; |
393 | ||
394 | if (strict_strtoul(buf, 10, &val) < 0) | |
395 | return -EINVAL; | |
1da177e4 | 396 | |
9a61bf63 | 397 | mutex_lock(&data->update_lock); |
1da177e4 | 398 | data->in_min[nr] = IN_TO_REG(val); |
b74f3fdd | 399 | it87_write_value(data, IT87_REG_VIN_MIN(nr), |
1da177e4 | 400 | data->in_min[nr]); |
9a61bf63 | 401 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
402 | return count; |
403 | } | |
20ad93d4 JD |
404 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
405 | const char *buf, size_t count) | |
1da177e4 | 406 | { |
20ad93d4 JD |
407 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
408 | int nr = sensor_attr->index; | |
409 | ||
b74f3fdd | 410 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 JD |
411 | unsigned long val; |
412 | ||
413 | if (strict_strtoul(buf, 10, &val) < 0) | |
414 | return -EINVAL; | |
1da177e4 | 415 | |
9a61bf63 | 416 | mutex_lock(&data->update_lock); |
1da177e4 | 417 | data->in_max[nr] = IN_TO_REG(val); |
b74f3fdd | 418 | it87_write_value(data, IT87_REG_VIN_MAX(nr), |
1da177e4 | 419 | data->in_max[nr]); |
9a61bf63 | 420 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
421 | return count; |
422 | } | |
423 | ||
424 | #define show_in_offset(offset) \ | |
20ad93d4 JD |
425 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
426 | show_in, NULL, offset); | |
1da177e4 LT |
427 | |
428 | #define limit_in_offset(offset) \ | |
20ad93d4 JD |
429 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
430 | show_in_min, set_in_min, offset); \ | |
431 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ | |
432 | show_in_max, set_in_max, offset); | |
1da177e4 LT |
433 | |
434 | show_in_offset(0); | |
435 | limit_in_offset(0); | |
436 | show_in_offset(1); | |
437 | limit_in_offset(1); | |
438 | show_in_offset(2); | |
439 | limit_in_offset(2); | |
440 | show_in_offset(3); | |
441 | limit_in_offset(3); | |
442 | show_in_offset(4); | |
443 | limit_in_offset(4); | |
444 | show_in_offset(5); | |
445 | limit_in_offset(5); | |
446 | show_in_offset(6); | |
447 | limit_in_offset(6); | |
448 | show_in_offset(7); | |
449 | limit_in_offset(7); | |
450 | show_in_offset(8); | |
451 | ||
452 | /* 3 temperatures */ | |
20ad93d4 JD |
453 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
454 | char *buf) | |
1da177e4 | 455 | { |
20ad93d4 JD |
456 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
457 | int nr = sensor_attr->index; | |
458 | ||
1da177e4 LT |
459 | struct it87_data *data = it87_update_device(dev); |
460 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); | |
461 | } | |
20ad93d4 JD |
462 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
463 | char *buf) | |
1da177e4 | 464 | { |
20ad93d4 JD |
465 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
466 | int nr = sensor_attr->index; | |
467 | ||
1da177e4 LT |
468 | struct it87_data *data = it87_update_device(dev); |
469 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); | |
470 | } | |
20ad93d4 JD |
471 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
472 | char *buf) | |
1da177e4 | 473 | { |
20ad93d4 JD |
474 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
475 | int nr = sensor_attr->index; | |
476 | ||
1da177e4 LT |
477 | struct it87_data *data = it87_update_device(dev); |
478 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])); | |
479 | } | |
20ad93d4 JD |
480 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
481 | const char *buf, size_t count) | |
1da177e4 | 482 | { |
20ad93d4 JD |
483 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
484 | int nr = sensor_attr->index; | |
485 | ||
b74f3fdd | 486 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 JD |
487 | long val; |
488 | ||
489 | if (strict_strtol(buf, 10, &val) < 0) | |
490 | return -EINVAL; | |
1da177e4 | 491 | |
9a61bf63 | 492 | mutex_lock(&data->update_lock); |
1da177e4 | 493 | data->temp_high[nr] = TEMP_TO_REG(val); |
b74f3fdd | 494 | it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); |
9a61bf63 | 495 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
496 | return count; |
497 | } | |
20ad93d4 JD |
498 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
499 | const char *buf, size_t count) | |
1da177e4 | 500 | { |
20ad93d4 JD |
501 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
502 | int nr = sensor_attr->index; | |
503 | ||
b74f3fdd | 504 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 JD |
505 | long val; |
506 | ||
507 | if (strict_strtol(buf, 10, &val) < 0) | |
508 | return -EINVAL; | |
1da177e4 | 509 | |
9a61bf63 | 510 | mutex_lock(&data->update_lock); |
1da177e4 | 511 | data->temp_low[nr] = TEMP_TO_REG(val); |
b74f3fdd | 512 | it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); |
9a61bf63 | 513 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
514 | return count; |
515 | } | |
516 | #define show_temp_offset(offset) \ | |
20ad93d4 JD |
517 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
518 | show_temp, NULL, offset - 1); \ | |
519 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ | |
520 | show_temp_max, set_temp_max, offset - 1); \ | |
521 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ | |
522 | show_temp_min, set_temp_min, offset - 1); | |
1da177e4 LT |
523 | |
524 | show_temp_offset(1); | |
525 | show_temp_offset(2); | |
526 | show_temp_offset(3); | |
527 | ||
20ad93d4 JD |
528 | static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, |
529 | char *buf) | |
1da177e4 | 530 | { |
20ad93d4 JD |
531 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
532 | int nr = sensor_attr->index; | |
533 | ||
1da177e4 | 534 | struct it87_data *data = it87_update_device(dev); |
5f2dc798 JD |
535 | u8 reg = data->sensor; /* In case the value is updated while |
536 | we use it */ | |
537 | ||
1da177e4 LT |
538 | if (reg & (1 << nr)) |
539 | return sprintf(buf, "3\n"); /* thermal diode */ | |
540 | if (reg & (8 << nr)) | |
4ed10779 | 541 | return sprintf(buf, "4\n"); /* thermistor */ |
1da177e4 LT |
542 | return sprintf(buf, "0\n"); /* disabled */ |
543 | } | |
20ad93d4 JD |
544 | static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, |
545 | const char *buf, size_t count) | |
1da177e4 | 546 | { |
20ad93d4 JD |
547 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
548 | int nr = sensor_attr->index; | |
549 | ||
b74f3fdd | 550 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 | 551 | long val; |
8acf07c5 | 552 | u8 reg; |
f5f64501 JD |
553 | |
554 | if (strict_strtol(buf, 10, &val) < 0) | |
555 | return -EINVAL; | |
1da177e4 | 556 | |
8acf07c5 JD |
557 | reg = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
558 | reg &= ~(1 << nr); | |
559 | reg &= ~(8 << nr); | |
4ed10779 JD |
560 | if (val == 2) { /* backwards compatibility */ |
561 | dev_warn(dev, "Sensor type 2 is deprecated, please use 4 " | |
562 | "instead\n"); | |
563 | val = 4; | |
564 | } | |
565 | /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ | |
1da177e4 | 566 | if (val == 3) |
8acf07c5 | 567 | reg |= 1 << nr; |
4ed10779 | 568 | else if (val == 4) |
8acf07c5 JD |
569 | reg |= 8 << nr; |
570 | else if (val != 0) | |
1da177e4 | 571 | return -EINVAL; |
8acf07c5 JD |
572 | |
573 | mutex_lock(&data->update_lock); | |
574 | data->sensor = reg; | |
b74f3fdd | 575 | it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); |
2b3d1d87 | 576 | data->valid = 0; /* Force cache refresh */ |
9a61bf63 | 577 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
578 | return count; |
579 | } | |
580 | #define show_sensor_offset(offset) \ | |
20ad93d4 JD |
581 | static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ |
582 | show_sensor, set_sensor, offset - 1); | |
1da177e4 LT |
583 | |
584 | show_sensor_offset(1); | |
585 | show_sensor_offset(2); | |
586 | show_sensor_offset(3); | |
587 | ||
588 | /* 3 Fans */ | |
b99883dc JD |
589 | |
590 | static int pwm_mode(const struct it87_data *data, int nr) | |
591 | { | |
592 | int ctrl = data->fan_main_ctrl & (1 << nr); | |
593 | ||
594 | if (ctrl == 0) /* Full speed */ | |
595 | return 0; | |
596 | if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ | |
597 | return 2; | |
598 | else /* Manual mode */ | |
599 | return 1; | |
600 | } | |
601 | ||
20ad93d4 JD |
602 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
603 | char *buf) | |
1da177e4 | 604 | { |
20ad93d4 JD |
605 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
606 | int nr = sensor_attr->index; | |
607 | ||
1da177e4 | 608 | struct it87_data *data = it87_update_device(dev); |
5f2dc798 | 609 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
1da177e4 LT |
610 | DIV_FROM_REG(data->fan_div[nr]))); |
611 | } | |
20ad93d4 JD |
612 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
613 | char *buf) | |
1da177e4 | 614 | { |
20ad93d4 JD |
615 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
616 | int nr = sensor_attr->index; | |
617 | ||
1da177e4 | 618 | struct it87_data *data = it87_update_device(dev); |
5f2dc798 JD |
619 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], |
620 | DIV_FROM_REG(data->fan_div[nr]))); | |
1da177e4 | 621 | } |
20ad93d4 JD |
622 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
623 | char *buf) | |
1da177e4 | 624 | { |
20ad93d4 JD |
625 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
626 | int nr = sensor_attr->index; | |
627 | ||
1da177e4 LT |
628 | struct it87_data *data = it87_update_device(dev); |
629 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); | |
630 | } | |
5f2dc798 JD |
631 | static ssize_t show_pwm_enable(struct device *dev, |
632 | struct device_attribute *attr, char *buf) | |
1da177e4 | 633 | { |
20ad93d4 JD |
634 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
635 | int nr = sensor_attr->index; | |
636 | ||
1da177e4 | 637 | struct it87_data *data = it87_update_device(dev); |
b99883dc | 638 | return sprintf(buf, "%d\n", pwm_mode(data, nr)); |
1da177e4 | 639 | } |
20ad93d4 JD |
640 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
641 | char *buf) | |
1da177e4 | 642 | { |
20ad93d4 JD |
643 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
644 | int nr = sensor_attr->index; | |
645 | ||
1da177e4 | 646 | struct it87_data *data = it87_update_device(dev); |
b99883dc | 647 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm_duty[nr])); |
1da177e4 | 648 | } |
f8d0c19a JD |
649 | static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, |
650 | char *buf) | |
651 | { | |
652 | struct it87_data *data = it87_update_device(dev); | |
653 | int index = (data->fan_ctl >> 4) & 0x07; | |
654 | ||
655 | return sprintf(buf, "%u\n", pwm_freq[index]); | |
656 | } | |
20ad93d4 JD |
657 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
658 | const char *buf, size_t count) | |
1da177e4 | 659 | { |
20ad93d4 JD |
660 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
661 | int nr = sensor_attr->index; | |
662 | ||
b74f3fdd | 663 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 | 664 | long val; |
7f999aa7 | 665 | u8 reg; |
1da177e4 | 666 | |
f5f64501 JD |
667 | if (strict_strtol(buf, 10, &val) < 0) |
668 | return -EINVAL; | |
669 | ||
9a61bf63 | 670 | mutex_lock(&data->update_lock); |
b74f3fdd | 671 | reg = it87_read_value(data, IT87_REG_FAN_DIV); |
07eab46d | 672 | switch (nr) { |
5f2dc798 JD |
673 | case 0: |
674 | data->fan_div[nr] = reg & 0x07; | |
675 | break; | |
676 | case 1: | |
677 | data->fan_div[nr] = (reg >> 3) & 0x07; | |
678 | break; | |
679 | case 2: | |
680 | data->fan_div[nr] = (reg & 0x40) ? 3 : 1; | |
681 | break; | |
07eab46d JD |
682 | } |
683 | ||
1da177e4 | 684 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
c7f1f716 | 685 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]); |
9a61bf63 | 686 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
687 | return count; |
688 | } | |
20ad93d4 JD |
689 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
690 | const char *buf, size_t count) | |
1da177e4 | 691 | { |
20ad93d4 JD |
692 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
693 | int nr = sensor_attr->index; | |
694 | ||
b74f3fdd | 695 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 | 696 | unsigned long val; |
8ab4ec3e | 697 | int min; |
1da177e4 LT |
698 | u8 old; |
699 | ||
f5f64501 JD |
700 | if (strict_strtoul(buf, 10, &val) < 0) |
701 | return -EINVAL; | |
702 | ||
9a61bf63 | 703 | mutex_lock(&data->update_lock); |
b74f3fdd | 704 | old = it87_read_value(data, IT87_REG_FAN_DIV); |
1da177e4 | 705 | |
8ab4ec3e JD |
706 | /* Save fan min limit */ |
707 | min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); | |
1da177e4 LT |
708 | |
709 | switch (nr) { | |
710 | case 0: | |
711 | case 1: | |
712 | data->fan_div[nr] = DIV_TO_REG(val); | |
713 | break; | |
714 | case 2: | |
715 | if (val < 8) | |
716 | data->fan_div[nr] = 1; | |
717 | else | |
718 | data->fan_div[nr] = 3; | |
719 | } | |
720 | val = old & 0x80; | |
721 | val |= (data->fan_div[0] & 0x07); | |
722 | val |= (data->fan_div[1] & 0x07) << 3; | |
723 | if (data->fan_div[2] == 3) | |
724 | val |= 0x1 << 6; | |
b74f3fdd | 725 | it87_write_value(data, IT87_REG_FAN_DIV, val); |
1da177e4 | 726 | |
8ab4ec3e JD |
727 | /* Restore fan min limit */ |
728 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); | |
c7f1f716 | 729 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]); |
8ab4ec3e | 730 | |
9a61bf63 | 731 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
732 | return count; |
733 | } | |
cccfc9c4 JD |
734 | |
735 | /* Returns 0 if OK, -EINVAL otherwise */ | |
736 | static int check_trip_points(struct device *dev, int nr) | |
737 | { | |
738 | const struct it87_data *data = dev_get_drvdata(dev); | |
739 | int i, err = 0; | |
740 | ||
741 | if (has_old_autopwm(data)) { | |
742 | for (i = 0; i < 3; i++) { | |
743 | if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) | |
744 | err = -EINVAL; | |
745 | } | |
746 | for (i = 0; i < 2; i++) { | |
747 | if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1]) | |
748 | err = -EINVAL; | |
749 | } | |
750 | } | |
751 | ||
752 | if (err) { | |
753 | dev_err(dev, "Inconsistent trip points, not switching to " | |
754 | "automatic mode\n"); | |
755 | dev_err(dev, "Adjust the trip points and try again\n"); | |
756 | } | |
757 | return err; | |
758 | } | |
759 | ||
20ad93d4 JD |
760 | static ssize_t set_pwm_enable(struct device *dev, |
761 | struct device_attribute *attr, const char *buf, size_t count) | |
1da177e4 | 762 | { |
20ad93d4 JD |
763 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
764 | int nr = sensor_attr->index; | |
765 | ||
b74f3fdd | 766 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 | 767 | long val; |
1da177e4 | 768 | |
f5f64501 | 769 | if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2) |
b99883dc JD |
770 | return -EINVAL; |
771 | ||
cccfc9c4 JD |
772 | /* Check trip points before switching to automatic mode */ |
773 | if (val == 2) { | |
774 | if (check_trip_points(dev, nr) < 0) | |
775 | return -EINVAL; | |
776 | } | |
777 | ||
9a61bf63 | 778 | mutex_lock(&data->update_lock); |
1da177e4 LT |
779 | |
780 | if (val == 0) { | |
781 | int tmp; | |
782 | /* make sure the fan is on when in on/off mode */ | |
b74f3fdd | 783 | tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
784 | it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); | |
1da177e4 LT |
785 | /* set on/off mode */ |
786 | data->fan_main_ctrl &= ~(1 << nr); | |
5f2dc798 JD |
787 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
788 | data->fan_main_ctrl); | |
b99883dc JD |
789 | } else { |
790 | if (val == 1) /* Manual mode */ | |
791 | data->pwm_ctrl[nr] = data->pwm_duty[nr]; | |
792 | else /* Automatic mode */ | |
793 | data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; | |
794 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); | |
1da177e4 LT |
795 | /* set SmartGuardian mode */ |
796 | data->fan_main_ctrl |= (1 << nr); | |
5f2dc798 JD |
797 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
798 | data->fan_main_ctrl); | |
1da177e4 LT |
799 | } |
800 | ||
9a61bf63 | 801 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
802 | return count; |
803 | } | |
20ad93d4 JD |
804 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
805 | const char *buf, size_t count) | |
1da177e4 | 806 | { |
20ad93d4 JD |
807 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
808 | int nr = sensor_attr->index; | |
809 | ||
b74f3fdd | 810 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 | 811 | long val; |
1da177e4 | 812 | |
f5f64501 | 813 | if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255) |
1da177e4 LT |
814 | return -EINVAL; |
815 | ||
9a61bf63 | 816 | mutex_lock(&data->update_lock); |
b99883dc JD |
817 | data->pwm_duty[nr] = PWM_TO_REG(val); |
818 | /* If we are in manual mode, write the duty cycle immediately; | |
819 | * otherwise, just store it for later use. */ | |
820 | if (!(data->pwm_ctrl[nr] & 0x80)) { | |
821 | data->pwm_ctrl[nr] = data->pwm_duty[nr]; | |
822 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); | |
823 | } | |
9a61bf63 | 824 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
825 | return count; |
826 | } | |
f8d0c19a JD |
827 | static ssize_t set_pwm_freq(struct device *dev, |
828 | struct device_attribute *attr, const char *buf, size_t count) | |
829 | { | |
b74f3fdd | 830 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 | 831 | unsigned long val; |
f8d0c19a JD |
832 | int i; |
833 | ||
f5f64501 JD |
834 | if (strict_strtoul(buf, 10, &val) < 0) |
835 | return -EINVAL; | |
836 | ||
f8d0c19a JD |
837 | /* Search for the nearest available frequency */ |
838 | for (i = 0; i < 7; i++) { | |
839 | if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2) | |
840 | break; | |
841 | } | |
842 | ||
843 | mutex_lock(&data->update_lock); | |
b74f3fdd | 844 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f; |
f8d0c19a | 845 | data->fan_ctl |= i << 4; |
b74f3fdd | 846 | it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); |
f8d0c19a JD |
847 | mutex_unlock(&data->update_lock); |
848 | ||
849 | return count; | |
850 | } | |
94ac7ee6 JD |
851 | static ssize_t show_pwm_temp_map(struct device *dev, |
852 | struct device_attribute *attr, char *buf) | |
853 | { | |
854 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | |
855 | int nr = sensor_attr->index; | |
856 | ||
857 | struct it87_data *data = it87_update_device(dev); | |
858 | int map; | |
859 | ||
860 | if (data->pwm_temp_map[nr] < 3) | |
861 | map = 1 << data->pwm_temp_map[nr]; | |
862 | else | |
863 | map = 0; /* Should never happen */ | |
864 | return sprintf(buf, "%d\n", map); | |
865 | } | |
866 | static ssize_t set_pwm_temp_map(struct device *dev, | |
867 | struct device_attribute *attr, const char *buf, size_t count) | |
868 | { | |
869 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | |
870 | int nr = sensor_attr->index; | |
871 | ||
872 | struct it87_data *data = dev_get_drvdata(dev); | |
873 | long val; | |
874 | u8 reg; | |
875 | ||
4f3f51bc JD |
876 | /* This check can go away if we ever support automatic fan speed |
877 | control on newer chips. */ | |
878 | if (!has_old_autopwm(data)) { | |
879 | dev_notice(dev, "Mapping change disabled for safety reasons\n"); | |
880 | return -EINVAL; | |
881 | } | |
882 | ||
94ac7ee6 JD |
883 | if (strict_strtol(buf, 10, &val) < 0) |
884 | return -EINVAL; | |
885 | ||
886 | switch (val) { | |
887 | case (1 << 0): | |
888 | reg = 0x00; | |
889 | break; | |
890 | case (1 << 1): | |
891 | reg = 0x01; | |
892 | break; | |
893 | case (1 << 2): | |
894 | reg = 0x02; | |
895 | break; | |
896 | default: | |
897 | return -EINVAL; | |
898 | } | |
899 | ||
900 | mutex_lock(&data->update_lock); | |
901 | data->pwm_temp_map[nr] = reg; | |
902 | /* If we are in automatic mode, write the temp mapping immediately; | |
903 | * otherwise, just store it for later use. */ | |
904 | if (data->pwm_ctrl[nr] & 0x80) { | |
905 | data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; | |
906 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); | |
907 | } | |
908 | mutex_unlock(&data->update_lock); | |
909 | return count; | |
910 | } | |
1da177e4 | 911 | |
4f3f51bc JD |
912 | static ssize_t show_auto_pwm(struct device *dev, |
913 | struct device_attribute *attr, char *buf) | |
914 | { | |
915 | struct it87_data *data = it87_update_device(dev); | |
916 | struct sensor_device_attribute_2 *sensor_attr = | |
917 | to_sensor_dev_attr_2(attr); | |
918 | int nr = sensor_attr->nr; | |
919 | int point = sensor_attr->index; | |
920 | ||
921 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->auto_pwm[nr][point])); | |
922 | } | |
923 | ||
924 | static ssize_t set_auto_pwm(struct device *dev, | |
925 | struct device_attribute *attr, const char *buf, size_t count) | |
926 | { | |
927 | struct it87_data *data = dev_get_drvdata(dev); | |
928 | struct sensor_device_attribute_2 *sensor_attr = | |
929 | to_sensor_dev_attr_2(attr); | |
930 | int nr = sensor_attr->nr; | |
931 | int point = sensor_attr->index; | |
932 | long val; | |
933 | ||
934 | if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255) | |
935 | return -EINVAL; | |
936 | ||
937 | mutex_lock(&data->update_lock); | |
938 | data->auto_pwm[nr][point] = PWM_TO_REG(val); | |
939 | it87_write_value(data, IT87_REG_AUTO_PWM(nr, point), | |
940 | data->auto_pwm[nr][point]); | |
941 | mutex_unlock(&data->update_lock); | |
942 | return count; | |
943 | } | |
944 | ||
945 | static ssize_t show_auto_temp(struct device *dev, | |
946 | struct device_attribute *attr, char *buf) | |
947 | { | |
948 | struct it87_data *data = it87_update_device(dev); | |
949 | struct sensor_device_attribute_2 *sensor_attr = | |
950 | to_sensor_dev_attr_2(attr); | |
951 | int nr = sensor_attr->nr; | |
952 | int point = sensor_attr->index; | |
953 | ||
954 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point])); | |
955 | } | |
956 | ||
957 | static ssize_t set_auto_temp(struct device *dev, | |
958 | struct device_attribute *attr, const char *buf, size_t count) | |
959 | { | |
960 | struct it87_data *data = dev_get_drvdata(dev); | |
961 | struct sensor_device_attribute_2 *sensor_attr = | |
962 | to_sensor_dev_attr_2(attr); | |
963 | int nr = sensor_attr->nr; | |
964 | int point = sensor_attr->index; | |
965 | long val; | |
966 | ||
967 | if (strict_strtol(buf, 10, &val) < 0 || val < -128000 || val > 127000) | |
968 | return -EINVAL; | |
969 | ||
970 | mutex_lock(&data->update_lock); | |
971 | data->auto_temp[nr][point] = TEMP_TO_REG(val); | |
972 | it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), | |
973 | data->auto_temp[nr][point]); | |
974 | mutex_unlock(&data->update_lock); | |
975 | return count; | |
976 | } | |
977 | ||
20ad93d4 JD |
978 | #define show_fan_offset(offset) \ |
979 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ | |
980 | show_fan, NULL, offset - 1); \ | |
981 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | |
982 | show_fan_min, set_fan_min, offset - 1); \ | |
983 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ | |
984 | show_fan_div, set_fan_div, offset - 1); | |
1da177e4 LT |
985 | |
986 | show_fan_offset(1); | |
987 | show_fan_offset(2); | |
988 | show_fan_offset(3); | |
989 | ||
990 | #define show_pwm_offset(offset) \ | |
20ad93d4 JD |
991 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ |
992 | show_pwm_enable, set_pwm_enable, offset - 1); \ | |
993 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ | |
f8d0c19a JD |
994 | show_pwm, set_pwm, offset - 1); \ |
995 | static DEVICE_ATTR(pwm##offset##_freq, \ | |
996 | (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \ | |
94ac7ee6 JD |
997 | show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \ |
998 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \ | |
4f3f51bc JD |
999 | S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \ |
1000 | offset - 1); \ | |
1001 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \ | |
1002 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ | |
1003 | offset - 1, 0); \ | |
1004 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \ | |
1005 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ | |
1006 | offset - 1, 1); \ | |
1007 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \ | |
1008 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ | |
1009 | offset - 1, 2); \ | |
1010 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \ | |
1011 | S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \ | |
1012 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \ | |
1013 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ | |
1014 | offset - 1, 1); \ | |
1015 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \ | |
1016 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ | |
1017 | offset - 1, 0); \ | |
1018 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \ | |
1019 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ | |
1020 | offset - 1, 2); \ | |
1021 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \ | |
1022 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ | |
1023 | offset - 1, 3); \ | |
1024 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \ | |
1025 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ | |
1026 | offset - 1, 4); | |
1da177e4 LT |
1027 | |
1028 | show_pwm_offset(1); | |
1029 | show_pwm_offset(2); | |
1030 | show_pwm_offset(3); | |
1031 | ||
17d648bf JD |
1032 | /* A different set of callbacks for 16-bit fans */ |
1033 | static ssize_t show_fan16(struct device *dev, struct device_attribute *attr, | |
1034 | char *buf) | |
1035 | { | |
1036 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | |
1037 | int nr = sensor_attr->index; | |
1038 | struct it87_data *data = it87_update_device(dev); | |
1039 | return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr])); | |
1040 | } | |
1041 | ||
1042 | static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr, | |
1043 | char *buf) | |
1044 | { | |
1045 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | |
1046 | int nr = sensor_attr->index; | |
1047 | struct it87_data *data = it87_update_device(dev); | |
1048 | return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr])); | |
1049 | } | |
1050 | ||
1051 | static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr, | |
1052 | const char *buf, size_t count) | |
1053 | { | |
1054 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); | |
1055 | int nr = sensor_attr->index; | |
b74f3fdd | 1056 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 JD |
1057 | long val; |
1058 | ||
1059 | if (strict_strtol(buf, 10, &val) < 0) | |
1060 | return -EINVAL; | |
17d648bf JD |
1061 | |
1062 | mutex_lock(&data->update_lock); | |
1063 | data->fan_min[nr] = FAN16_TO_REG(val); | |
c7f1f716 | 1064 | it87_write_value(data, IT87_REG_FAN_MIN[nr], |
17d648bf | 1065 | data->fan_min[nr] & 0xff); |
c7f1f716 | 1066 | it87_write_value(data, IT87_REG_FANX_MIN[nr], |
17d648bf JD |
1067 | data->fan_min[nr] >> 8); |
1068 | mutex_unlock(&data->update_lock); | |
1069 | return count; | |
1070 | } | |
1071 | ||
1072 | /* We want to use the same sysfs file names as 8-bit fans, but we need | |
1073 | different variable names, so we have to use SENSOR_ATTR instead of | |
1074 | SENSOR_DEVICE_ATTR. */ | |
1075 | #define show_fan16_offset(offset) \ | |
1076 | static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \ | |
1077 | = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \ | |
1078 | show_fan16, NULL, offset - 1); \ | |
1079 | static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \ | |
1080 | = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ | |
1081 | show_fan16_min, set_fan16_min, offset - 1) | |
1082 | ||
1083 | show_fan16_offset(1); | |
1084 | show_fan16_offset(2); | |
1085 | show_fan16_offset(3); | |
c7f1f716 JD |
1086 | show_fan16_offset(4); |
1087 | show_fan16_offset(5); | |
17d648bf | 1088 | |
1da177e4 | 1089 | /* Alarms */ |
5f2dc798 JD |
1090 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, |
1091 | char *buf) | |
1da177e4 LT |
1092 | { |
1093 | struct it87_data *data = it87_update_device(dev); | |
68188ba7 | 1094 | return sprintf(buf, "%u\n", data->alarms); |
1da177e4 | 1095 | } |
1d66c64c | 1096 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
1da177e4 | 1097 | |
0124dd78 JD |
1098 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
1099 | char *buf) | |
1100 | { | |
1101 | int bitnr = to_sensor_dev_attr(attr)->index; | |
1102 | struct it87_data *data = it87_update_device(dev); | |
1103 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); | |
1104 | } | |
1105 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8); | |
1106 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9); | |
1107 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10); | |
1108 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11); | |
1109 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12); | |
1110 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13); | |
1111 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14); | |
1112 | static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15); | |
1113 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0); | |
1114 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1); | |
1115 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2); | |
1116 | static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3); | |
1117 | static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6); | |
1118 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16); | |
1119 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17); | |
1120 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18); | |
1121 | ||
d9b327c3 JD |
1122 | static ssize_t show_beep(struct device *dev, struct device_attribute *attr, |
1123 | char *buf) | |
1124 | { | |
1125 | int bitnr = to_sensor_dev_attr(attr)->index; | |
1126 | struct it87_data *data = it87_update_device(dev); | |
1127 | return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1); | |
1128 | } | |
1129 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, | |
1130 | const char *buf, size_t count) | |
1131 | { | |
1132 | int bitnr = to_sensor_dev_attr(attr)->index; | |
1133 | struct it87_data *data = dev_get_drvdata(dev); | |
1134 | long val; | |
1135 | ||
1136 | if (strict_strtol(buf, 10, &val) < 0 | |
1137 | || (val != 0 && val != 1)) | |
1138 | return -EINVAL; | |
1139 | ||
1140 | mutex_lock(&data->update_lock); | |
1141 | data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); | |
1142 | if (val) | |
1143 | data->beeps |= (1 << bitnr); | |
1144 | else | |
1145 | data->beeps &= ~(1 << bitnr); | |
1146 | it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps); | |
1147 | mutex_unlock(&data->update_lock); | |
1148 | return count; | |
1149 | } | |
1150 | ||
1151 | static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, | |
1152 | show_beep, set_beep, 1); | |
1153 | static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1); | |
1154 | static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1); | |
1155 | static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1); | |
1156 | static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1); | |
1157 | static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1); | |
1158 | static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1); | |
1159 | static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1); | |
1160 | /* fanX_beep writability is set later */ | |
1161 | static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0); | |
1162 | static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0); | |
1163 | static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0); | |
1164 | static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0); | |
1165 | static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0); | |
1166 | static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, | |
1167 | show_beep, set_beep, 2); | |
1168 | static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2); | |
1169 | static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2); | |
1170 | ||
5f2dc798 JD |
1171 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, |
1172 | char *buf) | |
1da177e4 | 1173 | { |
90d6619a | 1174 | struct it87_data *data = dev_get_drvdata(dev); |
a7be58a1 | 1175 | return sprintf(buf, "%u\n", data->vrm); |
1da177e4 | 1176 | } |
5f2dc798 JD |
1177 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, |
1178 | const char *buf, size_t count) | |
1da177e4 | 1179 | { |
b74f3fdd | 1180 | struct it87_data *data = dev_get_drvdata(dev); |
f5f64501 JD |
1181 | unsigned long val; |
1182 | ||
1183 | if (strict_strtoul(buf, 10, &val) < 0) | |
1184 | return -EINVAL; | |
1da177e4 | 1185 | |
1da177e4 LT |
1186 | data->vrm = val; |
1187 | ||
1188 | return count; | |
1189 | } | |
1190 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); | |
1da177e4 | 1191 | |
5f2dc798 JD |
1192 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, |
1193 | char *buf) | |
1da177e4 LT |
1194 | { |
1195 | struct it87_data *data = it87_update_device(dev); | |
1196 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); | |
1197 | } | |
1198 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); | |
87808be4 | 1199 | |
738e5e05 JD |
1200 | static ssize_t show_label(struct device *dev, struct device_attribute *attr, |
1201 | char *buf) | |
1202 | { | |
1203 | static const char *labels[] = { | |
1204 | "+5V", | |
1205 | "5VSB", | |
1206 | "Vbat", | |
1207 | }; | |
1208 | int nr = to_sensor_dev_attr(attr)->index; | |
1209 | ||
1210 | return sprintf(buf, "%s\n", labels[nr]); | |
1211 | } | |
1212 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); | |
1213 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); | |
1214 | static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2); | |
1215 | ||
b74f3fdd | 1216 | static ssize_t show_name(struct device *dev, struct device_attribute |
1217 | *devattr, char *buf) | |
1218 | { | |
1219 | struct it87_data *data = dev_get_drvdata(dev); | |
1220 | return sprintf(buf, "%s\n", data->name); | |
1221 | } | |
1222 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); | |
1223 | ||
87808be4 JD |
1224 | static struct attribute *it87_attributes[] = { |
1225 | &sensor_dev_attr_in0_input.dev_attr.attr, | |
1226 | &sensor_dev_attr_in1_input.dev_attr.attr, | |
1227 | &sensor_dev_attr_in2_input.dev_attr.attr, | |
1228 | &sensor_dev_attr_in3_input.dev_attr.attr, | |
1229 | &sensor_dev_attr_in4_input.dev_attr.attr, | |
1230 | &sensor_dev_attr_in5_input.dev_attr.attr, | |
1231 | &sensor_dev_attr_in6_input.dev_attr.attr, | |
1232 | &sensor_dev_attr_in7_input.dev_attr.attr, | |
1233 | &sensor_dev_attr_in8_input.dev_attr.attr, | |
1234 | &sensor_dev_attr_in0_min.dev_attr.attr, | |
1235 | &sensor_dev_attr_in1_min.dev_attr.attr, | |
1236 | &sensor_dev_attr_in2_min.dev_attr.attr, | |
1237 | &sensor_dev_attr_in3_min.dev_attr.attr, | |
1238 | &sensor_dev_attr_in4_min.dev_attr.attr, | |
1239 | &sensor_dev_attr_in5_min.dev_attr.attr, | |
1240 | &sensor_dev_attr_in6_min.dev_attr.attr, | |
1241 | &sensor_dev_attr_in7_min.dev_attr.attr, | |
1242 | &sensor_dev_attr_in0_max.dev_attr.attr, | |
1243 | &sensor_dev_attr_in1_max.dev_attr.attr, | |
1244 | &sensor_dev_attr_in2_max.dev_attr.attr, | |
1245 | &sensor_dev_attr_in3_max.dev_attr.attr, | |
1246 | &sensor_dev_attr_in4_max.dev_attr.attr, | |
1247 | &sensor_dev_attr_in5_max.dev_attr.attr, | |
1248 | &sensor_dev_attr_in6_max.dev_attr.attr, | |
1249 | &sensor_dev_attr_in7_max.dev_attr.attr, | |
0124dd78 JD |
1250 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
1251 | &sensor_dev_attr_in1_alarm.dev_attr.attr, | |
1252 | &sensor_dev_attr_in2_alarm.dev_attr.attr, | |
1253 | &sensor_dev_attr_in3_alarm.dev_attr.attr, | |
1254 | &sensor_dev_attr_in4_alarm.dev_attr.attr, | |
1255 | &sensor_dev_attr_in5_alarm.dev_attr.attr, | |
1256 | &sensor_dev_attr_in6_alarm.dev_attr.attr, | |
1257 | &sensor_dev_attr_in7_alarm.dev_attr.attr, | |
87808be4 JD |
1258 | |
1259 | &sensor_dev_attr_temp1_input.dev_attr.attr, | |
1260 | &sensor_dev_attr_temp2_input.dev_attr.attr, | |
1261 | &sensor_dev_attr_temp3_input.dev_attr.attr, | |
1262 | &sensor_dev_attr_temp1_max.dev_attr.attr, | |
1263 | &sensor_dev_attr_temp2_max.dev_attr.attr, | |
1264 | &sensor_dev_attr_temp3_max.dev_attr.attr, | |
1265 | &sensor_dev_attr_temp1_min.dev_attr.attr, | |
1266 | &sensor_dev_attr_temp2_min.dev_attr.attr, | |
1267 | &sensor_dev_attr_temp3_min.dev_attr.attr, | |
1268 | &sensor_dev_attr_temp1_type.dev_attr.attr, | |
1269 | &sensor_dev_attr_temp2_type.dev_attr.attr, | |
1270 | &sensor_dev_attr_temp3_type.dev_attr.attr, | |
0124dd78 JD |
1271 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
1272 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, | |
1273 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, | |
87808be4 JD |
1274 | |
1275 | &dev_attr_alarms.attr, | |
b74f3fdd | 1276 | &dev_attr_name.attr, |
87808be4 JD |
1277 | NULL |
1278 | }; | |
1279 | ||
1280 | static const struct attribute_group it87_group = { | |
1281 | .attrs = it87_attributes, | |
1282 | }; | |
1283 | ||
d9b327c3 JD |
1284 | static struct attribute *it87_attributes_beep[] = { |
1285 | &sensor_dev_attr_in0_beep.dev_attr.attr, | |
1286 | &sensor_dev_attr_in1_beep.dev_attr.attr, | |
1287 | &sensor_dev_attr_in2_beep.dev_attr.attr, | |
1288 | &sensor_dev_attr_in3_beep.dev_attr.attr, | |
1289 | &sensor_dev_attr_in4_beep.dev_attr.attr, | |
1290 | &sensor_dev_attr_in5_beep.dev_attr.attr, | |
1291 | &sensor_dev_attr_in6_beep.dev_attr.attr, | |
1292 | &sensor_dev_attr_in7_beep.dev_attr.attr, | |
1293 | ||
1294 | &sensor_dev_attr_temp1_beep.dev_attr.attr, | |
1295 | &sensor_dev_attr_temp2_beep.dev_attr.attr, | |
1296 | &sensor_dev_attr_temp3_beep.dev_attr.attr, | |
1297 | NULL | |
1298 | }; | |
1299 | ||
1300 | static const struct attribute_group it87_group_beep = { | |
1301 | .attrs = it87_attributes_beep, | |
1302 | }; | |
1303 | ||
723a0aa0 | 1304 | static struct attribute *it87_attributes_fan16[5][3+1] = { { |
87808be4 JD |
1305 | &sensor_dev_attr_fan1_input16.dev_attr.attr, |
1306 | &sensor_dev_attr_fan1_min16.dev_attr.attr, | |
723a0aa0 JD |
1307 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
1308 | NULL | |
1309 | }, { | |
87808be4 JD |
1310 | &sensor_dev_attr_fan2_input16.dev_attr.attr, |
1311 | &sensor_dev_attr_fan2_min16.dev_attr.attr, | |
723a0aa0 JD |
1312 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
1313 | NULL | |
1314 | }, { | |
87808be4 JD |
1315 | &sensor_dev_attr_fan3_input16.dev_attr.attr, |
1316 | &sensor_dev_attr_fan3_min16.dev_attr.attr, | |
723a0aa0 JD |
1317 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
1318 | NULL | |
1319 | }, { | |
c7f1f716 JD |
1320 | &sensor_dev_attr_fan4_input16.dev_attr.attr, |
1321 | &sensor_dev_attr_fan4_min16.dev_attr.attr, | |
723a0aa0 JD |
1322 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
1323 | NULL | |
1324 | }, { | |
c7f1f716 JD |
1325 | &sensor_dev_attr_fan5_input16.dev_attr.attr, |
1326 | &sensor_dev_attr_fan5_min16.dev_attr.attr, | |
723a0aa0 JD |
1327 | &sensor_dev_attr_fan5_alarm.dev_attr.attr, |
1328 | NULL | |
1329 | } }; | |
1330 | ||
1331 | static const struct attribute_group it87_group_fan16[5] = { | |
1332 | { .attrs = it87_attributes_fan16[0] }, | |
1333 | { .attrs = it87_attributes_fan16[1] }, | |
1334 | { .attrs = it87_attributes_fan16[2] }, | |
1335 | { .attrs = it87_attributes_fan16[3] }, | |
1336 | { .attrs = it87_attributes_fan16[4] }, | |
1337 | }; | |
87808be4 | 1338 | |
723a0aa0 | 1339 | static struct attribute *it87_attributes_fan[3][4+1] = { { |
87808be4 JD |
1340 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
1341 | &sensor_dev_attr_fan1_min.dev_attr.attr, | |
1342 | &sensor_dev_attr_fan1_div.dev_attr.attr, | |
723a0aa0 JD |
1343 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
1344 | NULL | |
1345 | }, { | |
87808be4 JD |
1346 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
1347 | &sensor_dev_attr_fan2_min.dev_attr.attr, | |
1348 | &sensor_dev_attr_fan2_div.dev_attr.attr, | |
723a0aa0 JD |
1349 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
1350 | NULL | |
1351 | }, { | |
87808be4 JD |
1352 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
1353 | &sensor_dev_attr_fan3_min.dev_attr.attr, | |
1354 | &sensor_dev_attr_fan3_div.dev_attr.attr, | |
0124dd78 | 1355 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
723a0aa0 JD |
1356 | NULL |
1357 | } }; | |
1358 | ||
1359 | static const struct attribute_group it87_group_fan[3] = { | |
1360 | { .attrs = it87_attributes_fan[0] }, | |
1361 | { .attrs = it87_attributes_fan[1] }, | |
1362 | { .attrs = it87_attributes_fan[2] }, | |
1363 | }; | |
1364 | ||
1365 | static const struct attribute_group * | |
1366 | it87_get_fan_group(const struct it87_data *data) | |
1367 | { | |
1368 | return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan; | |
1369 | } | |
0124dd78 | 1370 | |
723a0aa0 | 1371 | static struct attribute *it87_attributes_pwm[3][4+1] = { { |
87808be4 | 1372 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
87808be4 | 1373 | &sensor_dev_attr_pwm1.dev_attr.attr, |
d5b0b5d6 | 1374 | &dev_attr_pwm1_freq.attr, |
94ac7ee6 | 1375 | &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, |
723a0aa0 JD |
1376 | NULL |
1377 | }, { | |
1378 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, | |
1379 | &sensor_dev_attr_pwm2.dev_attr.attr, | |
1380 | &dev_attr_pwm2_freq.attr, | |
94ac7ee6 | 1381 | &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, |
723a0aa0 JD |
1382 | NULL |
1383 | }, { | |
1384 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, | |
1385 | &sensor_dev_attr_pwm3.dev_attr.attr, | |
1386 | &dev_attr_pwm3_freq.attr, | |
94ac7ee6 | 1387 | &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, |
723a0aa0 JD |
1388 | NULL |
1389 | } }; | |
87808be4 | 1390 | |
723a0aa0 JD |
1391 | static const struct attribute_group it87_group_pwm[3] = { |
1392 | { .attrs = it87_attributes_pwm[0] }, | |
1393 | { .attrs = it87_attributes_pwm[1] }, | |
1394 | { .attrs = it87_attributes_pwm[2] }, | |
1395 | }; | |
1396 | ||
4f3f51bc JD |
1397 | static struct attribute *it87_attributes_autopwm[3][9+1] = { { |
1398 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, | |
1399 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, | |
1400 | &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, | |
1401 | &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr, | |
1402 | &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, | |
1403 | &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr, | |
1404 | &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, | |
1405 | &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, | |
1406 | &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr, | |
1407 | NULL | |
1408 | }, { | |
1409 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, | |
1410 | &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, | |
1411 | &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr, | |
1412 | &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr, | |
1413 | &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr, | |
1414 | &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr, | |
1415 | &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr, | |
1416 | &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr, | |
1417 | &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr, | |
1418 | NULL | |
1419 | }, { | |
1420 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, | |
1421 | &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, | |
1422 | &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr, | |
1423 | &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr, | |
1424 | &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, | |
1425 | &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr, | |
1426 | &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, | |
1427 | &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr, | |
1428 | &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr, | |
1429 | NULL | |
1430 | } }; | |
1431 | ||
1432 | static const struct attribute_group it87_group_autopwm[3] = { | |
1433 | { .attrs = it87_attributes_autopwm[0] }, | |
1434 | { .attrs = it87_attributes_autopwm[1] }, | |
1435 | { .attrs = it87_attributes_autopwm[2] }, | |
1436 | }; | |
1437 | ||
d9b327c3 JD |
1438 | static struct attribute *it87_attributes_fan_beep[] = { |
1439 | &sensor_dev_attr_fan1_beep.dev_attr.attr, | |
1440 | &sensor_dev_attr_fan2_beep.dev_attr.attr, | |
1441 | &sensor_dev_attr_fan3_beep.dev_attr.attr, | |
1442 | &sensor_dev_attr_fan4_beep.dev_attr.attr, | |
1443 | &sensor_dev_attr_fan5_beep.dev_attr.attr, | |
1444 | }; | |
1445 | ||
6a8d7acf | 1446 | static struct attribute *it87_attributes_vid[] = { |
87808be4 JD |
1447 | &dev_attr_vrm.attr, |
1448 | &dev_attr_cpu0_vid.attr, | |
1449 | NULL | |
1450 | }; | |
1451 | ||
6a8d7acf JD |
1452 | static const struct attribute_group it87_group_vid = { |
1453 | .attrs = it87_attributes_vid, | |
87808be4 | 1454 | }; |
1da177e4 | 1455 | |
738e5e05 JD |
1456 | static struct attribute *it87_attributes_label[] = { |
1457 | &sensor_dev_attr_in3_label.dev_attr.attr, | |
1458 | &sensor_dev_attr_in7_label.dev_attr.attr, | |
1459 | &sensor_dev_attr_in8_label.dev_attr.attr, | |
1460 | NULL | |
1461 | }; | |
1462 | ||
1463 | static const struct attribute_group it87_group_label = { | |
1464 | .attrs = it87_attributes_vid, | |
1465 | }; | |
1466 | ||
2d8672c5 | 1467 | /* SuperIO detection - will change isa_address if a chip is found */ |
b74f3fdd | 1468 | static int __init it87_find(unsigned short *address, |
1469 | struct it87_sio_data *sio_data) | |
1da177e4 LT |
1470 | { |
1471 | int err = -ENODEV; | |
b74f3fdd | 1472 | u16 chip_type; |
98dd22c3 | 1473 | const char *board_vendor, *board_name; |
1da177e4 LT |
1474 | |
1475 | superio_enter(); | |
67b671bc | 1476 | chip_type = force_id ? force_id : superio_inw(DEVID); |
b74f3fdd | 1477 | |
1478 | switch (chip_type) { | |
1479 | case IT8705F_DEVID: | |
1480 | sio_data->type = it87; | |
1481 | break; | |
1482 | case IT8712F_DEVID: | |
1483 | sio_data->type = it8712; | |
1484 | break; | |
1485 | case IT8716F_DEVID: | |
1486 | case IT8726F_DEVID: | |
1487 | sio_data->type = it8716; | |
1488 | break; | |
1489 | case IT8718F_DEVID: | |
1490 | sio_data->type = it8718; | |
1491 | break; | |
b4da93e4 JMS |
1492 | case IT8720F_DEVID: |
1493 | sio_data->type = it8720; | |
1494 | break; | |
b74f3fdd | 1495 | case 0xffff: /* No device at all */ |
1496 | goto exit; | |
1497 | default: | |
1498 | pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n", | |
1499 | chip_type); | |
1500 | goto exit; | |
1501 | } | |
1da177e4 | 1502 | |
87673dd7 | 1503 | superio_select(PME); |
1da177e4 LT |
1504 | if (!(superio_inb(IT87_ACT_REG) & 0x01)) { |
1505 | pr_info("it87: Device not activated, skipping\n"); | |
1506 | goto exit; | |
1507 | } | |
1508 | ||
1509 | *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1); | |
1510 | if (*address == 0) { | |
1511 | pr_info("it87: Base address not set, skipping\n"); | |
1512 | goto exit; | |
1513 | } | |
1514 | ||
1515 | err = 0; | |
0475169c | 1516 | sio_data->revision = superio_inb(DEVREV) & 0x0f; |
1da177e4 | 1517 | pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", |
0475169c | 1518 | chip_type, *address, sio_data->revision); |
1da177e4 | 1519 | |
738e5e05 JD |
1520 | /* in8 (Vbat) is always internal */ |
1521 | sio_data->internal = (1 << 2); | |
1522 | ||
87673dd7 | 1523 | /* Read GPIO config and VID value from LDN 7 (GPIO) */ |
895ff267 JD |
1524 | if (sio_data->type == it87) { |
1525 | /* The IT8705F doesn't have VID pins at all */ | |
1526 | sio_data->skip_vid = 1; | |
d9b327c3 JD |
1527 | |
1528 | /* The IT8705F has a different LD number for GPIO */ | |
1529 | superio_select(5); | |
1530 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; | |
895ff267 | 1531 | } else { |
87673dd7 JD |
1532 | int reg; |
1533 | ||
1534 | superio_select(GPIO); | |
895ff267 JD |
1535 | /* We need at least 4 VID pins */ |
1536 | reg = superio_inb(IT87_SIO_GPIO3_REG); | |
1537 | if (reg & 0x0f) { | |
1538 | pr_info("it87: VID is disabled (pins used for GPIO)\n"); | |
1539 | sio_data->skip_vid = 1; | |
1540 | } | |
1541 | ||
591ec650 JD |
1542 | /* Check if fan3 is there or not */ |
1543 | if (reg & (1 << 6)) | |
1544 | sio_data->skip_pwm |= (1 << 2); | |
1545 | if (reg & (1 << 7)) | |
1546 | sio_data->skip_fan |= (1 << 2); | |
1547 | ||
1548 | /* Check if fan2 is there or not */ | |
1549 | reg = superio_inb(IT87_SIO_GPIO5_REG); | |
1550 | if (reg & (1 << 1)) | |
1551 | sio_data->skip_pwm |= (1 << 1); | |
1552 | if (reg & (1 << 2)) | |
1553 | sio_data->skip_fan |= (1 << 1); | |
1554 | ||
895ff267 JD |
1555 | if ((sio_data->type == it8718 || sio_data->type == it8720) |
1556 | && !(sio_data->skip_vid)) | |
b74f3fdd | 1557 | sio_data->vid_value = superio_inb(IT87_SIO_VID_REG); |
87673dd7 JD |
1558 | |
1559 | reg = superio_inb(IT87_SIO_PINX2_REG); | |
436cad2a JD |
1560 | /* |
1561 | * The IT8720F has no VIN7 pin, so VCCH should always be | |
1562 | * routed internally to VIN7 with an internal divider. | |
1563 | * Curiously, there still is a configuration bit to control | |
1564 | * this, which means it can be set incorrectly. And even | |
1565 | * more curiously, many boards out there are improperly | |
1566 | * configured, even though the IT8720F datasheet claims | |
1567 | * that the internal routing of VCCH to VIN7 is the default | |
1568 | * setting. So we force the internal routing in this case. | |
1569 | */ | |
1570 | if (sio_data->type == it8720 && !(reg & (1 << 1))) { | |
1571 | reg |= (1 << 1); | |
1572 | superio_outb(IT87_SIO_PINX2_REG, reg); | |
1573 | pr_notice("it87: Routing internal VCCH to in7\n"); | |
1574 | } | |
87673dd7 | 1575 | if (reg & (1 << 0)) |
738e5e05 | 1576 | sio_data->internal |= (1 << 0); |
87673dd7 | 1577 | if (reg & (1 << 1)) |
738e5e05 | 1578 | sio_data->internal |= (1 << 1); |
d9b327c3 JD |
1579 | |
1580 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; | |
87673dd7 | 1581 | } |
d9b327c3 JD |
1582 | if (sio_data->beep_pin) |
1583 | pr_info("it87: Beeping is supported\n"); | |
87673dd7 | 1584 | |
98dd22c3 JD |
1585 | /* Disable specific features based on DMI strings */ |
1586 | board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); | |
1587 | board_name = dmi_get_system_info(DMI_BOARD_NAME); | |
1588 | if (board_vendor && board_name) { | |
1589 | if (strcmp(board_vendor, "nVIDIA") == 0 | |
1590 | && strcmp(board_name, "FN68PT") == 0) { | |
1591 | /* On the Shuttle SN68PT, FAN_CTL2 is apparently not | |
1592 | connected to a fan, but to something else. One user | |
1593 | has reported instant system power-off when changing | |
1594 | the PWM2 duty cycle, so we disable it. | |
1595 | I use the board name string as the trigger in case | |
1596 | the same board is ever used in other systems. */ | |
1597 | pr_info("it87: Disabling pwm2 due to " | |
1598 | "hardware constraints\n"); | |
1599 | sio_data->skip_pwm = (1 << 1); | |
1600 | } | |
1601 | } | |
1602 | ||
1da177e4 LT |
1603 | exit: |
1604 | superio_exit(); | |
1605 | return err; | |
1606 | } | |
1607 | ||
723a0aa0 JD |
1608 | static void it87_remove_files(struct device *dev) |
1609 | { | |
1610 | struct it87_data *data = platform_get_drvdata(pdev); | |
1611 | struct it87_sio_data *sio_data = dev->platform_data; | |
1612 | const struct attribute_group *fan_group = it87_get_fan_group(data); | |
1613 | int i; | |
1614 | ||
1615 | sysfs_remove_group(&dev->kobj, &it87_group); | |
d9b327c3 JD |
1616 | if (sio_data->beep_pin) |
1617 | sysfs_remove_group(&dev->kobj, &it87_group_beep); | |
723a0aa0 JD |
1618 | for (i = 0; i < 5; i++) { |
1619 | if (!(data->has_fan & (1 << i))) | |
1620 | continue; | |
1621 | sysfs_remove_group(&dev->kobj, &fan_group[i]); | |
d9b327c3 JD |
1622 | if (sio_data->beep_pin) |
1623 | sysfs_remove_file(&dev->kobj, | |
1624 | it87_attributes_fan_beep[i]); | |
723a0aa0 JD |
1625 | } |
1626 | for (i = 0; i < 3; i++) { | |
1627 | if (sio_data->skip_pwm & (1 << 0)) | |
1628 | continue; | |
1629 | sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]); | |
4f3f51bc JD |
1630 | if (has_old_autopwm(data)) |
1631 | sysfs_remove_group(&dev->kobj, | |
1632 | &it87_group_autopwm[i]); | |
723a0aa0 | 1633 | } |
6a8d7acf JD |
1634 | if (!sio_data->skip_vid) |
1635 | sysfs_remove_group(&dev->kobj, &it87_group_vid); | |
738e5e05 | 1636 | sysfs_remove_group(&dev->kobj, &it87_group_label); |
723a0aa0 JD |
1637 | } |
1638 | ||
b74f3fdd | 1639 | static int __devinit it87_probe(struct platform_device *pdev) |
1da177e4 | 1640 | { |
1da177e4 | 1641 | struct it87_data *data; |
b74f3fdd | 1642 | struct resource *res; |
1643 | struct device *dev = &pdev->dev; | |
1644 | struct it87_sio_data *sio_data = dev->platform_data; | |
723a0aa0 JD |
1645 | const struct attribute_group *fan_group; |
1646 | int err = 0, i; | |
1da177e4 | 1647 | int enable_pwm_interface; |
d9b327c3 | 1648 | int fan_beep_need_rw; |
b74f3fdd | 1649 | static const char *names[] = { |
1650 | "it87", | |
1651 | "it8712", | |
1652 | "it8716", | |
1653 | "it8718", | |
b4da93e4 | 1654 | "it8720", |
b74f3fdd | 1655 | }; |
1656 | ||
1657 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | |
87b4b663 | 1658 | if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) { |
b74f3fdd | 1659 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", |
1660 | (unsigned long)res->start, | |
87b4b663 | 1661 | (unsigned long)(res->start + IT87_EC_EXTENT - 1)); |
8e9afcbb JD |
1662 | err = -EBUSY; |
1663 | goto ERROR0; | |
1664 | } | |
1da177e4 | 1665 | |
5f2dc798 JD |
1666 | data = kzalloc(sizeof(struct it87_data), GFP_KERNEL); |
1667 | if (!data) { | |
1da177e4 LT |
1668 | err = -ENOMEM; |
1669 | goto ERROR1; | |
1670 | } | |
1da177e4 | 1671 | |
b74f3fdd | 1672 | data->addr = res->start; |
1673 | data->type = sio_data->type; | |
0475169c | 1674 | data->revision = sio_data->revision; |
b74f3fdd | 1675 | data->name = names[sio_data->type]; |
1da177e4 LT |
1676 | |
1677 | /* Now, we do the remaining detection. */ | |
b74f3fdd | 1678 | if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) |
1679 | || it87_read_value(data, IT87_REG_CHIPID) != 0x90) { | |
8e9afcbb JD |
1680 | err = -ENODEV; |
1681 | goto ERROR2; | |
1da177e4 LT |
1682 | } |
1683 | ||
b74f3fdd | 1684 | platform_set_drvdata(pdev, data); |
1da177e4 | 1685 | |
9a61bf63 | 1686 | mutex_init(&data->update_lock); |
1da177e4 | 1687 | |
1da177e4 | 1688 | /* Check PWM configuration */ |
b74f3fdd | 1689 | enable_pwm_interface = it87_check_pwm(dev); |
1da177e4 LT |
1690 | |
1691 | /* Initialize the IT87 chip */ | |
b74f3fdd | 1692 | it87_init_device(pdev); |
1da177e4 LT |
1693 | |
1694 | /* Register sysfs hooks */ | |
5f2dc798 JD |
1695 | err = sysfs_create_group(&dev->kobj, &it87_group); |
1696 | if (err) | |
b74f3fdd | 1697 | goto ERROR2; |
17d648bf | 1698 | |
d9b327c3 JD |
1699 | if (sio_data->beep_pin) { |
1700 | err = sysfs_create_group(&dev->kobj, &it87_group_beep); | |
1701 | if (err) | |
1702 | goto ERROR4; | |
1703 | } | |
1704 | ||
9060f8bd | 1705 | /* Do not create fan files for disabled fans */ |
723a0aa0 | 1706 | fan_group = it87_get_fan_group(data); |
d9b327c3 | 1707 | fan_beep_need_rw = 1; |
723a0aa0 JD |
1708 | for (i = 0; i < 5; i++) { |
1709 | if (!(data->has_fan & (1 << i))) | |
1710 | continue; | |
1711 | err = sysfs_create_group(&dev->kobj, &fan_group[i]); | |
1712 | if (err) | |
1713 | goto ERROR4; | |
d9b327c3 JD |
1714 | |
1715 | if (sio_data->beep_pin) { | |
1716 | err = sysfs_create_file(&dev->kobj, | |
1717 | it87_attributes_fan_beep[i]); | |
1718 | if (err) | |
1719 | goto ERROR4; | |
1720 | if (!fan_beep_need_rw) | |
1721 | continue; | |
1722 | ||
1723 | /* As we have a single beep enable bit for all fans, | |
1724 | * only the first enabled fan has a writable attribute | |
1725 | * for it. */ | |
1726 | if (sysfs_chmod_file(&dev->kobj, | |
1727 | it87_attributes_fan_beep[i], | |
1728 | S_IRUGO | S_IWUSR)) | |
1729 | dev_dbg(dev, "chmod +w fan%d_beep failed\n", | |
1730 | i + 1); | |
1731 | fan_beep_need_rw = 0; | |
1732 | } | |
17d648bf JD |
1733 | } |
1734 | ||
1da177e4 | 1735 | if (enable_pwm_interface) { |
723a0aa0 JD |
1736 | for (i = 0; i < 3; i++) { |
1737 | if (sio_data->skip_pwm & (1 << i)) | |
1738 | continue; | |
1739 | err = sysfs_create_group(&dev->kobj, | |
1740 | &it87_group_pwm[i]); | |
1741 | if (err) | |
98dd22c3 | 1742 | goto ERROR4; |
4f3f51bc JD |
1743 | |
1744 | if (!has_old_autopwm(data)) | |
1745 | continue; | |
1746 | err = sysfs_create_group(&dev->kobj, | |
1747 | &it87_group_autopwm[i]); | |
1748 | if (err) | |
1749 | goto ERROR4; | |
98dd22c3 | 1750 | } |
1da177e4 LT |
1751 | } |
1752 | ||
895ff267 | 1753 | if (!sio_data->skip_vid) { |
303760b4 | 1754 | data->vrm = vid_which_vrm(); |
87673dd7 | 1755 | /* VID reading from Super-I/O config space if available */ |
b74f3fdd | 1756 | data->vid = sio_data->vid_value; |
6a8d7acf JD |
1757 | err = sysfs_create_group(&dev->kobj, &it87_group_vid); |
1758 | if (err) | |
87808be4 JD |
1759 | goto ERROR4; |
1760 | } | |
1761 | ||
738e5e05 JD |
1762 | /* Export labels for internal sensors */ |
1763 | for (i = 0; i < 3; i++) { | |
1764 | if (!(sio_data->internal & (1 << i))) | |
1765 | continue; | |
1766 | err = sysfs_create_file(&dev->kobj, | |
1767 | it87_attributes_label[i]); | |
1768 | if (err) | |
1769 | goto ERROR4; | |
1770 | } | |
1771 | ||
1beeffe4 TJ |
1772 | data->hwmon_dev = hwmon_device_register(dev); |
1773 | if (IS_ERR(data->hwmon_dev)) { | |
1774 | err = PTR_ERR(data->hwmon_dev); | |
87808be4 | 1775 | goto ERROR4; |
1da177e4 LT |
1776 | } |
1777 | ||
1778 | return 0; | |
1779 | ||
87808be4 | 1780 | ERROR4: |
723a0aa0 | 1781 | it87_remove_files(dev); |
1da177e4 | 1782 | ERROR2: |
b74f3fdd | 1783 | platform_set_drvdata(pdev, NULL); |
1da177e4 LT |
1784 | kfree(data); |
1785 | ERROR1: | |
87b4b663 | 1786 | release_region(res->start, IT87_EC_EXTENT); |
1da177e4 LT |
1787 | ERROR0: |
1788 | return err; | |
1789 | } | |
1790 | ||
b74f3fdd | 1791 | static int __devexit it87_remove(struct platform_device *pdev) |
1da177e4 | 1792 | { |
b74f3fdd | 1793 | struct it87_data *data = platform_get_drvdata(pdev); |
1da177e4 | 1794 | |
1beeffe4 | 1795 | hwmon_device_unregister(data->hwmon_dev); |
723a0aa0 | 1796 | it87_remove_files(&pdev->dev); |
943b0830 | 1797 | |
87b4b663 | 1798 | release_region(data->addr, IT87_EC_EXTENT); |
b74f3fdd | 1799 | platform_set_drvdata(pdev, NULL); |
943b0830 | 1800 | kfree(data); |
1da177e4 LT |
1801 | |
1802 | return 0; | |
1803 | } | |
1804 | ||
7f999aa7 | 1805 | /* Must be called with data->update_lock held, except during initialization. |
1da177e4 LT |
1806 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
1807 | would slow down the IT87 access and should not be necessary. */ | |
b74f3fdd | 1808 | static int it87_read_value(struct it87_data *data, u8 reg) |
1da177e4 | 1809 | { |
b74f3fdd | 1810 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
1811 | return inb_p(data->addr + IT87_DATA_REG_OFFSET); | |
1da177e4 LT |
1812 | } |
1813 | ||
7f999aa7 | 1814 | /* Must be called with data->update_lock held, except during initialization. |
1da177e4 LT |
1815 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
1816 | would slow down the IT87 access and should not be necessary. */ | |
b74f3fdd | 1817 | static void it87_write_value(struct it87_data *data, u8 reg, u8 value) |
1da177e4 | 1818 | { |
b74f3fdd | 1819 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
1820 | outb_p(value, data->addr + IT87_DATA_REG_OFFSET); | |
1da177e4 LT |
1821 | } |
1822 | ||
1823 | /* Return 1 if and only if the PWM interface is safe to use */ | |
b74f3fdd | 1824 | static int __devinit it87_check_pwm(struct device *dev) |
1da177e4 | 1825 | { |
b74f3fdd | 1826 | struct it87_data *data = dev_get_drvdata(dev); |
1da177e4 LT |
1827 | /* Some BIOSes fail to correctly configure the IT87 fans. All fans off |
1828 | * and polarity set to active low is sign that this is the case so we | |
1829 | * disable pwm control to protect the user. */ | |
b74f3fdd | 1830 | int tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
1da177e4 LT |
1831 | if ((tmp & 0x87) == 0) { |
1832 | if (fix_pwm_polarity) { | |
1833 | /* The user asks us to attempt a chip reconfiguration. | |
1834 | * This means switching to active high polarity and | |
1835 | * inverting all fan speed values. */ | |
1836 | int i; | |
1837 | u8 pwm[3]; | |
1838 | ||
1839 | for (i = 0; i < 3; i++) | |
b74f3fdd | 1840 | pwm[i] = it87_read_value(data, |
1da177e4 LT |
1841 | IT87_REG_PWM(i)); |
1842 | ||
1843 | /* If any fan is in automatic pwm mode, the polarity | |
1844 | * might be correct, as suspicious as it seems, so we | |
1845 | * better don't change anything (but still disable the | |
1846 | * PWM interface). */ | |
1847 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { | |
b74f3fdd | 1848 | dev_info(dev, "Reconfiguring PWM to " |
1da177e4 | 1849 | "active high polarity\n"); |
b74f3fdd | 1850 | it87_write_value(data, IT87_REG_FAN_CTL, |
1da177e4 LT |
1851 | tmp | 0x87); |
1852 | for (i = 0; i < 3; i++) | |
b74f3fdd | 1853 | it87_write_value(data, |
1da177e4 LT |
1854 | IT87_REG_PWM(i), |
1855 | 0x7f & ~pwm[i]); | |
1856 | return 1; | |
1857 | } | |
1858 | ||
b74f3fdd | 1859 | dev_info(dev, "PWM configuration is " |
1da177e4 LT |
1860 | "too broken to be fixed\n"); |
1861 | } | |
1862 | ||
b74f3fdd | 1863 | dev_info(dev, "Detected broken BIOS " |
1da177e4 LT |
1864 | "defaults, disabling PWM interface\n"); |
1865 | return 0; | |
1866 | } else if (fix_pwm_polarity) { | |
b74f3fdd | 1867 | dev_info(dev, "PWM configuration looks " |
1da177e4 LT |
1868 | "sane, won't touch\n"); |
1869 | } | |
1870 | ||
1871 | return 1; | |
1872 | } | |
1873 | ||
1874 | /* Called when we have found a new IT87. */ | |
b74f3fdd | 1875 | static void __devinit it87_init_device(struct platform_device *pdev) |
1da177e4 | 1876 | { |
591ec650 | 1877 | struct it87_sio_data *sio_data = pdev->dev.platform_data; |
b74f3fdd | 1878 | struct it87_data *data = platform_get_drvdata(pdev); |
1da177e4 | 1879 | int tmp, i; |
591ec650 | 1880 | u8 mask; |
1da177e4 | 1881 | |
b99883dc JD |
1882 | /* For each PWM channel: |
1883 | * - If it is in automatic mode, setting to manual mode should set | |
1884 | * the fan to full speed by default. | |
1885 | * - If it is in manual mode, we need a mapping to temperature | |
1886 | * channels to use when later setting to automatic mode later. | |
1887 | * Use a 1:1 mapping by default (we are clueless.) | |
1888 | * In both cases, the value can (and should) be changed by the user | |
1889 | * prior to switching to a different mode. */ | |
1da177e4 | 1890 | for (i = 0; i < 3; i++) { |
b99883dc JD |
1891 | data->pwm_temp_map[i] = i; |
1892 | data->pwm_duty[i] = 0x7f; /* Full speed */ | |
4f3f51bc | 1893 | data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ |
1da177e4 LT |
1894 | } |
1895 | ||
c5df9b7a JD |
1896 | /* Some chips seem to have default value 0xff for all limit |
1897 | * registers. For low voltage limits it makes no sense and triggers | |
1898 | * alarms, so change to 0 instead. For high temperature limits, it | |
1899 | * means -1 degree C, which surprisingly doesn't trigger an alarm, | |
1900 | * but is still confusing, so change to 127 degrees C. */ | |
1901 | for (i = 0; i < 8; i++) { | |
b74f3fdd | 1902 | tmp = it87_read_value(data, IT87_REG_VIN_MIN(i)); |
c5df9b7a | 1903 | if (tmp == 0xff) |
b74f3fdd | 1904 | it87_write_value(data, IT87_REG_VIN_MIN(i), 0); |
c5df9b7a JD |
1905 | } |
1906 | for (i = 0; i < 3; i++) { | |
b74f3fdd | 1907 | tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
c5df9b7a | 1908 | if (tmp == 0xff) |
b74f3fdd | 1909 | it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); |
c5df9b7a JD |
1910 | } |
1911 | ||
a00afb97 JD |
1912 | /* Temperature channels are not forcibly enabled, as they can be |
1913 | * set to two different sensor types and we can't guess which one | |
1914 | * is correct for a given system. These channels can be enabled at | |
1915 | * run-time through the temp{1-3}_type sysfs accessors if needed. */ | |
1da177e4 LT |
1916 | |
1917 | /* Check if voltage monitors are reset manually or by some reason */ | |
b74f3fdd | 1918 | tmp = it87_read_value(data, IT87_REG_VIN_ENABLE); |
1da177e4 LT |
1919 | if ((tmp & 0xff) == 0) { |
1920 | /* Enable all voltage monitors */ | |
b74f3fdd | 1921 | it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff); |
1da177e4 LT |
1922 | } |
1923 | ||
1924 | /* Check if tachometers are reset manually or by some reason */ | |
591ec650 | 1925 | mask = 0x70 & ~(sio_data->skip_fan << 4); |
b74f3fdd | 1926 | data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); |
591ec650 | 1927 | if ((data->fan_main_ctrl & mask) == 0) { |
1da177e4 | 1928 | /* Enable all fan tachometers */ |
591ec650 | 1929 | data->fan_main_ctrl |= mask; |
5f2dc798 JD |
1930 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
1931 | data->fan_main_ctrl); | |
1da177e4 | 1932 | } |
9060f8bd | 1933 | data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; |
1da177e4 | 1934 | |
17d648bf | 1935 | /* Set tachometers to 16-bit mode if needed */ |
0475169c | 1936 | if (has_16bit_fans(data)) { |
b74f3fdd | 1937 | tmp = it87_read_value(data, IT87_REG_FAN_16BIT); |
9060f8bd | 1938 | if (~tmp & 0x07 & data->has_fan) { |
b74f3fdd | 1939 | dev_dbg(&pdev->dev, |
17d648bf | 1940 | "Setting fan1-3 to 16-bit mode\n"); |
b74f3fdd | 1941 | it87_write_value(data, IT87_REG_FAN_16BIT, |
17d648bf JD |
1942 | tmp | 0x07); |
1943 | } | |
816d8c6a AP |
1944 | /* IT8705F only supports three fans. */ |
1945 | if (data->type != it87) { | |
1946 | if (tmp & (1 << 4)) | |
1947 | data->has_fan |= (1 << 3); /* fan4 enabled */ | |
1948 | if (tmp & (1 << 5)) | |
1949 | data->has_fan |= (1 << 4); /* fan5 enabled */ | |
1950 | } | |
17d648bf JD |
1951 | } |
1952 | ||
591ec650 JD |
1953 | /* Fan input pins may be used for alternative functions */ |
1954 | data->has_fan &= ~sio_data->skip_fan; | |
1955 | ||
1da177e4 | 1956 | /* Start monitoring */ |
b74f3fdd | 1957 | it87_write_value(data, IT87_REG_CONFIG, |
1958 | (it87_read_value(data, IT87_REG_CONFIG) & 0x36) | |
1da177e4 LT |
1959 | | (update_vbat ? 0x41 : 0x01)); |
1960 | } | |
1961 | ||
b99883dc JD |
1962 | static void it87_update_pwm_ctrl(struct it87_data *data, int nr) |
1963 | { | |
1964 | data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr)); | |
1965 | if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ | |
1966 | data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; | |
1967 | else /* Manual mode */ | |
1968 | data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f; | |
4f3f51bc JD |
1969 | |
1970 | if (has_old_autopwm(data)) { | |
1971 | int i; | |
1972 | ||
1973 | for (i = 0; i < 5 ; i++) | |
1974 | data->auto_temp[nr][i] = it87_read_value(data, | |
1975 | IT87_REG_AUTO_TEMP(nr, i)); | |
1976 | for (i = 0; i < 3 ; i++) | |
1977 | data->auto_pwm[nr][i] = it87_read_value(data, | |
1978 | IT87_REG_AUTO_PWM(nr, i)); | |
1979 | } | |
b99883dc JD |
1980 | } |
1981 | ||
1da177e4 LT |
1982 | static struct it87_data *it87_update_device(struct device *dev) |
1983 | { | |
b74f3fdd | 1984 | struct it87_data *data = dev_get_drvdata(dev); |
1da177e4 LT |
1985 | int i; |
1986 | ||
9a61bf63 | 1987 | mutex_lock(&data->update_lock); |
1da177e4 LT |
1988 | |
1989 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | |
1990 | || !data->valid) { | |
1da177e4 LT |
1991 | if (update_vbat) { |
1992 | /* Cleared after each update, so reenable. Value | |
5f2dc798 | 1993 | returned by this read will be previous value */ |
b74f3fdd | 1994 | it87_write_value(data, IT87_REG_CONFIG, |
5f2dc798 | 1995 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); |
1da177e4 LT |
1996 | } |
1997 | for (i = 0; i <= 7; i++) { | |
1998 | data->in[i] = | |
5f2dc798 | 1999 | it87_read_value(data, IT87_REG_VIN(i)); |
1da177e4 | 2000 | data->in_min[i] = |
5f2dc798 | 2001 | it87_read_value(data, IT87_REG_VIN_MIN(i)); |
1da177e4 | 2002 | data->in_max[i] = |
5f2dc798 | 2003 | it87_read_value(data, IT87_REG_VIN_MAX(i)); |
1da177e4 | 2004 | } |
3543a53f | 2005 | /* in8 (battery) has no limit registers */ |
5f2dc798 | 2006 | data->in[8] = it87_read_value(data, IT87_REG_VIN(8)); |
1da177e4 | 2007 | |
c7f1f716 | 2008 | for (i = 0; i < 5; i++) { |
9060f8bd JD |
2009 | /* Skip disabled fans */ |
2010 | if (!(data->has_fan & (1 << i))) | |
2011 | continue; | |
2012 | ||
1da177e4 | 2013 | data->fan_min[i] = |
5f2dc798 | 2014 | it87_read_value(data, IT87_REG_FAN_MIN[i]); |
b74f3fdd | 2015 | data->fan[i] = it87_read_value(data, |
c7f1f716 | 2016 | IT87_REG_FAN[i]); |
17d648bf | 2017 | /* Add high byte if in 16-bit mode */ |
0475169c | 2018 | if (has_16bit_fans(data)) { |
b74f3fdd | 2019 | data->fan[i] |= it87_read_value(data, |
c7f1f716 | 2020 | IT87_REG_FANX[i]) << 8; |
b74f3fdd | 2021 | data->fan_min[i] |= it87_read_value(data, |
c7f1f716 | 2022 | IT87_REG_FANX_MIN[i]) << 8; |
17d648bf | 2023 | } |
1da177e4 LT |
2024 | } |
2025 | for (i = 0; i < 3; i++) { | |
2026 | data->temp[i] = | |
5f2dc798 | 2027 | it87_read_value(data, IT87_REG_TEMP(i)); |
1da177e4 | 2028 | data->temp_high[i] = |
5f2dc798 | 2029 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
1da177e4 | 2030 | data->temp_low[i] = |
5f2dc798 | 2031 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); |
1da177e4 LT |
2032 | } |
2033 | ||
17d648bf | 2034 | /* Newer chips don't have clock dividers */ |
0475169c | 2035 | if ((data->has_fan & 0x07) && !has_16bit_fans(data)) { |
b74f3fdd | 2036 | i = it87_read_value(data, IT87_REG_FAN_DIV); |
17d648bf JD |
2037 | data->fan_div[0] = i & 0x07; |
2038 | data->fan_div[1] = (i >> 3) & 0x07; | |
2039 | data->fan_div[2] = (i & 0x40) ? 3 : 1; | |
2040 | } | |
1da177e4 LT |
2041 | |
2042 | data->alarms = | |
b74f3fdd | 2043 | it87_read_value(data, IT87_REG_ALARM1) | |
2044 | (it87_read_value(data, IT87_REG_ALARM2) << 8) | | |
2045 | (it87_read_value(data, IT87_REG_ALARM3) << 16); | |
d9b327c3 | 2046 | data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
b99883dc | 2047 | |
b74f3fdd | 2048 | data->fan_main_ctrl = it87_read_value(data, |
2049 | IT87_REG_FAN_MAIN_CTRL); | |
2050 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); | |
b99883dc JD |
2051 | for (i = 0; i < 3; i++) |
2052 | it87_update_pwm_ctrl(data, i); | |
b74f3fdd | 2053 | |
2054 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); | |
0475169c | 2055 | /* The 8705 does not have VID capability. |
b4da93e4 JMS |
2056 | The 8718 and the 8720 don't use IT87_REG_VID for the |
2057 | same purpose. */ | |
17d648bf | 2058 | if (data->type == it8712 || data->type == it8716) { |
b74f3fdd | 2059 | data->vid = it87_read_value(data, IT87_REG_VID); |
17d648bf JD |
2060 | /* The older IT8712F revisions had only 5 VID pins, |
2061 | but we assume it is always safe to read 6 bits. */ | |
2062 | data->vid &= 0x3f; | |
1da177e4 LT |
2063 | } |
2064 | data->last_updated = jiffies; | |
2065 | data->valid = 1; | |
2066 | } | |
2067 | ||
9a61bf63 | 2068 | mutex_unlock(&data->update_lock); |
1da177e4 LT |
2069 | |
2070 | return data; | |
2071 | } | |
2072 | ||
b74f3fdd | 2073 | static int __init it87_device_add(unsigned short address, |
2074 | const struct it87_sio_data *sio_data) | |
2075 | { | |
2076 | struct resource res = { | |
87b4b663 BH |
2077 | .start = address + IT87_EC_OFFSET, |
2078 | .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1, | |
b74f3fdd | 2079 | .name = DRVNAME, |
2080 | .flags = IORESOURCE_IO, | |
2081 | }; | |
2082 | int err; | |
2083 | ||
b9acb64a JD |
2084 | err = acpi_check_resource_conflict(&res); |
2085 | if (err) | |
2086 | goto exit; | |
2087 | ||
b74f3fdd | 2088 | pdev = platform_device_alloc(DRVNAME, address); |
2089 | if (!pdev) { | |
2090 | err = -ENOMEM; | |
2091 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); | |
2092 | goto exit; | |
2093 | } | |
2094 | ||
2095 | err = platform_device_add_resources(pdev, &res, 1); | |
2096 | if (err) { | |
2097 | printk(KERN_ERR DRVNAME ": Device resource addition failed " | |
2098 | "(%d)\n", err); | |
2099 | goto exit_device_put; | |
2100 | } | |
2101 | ||
2102 | err = platform_device_add_data(pdev, sio_data, | |
2103 | sizeof(struct it87_sio_data)); | |
2104 | if (err) { | |
2105 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); | |
2106 | goto exit_device_put; | |
2107 | } | |
2108 | ||
2109 | err = platform_device_add(pdev); | |
2110 | if (err) { | |
2111 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", | |
2112 | err); | |
2113 | goto exit_device_put; | |
2114 | } | |
2115 | ||
2116 | return 0; | |
2117 | ||
2118 | exit_device_put: | |
2119 | platform_device_put(pdev); | |
2120 | exit: | |
2121 | return err; | |
2122 | } | |
2123 | ||
1da177e4 LT |
2124 | static int __init sm_it87_init(void) |
2125 | { | |
b74f3fdd | 2126 | int err; |
5f2dc798 | 2127 | unsigned short isa_address = 0; |
b74f3fdd | 2128 | struct it87_sio_data sio_data; |
2129 | ||
98dd22c3 | 2130 | memset(&sio_data, 0, sizeof(struct it87_sio_data)); |
b74f3fdd | 2131 | err = it87_find(&isa_address, &sio_data); |
2132 | if (err) | |
2133 | return err; | |
2134 | err = platform_driver_register(&it87_driver); | |
2135 | if (err) | |
2136 | return err; | |
fde09509 | 2137 | |
b74f3fdd | 2138 | err = it87_device_add(isa_address, &sio_data); |
5f2dc798 | 2139 | if (err) { |
b74f3fdd | 2140 | platform_driver_unregister(&it87_driver); |
2141 | return err; | |
2142 | } | |
2143 | ||
2144 | return 0; | |
1da177e4 LT |
2145 | } |
2146 | ||
2147 | static void __exit sm_it87_exit(void) | |
2148 | { | |
b74f3fdd | 2149 | platform_device_unregister(pdev); |
2150 | platform_driver_unregister(&it87_driver); | |
1da177e4 LT |
2151 | } |
2152 | ||
2153 | ||
f1d8e332 | 2154 | MODULE_AUTHOR("Chris Gauthron, " |
b19367c6 | 2155 | "Jean Delvare <khali@linux-fr.org>"); |
b4da93e4 | 2156 | MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver"); |
1da177e4 LT |
2157 | module_param(update_vbat, bool, 0); |
2158 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); | |
2159 | module_param(fix_pwm_polarity, bool, 0); | |
5f2dc798 JD |
2160 | MODULE_PARM_DESC(fix_pwm_polarity, |
2161 | "Force PWM polarity to active high (DANGEROUS)"); | |
1da177e4 LT |
2162 | MODULE_LICENSE("GPL"); |
2163 | ||
2164 | module_init(sm_it87_init); | |
2165 | module_exit(sm_it87_exit); |