1 /***************************************************************************
2 * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> *
3 * Copyright (C) 2007-2011 Hans de Goede <hdegoede@redhat.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/slab.h>
26 #include <linux/jiffies.h>
27 #include <linux/platform_device.h>
28 #include <linux/hwmon.h>
29 #include <linux/hwmon-sysfs.h>
30 #include <linux/err.h>
31 #include <linux/mutex.h>
33 #include <linux/acpi.h>
35 #define DRVNAME "f71882fg"
37 #define SIO_F71858FG_LD_HWM 0x02 /* Hardware monitor logical device */
38 #define SIO_F71882FG_LD_HWM 0x04 /* Hardware monitor logical device */
39 #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
40 #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
42 #define SIO_REG_LDSEL 0x07 /* Logical device select */
43 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
44 #define SIO_REG_DEVREV 0x22 /* Device revision */
45 #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
46 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
47 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
49 #define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
50 #define SIO_F71858_ID 0x0507 /* Chipset ID */
51 #define SIO_F71862_ID 0x0601 /* Chipset ID */
52 #define SIO_F71882_ID 0x0541 /* Chipset ID */
53 #define SIO_F71889_ID 0x0723 /* Chipset ID */
54 #define SIO_F8000_ID 0x0581 /* Chipset ID */
56 #define REGION_LENGTH 8
57 #define ADDR_REG_OFFSET 5
58 #define DATA_REG_OFFSET 6
60 #define F71882FG_REG_IN_STATUS 0x12 /* f71882fg only */
61 #define F71882FG_REG_IN_BEEP 0x13 /* f71882fg only */
62 #define F71882FG_REG_IN(nr) (0x20 + (nr))
63 #define F71882FG_REG_IN1_HIGH 0x32 /* f71882fg only */
65 #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
66 #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
67 #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
68 #define F71882FG_REG_FAN_STATUS 0x92
69 #define F71882FG_REG_FAN_BEEP 0x93
71 #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
72 #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
73 #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
74 #define F71882FG_REG_TEMP_STATUS 0x62
75 #define F71882FG_REG_TEMP_BEEP 0x63
76 #define F71882FG_REG_TEMP_CONFIG 0x69
77 #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
78 #define F71882FG_REG_TEMP_TYPE 0x6B
79 #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
81 #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
82 #define F71882FG_REG_PWM_TYPE 0x94
83 #define F71882FG_REG_PWM_ENABLE 0x96
85 #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
87 #define F71882FG_REG_FAN_FAULT_T 0x9F
88 #define F71882FG_FAN_NEG_TEMP_EN 0x20
90 #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
91 #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
92 #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
94 #define F71882FG_REG_START 0x01
96 #define F71882FG_MAX_INS 9
98 #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
100 static unsigned short force_id
;
101 module_param(force_id
, ushort
, 0);
102 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
104 enum chips
{ f71858fg
, f71862fg
, f71882fg
, f71889fg
, f8000
};
106 static const char *f71882fg_names
[] = {
114 static const char f71882fg_has_in
[5][F71882FG_MAX_INS
] = {
115 { 1, 1, 1, 0, 0, 0, 0, 0, 0 }, /* f71858fg */
116 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71862fg */
117 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71882fg */
118 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71889fg */
119 { 1, 1, 1, 0, 0, 0, 0, 0, 0 }, /* f8000 */
122 static const char f71882fg_has_in1_alarm
[5] = {
130 static const char f71882fg_has_beep
[5] = {
138 static struct platform_device
*f71882fg_pdev
;
140 /* Super-I/O Function prototypes */
141 static inline int superio_inb(int base
, int reg
);
142 static inline int superio_inw(int base
, int reg
);
143 static inline int superio_enter(int base
);
144 static inline void superio_select(int base
, int ld
);
145 static inline void superio_exit(int base
);
147 struct f71882fg_sio_data
{
151 struct f71882fg_data
{
154 struct device
*hwmon_dev
;
156 struct mutex update_lock
;
157 int temp_start
; /* temp numbering start (0 or 1) */
158 char valid
; /* !=0 if following fields are valid */
159 char auto_point_temp_signed
;
160 unsigned long last_updated
; /* In jiffies */
161 unsigned long last_limits
; /* In jiffies */
163 /* Register Values */
164 u8 in
[F71882FG_MAX_INS
];
170 u16 fan_full_speed
[4];
173 /* Note: all models have only 3 temperature channels, but on some
174 they are addressed as 0-2 and on others as 1-3, so for coding
175 convenience we reserve space for 4 channels */
179 u8 temp_hyst
[2]; /* 2 hysts stored per reg */
187 u8 pwm_auto_point_hyst
[2];
188 u8 pwm_auto_point_mapping
[4];
189 u8 pwm_auto_point_pwm
[4][5];
190 s8 pwm_auto_point_temp
[4][4];
194 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
196 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
197 *devattr
, char *buf
);
198 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
199 *devattr
, const char *buf
, size_t count
);
200 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
201 *devattr
, char *buf
);
202 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
203 *devattr
, const char *buf
, size_t count
);
204 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
205 *devattr
, char *buf
);
207 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
209 static ssize_t
show_fan_full_speed(struct device
*dev
,
210 struct device_attribute
*devattr
, char *buf
);
211 static ssize_t
store_fan_full_speed(struct device
*dev
,
212 struct device_attribute
*devattr
, const char *buf
, size_t count
);
213 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
214 *devattr
, char *buf
);
215 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
216 *devattr
, const char *buf
, size_t count
);
217 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
218 *devattr
, char *buf
);
220 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
221 *devattr
, char *buf
);
222 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
223 *devattr
, char *buf
);
224 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
225 *devattr
, const char *buf
, size_t count
);
226 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
227 *devattr
, char *buf
);
228 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
229 *devattr
, const char *buf
, size_t count
);
230 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
231 *devattr
, char *buf
);
232 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
233 *devattr
, const char *buf
, size_t count
);
234 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
235 *devattr
, char *buf
);
236 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
237 *devattr
, char *buf
);
238 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
239 *devattr
, char *buf
);
240 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
241 *devattr
, const char *buf
, size_t count
);
242 static ssize_t
show_temp_alarm(struct device
*dev
, struct device_attribute
243 *devattr
, char *buf
);
244 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
245 *devattr
, char *buf
);
246 /* PWM and Auto point control */
247 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*devattr
,
249 static ssize_t
store_pwm(struct device
*dev
, struct device_attribute
*devattr
,
250 const char *buf
, size_t count
);
251 static ssize_t
show_pwm_enable(struct device
*dev
,
252 struct device_attribute
*devattr
, char *buf
);
253 static ssize_t
store_pwm_enable(struct device
*dev
,
254 struct device_attribute
*devattr
, const char *buf
, size_t count
);
255 static ssize_t
show_pwm_interpolate(struct device
*dev
,
256 struct device_attribute
*devattr
, char *buf
);
257 static ssize_t
store_pwm_interpolate(struct device
*dev
,
258 struct device_attribute
*devattr
, const char *buf
, size_t count
);
259 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
260 struct device_attribute
*devattr
, char *buf
);
261 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
262 struct device_attribute
*devattr
, const char *buf
, size_t count
);
263 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
264 struct device_attribute
*devattr
, char *buf
);
265 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
266 struct device_attribute
*devattr
, const char *buf
, size_t count
);
267 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
268 struct device_attribute
*devattr
, char *buf
);
269 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
270 struct device_attribute
*devattr
, const char *buf
, size_t count
);
271 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
272 struct device_attribute
*devattr
, char *buf
);
273 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
274 struct device_attribute
*devattr
, const char *buf
, size_t count
);
276 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
279 static int __devinit
f71882fg_probe(struct platform_device
* pdev
);
280 static int f71882fg_remove(struct platform_device
*pdev
);
282 static struct platform_driver f71882fg_driver
= {
284 .owner
= THIS_MODULE
,
287 .probe
= f71882fg_probe
,
288 .remove
= f71882fg_remove
,
291 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
293 /* Temp attr for the f71858fg, the f71858fg is special as it has its
294 temperature indexes start at 0 (the others start at 1) */
295 static struct sensor_device_attribute_2 f71858fg_temp_attr
[] = {
296 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
297 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
298 store_temp_max
, 0, 0),
299 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
300 store_temp_max_hyst
, 0, 0),
301 SENSOR_ATTR_2(temp1_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 0),
302 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
303 store_temp_crit
, 0, 0),
304 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
306 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
307 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
308 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
309 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
310 store_temp_max
, 0, 1),
311 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
312 store_temp_max_hyst
, 0, 1),
313 SENSOR_ATTR_2(temp2_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
314 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
315 store_temp_crit
, 0, 1),
316 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
318 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
319 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
320 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
321 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
322 store_temp_max
, 0, 2),
323 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
324 store_temp_max_hyst
, 0, 2),
325 SENSOR_ATTR_2(temp3_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
326 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
327 store_temp_crit
, 0, 2),
328 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
330 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
331 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
334 /* Temp attr for the standard models */
335 static struct sensor_device_attribute_2 fxxxx_temp_attr
[3][9] = { {
336 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
337 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
338 store_temp_max
, 0, 1),
339 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
340 store_temp_max_hyst
, 0, 1),
341 /* Should really be temp1_max_alarm, but older versions did not handle
342 the max and crit alarms separately and lm_sensors v2 depends on the
343 presence of temp#_alarm files. The same goes for temp2/3 _alarm. */
344 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
345 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
346 store_temp_crit
, 0, 1),
347 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
349 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
350 SENSOR_ATTR_2(temp1_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 1),
351 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
353 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
354 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
355 store_temp_max
, 0, 2),
356 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
357 store_temp_max_hyst
, 0, 2),
358 /* Should be temp2_max_alarm, see temp1_alarm note */
359 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
360 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
361 store_temp_crit
, 0, 2),
362 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
364 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
365 SENSOR_ATTR_2(temp2_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 2),
366 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
368 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 3),
369 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
370 store_temp_max
, 0, 3),
371 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
372 store_temp_max_hyst
, 0, 3),
373 /* Should be temp3_max_alarm, see temp1_alarm note */
374 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 3),
375 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
376 store_temp_crit
, 0, 3),
377 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
379 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 7),
380 SENSOR_ATTR_2(temp3_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 3),
381 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 3),
384 /* Temp attr for models which can beep on temp alarm */
385 static struct sensor_device_attribute_2 fxxxx_temp_beep_attr
[3][2] = { {
386 SENSOR_ATTR_2(temp1_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
387 store_temp_beep
, 0, 1),
388 SENSOR_ATTR_2(temp1_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
389 store_temp_beep
, 0, 5),
391 SENSOR_ATTR_2(temp2_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
392 store_temp_beep
, 0, 2),
393 SENSOR_ATTR_2(temp2_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
394 store_temp_beep
, 0, 6),
396 SENSOR_ATTR_2(temp3_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
397 store_temp_beep
, 0, 3),
398 SENSOR_ATTR_2(temp3_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
399 store_temp_beep
, 0, 7),
402 /* Temp attr for the f8000
403 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
404 is used as hysteresis value to clear alarms
405 Also like the f71858fg its temperature indexes start at 0
407 static struct sensor_device_attribute_2 f8000_temp_attr
[] = {
408 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
409 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
410 store_temp_crit
, 0, 0),
411 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
412 store_temp_max
, 0, 0),
413 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
414 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
415 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
416 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
417 store_temp_crit
, 0, 1),
418 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
419 store_temp_max
, 0, 1),
420 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
421 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
422 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
423 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
424 store_temp_crit
, 0, 2),
425 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
426 store_temp_max
, 0, 2),
427 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
428 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
431 /* in attr for all models */
432 static struct sensor_device_attribute_2 fxxxx_in_attr
[] = {
433 SENSOR_ATTR_2(in0_input
, S_IRUGO
, show_in
, NULL
, 0, 0),
434 SENSOR_ATTR_2(in1_input
, S_IRUGO
, show_in
, NULL
, 0, 1),
435 SENSOR_ATTR_2(in2_input
, S_IRUGO
, show_in
, NULL
, 0, 2),
436 SENSOR_ATTR_2(in3_input
, S_IRUGO
, show_in
, NULL
, 0, 3),
437 SENSOR_ATTR_2(in4_input
, S_IRUGO
, show_in
, NULL
, 0, 4),
438 SENSOR_ATTR_2(in5_input
, S_IRUGO
, show_in
, NULL
, 0, 5),
439 SENSOR_ATTR_2(in6_input
, S_IRUGO
, show_in
, NULL
, 0, 6),
440 SENSOR_ATTR_2(in7_input
, S_IRUGO
, show_in
, NULL
, 0, 7),
441 SENSOR_ATTR_2(in8_input
, S_IRUGO
, show_in
, NULL
, 0, 8),
444 /* For models with in1 alarm capability */
445 static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr
[] = {
446 SENSOR_ATTR_2(in1_max
, S_IRUGO
|S_IWUSR
, show_in_max
, store_in_max
,
448 SENSOR_ATTR_2(in1_beep
, S_IRUGO
|S_IWUSR
, show_in_beep
, store_in_beep
,
450 SENSOR_ATTR_2(in1_alarm
, S_IRUGO
, show_in_alarm
, NULL
, 0, 1),
453 /* Fan / PWM attr common to all models */
454 static struct sensor_device_attribute_2 fxxxx_fan_attr
[4][6] = { {
455 SENSOR_ATTR_2(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0, 0),
456 SENSOR_ATTR_2(fan1_full_speed
, S_IRUGO
|S_IWUSR
,
458 store_fan_full_speed
, 0, 0),
459 SENSOR_ATTR_2(fan1_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 0),
460 SENSOR_ATTR_2(pwm1
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 0),
461 SENSOR_ATTR_2(pwm1_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
462 store_pwm_enable
, 0, 0),
463 SENSOR_ATTR_2(pwm1_interpolate
, S_IRUGO
|S_IWUSR
,
464 show_pwm_interpolate
, store_pwm_interpolate
, 0, 0),
466 SENSOR_ATTR_2(fan2_input
, S_IRUGO
, show_fan
, NULL
, 0, 1),
467 SENSOR_ATTR_2(fan2_full_speed
, S_IRUGO
|S_IWUSR
,
469 store_fan_full_speed
, 0, 1),
470 SENSOR_ATTR_2(fan2_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 1),
471 SENSOR_ATTR_2(pwm2
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 1),
472 SENSOR_ATTR_2(pwm2_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
473 store_pwm_enable
, 0, 1),
474 SENSOR_ATTR_2(pwm2_interpolate
, S_IRUGO
|S_IWUSR
,
475 show_pwm_interpolate
, store_pwm_interpolate
, 0, 1),
477 SENSOR_ATTR_2(fan3_input
, S_IRUGO
, show_fan
, NULL
, 0, 2),
478 SENSOR_ATTR_2(fan3_full_speed
, S_IRUGO
|S_IWUSR
,
480 store_fan_full_speed
, 0, 2),
481 SENSOR_ATTR_2(fan3_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 2),
482 SENSOR_ATTR_2(pwm3
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 2),
483 SENSOR_ATTR_2(pwm3_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
484 store_pwm_enable
, 0, 2),
485 SENSOR_ATTR_2(pwm3_interpolate
, S_IRUGO
|S_IWUSR
,
486 show_pwm_interpolate
, store_pwm_interpolate
, 0, 2),
488 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
489 SENSOR_ATTR_2(fan4_full_speed
, S_IRUGO
|S_IWUSR
,
491 store_fan_full_speed
, 0, 3),
492 SENSOR_ATTR_2(fan4_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 3),
493 SENSOR_ATTR_2(pwm4
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 3),
494 SENSOR_ATTR_2(pwm4_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
495 store_pwm_enable
, 0, 3),
496 SENSOR_ATTR_2(pwm4_interpolate
, S_IRUGO
|S_IWUSR
,
497 show_pwm_interpolate
, store_pwm_interpolate
, 0, 3),
500 /* Attr for models which can beep on Fan alarm */
501 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr
[] = {
502 SENSOR_ATTR_2(fan1_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
503 store_fan_beep
, 0, 0),
504 SENSOR_ATTR_2(fan2_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
505 store_fan_beep
, 0, 1),
506 SENSOR_ATTR_2(fan3_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
507 store_fan_beep
, 0, 2),
508 SENSOR_ATTR_2(fan4_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
509 store_fan_beep
, 0, 3),
512 /* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
513 f71858fg / f71882fg / f71889fg */
514 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr
[] = {
515 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
516 show_pwm_auto_point_channel
,
517 store_pwm_auto_point_channel
, 0, 0),
518 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
519 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
521 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
522 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
524 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
525 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
527 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
528 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
530 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
531 show_pwm_auto_point_temp_hyst
,
532 store_pwm_auto_point_temp_hyst
,
534 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
535 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
537 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
538 show_pwm_auto_point_channel
,
539 store_pwm_auto_point_channel
, 0, 1),
540 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
541 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
543 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
544 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
546 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
547 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
549 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
550 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
552 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
553 show_pwm_auto_point_temp_hyst
,
554 store_pwm_auto_point_temp_hyst
,
556 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
557 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
559 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
560 show_pwm_auto_point_channel
,
561 store_pwm_auto_point_channel
, 0, 2),
562 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
563 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
565 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
566 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
568 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
569 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
571 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
572 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
574 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
575 show_pwm_auto_point_temp_hyst
,
576 store_pwm_auto_point_temp_hyst
,
578 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
579 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
582 /* PWM attr common to the f71858fg, f71882fg and f71889fg */
583 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr
[4][14] = { {
584 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
585 show_pwm_auto_point_channel
,
586 store_pwm_auto_point_channel
, 0, 0),
587 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
588 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
590 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
591 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
593 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
594 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
596 SENSOR_ATTR_2(pwm1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
597 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
599 SENSOR_ATTR_2(pwm1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
600 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
602 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
603 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
605 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
606 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
608 SENSOR_ATTR_2(pwm1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
609 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
611 SENSOR_ATTR_2(pwm1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
612 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
614 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
615 show_pwm_auto_point_temp_hyst
,
616 store_pwm_auto_point_temp_hyst
,
618 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
619 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
620 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst
, S_IRUGO
,
621 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
622 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst
, S_IRUGO
,
623 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
625 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
626 show_pwm_auto_point_channel
,
627 store_pwm_auto_point_channel
, 0, 1),
628 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
629 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
631 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
632 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
634 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
635 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
637 SENSOR_ATTR_2(pwm2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
638 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
640 SENSOR_ATTR_2(pwm2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
641 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
643 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
644 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
646 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
647 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
649 SENSOR_ATTR_2(pwm2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
650 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
652 SENSOR_ATTR_2(pwm2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
653 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
655 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
656 show_pwm_auto_point_temp_hyst
,
657 store_pwm_auto_point_temp_hyst
,
659 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
660 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
661 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst
, S_IRUGO
,
662 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
663 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst
, S_IRUGO
,
664 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
666 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
667 show_pwm_auto_point_channel
,
668 store_pwm_auto_point_channel
, 0, 2),
669 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
670 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
672 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
673 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
675 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
676 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
678 SENSOR_ATTR_2(pwm3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
679 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
681 SENSOR_ATTR_2(pwm3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
682 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
684 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
685 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
687 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
688 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
690 SENSOR_ATTR_2(pwm3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
691 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
693 SENSOR_ATTR_2(pwm3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
694 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
696 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
697 show_pwm_auto_point_temp_hyst
,
698 store_pwm_auto_point_temp_hyst
,
700 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
701 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
702 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst
, S_IRUGO
,
703 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
704 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst
, S_IRUGO
,
705 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
707 SENSOR_ATTR_2(pwm4_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
708 show_pwm_auto_point_channel
,
709 store_pwm_auto_point_channel
, 0, 3),
710 SENSOR_ATTR_2(pwm4_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
711 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
713 SENSOR_ATTR_2(pwm4_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
714 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
716 SENSOR_ATTR_2(pwm4_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
717 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
719 SENSOR_ATTR_2(pwm4_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
720 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
722 SENSOR_ATTR_2(pwm4_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
723 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
725 SENSOR_ATTR_2(pwm4_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
726 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
728 SENSOR_ATTR_2(pwm4_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
729 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
731 SENSOR_ATTR_2(pwm4_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
732 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
734 SENSOR_ATTR_2(pwm4_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
735 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
737 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
738 show_pwm_auto_point_temp_hyst
,
739 store_pwm_auto_point_temp_hyst
,
741 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst
, S_IRUGO
,
742 show_pwm_auto_point_temp_hyst
, NULL
, 1, 3),
743 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst
, S_IRUGO
,
744 show_pwm_auto_point_temp_hyst
, NULL
, 2, 3),
745 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst
, S_IRUGO
,
746 show_pwm_auto_point_temp_hyst
, NULL
, 3, 3),
749 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
750 static struct sensor_device_attribute_2 f8000_fan_attr
[] = {
751 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
754 /* PWM attr for the f8000, zones mapped to temp instead of to pwm!
755 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
756 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
757 static struct sensor_device_attribute_2 f8000_auto_pwm_attr
[] = {
758 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
759 show_pwm_auto_point_channel
,
760 store_pwm_auto_point_channel
, 0, 0),
761 SENSOR_ATTR_2(temp1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
762 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
764 SENSOR_ATTR_2(temp1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
765 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
767 SENSOR_ATTR_2(temp1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
768 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
770 SENSOR_ATTR_2(temp1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
771 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
773 SENSOR_ATTR_2(temp1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
774 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
776 SENSOR_ATTR_2(temp1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
777 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
779 SENSOR_ATTR_2(temp1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
780 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
782 SENSOR_ATTR_2(temp1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
783 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
785 SENSOR_ATTR_2(temp1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
786 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
788 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
789 show_pwm_auto_point_temp_hyst
,
790 store_pwm_auto_point_temp_hyst
,
792 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst
, S_IRUGO
,
793 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
794 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst
, S_IRUGO
,
795 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
796 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst
, S_IRUGO
,
797 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
799 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
800 show_pwm_auto_point_channel
,
801 store_pwm_auto_point_channel
, 0, 1),
802 SENSOR_ATTR_2(temp2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
803 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
805 SENSOR_ATTR_2(temp2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
806 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
808 SENSOR_ATTR_2(temp2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
809 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
811 SENSOR_ATTR_2(temp2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
812 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
814 SENSOR_ATTR_2(temp2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
815 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
817 SENSOR_ATTR_2(temp2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
818 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
820 SENSOR_ATTR_2(temp2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
821 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
823 SENSOR_ATTR_2(temp2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
824 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
826 SENSOR_ATTR_2(temp2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
827 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
829 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
830 show_pwm_auto_point_temp_hyst
,
831 store_pwm_auto_point_temp_hyst
,
833 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst
, S_IRUGO
,
834 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
835 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst
, S_IRUGO
,
836 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
837 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst
, S_IRUGO
,
838 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
840 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
841 show_pwm_auto_point_channel
,
842 store_pwm_auto_point_channel
, 0, 2),
843 SENSOR_ATTR_2(temp3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
844 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
846 SENSOR_ATTR_2(temp3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
847 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
849 SENSOR_ATTR_2(temp3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
850 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
852 SENSOR_ATTR_2(temp3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
853 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
855 SENSOR_ATTR_2(temp3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
856 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
858 SENSOR_ATTR_2(temp3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
859 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
861 SENSOR_ATTR_2(temp3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
862 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
864 SENSOR_ATTR_2(temp3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
865 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
867 SENSOR_ATTR_2(temp3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
868 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
870 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
871 show_pwm_auto_point_temp_hyst
,
872 store_pwm_auto_point_temp_hyst
,
874 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst
, S_IRUGO
,
875 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
876 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst
, S_IRUGO
,
877 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
878 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst
, S_IRUGO
,
879 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
882 /* Super I/O functions */
883 static inline int superio_inb(int base
, int reg
)
886 return inb(base
+ 1);
889 static int superio_inw(int base
, int reg
)
892 val
= superio_inb(base
, reg
) << 8;
893 val
|= superio_inb(base
, reg
+ 1);
897 static inline int superio_enter(int base
)
899 /* Don't step on other drivers' I/O space by accident */
900 if (!request_muxed_region(base
, 2, DRVNAME
)) {
901 pr_err("I/O address 0x%04x already in use\n", base
);
905 /* according to the datasheet the key must be send twice! */
906 outb(SIO_UNLOCK_KEY
, base
);
907 outb(SIO_UNLOCK_KEY
, base
);
912 static inline void superio_select(int base
, int ld
)
914 outb(SIO_REG_LDSEL
, base
);
918 static inline void superio_exit(int base
)
920 outb(SIO_LOCK_KEY
, base
);
921 release_region(base
, 2);
924 static inline int fan_from_reg(u16 reg
)
926 return reg
? (1500000 / reg
) : 0;
929 static inline u16
fan_to_reg(int fan
)
931 return fan
? (1500000 / fan
) : 0;
934 static u8
f71882fg_read8(struct f71882fg_data
*data
, u8 reg
)
938 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
939 val
= inb(data
->addr
+ DATA_REG_OFFSET
);
944 static u16
f71882fg_read16(struct f71882fg_data
*data
, u8 reg
)
948 val
= f71882fg_read8(data
, reg
) << 8;
949 val
|= f71882fg_read8(data
, reg
+ 1);
954 static void f71882fg_write8(struct f71882fg_data
*data
, u8 reg
, u8 val
)
956 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
957 outb(val
, data
->addr
+ DATA_REG_OFFSET
);
960 static void f71882fg_write16(struct f71882fg_data
*data
, u8 reg
, u16 val
)
962 f71882fg_write8(data
, reg
, val
>> 8);
963 f71882fg_write8(data
, reg
+ 1, val
& 0xff);
966 static u16
f71882fg_read_temp(struct f71882fg_data
*data
, int nr
)
968 if (data
->type
== f71858fg
)
969 return f71882fg_read16(data
, F71882FG_REG_TEMP(nr
));
971 return f71882fg_read8(data
, F71882FG_REG_TEMP(nr
));
974 static struct f71882fg_data
*f71882fg_update_device(struct device
*dev
)
976 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
978 int nr_fans
= (data
->type
== f71882fg
) ? 4 : 3;
980 mutex_lock(&data
->update_lock
);
982 /* Update once every 60 seconds */
983 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
) ||
985 if (f71882fg_has_in1_alarm
[data
->type
]) {
987 f71882fg_read8(data
, F71882FG_REG_IN1_HIGH
);
989 f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
992 /* Get High & boundary temps*/
993 for (nr
= data
->temp_start
; nr
< 3 + data
->temp_start
; nr
++) {
994 data
->temp_ovt
[nr
] = f71882fg_read8(data
,
995 F71882FG_REG_TEMP_OVT(nr
));
996 data
->temp_high
[nr
] = f71882fg_read8(data
,
997 F71882FG_REG_TEMP_HIGH(nr
));
1000 if (data
->type
!= f8000
) {
1001 data
->temp_hyst
[0] = f71882fg_read8(data
,
1002 F71882FG_REG_TEMP_HYST(0));
1003 data
->temp_hyst
[1] = f71882fg_read8(data
,
1004 F71882FG_REG_TEMP_HYST(1));
1006 /* All but the f71858fg / f8000 have this register */
1007 if ((data
->type
!= f71858fg
) && (data
->type
!= f8000
)) {
1008 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_TYPE
);
1009 data
->temp_type
[1] = (reg
& 0x02) ? 2 : 4;
1010 data
->temp_type
[2] = (reg
& 0x04) ? 2 : 4;
1011 data
->temp_type
[3] = (reg
& 0x08) ? 2 : 4;
1014 if (f71882fg_has_beep
[data
->type
]) {
1015 data
->fan_beep
= f71882fg_read8(data
,
1016 F71882FG_REG_FAN_BEEP
);
1017 data
->temp_beep
= f71882fg_read8(data
,
1018 F71882FG_REG_TEMP_BEEP
);
1021 data
->pwm_enable
= f71882fg_read8(data
,
1022 F71882FG_REG_PWM_ENABLE
);
1023 data
->pwm_auto_point_hyst
[0] =
1024 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(0));
1025 data
->pwm_auto_point_hyst
[1] =
1026 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(1));
1028 for (nr
= 0; nr
< nr_fans
; nr
++) {
1029 data
->pwm_auto_point_mapping
[nr
] =
1030 f71882fg_read8(data
,
1031 F71882FG_REG_POINT_MAPPING(nr
));
1033 if (data
->type
!= f71862fg
) {
1035 for (point
= 0; point
< 5; point
++) {
1036 data
->pwm_auto_point_pwm
[nr
][point
] =
1037 f71882fg_read8(data
,
1038 F71882FG_REG_POINT_PWM
1041 for (point
= 0; point
< 4; point
++) {
1042 data
->pwm_auto_point_temp
[nr
][point
] =
1043 f71882fg_read8(data
,
1044 F71882FG_REG_POINT_TEMP
1048 data
->pwm_auto_point_pwm
[nr
][1] =
1049 f71882fg_read8(data
,
1050 F71882FG_REG_POINT_PWM
1052 data
->pwm_auto_point_pwm
[nr
][4] =
1053 f71882fg_read8(data
,
1054 F71882FG_REG_POINT_PWM
1056 data
->pwm_auto_point_temp
[nr
][0] =
1057 f71882fg_read8(data
,
1058 F71882FG_REG_POINT_TEMP
1060 data
->pwm_auto_point_temp
[nr
][3] =
1061 f71882fg_read8(data
,
1062 F71882FG_REG_POINT_TEMP
1066 data
->last_limits
= jiffies
;
1069 /* Update every second */
1070 if (time_after(jiffies
, data
->last_updated
+ HZ
) || !data
->valid
) {
1071 data
->temp_status
= f71882fg_read8(data
,
1072 F71882FG_REG_TEMP_STATUS
);
1073 data
->temp_diode_open
= f71882fg_read8(data
,
1074 F71882FG_REG_TEMP_DIODE_OPEN
);
1075 for (nr
= data
->temp_start
; nr
< 3 + data
->temp_start
; nr
++)
1076 data
->temp
[nr
] = f71882fg_read_temp(data
, nr
);
1078 data
->fan_status
= f71882fg_read8(data
,
1079 F71882FG_REG_FAN_STATUS
);
1080 for (nr
= 0; nr
< nr_fans
; nr
++) {
1081 data
->fan
[nr
] = f71882fg_read16(data
,
1082 F71882FG_REG_FAN(nr
));
1083 data
->fan_target
[nr
] =
1084 f71882fg_read16(data
, F71882FG_REG_FAN_TARGET(nr
));
1085 data
->fan_full_speed
[nr
] =
1086 f71882fg_read16(data
,
1087 F71882FG_REG_FAN_FULL_SPEED(nr
));
1089 f71882fg_read8(data
, F71882FG_REG_PWM(nr
));
1091 /* The f8000 can monitor 1 more fan, but has no pwm for it */
1092 if (data
->type
== f8000
)
1093 data
->fan
[3] = f71882fg_read16(data
,
1094 F71882FG_REG_FAN(3));
1096 if (f71882fg_has_in1_alarm
[data
->type
])
1097 data
->in_status
= f71882fg_read8(data
,
1098 F71882FG_REG_IN_STATUS
);
1099 for (nr
= 0; nr
< F71882FG_MAX_INS
; nr
++)
1100 if (f71882fg_has_in
[data
->type
][nr
])
1101 data
->in
[nr
] = f71882fg_read8(data
,
1102 F71882FG_REG_IN(nr
));
1104 data
->last_updated
= jiffies
;
1108 mutex_unlock(&data
->update_lock
);
1113 /* Sysfs Interface */
1114 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
1117 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1118 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1119 int speed
= fan_from_reg(data
->fan
[nr
]);
1121 if (speed
== FAN_MIN_DETECT
)
1124 return sprintf(buf
, "%d\n", speed
);
1127 static ssize_t
show_fan_full_speed(struct device
*dev
,
1128 struct device_attribute
*devattr
, char *buf
)
1130 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1131 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1132 int speed
= fan_from_reg(data
->fan_full_speed
[nr
]);
1133 return sprintf(buf
, "%d\n", speed
);
1136 static ssize_t
store_fan_full_speed(struct device
*dev
,
1137 struct device_attribute
*devattr
,
1138 const char *buf
, size_t count
)
1140 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1141 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1144 err
= strict_strtol(buf
, 10, &val
);
1148 val
= SENSORS_LIMIT(val
, 23, 1500000);
1149 val
= fan_to_reg(val
);
1151 mutex_lock(&data
->update_lock
);
1152 f71882fg_write16(data
, F71882FG_REG_FAN_FULL_SPEED(nr
), val
);
1153 data
->fan_full_speed
[nr
] = val
;
1154 mutex_unlock(&data
->update_lock
);
1159 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
1160 *devattr
, char *buf
)
1162 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1163 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1165 if (data
->fan_beep
& (1 << nr
))
1166 return sprintf(buf
, "1\n");
1168 return sprintf(buf
, "0\n");
1171 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
1172 *devattr
, const char *buf
, size_t count
)
1174 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1175 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1178 err
= strict_strtoul(buf
, 10, &val
);
1182 mutex_lock(&data
->update_lock
);
1183 data
->fan_beep
= f71882fg_read8(data
, F71882FG_REG_FAN_BEEP
);
1185 data
->fan_beep
|= 1 << nr
;
1187 data
->fan_beep
&= ~(1 << nr
);
1189 f71882fg_write8(data
, F71882FG_REG_FAN_BEEP
, data
->fan_beep
);
1190 mutex_unlock(&data
->update_lock
);
1195 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
1196 *devattr
, char *buf
)
1198 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1199 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1201 if (data
->fan_status
& (1 << nr
))
1202 return sprintf(buf
, "1\n");
1204 return sprintf(buf
, "0\n");
1207 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
1210 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1211 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1213 return sprintf(buf
, "%d\n", data
->in
[nr
] * 8);
1216 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
1217 *devattr
, char *buf
)
1219 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1221 return sprintf(buf
, "%d\n", data
->in1_max
* 8);
1224 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
1225 *devattr
, const char *buf
, size_t count
)
1227 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1231 err
= strict_strtol(buf
, 10, &val
);
1236 val
= SENSORS_LIMIT(val
, 0, 255);
1238 mutex_lock(&data
->update_lock
);
1239 f71882fg_write8(data
, F71882FG_REG_IN1_HIGH
, val
);
1240 data
->in1_max
= val
;
1241 mutex_unlock(&data
->update_lock
);
1246 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
1247 *devattr
, char *buf
)
1249 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1250 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1252 if (data
->in_beep
& (1 << nr
))
1253 return sprintf(buf
, "1\n");
1255 return sprintf(buf
, "0\n");
1258 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
1259 *devattr
, const char *buf
, size_t count
)
1261 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1262 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1265 err
= strict_strtoul(buf
, 10, &val
);
1269 mutex_lock(&data
->update_lock
);
1270 data
->in_beep
= f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1272 data
->in_beep
|= 1 << nr
;
1274 data
->in_beep
&= ~(1 << nr
);
1276 f71882fg_write8(data
, F71882FG_REG_IN_BEEP
, data
->in_beep
);
1277 mutex_unlock(&data
->update_lock
);
1282 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
1283 *devattr
, char *buf
)
1285 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1286 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1288 if (data
->in_status
& (1 << nr
))
1289 return sprintf(buf
, "1\n");
1291 return sprintf(buf
, "0\n");
1294 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*devattr
,
1297 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1298 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1301 if (data
->type
== f71858fg
) {
1302 /* TEMP_TABLE_SEL 1 or 3 ? */
1303 if (data
->temp_config
& 1) {
1304 sign
= data
->temp
[nr
] & 0x0001;
1305 temp
= (data
->temp
[nr
] >> 5) & 0x7ff;
1307 sign
= data
->temp
[nr
] & 0x8000;
1308 temp
= (data
->temp
[nr
] >> 5) & 0x3ff;
1314 temp
= data
->temp
[nr
] * 1000;
1316 return sprintf(buf
, "%d\n", temp
);
1319 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
1320 *devattr
, char *buf
)
1322 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1323 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1325 return sprintf(buf
, "%d\n", data
->temp_high
[nr
] * 1000);
1328 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
1329 *devattr
, const char *buf
, size_t count
)
1331 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1332 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1335 err
= strict_strtol(buf
, 10, &val
);
1340 val
= SENSORS_LIMIT(val
, 0, 255);
1342 mutex_lock(&data
->update_lock
);
1343 f71882fg_write8(data
, F71882FG_REG_TEMP_HIGH(nr
), val
);
1344 data
->temp_high
[nr
] = val
;
1345 mutex_unlock(&data
->update_lock
);
1350 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
1351 *devattr
, char *buf
)
1353 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1354 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1357 mutex_lock(&data
->update_lock
);
1359 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1361 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1362 temp_max_hyst
= (data
->temp_high
[nr
] - temp_max_hyst
) * 1000;
1363 mutex_unlock(&data
->update_lock
);
1365 return sprintf(buf
, "%d\n", temp_max_hyst
);
1368 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
1369 *devattr
, const char *buf
, size_t count
)
1371 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1372 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1373 ssize_t ret
= count
;
1377 err
= strict_strtol(buf
, 10, &val
);
1383 mutex_lock(&data
->update_lock
);
1385 /* convert abs to relative and check */
1386 data
->temp_high
[nr
] = f71882fg_read8(data
, F71882FG_REG_TEMP_HIGH(nr
));
1387 val
= SENSORS_LIMIT(val
, data
->temp_high
[nr
] - 15,
1388 data
->temp_high
[nr
]);
1389 val
= data
->temp_high
[nr
] - val
;
1391 /* convert value to register contents */
1392 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2));
1394 reg
= (reg
& 0x0f) | (val
<< 4);
1396 reg
= (reg
& 0xf0) | val
;
1397 f71882fg_write8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2), reg
);
1398 data
->temp_hyst
[nr
/ 2] = reg
;
1400 mutex_unlock(&data
->update_lock
);
1404 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
1405 *devattr
, char *buf
)
1407 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1408 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1410 return sprintf(buf
, "%d\n", data
->temp_ovt
[nr
] * 1000);
1413 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
1414 *devattr
, const char *buf
, size_t count
)
1416 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1417 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1420 err
= strict_strtol(buf
, 10, &val
);
1425 val
= SENSORS_LIMIT(val
, 0, 255);
1427 mutex_lock(&data
->update_lock
);
1428 f71882fg_write8(data
, F71882FG_REG_TEMP_OVT(nr
), val
);
1429 data
->temp_ovt
[nr
] = val
;
1430 mutex_unlock(&data
->update_lock
);
1435 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
1436 *devattr
, char *buf
)
1438 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1439 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1442 mutex_lock(&data
->update_lock
);
1444 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1446 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1447 temp_crit_hyst
= (data
->temp_ovt
[nr
] - temp_crit_hyst
) * 1000;
1448 mutex_unlock(&data
->update_lock
);
1450 return sprintf(buf
, "%d\n", temp_crit_hyst
);
1453 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
1454 *devattr
, char *buf
)
1456 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1457 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1459 return sprintf(buf
, "%d\n", data
->temp_type
[nr
]);
1462 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
1463 *devattr
, char *buf
)
1465 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1466 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1468 if (data
->temp_beep
& (1 << nr
))
1469 return sprintf(buf
, "1\n");
1471 return sprintf(buf
, "0\n");
1474 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
1475 *devattr
, const char *buf
, size_t count
)
1477 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1478 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1481 err
= strict_strtoul(buf
, 10, &val
);
1485 mutex_lock(&data
->update_lock
);
1486 data
->temp_beep
= f71882fg_read8(data
, F71882FG_REG_TEMP_BEEP
);
1488 data
->temp_beep
|= 1 << nr
;
1490 data
->temp_beep
&= ~(1 << nr
);
1492 f71882fg_write8(data
, F71882FG_REG_TEMP_BEEP
, data
->temp_beep
);
1493 mutex_unlock(&data
->update_lock
);
1498 static ssize_t
show_temp_alarm(struct device
*dev
, struct device_attribute
1499 *devattr
, char *buf
)
1501 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1502 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1504 if (data
->temp_status
& (1 << nr
))
1505 return sprintf(buf
, "1\n");
1507 return sprintf(buf
, "0\n");
1510 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
1511 *devattr
, char *buf
)
1513 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1514 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1516 if (data
->temp_diode_open
& (1 << nr
))
1517 return sprintf(buf
, "1\n");
1519 return sprintf(buf
, "0\n");
1522 static ssize_t
show_pwm(struct device
*dev
,
1523 struct device_attribute
*devattr
, char *buf
)
1525 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1526 int val
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1527 mutex_lock(&data
->update_lock
);
1528 if (data
->pwm_enable
& (1 << (2 * nr
)))
1530 val
= data
->pwm
[nr
];
1533 val
= 255 * fan_from_reg(data
->fan_target
[nr
])
1534 / fan_from_reg(data
->fan_full_speed
[nr
]);
1536 mutex_unlock(&data
->update_lock
);
1537 return sprintf(buf
, "%d\n", val
);
1540 static ssize_t
store_pwm(struct device
*dev
,
1541 struct device_attribute
*devattr
, const char *buf
,
1544 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1545 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1548 err
= strict_strtol(buf
, 10, &val
);
1552 val
= SENSORS_LIMIT(val
, 0, 255);
1554 mutex_lock(&data
->update_lock
);
1555 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1556 if ((data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 3) != 2) ||
1557 (data
->type
!= f8000
&& !((data
->pwm_enable
>> 2 * nr
) & 2))) {
1561 if (data
->pwm_enable
& (1 << (2 * nr
))) {
1563 f71882fg_write8(data
, F71882FG_REG_PWM(nr
), val
);
1564 data
->pwm
[nr
] = val
;
1567 int target
, full_speed
;
1568 full_speed
= f71882fg_read16(data
,
1569 F71882FG_REG_FAN_FULL_SPEED(nr
));
1570 target
= fan_to_reg(val
* fan_from_reg(full_speed
) / 255);
1571 f71882fg_write16(data
, F71882FG_REG_FAN_TARGET(nr
), target
);
1572 data
->fan_target
[nr
] = target
;
1573 data
->fan_full_speed
[nr
] = full_speed
;
1576 mutex_unlock(&data
->update_lock
);
1581 static ssize_t
show_pwm_enable(struct device
*dev
,
1582 struct device_attribute
*devattr
, char *buf
)
1585 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1586 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1588 switch ((data
->pwm_enable
>> 2 * nr
) & 3) {
1591 result
= 2; /* Normal auto mode */
1594 result
= 1; /* Manual mode */
1597 if (data
->type
== f8000
)
1598 result
= 3; /* Thermostat mode */
1600 result
= 1; /* Manual mode */
1604 return sprintf(buf
, "%d\n", result
);
1607 static ssize_t
store_pwm_enable(struct device
*dev
, struct device_attribute
1608 *devattr
, const char *buf
, size_t count
)
1610 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1611 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1614 err
= strict_strtol(buf
, 10, &val
);
1618 /* Special case for F8000 pwm channel 3 which only does auto mode */
1619 if (data
->type
== f8000
&& nr
== 2 && val
!= 2)
1622 mutex_lock(&data
->update_lock
);
1623 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1624 /* Special case for F8000 auto PWM mode / Thermostat mode */
1625 if (data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 1)) {
1628 data
->pwm_enable
&= ~(2 << (2 * nr
));
1629 break; /* Normal auto mode */
1631 data
->pwm_enable
|= 2 << (2 * nr
);
1632 break; /* Thermostat mode */
1640 /* The f71858fg does not support manual RPM mode */
1641 if (data
->type
== f71858fg
&&
1642 ((data
->pwm_enable
>> (2 * nr
)) & 1)) {
1646 data
->pwm_enable
|= 2 << (2 * nr
);
1649 data
->pwm_enable
&= ~(2 << (2 * nr
));
1650 break; /* Normal auto mode */
1656 f71882fg_write8(data
, F71882FG_REG_PWM_ENABLE
, data
->pwm_enable
);
1658 mutex_unlock(&data
->update_lock
);
1663 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
1664 struct device_attribute
*devattr
,
1668 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1669 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1670 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1672 mutex_lock(&data
->update_lock
);
1673 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1675 result
= data
->pwm_auto_point_pwm
[pwm
][point
];
1678 result
= 32 * 255 / (32 + data
->pwm_auto_point_pwm
[pwm
][point
]);
1680 mutex_unlock(&data
->update_lock
);
1682 return sprintf(buf
, "%d\n", result
);
1685 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
1686 struct device_attribute
*devattr
,
1687 const char *buf
, size_t count
)
1689 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1690 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1691 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1694 err
= strict_strtol(buf
, 10, &val
);
1698 val
= SENSORS_LIMIT(val
, 0, 255);
1700 mutex_lock(&data
->update_lock
);
1701 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1702 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1706 if (val
< 29) /* Prevent negative numbers */
1709 val
= (255 - val
) * 32 / val
;
1711 f71882fg_write8(data
, F71882FG_REG_POINT_PWM(pwm
, point
), val
);
1712 data
->pwm_auto_point_pwm
[pwm
][point
] = val
;
1713 mutex_unlock(&data
->update_lock
);
1718 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
1719 struct device_attribute
*devattr
,
1723 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1724 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1725 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1727 mutex_lock(&data
->update_lock
);
1729 result
= data
->pwm_auto_point_hyst
[nr
/ 2] >> 4;
1731 result
= data
->pwm_auto_point_hyst
[nr
/ 2] & 0x0f;
1732 result
= 1000 * (data
->pwm_auto_point_temp
[nr
][point
] - result
);
1733 mutex_unlock(&data
->update_lock
);
1735 return sprintf(buf
, "%d\n", result
);
1738 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
1739 struct device_attribute
*devattr
,
1740 const char *buf
, size_t count
)
1742 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1743 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1744 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1748 err
= strict_strtol(buf
, 10, &val
);
1754 mutex_lock(&data
->update_lock
);
1755 data
->pwm_auto_point_temp
[nr
][point
] =
1756 f71882fg_read8(data
, F71882FG_REG_POINT_TEMP(nr
, point
));
1757 val
= SENSORS_LIMIT(val
, data
->pwm_auto_point_temp
[nr
][point
] - 15,
1758 data
->pwm_auto_point_temp
[nr
][point
]);
1759 val
= data
->pwm_auto_point_temp
[nr
][point
] - val
;
1761 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_HYST(nr
/ 2));
1763 reg
= (reg
& 0x0f) | (val
<< 4);
1765 reg
= (reg
& 0xf0) | val
;
1767 f71882fg_write8(data
, F71882FG_REG_FAN_HYST(nr
/ 2), reg
);
1768 data
->pwm_auto_point_hyst
[nr
/ 2] = reg
;
1769 mutex_unlock(&data
->update_lock
);
1774 static ssize_t
show_pwm_interpolate(struct device
*dev
,
1775 struct device_attribute
*devattr
, char *buf
)
1778 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1779 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1781 result
= (data
->pwm_auto_point_mapping
[nr
] >> 4) & 1;
1783 return sprintf(buf
, "%d\n", result
);
1786 static ssize_t
store_pwm_interpolate(struct device
*dev
,
1787 struct device_attribute
*devattr
,
1788 const char *buf
, size_t count
)
1790 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1791 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1794 err
= strict_strtoul(buf
, 10, &val
);
1798 mutex_lock(&data
->update_lock
);
1799 data
->pwm_auto_point_mapping
[nr
] =
1800 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
1802 val
= data
->pwm_auto_point_mapping
[nr
] | (1 << 4);
1804 val
= data
->pwm_auto_point_mapping
[nr
] & (~(1 << 4));
1805 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
1806 data
->pwm_auto_point_mapping
[nr
] = val
;
1807 mutex_unlock(&data
->update_lock
);
1812 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
1813 struct device_attribute
*devattr
,
1817 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1818 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1820 result
= 1 << ((data
->pwm_auto_point_mapping
[nr
] & 3) -
1823 return sprintf(buf
, "%d\n", result
);
1826 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
1827 struct device_attribute
*devattr
,
1828 const char *buf
, size_t count
)
1830 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1831 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1834 err
= strict_strtol(buf
, 10, &val
);
1851 val
+= data
->temp_start
;
1852 mutex_lock(&data
->update_lock
);
1853 data
->pwm_auto_point_mapping
[nr
] =
1854 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
1855 val
= (data
->pwm_auto_point_mapping
[nr
] & 0xfc) | val
;
1856 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
1857 data
->pwm_auto_point_mapping
[nr
] = val
;
1858 mutex_unlock(&data
->update_lock
);
1863 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
1864 struct device_attribute
*devattr
,
1868 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1869 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1870 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1872 result
= data
->pwm_auto_point_temp
[pwm
][point
];
1873 return sprintf(buf
, "%d\n", 1000 * result
);
1876 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
1877 struct device_attribute
*devattr
,
1878 const char *buf
, size_t count
)
1880 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1881 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1882 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1885 err
= strict_strtol(buf
, 10, &val
);
1891 if (data
->auto_point_temp_signed
)
1892 val
= SENSORS_LIMIT(val
, -128, 127);
1894 val
= SENSORS_LIMIT(val
, 0, 127);
1896 mutex_lock(&data
->update_lock
);
1897 f71882fg_write8(data
, F71882FG_REG_POINT_TEMP(pwm
, point
), val
);
1898 data
->pwm_auto_point_temp
[pwm
][point
] = val
;
1899 mutex_unlock(&data
->update_lock
);
1904 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
1907 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1908 return sprintf(buf
, "%s\n", f71882fg_names
[data
->type
]);
1911 static int __devinit
f71882fg_create_sysfs_files(struct platform_device
*pdev
,
1912 struct sensor_device_attribute_2
*attr
, int count
)
1916 for (i
= 0; i
< count
; i
++) {
1917 err
= device_create_file(&pdev
->dev
, &attr
[i
].dev_attr
);
1924 static void f71882fg_remove_sysfs_files(struct platform_device
*pdev
,
1925 struct sensor_device_attribute_2
*attr
, int count
)
1929 for (i
= 0; i
< count
; i
++)
1930 device_remove_file(&pdev
->dev
, &attr
[i
].dev_attr
);
1933 static int __devinit
f71882fg_probe(struct platform_device
*pdev
)
1935 struct f71882fg_data
*data
;
1936 struct f71882fg_sio_data
*sio_data
= pdev
->dev
.platform_data
;
1937 int err
, i
, nr_fans
= (sio_data
->type
== f71882fg
) ? 4 : 3;
1941 data
= kzalloc(sizeof(struct f71882fg_data
), GFP_KERNEL
);
1945 data
->addr
= platform_get_resource(pdev
, IORESOURCE_IO
, 0)->start
;
1946 data
->type
= sio_data
->type
;
1948 (data
->type
== f71858fg
|| data
->type
== f8000
) ? 0 : 1;
1949 mutex_init(&data
->update_lock
);
1950 platform_set_drvdata(pdev
, data
);
1952 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
1953 if (start_reg
& 0x04) {
1954 dev_warn(&pdev
->dev
, "Hardware monitor is powered down\n");
1958 if (!(start_reg
& 0x03)) {
1959 dev_warn(&pdev
->dev
, "Hardware monitoring not activated\n");
1964 /* Register sysfs interface files */
1965 err
= device_create_file(&pdev
->dev
, &dev_attr_name
);
1967 goto exit_unregister_sysfs
;
1969 if (start_reg
& 0x01) {
1970 switch (data
->type
) {
1973 f71882fg_read8(data
, F71882FG_REG_TEMP_CONFIG
);
1974 if (data
->temp_config
& 0x10)
1975 /* The f71858fg temperature alarms behave as
1976 the f8000 alarms in this mode */
1977 err
= f71882fg_create_sysfs_files(pdev
,
1979 ARRAY_SIZE(f8000_temp_attr
));
1981 err
= f71882fg_create_sysfs_files(pdev
,
1983 ARRAY_SIZE(f71858fg_temp_attr
));
1986 err
= f71882fg_create_sysfs_files(pdev
,
1988 ARRAY_SIZE(f8000_temp_attr
));
1991 err
= f71882fg_create_sysfs_files(pdev
,
1992 &fxxxx_temp_attr
[0][0],
1993 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
1996 goto exit_unregister_sysfs
;
1998 if (f71882fg_has_beep
[data
->type
]) {
1999 err
= f71882fg_create_sysfs_files(pdev
,
2000 &fxxxx_temp_beep_attr
[0][0],
2001 ARRAY_SIZE(fxxxx_temp_beep_attr
[0])
2004 goto exit_unregister_sysfs
;
2007 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2008 if (f71882fg_has_in
[data
->type
][i
]) {
2009 err
= device_create_file(&pdev
->dev
,
2010 &fxxxx_in_attr
[i
].dev_attr
);
2012 goto exit_unregister_sysfs
;
2015 if (f71882fg_has_in1_alarm
[data
->type
]) {
2016 err
= f71882fg_create_sysfs_files(pdev
,
2017 fxxxx_in1_alarm_attr
,
2018 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2020 goto exit_unregister_sysfs
;
2024 if (start_reg
& 0x02) {
2025 switch (data
->type
) {
2027 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_FAULT_T
);
2028 if (reg
& F71882FG_FAN_NEG_TEMP_EN
)
2029 data
->auto_point_temp_signed
= 1;
2036 f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
2038 /* Sanity check the pwm settings */
2039 switch (data
->type
) {
2042 for (i
= 0; i
< nr_fans
; i
++)
2043 if (((data
->pwm_enable
>> (i
* 2)) & 3) == 3)
2047 err
= (data
->pwm_enable
& 0x15) != 0x15;
2054 err
= data
->pwm_enable
& 0x20;
2059 "Invalid (reserved) pwm settings: 0x%02x\n",
2060 (unsigned int)data
->pwm_enable
);
2062 goto exit_unregister_sysfs
;
2065 err
= f71882fg_create_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2066 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2068 goto exit_unregister_sysfs
;
2070 if (f71882fg_has_beep
[data
->type
]) {
2071 err
= f71882fg_create_sysfs_files(pdev
,
2072 fxxxx_fan_beep_attr
, nr_fans
);
2074 goto exit_unregister_sysfs
;
2077 switch (data
->type
) {
2079 err
= f71882fg_create_sysfs_files(pdev
,
2080 f71862fg_auto_pwm_attr
,
2081 ARRAY_SIZE(f71862fg_auto_pwm_attr
));
2084 err
= f71882fg_create_sysfs_files(pdev
,
2086 ARRAY_SIZE(f8000_fan_attr
));
2088 goto exit_unregister_sysfs
;
2089 err
= f71882fg_create_sysfs_files(pdev
,
2090 f8000_auto_pwm_attr
,
2091 ARRAY_SIZE(f8000_auto_pwm_attr
));
2094 for (i
= 0; i
< nr_fans
; i
++) {
2095 data
->pwm_auto_point_mapping
[i
] =
2096 f71882fg_read8(data
,
2097 F71882FG_REG_POINT_MAPPING(i
));
2098 if (data
->pwm_auto_point_mapping
[i
] & 0x80)
2102 dev_warn(&pdev
->dev
,
2103 "Auto pwm controlled by raw digital "
2104 "data, disabling pwm auto_point "
2105 "sysfs attributes\n");
2109 default: /* f71858fg / f71882fg */
2110 err
= f71882fg_create_sysfs_files(pdev
,
2111 &fxxxx_auto_pwm_attr
[0][0],
2112 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2115 goto exit_unregister_sysfs
;
2117 for (i
= 0; i
< nr_fans
; i
++)
2118 dev_info(&pdev
->dev
, "Fan: %d is in %s mode\n", i
+ 1,
2119 (data
->pwm_enable
& (1 << 2 * i
)) ?
2120 "duty-cycle" : "RPM");
2123 data
->hwmon_dev
= hwmon_device_register(&pdev
->dev
);
2124 if (IS_ERR(data
->hwmon_dev
)) {
2125 err
= PTR_ERR(data
->hwmon_dev
);
2126 data
->hwmon_dev
= NULL
;
2127 goto exit_unregister_sysfs
;
2132 exit_unregister_sysfs
:
2133 f71882fg_remove(pdev
); /* Will unregister the sysfs files for us */
2134 return err
; /* f71882fg_remove() also frees our data */
2140 static int f71882fg_remove(struct platform_device
*pdev
)
2142 struct f71882fg_data
*data
= platform_get_drvdata(pdev
);
2143 int i
, nr_fans
= (data
->type
== f71882fg
) ? 4 : 3;
2145 u8 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2147 if (data
->hwmon_dev
)
2148 hwmon_device_unregister(data
->hwmon_dev
);
2150 device_remove_file(&pdev
->dev
, &dev_attr_name
);
2152 if (start_reg
& 0x01) {
2153 switch (data
->type
) {
2155 if (data
->temp_config
& 0x10)
2156 f71882fg_remove_sysfs_files(pdev
,
2158 ARRAY_SIZE(f8000_temp_attr
));
2160 f71882fg_remove_sysfs_files(pdev
,
2162 ARRAY_SIZE(f71858fg_temp_attr
));
2165 f71882fg_remove_sysfs_files(pdev
,
2167 ARRAY_SIZE(f8000_temp_attr
));
2170 f71882fg_remove_sysfs_files(pdev
,
2171 &fxxxx_temp_attr
[0][0],
2172 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2174 if (f71882fg_has_beep
[data
->type
]) {
2175 f71882fg_remove_sysfs_files(pdev
,
2176 &fxxxx_temp_beep_attr
[0][0],
2177 ARRAY_SIZE(fxxxx_temp_beep_attr
[0]) * nr_temps
);
2180 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2181 if (f71882fg_has_in
[data
->type
][i
]) {
2182 device_remove_file(&pdev
->dev
,
2183 &fxxxx_in_attr
[i
].dev_attr
);
2186 if (f71882fg_has_in1_alarm
[data
->type
]) {
2187 f71882fg_remove_sysfs_files(pdev
,
2188 fxxxx_in1_alarm_attr
,
2189 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2193 if (start_reg
& 0x02) {
2194 f71882fg_remove_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2195 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2197 if (f71882fg_has_beep
[data
->type
]) {
2198 f71882fg_remove_sysfs_files(pdev
,
2199 fxxxx_fan_beep_attr
, nr_fans
);
2202 switch (data
->type
) {
2204 f71882fg_remove_sysfs_files(pdev
,
2205 f71862fg_auto_pwm_attr
,
2206 ARRAY_SIZE(f71862fg_auto_pwm_attr
));
2209 f71882fg_remove_sysfs_files(pdev
,
2211 ARRAY_SIZE(f8000_fan_attr
));
2212 f71882fg_remove_sysfs_files(pdev
,
2213 f8000_auto_pwm_attr
,
2214 ARRAY_SIZE(f8000_auto_pwm_attr
));
2216 default: /* f71858fg / f71882fg / f71889fg */
2217 f71882fg_remove_sysfs_files(pdev
,
2218 &fxxxx_auto_pwm_attr
[0][0],
2219 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2223 platform_set_drvdata(pdev
, NULL
);
2229 static int __init
f71882fg_find(int sioaddr
, unsigned short *address
,
2230 struct f71882fg_sio_data
*sio_data
)
2233 int err
= superio_enter(sioaddr
);
2237 devid
= superio_inw(sioaddr
, SIO_REG_MANID
);
2238 if (devid
!= SIO_FINTEK_ID
) {
2239 pr_debug("Not a Fintek device\n");
2244 devid
= force_id
? force_id
: superio_inw(sioaddr
, SIO_REG_DEVID
);
2247 sio_data
->type
= f71858fg
;
2250 sio_data
->type
= f71862fg
;
2253 sio_data
->type
= f71882fg
;
2256 sio_data
->type
= f71889fg
;
2259 sio_data
->type
= f8000
;
2262 pr_info("Unsupported Fintek device: %04x\n",
2263 (unsigned int)devid
);
2268 if (sio_data
->type
== f71858fg
)
2269 superio_select(sioaddr
, SIO_F71858FG_LD_HWM
);
2271 superio_select(sioaddr
, SIO_F71882FG_LD_HWM
);
2273 if (!(superio_inb(sioaddr
, SIO_REG_ENABLE
) & 0x01)) {
2274 pr_warn("Device not activated\n");
2279 *address
= superio_inw(sioaddr
, SIO_REG_ADDR
);
2280 if (*address
== 0) {
2281 pr_warn("Base address not set\n");
2285 *address
&= ~(REGION_LENGTH
- 1); /* Ignore 3 LSB */
2288 pr_info("Found %s chip at %#x, revision %d\n",
2289 f71882fg_names
[sio_data
->type
], (unsigned int)*address
,
2290 (int)superio_inb(sioaddr
, SIO_REG_DEVREV
));
2292 superio_exit(sioaddr
);
2296 static int __init
f71882fg_device_add(unsigned short address
,
2297 const struct f71882fg_sio_data
*sio_data
)
2299 struct resource res
= {
2301 .end
= address
+ REGION_LENGTH
- 1,
2302 .flags
= IORESOURCE_IO
,
2306 f71882fg_pdev
= platform_device_alloc(DRVNAME
, address
);
2310 res
.name
= f71882fg_pdev
->name
;
2311 err
= acpi_check_resource_conflict(&res
);
2313 goto exit_device_put
;
2315 err
= platform_device_add_resources(f71882fg_pdev
, &res
, 1);
2317 pr_err("Device resource addition failed\n");
2318 goto exit_device_put
;
2321 err
= platform_device_add_data(f71882fg_pdev
, sio_data
,
2322 sizeof(struct f71882fg_sio_data
));
2324 pr_err("Platform data allocation failed\n");
2325 goto exit_device_put
;
2328 err
= platform_device_add(f71882fg_pdev
);
2330 pr_err("Device addition failed\n");
2331 goto exit_device_put
;
2337 platform_device_put(f71882fg_pdev
);
2342 static int __init
f71882fg_init(void)
2345 unsigned short address
;
2346 struct f71882fg_sio_data sio_data
;
2348 memset(&sio_data
, 0, sizeof(sio_data
));
2350 if (f71882fg_find(0x2e, &address
, &sio_data
) &&
2351 f71882fg_find(0x4e, &address
, &sio_data
))
2354 err
= platform_driver_register(&f71882fg_driver
);
2358 err
= f71882fg_device_add(address
, &sio_data
);
2365 platform_driver_unregister(&f71882fg_driver
);
2370 static void __exit
f71882fg_exit(void)
2372 platform_device_unregister(f71882fg_pdev
);
2373 platform_driver_unregister(&f71882fg_driver
);
2376 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2377 MODULE_AUTHOR("Hans Edgington, Hans de Goede (hdegoede@redhat.com)");
2378 MODULE_LICENSE("GPL");
2380 module_init(f71882fg_init
);
2381 module_exit(f71882fg_exit
);