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_F71858_ID 0x0507 /* Chipset ID */
52 #define SIO_F71862_ID 0x0601 /* Chipset ID */
53 #define SIO_F71869_ID 0x0814 /* Chipset ID */
54 #define SIO_F71882_ID 0x0541 /* Chipset ID */
55 #define SIO_F71889_ID 0x0723 /* Chipset ID */
56 #define SIO_F71889E_ID 0x0909 /* Chipset ID */
57 #define SIO_F71889A_ID 0x1005 /* Chipset ID */
58 #define SIO_F8000_ID 0x0581 /* Chipset ID */
59 #define SIO_F81865_ID 0x0704 /* Chipset ID */
61 #define REGION_LENGTH 8
62 #define ADDR_REG_OFFSET 5
63 #define DATA_REG_OFFSET 6
65 #define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */
66 #define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */
67 #define F71882FG_REG_IN(nr) (0x20 + (nr))
68 #define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */
70 #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
71 #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
72 #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
73 #define F71882FG_REG_FAN_STATUS 0x92
74 #define F71882FG_REG_FAN_BEEP 0x93
76 #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
77 #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
78 #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
79 #define F71882FG_REG_TEMP_STATUS 0x62
80 #define F71882FG_REG_TEMP_BEEP 0x63
81 #define F71882FG_REG_TEMP_CONFIG 0x69
82 #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
83 #define F71882FG_REG_TEMP_TYPE 0x6B
84 #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
86 #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
87 #define F71882FG_REG_PWM_TYPE 0x94
88 #define F71882FG_REG_PWM_ENABLE 0x96
90 #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
92 #define F71882FG_REG_FAN_FAULT_T 0x9F
93 #define F71882FG_FAN_NEG_TEMP_EN 0x20
94 #define F71882FG_FAN_PROG_SEL 0x80
96 #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
97 #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
98 #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
100 #define F71882FG_REG_START 0x01
102 #define F71882FG_MAX_INS 9
104 #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
106 static unsigned short force_id
;
107 module_param(force_id
, ushort
, 0);
108 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
110 enum chips
{ f71808e
, f71858fg
, f71862fg
, f71869
, f71882fg
, f71889fg
,
111 f71889ed
, f71889a
, f8000
, f81865f
};
113 static const char *f71882fg_names
[] = {
117 "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
119 "f71889fg", /* f81801u too, same id */
126 static const char f71882fg_has_in
[][F71882FG_MAX_INS
] = {
127 [f71808e
] = { 1, 1, 1, 1, 1, 1, 0, 1, 1 },
128 [f71858fg
] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
129 [f71862fg
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
130 [f71869
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
131 [f71882fg
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
132 [f71889fg
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
133 [f71889ed
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
134 [f71889a
] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
135 [f8000
] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
136 [f81865f
] = { 1, 1, 1, 1, 1, 1, 1, 0, 0 },
139 static const char f71882fg_has_in1_alarm
[] = {
152 static const char f71882fg_fan_has_beep
[] = {
165 static const char f71882fg_nr_fans
[] = {
178 static const char f71882fg_temp_has_beep
[] = {
191 static const char f71882fg_nr_temps
[] = {
204 static struct platform_device
*f71882fg_pdev
;
206 /* Super-I/O Function prototypes */
207 static inline int superio_inb(int base
, int reg
);
208 static inline int superio_inw(int base
, int reg
);
209 static inline int superio_enter(int base
);
210 static inline void superio_select(int base
, int ld
);
211 static inline void superio_exit(int base
);
213 struct f71882fg_sio_data
{
217 struct f71882fg_data
{
220 struct device
*hwmon_dev
;
222 struct mutex update_lock
;
223 int temp_start
; /* temp numbering start (0 or 1) */
224 char valid
; /* !=0 if following fields are valid */
225 char auto_point_temp_signed
;
226 unsigned long last_updated
; /* In jiffies */
227 unsigned long last_limits
; /* In jiffies */
229 /* Register Values */
230 u8 in
[F71882FG_MAX_INS
];
236 u16 fan_full_speed
[4];
239 /* Note: all models have max 3 temperature channels, but on some
240 they are addressed as 0-2 and on others as 1-3, so for coding
241 convenience we reserve space for 4 channels */
245 u8 temp_hyst
[2]; /* 2 hysts stored per reg */
253 u8 pwm_auto_point_hyst
[2];
254 u8 pwm_auto_point_mapping
[4];
255 u8 pwm_auto_point_pwm
[4][5];
256 s8 pwm_auto_point_temp
[4][4];
260 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
262 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
263 *devattr
, char *buf
);
264 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
265 *devattr
, const char *buf
, size_t count
);
266 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
267 *devattr
, char *buf
);
268 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
269 *devattr
, const char *buf
, size_t count
);
270 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
271 *devattr
, char *buf
);
273 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
275 static ssize_t
show_fan_full_speed(struct device
*dev
,
276 struct device_attribute
*devattr
, char *buf
);
277 static ssize_t
store_fan_full_speed(struct device
*dev
,
278 struct device_attribute
*devattr
, const char *buf
, size_t count
);
279 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
280 *devattr
, char *buf
);
281 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
282 *devattr
, const char *buf
, size_t count
);
283 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
284 *devattr
, char *buf
);
286 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
287 *devattr
, char *buf
);
288 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
289 *devattr
, char *buf
);
290 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
291 *devattr
, const char *buf
, size_t count
);
292 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
293 *devattr
, char *buf
);
294 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
295 *devattr
, const char *buf
, size_t count
);
296 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
297 *devattr
, char *buf
);
298 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
299 *devattr
, const char *buf
, size_t count
);
300 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
301 *devattr
, char *buf
);
302 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
303 *devattr
, char *buf
);
304 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
305 *devattr
, char *buf
);
306 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
307 *devattr
, const char *buf
, size_t count
);
308 static ssize_t
show_temp_alarm(struct device
*dev
, struct device_attribute
309 *devattr
, char *buf
);
310 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
311 *devattr
, char *buf
);
312 /* PWM and Auto point control */
313 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*devattr
,
315 static ssize_t
store_pwm(struct device
*dev
, struct device_attribute
*devattr
,
316 const char *buf
, size_t count
);
317 static ssize_t
show_pwm_enable(struct device
*dev
,
318 struct device_attribute
*devattr
, char *buf
);
319 static ssize_t
store_pwm_enable(struct device
*dev
,
320 struct device_attribute
*devattr
, const char *buf
, size_t count
);
321 static ssize_t
show_pwm_interpolate(struct device
*dev
,
322 struct device_attribute
*devattr
, char *buf
);
323 static ssize_t
store_pwm_interpolate(struct device
*dev
,
324 struct device_attribute
*devattr
, const char *buf
, size_t count
);
325 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
326 struct device_attribute
*devattr
, char *buf
);
327 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
328 struct device_attribute
*devattr
, const char *buf
, size_t count
);
329 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
330 struct device_attribute
*devattr
, char *buf
);
331 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
332 struct device_attribute
*devattr
, const char *buf
, size_t count
);
333 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
334 struct device_attribute
*devattr
, char *buf
);
335 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
336 struct device_attribute
*devattr
, const char *buf
, size_t count
);
337 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
338 struct device_attribute
*devattr
, char *buf
);
339 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
340 struct device_attribute
*devattr
, const char *buf
, size_t count
);
342 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
345 static int __devinit
f71882fg_probe(struct platform_device
* pdev
);
346 static int f71882fg_remove(struct platform_device
*pdev
);
348 static struct platform_driver f71882fg_driver
= {
350 .owner
= THIS_MODULE
,
353 .probe
= f71882fg_probe
,
354 .remove
= f71882fg_remove
,
357 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
359 /* Temp attr for the f71858fg, the f71858fg is special as it has its
360 temperature indexes start at 0 (the others start at 1) */
361 static struct sensor_device_attribute_2 f71858fg_temp_attr
[] = {
362 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
363 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
364 store_temp_max
, 0, 0),
365 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
366 store_temp_max_hyst
, 0, 0),
367 SENSOR_ATTR_2(temp1_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 0),
368 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
369 store_temp_crit
, 0, 0),
370 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
372 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
373 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
374 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
375 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
376 store_temp_max
, 0, 1),
377 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
378 store_temp_max_hyst
, 0, 1),
379 SENSOR_ATTR_2(temp2_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
380 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
381 store_temp_crit
, 0, 1),
382 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
384 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
385 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
386 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
387 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
388 store_temp_max
, 0, 2),
389 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
390 store_temp_max_hyst
, 0, 2),
391 SENSOR_ATTR_2(temp3_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
392 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
393 store_temp_crit
, 0, 2),
394 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
396 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
397 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
400 /* Temp attr for the standard models */
401 static struct sensor_device_attribute_2 fxxxx_temp_attr
[3][9] = { {
402 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
403 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
404 store_temp_max
, 0, 1),
405 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
406 store_temp_max_hyst
, 0, 1),
407 /* Should really be temp1_max_alarm, but older versions did not handle
408 the max and crit alarms separately and lm_sensors v2 depends on the
409 presence of temp#_alarm files. The same goes for temp2/3 _alarm. */
410 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
411 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
412 store_temp_crit
, 0, 1),
413 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
415 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
416 SENSOR_ATTR_2(temp1_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 1),
417 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
419 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
420 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
421 store_temp_max
, 0, 2),
422 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
423 store_temp_max_hyst
, 0, 2),
424 /* Should be temp2_max_alarm, see temp1_alarm note */
425 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
426 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
427 store_temp_crit
, 0, 2),
428 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
430 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
431 SENSOR_ATTR_2(temp2_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 2),
432 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
434 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 3),
435 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
436 store_temp_max
, 0, 3),
437 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
438 store_temp_max_hyst
, 0, 3),
439 /* Should be temp3_max_alarm, see temp1_alarm note */
440 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 3),
441 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
442 store_temp_crit
, 0, 3),
443 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
445 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 7),
446 SENSOR_ATTR_2(temp3_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 3),
447 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 3),
450 /* Temp attr for models which can beep on temp alarm */
451 static struct sensor_device_attribute_2 fxxxx_temp_beep_attr
[3][2] = { {
452 SENSOR_ATTR_2(temp1_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
453 store_temp_beep
, 0, 1),
454 SENSOR_ATTR_2(temp1_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
455 store_temp_beep
, 0, 5),
457 SENSOR_ATTR_2(temp2_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
458 store_temp_beep
, 0, 2),
459 SENSOR_ATTR_2(temp2_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
460 store_temp_beep
, 0, 6),
462 SENSOR_ATTR_2(temp3_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
463 store_temp_beep
, 0, 3),
464 SENSOR_ATTR_2(temp3_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
465 store_temp_beep
, 0, 7),
468 /* Temp attr for the f8000
469 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
470 is used as hysteresis value to clear alarms
471 Also like the f71858fg its temperature indexes start at 0
473 static struct sensor_device_attribute_2 f8000_temp_attr
[] = {
474 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
475 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
476 store_temp_crit
, 0, 0),
477 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
478 store_temp_max
, 0, 0),
479 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
480 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
481 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
482 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
483 store_temp_crit
, 0, 1),
484 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
485 store_temp_max
, 0, 1),
486 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
487 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
488 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
489 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
490 store_temp_crit
, 0, 2),
491 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
492 store_temp_max
, 0, 2),
493 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
494 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
497 /* in attr for all models */
498 static struct sensor_device_attribute_2 fxxxx_in_attr
[] = {
499 SENSOR_ATTR_2(in0_input
, S_IRUGO
, show_in
, NULL
, 0, 0),
500 SENSOR_ATTR_2(in1_input
, S_IRUGO
, show_in
, NULL
, 0, 1),
501 SENSOR_ATTR_2(in2_input
, S_IRUGO
, show_in
, NULL
, 0, 2),
502 SENSOR_ATTR_2(in3_input
, S_IRUGO
, show_in
, NULL
, 0, 3),
503 SENSOR_ATTR_2(in4_input
, S_IRUGO
, show_in
, NULL
, 0, 4),
504 SENSOR_ATTR_2(in5_input
, S_IRUGO
, show_in
, NULL
, 0, 5),
505 SENSOR_ATTR_2(in6_input
, S_IRUGO
, show_in
, NULL
, 0, 6),
506 SENSOR_ATTR_2(in7_input
, S_IRUGO
, show_in
, NULL
, 0, 7),
507 SENSOR_ATTR_2(in8_input
, S_IRUGO
, show_in
, NULL
, 0, 8),
510 /* For models with in1 alarm capability */
511 static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr
[] = {
512 SENSOR_ATTR_2(in1_max
, S_IRUGO
|S_IWUSR
, show_in_max
, store_in_max
,
514 SENSOR_ATTR_2(in1_beep
, S_IRUGO
|S_IWUSR
, show_in_beep
, store_in_beep
,
516 SENSOR_ATTR_2(in1_alarm
, S_IRUGO
, show_in_alarm
, NULL
, 0, 1),
519 /* Fan / PWM attr common to all models */
520 static struct sensor_device_attribute_2 fxxxx_fan_attr
[4][6] = { {
521 SENSOR_ATTR_2(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0, 0),
522 SENSOR_ATTR_2(fan1_full_speed
, S_IRUGO
|S_IWUSR
,
524 store_fan_full_speed
, 0, 0),
525 SENSOR_ATTR_2(fan1_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 0),
526 SENSOR_ATTR_2(pwm1
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 0),
527 SENSOR_ATTR_2(pwm1_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
528 store_pwm_enable
, 0, 0),
529 SENSOR_ATTR_2(pwm1_interpolate
, S_IRUGO
|S_IWUSR
,
530 show_pwm_interpolate
, store_pwm_interpolate
, 0, 0),
532 SENSOR_ATTR_2(fan2_input
, S_IRUGO
, show_fan
, NULL
, 0, 1),
533 SENSOR_ATTR_2(fan2_full_speed
, S_IRUGO
|S_IWUSR
,
535 store_fan_full_speed
, 0, 1),
536 SENSOR_ATTR_2(fan2_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 1),
537 SENSOR_ATTR_2(pwm2
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 1),
538 SENSOR_ATTR_2(pwm2_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
539 store_pwm_enable
, 0, 1),
540 SENSOR_ATTR_2(pwm2_interpolate
, S_IRUGO
|S_IWUSR
,
541 show_pwm_interpolate
, store_pwm_interpolate
, 0, 1),
543 SENSOR_ATTR_2(fan3_input
, S_IRUGO
, show_fan
, NULL
, 0, 2),
544 SENSOR_ATTR_2(fan3_full_speed
, S_IRUGO
|S_IWUSR
,
546 store_fan_full_speed
, 0, 2),
547 SENSOR_ATTR_2(fan3_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 2),
548 SENSOR_ATTR_2(pwm3
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 2),
549 SENSOR_ATTR_2(pwm3_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
550 store_pwm_enable
, 0, 2),
551 SENSOR_ATTR_2(pwm3_interpolate
, S_IRUGO
|S_IWUSR
,
552 show_pwm_interpolate
, store_pwm_interpolate
, 0, 2),
554 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
555 SENSOR_ATTR_2(fan4_full_speed
, S_IRUGO
|S_IWUSR
,
557 store_fan_full_speed
, 0, 3),
558 SENSOR_ATTR_2(fan4_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 3),
559 SENSOR_ATTR_2(pwm4
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 3),
560 SENSOR_ATTR_2(pwm4_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
561 store_pwm_enable
, 0, 3),
562 SENSOR_ATTR_2(pwm4_interpolate
, S_IRUGO
|S_IWUSR
,
563 show_pwm_interpolate
, store_pwm_interpolate
, 0, 3),
566 /* Attr for models which can beep on Fan alarm */
567 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr
[] = {
568 SENSOR_ATTR_2(fan1_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
569 store_fan_beep
, 0, 0),
570 SENSOR_ATTR_2(fan2_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
571 store_fan_beep
, 0, 1),
572 SENSOR_ATTR_2(fan3_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
573 store_fan_beep
, 0, 2),
574 SENSOR_ATTR_2(fan4_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
575 store_fan_beep
, 0, 3),
578 /* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
580 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr
[] = {
581 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
582 show_pwm_auto_point_channel
,
583 store_pwm_auto_point_channel
, 0, 0),
584 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
585 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
587 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
588 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
590 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
591 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
593 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
594 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
596 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
597 show_pwm_auto_point_temp_hyst
,
598 store_pwm_auto_point_temp_hyst
,
600 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
601 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
603 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
604 show_pwm_auto_point_channel
,
605 store_pwm_auto_point_channel
, 0, 1),
606 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
607 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
609 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
610 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
612 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
613 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
615 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
616 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
618 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
619 show_pwm_auto_point_temp_hyst
,
620 store_pwm_auto_point_temp_hyst
,
622 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
623 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
625 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
626 show_pwm_auto_point_channel
,
627 store_pwm_auto_point_channel
, 0, 2),
628 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
629 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
631 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
632 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
634 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
635 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
637 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
638 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
640 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
641 show_pwm_auto_point_temp_hyst
,
642 store_pwm_auto_point_temp_hyst
,
644 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
645 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
648 /* PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
649 pwm setting when the temperature is above the pwmX_auto_point1_temp can be
650 programmed instead of being hardcoded to 0xff */
651 static struct sensor_device_attribute_2 f71869_auto_pwm_attr
[] = {
652 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
653 show_pwm_auto_point_channel
,
654 store_pwm_auto_point_channel
, 0, 0),
655 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
656 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
658 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
659 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
661 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
662 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
664 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
665 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
667 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
668 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
670 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
671 show_pwm_auto_point_temp_hyst
,
672 store_pwm_auto_point_temp_hyst
,
674 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
675 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
677 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
678 show_pwm_auto_point_channel
,
679 store_pwm_auto_point_channel
, 0, 1),
680 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
681 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
683 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
684 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
686 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
687 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
689 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
690 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
692 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
693 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
695 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
696 show_pwm_auto_point_temp_hyst
,
697 store_pwm_auto_point_temp_hyst
,
699 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
700 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
702 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
703 show_pwm_auto_point_channel
,
704 store_pwm_auto_point_channel
, 0, 2),
705 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
706 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
708 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
709 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
711 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
712 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
714 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
715 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
717 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
718 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
720 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
721 show_pwm_auto_point_temp_hyst
,
722 store_pwm_auto_point_temp_hyst
,
724 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
725 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
728 /* PWM attr for the standard models */
729 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr
[4][14] = { {
730 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
731 show_pwm_auto_point_channel
,
732 store_pwm_auto_point_channel
, 0, 0),
733 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
734 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
736 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
737 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
739 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
740 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
742 SENSOR_ATTR_2(pwm1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
743 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
745 SENSOR_ATTR_2(pwm1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
746 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
748 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
749 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
751 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
752 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
754 SENSOR_ATTR_2(pwm1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
755 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
757 SENSOR_ATTR_2(pwm1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
758 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
760 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
761 show_pwm_auto_point_temp_hyst
,
762 store_pwm_auto_point_temp_hyst
,
764 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
765 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
766 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst
, S_IRUGO
,
767 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
768 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst
, S_IRUGO
,
769 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
771 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
772 show_pwm_auto_point_channel
,
773 store_pwm_auto_point_channel
, 0, 1),
774 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
775 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
777 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
778 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
780 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
781 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
783 SENSOR_ATTR_2(pwm2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
784 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
786 SENSOR_ATTR_2(pwm2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
787 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
789 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
790 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
792 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
793 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
795 SENSOR_ATTR_2(pwm2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
796 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
798 SENSOR_ATTR_2(pwm2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
799 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
801 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
802 show_pwm_auto_point_temp_hyst
,
803 store_pwm_auto_point_temp_hyst
,
805 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
806 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
807 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst
, S_IRUGO
,
808 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
809 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst
, S_IRUGO
,
810 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
812 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
813 show_pwm_auto_point_channel
,
814 store_pwm_auto_point_channel
, 0, 2),
815 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
816 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
818 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
819 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
821 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
822 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
824 SENSOR_ATTR_2(pwm3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
825 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
827 SENSOR_ATTR_2(pwm3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
828 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
830 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
831 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
833 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
834 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
836 SENSOR_ATTR_2(pwm3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
837 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
839 SENSOR_ATTR_2(pwm3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
840 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
842 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
843 show_pwm_auto_point_temp_hyst
,
844 store_pwm_auto_point_temp_hyst
,
846 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
847 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
848 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst
, S_IRUGO
,
849 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
850 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst
, S_IRUGO
,
851 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
853 SENSOR_ATTR_2(pwm4_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
854 show_pwm_auto_point_channel
,
855 store_pwm_auto_point_channel
, 0, 3),
856 SENSOR_ATTR_2(pwm4_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
857 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
859 SENSOR_ATTR_2(pwm4_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
860 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
862 SENSOR_ATTR_2(pwm4_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
863 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
865 SENSOR_ATTR_2(pwm4_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
866 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
868 SENSOR_ATTR_2(pwm4_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
869 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
871 SENSOR_ATTR_2(pwm4_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
872 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
874 SENSOR_ATTR_2(pwm4_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
875 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
877 SENSOR_ATTR_2(pwm4_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
878 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
880 SENSOR_ATTR_2(pwm4_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
881 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
883 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
884 show_pwm_auto_point_temp_hyst
,
885 store_pwm_auto_point_temp_hyst
,
887 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst
, S_IRUGO
,
888 show_pwm_auto_point_temp_hyst
, NULL
, 1, 3),
889 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst
, S_IRUGO
,
890 show_pwm_auto_point_temp_hyst
, NULL
, 2, 3),
891 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst
, S_IRUGO
,
892 show_pwm_auto_point_temp_hyst
, NULL
, 3, 3),
895 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
896 static struct sensor_device_attribute_2 f8000_fan_attr
[] = {
897 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
900 /* PWM attr for the f8000, zones mapped to temp instead of to pwm!
901 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
902 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
903 static struct sensor_device_attribute_2 f8000_auto_pwm_attr
[] = {
904 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
905 show_pwm_auto_point_channel
,
906 store_pwm_auto_point_channel
, 0, 0),
907 SENSOR_ATTR_2(temp1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
908 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
910 SENSOR_ATTR_2(temp1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
911 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
913 SENSOR_ATTR_2(temp1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
914 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
916 SENSOR_ATTR_2(temp1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
917 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
919 SENSOR_ATTR_2(temp1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
920 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
922 SENSOR_ATTR_2(temp1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
923 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
925 SENSOR_ATTR_2(temp1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
926 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
928 SENSOR_ATTR_2(temp1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
929 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
931 SENSOR_ATTR_2(temp1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
932 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
934 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
935 show_pwm_auto_point_temp_hyst
,
936 store_pwm_auto_point_temp_hyst
,
938 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst
, S_IRUGO
,
939 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
940 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst
, S_IRUGO
,
941 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
942 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst
, S_IRUGO
,
943 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
945 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
946 show_pwm_auto_point_channel
,
947 store_pwm_auto_point_channel
, 0, 1),
948 SENSOR_ATTR_2(temp2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
949 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
951 SENSOR_ATTR_2(temp2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
952 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
954 SENSOR_ATTR_2(temp2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
955 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
957 SENSOR_ATTR_2(temp2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
958 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
960 SENSOR_ATTR_2(temp2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
961 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
963 SENSOR_ATTR_2(temp2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
964 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
966 SENSOR_ATTR_2(temp2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
967 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
969 SENSOR_ATTR_2(temp2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
970 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
972 SENSOR_ATTR_2(temp2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
973 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
975 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
976 show_pwm_auto_point_temp_hyst
,
977 store_pwm_auto_point_temp_hyst
,
979 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst
, S_IRUGO
,
980 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
981 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst
, S_IRUGO
,
982 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
983 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst
, S_IRUGO
,
984 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
986 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
987 show_pwm_auto_point_channel
,
988 store_pwm_auto_point_channel
, 0, 2),
989 SENSOR_ATTR_2(temp3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
990 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
992 SENSOR_ATTR_2(temp3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
993 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
995 SENSOR_ATTR_2(temp3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
996 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
998 SENSOR_ATTR_2(temp3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
999 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1001 SENSOR_ATTR_2(temp3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
1002 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
1004 SENSOR_ATTR_2(temp3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
1005 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1007 SENSOR_ATTR_2(temp3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
1008 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1010 SENSOR_ATTR_2(temp3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
1011 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1013 SENSOR_ATTR_2(temp3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
1014 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1016 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
1017 show_pwm_auto_point_temp_hyst
,
1018 store_pwm_auto_point_temp_hyst
,
1020 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst
, S_IRUGO
,
1021 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
1022 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst
, S_IRUGO
,
1023 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
1024 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst
, S_IRUGO
,
1025 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
1028 /* Super I/O functions */
1029 static inline int superio_inb(int base
, int reg
)
1032 return inb(base
+ 1);
1035 static int superio_inw(int base
, int reg
)
1038 val
= superio_inb(base
, reg
) << 8;
1039 val
|= superio_inb(base
, reg
+ 1);
1043 static inline int superio_enter(int base
)
1045 /* Don't step on other drivers' I/O space by accident */
1046 if (!request_muxed_region(base
, 2, DRVNAME
)) {
1047 pr_err("I/O address 0x%04x already in use\n", base
);
1051 /* according to the datasheet the key must be send twice! */
1052 outb(SIO_UNLOCK_KEY
, base
);
1053 outb(SIO_UNLOCK_KEY
, base
);
1058 static inline void superio_select(int base
, int ld
)
1060 outb(SIO_REG_LDSEL
, base
);
1064 static inline void superio_exit(int base
)
1066 outb(SIO_LOCK_KEY
, base
);
1067 release_region(base
, 2);
1070 static inline int fan_from_reg(u16 reg
)
1072 return reg
? (1500000 / reg
) : 0;
1075 static inline u16
fan_to_reg(int fan
)
1077 return fan
? (1500000 / fan
) : 0;
1080 static u8
f71882fg_read8(struct f71882fg_data
*data
, u8 reg
)
1084 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
1085 val
= inb(data
->addr
+ DATA_REG_OFFSET
);
1090 static u16
f71882fg_read16(struct f71882fg_data
*data
, u8 reg
)
1094 val
= f71882fg_read8(data
, reg
) << 8;
1095 val
|= f71882fg_read8(data
, reg
+ 1);
1100 static void f71882fg_write8(struct f71882fg_data
*data
, u8 reg
, u8 val
)
1102 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
1103 outb(val
, data
->addr
+ DATA_REG_OFFSET
);
1106 static void f71882fg_write16(struct f71882fg_data
*data
, u8 reg
, u16 val
)
1108 f71882fg_write8(data
, reg
, val
>> 8);
1109 f71882fg_write8(data
, reg
+ 1, val
& 0xff);
1112 static u16
f71882fg_read_temp(struct f71882fg_data
*data
, int nr
)
1114 if (data
->type
== f71858fg
)
1115 return f71882fg_read16(data
, F71882FG_REG_TEMP(nr
));
1117 return f71882fg_read8(data
, F71882FG_REG_TEMP(nr
));
1120 static struct f71882fg_data
*f71882fg_update_device(struct device
*dev
)
1122 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1123 int nr_fans
= f71882fg_nr_fans
[data
->type
];
1124 int nr_temps
= f71882fg_nr_temps
[data
->type
];
1127 mutex_lock(&data
->update_lock
);
1129 /* Update once every 60 seconds */
1130 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
) ||
1132 if (f71882fg_has_in1_alarm
[data
->type
]) {
1134 f71882fg_read8(data
, F71882FG_REG_IN1_HIGH
);
1136 f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1139 /* Get High & boundary temps*/
1140 for (nr
= data
->temp_start
; nr
< nr_temps
+ data
->temp_start
;
1142 data
->temp_ovt
[nr
] = f71882fg_read8(data
,
1143 F71882FG_REG_TEMP_OVT(nr
));
1144 data
->temp_high
[nr
] = f71882fg_read8(data
,
1145 F71882FG_REG_TEMP_HIGH(nr
));
1148 if (data
->type
!= f8000
) {
1149 data
->temp_hyst
[0] = f71882fg_read8(data
,
1150 F71882FG_REG_TEMP_HYST(0));
1151 data
->temp_hyst
[1] = f71882fg_read8(data
,
1152 F71882FG_REG_TEMP_HYST(1));
1154 /* All but the f71858fg / f8000 have this register */
1155 if ((data
->type
!= f71858fg
) && (data
->type
!= f8000
)) {
1156 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_TYPE
);
1157 data
->temp_type
[1] = (reg
& 0x02) ? 2 : 4;
1158 data
->temp_type
[2] = (reg
& 0x04) ? 2 : 4;
1159 data
->temp_type
[3] = (reg
& 0x08) ? 2 : 4;
1162 if (f71882fg_fan_has_beep
[data
->type
])
1163 data
->fan_beep
= f71882fg_read8(data
,
1164 F71882FG_REG_FAN_BEEP
);
1166 if (f71882fg_temp_has_beep
[data
->type
])
1167 data
->temp_beep
= f71882fg_read8(data
,
1168 F71882FG_REG_TEMP_BEEP
);
1170 data
->pwm_enable
= f71882fg_read8(data
,
1171 F71882FG_REG_PWM_ENABLE
);
1172 data
->pwm_auto_point_hyst
[0] =
1173 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(0));
1174 data
->pwm_auto_point_hyst
[1] =
1175 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(1));
1177 for (nr
= 0; nr
< nr_fans
; nr
++) {
1178 data
->pwm_auto_point_mapping
[nr
] =
1179 f71882fg_read8(data
,
1180 F71882FG_REG_POINT_MAPPING(nr
));
1182 switch (data
->type
) {
1184 for (point
= 0; point
< 5; point
++) {
1185 data
->pwm_auto_point_pwm
[nr
][point
] =
1186 f71882fg_read8(data
,
1187 F71882FG_REG_POINT_PWM
1190 for (point
= 0; point
< 4; point
++) {
1191 data
->pwm_auto_point_temp
[nr
][point
] =
1192 f71882fg_read8(data
,
1193 F71882FG_REG_POINT_TEMP
1199 data
->pwm_auto_point_pwm
[nr
][0] =
1200 f71882fg_read8(data
,
1201 F71882FG_REG_POINT_PWM(nr
, 0));
1204 data
->pwm_auto_point_pwm
[nr
][1] =
1205 f71882fg_read8(data
,
1206 F71882FG_REG_POINT_PWM
1208 data
->pwm_auto_point_pwm
[nr
][4] =
1209 f71882fg_read8(data
,
1210 F71882FG_REG_POINT_PWM
1212 data
->pwm_auto_point_temp
[nr
][0] =
1213 f71882fg_read8(data
,
1214 F71882FG_REG_POINT_TEMP
1216 data
->pwm_auto_point_temp
[nr
][3] =
1217 f71882fg_read8(data
,
1218 F71882FG_REG_POINT_TEMP
1223 data
->last_limits
= jiffies
;
1226 /* Update every second */
1227 if (time_after(jiffies
, data
->last_updated
+ HZ
) || !data
->valid
) {
1228 data
->temp_status
= f71882fg_read8(data
,
1229 F71882FG_REG_TEMP_STATUS
);
1230 data
->temp_diode_open
= f71882fg_read8(data
,
1231 F71882FG_REG_TEMP_DIODE_OPEN
);
1232 for (nr
= data
->temp_start
; nr
< nr_temps
+ data
->temp_start
;
1234 data
->temp
[nr
] = f71882fg_read_temp(data
, nr
);
1236 data
->fan_status
= f71882fg_read8(data
,
1237 F71882FG_REG_FAN_STATUS
);
1238 for (nr
= 0; nr
< nr_fans
; nr
++) {
1239 data
->fan
[nr
] = f71882fg_read16(data
,
1240 F71882FG_REG_FAN(nr
));
1241 data
->fan_target
[nr
] =
1242 f71882fg_read16(data
, F71882FG_REG_FAN_TARGET(nr
));
1243 data
->fan_full_speed
[nr
] =
1244 f71882fg_read16(data
,
1245 F71882FG_REG_FAN_FULL_SPEED(nr
));
1247 f71882fg_read8(data
, F71882FG_REG_PWM(nr
));
1249 /* The f8000 can monitor 1 more fan, but has no pwm for it */
1250 if (data
->type
== f8000
)
1251 data
->fan
[3] = f71882fg_read16(data
,
1252 F71882FG_REG_FAN(3));
1254 if (f71882fg_has_in1_alarm
[data
->type
])
1255 data
->in_status
= f71882fg_read8(data
,
1256 F71882FG_REG_IN_STATUS
);
1257 for (nr
= 0; nr
< F71882FG_MAX_INS
; nr
++)
1258 if (f71882fg_has_in
[data
->type
][nr
])
1259 data
->in
[nr
] = f71882fg_read8(data
,
1260 F71882FG_REG_IN(nr
));
1262 data
->last_updated
= jiffies
;
1266 mutex_unlock(&data
->update_lock
);
1271 /* Sysfs Interface */
1272 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
1275 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1276 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1277 int speed
= fan_from_reg(data
->fan
[nr
]);
1279 if (speed
== FAN_MIN_DETECT
)
1282 return sprintf(buf
, "%d\n", speed
);
1285 static ssize_t
show_fan_full_speed(struct device
*dev
,
1286 struct device_attribute
*devattr
, char *buf
)
1288 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1289 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1290 int speed
= fan_from_reg(data
->fan_full_speed
[nr
]);
1291 return sprintf(buf
, "%d\n", speed
);
1294 static ssize_t
store_fan_full_speed(struct device
*dev
,
1295 struct device_attribute
*devattr
,
1296 const char *buf
, size_t count
)
1298 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1299 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1302 err
= strict_strtol(buf
, 10, &val
);
1306 val
= SENSORS_LIMIT(val
, 23, 1500000);
1307 val
= fan_to_reg(val
);
1309 mutex_lock(&data
->update_lock
);
1310 f71882fg_write16(data
, F71882FG_REG_FAN_FULL_SPEED(nr
), val
);
1311 data
->fan_full_speed
[nr
] = val
;
1312 mutex_unlock(&data
->update_lock
);
1317 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
1318 *devattr
, char *buf
)
1320 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1321 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1323 if (data
->fan_beep
& (1 << nr
))
1324 return sprintf(buf
, "1\n");
1326 return sprintf(buf
, "0\n");
1329 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
1330 *devattr
, const char *buf
, size_t count
)
1332 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1333 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1336 err
= strict_strtoul(buf
, 10, &val
);
1340 mutex_lock(&data
->update_lock
);
1341 data
->fan_beep
= f71882fg_read8(data
, F71882FG_REG_FAN_BEEP
);
1343 data
->fan_beep
|= 1 << nr
;
1345 data
->fan_beep
&= ~(1 << nr
);
1347 f71882fg_write8(data
, F71882FG_REG_FAN_BEEP
, data
->fan_beep
);
1348 mutex_unlock(&data
->update_lock
);
1353 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
1354 *devattr
, char *buf
)
1356 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1357 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1359 if (data
->fan_status
& (1 << nr
))
1360 return sprintf(buf
, "1\n");
1362 return sprintf(buf
, "0\n");
1365 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
1368 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1369 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1371 return sprintf(buf
, "%d\n", data
->in
[nr
] * 8);
1374 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
1375 *devattr
, char *buf
)
1377 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1379 return sprintf(buf
, "%d\n", data
->in1_max
* 8);
1382 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
1383 *devattr
, const char *buf
, size_t count
)
1385 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1389 err
= strict_strtol(buf
, 10, &val
);
1394 val
= SENSORS_LIMIT(val
, 0, 255);
1396 mutex_lock(&data
->update_lock
);
1397 f71882fg_write8(data
, F71882FG_REG_IN1_HIGH
, val
);
1398 data
->in1_max
= val
;
1399 mutex_unlock(&data
->update_lock
);
1404 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
1405 *devattr
, char *buf
)
1407 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1408 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1410 if (data
->in_beep
& (1 << nr
))
1411 return sprintf(buf
, "1\n");
1413 return sprintf(buf
, "0\n");
1416 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
1417 *devattr
, const char *buf
, size_t count
)
1419 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1420 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1423 err
= strict_strtoul(buf
, 10, &val
);
1427 mutex_lock(&data
->update_lock
);
1428 data
->in_beep
= f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1430 data
->in_beep
|= 1 << nr
;
1432 data
->in_beep
&= ~(1 << nr
);
1434 f71882fg_write8(data
, F71882FG_REG_IN_BEEP
, data
->in_beep
);
1435 mutex_unlock(&data
->update_lock
);
1440 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
1441 *devattr
, char *buf
)
1443 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1444 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1446 if (data
->in_status
& (1 << nr
))
1447 return sprintf(buf
, "1\n");
1449 return sprintf(buf
, "0\n");
1452 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*devattr
,
1455 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1456 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1459 if (data
->type
== f71858fg
) {
1460 /* TEMP_TABLE_SEL 1 or 3 ? */
1461 if (data
->temp_config
& 1) {
1462 sign
= data
->temp
[nr
] & 0x0001;
1463 temp
= (data
->temp
[nr
] >> 5) & 0x7ff;
1465 sign
= data
->temp
[nr
] & 0x8000;
1466 temp
= (data
->temp
[nr
] >> 5) & 0x3ff;
1472 temp
= data
->temp
[nr
] * 1000;
1474 return sprintf(buf
, "%d\n", temp
);
1477 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
1478 *devattr
, char *buf
)
1480 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1481 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1483 return sprintf(buf
, "%d\n", data
->temp_high
[nr
] * 1000);
1486 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
1487 *devattr
, const char *buf
, size_t count
)
1489 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1490 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1493 err
= strict_strtol(buf
, 10, &val
);
1498 val
= SENSORS_LIMIT(val
, 0, 255);
1500 mutex_lock(&data
->update_lock
);
1501 f71882fg_write8(data
, F71882FG_REG_TEMP_HIGH(nr
), val
);
1502 data
->temp_high
[nr
] = val
;
1503 mutex_unlock(&data
->update_lock
);
1508 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
1509 *devattr
, char *buf
)
1511 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1512 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1515 mutex_lock(&data
->update_lock
);
1517 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1519 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1520 temp_max_hyst
= (data
->temp_high
[nr
] - temp_max_hyst
) * 1000;
1521 mutex_unlock(&data
->update_lock
);
1523 return sprintf(buf
, "%d\n", temp_max_hyst
);
1526 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
1527 *devattr
, const char *buf
, size_t count
)
1529 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1530 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1531 ssize_t ret
= count
;
1535 err
= strict_strtol(buf
, 10, &val
);
1541 mutex_lock(&data
->update_lock
);
1543 /* convert abs to relative and check */
1544 data
->temp_high
[nr
] = f71882fg_read8(data
, F71882FG_REG_TEMP_HIGH(nr
));
1545 val
= SENSORS_LIMIT(val
, data
->temp_high
[nr
] - 15,
1546 data
->temp_high
[nr
]);
1547 val
= data
->temp_high
[nr
] - val
;
1549 /* convert value to register contents */
1550 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2));
1552 reg
= (reg
& 0x0f) | (val
<< 4);
1554 reg
= (reg
& 0xf0) | val
;
1555 f71882fg_write8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2), reg
);
1556 data
->temp_hyst
[nr
/ 2] = reg
;
1558 mutex_unlock(&data
->update_lock
);
1562 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
1563 *devattr
, char *buf
)
1565 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1566 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1568 return sprintf(buf
, "%d\n", data
->temp_ovt
[nr
] * 1000);
1571 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
1572 *devattr
, const char *buf
, size_t count
)
1574 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1575 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1578 err
= strict_strtol(buf
, 10, &val
);
1583 val
= SENSORS_LIMIT(val
, 0, 255);
1585 mutex_lock(&data
->update_lock
);
1586 f71882fg_write8(data
, F71882FG_REG_TEMP_OVT(nr
), val
);
1587 data
->temp_ovt
[nr
] = val
;
1588 mutex_unlock(&data
->update_lock
);
1593 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
1594 *devattr
, char *buf
)
1596 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1597 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1600 mutex_lock(&data
->update_lock
);
1602 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1604 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1605 temp_crit_hyst
= (data
->temp_ovt
[nr
] - temp_crit_hyst
) * 1000;
1606 mutex_unlock(&data
->update_lock
);
1608 return sprintf(buf
, "%d\n", temp_crit_hyst
);
1611 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
1612 *devattr
, char *buf
)
1614 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1615 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1617 return sprintf(buf
, "%d\n", data
->temp_type
[nr
]);
1620 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
1621 *devattr
, char *buf
)
1623 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1624 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1626 if (data
->temp_beep
& (1 << nr
))
1627 return sprintf(buf
, "1\n");
1629 return sprintf(buf
, "0\n");
1632 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
1633 *devattr
, const char *buf
, size_t count
)
1635 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1636 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1639 err
= strict_strtoul(buf
, 10, &val
);
1643 mutex_lock(&data
->update_lock
);
1644 data
->temp_beep
= f71882fg_read8(data
, F71882FG_REG_TEMP_BEEP
);
1646 data
->temp_beep
|= 1 << nr
;
1648 data
->temp_beep
&= ~(1 << nr
);
1650 f71882fg_write8(data
, F71882FG_REG_TEMP_BEEP
, data
->temp_beep
);
1651 mutex_unlock(&data
->update_lock
);
1656 static ssize_t
show_temp_alarm(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 if (data
->temp_status
& (1 << nr
))
1663 return sprintf(buf
, "1\n");
1665 return sprintf(buf
, "0\n");
1668 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
1669 *devattr
, char *buf
)
1671 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1672 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1674 if (data
->temp_diode_open
& (1 << nr
))
1675 return sprintf(buf
, "1\n");
1677 return sprintf(buf
, "0\n");
1680 static ssize_t
show_pwm(struct device
*dev
,
1681 struct device_attribute
*devattr
, char *buf
)
1683 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1684 int val
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1685 mutex_lock(&data
->update_lock
);
1686 if (data
->pwm_enable
& (1 << (2 * nr
)))
1688 val
= data
->pwm
[nr
];
1691 val
= 255 * fan_from_reg(data
->fan_target
[nr
])
1692 / fan_from_reg(data
->fan_full_speed
[nr
]);
1694 mutex_unlock(&data
->update_lock
);
1695 return sprintf(buf
, "%d\n", val
);
1698 static ssize_t
store_pwm(struct device
*dev
,
1699 struct device_attribute
*devattr
, const char *buf
,
1702 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1703 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1706 err
= strict_strtol(buf
, 10, &val
);
1710 val
= SENSORS_LIMIT(val
, 0, 255);
1712 mutex_lock(&data
->update_lock
);
1713 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1714 if ((data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 3) != 2) ||
1715 (data
->type
!= f8000
&& !((data
->pwm_enable
>> 2 * nr
) & 2))) {
1719 if (data
->pwm_enable
& (1 << (2 * nr
))) {
1721 f71882fg_write8(data
, F71882FG_REG_PWM(nr
), val
);
1722 data
->pwm
[nr
] = val
;
1725 int target
, full_speed
;
1726 full_speed
= f71882fg_read16(data
,
1727 F71882FG_REG_FAN_FULL_SPEED(nr
));
1728 target
= fan_to_reg(val
* fan_from_reg(full_speed
) / 255);
1729 f71882fg_write16(data
, F71882FG_REG_FAN_TARGET(nr
), target
);
1730 data
->fan_target
[nr
] = target
;
1731 data
->fan_full_speed
[nr
] = full_speed
;
1734 mutex_unlock(&data
->update_lock
);
1739 static ssize_t
show_pwm_enable(struct device
*dev
,
1740 struct device_attribute
*devattr
, char *buf
)
1743 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1744 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1746 switch ((data
->pwm_enable
>> 2 * nr
) & 3) {
1749 result
= 2; /* Normal auto mode */
1752 result
= 1; /* Manual mode */
1755 if (data
->type
== f8000
)
1756 result
= 3; /* Thermostat mode */
1758 result
= 1; /* Manual mode */
1762 return sprintf(buf
, "%d\n", result
);
1765 static ssize_t
store_pwm_enable(struct device
*dev
, struct device_attribute
1766 *devattr
, const char *buf
, size_t count
)
1768 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1769 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1772 err
= strict_strtol(buf
, 10, &val
);
1776 /* Special case for F8000 pwm channel 3 which only does auto mode */
1777 if (data
->type
== f8000
&& nr
== 2 && val
!= 2)
1780 mutex_lock(&data
->update_lock
);
1781 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1782 /* Special case for F8000 auto PWM mode / Thermostat mode */
1783 if (data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 1)) {
1786 data
->pwm_enable
&= ~(2 << (2 * nr
));
1787 break; /* Normal auto mode */
1789 data
->pwm_enable
|= 2 << (2 * nr
);
1790 break; /* Thermostat mode */
1798 /* The f71858fg does not support manual RPM mode */
1799 if (data
->type
== f71858fg
&&
1800 ((data
->pwm_enable
>> (2 * nr
)) & 1)) {
1804 data
->pwm_enable
|= 2 << (2 * nr
);
1807 data
->pwm_enable
&= ~(2 << (2 * nr
));
1808 break; /* Normal auto mode */
1814 f71882fg_write8(data
, F71882FG_REG_PWM_ENABLE
, data
->pwm_enable
);
1816 mutex_unlock(&data
->update_lock
);
1821 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
1822 struct device_attribute
*devattr
,
1826 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1827 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1828 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1830 mutex_lock(&data
->update_lock
);
1831 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1833 result
= data
->pwm_auto_point_pwm
[pwm
][point
];
1836 result
= 32 * 255 / (32 + data
->pwm_auto_point_pwm
[pwm
][point
]);
1838 mutex_unlock(&data
->update_lock
);
1840 return sprintf(buf
, "%d\n", result
);
1843 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
1844 struct device_attribute
*devattr
,
1845 const char *buf
, size_t count
)
1847 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1848 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1849 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1852 err
= strict_strtol(buf
, 10, &val
);
1856 val
= SENSORS_LIMIT(val
, 0, 255);
1858 mutex_lock(&data
->update_lock
);
1859 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1860 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1864 if (val
< 29) /* Prevent negative numbers */
1867 val
= (255 - val
) * 32 / val
;
1869 f71882fg_write8(data
, F71882FG_REG_POINT_PWM(pwm
, point
), val
);
1870 data
->pwm_auto_point_pwm
[pwm
][point
] = val
;
1871 mutex_unlock(&data
->update_lock
);
1876 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
1877 struct device_attribute
*devattr
,
1881 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1882 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1883 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1885 mutex_lock(&data
->update_lock
);
1887 result
= data
->pwm_auto_point_hyst
[nr
/ 2] >> 4;
1889 result
= data
->pwm_auto_point_hyst
[nr
/ 2] & 0x0f;
1890 result
= 1000 * (data
->pwm_auto_point_temp
[nr
][point
] - result
);
1891 mutex_unlock(&data
->update_lock
);
1893 return sprintf(buf
, "%d\n", result
);
1896 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
1897 struct device_attribute
*devattr
,
1898 const char *buf
, size_t count
)
1900 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1901 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1902 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1906 err
= strict_strtol(buf
, 10, &val
);
1912 mutex_lock(&data
->update_lock
);
1913 data
->pwm_auto_point_temp
[nr
][point
] =
1914 f71882fg_read8(data
, F71882FG_REG_POINT_TEMP(nr
, point
));
1915 val
= SENSORS_LIMIT(val
, data
->pwm_auto_point_temp
[nr
][point
] - 15,
1916 data
->pwm_auto_point_temp
[nr
][point
]);
1917 val
= data
->pwm_auto_point_temp
[nr
][point
] - val
;
1919 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_HYST(nr
/ 2));
1921 reg
= (reg
& 0x0f) | (val
<< 4);
1923 reg
= (reg
& 0xf0) | val
;
1925 f71882fg_write8(data
, F71882FG_REG_FAN_HYST(nr
/ 2), reg
);
1926 data
->pwm_auto_point_hyst
[nr
/ 2] = reg
;
1927 mutex_unlock(&data
->update_lock
);
1932 static ssize_t
show_pwm_interpolate(struct device
*dev
,
1933 struct device_attribute
*devattr
, char *buf
)
1936 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1937 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1939 result
= (data
->pwm_auto_point_mapping
[nr
] >> 4) & 1;
1941 return sprintf(buf
, "%d\n", result
);
1944 static ssize_t
store_pwm_interpolate(struct device
*dev
,
1945 struct device_attribute
*devattr
,
1946 const char *buf
, size_t count
)
1948 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1949 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1952 err
= strict_strtoul(buf
, 10, &val
);
1956 mutex_lock(&data
->update_lock
);
1957 data
->pwm_auto_point_mapping
[nr
] =
1958 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
1960 val
= data
->pwm_auto_point_mapping
[nr
] | (1 << 4);
1962 val
= data
->pwm_auto_point_mapping
[nr
] & (~(1 << 4));
1963 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
1964 data
->pwm_auto_point_mapping
[nr
] = val
;
1965 mutex_unlock(&data
->update_lock
);
1970 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
1971 struct device_attribute
*devattr
,
1975 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1976 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1978 result
= 1 << ((data
->pwm_auto_point_mapping
[nr
] & 3) -
1981 return sprintf(buf
, "%d\n", result
);
1984 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
1985 struct device_attribute
*devattr
,
1986 const char *buf
, size_t count
)
1988 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1989 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1992 err
= strict_strtol(buf
, 10, &val
);
2009 val
+= data
->temp_start
;
2010 mutex_lock(&data
->update_lock
);
2011 data
->pwm_auto_point_mapping
[nr
] =
2012 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
2013 val
= (data
->pwm_auto_point_mapping
[nr
] & 0xfc) | val
;
2014 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
2015 data
->pwm_auto_point_mapping
[nr
] = val
;
2016 mutex_unlock(&data
->update_lock
);
2021 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
2022 struct device_attribute
*devattr
,
2026 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
2027 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
2028 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
2030 result
= data
->pwm_auto_point_temp
[pwm
][point
];
2031 return sprintf(buf
, "%d\n", 1000 * result
);
2034 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
2035 struct device_attribute
*devattr
,
2036 const char *buf
, size_t count
)
2038 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2039 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
2040 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
2043 err
= strict_strtol(buf
, 10, &val
);
2049 if (data
->auto_point_temp_signed
)
2050 val
= SENSORS_LIMIT(val
, -128, 127);
2052 val
= SENSORS_LIMIT(val
, 0, 127);
2054 mutex_lock(&data
->update_lock
);
2055 f71882fg_write8(data
, F71882FG_REG_POINT_TEMP(pwm
, point
), val
);
2056 data
->pwm_auto_point_temp
[pwm
][point
] = val
;
2057 mutex_unlock(&data
->update_lock
);
2062 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
2065 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2066 return sprintf(buf
, "%s\n", f71882fg_names
[data
->type
]);
2069 static int __devinit
f71882fg_create_sysfs_files(struct platform_device
*pdev
,
2070 struct sensor_device_attribute_2
*attr
, int count
)
2074 for (i
= 0; i
< count
; i
++) {
2075 err
= device_create_file(&pdev
->dev
, &attr
[i
].dev_attr
);
2082 static void f71882fg_remove_sysfs_files(struct platform_device
*pdev
,
2083 struct sensor_device_attribute_2
*attr
, int count
)
2087 for (i
= 0; i
< count
; i
++)
2088 device_remove_file(&pdev
->dev
, &attr
[i
].dev_attr
);
2091 static int __devinit
f71882fg_probe(struct platform_device
*pdev
)
2093 struct f71882fg_data
*data
;
2094 struct f71882fg_sio_data
*sio_data
= pdev
->dev
.platform_data
;
2095 int nr_fans
= f71882fg_nr_fans
[sio_data
->type
];
2096 int nr_temps
= f71882fg_nr_temps
[sio_data
->type
];
2100 data
= kzalloc(sizeof(struct f71882fg_data
), GFP_KERNEL
);
2104 data
->addr
= platform_get_resource(pdev
, IORESOURCE_IO
, 0)->start
;
2105 data
->type
= sio_data
->type
;
2107 (data
->type
== f71858fg
|| data
->type
== f8000
) ? 0 : 1;
2108 mutex_init(&data
->update_lock
);
2109 platform_set_drvdata(pdev
, data
);
2111 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2112 if (start_reg
& 0x04) {
2113 dev_warn(&pdev
->dev
, "Hardware monitor is powered down\n");
2117 if (!(start_reg
& 0x03)) {
2118 dev_warn(&pdev
->dev
, "Hardware monitoring not activated\n");
2123 /* Register sysfs interface files */
2124 err
= device_create_file(&pdev
->dev
, &dev_attr_name
);
2126 goto exit_unregister_sysfs
;
2128 if (start_reg
& 0x01) {
2129 switch (data
->type
) {
2132 f71882fg_read8(data
, F71882FG_REG_TEMP_CONFIG
);
2133 if (data
->temp_config
& 0x10)
2134 /* The f71858fg temperature alarms behave as
2135 the f8000 alarms in this mode */
2136 err
= f71882fg_create_sysfs_files(pdev
,
2138 ARRAY_SIZE(f8000_temp_attr
));
2140 err
= f71882fg_create_sysfs_files(pdev
,
2142 ARRAY_SIZE(f71858fg_temp_attr
));
2145 err
= f71882fg_create_sysfs_files(pdev
,
2147 ARRAY_SIZE(f8000_temp_attr
));
2150 err
= f71882fg_create_sysfs_files(pdev
,
2151 &fxxxx_temp_attr
[0][0],
2152 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2155 goto exit_unregister_sysfs
;
2157 if (f71882fg_temp_has_beep
[data
->type
]) {
2158 err
= f71882fg_create_sysfs_files(pdev
,
2159 &fxxxx_temp_beep_attr
[0][0],
2160 ARRAY_SIZE(fxxxx_temp_beep_attr
[0])
2163 goto exit_unregister_sysfs
;
2166 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2167 if (f71882fg_has_in
[data
->type
][i
]) {
2168 err
= device_create_file(&pdev
->dev
,
2169 &fxxxx_in_attr
[i
].dev_attr
);
2171 goto exit_unregister_sysfs
;
2174 if (f71882fg_has_in1_alarm
[data
->type
]) {
2175 err
= f71882fg_create_sysfs_files(pdev
,
2176 fxxxx_in1_alarm_attr
,
2177 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2179 goto exit_unregister_sysfs
;
2183 if (start_reg
& 0x02) {
2184 switch (data
->type
) {
2187 /* These always have signed auto point temps */
2188 data
->auto_point_temp_signed
= 1;
2189 /* Fall through to select correct fan/pwm reg bank! */
2193 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_FAULT_T
);
2194 if (reg
& F71882FG_FAN_NEG_TEMP_EN
)
2195 data
->auto_point_temp_signed
= 1;
2196 /* Ensure banked pwm registers point to right bank */
2197 reg
&= ~F71882FG_FAN_PROG_SEL
;
2198 f71882fg_write8(data
, F71882FG_REG_FAN_FAULT_T
, reg
);
2205 f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
2207 /* Sanity check the pwm settings */
2208 switch (data
->type
) {
2211 for (i
= 0; i
< nr_fans
; i
++)
2212 if (((data
->pwm_enable
>> (i
* 2)) & 3) == 3)
2216 err
= (data
->pwm_enable
& 0x15) != 0x15;
2219 err
= data
->pwm_enable
& 0x20;
2227 "Invalid (reserved) pwm settings: 0x%02x\n",
2228 (unsigned int)data
->pwm_enable
);
2230 goto exit_unregister_sysfs
;
2233 err
= f71882fg_create_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2234 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2236 goto exit_unregister_sysfs
;
2238 if (f71882fg_fan_has_beep
[data
->type
]) {
2239 err
= f71882fg_create_sysfs_files(pdev
,
2240 fxxxx_fan_beep_attr
, nr_fans
);
2242 goto exit_unregister_sysfs
;
2245 switch (data
->type
) {
2251 for (i
= 0; i
< nr_fans
; i
++) {
2252 data
->pwm_auto_point_mapping
[i
] =
2253 f71882fg_read8(data
,
2254 F71882FG_REG_POINT_MAPPING(i
));
2255 if ((data
->pwm_auto_point_mapping
[i
] & 0x80) ||
2256 (data
->pwm_auto_point_mapping
[i
] & 3) == 0)
2260 dev_warn(&pdev
->dev
,
2261 "Auto pwm controlled by raw digital "
2262 "data, disabling pwm auto_point "
2263 "sysfs attributes\n");
2264 goto no_pwm_auto_point
;
2271 switch (data
->type
) {
2273 err
= f71882fg_create_sysfs_files(pdev
,
2274 f71862fg_auto_pwm_attr
,
2275 ARRAY_SIZE(f71862fg_auto_pwm_attr
));
2279 err
= f71882fg_create_sysfs_files(pdev
,
2280 f71869_auto_pwm_attr
,
2281 ARRAY_SIZE(f71869_auto_pwm_attr
));
2284 err
= f71882fg_create_sysfs_files(pdev
,
2286 ARRAY_SIZE(f8000_fan_attr
));
2288 goto exit_unregister_sysfs
;
2289 err
= f71882fg_create_sysfs_files(pdev
,
2290 f8000_auto_pwm_attr
,
2291 ARRAY_SIZE(f8000_auto_pwm_attr
));
2294 err
= f71882fg_create_sysfs_files(pdev
,
2295 &fxxxx_auto_pwm_attr
[0][0],
2296 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2299 goto exit_unregister_sysfs
;
2302 for (i
= 0; i
< nr_fans
; i
++)
2303 dev_info(&pdev
->dev
, "Fan: %d is in %s mode\n", i
+ 1,
2304 (data
->pwm_enable
& (1 << 2 * i
)) ?
2305 "duty-cycle" : "RPM");
2308 data
->hwmon_dev
= hwmon_device_register(&pdev
->dev
);
2309 if (IS_ERR(data
->hwmon_dev
)) {
2310 err
= PTR_ERR(data
->hwmon_dev
);
2311 data
->hwmon_dev
= NULL
;
2312 goto exit_unregister_sysfs
;
2317 exit_unregister_sysfs
:
2318 f71882fg_remove(pdev
); /* Will unregister the sysfs files for us */
2319 return err
; /* f71882fg_remove() also frees our data */
2325 static int f71882fg_remove(struct platform_device
*pdev
)
2327 struct f71882fg_data
*data
= platform_get_drvdata(pdev
);
2328 int nr_fans
= f71882fg_nr_fans
[data
->type
];
2329 int nr_temps
= f71882fg_nr_temps
[data
->type
];
2331 u8 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2333 if (data
->hwmon_dev
)
2334 hwmon_device_unregister(data
->hwmon_dev
);
2336 device_remove_file(&pdev
->dev
, &dev_attr_name
);
2338 if (start_reg
& 0x01) {
2339 switch (data
->type
) {
2341 if (data
->temp_config
& 0x10)
2342 f71882fg_remove_sysfs_files(pdev
,
2344 ARRAY_SIZE(f8000_temp_attr
));
2346 f71882fg_remove_sysfs_files(pdev
,
2348 ARRAY_SIZE(f71858fg_temp_attr
));
2351 f71882fg_remove_sysfs_files(pdev
,
2353 ARRAY_SIZE(f8000_temp_attr
));
2356 f71882fg_remove_sysfs_files(pdev
,
2357 &fxxxx_temp_attr
[0][0],
2358 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2360 if (f71882fg_temp_has_beep
[data
->type
]) {
2361 f71882fg_remove_sysfs_files(pdev
,
2362 &fxxxx_temp_beep_attr
[0][0],
2363 ARRAY_SIZE(fxxxx_temp_beep_attr
[0]) * nr_temps
);
2366 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2367 if (f71882fg_has_in
[data
->type
][i
]) {
2368 device_remove_file(&pdev
->dev
,
2369 &fxxxx_in_attr
[i
].dev_attr
);
2372 if (f71882fg_has_in1_alarm
[data
->type
]) {
2373 f71882fg_remove_sysfs_files(pdev
,
2374 fxxxx_in1_alarm_attr
,
2375 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2379 if (start_reg
& 0x02) {
2380 f71882fg_remove_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2381 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2383 if (f71882fg_fan_has_beep
[data
->type
]) {
2384 f71882fg_remove_sysfs_files(pdev
,
2385 fxxxx_fan_beep_attr
, nr_fans
);
2388 switch (data
->type
) {
2390 f71882fg_remove_sysfs_files(pdev
,
2391 f71862fg_auto_pwm_attr
,
2392 ARRAY_SIZE(f71862fg_auto_pwm_attr
));
2396 f71882fg_remove_sysfs_files(pdev
,
2397 f71869_auto_pwm_attr
,
2398 ARRAY_SIZE(f71869_auto_pwm_attr
));
2401 f71882fg_remove_sysfs_files(pdev
,
2403 ARRAY_SIZE(f8000_fan_attr
));
2404 f71882fg_remove_sysfs_files(pdev
,
2405 f8000_auto_pwm_attr
,
2406 ARRAY_SIZE(f8000_auto_pwm_attr
));
2409 f71882fg_remove_sysfs_files(pdev
,
2410 &fxxxx_auto_pwm_attr
[0][0],
2411 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2415 platform_set_drvdata(pdev
, NULL
);
2421 static int __init
f71882fg_find(int sioaddr
, unsigned short *address
,
2422 struct f71882fg_sio_data
*sio_data
)
2425 int err
= superio_enter(sioaddr
);
2429 devid
= superio_inw(sioaddr
, SIO_REG_MANID
);
2430 if (devid
!= SIO_FINTEK_ID
) {
2431 pr_debug("Not a Fintek device\n");
2436 devid
= force_id
? force_id
: superio_inw(sioaddr
, SIO_REG_DEVID
);
2438 case SIO_F71808E_ID
:
2439 sio_data
->type
= f71808e
;
2442 sio_data
->type
= f71858fg
;
2445 sio_data
->type
= f71862fg
;
2448 sio_data
->type
= f71869
;
2451 sio_data
->type
= f71882fg
;
2454 sio_data
->type
= f71889fg
;
2456 case SIO_F71889E_ID
:
2457 sio_data
->type
= f71889ed
;
2459 case SIO_F71889A_ID
:
2460 sio_data
->type
= f71889a
;
2463 sio_data
->type
= f8000
;
2466 sio_data
->type
= f81865f
;
2469 pr_info("Unsupported Fintek device: %04x\n",
2470 (unsigned int)devid
);
2475 if (sio_data
->type
== f71858fg
)
2476 superio_select(sioaddr
, SIO_F71858FG_LD_HWM
);
2478 superio_select(sioaddr
, SIO_F71882FG_LD_HWM
);
2480 if (!(superio_inb(sioaddr
, SIO_REG_ENABLE
) & 0x01)) {
2481 pr_warn("Device not activated\n");
2486 *address
= superio_inw(sioaddr
, SIO_REG_ADDR
);
2487 if (*address
== 0) {
2488 pr_warn("Base address not set\n");
2492 *address
&= ~(REGION_LENGTH
- 1); /* Ignore 3 LSB */
2495 pr_info("Found %s chip at %#x, revision %d\n",
2496 f71882fg_names
[sio_data
->type
], (unsigned int)*address
,
2497 (int)superio_inb(sioaddr
, SIO_REG_DEVREV
));
2499 superio_exit(sioaddr
);
2503 static int __init
f71882fg_device_add(unsigned short address
,
2504 const struct f71882fg_sio_data
*sio_data
)
2506 struct resource res
= {
2508 .end
= address
+ REGION_LENGTH
- 1,
2509 .flags
= IORESOURCE_IO
,
2513 f71882fg_pdev
= platform_device_alloc(DRVNAME
, address
);
2517 res
.name
= f71882fg_pdev
->name
;
2518 err
= acpi_check_resource_conflict(&res
);
2520 goto exit_device_put
;
2522 err
= platform_device_add_resources(f71882fg_pdev
, &res
, 1);
2524 pr_err("Device resource addition failed\n");
2525 goto exit_device_put
;
2528 err
= platform_device_add_data(f71882fg_pdev
, sio_data
,
2529 sizeof(struct f71882fg_sio_data
));
2531 pr_err("Platform data allocation failed\n");
2532 goto exit_device_put
;
2535 err
= platform_device_add(f71882fg_pdev
);
2537 pr_err("Device addition failed\n");
2538 goto exit_device_put
;
2544 platform_device_put(f71882fg_pdev
);
2549 static int __init
f71882fg_init(void)
2552 unsigned short address
;
2553 struct f71882fg_sio_data sio_data
;
2555 memset(&sio_data
, 0, sizeof(sio_data
));
2557 if (f71882fg_find(0x2e, &address
, &sio_data
) &&
2558 f71882fg_find(0x4e, &address
, &sio_data
))
2561 err
= platform_driver_register(&f71882fg_driver
);
2565 err
= f71882fg_device_add(address
, &sio_data
);
2572 platform_driver_unregister(&f71882fg_driver
);
2577 static void __exit
f71882fg_exit(void)
2579 platform_device_unregister(f71882fg_pdev
);
2580 platform_driver_unregister(&f71882fg_driver
);
2583 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2584 MODULE_AUTHOR("Hans Edgington, Hans de Goede (hdegoede@redhat.com)");
2585 MODULE_LICENSE("GPL");
2587 module_init(f71882fg_init
);
2588 module_exit(f71882fg_exit
);