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_F71808E_ID 0x0901 /* Chipset ID */
51 #define SIO_F71808A_ID 0x1001 /* Chipset ID */
52 #define SIO_F71858_ID 0x0507 /* Chipset ID */
53 #define SIO_F71862_ID 0x0601 /* Chipset ID */
54 #define SIO_F71869_ID 0x0814 /* Chipset ID */
55 #define SIO_F71882_ID 0x0541 /* Chipset ID */
56 #define SIO_F71889_ID 0x0723 /* Chipset ID */
57 #define SIO_F71889E_ID 0x0909 /* Chipset ID */
58 #define SIO_F71889A_ID 0x1005 /* Chipset ID */
59 #define SIO_F8000_ID 0x0581 /* Chipset ID */
60 #define SIO_F81865_ID 0x0704 /* Chipset ID */
62 #define REGION_LENGTH 8
63 #define ADDR_REG_OFFSET 5
64 #define DATA_REG_OFFSET 6
66 #define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */
67 #define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */
68 #define F71882FG_REG_IN(nr) (0x20 + (nr))
69 #define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */
71 #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
72 #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
73 #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
74 #define F71882FG_REG_FAN_STATUS 0x92
75 #define F71882FG_REG_FAN_BEEP 0x93
77 #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
78 #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
79 #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
80 #define F71882FG_REG_TEMP_STATUS 0x62
81 #define F71882FG_REG_TEMP_BEEP 0x63
82 #define F71882FG_REG_TEMP_CONFIG 0x69
83 #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
84 #define F71882FG_REG_TEMP_TYPE 0x6B
85 #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
87 #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
88 #define F71882FG_REG_PWM_TYPE 0x94
89 #define F71882FG_REG_PWM_ENABLE 0x96
91 #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
93 #define F71882FG_REG_FAN_FAULT_T 0x9F
94 #define F71882FG_FAN_NEG_TEMP_EN 0x20
95 #define F71882FG_FAN_PROG_SEL 0x80
97 #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
98 #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
99 #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
101 #define F71882FG_REG_START 0x01
103 #define F71882FG_MAX_INS 9
105 #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
107 static unsigned short force_id
;
108 module_param(force_id
, ushort
, 0);
109 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
111 enum chips
{ f71808e
, f71808a
, f71858fg
, f71862fg
, f71869
, f71882fg
, f71889fg
,
112 f71889ed
, f71889a
, f8000
, f81865f
};
114 static const char *f71882fg_names
[] = {
119 "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
121 "f71889fg", /* f81801u too, same id */
128 static const char f71882fg_has_in
[][F71882FG_MAX_INS
] = {
129 [f71808e
] = { 1, 1, 1, 1, 1, 1, 0, 1, 1 },
130 [f71808a
] = { 1, 1, 1, 1, 0, 0, 0, 1, 1 },
131 [f71858fg
] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
132 [f71862fg
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
133 [f71869
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
134 [f71882fg
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
135 [f71889fg
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
136 [f71889ed
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
137 [f71889a
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
138 [f8000
] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
139 [f81865f
] = { 1, 1, 1, 1, 1, 1, 1, 0, 0 },
142 static const char f71882fg_has_in1_alarm
[] = {
156 static const char f71882fg_fan_has_beep
[] = {
170 static const char f71882fg_nr_fans
[] = {
172 [f71808a
] = 2, /* +1 fan which is monitor + simple pwm only */
180 [f8000
] = 3, /* +1 fan which is monitor only */
184 static const char f71882fg_temp_has_beep
[] = {
198 static const char f71882fg_nr_temps
[] = {
212 static struct platform_device
*f71882fg_pdev
;
214 /* Super-I/O Function prototypes */
215 static inline int superio_inb(int base
, int reg
);
216 static inline int superio_inw(int base
, int reg
);
217 static inline int superio_enter(int base
);
218 static inline void superio_select(int base
, int ld
);
219 static inline void superio_exit(int base
);
221 struct f71882fg_sio_data
{
225 struct f71882fg_data
{
228 struct device
*hwmon_dev
;
230 struct mutex update_lock
;
231 int temp_start
; /* temp numbering start (0 or 1) */
232 char valid
; /* !=0 if following fields are valid */
233 char auto_point_temp_signed
;
234 unsigned long last_updated
; /* In jiffies */
235 unsigned long last_limits
; /* In jiffies */
237 /* Register Values */
238 u8 in
[F71882FG_MAX_INS
];
244 u16 fan_full_speed
[4];
247 /* Note: all models have max 3 temperature channels, but on some
248 they are addressed as 0-2 and on others as 1-3, so for coding
249 convenience we reserve space for 4 channels */
253 u8 temp_hyst
[2]; /* 2 hysts stored per reg */
261 u8 pwm_auto_point_hyst
[2];
262 u8 pwm_auto_point_mapping
[4];
263 u8 pwm_auto_point_pwm
[4][5];
264 s8 pwm_auto_point_temp
[4][4];
268 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
270 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
271 *devattr
, char *buf
);
272 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
273 *devattr
, const char *buf
, size_t count
);
274 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
275 *devattr
, char *buf
);
276 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
277 *devattr
, const char *buf
, size_t count
);
278 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
279 *devattr
, char *buf
);
281 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
283 static ssize_t
show_fan_full_speed(struct device
*dev
,
284 struct device_attribute
*devattr
, char *buf
);
285 static ssize_t
store_fan_full_speed(struct device
*dev
,
286 struct device_attribute
*devattr
, const char *buf
, size_t count
);
287 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
288 *devattr
, char *buf
);
289 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
290 *devattr
, const char *buf
, size_t count
);
291 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
292 *devattr
, char *buf
);
294 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
295 *devattr
, char *buf
);
296 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
297 *devattr
, char *buf
);
298 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
299 *devattr
, const char *buf
, size_t count
);
300 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
301 *devattr
, char *buf
);
302 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
303 *devattr
, const char *buf
, size_t count
);
304 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
305 *devattr
, char *buf
);
306 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
307 *devattr
, const char *buf
, size_t count
);
308 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
309 *devattr
, char *buf
);
310 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
311 *devattr
, char *buf
);
312 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
313 *devattr
, char *buf
);
314 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
315 *devattr
, const char *buf
, size_t count
);
316 static ssize_t
show_temp_alarm(struct device
*dev
, struct device_attribute
317 *devattr
, char *buf
);
318 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
319 *devattr
, char *buf
);
320 /* PWM and Auto point control */
321 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*devattr
,
323 static ssize_t
store_pwm(struct device
*dev
, struct device_attribute
*devattr
,
324 const char *buf
, size_t count
);
325 static ssize_t
show_simple_pwm(struct device
*dev
,
326 struct device_attribute
*devattr
, char *buf
);
327 static ssize_t
store_simple_pwm(struct device
*dev
,
328 struct device_attribute
*devattr
, const char *buf
, size_t count
);
329 static ssize_t
show_pwm_enable(struct device
*dev
,
330 struct device_attribute
*devattr
, char *buf
);
331 static ssize_t
store_pwm_enable(struct device
*dev
,
332 struct device_attribute
*devattr
, const char *buf
, size_t count
);
333 static ssize_t
show_pwm_interpolate(struct device
*dev
,
334 struct device_attribute
*devattr
, char *buf
);
335 static ssize_t
store_pwm_interpolate(struct device
*dev
,
336 struct device_attribute
*devattr
, const char *buf
, size_t count
);
337 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
338 struct device_attribute
*devattr
, char *buf
);
339 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
340 struct device_attribute
*devattr
, const char *buf
, size_t count
);
341 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
342 struct device_attribute
*devattr
, char *buf
);
343 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
344 struct device_attribute
*devattr
, const char *buf
, size_t count
);
345 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
346 struct device_attribute
*devattr
, char *buf
);
347 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
348 struct device_attribute
*devattr
, const char *buf
, size_t count
);
349 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
350 struct device_attribute
*devattr
, char *buf
);
351 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
352 struct device_attribute
*devattr
, const char *buf
, size_t count
);
354 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
357 static int __devinit
f71882fg_probe(struct platform_device
* pdev
);
358 static int f71882fg_remove(struct platform_device
*pdev
);
360 static struct platform_driver f71882fg_driver
= {
362 .owner
= THIS_MODULE
,
365 .probe
= f71882fg_probe
,
366 .remove
= f71882fg_remove
,
369 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
371 /* Temp attr for the f71858fg, the f71858fg is special as it has its
372 temperature indexes start at 0 (the others start at 1) */
373 static struct sensor_device_attribute_2 f71858fg_temp_attr
[] = {
374 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
375 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
376 store_temp_max
, 0, 0),
377 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
378 store_temp_max_hyst
, 0, 0),
379 SENSOR_ATTR_2(temp1_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 0),
380 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
381 store_temp_crit
, 0, 0),
382 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
384 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
385 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
386 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
387 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
388 store_temp_max
, 0, 1),
389 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
390 store_temp_max_hyst
, 0, 1),
391 SENSOR_ATTR_2(temp2_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
392 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
393 store_temp_crit
, 0, 1),
394 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
396 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
397 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
398 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
399 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
400 store_temp_max
, 0, 2),
401 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
402 store_temp_max_hyst
, 0, 2),
403 SENSOR_ATTR_2(temp3_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
404 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
405 store_temp_crit
, 0, 2),
406 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
408 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
409 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
412 /* Temp attr for the standard models */
413 static struct sensor_device_attribute_2 fxxxx_temp_attr
[3][9] = { {
414 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
415 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
416 store_temp_max
, 0, 1),
417 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
418 store_temp_max_hyst
, 0, 1),
419 /* Should really be temp1_max_alarm, but older versions did not handle
420 the max and crit alarms separately and lm_sensors v2 depends on the
421 presence of temp#_alarm files. The same goes for temp2/3 _alarm. */
422 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
423 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
424 store_temp_crit
, 0, 1),
425 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
427 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
428 SENSOR_ATTR_2(temp1_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 1),
429 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
431 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
432 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
433 store_temp_max
, 0, 2),
434 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
435 store_temp_max_hyst
, 0, 2),
436 /* Should be temp2_max_alarm, see temp1_alarm note */
437 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
438 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
439 store_temp_crit
, 0, 2),
440 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
442 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
443 SENSOR_ATTR_2(temp2_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 2),
444 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
446 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 3),
447 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
448 store_temp_max
, 0, 3),
449 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
450 store_temp_max_hyst
, 0, 3),
451 /* Should be temp3_max_alarm, see temp1_alarm note */
452 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 3),
453 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
454 store_temp_crit
, 0, 3),
455 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
457 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 7),
458 SENSOR_ATTR_2(temp3_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 3),
459 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 3),
462 /* Temp attr for models which can beep on temp alarm */
463 static struct sensor_device_attribute_2 fxxxx_temp_beep_attr
[3][2] = { {
464 SENSOR_ATTR_2(temp1_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
465 store_temp_beep
, 0, 1),
466 SENSOR_ATTR_2(temp1_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
467 store_temp_beep
, 0, 5),
469 SENSOR_ATTR_2(temp2_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
470 store_temp_beep
, 0, 2),
471 SENSOR_ATTR_2(temp2_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
472 store_temp_beep
, 0, 6),
474 SENSOR_ATTR_2(temp3_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
475 store_temp_beep
, 0, 3),
476 SENSOR_ATTR_2(temp3_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
477 store_temp_beep
, 0, 7),
480 /* Temp attr for the f8000
481 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
482 is used as hysteresis value to clear alarms
483 Also like the f71858fg its temperature indexes start at 0
485 static struct sensor_device_attribute_2 f8000_temp_attr
[] = {
486 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
487 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
488 store_temp_crit
, 0, 0),
489 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
490 store_temp_max
, 0, 0),
491 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
492 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
493 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
494 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
495 store_temp_crit
, 0, 1),
496 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
497 store_temp_max
, 0, 1),
498 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
499 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
500 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
501 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
502 store_temp_crit
, 0, 2),
503 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
504 store_temp_max
, 0, 2),
505 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
506 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
509 /* in attr for all models */
510 static struct sensor_device_attribute_2 fxxxx_in_attr
[] = {
511 SENSOR_ATTR_2(in0_input
, S_IRUGO
, show_in
, NULL
, 0, 0),
512 SENSOR_ATTR_2(in1_input
, S_IRUGO
, show_in
, NULL
, 0, 1),
513 SENSOR_ATTR_2(in2_input
, S_IRUGO
, show_in
, NULL
, 0, 2),
514 SENSOR_ATTR_2(in3_input
, S_IRUGO
, show_in
, NULL
, 0, 3),
515 SENSOR_ATTR_2(in4_input
, S_IRUGO
, show_in
, NULL
, 0, 4),
516 SENSOR_ATTR_2(in5_input
, S_IRUGO
, show_in
, NULL
, 0, 5),
517 SENSOR_ATTR_2(in6_input
, S_IRUGO
, show_in
, NULL
, 0, 6),
518 SENSOR_ATTR_2(in7_input
, S_IRUGO
, show_in
, NULL
, 0, 7),
519 SENSOR_ATTR_2(in8_input
, S_IRUGO
, show_in
, NULL
, 0, 8),
522 /* For models with in1 alarm capability */
523 static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr
[] = {
524 SENSOR_ATTR_2(in1_max
, S_IRUGO
|S_IWUSR
, show_in_max
, store_in_max
,
526 SENSOR_ATTR_2(in1_beep
, S_IRUGO
|S_IWUSR
, show_in_beep
, store_in_beep
,
528 SENSOR_ATTR_2(in1_alarm
, S_IRUGO
, show_in_alarm
, NULL
, 0, 1),
531 /* Fan / PWM attr common to all models */
532 static struct sensor_device_attribute_2 fxxxx_fan_attr
[4][6] = { {
533 SENSOR_ATTR_2(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0, 0),
534 SENSOR_ATTR_2(fan1_full_speed
, S_IRUGO
|S_IWUSR
,
536 store_fan_full_speed
, 0, 0),
537 SENSOR_ATTR_2(fan1_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 0),
538 SENSOR_ATTR_2(pwm1
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 0),
539 SENSOR_ATTR_2(pwm1_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
540 store_pwm_enable
, 0, 0),
541 SENSOR_ATTR_2(pwm1_interpolate
, S_IRUGO
|S_IWUSR
,
542 show_pwm_interpolate
, store_pwm_interpolate
, 0, 0),
544 SENSOR_ATTR_2(fan2_input
, S_IRUGO
, show_fan
, NULL
, 0, 1),
545 SENSOR_ATTR_2(fan2_full_speed
, S_IRUGO
|S_IWUSR
,
547 store_fan_full_speed
, 0, 1),
548 SENSOR_ATTR_2(fan2_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 1),
549 SENSOR_ATTR_2(pwm2
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 1),
550 SENSOR_ATTR_2(pwm2_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
551 store_pwm_enable
, 0, 1),
552 SENSOR_ATTR_2(pwm2_interpolate
, S_IRUGO
|S_IWUSR
,
553 show_pwm_interpolate
, store_pwm_interpolate
, 0, 1),
555 SENSOR_ATTR_2(fan3_input
, S_IRUGO
, show_fan
, NULL
, 0, 2),
556 SENSOR_ATTR_2(fan3_full_speed
, S_IRUGO
|S_IWUSR
,
558 store_fan_full_speed
, 0, 2),
559 SENSOR_ATTR_2(fan3_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 2),
560 SENSOR_ATTR_2(pwm3
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 2),
561 SENSOR_ATTR_2(pwm3_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
562 store_pwm_enable
, 0, 2),
563 SENSOR_ATTR_2(pwm3_interpolate
, S_IRUGO
|S_IWUSR
,
564 show_pwm_interpolate
, store_pwm_interpolate
, 0, 2),
566 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
567 SENSOR_ATTR_2(fan4_full_speed
, S_IRUGO
|S_IWUSR
,
569 store_fan_full_speed
, 0, 3),
570 SENSOR_ATTR_2(fan4_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 3),
571 SENSOR_ATTR_2(pwm4
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 3),
572 SENSOR_ATTR_2(pwm4_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
573 store_pwm_enable
, 0, 3),
574 SENSOR_ATTR_2(pwm4_interpolate
, S_IRUGO
|S_IWUSR
,
575 show_pwm_interpolate
, store_pwm_interpolate
, 0, 3),
578 /* Attr for the third fan of the f71808a, which only has manual pwm */
579 static struct sensor_device_attribute_2 f71808a_fan3_attr
[] = {
580 SENSOR_ATTR_2(fan3_input
, S_IRUGO
, show_fan
, NULL
, 0, 2),
581 SENSOR_ATTR_2(fan3_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 2),
582 SENSOR_ATTR_2(pwm3
, S_IRUGO
|S_IWUSR
,
583 show_simple_pwm
, store_simple_pwm
, 0, 2),
586 /* Attr for models which can beep on Fan alarm */
587 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr
[] = {
588 SENSOR_ATTR_2(fan1_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
589 store_fan_beep
, 0, 0),
590 SENSOR_ATTR_2(fan2_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
591 store_fan_beep
, 0, 1),
592 SENSOR_ATTR_2(fan3_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
593 store_fan_beep
, 0, 2),
594 SENSOR_ATTR_2(fan4_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
595 store_fan_beep
, 0, 3),
598 /* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
600 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr
[] = {
601 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
602 show_pwm_auto_point_channel
,
603 store_pwm_auto_point_channel
, 0, 0),
604 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
605 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
607 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
608 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
610 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
611 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
613 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
614 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
616 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
617 show_pwm_auto_point_temp_hyst
,
618 store_pwm_auto_point_temp_hyst
,
620 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
621 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
623 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
624 show_pwm_auto_point_channel
,
625 store_pwm_auto_point_channel
, 0, 1),
626 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
627 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
629 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
630 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
632 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
633 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
635 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
636 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
638 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
639 show_pwm_auto_point_temp_hyst
,
640 store_pwm_auto_point_temp_hyst
,
642 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
643 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
645 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
646 show_pwm_auto_point_channel
,
647 store_pwm_auto_point_channel
, 0, 2),
648 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
649 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
651 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
652 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
654 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
655 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
657 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
658 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
660 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
661 show_pwm_auto_point_temp_hyst
,
662 store_pwm_auto_point_temp_hyst
,
664 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
665 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
668 /* PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
669 pwm setting when the temperature is above the pwmX_auto_point1_temp can be
670 programmed instead of being hardcoded to 0xff */
671 static struct sensor_device_attribute_2 f71869_auto_pwm_attr
[] = {
672 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
673 show_pwm_auto_point_channel
,
674 store_pwm_auto_point_channel
, 0, 0),
675 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
676 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
678 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
679 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
681 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
682 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
684 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
685 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
687 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
688 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
690 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
691 show_pwm_auto_point_temp_hyst
,
692 store_pwm_auto_point_temp_hyst
,
694 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
695 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
697 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
698 show_pwm_auto_point_channel
,
699 store_pwm_auto_point_channel
, 0, 1),
700 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
701 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
703 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
704 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
706 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
707 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
709 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
710 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
712 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
713 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
715 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
716 show_pwm_auto_point_temp_hyst
,
717 store_pwm_auto_point_temp_hyst
,
719 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
720 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
722 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
723 show_pwm_auto_point_channel
,
724 store_pwm_auto_point_channel
, 0, 2),
725 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
726 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
728 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
729 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
731 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
732 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
734 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
735 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
737 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
738 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
740 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
741 show_pwm_auto_point_temp_hyst
,
742 store_pwm_auto_point_temp_hyst
,
744 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
745 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
748 /* PWM attr for the standard models */
749 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr
[4][14] = { {
750 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
751 show_pwm_auto_point_channel
,
752 store_pwm_auto_point_channel
, 0, 0),
753 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
754 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
756 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
757 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
759 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
760 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
762 SENSOR_ATTR_2(pwm1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
763 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
765 SENSOR_ATTR_2(pwm1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
766 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
768 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
769 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
771 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
772 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
774 SENSOR_ATTR_2(pwm1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
775 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
777 SENSOR_ATTR_2(pwm1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
778 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
780 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
781 show_pwm_auto_point_temp_hyst
,
782 store_pwm_auto_point_temp_hyst
,
784 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
785 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
786 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst
, S_IRUGO
,
787 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
788 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst
, S_IRUGO
,
789 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
791 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
792 show_pwm_auto_point_channel
,
793 store_pwm_auto_point_channel
, 0, 1),
794 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
795 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
797 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
798 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
800 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
801 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
803 SENSOR_ATTR_2(pwm2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
804 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
806 SENSOR_ATTR_2(pwm2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
807 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
809 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
810 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
812 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
813 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
815 SENSOR_ATTR_2(pwm2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
816 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
818 SENSOR_ATTR_2(pwm2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
819 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
821 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
822 show_pwm_auto_point_temp_hyst
,
823 store_pwm_auto_point_temp_hyst
,
825 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
826 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
827 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst
, S_IRUGO
,
828 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
829 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst
, S_IRUGO
,
830 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
832 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
833 show_pwm_auto_point_channel
,
834 store_pwm_auto_point_channel
, 0, 2),
835 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
836 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
838 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
839 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
841 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
842 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
844 SENSOR_ATTR_2(pwm3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
845 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
847 SENSOR_ATTR_2(pwm3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
848 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
850 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
851 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
853 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
854 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
856 SENSOR_ATTR_2(pwm3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
857 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
859 SENSOR_ATTR_2(pwm3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
860 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
862 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
863 show_pwm_auto_point_temp_hyst
,
864 store_pwm_auto_point_temp_hyst
,
866 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
867 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
868 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst
, S_IRUGO
,
869 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
870 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst
, S_IRUGO
,
871 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
873 SENSOR_ATTR_2(pwm4_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
874 show_pwm_auto_point_channel
,
875 store_pwm_auto_point_channel
, 0, 3),
876 SENSOR_ATTR_2(pwm4_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
877 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
879 SENSOR_ATTR_2(pwm4_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
880 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
882 SENSOR_ATTR_2(pwm4_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
883 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
885 SENSOR_ATTR_2(pwm4_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
886 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
888 SENSOR_ATTR_2(pwm4_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
889 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
891 SENSOR_ATTR_2(pwm4_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
892 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
894 SENSOR_ATTR_2(pwm4_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
895 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
897 SENSOR_ATTR_2(pwm4_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
898 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
900 SENSOR_ATTR_2(pwm4_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
901 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
903 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
904 show_pwm_auto_point_temp_hyst
,
905 store_pwm_auto_point_temp_hyst
,
907 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst
, S_IRUGO
,
908 show_pwm_auto_point_temp_hyst
, NULL
, 1, 3),
909 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst
, S_IRUGO
,
910 show_pwm_auto_point_temp_hyst
, NULL
, 2, 3),
911 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst
, S_IRUGO
,
912 show_pwm_auto_point_temp_hyst
, NULL
, 3, 3),
915 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
916 static struct sensor_device_attribute_2 f8000_fan_attr
[] = {
917 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
920 /* PWM attr for the f8000, zones mapped to temp instead of to pwm!
921 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
922 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
923 static struct sensor_device_attribute_2 f8000_auto_pwm_attr
[] = {
924 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
925 show_pwm_auto_point_channel
,
926 store_pwm_auto_point_channel
, 0, 0),
927 SENSOR_ATTR_2(temp1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
928 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
930 SENSOR_ATTR_2(temp1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
931 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
933 SENSOR_ATTR_2(temp1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
934 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
936 SENSOR_ATTR_2(temp1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
937 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
939 SENSOR_ATTR_2(temp1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
940 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
942 SENSOR_ATTR_2(temp1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
943 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
945 SENSOR_ATTR_2(temp1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
946 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
948 SENSOR_ATTR_2(temp1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
949 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
951 SENSOR_ATTR_2(temp1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
952 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
954 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
955 show_pwm_auto_point_temp_hyst
,
956 store_pwm_auto_point_temp_hyst
,
958 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst
, S_IRUGO
,
959 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
960 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst
, S_IRUGO
,
961 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
962 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst
, S_IRUGO
,
963 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
965 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
966 show_pwm_auto_point_channel
,
967 store_pwm_auto_point_channel
, 0, 1),
968 SENSOR_ATTR_2(temp2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
969 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
971 SENSOR_ATTR_2(temp2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
972 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
974 SENSOR_ATTR_2(temp2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
975 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
977 SENSOR_ATTR_2(temp2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
978 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
980 SENSOR_ATTR_2(temp2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
981 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
983 SENSOR_ATTR_2(temp2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
984 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
986 SENSOR_ATTR_2(temp2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
987 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
989 SENSOR_ATTR_2(temp2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
990 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
992 SENSOR_ATTR_2(temp2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
993 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
995 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
996 show_pwm_auto_point_temp_hyst
,
997 store_pwm_auto_point_temp_hyst
,
999 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst
, S_IRUGO
,
1000 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
1001 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst
, S_IRUGO
,
1002 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
1003 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst
, S_IRUGO
,
1004 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
1006 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
1007 show_pwm_auto_point_channel
,
1008 store_pwm_auto_point_channel
, 0, 2),
1009 SENSOR_ATTR_2(temp3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
1010 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1012 SENSOR_ATTR_2(temp3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
1013 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1015 SENSOR_ATTR_2(temp3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
1016 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1018 SENSOR_ATTR_2(temp3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
1019 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1021 SENSOR_ATTR_2(temp3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
1022 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1024 SENSOR_ATTR_2(temp3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
1025 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1027 SENSOR_ATTR_2(temp3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
1028 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1030 SENSOR_ATTR_2(temp3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
1031 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1033 SENSOR_ATTR_2(temp3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
1034 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1036 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
1037 show_pwm_auto_point_temp_hyst
,
1038 store_pwm_auto_point_temp_hyst
,
1040 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst
, S_IRUGO
,
1041 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
1042 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst
, S_IRUGO
,
1043 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
1044 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst
, S_IRUGO
,
1045 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
1048 /* Super I/O functions */
1049 static inline int superio_inb(int base
, int reg
)
1052 return inb(base
+ 1);
1055 static int superio_inw(int base
, int reg
)
1058 val
= superio_inb(base
, reg
) << 8;
1059 val
|= superio_inb(base
, reg
+ 1);
1063 static inline int superio_enter(int base
)
1065 /* Don't step on other drivers' I/O space by accident */
1066 if (!request_muxed_region(base
, 2, DRVNAME
)) {
1067 pr_err("I/O address 0x%04x already in use\n", base
);
1071 /* according to the datasheet the key must be send twice! */
1072 outb(SIO_UNLOCK_KEY
, base
);
1073 outb(SIO_UNLOCK_KEY
, base
);
1078 static inline void superio_select(int base
, int ld
)
1080 outb(SIO_REG_LDSEL
, base
);
1084 static inline void superio_exit(int base
)
1086 outb(SIO_LOCK_KEY
, base
);
1087 release_region(base
, 2);
1090 static inline int fan_from_reg(u16 reg
)
1092 return reg
? (1500000 / reg
) : 0;
1095 static inline u16
fan_to_reg(int fan
)
1097 return fan
? (1500000 / fan
) : 0;
1100 static u8
f71882fg_read8(struct f71882fg_data
*data
, u8 reg
)
1104 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
1105 val
= inb(data
->addr
+ DATA_REG_OFFSET
);
1110 static u16
f71882fg_read16(struct f71882fg_data
*data
, u8 reg
)
1114 val
= f71882fg_read8(data
, reg
) << 8;
1115 val
|= f71882fg_read8(data
, reg
+ 1);
1120 static void f71882fg_write8(struct f71882fg_data
*data
, u8 reg
, u8 val
)
1122 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
1123 outb(val
, data
->addr
+ DATA_REG_OFFSET
);
1126 static void f71882fg_write16(struct f71882fg_data
*data
, u8 reg
, u16 val
)
1128 f71882fg_write8(data
, reg
, val
>> 8);
1129 f71882fg_write8(data
, reg
+ 1, val
& 0xff);
1132 static u16
f71882fg_read_temp(struct f71882fg_data
*data
, int nr
)
1134 if (data
->type
== f71858fg
)
1135 return f71882fg_read16(data
, F71882FG_REG_TEMP(nr
));
1137 return f71882fg_read8(data
, F71882FG_REG_TEMP(nr
));
1140 static struct f71882fg_data
*f71882fg_update_device(struct device
*dev
)
1142 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1143 int nr_fans
= f71882fg_nr_fans
[data
->type
];
1144 int nr_temps
= f71882fg_nr_temps
[data
->type
];
1147 mutex_lock(&data
->update_lock
);
1149 /* Update once every 60 seconds */
1150 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
) ||
1152 if (f71882fg_has_in1_alarm
[data
->type
]) {
1154 f71882fg_read8(data
, F71882FG_REG_IN1_HIGH
);
1156 f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1159 /* Get High & boundary temps*/
1160 for (nr
= data
->temp_start
; nr
< nr_temps
+ data
->temp_start
;
1162 data
->temp_ovt
[nr
] = f71882fg_read8(data
,
1163 F71882FG_REG_TEMP_OVT(nr
));
1164 data
->temp_high
[nr
] = f71882fg_read8(data
,
1165 F71882FG_REG_TEMP_HIGH(nr
));
1168 if (data
->type
!= f8000
) {
1169 data
->temp_hyst
[0] = f71882fg_read8(data
,
1170 F71882FG_REG_TEMP_HYST(0));
1171 data
->temp_hyst
[1] = f71882fg_read8(data
,
1172 F71882FG_REG_TEMP_HYST(1));
1174 /* All but the f71858fg / f8000 have this register */
1175 if ((data
->type
!= f71858fg
) && (data
->type
!= f8000
)) {
1176 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_TYPE
);
1177 data
->temp_type
[1] = (reg
& 0x02) ? 2 : 4;
1178 data
->temp_type
[2] = (reg
& 0x04) ? 2 : 4;
1179 data
->temp_type
[3] = (reg
& 0x08) ? 2 : 4;
1182 if (f71882fg_fan_has_beep
[data
->type
])
1183 data
->fan_beep
= f71882fg_read8(data
,
1184 F71882FG_REG_FAN_BEEP
);
1186 if (f71882fg_temp_has_beep
[data
->type
])
1187 data
->temp_beep
= f71882fg_read8(data
,
1188 F71882FG_REG_TEMP_BEEP
);
1190 data
->pwm_enable
= f71882fg_read8(data
,
1191 F71882FG_REG_PWM_ENABLE
);
1192 data
->pwm_auto_point_hyst
[0] =
1193 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(0));
1194 data
->pwm_auto_point_hyst
[1] =
1195 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(1));
1197 for (nr
= 0; nr
< nr_fans
; nr
++) {
1198 data
->pwm_auto_point_mapping
[nr
] =
1199 f71882fg_read8(data
,
1200 F71882FG_REG_POINT_MAPPING(nr
));
1202 switch (data
->type
) {
1204 for (point
= 0; point
< 5; point
++) {
1205 data
->pwm_auto_point_pwm
[nr
][point
] =
1206 f71882fg_read8(data
,
1207 F71882FG_REG_POINT_PWM
1210 for (point
= 0; point
< 4; point
++) {
1211 data
->pwm_auto_point_temp
[nr
][point
] =
1212 f71882fg_read8(data
,
1213 F71882FG_REG_POINT_TEMP
1219 data
->pwm_auto_point_pwm
[nr
][0] =
1220 f71882fg_read8(data
,
1221 F71882FG_REG_POINT_PWM(nr
, 0));
1224 data
->pwm_auto_point_pwm
[nr
][1] =
1225 f71882fg_read8(data
,
1226 F71882FG_REG_POINT_PWM
1228 data
->pwm_auto_point_pwm
[nr
][4] =
1229 f71882fg_read8(data
,
1230 F71882FG_REG_POINT_PWM
1232 data
->pwm_auto_point_temp
[nr
][0] =
1233 f71882fg_read8(data
,
1234 F71882FG_REG_POINT_TEMP
1236 data
->pwm_auto_point_temp
[nr
][3] =
1237 f71882fg_read8(data
,
1238 F71882FG_REG_POINT_TEMP
1243 data
->last_limits
= jiffies
;
1246 /* Update every second */
1247 if (time_after(jiffies
, data
->last_updated
+ HZ
) || !data
->valid
) {
1248 data
->temp_status
= f71882fg_read8(data
,
1249 F71882FG_REG_TEMP_STATUS
);
1250 data
->temp_diode_open
= f71882fg_read8(data
,
1251 F71882FG_REG_TEMP_DIODE_OPEN
);
1252 for (nr
= data
->temp_start
; nr
< nr_temps
+ data
->temp_start
;
1254 data
->temp
[nr
] = f71882fg_read_temp(data
, nr
);
1256 data
->fan_status
= f71882fg_read8(data
,
1257 F71882FG_REG_FAN_STATUS
);
1258 for (nr
= 0; nr
< nr_fans
; nr
++) {
1259 data
->fan
[nr
] = f71882fg_read16(data
,
1260 F71882FG_REG_FAN(nr
));
1261 data
->fan_target
[nr
] =
1262 f71882fg_read16(data
, F71882FG_REG_FAN_TARGET(nr
));
1263 data
->fan_full_speed
[nr
] =
1264 f71882fg_read16(data
,
1265 F71882FG_REG_FAN_FULL_SPEED(nr
));
1267 f71882fg_read8(data
, F71882FG_REG_PWM(nr
));
1269 /* Some models have 1 more fan with limited capabilities */
1270 if (data
->type
== f71808a
) {
1271 data
->fan
[2] = f71882fg_read16(data
,
1272 F71882FG_REG_FAN(2));
1273 data
->pwm
[2] = f71882fg_read8(data
,
1274 F71882FG_REG_PWM(2));
1276 if (data
->type
== f8000
)
1277 data
->fan
[3] = f71882fg_read16(data
,
1278 F71882FG_REG_FAN(3));
1280 if (f71882fg_has_in1_alarm
[data
->type
])
1281 data
->in_status
= f71882fg_read8(data
,
1282 F71882FG_REG_IN_STATUS
);
1283 for (nr
= 0; nr
< F71882FG_MAX_INS
; nr
++)
1284 if (f71882fg_has_in
[data
->type
][nr
])
1285 data
->in
[nr
] = f71882fg_read8(data
,
1286 F71882FG_REG_IN(nr
));
1288 data
->last_updated
= jiffies
;
1292 mutex_unlock(&data
->update_lock
);
1297 /* Sysfs Interface */
1298 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
1301 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1302 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1303 int speed
= fan_from_reg(data
->fan
[nr
]);
1305 if (speed
== FAN_MIN_DETECT
)
1308 return sprintf(buf
, "%d\n", speed
);
1311 static ssize_t
show_fan_full_speed(struct device
*dev
,
1312 struct device_attribute
*devattr
, char *buf
)
1314 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1315 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1316 int speed
= fan_from_reg(data
->fan_full_speed
[nr
]);
1317 return sprintf(buf
, "%d\n", speed
);
1320 static ssize_t
store_fan_full_speed(struct device
*dev
,
1321 struct device_attribute
*devattr
,
1322 const char *buf
, size_t count
)
1324 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1325 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1328 err
= strict_strtol(buf
, 10, &val
);
1332 val
= SENSORS_LIMIT(val
, 23, 1500000);
1333 val
= fan_to_reg(val
);
1335 mutex_lock(&data
->update_lock
);
1336 f71882fg_write16(data
, F71882FG_REG_FAN_FULL_SPEED(nr
), val
);
1337 data
->fan_full_speed
[nr
] = val
;
1338 mutex_unlock(&data
->update_lock
);
1343 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
1344 *devattr
, char *buf
)
1346 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1347 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1349 if (data
->fan_beep
& (1 << nr
))
1350 return sprintf(buf
, "1\n");
1352 return sprintf(buf
, "0\n");
1355 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
1356 *devattr
, const char *buf
, size_t count
)
1358 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1359 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1362 err
= strict_strtoul(buf
, 10, &val
);
1366 mutex_lock(&data
->update_lock
);
1367 data
->fan_beep
= f71882fg_read8(data
, F71882FG_REG_FAN_BEEP
);
1369 data
->fan_beep
|= 1 << nr
;
1371 data
->fan_beep
&= ~(1 << nr
);
1373 f71882fg_write8(data
, F71882FG_REG_FAN_BEEP
, data
->fan_beep
);
1374 mutex_unlock(&data
->update_lock
);
1379 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
1380 *devattr
, char *buf
)
1382 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1383 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1385 if (data
->fan_status
& (1 << nr
))
1386 return sprintf(buf
, "1\n");
1388 return sprintf(buf
, "0\n");
1391 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
1394 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1395 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1397 return sprintf(buf
, "%d\n", data
->in
[nr
] * 8);
1400 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
1401 *devattr
, char *buf
)
1403 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1405 return sprintf(buf
, "%d\n", data
->in1_max
* 8);
1408 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
1409 *devattr
, const char *buf
, size_t count
)
1411 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1415 err
= strict_strtol(buf
, 10, &val
);
1420 val
= SENSORS_LIMIT(val
, 0, 255);
1422 mutex_lock(&data
->update_lock
);
1423 f71882fg_write8(data
, F71882FG_REG_IN1_HIGH
, val
);
1424 data
->in1_max
= val
;
1425 mutex_unlock(&data
->update_lock
);
1430 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
1431 *devattr
, char *buf
)
1433 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1434 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1436 if (data
->in_beep
& (1 << nr
))
1437 return sprintf(buf
, "1\n");
1439 return sprintf(buf
, "0\n");
1442 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
1443 *devattr
, const char *buf
, size_t count
)
1445 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1446 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1449 err
= strict_strtoul(buf
, 10, &val
);
1453 mutex_lock(&data
->update_lock
);
1454 data
->in_beep
= f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1456 data
->in_beep
|= 1 << nr
;
1458 data
->in_beep
&= ~(1 << nr
);
1460 f71882fg_write8(data
, F71882FG_REG_IN_BEEP
, data
->in_beep
);
1461 mutex_unlock(&data
->update_lock
);
1466 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
1467 *devattr
, char *buf
)
1469 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1470 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1472 if (data
->in_status
& (1 << nr
))
1473 return sprintf(buf
, "1\n");
1475 return sprintf(buf
, "0\n");
1478 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*devattr
,
1481 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1482 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1485 if (data
->type
== f71858fg
) {
1486 /* TEMP_TABLE_SEL 1 or 3 ? */
1487 if (data
->temp_config
& 1) {
1488 sign
= data
->temp
[nr
] & 0x0001;
1489 temp
= (data
->temp
[nr
] >> 5) & 0x7ff;
1491 sign
= data
->temp
[nr
] & 0x8000;
1492 temp
= (data
->temp
[nr
] >> 5) & 0x3ff;
1498 temp
= data
->temp
[nr
] * 1000;
1500 return sprintf(buf
, "%d\n", temp
);
1503 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
1504 *devattr
, char *buf
)
1506 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1507 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1509 return sprintf(buf
, "%d\n", data
->temp_high
[nr
] * 1000);
1512 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
1513 *devattr
, const char *buf
, size_t count
)
1515 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1516 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1519 err
= strict_strtol(buf
, 10, &val
);
1524 val
= SENSORS_LIMIT(val
, 0, 255);
1526 mutex_lock(&data
->update_lock
);
1527 f71882fg_write8(data
, F71882FG_REG_TEMP_HIGH(nr
), val
);
1528 data
->temp_high
[nr
] = val
;
1529 mutex_unlock(&data
->update_lock
);
1534 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
1535 *devattr
, char *buf
)
1537 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1538 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1541 mutex_lock(&data
->update_lock
);
1543 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1545 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1546 temp_max_hyst
= (data
->temp_high
[nr
] - temp_max_hyst
) * 1000;
1547 mutex_unlock(&data
->update_lock
);
1549 return sprintf(buf
, "%d\n", temp_max_hyst
);
1552 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
1553 *devattr
, const char *buf
, size_t count
)
1555 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1556 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1557 ssize_t ret
= count
;
1561 err
= strict_strtol(buf
, 10, &val
);
1567 mutex_lock(&data
->update_lock
);
1569 /* convert abs to relative and check */
1570 data
->temp_high
[nr
] = f71882fg_read8(data
, F71882FG_REG_TEMP_HIGH(nr
));
1571 val
= SENSORS_LIMIT(val
, data
->temp_high
[nr
] - 15,
1572 data
->temp_high
[nr
]);
1573 val
= data
->temp_high
[nr
] - val
;
1575 /* convert value to register contents */
1576 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2));
1578 reg
= (reg
& 0x0f) | (val
<< 4);
1580 reg
= (reg
& 0xf0) | val
;
1581 f71882fg_write8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2), reg
);
1582 data
->temp_hyst
[nr
/ 2] = reg
;
1584 mutex_unlock(&data
->update_lock
);
1588 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
1589 *devattr
, char *buf
)
1591 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1592 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1594 return sprintf(buf
, "%d\n", data
->temp_ovt
[nr
] * 1000);
1597 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
1598 *devattr
, const char *buf
, size_t count
)
1600 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1601 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1604 err
= strict_strtol(buf
, 10, &val
);
1609 val
= SENSORS_LIMIT(val
, 0, 255);
1611 mutex_lock(&data
->update_lock
);
1612 f71882fg_write8(data
, F71882FG_REG_TEMP_OVT(nr
), val
);
1613 data
->temp_ovt
[nr
] = val
;
1614 mutex_unlock(&data
->update_lock
);
1619 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
1620 *devattr
, char *buf
)
1622 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1623 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1626 mutex_lock(&data
->update_lock
);
1628 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1630 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1631 temp_crit_hyst
= (data
->temp_ovt
[nr
] - temp_crit_hyst
) * 1000;
1632 mutex_unlock(&data
->update_lock
);
1634 return sprintf(buf
, "%d\n", temp_crit_hyst
);
1637 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
1638 *devattr
, char *buf
)
1640 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1641 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1643 return sprintf(buf
, "%d\n", data
->temp_type
[nr
]);
1646 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
1647 *devattr
, char *buf
)
1649 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1650 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1652 if (data
->temp_beep
& (1 << nr
))
1653 return sprintf(buf
, "1\n");
1655 return sprintf(buf
, "0\n");
1658 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
1659 *devattr
, const char *buf
, size_t count
)
1661 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1662 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1665 err
= strict_strtoul(buf
, 10, &val
);
1669 mutex_lock(&data
->update_lock
);
1670 data
->temp_beep
= f71882fg_read8(data
, F71882FG_REG_TEMP_BEEP
);
1672 data
->temp_beep
|= 1 << nr
;
1674 data
->temp_beep
&= ~(1 << nr
);
1676 f71882fg_write8(data
, F71882FG_REG_TEMP_BEEP
, data
->temp_beep
);
1677 mutex_unlock(&data
->update_lock
);
1682 static ssize_t
show_temp_alarm(struct device
*dev
, struct device_attribute
1683 *devattr
, char *buf
)
1685 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1686 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1688 if (data
->temp_status
& (1 << nr
))
1689 return sprintf(buf
, "1\n");
1691 return sprintf(buf
, "0\n");
1694 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
1695 *devattr
, char *buf
)
1697 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1698 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1700 if (data
->temp_diode_open
& (1 << nr
))
1701 return sprintf(buf
, "1\n");
1703 return sprintf(buf
, "0\n");
1706 static ssize_t
show_pwm(struct device
*dev
,
1707 struct device_attribute
*devattr
, char *buf
)
1709 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1710 int val
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1711 mutex_lock(&data
->update_lock
);
1712 if (data
->pwm_enable
& (1 << (2 * nr
)))
1714 val
= data
->pwm
[nr
];
1717 val
= 255 * fan_from_reg(data
->fan_target
[nr
])
1718 / fan_from_reg(data
->fan_full_speed
[nr
]);
1720 mutex_unlock(&data
->update_lock
);
1721 return sprintf(buf
, "%d\n", val
);
1724 static ssize_t
store_pwm(struct device
*dev
,
1725 struct device_attribute
*devattr
, const char *buf
,
1728 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1729 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1732 err
= strict_strtol(buf
, 10, &val
);
1736 val
= SENSORS_LIMIT(val
, 0, 255);
1738 mutex_lock(&data
->update_lock
);
1739 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1740 if ((data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 3) != 2) ||
1741 (data
->type
!= f8000
&& !((data
->pwm_enable
>> 2 * nr
) & 2))) {
1745 if (data
->pwm_enable
& (1 << (2 * nr
))) {
1747 f71882fg_write8(data
, F71882FG_REG_PWM(nr
), val
);
1748 data
->pwm
[nr
] = val
;
1751 int target
, full_speed
;
1752 full_speed
= f71882fg_read16(data
,
1753 F71882FG_REG_FAN_FULL_SPEED(nr
));
1754 target
= fan_to_reg(val
* fan_from_reg(full_speed
) / 255);
1755 f71882fg_write16(data
, F71882FG_REG_FAN_TARGET(nr
), target
);
1756 data
->fan_target
[nr
] = target
;
1757 data
->fan_full_speed
[nr
] = full_speed
;
1760 mutex_unlock(&data
->update_lock
);
1765 static ssize_t
show_simple_pwm(struct device
*dev
,
1766 struct device_attribute
*devattr
, char *buf
)
1768 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1769 int val
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1771 val
= data
->pwm
[nr
];
1772 return sprintf(buf
, "%d\n", val
);
1775 static ssize_t
store_simple_pwm(struct device
*dev
,
1776 struct device_attribute
*devattr
,
1777 const char *buf
, size_t count
)
1779 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1780 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1783 err
= strict_strtol(buf
, 10, &val
);
1787 val
= SENSORS_LIMIT(val
, 0, 255);
1789 mutex_lock(&data
->update_lock
);
1790 f71882fg_write8(data
, F71882FG_REG_PWM(nr
), val
);
1791 data
->pwm
[nr
] = val
;
1792 mutex_unlock(&data
->update_lock
);
1797 static ssize_t
show_pwm_enable(struct device
*dev
,
1798 struct device_attribute
*devattr
, char *buf
)
1801 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1802 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1804 switch ((data
->pwm_enable
>> 2 * nr
) & 3) {
1807 result
= 2; /* Normal auto mode */
1810 result
= 1; /* Manual mode */
1813 if (data
->type
== f8000
)
1814 result
= 3; /* Thermostat mode */
1816 result
= 1; /* Manual mode */
1820 return sprintf(buf
, "%d\n", result
);
1823 static ssize_t
store_pwm_enable(struct device
*dev
, struct device_attribute
1824 *devattr
, const char *buf
, size_t count
)
1826 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1827 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1830 err
= strict_strtol(buf
, 10, &val
);
1834 /* Special case for F8000 pwm channel 3 which only does auto mode */
1835 if (data
->type
== f8000
&& nr
== 2 && val
!= 2)
1838 mutex_lock(&data
->update_lock
);
1839 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1840 /* Special case for F8000 auto PWM mode / Thermostat mode */
1841 if (data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 1)) {
1844 data
->pwm_enable
&= ~(2 << (2 * nr
));
1845 break; /* Normal auto mode */
1847 data
->pwm_enable
|= 2 << (2 * nr
);
1848 break; /* Thermostat mode */
1856 /* The f71858fg does not support manual RPM mode */
1857 if (data
->type
== f71858fg
&&
1858 ((data
->pwm_enable
>> (2 * nr
)) & 1)) {
1862 data
->pwm_enable
|= 2 << (2 * nr
);
1865 data
->pwm_enable
&= ~(2 << (2 * nr
));
1866 break; /* Normal auto mode */
1872 f71882fg_write8(data
, F71882FG_REG_PWM_ENABLE
, data
->pwm_enable
);
1874 mutex_unlock(&data
->update_lock
);
1879 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
1880 struct device_attribute
*devattr
,
1884 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1885 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1886 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1888 mutex_lock(&data
->update_lock
);
1889 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1891 result
= data
->pwm_auto_point_pwm
[pwm
][point
];
1894 result
= 32 * 255 / (32 + data
->pwm_auto_point_pwm
[pwm
][point
]);
1896 mutex_unlock(&data
->update_lock
);
1898 return sprintf(buf
, "%d\n", result
);
1901 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
1902 struct device_attribute
*devattr
,
1903 const char *buf
, size_t count
)
1905 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1906 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1907 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1910 err
= strict_strtol(buf
, 10, &val
);
1914 val
= SENSORS_LIMIT(val
, 0, 255);
1916 mutex_lock(&data
->update_lock
);
1917 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1918 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1922 if (val
< 29) /* Prevent negative numbers */
1925 val
= (255 - val
) * 32 / val
;
1927 f71882fg_write8(data
, F71882FG_REG_POINT_PWM(pwm
, point
), val
);
1928 data
->pwm_auto_point_pwm
[pwm
][point
] = val
;
1929 mutex_unlock(&data
->update_lock
);
1934 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
1935 struct device_attribute
*devattr
,
1939 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1940 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1941 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1943 mutex_lock(&data
->update_lock
);
1945 result
= data
->pwm_auto_point_hyst
[nr
/ 2] >> 4;
1947 result
= data
->pwm_auto_point_hyst
[nr
/ 2] & 0x0f;
1948 result
= 1000 * (data
->pwm_auto_point_temp
[nr
][point
] - result
);
1949 mutex_unlock(&data
->update_lock
);
1951 return sprintf(buf
, "%d\n", result
);
1954 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
1955 struct device_attribute
*devattr
,
1956 const char *buf
, size_t count
)
1958 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1959 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1960 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1964 err
= strict_strtol(buf
, 10, &val
);
1970 mutex_lock(&data
->update_lock
);
1971 data
->pwm_auto_point_temp
[nr
][point
] =
1972 f71882fg_read8(data
, F71882FG_REG_POINT_TEMP(nr
, point
));
1973 val
= SENSORS_LIMIT(val
, data
->pwm_auto_point_temp
[nr
][point
] - 15,
1974 data
->pwm_auto_point_temp
[nr
][point
]);
1975 val
= data
->pwm_auto_point_temp
[nr
][point
] - val
;
1977 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_HYST(nr
/ 2));
1979 reg
= (reg
& 0x0f) | (val
<< 4);
1981 reg
= (reg
& 0xf0) | val
;
1983 f71882fg_write8(data
, F71882FG_REG_FAN_HYST(nr
/ 2), reg
);
1984 data
->pwm_auto_point_hyst
[nr
/ 2] = reg
;
1985 mutex_unlock(&data
->update_lock
);
1990 static ssize_t
show_pwm_interpolate(struct device
*dev
,
1991 struct device_attribute
*devattr
, char *buf
)
1994 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1995 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1997 result
= (data
->pwm_auto_point_mapping
[nr
] >> 4) & 1;
1999 return sprintf(buf
, "%d\n", result
);
2002 static ssize_t
store_pwm_interpolate(struct device
*dev
,
2003 struct device_attribute
*devattr
,
2004 const char *buf
, size_t count
)
2006 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2007 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
2010 err
= strict_strtoul(buf
, 10, &val
);
2014 mutex_lock(&data
->update_lock
);
2015 data
->pwm_auto_point_mapping
[nr
] =
2016 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
2018 val
= data
->pwm_auto_point_mapping
[nr
] | (1 << 4);
2020 val
= data
->pwm_auto_point_mapping
[nr
] & (~(1 << 4));
2021 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
2022 data
->pwm_auto_point_mapping
[nr
] = val
;
2023 mutex_unlock(&data
->update_lock
);
2028 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
2029 struct device_attribute
*devattr
,
2033 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
2034 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
2036 result
= 1 << ((data
->pwm_auto_point_mapping
[nr
] & 3) -
2039 return sprintf(buf
, "%d\n", result
);
2042 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
2043 struct device_attribute
*devattr
,
2044 const char *buf
, size_t count
)
2046 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2047 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
2050 err
= strict_strtol(buf
, 10, &val
);
2067 val
+= data
->temp_start
;
2068 mutex_lock(&data
->update_lock
);
2069 data
->pwm_auto_point_mapping
[nr
] =
2070 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
2071 val
= (data
->pwm_auto_point_mapping
[nr
] & 0xfc) | val
;
2072 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
2073 data
->pwm_auto_point_mapping
[nr
] = val
;
2074 mutex_unlock(&data
->update_lock
);
2079 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
2080 struct device_attribute
*devattr
,
2084 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
2085 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
2086 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
2088 result
= data
->pwm_auto_point_temp
[pwm
][point
];
2089 return sprintf(buf
, "%d\n", 1000 * result
);
2092 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
2093 struct device_attribute
*devattr
,
2094 const char *buf
, size_t count
)
2096 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2097 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
2098 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
2101 err
= strict_strtol(buf
, 10, &val
);
2107 if (data
->auto_point_temp_signed
)
2108 val
= SENSORS_LIMIT(val
, -128, 127);
2110 val
= SENSORS_LIMIT(val
, 0, 127);
2112 mutex_lock(&data
->update_lock
);
2113 f71882fg_write8(data
, F71882FG_REG_POINT_TEMP(pwm
, point
), val
);
2114 data
->pwm_auto_point_temp
[pwm
][point
] = val
;
2115 mutex_unlock(&data
->update_lock
);
2120 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
2123 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2124 return sprintf(buf
, "%s\n", f71882fg_names
[data
->type
]);
2127 static int __devinit
f71882fg_create_sysfs_files(struct platform_device
*pdev
,
2128 struct sensor_device_attribute_2
*attr
, int count
)
2132 for (i
= 0; i
< count
; i
++) {
2133 err
= device_create_file(&pdev
->dev
, &attr
[i
].dev_attr
);
2140 static void f71882fg_remove_sysfs_files(struct platform_device
*pdev
,
2141 struct sensor_device_attribute_2
*attr
, int count
)
2145 for (i
= 0; i
< count
; i
++)
2146 device_remove_file(&pdev
->dev
, &attr
[i
].dev_attr
);
2149 static int __devinit
f71882fg_probe(struct platform_device
*pdev
)
2151 struct f71882fg_data
*data
;
2152 struct f71882fg_sio_data
*sio_data
= pdev
->dev
.platform_data
;
2153 int nr_fans
= f71882fg_nr_fans
[sio_data
->type
];
2154 int nr_temps
= f71882fg_nr_temps
[sio_data
->type
];
2158 data
= kzalloc(sizeof(struct f71882fg_data
), GFP_KERNEL
);
2162 data
->addr
= platform_get_resource(pdev
, IORESOURCE_IO
, 0)->start
;
2163 data
->type
= sio_data
->type
;
2165 (data
->type
== f71858fg
|| data
->type
== f8000
) ? 0 : 1;
2166 mutex_init(&data
->update_lock
);
2167 platform_set_drvdata(pdev
, data
);
2169 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2170 if (start_reg
& 0x04) {
2171 dev_warn(&pdev
->dev
, "Hardware monitor is powered down\n");
2175 if (!(start_reg
& 0x03)) {
2176 dev_warn(&pdev
->dev
, "Hardware monitoring not activated\n");
2181 /* Register sysfs interface files */
2182 err
= device_create_file(&pdev
->dev
, &dev_attr_name
);
2184 goto exit_unregister_sysfs
;
2186 if (start_reg
& 0x01) {
2187 switch (data
->type
) {
2190 f71882fg_read8(data
, F71882FG_REG_TEMP_CONFIG
);
2191 if (data
->temp_config
& 0x10)
2192 /* The f71858fg temperature alarms behave as
2193 the f8000 alarms in this mode */
2194 err
= f71882fg_create_sysfs_files(pdev
,
2196 ARRAY_SIZE(f8000_temp_attr
));
2198 err
= f71882fg_create_sysfs_files(pdev
,
2200 ARRAY_SIZE(f71858fg_temp_attr
));
2203 err
= f71882fg_create_sysfs_files(pdev
,
2205 ARRAY_SIZE(f8000_temp_attr
));
2208 err
= f71882fg_create_sysfs_files(pdev
,
2209 &fxxxx_temp_attr
[0][0],
2210 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2213 goto exit_unregister_sysfs
;
2215 if (f71882fg_temp_has_beep
[data
->type
]) {
2216 err
= f71882fg_create_sysfs_files(pdev
,
2217 &fxxxx_temp_beep_attr
[0][0],
2218 ARRAY_SIZE(fxxxx_temp_beep_attr
[0])
2221 goto exit_unregister_sysfs
;
2224 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2225 if (f71882fg_has_in
[data
->type
][i
]) {
2226 err
= device_create_file(&pdev
->dev
,
2227 &fxxxx_in_attr
[i
].dev_attr
);
2229 goto exit_unregister_sysfs
;
2232 if (f71882fg_has_in1_alarm
[data
->type
]) {
2233 err
= f71882fg_create_sysfs_files(pdev
,
2234 fxxxx_in1_alarm_attr
,
2235 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2237 goto exit_unregister_sysfs
;
2241 if (start_reg
& 0x02) {
2242 switch (data
->type
) {
2246 /* These always have signed auto point temps */
2247 data
->auto_point_temp_signed
= 1;
2248 /* Fall through to select correct fan/pwm reg bank! */
2252 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_FAULT_T
);
2253 if (reg
& F71882FG_FAN_NEG_TEMP_EN
)
2254 data
->auto_point_temp_signed
= 1;
2255 /* Ensure banked pwm registers point to right bank */
2256 reg
&= ~F71882FG_FAN_PROG_SEL
;
2257 f71882fg_write8(data
, F71882FG_REG_FAN_FAULT_T
, reg
);
2264 f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
2266 /* Sanity check the pwm settings */
2267 switch (data
->type
) {
2270 for (i
= 0; i
< nr_fans
; i
++)
2271 if (((data
->pwm_enable
>> (i
* 2)) & 3) == 3)
2275 err
= (data
->pwm_enable
& 0x15) != 0x15;
2278 err
= data
->pwm_enable
& 0x20;
2286 "Invalid (reserved) pwm settings: 0x%02x\n",
2287 (unsigned int)data
->pwm_enable
);
2289 goto exit_unregister_sysfs
;
2292 err
= f71882fg_create_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2293 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2295 goto exit_unregister_sysfs
;
2297 if (f71882fg_fan_has_beep
[data
->type
]) {
2298 err
= f71882fg_create_sysfs_files(pdev
,
2299 fxxxx_fan_beep_attr
, nr_fans
);
2301 goto exit_unregister_sysfs
;
2304 switch (data
->type
) {
2311 for (i
= 0; i
< nr_fans
; i
++) {
2312 data
->pwm_auto_point_mapping
[i
] =
2313 f71882fg_read8(data
,
2314 F71882FG_REG_POINT_MAPPING(i
));
2315 if ((data
->pwm_auto_point_mapping
[i
] & 0x80) ||
2316 (data
->pwm_auto_point_mapping
[i
] & 3) == 0)
2320 dev_warn(&pdev
->dev
,
2321 "Auto pwm controlled by raw digital "
2322 "data, disabling pwm auto_point "
2323 "sysfs attributes\n");
2324 goto no_pwm_auto_point
;
2331 switch (data
->type
) {
2333 err
= f71882fg_create_sysfs_files(pdev
,
2334 &fxxxx_auto_pwm_attr
[0][0],
2335 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2337 goto exit_unregister_sysfs
;
2338 err
= f71882fg_create_sysfs_files(pdev
,
2340 ARRAY_SIZE(f71808a_fan3_attr
));
2343 err
= f71882fg_create_sysfs_files(pdev
,
2344 f71862fg_auto_pwm_attr
,
2345 ARRAY_SIZE(f71862fg_auto_pwm_attr
));
2349 err
= f71882fg_create_sysfs_files(pdev
,
2350 f71869_auto_pwm_attr
,
2351 ARRAY_SIZE(f71869_auto_pwm_attr
));
2354 err
= f71882fg_create_sysfs_files(pdev
,
2356 ARRAY_SIZE(f8000_fan_attr
));
2358 goto exit_unregister_sysfs
;
2359 err
= f71882fg_create_sysfs_files(pdev
,
2360 f8000_auto_pwm_attr
,
2361 ARRAY_SIZE(f8000_auto_pwm_attr
));
2364 err
= f71882fg_create_sysfs_files(pdev
,
2365 &fxxxx_auto_pwm_attr
[0][0],
2366 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2369 goto exit_unregister_sysfs
;
2372 for (i
= 0; i
< nr_fans
; i
++)
2373 dev_info(&pdev
->dev
, "Fan: %d is in %s mode\n", i
+ 1,
2374 (data
->pwm_enable
& (1 << 2 * i
)) ?
2375 "duty-cycle" : "RPM");
2378 data
->hwmon_dev
= hwmon_device_register(&pdev
->dev
);
2379 if (IS_ERR(data
->hwmon_dev
)) {
2380 err
= PTR_ERR(data
->hwmon_dev
);
2381 data
->hwmon_dev
= NULL
;
2382 goto exit_unregister_sysfs
;
2387 exit_unregister_sysfs
:
2388 f71882fg_remove(pdev
); /* Will unregister the sysfs files for us */
2389 return err
; /* f71882fg_remove() also frees our data */
2395 static int f71882fg_remove(struct platform_device
*pdev
)
2397 struct f71882fg_data
*data
= platform_get_drvdata(pdev
);
2398 int nr_fans
= f71882fg_nr_fans
[data
->type
];
2399 int nr_temps
= f71882fg_nr_temps
[data
->type
];
2401 u8 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2403 if (data
->hwmon_dev
)
2404 hwmon_device_unregister(data
->hwmon_dev
);
2406 device_remove_file(&pdev
->dev
, &dev_attr_name
);
2408 if (start_reg
& 0x01) {
2409 switch (data
->type
) {
2411 if (data
->temp_config
& 0x10)
2412 f71882fg_remove_sysfs_files(pdev
,
2414 ARRAY_SIZE(f8000_temp_attr
));
2416 f71882fg_remove_sysfs_files(pdev
,
2418 ARRAY_SIZE(f71858fg_temp_attr
));
2421 f71882fg_remove_sysfs_files(pdev
,
2423 ARRAY_SIZE(f8000_temp_attr
));
2426 f71882fg_remove_sysfs_files(pdev
,
2427 &fxxxx_temp_attr
[0][0],
2428 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2430 if (f71882fg_temp_has_beep
[data
->type
]) {
2431 f71882fg_remove_sysfs_files(pdev
,
2432 &fxxxx_temp_beep_attr
[0][0],
2433 ARRAY_SIZE(fxxxx_temp_beep_attr
[0]) * nr_temps
);
2436 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2437 if (f71882fg_has_in
[data
->type
][i
]) {
2438 device_remove_file(&pdev
->dev
,
2439 &fxxxx_in_attr
[i
].dev_attr
);
2442 if (f71882fg_has_in1_alarm
[data
->type
]) {
2443 f71882fg_remove_sysfs_files(pdev
,
2444 fxxxx_in1_alarm_attr
,
2445 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2449 if (start_reg
& 0x02) {
2450 f71882fg_remove_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2451 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2453 if (f71882fg_fan_has_beep
[data
->type
]) {
2454 f71882fg_remove_sysfs_files(pdev
,
2455 fxxxx_fan_beep_attr
, nr_fans
);
2458 switch (data
->type
) {
2460 f71882fg_remove_sysfs_files(pdev
,
2461 &fxxxx_auto_pwm_attr
[0][0],
2462 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2463 f71882fg_remove_sysfs_files(pdev
,
2465 ARRAY_SIZE(f71808a_fan3_attr
));
2468 f71882fg_remove_sysfs_files(pdev
,
2469 f71862fg_auto_pwm_attr
,
2470 ARRAY_SIZE(f71862fg_auto_pwm_attr
));
2474 f71882fg_remove_sysfs_files(pdev
,
2475 f71869_auto_pwm_attr
,
2476 ARRAY_SIZE(f71869_auto_pwm_attr
));
2479 f71882fg_remove_sysfs_files(pdev
,
2481 ARRAY_SIZE(f8000_fan_attr
));
2482 f71882fg_remove_sysfs_files(pdev
,
2483 f8000_auto_pwm_attr
,
2484 ARRAY_SIZE(f8000_auto_pwm_attr
));
2487 f71882fg_remove_sysfs_files(pdev
,
2488 &fxxxx_auto_pwm_attr
[0][0],
2489 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2493 platform_set_drvdata(pdev
, NULL
);
2499 static int __init
f71882fg_find(int sioaddr
, unsigned short *address
,
2500 struct f71882fg_sio_data
*sio_data
)
2503 int err
= superio_enter(sioaddr
);
2507 devid
= superio_inw(sioaddr
, SIO_REG_MANID
);
2508 if (devid
!= SIO_FINTEK_ID
) {
2509 pr_debug("Not a Fintek device\n");
2514 devid
= force_id
? force_id
: superio_inw(sioaddr
, SIO_REG_DEVID
);
2516 case SIO_F71808E_ID
:
2517 sio_data
->type
= f71808e
;
2519 case SIO_F71808A_ID
:
2520 sio_data
->type
= f71808a
;
2523 sio_data
->type
= f71858fg
;
2526 sio_data
->type
= f71862fg
;
2529 sio_data
->type
= f71869
;
2532 sio_data
->type
= f71882fg
;
2535 sio_data
->type
= f71889fg
;
2537 case SIO_F71889E_ID
:
2538 sio_data
->type
= f71889ed
;
2540 case SIO_F71889A_ID
:
2541 sio_data
->type
= f71889a
;
2544 sio_data
->type
= f8000
;
2547 sio_data
->type
= f81865f
;
2550 pr_info("Unsupported Fintek device: %04x\n",
2551 (unsigned int)devid
);
2556 if (sio_data
->type
== f71858fg
)
2557 superio_select(sioaddr
, SIO_F71858FG_LD_HWM
);
2559 superio_select(sioaddr
, SIO_F71882FG_LD_HWM
);
2561 if (!(superio_inb(sioaddr
, SIO_REG_ENABLE
) & 0x01)) {
2562 pr_warn("Device not activated\n");
2567 *address
= superio_inw(sioaddr
, SIO_REG_ADDR
);
2568 if (*address
== 0) {
2569 pr_warn("Base address not set\n");
2573 *address
&= ~(REGION_LENGTH
- 1); /* Ignore 3 LSB */
2576 pr_info("Found %s chip at %#x, revision %d\n",
2577 f71882fg_names
[sio_data
->type
], (unsigned int)*address
,
2578 (int)superio_inb(sioaddr
, SIO_REG_DEVREV
));
2580 superio_exit(sioaddr
);
2584 static int __init
f71882fg_device_add(unsigned short address
,
2585 const struct f71882fg_sio_data
*sio_data
)
2587 struct resource res
= {
2589 .end
= address
+ REGION_LENGTH
- 1,
2590 .flags
= IORESOURCE_IO
,
2594 f71882fg_pdev
= platform_device_alloc(DRVNAME
, address
);
2598 res
.name
= f71882fg_pdev
->name
;
2599 err
= acpi_check_resource_conflict(&res
);
2601 goto exit_device_put
;
2603 err
= platform_device_add_resources(f71882fg_pdev
, &res
, 1);
2605 pr_err("Device resource addition failed\n");
2606 goto exit_device_put
;
2609 err
= platform_device_add_data(f71882fg_pdev
, sio_data
,
2610 sizeof(struct f71882fg_sio_data
));
2612 pr_err("Platform data allocation failed\n");
2613 goto exit_device_put
;
2616 err
= platform_device_add(f71882fg_pdev
);
2618 pr_err("Device addition failed\n");
2619 goto exit_device_put
;
2625 platform_device_put(f71882fg_pdev
);
2630 static int __init
f71882fg_init(void)
2633 unsigned short address
;
2634 struct f71882fg_sio_data sio_data
;
2636 memset(&sio_data
, 0, sizeof(sio_data
));
2638 if (f71882fg_find(0x2e, &address
, &sio_data
) &&
2639 f71882fg_find(0x4e, &address
, &sio_data
))
2642 err
= platform_driver_register(&f71882fg_driver
);
2646 err
= f71882fg_device_add(address
, &sio_data
);
2653 platform_driver_unregister(&f71882fg_driver
);
2658 static void __exit
f71882fg_exit(void)
2660 platform_device_unregister(f71882fg_pdev
);
2661 platform_driver_unregister(&f71882fg_driver
);
2664 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2665 MODULE_AUTHOR("Hans Edgington, Hans de Goede (hdegoede@redhat.com)");
2666 MODULE_LICENSE("GPL");
2668 module_init(f71882fg_init
);
2669 module_exit(f71882fg_exit
);