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_F71869A_ID 0x1007 /* Chipset ID */
56 #define SIO_F71882_ID 0x0541 /* Chipset ID */
57 #define SIO_F71889_ID 0x0723 /* Chipset ID */
58 #define SIO_F71889E_ID 0x0909 /* Chipset ID */
59 #define SIO_F71889A_ID 0x1005 /* Chipset ID */
60 #define SIO_F8000_ID 0x0581 /* Chipset ID */
61 #define SIO_F81865_ID 0x0704 /* Chipset ID */
63 #define REGION_LENGTH 8
64 #define ADDR_REG_OFFSET 5
65 #define DATA_REG_OFFSET 6
67 #define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */
68 #define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */
69 #define F71882FG_REG_IN(nr) (0x20 + (nr))
70 #define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */
72 #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
73 #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
74 #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
75 #define F71882FG_REG_FAN_STATUS 0x92
76 #define F71882FG_REG_FAN_BEEP 0x93
78 #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
79 #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
80 #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
81 #define F71882FG_REG_TEMP_STATUS 0x62
82 #define F71882FG_REG_TEMP_BEEP 0x63
83 #define F71882FG_REG_TEMP_CONFIG 0x69
84 #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
85 #define F71882FG_REG_TEMP_TYPE 0x6B
86 #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
88 #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
89 #define F71882FG_REG_PWM_TYPE 0x94
90 #define F71882FG_REG_PWM_ENABLE 0x96
92 #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
94 #define F71882FG_REG_FAN_FAULT_T 0x9F
95 #define F71882FG_FAN_NEG_TEMP_EN 0x20
96 #define F71882FG_FAN_PROG_SEL 0x80
98 #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
99 #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
100 #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
102 #define F71882FG_REG_START 0x01
104 #define F71882FG_MAX_INS 9
106 #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
108 static unsigned short force_id
;
109 module_param(force_id
, ushort
, 0);
110 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
112 enum chips
{ f71808e
, f71808a
, f71858fg
, f71862fg
, f71869
, f71869a
, f71882fg
,
113 f71889fg
, f71889ed
, f71889a
, f8000
, f81865f
};
115 static const char *const f71882fg_names
[] = {
120 "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
123 "f71889fg", /* f81801u too, same id */
130 static const char f71882fg_has_in
[][F71882FG_MAX_INS
] = {
131 [f71808e
] = { 1, 1, 1, 1, 1, 1, 0, 1, 1 },
132 [f71808a
] = { 1, 1, 1, 1, 0, 0, 0, 1, 1 },
133 [f71858fg
] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
134 [f71862fg
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
135 [f71869
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
136 [f71869a
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
137 [f71882fg
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
138 [f71889fg
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
139 [f71889ed
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
140 [f71889a
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
141 [f8000
] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
142 [f81865f
] = { 1, 1, 1, 1, 1, 1, 1, 0, 0 },
145 static const char f71882fg_has_in1_alarm
[] = {
160 static const char f71882fg_fan_has_beep
[] = {
175 static const char f71882fg_nr_fans
[] = {
177 [f71808a
] = 2, /* +1 fan which is monitor + simple pwm only */
186 [f8000
] = 3, /* +1 fan which is monitor only */
190 static const char f71882fg_temp_has_beep
[] = {
205 static const char f71882fg_nr_temps
[] = {
220 static struct platform_device
*f71882fg_pdev
;
222 /* Super-I/O Function prototypes */
223 static inline int superio_inb(int base
, int reg
);
224 static inline int superio_inw(int base
, int reg
);
225 static inline int superio_enter(int base
);
226 static inline void superio_select(int base
, int ld
);
227 static inline void superio_exit(int base
);
229 struct f71882fg_sio_data
{
233 struct f71882fg_data
{
236 struct device
*hwmon_dev
;
238 struct mutex update_lock
;
239 int temp_start
; /* temp numbering start (0 or 1) */
240 char valid
; /* !=0 if following fields are valid */
241 char auto_point_temp_signed
;
242 unsigned long last_updated
; /* In jiffies */
243 unsigned long last_limits
; /* In jiffies */
245 /* Register Values */
246 u8 in
[F71882FG_MAX_INS
];
252 u16 fan_full_speed
[4];
256 * Note: all models have max 3 temperature channels, but on some
257 * they are addressed as 0-2 and on others as 1-3, so for coding
258 * convenience we reserve space for 4 channels
263 u8 temp_hyst
[2]; /* 2 hysts stored per reg */
271 u8 pwm_auto_point_hyst
[2];
272 u8 pwm_auto_point_mapping
[4];
273 u8 pwm_auto_point_pwm
[4][5];
274 s8 pwm_auto_point_temp
[4][4];
278 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
280 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
281 *devattr
, char *buf
);
282 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
283 *devattr
, const char *buf
, size_t count
);
284 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
285 *devattr
, char *buf
);
286 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
287 *devattr
, const char *buf
, size_t count
);
288 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
289 *devattr
, char *buf
);
291 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
293 static ssize_t
show_fan_full_speed(struct device
*dev
,
294 struct device_attribute
*devattr
, char *buf
);
295 static ssize_t
store_fan_full_speed(struct device
*dev
,
296 struct device_attribute
*devattr
, const char *buf
, size_t count
);
297 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
298 *devattr
, char *buf
);
299 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
300 *devattr
, const char *buf
, size_t count
);
301 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
302 *devattr
, char *buf
);
304 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
305 *devattr
, char *buf
);
306 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
307 *devattr
, char *buf
);
308 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
309 *devattr
, const char *buf
, size_t count
);
310 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
311 *devattr
, char *buf
);
312 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
313 *devattr
, const char *buf
, size_t count
);
314 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
315 *devattr
, char *buf
);
316 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
317 *devattr
, const char *buf
, size_t count
);
318 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
319 *devattr
, char *buf
);
320 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
321 *devattr
, char *buf
);
322 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
323 *devattr
, char *buf
);
324 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
325 *devattr
, const char *buf
, size_t count
);
326 static ssize_t
show_temp_alarm(struct device
*dev
, struct device_attribute
327 *devattr
, char *buf
);
328 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
329 *devattr
, char *buf
);
330 /* PWM and Auto point control */
331 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*devattr
,
333 static ssize_t
store_pwm(struct device
*dev
, struct device_attribute
*devattr
,
334 const char *buf
, size_t count
);
335 static ssize_t
show_simple_pwm(struct device
*dev
,
336 struct device_attribute
*devattr
, char *buf
);
337 static ssize_t
store_simple_pwm(struct device
*dev
,
338 struct device_attribute
*devattr
, const char *buf
, size_t count
);
339 static ssize_t
show_pwm_enable(struct device
*dev
,
340 struct device_attribute
*devattr
, char *buf
);
341 static ssize_t
store_pwm_enable(struct device
*dev
,
342 struct device_attribute
*devattr
, const char *buf
, size_t count
);
343 static ssize_t
show_pwm_interpolate(struct device
*dev
,
344 struct device_attribute
*devattr
, char *buf
);
345 static ssize_t
store_pwm_interpolate(struct device
*dev
,
346 struct device_attribute
*devattr
, const char *buf
, size_t count
);
347 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
348 struct device_attribute
*devattr
, char *buf
);
349 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
350 struct device_attribute
*devattr
, const char *buf
, size_t count
);
351 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
352 struct device_attribute
*devattr
, char *buf
);
353 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
354 struct device_attribute
*devattr
, const char *buf
, size_t count
);
355 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
356 struct device_attribute
*devattr
, char *buf
);
357 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
358 struct device_attribute
*devattr
, const char *buf
, size_t count
);
359 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
360 struct device_attribute
*devattr
, char *buf
);
361 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
362 struct device_attribute
*devattr
, const char *buf
, size_t count
);
364 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
367 static int f71882fg_probe(struct platform_device
*pdev
);
368 static int f71882fg_remove(struct platform_device
*pdev
);
370 static struct platform_driver f71882fg_driver
= {
374 .probe
= f71882fg_probe
,
375 .remove
= f71882fg_remove
,
378 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
381 * Temp attr for the f71858fg, the f71858fg is special as it has its
382 * temperature indexes start at 0 (the others start at 1)
384 static struct sensor_device_attribute_2 f71858fg_temp_attr
[] = {
385 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
386 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
387 store_temp_max
, 0, 0),
388 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
389 store_temp_max_hyst
, 0, 0),
390 SENSOR_ATTR_2(temp1_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 0),
391 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
392 store_temp_crit
, 0, 0),
393 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
395 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
396 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
397 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
398 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
399 store_temp_max
, 0, 1),
400 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
401 store_temp_max_hyst
, 0, 1),
402 SENSOR_ATTR_2(temp2_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
403 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
404 store_temp_crit
, 0, 1),
405 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
407 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
408 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
409 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
410 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
411 store_temp_max
, 0, 2),
412 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
413 store_temp_max_hyst
, 0, 2),
414 SENSOR_ATTR_2(temp3_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
415 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
416 store_temp_crit
, 0, 2),
417 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
419 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
420 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
423 /* Temp attr for the standard models */
424 static struct sensor_device_attribute_2 fxxxx_temp_attr
[3][9] = { {
425 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
426 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
427 store_temp_max
, 0, 1),
428 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
429 store_temp_max_hyst
, 0, 1),
431 * Should really be temp1_max_alarm, but older versions did not handle
432 * the max and crit alarms separately and lm_sensors v2 depends on the
433 * presence of temp#_alarm files. The same goes for temp2/3 _alarm.
435 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
436 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
437 store_temp_crit
, 0, 1),
438 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
440 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
441 SENSOR_ATTR_2(temp1_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 1),
442 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
444 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
445 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
446 store_temp_max
, 0, 2),
447 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
448 store_temp_max_hyst
, 0, 2),
449 /* Should be temp2_max_alarm, see temp1_alarm note */
450 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
451 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
452 store_temp_crit
, 0, 2),
453 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
455 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
456 SENSOR_ATTR_2(temp2_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 2),
457 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
459 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 3),
460 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
461 store_temp_max
, 0, 3),
462 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
463 store_temp_max_hyst
, 0, 3),
464 /* Should be temp3_max_alarm, see temp1_alarm note */
465 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 3),
466 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
467 store_temp_crit
, 0, 3),
468 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
470 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 7),
471 SENSOR_ATTR_2(temp3_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 3),
472 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 3),
475 /* Temp attr for models which can beep on temp alarm */
476 static struct sensor_device_attribute_2 fxxxx_temp_beep_attr
[3][2] = { {
477 SENSOR_ATTR_2(temp1_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
478 store_temp_beep
, 0, 1),
479 SENSOR_ATTR_2(temp1_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
480 store_temp_beep
, 0, 5),
482 SENSOR_ATTR_2(temp2_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
483 store_temp_beep
, 0, 2),
484 SENSOR_ATTR_2(temp2_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
485 store_temp_beep
, 0, 6),
487 SENSOR_ATTR_2(temp3_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
488 store_temp_beep
, 0, 3),
489 SENSOR_ATTR_2(temp3_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
490 store_temp_beep
, 0, 7),
494 * Temp attr for the f8000
495 * Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
496 * is used as hysteresis value to clear alarms
497 * Also like the f71858fg its temperature indexes start at 0
499 static struct sensor_device_attribute_2 f8000_temp_attr
[] = {
500 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
501 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
502 store_temp_crit
, 0, 0),
503 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
504 store_temp_max
, 0, 0),
505 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
506 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
507 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
508 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
509 store_temp_crit
, 0, 1),
510 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
511 store_temp_max
, 0, 1),
512 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
513 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
514 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
515 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
516 store_temp_crit
, 0, 2),
517 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
518 store_temp_max
, 0, 2),
519 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
520 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
523 /* in attr for all models */
524 static struct sensor_device_attribute_2 fxxxx_in_attr
[] = {
525 SENSOR_ATTR_2(in0_input
, S_IRUGO
, show_in
, NULL
, 0, 0),
526 SENSOR_ATTR_2(in1_input
, S_IRUGO
, show_in
, NULL
, 0, 1),
527 SENSOR_ATTR_2(in2_input
, S_IRUGO
, show_in
, NULL
, 0, 2),
528 SENSOR_ATTR_2(in3_input
, S_IRUGO
, show_in
, NULL
, 0, 3),
529 SENSOR_ATTR_2(in4_input
, S_IRUGO
, show_in
, NULL
, 0, 4),
530 SENSOR_ATTR_2(in5_input
, S_IRUGO
, show_in
, NULL
, 0, 5),
531 SENSOR_ATTR_2(in6_input
, S_IRUGO
, show_in
, NULL
, 0, 6),
532 SENSOR_ATTR_2(in7_input
, S_IRUGO
, show_in
, NULL
, 0, 7),
533 SENSOR_ATTR_2(in8_input
, S_IRUGO
, show_in
, NULL
, 0, 8),
536 /* For models with in1 alarm capability */
537 static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr
[] = {
538 SENSOR_ATTR_2(in1_max
, S_IRUGO
|S_IWUSR
, show_in_max
, store_in_max
,
540 SENSOR_ATTR_2(in1_beep
, S_IRUGO
|S_IWUSR
, show_in_beep
, store_in_beep
,
542 SENSOR_ATTR_2(in1_alarm
, S_IRUGO
, show_in_alarm
, NULL
, 0, 1),
545 /* Fan / PWM attr common to all models */
546 static struct sensor_device_attribute_2 fxxxx_fan_attr
[4][6] = { {
547 SENSOR_ATTR_2(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0, 0),
548 SENSOR_ATTR_2(fan1_full_speed
, S_IRUGO
|S_IWUSR
,
550 store_fan_full_speed
, 0, 0),
551 SENSOR_ATTR_2(fan1_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 0),
552 SENSOR_ATTR_2(pwm1
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 0),
553 SENSOR_ATTR_2(pwm1_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
554 store_pwm_enable
, 0, 0),
555 SENSOR_ATTR_2(pwm1_interpolate
, S_IRUGO
|S_IWUSR
,
556 show_pwm_interpolate
, store_pwm_interpolate
, 0, 0),
558 SENSOR_ATTR_2(fan2_input
, S_IRUGO
, show_fan
, NULL
, 0, 1),
559 SENSOR_ATTR_2(fan2_full_speed
, S_IRUGO
|S_IWUSR
,
561 store_fan_full_speed
, 0, 1),
562 SENSOR_ATTR_2(fan2_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 1),
563 SENSOR_ATTR_2(pwm2
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 1),
564 SENSOR_ATTR_2(pwm2_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
565 store_pwm_enable
, 0, 1),
566 SENSOR_ATTR_2(pwm2_interpolate
, S_IRUGO
|S_IWUSR
,
567 show_pwm_interpolate
, store_pwm_interpolate
, 0, 1),
569 SENSOR_ATTR_2(fan3_input
, S_IRUGO
, show_fan
, NULL
, 0, 2),
570 SENSOR_ATTR_2(fan3_full_speed
, S_IRUGO
|S_IWUSR
,
572 store_fan_full_speed
, 0, 2),
573 SENSOR_ATTR_2(fan3_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 2),
574 SENSOR_ATTR_2(pwm3
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 2),
575 SENSOR_ATTR_2(pwm3_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
576 store_pwm_enable
, 0, 2),
577 SENSOR_ATTR_2(pwm3_interpolate
, S_IRUGO
|S_IWUSR
,
578 show_pwm_interpolate
, store_pwm_interpolate
, 0, 2),
580 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
581 SENSOR_ATTR_2(fan4_full_speed
, S_IRUGO
|S_IWUSR
,
583 store_fan_full_speed
, 0, 3),
584 SENSOR_ATTR_2(fan4_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 3),
585 SENSOR_ATTR_2(pwm4
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 3),
586 SENSOR_ATTR_2(pwm4_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
587 store_pwm_enable
, 0, 3),
588 SENSOR_ATTR_2(pwm4_interpolate
, S_IRUGO
|S_IWUSR
,
589 show_pwm_interpolate
, store_pwm_interpolate
, 0, 3),
592 /* Attr for the third fan of the f71808a, which only has manual pwm */
593 static struct sensor_device_attribute_2 f71808a_fan3_attr
[] = {
594 SENSOR_ATTR_2(fan3_input
, S_IRUGO
, show_fan
, NULL
, 0, 2),
595 SENSOR_ATTR_2(fan3_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 2),
596 SENSOR_ATTR_2(pwm3
, S_IRUGO
|S_IWUSR
,
597 show_simple_pwm
, store_simple_pwm
, 0, 2),
600 /* Attr for models which can beep on Fan alarm */
601 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr
[] = {
602 SENSOR_ATTR_2(fan1_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
603 store_fan_beep
, 0, 0),
604 SENSOR_ATTR_2(fan2_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
605 store_fan_beep
, 0, 1),
606 SENSOR_ATTR_2(fan3_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
607 store_fan_beep
, 0, 2),
608 SENSOR_ATTR_2(fan4_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
609 store_fan_beep
, 0, 3),
613 * PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
616 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr
[3][7] = { {
617 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
618 show_pwm_auto_point_channel
,
619 store_pwm_auto_point_channel
, 0, 0),
620 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
621 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
623 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
624 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
626 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
627 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
629 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
630 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
632 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
633 show_pwm_auto_point_temp_hyst
,
634 store_pwm_auto_point_temp_hyst
,
636 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
637 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
639 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
640 show_pwm_auto_point_channel
,
641 store_pwm_auto_point_channel
, 0, 1),
642 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
643 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
645 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
646 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
648 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
649 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
651 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
652 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
654 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
655 show_pwm_auto_point_temp_hyst
,
656 store_pwm_auto_point_temp_hyst
,
658 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
659 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
661 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
662 show_pwm_auto_point_channel
,
663 store_pwm_auto_point_channel
, 0, 2),
664 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
665 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
667 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
668 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
670 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
671 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
673 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
674 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
676 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
677 show_pwm_auto_point_temp_hyst
,
678 store_pwm_auto_point_temp_hyst
,
680 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
681 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
685 * PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
686 * pwm setting when the temperature is above the pwmX_auto_point1_temp can be
687 * programmed instead of being hardcoded to 0xff
689 static struct sensor_device_attribute_2 f71869_auto_pwm_attr
[3][8] = { {
690 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
691 show_pwm_auto_point_channel
,
692 store_pwm_auto_point_channel
, 0, 0),
693 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
694 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
696 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
697 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
699 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
700 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
702 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
703 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
705 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
706 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
708 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
709 show_pwm_auto_point_temp_hyst
,
710 store_pwm_auto_point_temp_hyst
,
712 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
713 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
715 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
716 show_pwm_auto_point_channel
,
717 store_pwm_auto_point_channel
, 0, 1),
718 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
719 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
721 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
722 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
724 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
725 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
727 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
728 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
730 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
731 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
733 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
734 show_pwm_auto_point_temp_hyst
,
735 store_pwm_auto_point_temp_hyst
,
737 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
738 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
740 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
741 show_pwm_auto_point_channel
,
742 store_pwm_auto_point_channel
, 0, 2),
743 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
744 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
746 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
747 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
749 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
750 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
752 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
753 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
755 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
756 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
758 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
759 show_pwm_auto_point_temp_hyst
,
760 store_pwm_auto_point_temp_hyst
,
762 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
763 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
766 /* PWM attr for the standard models */
767 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr
[4][14] = { {
768 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
769 show_pwm_auto_point_channel
,
770 store_pwm_auto_point_channel
, 0, 0),
771 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
772 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
774 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
775 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
777 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
778 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
780 SENSOR_ATTR_2(pwm1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
781 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
783 SENSOR_ATTR_2(pwm1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
784 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
786 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
787 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
789 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
790 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
792 SENSOR_ATTR_2(pwm1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
793 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
795 SENSOR_ATTR_2(pwm1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
796 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
798 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
799 show_pwm_auto_point_temp_hyst
,
800 store_pwm_auto_point_temp_hyst
,
802 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
803 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
804 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst
, S_IRUGO
,
805 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
806 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst
, S_IRUGO
,
807 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
809 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
810 show_pwm_auto_point_channel
,
811 store_pwm_auto_point_channel
, 0, 1),
812 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
813 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
815 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
816 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
818 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
819 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
821 SENSOR_ATTR_2(pwm2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
822 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
824 SENSOR_ATTR_2(pwm2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
825 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
827 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
828 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
830 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
831 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
833 SENSOR_ATTR_2(pwm2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
834 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
836 SENSOR_ATTR_2(pwm2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
837 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
839 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
840 show_pwm_auto_point_temp_hyst
,
841 store_pwm_auto_point_temp_hyst
,
843 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
844 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
845 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst
, S_IRUGO
,
846 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
847 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst
, S_IRUGO
,
848 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
850 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
851 show_pwm_auto_point_channel
,
852 store_pwm_auto_point_channel
, 0, 2),
853 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
854 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
856 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
857 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
859 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
860 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
862 SENSOR_ATTR_2(pwm3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
863 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
865 SENSOR_ATTR_2(pwm3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
866 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
868 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
869 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
871 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
872 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
874 SENSOR_ATTR_2(pwm3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
875 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
877 SENSOR_ATTR_2(pwm3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
878 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
880 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
881 show_pwm_auto_point_temp_hyst
,
882 store_pwm_auto_point_temp_hyst
,
884 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
885 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
886 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst
, S_IRUGO
,
887 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
888 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst
, S_IRUGO
,
889 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
891 SENSOR_ATTR_2(pwm4_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
892 show_pwm_auto_point_channel
,
893 store_pwm_auto_point_channel
, 0, 3),
894 SENSOR_ATTR_2(pwm4_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
895 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
897 SENSOR_ATTR_2(pwm4_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
898 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
900 SENSOR_ATTR_2(pwm4_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
901 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
903 SENSOR_ATTR_2(pwm4_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
904 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
906 SENSOR_ATTR_2(pwm4_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
907 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
909 SENSOR_ATTR_2(pwm4_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
910 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
912 SENSOR_ATTR_2(pwm4_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
913 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
915 SENSOR_ATTR_2(pwm4_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
916 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
918 SENSOR_ATTR_2(pwm4_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
919 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
921 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
922 show_pwm_auto_point_temp_hyst
,
923 store_pwm_auto_point_temp_hyst
,
925 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst
, S_IRUGO
,
926 show_pwm_auto_point_temp_hyst
, NULL
, 1, 3),
927 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst
, S_IRUGO
,
928 show_pwm_auto_point_temp_hyst
, NULL
, 2, 3),
929 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst
, S_IRUGO
,
930 show_pwm_auto_point_temp_hyst
, NULL
, 3, 3),
933 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
934 static struct sensor_device_attribute_2 f8000_fan_attr
[] = {
935 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
939 * PWM attr for the f8000, zones mapped to temp instead of to pwm!
940 * Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
941 * F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0
943 static struct sensor_device_attribute_2 f8000_auto_pwm_attr
[3][14] = { {
944 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
945 show_pwm_auto_point_channel
,
946 store_pwm_auto_point_channel
, 0, 0),
947 SENSOR_ATTR_2(temp1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
948 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
950 SENSOR_ATTR_2(temp1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
951 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
953 SENSOR_ATTR_2(temp1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
954 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
956 SENSOR_ATTR_2(temp1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
957 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
959 SENSOR_ATTR_2(temp1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
960 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
962 SENSOR_ATTR_2(temp1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
963 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
965 SENSOR_ATTR_2(temp1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
966 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
968 SENSOR_ATTR_2(temp1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
969 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
971 SENSOR_ATTR_2(temp1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
972 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
974 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
975 show_pwm_auto_point_temp_hyst
,
976 store_pwm_auto_point_temp_hyst
,
978 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst
, S_IRUGO
,
979 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
980 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst
, S_IRUGO
,
981 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
982 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst
, S_IRUGO
,
983 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
985 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
986 show_pwm_auto_point_channel
,
987 store_pwm_auto_point_channel
, 0, 1),
988 SENSOR_ATTR_2(temp2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
989 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
991 SENSOR_ATTR_2(temp2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
992 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
994 SENSOR_ATTR_2(temp2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
995 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
997 SENSOR_ATTR_2(temp2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
998 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1000 SENSOR_ATTR_2(temp2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
1001 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1003 SENSOR_ATTR_2(temp2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
1004 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1006 SENSOR_ATTR_2(temp2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
1007 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1009 SENSOR_ATTR_2(temp2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
1010 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1012 SENSOR_ATTR_2(temp2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
1013 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1015 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
1016 show_pwm_auto_point_temp_hyst
,
1017 store_pwm_auto_point_temp_hyst
,
1019 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst
, S_IRUGO
,
1020 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
1021 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst
, S_IRUGO
,
1022 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
1023 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst
, S_IRUGO
,
1024 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
1026 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
1027 show_pwm_auto_point_channel
,
1028 store_pwm_auto_point_channel
, 0, 2),
1029 SENSOR_ATTR_2(temp3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
1030 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1032 SENSOR_ATTR_2(temp3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
1033 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1035 SENSOR_ATTR_2(temp3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
1036 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1038 SENSOR_ATTR_2(temp3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
1039 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1041 SENSOR_ATTR_2(temp3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
1042 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1044 SENSOR_ATTR_2(temp3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
1045 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1047 SENSOR_ATTR_2(temp3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
1048 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1050 SENSOR_ATTR_2(temp3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
1051 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1053 SENSOR_ATTR_2(temp3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
1054 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1056 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
1057 show_pwm_auto_point_temp_hyst
,
1058 store_pwm_auto_point_temp_hyst
,
1060 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst
, S_IRUGO
,
1061 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
1062 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst
, S_IRUGO
,
1063 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
1064 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst
, S_IRUGO
,
1065 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
1068 /* Super I/O functions */
1069 static inline int superio_inb(int base
, int reg
)
1072 return inb(base
+ 1);
1075 static int superio_inw(int base
, int reg
)
1078 val
= superio_inb(base
, reg
) << 8;
1079 val
|= superio_inb(base
, reg
+ 1);
1083 static inline int superio_enter(int base
)
1085 /* Don't step on other drivers' I/O space by accident */
1086 if (!request_muxed_region(base
, 2, DRVNAME
)) {
1087 pr_err("I/O address 0x%04x already in use\n", base
);
1091 /* according to the datasheet the key must be send twice! */
1092 outb(SIO_UNLOCK_KEY
, base
);
1093 outb(SIO_UNLOCK_KEY
, base
);
1098 static inline void superio_select(int base
, int ld
)
1100 outb(SIO_REG_LDSEL
, base
);
1104 static inline void superio_exit(int base
)
1106 outb(SIO_LOCK_KEY
, base
);
1107 release_region(base
, 2);
1110 static inline int fan_from_reg(u16 reg
)
1112 return reg
? (1500000 / reg
) : 0;
1115 static inline u16
fan_to_reg(int fan
)
1117 return fan
? (1500000 / fan
) : 0;
1120 static u8
f71882fg_read8(struct f71882fg_data
*data
, u8 reg
)
1124 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
1125 val
= inb(data
->addr
+ DATA_REG_OFFSET
);
1130 static u16
f71882fg_read16(struct f71882fg_data
*data
, u8 reg
)
1134 val
= f71882fg_read8(data
, reg
) << 8;
1135 val
|= f71882fg_read8(data
, reg
+ 1);
1140 static void f71882fg_write8(struct f71882fg_data
*data
, u8 reg
, u8 val
)
1142 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
1143 outb(val
, data
->addr
+ DATA_REG_OFFSET
);
1146 static void f71882fg_write16(struct f71882fg_data
*data
, u8 reg
, u16 val
)
1148 f71882fg_write8(data
, reg
, val
>> 8);
1149 f71882fg_write8(data
, reg
+ 1, val
& 0xff);
1152 static u16
f71882fg_read_temp(struct f71882fg_data
*data
, int nr
)
1154 if (data
->type
== f71858fg
)
1155 return f71882fg_read16(data
, F71882FG_REG_TEMP(nr
));
1157 return f71882fg_read8(data
, F71882FG_REG_TEMP(nr
));
1160 static struct f71882fg_data
*f71882fg_update_device(struct device
*dev
)
1162 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1163 int nr_fans
= f71882fg_nr_fans
[data
->type
];
1164 int nr_temps
= f71882fg_nr_temps
[data
->type
];
1167 mutex_lock(&data
->update_lock
);
1169 /* Update once every 60 seconds */
1170 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
) ||
1172 if (f71882fg_has_in1_alarm
[data
->type
]) {
1174 f71882fg_read8(data
, F71882FG_REG_IN1_HIGH
);
1176 f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1179 /* Get High & boundary temps*/
1180 for (nr
= data
->temp_start
; nr
< nr_temps
+ data
->temp_start
;
1182 data
->temp_ovt
[nr
] = f71882fg_read8(data
,
1183 F71882FG_REG_TEMP_OVT(nr
));
1184 data
->temp_high
[nr
] = f71882fg_read8(data
,
1185 F71882FG_REG_TEMP_HIGH(nr
));
1188 if (data
->type
!= f8000
) {
1189 data
->temp_hyst
[0] = f71882fg_read8(data
,
1190 F71882FG_REG_TEMP_HYST(0));
1191 data
->temp_hyst
[1] = f71882fg_read8(data
,
1192 F71882FG_REG_TEMP_HYST(1));
1194 /* All but the f71858fg / f8000 have this register */
1195 if ((data
->type
!= f71858fg
) && (data
->type
!= f8000
)) {
1196 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_TYPE
);
1197 data
->temp_type
[1] = (reg
& 0x02) ? 2 : 4;
1198 data
->temp_type
[2] = (reg
& 0x04) ? 2 : 4;
1199 data
->temp_type
[3] = (reg
& 0x08) ? 2 : 4;
1202 if (f71882fg_fan_has_beep
[data
->type
])
1203 data
->fan_beep
= f71882fg_read8(data
,
1204 F71882FG_REG_FAN_BEEP
);
1206 if (f71882fg_temp_has_beep
[data
->type
])
1207 data
->temp_beep
= f71882fg_read8(data
,
1208 F71882FG_REG_TEMP_BEEP
);
1210 data
->pwm_enable
= f71882fg_read8(data
,
1211 F71882FG_REG_PWM_ENABLE
);
1212 data
->pwm_auto_point_hyst
[0] =
1213 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(0));
1214 data
->pwm_auto_point_hyst
[1] =
1215 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(1));
1217 for (nr
= 0; nr
< nr_fans
; nr
++) {
1218 data
->pwm_auto_point_mapping
[nr
] =
1219 f71882fg_read8(data
,
1220 F71882FG_REG_POINT_MAPPING(nr
));
1222 switch (data
->type
) {
1224 for (point
= 0; point
< 5; point
++) {
1225 data
->pwm_auto_point_pwm
[nr
][point
] =
1226 f71882fg_read8(data
,
1227 F71882FG_REG_POINT_PWM
1230 for (point
= 0; point
< 4; point
++) {
1231 data
->pwm_auto_point_temp
[nr
][point
] =
1232 f71882fg_read8(data
,
1233 F71882FG_REG_POINT_TEMP
1239 data
->pwm_auto_point_pwm
[nr
][0] =
1240 f71882fg_read8(data
,
1241 F71882FG_REG_POINT_PWM(nr
, 0));
1244 data
->pwm_auto_point_pwm
[nr
][1] =
1245 f71882fg_read8(data
,
1246 F71882FG_REG_POINT_PWM
1248 data
->pwm_auto_point_pwm
[nr
][4] =
1249 f71882fg_read8(data
,
1250 F71882FG_REG_POINT_PWM
1252 data
->pwm_auto_point_temp
[nr
][0] =
1253 f71882fg_read8(data
,
1254 F71882FG_REG_POINT_TEMP
1256 data
->pwm_auto_point_temp
[nr
][3] =
1257 f71882fg_read8(data
,
1258 F71882FG_REG_POINT_TEMP
1263 data
->last_limits
= jiffies
;
1266 /* Update every second */
1267 if (time_after(jiffies
, data
->last_updated
+ HZ
) || !data
->valid
) {
1268 data
->temp_status
= f71882fg_read8(data
,
1269 F71882FG_REG_TEMP_STATUS
);
1270 data
->temp_diode_open
= f71882fg_read8(data
,
1271 F71882FG_REG_TEMP_DIODE_OPEN
);
1272 for (nr
= data
->temp_start
; nr
< nr_temps
+ data
->temp_start
;
1274 data
->temp
[nr
] = f71882fg_read_temp(data
, nr
);
1276 data
->fan_status
= f71882fg_read8(data
,
1277 F71882FG_REG_FAN_STATUS
);
1278 for (nr
= 0; nr
< nr_fans
; nr
++) {
1279 data
->fan
[nr
] = f71882fg_read16(data
,
1280 F71882FG_REG_FAN(nr
));
1281 data
->fan_target
[nr
] =
1282 f71882fg_read16(data
, F71882FG_REG_FAN_TARGET(nr
));
1283 data
->fan_full_speed
[nr
] =
1284 f71882fg_read16(data
,
1285 F71882FG_REG_FAN_FULL_SPEED(nr
));
1287 f71882fg_read8(data
, F71882FG_REG_PWM(nr
));
1289 /* Some models have 1 more fan with limited capabilities */
1290 if (data
->type
== f71808a
) {
1291 data
->fan
[2] = f71882fg_read16(data
,
1292 F71882FG_REG_FAN(2));
1293 data
->pwm
[2] = f71882fg_read8(data
,
1294 F71882FG_REG_PWM(2));
1296 if (data
->type
== f8000
)
1297 data
->fan
[3] = f71882fg_read16(data
,
1298 F71882FG_REG_FAN(3));
1300 if (f71882fg_has_in1_alarm
[data
->type
])
1301 data
->in_status
= f71882fg_read8(data
,
1302 F71882FG_REG_IN_STATUS
);
1303 for (nr
= 0; nr
< F71882FG_MAX_INS
; nr
++)
1304 if (f71882fg_has_in
[data
->type
][nr
])
1305 data
->in
[nr
] = f71882fg_read8(data
,
1306 F71882FG_REG_IN(nr
));
1308 data
->last_updated
= jiffies
;
1312 mutex_unlock(&data
->update_lock
);
1317 /* Sysfs Interface */
1318 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
1321 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1322 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1323 int speed
= fan_from_reg(data
->fan
[nr
]);
1325 if (speed
== FAN_MIN_DETECT
)
1328 return sprintf(buf
, "%d\n", speed
);
1331 static ssize_t
show_fan_full_speed(struct device
*dev
,
1332 struct device_attribute
*devattr
, char *buf
)
1334 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1335 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1336 int speed
= fan_from_reg(data
->fan_full_speed
[nr
]);
1337 return sprintf(buf
, "%d\n", speed
);
1340 static ssize_t
store_fan_full_speed(struct device
*dev
,
1341 struct device_attribute
*devattr
,
1342 const char *buf
, size_t count
)
1344 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1345 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1348 err
= kstrtol(buf
, 10, &val
);
1352 val
= clamp_val(val
, 23, 1500000);
1353 val
= fan_to_reg(val
);
1355 mutex_lock(&data
->update_lock
);
1356 f71882fg_write16(data
, F71882FG_REG_FAN_FULL_SPEED(nr
), val
);
1357 data
->fan_full_speed
[nr
] = val
;
1358 mutex_unlock(&data
->update_lock
);
1363 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
1364 *devattr
, char *buf
)
1366 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1367 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1369 if (data
->fan_beep
& (1 << nr
))
1370 return sprintf(buf
, "1\n");
1372 return sprintf(buf
, "0\n");
1375 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
1376 *devattr
, const char *buf
, size_t count
)
1378 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1379 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1382 err
= kstrtoul(buf
, 10, &val
);
1386 mutex_lock(&data
->update_lock
);
1387 data
->fan_beep
= f71882fg_read8(data
, F71882FG_REG_FAN_BEEP
);
1389 data
->fan_beep
|= 1 << nr
;
1391 data
->fan_beep
&= ~(1 << nr
);
1393 f71882fg_write8(data
, F71882FG_REG_FAN_BEEP
, data
->fan_beep
);
1394 mutex_unlock(&data
->update_lock
);
1399 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
1400 *devattr
, char *buf
)
1402 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1403 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1405 if (data
->fan_status
& (1 << nr
))
1406 return sprintf(buf
, "1\n");
1408 return sprintf(buf
, "0\n");
1411 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
1414 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1415 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1417 return sprintf(buf
, "%d\n", data
->in
[nr
] * 8);
1420 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
1421 *devattr
, char *buf
)
1423 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1425 return sprintf(buf
, "%d\n", data
->in1_max
* 8);
1428 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
1429 *devattr
, const char *buf
, size_t count
)
1431 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1435 err
= kstrtol(buf
, 10, &val
);
1440 val
= clamp_val(val
, 0, 255);
1442 mutex_lock(&data
->update_lock
);
1443 f71882fg_write8(data
, F71882FG_REG_IN1_HIGH
, val
);
1444 data
->in1_max
= val
;
1445 mutex_unlock(&data
->update_lock
);
1450 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
1451 *devattr
, char *buf
)
1453 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1454 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1456 if (data
->in_beep
& (1 << nr
))
1457 return sprintf(buf
, "1\n");
1459 return sprintf(buf
, "0\n");
1462 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
1463 *devattr
, const char *buf
, size_t count
)
1465 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1466 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1469 err
= kstrtoul(buf
, 10, &val
);
1473 mutex_lock(&data
->update_lock
);
1474 data
->in_beep
= f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1476 data
->in_beep
|= 1 << nr
;
1478 data
->in_beep
&= ~(1 << nr
);
1480 f71882fg_write8(data
, F71882FG_REG_IN_BEEP
, data
->in_beep
);
1481 mutex_unlock(&data
->update_lock
);
1486 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
1487 *devattr
, char *buf
)
1489 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1490 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1492 if (data
->in_status
& (1 << nr
))
1493 return sprintf(buf
, "1\n");
1495 return sprintf(buf
, "0\n");
1498 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*devattr
,
1501 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1502 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1505 if (data
->type
== f71858fg
) {
1506 /* TEMP_TABLE_SEL 1 or 3 ? */
1507 if (data
->temp_config
& 1) {
1508 sign
= data
->temp
[nr
] & 0x0001;
1509 temp
= (data
->temp
[nr
] >> 5) & 0x7ff;
1511 sign
= data
->temp
[nr
] & 0x8000;
1512 temp
= (data
->temp
[nr
] >> 5) & 0x3ff;
1518 temp
= data
->temp
[nr
] * 1000;
1520 return sprintf(buf
, "%d\n", temp
);
1523 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
1524 *devattr
, char *buf
)
1526 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1527 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1529 return sprintf(buf
, "%d\n", data
->temp_high
[nr
] * 1000);
1532 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
1533 *devattr
, const char *buf
, size_t count
)
1535 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1536 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1539 err
= kstrtol(buf
, 10, &val
);
1544 val
= clamp_val(val
, 0, 255);
1546 mutex_lock(&data
->update_lock
);
1547 f71882fg_write8(data
, F71882FG_REG_TEMP_HIGH(nr
), val
);
1548 data
->temp_high
[nr
] = val
;
1549 mutex_unlock(&data
->update_lock
);
1554 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
1555 *devattr
, char *buf
)
1557 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1558 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1561 mutex_lock(&data
->update_lock
);
1563 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1565 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1566 temp_max_hyst
= (data
->temp_high
[nr
] - temp_max_hyst
) * 1000;
1567 mutex_unlock(&data
->update_lock
);
1569 return sprintf(buf
, "%d\n", temp_max_hyst
);
1572 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
1573 *devattr
, const char *buf
, size_t count
)
1575 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1576 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1577 ssize_t ret
= count
;
1581 err
= kstrtol(buf
, 10, &val
);
1587 mutex_lock(&data
->update_lock
);
1589 /* convert abs to relative and check */
1590 data
->temp_high
[nr
] = f71882fg_read8(data
, F71882FG_REG_TEMP_HIGH(nr
));
1591 val
= clamp_val(val
, data
->temp_high
[nr
] - 15, data
->temp_high
[nr
]);
1592 val
= data
->temp_high
[nr
] - val
;
1594 /* convert value to register contents */
1595 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2));
1597 reg
= (reg
& 0x0f) | (val
<< 4);
1599 reg
= (reg
& 0xf0) | val
;
1600 f71882fg_write8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2), reg
);
1601 data
->temp_hyst
[nr
/ 2] = reg
;
1603 mutex_unlock(&data
->update_lock
);
1607 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
1608 *devattr
, char *buf
)
1610 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1611 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1613 return sprintf(buf
, "%d\n", data
->temp_ovt
[nr
] * 1000);
1616 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
1617 *devattr
, const char *buf
, size_t count
)
1619 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1620 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1623 err
= kstrtol(buf
, 10, &val
);
1628 val
= clamp_val(val
, 0, 255);
1630 mutex_lock(&data
->update_lock
);
1631 f71882fg_write8(data
, F71882FG_REG_TEMP_OVT(nr
), val
);
1632 data
->temp_ovt
[nr
] = val
;
1633 mutex_unlock(&data
->update_lock
);
1638 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
1639 *devattr
, char *buf
)
1641 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1642 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1645 mutex_lock(&data
->update_lock
);
1647 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1649 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1650 temp_crit_hyst
= (data
->temp_ovt
[nr
] - temp_crit_hyst
) * 1000;
1651 mutex_unlock(&data
->update_lock
);
1653 return sprintf(buf
, "%d\n", temp_crit_hyst
);
1656 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
1657 *devattr
, char *buf
)
1659 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1660 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1662 return sprintf(buf
, "%d\n", data
->temp_type
[nr
]);
1665 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
1666 *devattr
, char *buf
)
1668 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1669 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1671 if (data
->temp_beep
& (1 << nr
))
1672 return sprintf(buf
, "1\n");
1674 return sprintf(buf
, "0\n");
1677 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
1678 *devattr
, const char *buf
, size_t count
)
1680 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1681 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1684 err
= kstrtoul(buf
, 10, &val
);
1688 mutex_lock(&data
->update_lock
);
1689 data
->temp_beep
= f71882fg_read8(data
, F71882FG_REG_TEMP_BEEP
);
1691 data
->temp_beep
|= 1 << nr
;
1693 data
->temp_beep
&= ~(1 << nr
);
1695 f71882fg_write8(data
, F71882FG_REG_TEMP_BEEP
, data
->temp_beep
);
1696 mutex_unlock(&data
->update_lock
);
1701 static ssize_t
show_temp_alarm(struct device
*dev
, struct device_attribute
1702 *devattr
, char *buf
)
1704 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1705 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1707 if (data
->temp_status
& (1 << nr
))
1708 return sprintf(buf
, "1\n");
1710 return sprintf(buf
, "0\n");
1713 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
1714 *devattr
, char *buf
)
1716 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1717 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1719 if (data
->temp_diode_open
& (1 << nr
))
1720 return sprintf(buf
, "1\n");
1722 return sprintf(buf
, "0\n");
1725 static ssize_t
show_pwm(struct device
*dev
,
1726 struct device_attribute
*devattr
, char *buf
)
1728 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1729 int val
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1730 mutex_lock(&data
->update_lock
);
1731 if (data
->pwm_enable
& (1 << (2 * nr
)))
1733 val
= data
->pwm
[nr
];
1736 val
= 255 * fan_from_reg(data
->fan_target
[nr
])
1737 / fan_from_reg(data
->fan_full_speed
[nr
]);
1739 mutex_unlock(&data
->update_lock
);
1740 return sprintf(buf
, "%d\n", val
);
1743 static ssize_t
store_pwm(struct device
*dev
,
1744 struct device_attribute
*devattr
, const char *buf
,
1747 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1748 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1751 err
= kstrtol(buf
, 10, &val
);
1755 val
= clamp_val(val
, 0, 255);
1757 mutex_lock(&data
->update_lock
);
1758 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1759 if ((data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 3) != 2) ||
1760 (data
->type
!= f8000
&& !((data
->pwm_enable
>> 2 * nr
) & 2))) {
1764 if (data
->pwm_enable
& (1 << (2 * nr
))) {
1766 f71882fg_write8(data
, F71882FG_REG_PWM(nr
), val
);
1767 data
->pwm
[nr
] = val
;
1770 int target
, full_speed
;
1771 full_speed
= f71882fg_read16(data
,
1772 F71882FG_REG_FAN_FULL_SPEED(nr
));
1773 target
= fan_to_reg(val
* fan_from_reg(full_speed
) / 255);
1774 f71882fg_write16(data
, F71882FG_REG_FAN_TARGET(nr
), target
);
1775 data
->fan_target
[nr
] = target
;
1776 data
->fan_full_speed
[nr
] = full_speed
;
1779 mutex_unlock(&data
->update_lock
);
1784 static ssize_t
show_simple_pwm(struct device
*dev
,
1785 struct device_attribute
*devattr
, char *buf
)
1787 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1788 int val
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1790 val
= data
->pwm
[nr
];
1791 return sprintf(buf
, "%d\n", val
);
1794 static ssize_t
store_simple_pwm(struct device
*dev
,
1795 struct device_attribute
*devattr
,
1796 const char *buf
, size_t count
)
1798 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1799 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1802 err
= kstrtol(buf
, 10, &val
);
1806 val
= clamp_val(val
, 0, 255);
1808 mutex_lock(&data
->update_lock
);
1809 f71882fg_write8(data
, F71882FG_REG_PWM(nr
), val
);
1810 data
->pwm
[nr
] = val
;
1811 mutex_unlock(&data
->update_lock
);
1816 static ssize_t
show_pwm_enable(struct device
*dev
,
1817 struct device_attribute
*devattr
, char *buf
)
1820 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1821 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1823 switch ((data
->pwm_enable
>> 2 * nr
) & 3) {
1826 result
= 2; /* Normal auto mode */
1829 result
= 1; /* Manual mode */
1832 if (data
->type
== f8000
)
1833 result
= 3; /* Thermostat mode */
1835 result
= 1; /* Manual mode */
1839 return sprintf(buf
, "%d\n", result
);
1842 static ssize_t
store_pwm_enable(struct device
*dev
, struct device_attribute
1843 *devattr
, const char *buf
, size_t count
)
1845 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1846 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1849 err
= kstrtol(buf
, 10, &val
);
1853 /* Special case for F8000 pwm channel 3 which only does auto mode */
1854 if (data
->type
== f8000
&& nr
== 2 && val
!= 2)
1857 mutex_lock(&data
->update_lock
);
1858 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1859 /* Special case for F8000 auto PWM mode / Thermostat mode */
1860 if (data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 1)) {
1863 data
->pwm_enable
&= ~(2 << (2 * nr
));
1864 break; /* Normal auto mode */
1866 data
->pwm_enable
|= 2 << (2 * nr
);
1867 break; /* Thermostat mode */
1875 /* The f71858fg does not support manual RPM mode */
1876 if (data
->type
== f71858fg
&&
1877 ((data
->pwm_enable
>> (2 * nr
)) & 1)) {
1881 data
->pwm_enable
|= 2 << (2 * nr
);
1884 data
->pwm_enable
&= ~(2 << (2 * nr
));
1885 break; /* Normal auto mode */
1891 f71882fg_write8(data
, F71882FG_REG_PWM_ENABLE
, data
->pwm_enable
);
1893 mutex_unlock(&data
->update_lock
);
1898 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
1899 struct device_attribute
*devattr
,
1903 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1904 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1905 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1907 mutex_lock(&data
->update_lock
);
1908 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1910 result
= data
->pwm_auto_point_pwm
[pwm
][point
];
1913 result
= 32 * 255 / (32 + data
->pwm_auto_point_pwm
[pwm
][point
]);
1915 mutex_unlock(&data
->update_lock
);
1917 return sprintf(buf
, "%d\n", result
);
1920 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
1921 struct device_attribute
*devattr
,
1922 const char *buf
, size_t count
)
1924 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1925 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1926 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1929 err
= kstrtol(buf
, 10, &val
);
1933 val
= clamp_val(val
, 0, 255);
1935 mutex_lock(&data
->update_lock
);
1936 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1937 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1941 if (val
< 29) /* Prevent negative numbers */
1944 val
= (255 - val
) * 32 / val
;
1946 f71882fg_write8(data
, F71882FG_REG_POINT_PWM(pwm
, point
), val
);
1947 data
->pwm_auto_point_pwm
[pwm
][point
] = val
;
1948 mutex_unlock(&data
->update_lock
);
1953 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
1954 struct device_attribute
*devattr
,
1958 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1959 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1960 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1962 mutex_lock(&data
->update_lock
);
1964 result
= data
->pwm_auto_point_hyst
[nr
/ 2] >> 4;
1966 result
= data
->pwm_auto_point_hyst
[nr
/ 2] & 0x0f;
1967 result
= 1000 * (data
->pwm_auto_point_temp
[nr
][point
] - result
);
1968 mutex_unlock(&data
->update_lock
);
1970 return sprintf(buf
, "%d\n", result
);
1973 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
1974 struct device_attribute
*devattr
,
1975 const char *buf
, size_t count
)
1977 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1978 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1979 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1983 err
= kstrtol(buf
, 10, &val
);
1989 mutex_lock(&data
->update_lock
);
1990 data
->pwm_auto_point_temp
[nr
][point
] =
1991 f71882fg_read8(data
, F71882FG_REG_POINT_TEMP(nr
, point
));
1992 val
= clamp_val(val
, data
->pwm_auto_point_temp
[nr
][point
] - 15,
1993 data
->pwm_auto_point_temp
[nr
][point
]);
1994 val
= data
->pwm_auto_point_temp
[nr
][point
] - val
;
1996 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_HYST(nr
/ 2));
1998 reg
= (reg
& 0x0f) | (val
<< 4);
2000 reg
= (reg
& 0xf0) | val
;
2002 f71882fg_write8(data
, F71882FG_REG_FAN_HYST(nr
/ 2), reg
);
2003 data
->pwm_auto_point_hyst
[nr
/ 2] = reg
;
2004 mutex_unlock(&data
->update_lock
);
2009 static ssize_t
show_pwm_interpolate(struct device
*dev
,
2010 struct device_attribute
*devattr
, char *buf
)
2013 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
2014 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
2016 result
= (data
->pwm_auto_point_mapping
[nr
] >> 4) & 1;
2018 return sprintf(buf
, "%d\n", result
);
2021 static ssize_t
store_pwm_interpolate(struct device
*dev
,
2022 struct device_attribute
*devattr
,
2023 const char *buf
, size_t count
)
2025 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2026 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
2029 err
= kstrtoul(buf
, 10, &val
);
2033 mutex_lock(&data
->update_lock
);
2034 data
->pwm_auto_point_mapping
[nr
] =
2035 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
2037 val
= data
->pwm_auto_point_mapping
[nr
] | (1 << 4);
2039 val
= data
->pwm_auto_point_mapping
[nr
] & (~(1 << 4));
2040 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
2041 data
->pwm_auto_point_mapping
[nr
] = val
;
2042 mutex_unlock(&data
->update_lock
);
2047 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
2048 struct device_attribute
*devattr
,
2052 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
2053 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
2055 result
= 1 << ((data
->pwm_auto_point_mapping
[nr
] & 3) -
2058 return sprintf(buf
, "%d\n", result
);
2061 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
2062 struct device_attribute
*devattr
,
2063 const char *buf
, size_t count
)
2065 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2066 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
2069 err
= kstrtol(buf
, 10, &val
);
2086 val
+= data
->temp_start
;
2087 mutex_lock(&data
->update_lock
);
2088 data
->pwm_auto_point_mapping
[nr
] =
2089 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
2090 val
= (data
->pwm_auto_point_mapping
[nr
] & 0xfc) | val
;
2091 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
2092 data
->pwm_auto_point_mapping
[nr
] = val
;
2093 mutex_unlock(&data
->update_lock
);
2098 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
2099 struct device_attribute
*devattr
,
2103 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
2104 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
2105 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
2107 result
= data
->pwm_auto_point_temp
[pwm
][point
];
2108 return sprintf(buf
, "%d\n", 1000 * result
);
2111 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
2112 struct device_attribute
*devattr
,
2113 const char *buf
, size_t count
)
2115 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2116 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
2117 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
2120 err
= kstrtol(buf
, 10, &val
);
2126 if (data
->auto_point_temp_signed
)
2127 val
= clamp_val(val
, -128, 127);
2129 val
= clamp_val(val
, 0, 127);
2131 mutex_lock(&data
->update_lock
);
2132 f71882fg_write8(data
, F71882FG_REG_POINT_TEMP(pwm
, point
), val
);
2133 data
->pwm_auto_point_temp
[pwm
][point
] = val
;
2134 mutex_unlock(&data
->update_lock
);
2139 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
2142 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2143 return sprintf(buf
, "%s\n", f71882fg_names
[data
->type
]);
2146 static int f71882fg_create_sysfs_files(struct platform_device
*pdev
,
2147 struct sensor_device_attribute_2
*attr
, int count
)
2151 for (i
= 0; i
< count
; i
++) {
2152 err
= device_create_file(&pdev
->dev
, &attr
[i
].dev_attr
);
2159 static void f71882fg_remove_sysfs_files(struct platform_device
*pdev
,
2160 struct sensor_device_attribute_2
*attr
, int count
)
2164 for (i
= 0; i
< count
; i
++)
2165 device_remove_file(&pdev
->dev
, &attr
[i
].dev_attr
);
2168 static int f71882fg_create_fan_sysfs_files(
2169 struct platform_device
*pdev
, int idx
)
2171 struct f71882fg_data
*data
= platform_get_drvdata(pdev
);
2174 /* Sanity check the pwm setting */
2176 switch (data
->type
) {
2178 if (((data
->pwm_enable
>> (idx
* 2)) & 3) == 3)
2182 if (((data
->pwm_enable
>> (idx
* 2)) & 1) != 1)
2187 err
= data
->pwm_enable
& 0x20;
2194 "Invalid (reserved) pwm settings: 0x%02x, "
2195 "skipping fan %d\n",
2196 (data
->pwm_enable
>> (idx
* 2)) & 3, idx
+ 1);
2197 return 0; /* This is a non fatal condition */
2200 err
= f71882fg_create_sysfs_files(pdev
, &fxxxx_fan_attr
[idx
][0],
2201 ARRAY_SIZE(fxxxx_fan_attr
[0]));
2205 if (f71882fg_fan_has_beep
[data
->type
]) {
2206 err
= f71882fg_create_sysfs_files(pdev
,
2207 &fxxxx_fan_beep_attr
[idx
],
2213 dev_info(&pdev
->dev
, "Fan: %d is in %s mode\n", idx
+ 1,
2214 (data
->pwm_enable
& (1 << (2 * idx
))) ? "duty-cycle" : "RPM");
2216 /* Check for unsupported auto pwm settings */
2217 switch (data
->type
) {
2225 data
->pwm_auto_point_mapping
[idx
] =
2226 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(idx
));
2227 if ((data
->pwm_auto_point_mapping
[idx
] & 0x80) ||
2228 (data
->pwm_auto_point_mapping
[idx
] & 3) == 0) {
2229 dev_warn(&pdev
->dev
,
2230 "Auto pwm controlled by raw digital "
2231 "data, disabling pwm auto_point "
2232 "sysfs attributes for fan %d\n", idx
+ 1);
2233 return 0; /* This is a non fatal condition */
2240 switch (data
->type
) {
2242 err
= f71882fg_create_sysfs_files(pdev
,
2243 &f71862fg_auto_pwm_attr
[idx
][0],
2244 ARRAY_SIZE(f71862fg_auto_pwm_attr
[0]));
2248 err
= f71882fg_create_sysfs_files(pdev
,
2249 &f71869_auto_pwm_attr
[idx
][0],
2250 ARRAY_SIZE(f71869_auto_pwm_attr
[0]));
2253 err
= f71882fg_create_sysfs_files(pdev
,
2254 &f8000_auto_pwm_attr
[idx
][0],
2255 ARRAY_SIZE(f8000_auto_pwm_attr
[0]));
2258 err
= f71882fg_create_sysfs_files(pdev
,
2259 &fxxxx_auto_pwm_attr
[idx
][0],
2260 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]));
2266 static int f71882fg_probe(struct platform_device
*pdev
)
2268 struct f71882fg_data
*data
;
2269 struct f71882fg_sio_data
*sio_data
= dev_get_platdata(&pdev
->dev
);
2270 int nr_fans
= f71882fg_nr_fans
[sio_data
->type
];
2271 int nr_temps
= f71882fg_nr_temps
[sio_data
->type
];
2275 data
= devm_kzalloc(&pdev
->dev
, sizeof(struct f71882fg_data
),
2280 data
->addr
= platform_get_resource(pdev
, IORESOURCE_IO
, 0)->start
;
2281 data
->type
= sio_data
->type
;
2283 (data
->type
== f71858fg
|| data
->type
== f8000
) ? 0 : 1;
2284 mutex_init(&data
->update_lock
);
2285 platform_set_drvdata(pdev
, data
);
2287 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2288 if (start_reg
& 0x04) {
2289 dev_warn(&pdev
->dev
, "Hardware monitor is powered down\n");
2292 if (!(start_reg
& 0x03)) {
2293 dev_warn(&pdev
->dev
, "Hardware monitoring not activated\n");
2297 /* Register sysfs interface files */
2298 err
= device_create_file(&pdev
->dev
, &dev_attr_name
);
2300 goto exit_unregister_sysfs
;
2302 if (start_reg
& 0x01) {
2303 switch (data
->type
) {
2306 f71882fg_read8(data
, F71882FG_REG_TEMP_CONFIG
);
2307 if (data
->temp_config
& 0x10)
2309 * The f71858fg temperature alarms behave as
2310 * the f8000 alarms in this mode
2312 err
= f71882fg_create_sysfs_files(pdev
,
2314 ARRAY_SIZE(f8000_temp_attr
));
2316 err
= f71882fg_create_sysfs_files(pdev
,
2318 ARRAY_SIZE(f71858fg_temp_attr
));
2321 err
= f71882fg_create_sysfs_files(pdev
,
2323 ARRAY_SIZE(f8000_temp_attr
));
2326 err
= f71882fg_create_sysfs_files(pdev
,
2327 &fxxxx_temp_attr
[0][0],
2328 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2331 goto exit_unregister_sysfs
;
2333 if (f71882fg_temp_has_beep
[data
->type
]) {
2334 err
= f71882fg_create_sysfs_files(pdev
,
2335 &fxxxx_temp_beep_attr
[0][0],
2336 ARRAY_SIZE(fxxxx_temp_beep_attr
[0])
2339 goto exit_unregister_sysfs
;
2342 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2343 if (f71882fg_has_in
[data
->type
][i
]) {
2344 err
= device_create_file(&pdev
->dev
,
2345 &fxxxx_in_attr
[i
].dev_attr
);
2347 goto exit_unregister_sysfs
;
2350 if (f71882fg_has_in1_alarm
[data
->type
]) {
2351 err
= f71882fg_create_sysfs_files(pdev
,
2352 fxxxx_in1_alarm_attr
,
2353 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2355 goto exit_unregister_sysfs
;
2359 if (start_reg
& 0x02) {
2360 switch (data
->type
) {
2365 /* These always have signed auto point temps */
2366 data
->auto_point_temp_signed
= 1;
2367 /* Fall through to select correct fan/pwm reg bank! */
2371 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_FAULT_T
);
2372 if (reg
& F71882FG_FAN_NEG_TEMP_EN
)
2373 data
->auto_point_temp_signed
= 1;
2374 /* Ensure banked pwm registers point to right bank */
2375 reg
&= ~F71882FG_FAN_PROG_SEL
;
2376 f71882fg_write8(data
, F71882FG_REG_FAN_FAULT_T
, reg
);
2383 f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
2385 for (i
= 0; i
< nr_fans
; i
++) {
2386 err
= f71882fg_create_fan_sysfs_files(pdev
, i
);
2388 goto exit_unregister_sysfs
;
2391 /* Some types have 1 extra fan with limited functionality */
2392 switch (data
->type
) {
2394 err
= f71882fg_create_sysfs_files(pdev
,
2396 ARRAY_SIZE(f71808a_fan3_attr
));
2399 err
= f71882fg_create_sysfs_files(pdev
,
2401 ARRAY_SIZE(f8000_fan_attr
));
2407 goto exit_unregister_sysfs
;
2410 data
->hwmon_dev
= hwmon_device_register(&pdev
->dev
);
2411 if (IS_ERR(data
->hwmon_dev
)) {
2412 err
= PTR_ERR(data
->hwmon_dev
);
2413 data
->hwmon_dev
= NULL
;
2414 goto exit_unregister_sysfs
;
2419 exit_unregister_sysfs
:
2420 f71882fg_remove(pdev
); /* Will unregister the sysfs files for us */
2421 return err
; /* f71882fg_remove() also frees our data */
2424 static int f71882fg_remove(struct platform_device
*pdev
)
2426 struct f71882fg_data
*data
= platform_get_drvdata(pdev
);
2427 int nr_fans
= f71882fg_nr_fans
[data
->type
];
2428 int nr_temps
= f71882fg_nr_temps
[data
->type
];
2430 u8 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2432 if (data
->hwmon_dev
)
2433 hwmon_device_unregister(data
->hwmon_dev
);
2435 device_remove_file(&pdev
->dev
, &dev_attr_name
);
2437 if (start_reg
& 0x01) {
2438 switch (data
->type
) {
2440 if (data
->temp_config
& 0x10)
2441 f71882fg_remove_sysfs_files(pdev
,
2443 ARRAY_SIZE(f8000_temp_attr
));
2445 f71882fg_remove_sysfs_files(pdev
,
2447 ARRAY_SIZE(f71858fg_temp_attr
));
2450 f71882fg_remove_sysfs_files(pdev
,
2452 ARRAY_SIZE(f8000_temp_attr
));
2455 f71882fg_remove_sysfs_files(pdev
,
2456 &fxxxx_temp_attr
[0][0],
2457 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2459 if (f71882fg_temp_has_beep
[data
->type
]) {
2460 f71882fg_remove_sysfs_files(pdev
,
2461 &fxxxx_temp_beep_attr
[0][0],
2462 ARRAY_SIZE(fxxxx_temp_beep_attr
[0]) * nr_temps
);
2465 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2466 if (f71882fg_has_in
[data
->type
][i
]) {
2467 device_remove_file(&pdev
->dev
,
2468 &fxxxx_in_attr
[i
].dev_attr
);
2471 if (f71882fg_has_in1_alarm
[data
->type
]) {
2472 f71882fg_remove_sysfs_files(pdev
,
2473 fxxxx_in1_alarm_attr
,
2474 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2478 if (start_reg
& 0x02) {
2479 f71882fg_remove_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2480 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2482 if (f71882fg_fan_has_beep
[data
->type
]) {
2483 f71882fg_remove_sysfs_files(pdev
,
2484 fxxxx_fan_beep_attr
, nr_fans
);
2487 switch (data
->type
) {
2489 f71882fg_remove_sysfs_files(pdev
,
2490 &fxxxx_auto_pwm_attr
[0][0],
2491 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2492 f71882fg_remove_sysfs_files(pdev
,
2494 ARRAY_SIZE(f71808a_fan3_attr
));
2497 f71882fg_remove_sysfs_files(pdev
,
2498 &f71862fg_auto_pwm_attr
[0][0],
2499 ARRAY_SIZE(f71862fg_auto_pwm_attr
[0]) *
2504 f71882fg_remove_sysfs_files(pdev
,
2505 &f71869_auto_pwm_attr
[0][0],
2506 ARRAY_SIZE(f71869_auto_pwm_attr
[0]) * nr_fans
);
2509 f71882fg_remove_sysfs_files(pdev
,
2511 ARRAY_SIZE(f8000_fan_attr
));
2512 f71882fg_remove_sysfs_files(pdev
,
2513 &f8000_auto_pwm_attr
[0][0],
2514 ARRAY_SIZE(f8000_auto_pwm_attr
[0]) * nr_fans
);
2517 f71882fg_remove_sysfs_files(pdev
,
2518 &fxxxx_auto_pwm_attr
[0][0],
2519 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2525 static int __init
f71882fg_find(int sioaddr
, struct f71882fg_sio_data
*sio_data
)
2528 unsigned short address
;
2529 int err
= superio_enter(sioaddr
);
2533 devid
= superio_inw(sioaddr
, SIO_REG_MANID
);
2534 if (devid
!= SIO_FINTEK_ID
) {
2535 pr_debug("Not a Fintek device\n");
2540 devid
= force_id
? force_id
: superio_inw(sioaddr
, SIO_REG_DEVID
);
2542 case SIO_F71808E_ID
:
2543 sio_data
->type
= f71808e
;
2545 case SIO_F71808A_ID
:
2546 sio_data
->type
= f71808a
;
2549 sio_data
->type
= f71858fg
;
2552 sio_data
->type
= f71862fg
;
2555 sio_data
->type
= f71869
;
2557 case SIO_F71869A_ID
:
2558 sio_data
->type
= f71869a
;
2561 sio_data
->type
= f71882fg
;
2564 sio_data
->type
= f71889fg
;
2566 case SIO_F71889E_ID
:
2567 sio_data
->type
= f71889ed
;
2569 case SIO_F71889A_ID
:
2570 sio_data
->type
= f71889a
;
2573 sio_data
->type
= f8000
;
2576 sio_data
->type
= f81865f
;
2579 pr_info("Unsupported Fintek device: %04x\n",
2580 (unsigned int)devid
);
2585 if (sio_data
->type
== f71858fg
)
2586 superio_select(sioaddr
, SIO_F71858FG_LD_HWM
);
2588 superio_select(sioaddr
, SIO_F71882FG_LD_HWM
);
2590 if (!(superio_inb(sioaddr
, SIO_REG_ENABLE
) & 0x01)) {
2591 pr_warn("Device not activated\n");
2596 address
= superio_inw(sioaddr
, SIO_REG_ADDR
);
2598 pr_warn("Base address not set\n");
2602 address
&= ~(REGION_LENGTH
- 1); /* Ignore 3 LSB */
2605 pr_info("Found %s chip at %#x, revision %d\n",
2606 f71882fg_names
[sio_data
->type
], (unsigned int)address
,
2607 (int)superio_inb(sioaddr
, SIO_REG_DEVREV
));
2609 superio_exit(sioaddr
);
2613 static int __init
f71882fg_device_add(int address
,
2614 const struct f71882fg_sio_data
*sio_data
)
2616 struct resource res
= {
2618 .end
= address
+ REGION_LENGTH
- 1,
2619 .flags
= IORESOURCE_IO
,
2623 f71882fg_pdev
= platform_device_alloc(DRVNAME
, address
);
2627 res
.name
= f71882fg_pdev
->name
;
2628 err
= acpi_check_resource_conflict(&res
);
2630 goto exit_device_put
;
2632 err
= platform_device_add_resources(f71882fg_pdev
, &res
, 1);
2634 pr_err("Device resource addition failed\n");
2635 goto exit_device_put
;
2638 err
= platform_device_add_data(f71882fg_pdev
, sio_data
,
2639 sizeof(struct f71882fg_sio_data
));
2641 pr_err("Platform data allocation failed\n");
2642 goto exit_device_put
;
2645 err
= platform_device_add(f71882fg_pdev
);
2647 pr_err("Device addition failed\n");
2648 goto exit_device_put
;
2654 platform_device_put(f71882fg_pdev
);
2659 static int __init
f71882fg_init(void)
2663 struct f71882fg_sio_data sio_data
;
2665 memset(&sio_data
, 0, sizeof(sio_data
));
2667 address
= f71882fg_find(0x2e, &sio_data
);
2669 address
= f71882fg_find(0x4e, &sio_data
);
2673 err
= platform_driver_register(&f71882fg_driver
);
2677 err
= f71882fg_device_add(address
, &sio_data
);
2684 platform_driver_unregister(&f71882fg_driver
);
2688 static void __exit
f71882fg_exit(void)
2690 platform_device_unregister(f71882fg_pdev
);
2691 platform_driver_unregister(&f71882fg_driver
);
2694 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2695 MODULE_AUTHOR("Hans Edgington, Hans de Goede <hdegoede@redhat.com>");
2696 MODULE_LICENSE("GPL");
2698 module_init(f71882fg_init
);
2699 module_exit(f71882fg_exit
);