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_has_beep
[] = {
165 static const char f71882fg_nr_fans
[] = {
178 static const char f71882fg_nr_temps
[] = {
191 static struct platform_device
*f71882fg_pdev
;
193 /* Super-I/O Function prototypes */
194 static inline int superio_inb(int base
, int reg
);
195 static inline int superio_inw(int base
, int reg
);
196 static inline int superio_enter(int base
);
197 static inline void superio_select(int base
, int ld
);
198 static inline void superio_exit(int base
);
200 struct f71882fg_sio_data
{
204 struct f71882fg_data
{
207 struct device
*hwmon_dev
;
209 struct mutex update_lock
;
210 int temp_start
; /* temp numbering start (0 or 1) */
211 char valid
; /* !=0 if following fields are valid */
212 char auto_point_temp_signed
;
213 unsigned long last_updated
; /* In jiffies */
214 unsigned long last_limits
; /* In jiffies */
216 /* Register Values */
217 u8 in
[F71882FG_MAX_INS
];
223 u16 fan_full_speed
[4];
226 /* Note: all models have max 3 temperature channels, but on some
227 they are addressed as 0-2 and on others as 1-3, so for coding
228 convenience we reserve space for 4 channels */
232 u8 temp_hyst
[2]; /* 2 hysts stored per reg */
240 u8 pwm_auto_point_hyst
[2];
241 u8 pwm_auto_point_mapping
[4];
242 u8 pwm_auto_point_pwm
[4][5];
243 s8 pwm_auto_point_temp
[4][4];
247 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
249 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
250 *devattr
, char *buf
);
251 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
252 *devattr
, const char *buf
, size_t count
);
253 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
254 *devattr
, char *buf
);
255 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
256 *devattr
, const char *buf
, size_t count
);
257 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
258 *devattr
, char *buf
);
260 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
262 static ssize_t
show_fan_full_speed(struct device
*dev
,
263 struct device_attribute
*devattr
, char *buf
);
264 static ssize_t
store_fan_full_speed(struct device
*dev
,
265 struct device_attribute
*devattr
, const char *buf
, size_t count
);
266 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
267 *devattr
, char *buf
);
268 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
269 *devattr
, const char *buf
, size_t count
);
270 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
271 *devattr
, char *buf
);
273 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
274 *devattr
, char *buf
);
275 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
276 *devattr
, char *buf
);
277 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
278 *devattr
, const char *buf
, size_t count
);
279 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
280 *devattr
, char *buf
);
281 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
282 *devattr
, const char *buf
, size_t count
);
283 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
284 *devattr
, char *buf
);
285 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
286 *devattr
, const char *buf
, size_t count
);
287 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
288 *devattr
, char *buf
);
289 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
290 *devattr
, char *buf
);
291 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
292 *devattr
, char *buf
);
293 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
294 *devattr
, const char *buf
, size_t count
);
295 static ssize_t
show_temp_alarm(struct device
*dev
, struct device_attribute
296 *devattr
, char *buf
);
297 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
298 *devattr
, char *buf
);
299 /* PWM and Auto point control */
300 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*devattr
,
302 static ssize_t
store_pwm(struct device
*dev
, struct device_attribute
*devattr
,
303 const char *buf
, size_t count
);
304 static ssize_t
show_pwm_enable(struct device
*dev
,
305 struct device_attribute
*devattr
, char *buf
);
306 static ssize_t
store_pwm_enable(struct device
*dev
,
307 struct device_attribute
*devattr
, const char *buf
, size_t count
);
308 static ssize_t
show_pwm_interpolate(struct device
*dev
,
309 struct device_attribute
*devattr
, char *buf
);
310 static ssize_t
store_pwm_interpolate(struct device
*dev
,
311 struct device_attribute
*devattr
, const char *buf
, size_t count
);
312 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
313 struct device_attribute
*devattr
, char *buf
);
314 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
315 struct device_attribute
*devattr
, const char *buf
, size_t count
);
316 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
317 struct device_attribute
*devattr
, char *buf
);
318 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
319 struct device_attribute
*devattr
, const char *buf
, size_t count
);
320 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
321 struct device_attribute
*devattr
, char *buf
);
322 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
323 struct device_attribute
*devattr
, const char *buf
, size_t count
);
324 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
325 struct device_attribute
*devattr
, char *buf
);
326 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
327 struct device_attribute
*devattr
, const char *buf
, size_t count
);
329 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
332 static int __devinit
f71882fg_probe(struct platform_device
* pdev
);
333 static int f71882fg_remove(struct platform_device
*pdev
);
335 static struct platform_driver f71882fg_driver
= {
337 .owner
= THIS_MODULE
,
340 .probe
= f71882fg_probe
,
341 .remove
= f71882fg_remove
,
344 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
346 /* Temp attr for the f71858fg, the f71858fg is special as it has its
347 temperature indexes start at 0 (the others start at 1) */
348 static struct sensor_device_attribute_2 f71858fg_temp_attr
[] = {
349 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
350 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
351 store_temp_max
, 0, 0),
352 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
353 store_temp_max_hyst
, 0, 0),
354 SENSOR_ATTR_2(temp1_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 0),
355 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
356 store_temp_crit
, 0, 0),
357 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
359 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
360 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
361 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
362 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
363 store_temp_max
, 0, 1),
364 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
365 store_temp_max_hyst
, 0, 1),
366 SENSOR_ATTR_2(temp2_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
367 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
368 store_temp_crit
, 0, 1),
369 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
371 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
372 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
373 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
374 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
375 store_temp_max
, 0, 2),
376 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
377 store_temp_max_hyst
, 0, 2),
378 SENSOR_ATTR_2(temp3_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
379 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
380 store_temp_crit
, 0, 2),
381 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
383 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
384 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
387 /* Temp attr for the standard models */
388 static struct sensor_device_attribute_2 fxxxx_temp_attr
[3][9] = { {
389 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
390 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
391 store_temp_max
, 0, 1),
392 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
393 store_temp_max_hyst
, 0, 1),
394 /* Should really be temp1_max_alarm, but older versions did not handle
395 the max and crit alarms separately and lm_sensors v2 depends on the
396 presence of temp#_alarm files. The same goes for temp2/3 _alarm. */
397 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
398 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
399 store_temp_crit
, 0, 1),
400 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
402 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
403 SENSOR_ATTR_2(temp1_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 1),
404 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
406 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
407 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
408 store_temp_max
, 0, 2),
409 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
410 store_temp_max_hyst
, 0, 2),
411 /* Should be temp2_max_alarm, see temp1_alarm note */
412 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
413 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
414 store_temp_crit
, 0, 2),
415 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
417 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
418 SENSOR_ATTR_2(temp2_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 2),
419 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
421 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 3),
422 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
423 store_temp_max
, 0, 3),
424 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
425 store_temp_max_hyst
, 0, 3),
426 /* Should be temp3_max_alarm, see temp1_alarm note */
427 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 3),
428 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
429 store_temp_crit
, 0, 3),
430 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
432 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 7),
433 SENSOR_ATTR_2(temp3_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 3),
434 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 3),
437 /* Temp attr for models which can beep on temp alarm */
438 static struct sensor_device_attribute_2 fxxxx_temp_beep_attr
[3][2] = { {
439 SENSOR_ATTR_2(temp1_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
440 store_temp_beep
, 0, 1),
441 SENSOR_ATTR_2(temp1_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
442 store_temp_beep
, 0, 5),
444 SENSOR_ATTR_2(temp2_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
445 store_temp_beep
, 0, 2),
446 SENSOR_ATTR_2(temp2_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
447 store_temp_beep
, 0, 6),
449 SENSOR_ATTR_2(temp3_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
450 store_temp_beep
, 0, 3),
451 SENSOR_ATTR_2(temp3_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
452 store_temp_beep
, 0, 7),
455 /* Temp attr for the f8000
456 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
457 is used as hysteresis value to clear alarms
458 Also like the f71858fg its temperature indexes start at 0
460 static struct sensor_device_attribute_2 f8000_temp_attr
[] = {
461 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
462 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
463 store_temp_crit
, 0, 0),
464 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
465 store_temp_max
, 0, 0),
466 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
467 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
468 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
469 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
470 store_temp_crit
, 0, 1),
471 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
472 store_temp_max
, 0, 1),
473 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
474 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
475 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
476 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
477 store_temp_crit
, 0, 2),
478 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
479 store_temp_max
, 0, 2),
480 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
481 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
484 /* in attr for all models */
485 static struct sensor_device_attribute_2 fxxxx_in_attr
[] = {
486 SENSOR_ATTR_2(in0_input
, S_IRUGO
, show_in
, NULL
, 0, 0),
487 SENSOR_ATTR_2(in1_input
, S_IRUGO
, show_in
, NULL
, 0, 1),
488 SENSOR_ATTR_2(in2_input
, S_IRUGO
, show_in
, NULL
, 0, 2),
489 SENSOR_ATTR_2(in3_input
, S_IRUGO
, show_in
, NULL
, 0, 3),
490 SENSOR_ATTR_2(in4_input
, S_IRUGO
, show_in
, NULL
, 0, 4),
491 SENSOR_ATTR_2(in5_input
, S_IRUGO
, show_in
, NULL
, 0, 5),
492 SENSOR_ATTR_2(in6_input
, S_IRUGO
, show_in
, NULL
, 0, 6),
493 SENSOR_ATTR_2(in7_input
, S_IRUGO
, show_in
, NULL
, 0, 7),
494 SENSOR_ATTR_2(in8_input
, S_IRUGO
, show_in
, NULL
, 0, 8),
497 /* For models with in1 alarm capability */
498 static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr
[] = {
499 SENSOR_ATTR_2(in1_max
, S_IRUGO
|S_IWUSR
, show_in_max
, store_in_max
,
501 SENSOR_ATTR_2(in1_beep
, S_IRUGO
|S_IWUSR
, show_in_beep
, store_in_beep
,
503 SENSOR_ATTR_2(in1_alarm
, S_IRUGO
, show_in_alarm
, NULL
, 0, 1),
506 /* Fan / PWM attr common to all models */
507 static struct sensor_device_attribute_2 fxxxx_fan_attr
[4][6] = { {
508 SENSOR_ATTR_2(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0, 0),
509 SENSOR_ATTR_2(fan1_full_speed
, S_IRUGO
|S_IWUSR
,
511 store_fan_full_speed
, 0, 0),
512 SENSOR_ATTR_2(fan1_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 0),
513 SENSOR_ATTR_2(pwm1
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 0),
514 SENSOR_ATTR_2(pwm1_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
515 store_pwm_enable
, 0, 0),
516 SENSOR_ATTR_2(pwm1_interpolate
, S_IRUGO
|S_IWUSR
,
517 show_pwm_interpolate
, store_pwm_interpolate
, 0, 0),
519 SENSOR_ATTR_2(fan2_input
, S_IRUGO
, show_fan
, NULL
, 0, 1),
520 SENSOR_ATTR_2(fan2_full_speed
, S_IRUGO
|S_IWUSR
,
522 store_fan_full_speed
, 0, 1),
523 SENSOR_ATTR_2(fan2_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 1),
524 SENSOR_ATTR_2(pwm2
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 1),
525 SENSOR_ATTR_2(pwm2_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
526 store_pwm_enable
, 0, 1),
527 SENSOR_ATTR_2(pwm2_interpolate
, S_IRUGO
|S_IWUSR
,
528 show_pwm_interpolate
, store_pwm_interpolate
, 0, 1),
530 SENSOR_ATTR_2(fan3_input
, S_IRUGO
, show_fan
, NULL
, 0, 2),
531 SENSOR_ATTR_2(fan3_full_speed
, S_IRUGO
|S_IWUSR
,
533 store_fan_full_speed
, 0, 2),
534 SENSOR_ATTR_2(fan3_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 2),
535 SENSOR_ATTR_2(pwm3
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 2),
536 SENSOR_ATTR_2(pwm3_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
537 store_pwm_enable
, 0, 2),
538 SENSOR_ATTR_2(pwm3_interpolate
, S_IRUGO
|S_IWUSR
,
539 show_pwm_interpolate
, store_pwm_interpolate
, 0, 2),
541 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
542 SENSOR_ATTR_2(fan4_full_speed
, S_IRUGO
|S_IWUSR
,
544 store_fan_full_speed
, 0, 3),
545 SENSOR_ATTR_2(fan4_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 3),
546 SENSOR_ATTR_2(pwm4
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 3),
547 SENSOR_ATTR_2(pwm4_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
548 store_pwm_enable
, 0, 3),
549 SENSOR_ATTR_2(pwm4_interpolate
, S_IRUGO
|S_IWUSR
,
550 show_pwm_interpolate
, store_pwm_interpolate
, 0, 3),
553 /* Attr for models which can beep on Fan alarm */
554 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr
[] = {
555 SENSOR_ATTR_2(fan1_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
556 store_fan_beep
, 0, 0),
557 SENSOR_ATTR_2(fan2_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
558 store_fan_beep
, 0, 1),
559 SENSOR_ATTR_2(fan3_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
560 store_fan_beep
, 0, 2),
561 SENSOR_ATTR_2(fan4_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
562 store_fan_beep
, 0, 3),
565 /* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
567 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr
[] = {
568 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
569 show_pwm_auto_point_channel
,
570 store_pwm_auto_point_channel
, 0, 0),
571 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
572 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
574 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
575 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
577 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
578 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
580 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
581 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
583 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
584 show_pwm_auto_point_temp_hyst
,
585 store_pwm_auto_point_temp_hyst
,
587 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
588 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
590 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
591 show_pwm_auto_point_channel
,
592 store_pwm_auto_point_channel
, 0, 1),
593 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
594 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
596 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
597 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
599 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
600 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
602 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
603 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
605 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
606 show_pwm_auto_point_temp_hyst
,
607 store_pwm_auto_point_temp_hyst
,
609 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
610 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
612 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
613 show_pwm_auto_point_channel
,
614 store_pwm_auto_point_channel
, 0, 2),
615 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
616 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
618 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
619 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
621 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
622 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
624 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
625 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
627 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
628 show_pwm_auto_point_temp_hyst
,
629 store_pwm_auto_point_temp_hyst
,
631 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
632 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
635 /* PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
636 pwm setting when the temperature is above the pwmX_auto_point1_temp can be
637 programmed instead of being hardcoded to 0xff */
638 static struct sensor_device_attribute_2 f71869_auto_pwm_attr
[] = {
639 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
640 show_pwm_auto_point_channel
,
641 store_pwm_auto_point_channel
, 0, 0),
642 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
643 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
645 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
646 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
648 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
649 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
651 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
652 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
654 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
655 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
657 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
658 show_pwm_auto_point_temp_hyst
,
659 store_pwm_auto_point_temp_hyst
,
661 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
662 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
664 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
665 show_pwm_auto_point_channel
,
666 store_pwm_auto_point_channel
, 0, 1),
667 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
668 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
670 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
671 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
673 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
674 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
676 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
677 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
679 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
680 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
682 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
683 show_pwm_auto_point_temp_hyst
,
684 store_pwm_auto_point_temp_hyst
,
686 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
687 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
689 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
690 show_pwm_auto_point_channel
,
691 store_pwm_auto_point_channel
, 0, 2),
692 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
693 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
695 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
696 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
698 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
699 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
701 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
702 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
704 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
705 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
707 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
708 show_pwm_auto_point_temp_hyst
,
709 store_pwm_auto_point_temp_hyst
,
711 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
712 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
715 /* PWM attr for the standard models */
716 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr
[4][14] = { {
717 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
718 show_pwm_auto_point_channel
,
719 store_pwm_auto_point_channel
, 0, 0),
720 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
721 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
723 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
724 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
726 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
727 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
729 SENSOR_ATTR_2(pwm1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
730 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
732 SENSOR_ATTR_2(pwm1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
733 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
735 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
736 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
738 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
739 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
741 SENSOR_ATTR_2(pwm1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
742 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
744 SENSOR_ATTR_2(pwm1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
745 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
747 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
748 show_pwm_auto_point_temp_hyst
,
749 store_pwm_auto_point_temp_hyst
,
751 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
752 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
753 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst
, S_IRUGO
,
754 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
755 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst
, S_IRUGO
,
756 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
758 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
759 show_pwm_auto_point_channel
,
760 store_pwm_auto_point_channel
, 0, 1),
761 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
762 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
764 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
765 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
767 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
768 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
770 SENSOR_ATTR_2(pwm2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
771 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
773 SENSOR_ATTR_2(pwm2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
774 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
776 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
777 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
779 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
780 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
782 SENSOR_ATTR_2(pwm2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
783 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
785 SENSOR_ATTR_2(pwm2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
786 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
788 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
789 show_pwm_auto_point_temp_hyst
,
790 store_pwm_auto_point_temp_hyst
,
792 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
793 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
794 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst
, S_IRUGO
,
795 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
796 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst
, S_IRUGO
,
797 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
799 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
800 show_pwm_auto_point_channel
,
801 store_pwm_auto_point_channel
, 0, 2),
802 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
803 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
805 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
806 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
808 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
809 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
811 SENSOR_ATTR_2(pwm3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
812 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
814 SENSOR_ATTR_2(pwm3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
815 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
817 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
818 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
820 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
821 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
823 SENSOR_ATTR_2(pwm3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
824 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
826 SENSOR_ATTR_2(pwm3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
827 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
829 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
830 show_pwm_auto_point_temp_hyst
,
831 store_pwm_auto_point_temp_hyst
,
833 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
834 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
835 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst
, S_IRUGO
,
836 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
837 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst
, S_IRUGO
,
838 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
840 SENSOR_ATTR_2(pwm4_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
841 show_pwm_auto_point_channel
,
842 store_pwm_auto_point_channel
, 0, 3),
843 SENSOR_ATTR_2(pwm4_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
844 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
846 SENSOR_ATTR_2(pwm4_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
847 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
849 SENSOR_ATTR_2(pwm4_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
850 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
852 SENSOR_ATTR_2(pwm4_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
853 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
855 SENSOR_ATTR_2(pwm4_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
856 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
858 SENSOR_ATTR_2(pwm4_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
859 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
861 SENSOR_ATTR_2(pwm4_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
862 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
864 SENSOR_ATTR_2(pwm4_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
865 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
867 SENSOR_ATTR_2(pwm4_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
868 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
870 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
871 show_pwm_auto_point_temp_hyst
,
872 store_pwm_auto_point_temp_hyst
,
874 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst
, S_IRUGO
,
875 show_pwm_auto_point_temp_hyst
, NULL
, 1, 3),
876 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst
, S_IRUGO
,
877 show_pwm_auto_point_temp_hyst
, NULL
, 2, 3),
878 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst
, S_IRUGO
,
879 show_pwm_auto_point_temp_hyst
, NULL
, 3, 3),
882 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
883 static struct sensor_device_attribute_2 f8000_fan_attr
[] = {
884 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
887 /* PWM attr for the f8000, zones mapped to temp instead of to pwm!
888 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
889 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
890 static struct sensor_device_attribute_2 f8000_auto_pwm_attr
[] = {
891 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
892 show_pwm_auto_point_channel
,
893 store_pwm_auto_point_channel
, 0, 0),
894 SENSOR_ATTR_2(temp1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
895 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
897 SENSOR_ATTR_2(temp1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
898 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
900 SENSOR_ATTR_2(temp1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
901 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
903 SENSOR_ATTR_2(temp1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
904 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
906 SENSOR_ATTR_2(temp1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
907 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
909 SENSOR_ATTR_2(temp1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
910 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
912 SENSOR_ATTR_2(temp1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
913 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
915 SENSOR_ATTR_2(temp1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
916 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
918 SENSOR_ATTR_2(temp1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
919 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
921 SENSOR_ATTR_2(temp1_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(temp1_auto_point2_temp_hyst
, S_IRUGO
,
926 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
927 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst
, S_IRUGO
,
928 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
929 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst
, S_IRUGO
,
930 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
932 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
933 show_pwm_auto_point_channel
,
934 store_pwm_auto_point_channel
, 0, 1),
935 SENSOR_ATTR_2(temp2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
936 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
938 SENSOR_ATTR_2(temp2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
939 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
941 SENSOR_ATTR_2(temp2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
942 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
944 SENSOR_ATTR_2(temp2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
945 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
947 SENSOR_ATTR_2(temp2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
948 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
950 SENSOR_ATTR_2(temp2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
951 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
953 SENSOR_ATTR_2(temp2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
954 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
956 SENSOR_ATTR_2(temp2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
957 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
959 SENSOR_ATTR_2(temp2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
960 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
962 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
963 show_pwm_auto_point_temp_hyst
,
964 store_pwm_auto_point_temp_hyst
,
966 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst
, S_IRUGO
,
967 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
968 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst
, S_IRUGO
,
969 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
970 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst
, S_IRUGO
,
971 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
973 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
974 show_pwm_auto_point_channel
,
975 store_pwm_auto_point_channel
, 0, 2),
976 SENSOR_ATTR_2(temp3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
977 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
979 SENSOR_ATTR_2(temp3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
980 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
982 SENSOR_ATTR_2(temp3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
983 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
985 SENSOR_ATTR_2(temp3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
986 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
988 SENSOR_ATTR_2(temp3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
989 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
991 SENSOR_ATTR_2(temp3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
992 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
994 SENSOR_ATTR_2(temp3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
995 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
997 SENSOR_ATTR_2(temp3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
998 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1000 SENSOR_ATTR_2(temp3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
1001 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
1003 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
1004 show_pwm_auto_point_temp_hyst
,
1005 store_pwm_auto_point_temp_hyst
,
1007 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst
, S_IRUGO
,
1008 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
1009 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst
, S_IRUGO
,
1010 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
1011 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst
, S_IRUGO
,
1012 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
1015 /* Super I/O functions */
1016 static inline int superio_inb(int base
, int reg
)
1019 return inb(base
+ 1);
1022 static int superio_inw(int base
, int reg
)
1025 val
= superio_inb(base
, reg
) << 8;
1026 val
|= superio_inb(base
, reg
+ 1);
1030 static inline int superio_enter(int base
)
1032 /* Don't step on other drivers' I/O space by accident */
1033 if (!request_muxed_region(base
, 2, DRVNAME
)) {
1034 pr_err("I/O address 0x%04x already in use\n", base
);
1038 /* according to the datasheet the key must be send twice! */
1039 outb(SIO_UNLOCK_KEY
, base
);
1040 outb(SIO_UNLOCK_KEY
, base
);
1045 static inline void superio_select(int base
, int ld
)
1047 outb(SIO_REG_LDSEL
, base
);
1051 static inline void superio_exit(int base
)
1053 outb(SIO_LOCK_KEY
, base
);
1054 release_region(base
, 2);
1057 static inline int fan_from_reg(u16 reg
)
1059 return reg
? (1500000 / reg
) : 0;
1062 static inline u16
fan_to_reg(int fan
)
1064 return fan
? (1500000 / fan
) : 0;
1067 static u8
f71882fg_read8(struct f71882fg_data
*data
, u8 reg
)
1071 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
1072 val
= inb(data
->addr
+ DATA_REG_OFFSET
);
1077 static u16
f71882fg_read16(struct f71882fg_data
*data
, u8 reg
)
1081 val
= f71882fg_read8(data
, reg
) << 8;
1082 val
|= f71882fg_read8(data
, reg
+ 1);
1087 static void f71882fg_write8(struct f71882fg_data
*data
, u8 reg
, u8 val
)
1089 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
1090 outb(val
, data
->addr
+ DATA_REG_OFFSET
);
1093 static void f71882fg_write16(struct f71882fg_data
*data
, u8 reg
, u16 val
)
1095 f71882fg_write8(data
, reg
, val
>> 8);
1096 f71882fg_write8(data
, reg
+ 1, val
& 0xff);
1099 static u16
f71882fg_read_temp(struct f71882fg_data
*data
, int nr
)
1101 if (data
->type
== f71858fg
)
1102 return f71882fg_read16(data
, F71882FG_REG_TEMP(nr
));
1104 return f71882fg_read8(data
, F71882FG_REG_TEMP(nr
));
1107 static struct f71882fg_data
*f71882fg_update_device(struct device
*dev
)
1109 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1110 int nr_fans
= f71882fg_nr_fans
[data
->type
];
1111 int nr_temps
= f71882fg_nr_temps
[data
->type
];
1114 mutex_lock(&data
->update_lock
);
1116 /* Update once every 60 seconds */
1117 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
) ||
1119 if (f71882fg_has_in1_alarm
[data
->type
]) {
1121 f71882fg_read8(data
, F71882FG_REG_IN1_HIGH
);
1123 f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1126 /* Get High & boundary temps*/
1127 for (nr
= data
->temp_start
; nr
< nr_temps
+ data
->temp_start
;
1129 data
->temp_ovt
[nr
] = f71882fg_read8(data
,
1130 F71882FG_REG_TEMP_OVT(nr
));
1131 data
->temp_high
[nr
] = f71882fg_read8(data
,
1132 F71882FG_REG_TEMP_HIGH(nr
));
1135 if (data
->type
!= f8000
) {
1136 data
->temp_hyst
[0] = f71882fg_read8(data
,
1137 F71882FG_REG_TEMP_HYST(0));
1138 data
->temp_hyst
[1] = f71882fg_read8(data
,
1139 F71882FG_REG_TEMP_HYST(1));
1141 /* All but the f71858fg / f8000 have this register */
1142 if ((data
->type
!= f71858fg
) && (data
->type
!= f8000
)) {
1143 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_TYPE
);
1144 data
->temp_type
[1] = (reg
& 0x02) ? 2 : 4;
1145 data
->temp_type
[2] = (reg
& 0x04) ? 2 : 4;
1146 data
->temp_type
[3] = (reg
& 0x08) ? 2 : 4;
1149 if (f71882fg_has_beep
[data
->type
]) {
1150 data
->fan_beep
= f71882fg_read8(data
,
1151 F71882FG_REG_FAN_BEEP
);
1152 data
->temp_beep
= f71882fg_read8(data
,
1153 F71882FG_REG_TEMP_BEEP
);
1156 data
->pwm_enable
= f71882fg_read8(data
,
1157 F71882FG_REG_PWM_ENABLE
);
1158 data
->pwm_auto_point_hyst
[0] =
1159 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(0));
1160 data
->pwm_auto_point_hyst
[1] =
1161 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(1));
1163 for (nr
= 0; nr
< nr_fans
; nr
++) {
1164 data
->pwm_auto_point_mapping
[nr
] =
1165 f71882fg_read8(data
,
1166 F71882FG_REG_POINT_MAPPING(nr
));
1168 switch (data
->type
) {
1170 for (point
= 0; point
< 5; point
++) {
1171 data
->pwm_auto_point_pwm
[nr
][point
] =
1172 f71882fg_read8(data
,
1173 F71882FG_REG_POINT_PWM
1176 for (point
= 0; point
< 4; point
++) {
1177 data
->pwm_auto_point_temp
[nr
][point
] =
1178 f71882fg_read8(data
,
1179 F71882FG_REG_POINT_TEMP
1185 data
->pwm_auto_point_pwm
[nr
][0] =
1186 f71882fg_read8(data
,
1187 F71882FG_REG_POINT_PWM(nr
, 0));
1190 data
->pwm_auto_point_pwm
[nr
][1] =
1191 f71882fg_read8(data
,
1192 F71882FG_REG_POINT_PWM
1194 data
->pwm_auto_point_pwm
[nr
][4] =
1195 f71882fg_read8(data
,
1196 F71882FG_REG_POINT_PWM
1198 data
->pwm_auto_point_temp
[nr
][0] =
1199 f71882fg_read8(data
,
1200 F71882FG_REG_POINT_TEMP
1202 data
->pwm_auto_point_temp
[nr
][3] =
1203 f71882fg_read8(data
,
1204 F71882FG_REG_POINT_TEMP
1209 data
->last_limits
= jiffies
;
1212 /* Update every second */
1213 if (time_after(jiffies
, data
->last_updated
+ HZ
) || !data
->valid
) {
1214 data
->temp_status
= f71882fg_read8(data
,
1215 F71882FG_REG_TEMP_STATUS
);
1216 data
->temp_diode_open
= f71882fg_read8(data
,
1217 F71882FG_REG_TEMP_DIODE_OPEN
);
1218 for (nr
= data
->temp_start
; nr
< nr_temps
+ data
->temp_start
;
1220 data
->temp
[nr
] = f71882fg_read_temp(data
, nr
);
1222 data
->fan_status
= f71882fg_read8(data
,
1223 F71882FG_REG_FAN_STATUS
);
1224 for (nr
= 0; nr
< nr_fans
; nr
++) {
1225 data
->fan
[nr
] = f71882fg_read16(data
,
1226 F71882FG_REG_FAN(nr
));
1227 data
->fan_target
[nr
] =
1228 f71882fg_read16(data
, F71882FG_REG_FAN_TARGET(nr
));
1229 data
->fan_full_speed
[nr
] =
1230 f71882fg_read16(data
,
1231 F71882FG_REG_FAN_FULL_SPEED(nr
));
1233 f71882fg_read8(data
, F71882FG_REG_PWM(nr
));
1235 /* The f8000 can monitor 1 more fan, but has no pwm for it */
1236 if (data
->type
== f8000
)
1237 data
->fan
[3] = f71882fg_read16(data
,
1238 F71882FG_REG_FAN(3));
1240 if (f71882fg_has_in1_alarm
[data
->type
])
1241 data
->in_status
= f71882fg_read8(data
,
1242 F71882FG_REG_IN_STATUS
);
1243 for (nr
= 0; nr
< F71882FG_MAX_INS
; nr
++)
1244 if (f71882fg_has_in
[data
->type
][nr
])
1245 data
->in
[nr
] = f71882fg_read8(data
,
1246 F71882FG_REG_IN(nr
));
1248 data
->last_updated
= jiffies
;
1252 mutex_unlock(&data
->update_lock
);
1257 /* Sysfs Interface */
1258 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
1261 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1262 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1263 int speed
= fan_from_reg(data
->fan
[nr
]);
1265 if (speed
== FAN_MIN_DETECT
)
1268 return sprintf(buf
, "%d\n", speed
);
1271 static ssize_t
show_fan_full_speed(struct device
*dev
,
1272 struct device_attribute
*devattr
, char *buf
)
1274 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1275 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1276 int speed
= fan_from_reg(data
->fan_full_speed
[nr
]);
1277 return sprintf(buf
, "%d\n", speed
);
1280 static ssize_t
store_fan_full_speed(struct device
*dev
,
1281 struct device_attribute
*devattr
,
1282 const char *buf
, size_t count
)
1284 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1285 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1288 err
= strict_strtol(buf
, 10, &val
);
1292 val
= SENSORS_LIMIT(val
, 23, 1500000);
1293 val
= fan_to_reg(val
);
1295 mutex_lock(&data
->update_lock
);
1296 f71882fg_write16(data
, F71882FG_REG_FAN_FULL_SPEED(nr
), val
);
1297 data
->fan_full_speed
[nr
] = val
;
1298 mutex_unlock(&data
->update_lock
);
1303 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
1304 *devattr
, char *buf
)
1306 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1307 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1309 if (data
->fan_beep
& (1 << nr
))
1310 return sprintf(buf
, "1\n");
1312 return sprintf(buf
, "0\n");
1315 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
1316 *devattr
, const char *buf
, size_t count
)
1318 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1319 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1322 err
= strict_strtoul(buf
, 10, &val
);
1326 mutex_lock(&data
->update_lock
);
1327 data
->fan_beep
= f71882fg_read8(data
, F71882FG_REG_FAN_BEEP
);
1329 data
->fan_beep
|= 1 << nr
;
1331 data
->fan_beep
&= ~(1 << nr
);
1333 f71882fg_write8(data
, F71882FG_REG_FAN_BEEP
, data
->fan_beep
);
1334 mutex_unlock(&data
->update_lock
);
1339 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
1340 *devattr
, char *buf
)
1342 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1343 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1345 if (data
->fan_status
& (1 << nr
))
1346 return sprintf(buf
, "1\n");
1348 return sprintf(buf
, "0\n");
1351 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
1354 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1355 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1357 return sprintf(buf
, "%d\n", data
->in
[nr
] * 8);
1360 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
1361 *devattr
, char *buf
)
1363 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1365 return sprintf(buf
, "%d\n", data
->in1_max
* 8);
1368 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
1369 *devattr
, const char *buf
, size_t count
)
1371 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1375 err
= strict_strtol(buf
, 10, &val
);
1380 val
= SENSORS_LIMIT(val
, 0, 255);
1382 mutex_lock(&data
->update_lock
);
1383 f71882fg_write8(data
, F71882FG_REG_IN1_HIGH
, val
);
1384 data
->in1_max
= val
;
1385 mutex_unlock(&data
->update_lock
);
1390 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
1391 *devattr
, char *buf
)
1393 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1394 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1396 if (data
->in_beep
& (1 << nr
))
1397 return sprintf(buf
, "1\n");
1399 return sprintf(buf
, "0\n");
1402 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
1403 *devattr
, const char *buf
, size_t count
)
1405 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1406 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1409 err
= strict_strtoul(buf
, 10, &val
);
1413 mutex_lock(&data
->update_lock
);
1414 data
->in_beep
= f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1416 data
->in_beep
|= 1 << nr
;
1418 data
->in_beep
&= ~(1 << nr
);
1420 f71882fg_write8(data
, F71882FG_REG_IN_BEEP
, data
->in_beep
);
1421 mutex_unlock(&data
->update_lock
);
1426 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
1427 *devattr
, char *buf
)
1429 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1430 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1432 if (data
->in_status
& (1 << nr
))
1433 return sprintf(buf
, "1\n");
1435 return sprintf(buf
, "0\n");
1438 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*devattr
,
1441 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1442 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1445 if (data
->type
== f71858fg
) {
1446 /* TEMP_TABLE_SEL 1 or 3 ? */
1447 if (data
->temp_config
& 1) {
1448 sign
= data
->temp
[nr
] & 0x0001;
1449 temp
= (data
->temp
[nr
] >> 5) & 0x7ff;
1451 sign
= data
->temp
[nr
] & 0x8000;
1452 temp
= (data
->temp
[nr
] >> 5) & 0x3ff;
1458 temp
= data
->temp
[nr
] * 1000;
1460 return sprintf(buf
, "%d\n", temp
);
1463 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
1464 *devattr
, char *buf
)
1466 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1467 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1469 return sprintf(buf
, "%d\n", data
->temp_high
[nr
] * 1000);
1472 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
1473 *devattr
, const char *buf
, size_t count
)
1475 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1476 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1479 err
= strict_strtol(buf
, 10, &val
);
1484 val
= SENSORS_LIMIT(val
, 0, 255);
1486 mutex_lock(&data
->update_lock
);
1487 f71882fg_write8(data
, F71882FG_REG_TEMP_HIGH(nr
), val
);
1488 data
->temp_high
[nr
] = val
;
1489 mutex_unlock(&data
->update_lock
);
1494 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
1495 *devattr
, char *buf
)
1497 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1498 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1501 mutex_lock(&data
->update_lock
);
1503 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1505 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1506 temp_max_hyst
= (data
->temp_high
[nr
] - temp_max_hyst
) * 1000;
1507 mutex_unlock(&data
->update_lock
);
1509 return sprintf(buf
, "%d\n", temp_max_hyst
);
1512 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
1513 *devattr
, const char *buf
, size_t count
)
1515 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1516 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1517 ssize_t ret
= count
;
1521 err
= strict_strtol(buf
, 10, &val
);
1527 mutex_lock(&data
->update_lock
);
1529 /* convert abs to relative and check */
1530 data
->temp_high
[nr
] = f71882fg_read8(data
, F71882FG_REG_TEMP_HIGH(nr
));
1531 val
= SENSORS_LIMIT(val
, data
->temp_high
[nr
] - 15,
1532 data
->temp_high
[nr
]);
1533 val
= data
->temp_high
[nr
] - val
;
1535 /* convert value to register contents */
1536 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2));
1538 reg
= (reg
& 0x0f) | (val
<< 4);
1540 reg
= (reg
& 0xf0) | val
;
1541 f71882fg_write8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2), reg
);
1542 data
->temp_hyst
[nr
/ 2] = reg
;
1544 mutex_unlock(&data
->update_lock
);
1548 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
1549 *devattr
, char *buf
)
1551 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1552 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1554 return sprintf(buf
, "%d\n", data
->temp_ovt
[nr
] * 1000);
1557 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
1558 *devattr
, const char *buf
, size_t count
)
1560 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1561 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1564 err
= strict_strtol(buf
, 10, &val
);
1569 val
= SENSORS_LIMIT(val
, 0, 255);
1571 mutex_lock(&data
->update_lock
);
1572 f71882fg_write8(data
, F71882FG_REG_TEMP_OVT(nr
), val
);
1573 data
->temp_ovt
[nr
] = val
;
1574 mutex_unlock(&data
->update_lock
);
1579 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
1580 *devattr
, char *buf
)
1582 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1583 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1586 mutex_lock(&data
->update_lock
);
1588 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1590 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1591 temp_crit_hyst
= (data
->temp_ovt
[nr
] - temp_crit_hyst
) * 1000;
1592 mutex_unlock(&data
->update_lock
);
1594 return sprintf(buf
, "%d\n", temp_crit_hyst
);
1597 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
1598 *devattr
, char *buf
)
1600 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1601 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1603 return sprintf(buf
, "%d\n", data
->temp_type
[nr
]);
1606 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
1607 *devattr
, char *buf
)
1609 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1610 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1612 if (data
->temp_beep
& (1 << nr
))
1613 return sprintf(buf
, "1\n");
1615 return sprintf(buf
, "0\n");
1618 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
1619 *devattr
, const char *buf
, size_t count
)
1621 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1622 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1625 err
= strict_strtoul(buf
, 10, &val
);
1629 mutex_lock(&data
->update_lock
);
1630 data
->temp_beep
= f71882fg_read8(data
, F71882FG_REG_TEMP_BEEP
);
1632 data
->temp_beep
|= 1 << nr
;
1634 data
->temp_beep
&= ~(1 << nr
);
1636 f71882fg_write8(data
, F71882FG_REG_TEMP_BEEP
, data
->temp_beep
);
1637 mutex_unlock(&data
->update_lock
);
1642 static ssize_t
show_temp_alarm(struct device
*dev
, struct device_attribute
1643 *devattr
, char *buf
)
1645 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1646 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1648 if (data
->temp_status
& (1 << nr
))
1649 return sprintf(buf
, "1\n");
1651 return sprintf(buf
, "0\n");
1654 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
1655 *devattr
, char *buf
)
1657 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1658 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1660 if (data
->temp_diode_open
& (1 << nr
))
1661 return sprintf(buf
, "1\n");
1663 return sprintf(buf
, "0\n");
1666 static ssize_t
show_pwm(struct device
*dev
,
1667 struct device_attribute
*devattr
, char *buf
)
1669 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1670 int val
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1671 mutex_lock(&data
->update_lock
);
1672 if (data
->pwm_enable
& (1 << (2 * nr
)))
1674 val
= data
->pwm
[nr
];
1677 val
= 255 * fan_from_reg(data
->fan_target
[nr
])
1678 / fan_from_reg(data
->fan_full_speed
[nr
]);
1680 mutex_unlock(&data
->update_lock
);
1681 return sprintf(buf
, "%d\n", val
);
1684 static ssize_t
store_pwm(struct device
*dev
,
1685 struct device_attribute
*devattr
, const char *buf
,
1688 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1689 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1692 err
= strict_strtol(buf
, 10, &val
);
1696 val
= SENSORS_LIMIT(val
, 0, 255);
1698 mutex_lock(&data
->update_lock
);
1699 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1700 if ((data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 3) != 2) ||
1701 (data
->type
!= f8000
&& !((data
->pwm_enable
>> 2 * nr
) & 2))) {
1705 if (data
->pwm_enable
& (1 << (2 * nr
))) {
1707 f71882fg_write8(data
, F71882FG_REG_PWM(nr
), val
);
1708 data
->pwm
[nr
] = val
;
1711 int target
, full_speed
;
1712 full_speed
= f71882fg_read16(data
,
1713 F71882FG_REG_FAN_FULL_SPEED(nr
));
1714 target
= fan_to_reg(val
* fan_from_reg(full_speed
) / 255);
1715 f71882fg_write16(data
, F71882FG_REG_FAN_TARGET(nr
), target
);
1716 data
->fan_target
[nr
] = target
;
1717 data
->fan_full_speed
[nr
] = full_speed
;
1720 mutex_unlock(&data
->update_lock
);
1725 static ssize_t
show_pwm_enable(struct device
*dev
,
1726 struct device_attribute
*devattr
, char *buf
)
1729 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1730 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1732 switch ((data
->pwm_enable
>> 2 * nr
) & 3) {
1735 result
= 2; /* Normal auto mode */
1738 result
= 1; /* Manual mode */
1741 if (data
->type
== f8000
)
1742 result
= 3; /* Thermostat mode */
1744 result
= 1; /* Manual mode */
1748 return sprintf(buf
, "%d\n", result
);
1751 static ssize_t
store_pwm_enable(struct device
*dev
, struct device_attribute
1752 *devattr
, const char *buf
, size_t count
)
1754 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1755 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1758 err
= strict_strtol(buf
, 10, &val
);
1762 /* Special case for F8000 pwm channel 3 which only does auto mode */
1763 if (data
->type
== f8000
&& nr
== 2 && val
!= 2)
1766 mutex_lock(&data
->update_lock
);
1767 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1768 /* Special case for F8000 auto PWM mode / Thermostat mode */
1769 if (data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 1)) {
1772 data
->pwm_enable
&= ~(2 << (2 * nr
));
1773 break; /* Normal auto mode */
1775 data
->pwm_enable
|= 2 << (2 * nr
);
1776 break; /* Thermostat mode */
1784 /* The f71858fg does not support manual RPM mode */
1785 if (data
->type
== f71858fg
&&
1786 ((data
->pwm_enable
>> (2 * nr
)) & 1)) {
1790 data
->pwm_enable
|= 2 << (2 * nr
);
1793 data
->pwm_enable
&= ~(2 << (2 * nr
));
1794 break; /* Normal auto mode */
1800 f71882fg_write8(data
, F71882FG_REG_PWM_ENABLE
, data
->pwm_enable
);
1802 mutex_unlock(&data
->update_lock
);
1807 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
1808 struct device_attribute
*devattr
,
1812 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1813 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1814 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1816 mutex_lock(&data
->update_lock
);
1817 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1819 result
= data
->pwm_auto_point_pwm
[pwm
][point
];
1822 result
= 32 * 255 / (32 + data
->pwm_auto_point_pwm
[pwm
][point
]);
1824 mutex_unlock(&data
->update_lock
);
1826 return sprintf(buf
, "%d\n", result
);
1829 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
1830 struct device_attribute
*devattr
,
1831 const char *buf
, size_t count
)
1833 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1834 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1835 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1838 err
= strict_strtol(buf
, 10, &val
);
1842 val
= SENSORS_LIMIT(val
, 0, 255);
1844 mutex_lock(&data
->update_lock
);
1845 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1846 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1850 if (val
< 29) /* Prevent negative numbers */
1853 val
= (255 - val
) * 32 / val
;
1855 f71882fg_write8(data
, F71882FG_REG_POINT_PWM(pwm
, point
), val
);
1856 data
->pwm_auto_point_pwm
[pwm
][point
] = val
;
1857 mutex_unlock(&data
->update_lock
);
1862 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
1863 struct device_attribute
*devattr
,
1867 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1868 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1869 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1871 mutex_lock(&data
->update_lock
);
1873 result
= data
->pwm_auto_point_hyst
[nr
/ 2] >> 4;
1875 result
= data
->pwm_auto_point_hyst
[nr
/ 2] & 0x0f;
1876 result
= 1000 * (data
->pwm_auto_point_temp
[nr
][point
] - result
);
1877 mutex_unlock(&data
->update_lock
);
1879 return sprintf(buf
, "%d\n", result
);
1882 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
1883 struct device_attribute
*devattr
,
1884 const char *buf
, size_t count
)
1886 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1887 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1888 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1892 err
= strict_strtol(buf
, 10, &val
);
1898 mutex_lock(&data
->update_lock
);
1899 data
->pwm_auto_point_temp
[nr
][point
] =
1900 f71882fg_read8(data
, F71882FG_REG_POINT_TEMP(nr
, point
));
1901 val
= SENSORS_LIMIT(val
, data
->pwm_auto_point_temp
[nr
][point
] - 15,
1902 data
->pwm_auto_point_temp
[nr
][point
]);
1903 val
= data
->pwm_auto_point_temp
[nr
][point
] - val
;
1905 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_HYST(nr
/ 2));
1907 reg
= (reg
& 0x0f) | (val
<< 4);
1909 reg
= (reg
& 0xf0) | val
;
1911 f71882fg_write8(data
, F71882FG_REG_FAN_HYST(nr
/ 2), reg
);
1912 data
->pwm_auto_point_hyst
[nr
/ 2] = reg
;
1913 mutex_unlock(&data
->update_lock
);
1918 static ssize_t
show_pwm_interpolate(struct device
*dev
,
1919 struct device_attribute
*devattr
, char *buf
)
1922 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1923 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1925 result
= (data
->pwm_auto_point_mapping
[nr
] >> 4) & 1;
1927 return sprintf(buf
, "%d\n", result
);
1930 static ssize_t
store_pwm_interpolate(struct device
*dev
,
1931 struct device_attribute
*devattr
,
1932 const char *buf
, size_t count
)
1934 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1935 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1938 err
= strict_strtoul(buf
, 10, &val
);
1942 mutex_lock(&data
->update_lock
);
1943 data
->pwm_auto_point_mapping
[nr
] =
1944 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
1946 val
= data
->pwm_auto_point_mapping
[nr
] | (1 << 4);
1948 val
= data
->pwm_auto_point_mapping
[nr
] & (~(1 << 4));
1949 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
1950 data
->pwm_auto_point_mapping
[nr
] = val
;
1951 mutex_unlock(&data
->update_lock
);
1956 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
1957 struct device_attribute
*devattr
,
1961 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1962 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1964 result
= 1 << ((data
->pwm_auto_point_mapping
[nr
] & 3) -
1967 return sprintf(buf
, "%d\n", result
);
1970 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
1971 struct device_attribute
*devattr
,
1972 const char *buf
, size_t count
)
1974 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1975 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1978 err
= strict_strtol(buf
, 10, &val
);
1995 val
+= data
->temp_start
;
1996 mutex_lock(&data
->update_lock
);
1997 data
->pwm_auto_point_mapping
[nr
] =
1998 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
1999 val
= (data
->pwm_auto_point_mapping
[nr
] & 0xfc) | val
;
2000 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
2001 data
->pwm_auto_point_mapping
[nr
] = val
;
2002 mutex_unlock(&data
->update_lock
);
2007 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
2008 struct device_attribute
*devattr
,
2012 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
2013 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
2014 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
2016 result
= data
->pwm_auto_point_temp
[pwm
][point
];
2017 return sprintf(buf
, "%d\n", 1000 * result
);
2020 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
2021 struct device_attribute
*devattr
,
2022 const char *buf
, size_t count
)
2024 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2025 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
2026 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
2029 err
= strict_strtol(buf
, 10, &val
);
2035 if (data
->auto_point_temp_signed
)
2036 val
= SENSORS_LIMIT(val
, -128, 127);
2038 val
= SENSORS_LIMIT(val
, 0, 127);
2040 mutex_lock(&data
->update_lock
);
2041 f71882fg_write8(data
, F71882FG_REG_POINT_TEMP(pwm
, point
), val
);
2042 data
->pwm_auto_point_temp
[pwm
][point
] = val
;
2043 mutex_unlock(&data
->update_lock
);
2048 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
2051 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2052 return sprintf(buf
, "%s\n", f71882fg_names
[data
->type
]);
2055 static int __devinit
f71882fg_create_sysfs_files(struct platform_device
*pdev
,
2056 struct sensor_device_attribute_2
*attr
, int count
)
2060 for (i
= 0; i
< count
; i
++) {
2061 err
= device_create_file(&pdev
->dev
, &attr
[i
].dev_attr
);
2068 static void f71882fg_remove_sysfs_files(struct platform_device
*pdev
,
2069 struct sensor_device_attribute_2
*attr
, int count
)
2073 for (i
= 0; i
< count
; i
++)
2074 device_remove_file(&pdev
->dev
, &attr
[i
].dev_attr
);
2077 static int __devinit
f71882fg_probe(struct platform_device
*pdev
)
2079 struct f71882fg_data
*data
;
2080 struct f71882fg_sio_data
*sio_data
= pdev
->dev
.platform_data
;
2081 int nr_fans
= f71882fg_nr_fans
[sio_data
->type
];
2082 int nr_temps
= f71882fg_nr_temps
[sio_data
->type
];
2086 data
= kzalloc(sizeof(struct f71882fg_data
), GFP_KERNEL
);
2090 data
->addr
= platform_get_resource(pdev
, IORESOURCE_IO
, 0)->start
;
2091 data
->type
= sio_data
->type
;
2093 (data
->type
== f71858fg
|| data
->type
== f8000
) ? 0 : 1;
2094 mutex_init(&data
->update_lock
);
2095 platform_set_drvdata(pdev
, data
);
2097 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2098 if (start_reg
& 0x04) {
2099 dev_warn(&pdev
->dev
, "Hardware monitor is powered down\n");
2103 if (!(start_reg
& 0x03)) {
2104 dev_warn(&pdev
->dev
, "Hardware monitoring not activated\n");
2109 /* Register sysfs interface files */
2110 err
= device_create_file(&pdev
->dev
, &dev_attr_name
);
2112 goto exit_unregister_sysfs
;
2114 if (start_reg
& 0x01) {
2115 switch (data
->type
) {
2118 f71882fg_read8(data
, F71882FG_REG_TEMP_CONFIG
);
2119 if (data
->temp_config
& 0x10)
2120 /* The f71858fg temperature alarms behave as
2121 the f8000 alarms in this mode */
2122 err
= f71882fg_create_sysfs_files(pdev
,
2124 ARRAY_SIZE(f8000_temp_attr
));
2126 err
= f71882fg_create_sysfs_files(pdev
,
2128 ARRAY_SIZE(f71858fg_temp_attr
));
2131 err
= f71882fg_create_sysfs_files(pdev
,
2133 ARRAY_SIZE(f8000_temp_attr
));
2136 err
= f71882fg_create_sysfs_files(pdev
,
2137 &fxxxx_temp_attr
[0][0],
2138 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2141 goto exit_unregister_sysfs
;
2143 if (f71882fg_has_beep
[data
->type
]) {
2144 err
= f71882fg_create_sysfs_files(pdev
,
2145 &fxxxx_temp_beep_attr
[0][0],
2146 ARRAY_SIZE(fxxxx_temp_beep_attr
[0])
2149 goto exit_unregister_sysfs
;
2152 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2153 if (f71882fg_has_in
[data
->type
][i
]) {
2154 err
= device_create_file(&pdev
->dev
,
2155 &fxxxx_in_attr
[i
].dev_attr
);
2157 goto exit_unregister_sysfs
;
2160 if (f71882fg_has_in1_alarm
[data
->type
]) {
2161 err
= f71882fg_create_sysfs_files(pdev
,
2162 fxxxx_in1_alarm_attr
,
2163 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2165 goto exit_unregister_sysfs
;
2169 if (start_reg
& 0x02) {
2170 switch (data
->type
) {
2173 /* These always have signed auto point temps */
2174 data
->auto_point_temp_signed
= 1;
2175 /* Fall through to select correct fan/pwm reg bank! */
2179 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_FAULT_T
);
2180 if (reg
& F71882FG_FAN_NEG_TEMP_EN
)
2181 data
->auto_point_temp_signed
= 1;
2182 /* Ensure banked pwm registers point to right bank */
2183 reg
&= ~F71882FG_FAN_PROG_SEL
;
2184 f71882fg_write8(data
, F71882FG_REG_FAN_FAULT_T
, reg
);
2191 f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
2193 /* Sanity check the pwm settings */
2194 switch (data
->type
) {
2197 for (i
= 0; i
< nr_fans
; i
++)
2198 if (((data
->pwm_enable
>> (i
* 2)) & 3) == 3)
2202 err
= (data
->pwm_enable
& 0x15) != 0x15;
2205 err
= data
->pwm_enable
& 0x20;
2213 "Invalid (reserved) pwm settings: 0x%02x\n",
2214 (unsigned int)data
->pwm_enable
);
2216 goto exit_unregister_sysfs
;
2219 err
= f71882fg_create_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2220 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2222 goto exit_unregister_sysfs
;
2224 if (f71882fg_has_beep
[data
->type
]) {
2225 err
= f71882fg_create_sysfs_files(pdev
,
2226 fxxxx_fan_beep_attr
, nr_fans
);
2228 goto exit_unregister_sysfs
;
2231 switch (data
->type
) {
2237 for (i
= 0; i
< nr_fans
; i
++) {
2238 data
->pwm_auto_point_mapping
[i
] =
2239 f71882fg_read8(data
,
2240 F71882FG_REG_POINT_MAPPING(i
));
2241 if ((data
->pwm_auto_point_mapping
[i
] & 0x80) ||
2242 (data
->pwm_auto_point_mapping
[i
] & 3) == 0)
2246 dev_warn(&pdev
->dev
,
2247 "Auto pwm controlled by raw digital "
2248 "data, disabling pwm auto_point "
2249 "sysfs attributes\n");
2250 goto no_pwm_auto_point
;
2257 switch (data
->type
) {
2259 err
= f71882fg_create_sysfs_files(pdev
,
2260 f71862fg_auto_pwm_attr
,
2261 ARRAY_SIZE(f71862fg_auto_pwm_attr
));
2265 err
= f71882fg_create_sysfs_files(pdev
,
2266 f71869_auto_pwm_attr
,
2267 ARRAY_SIZE(f71869_auto_pwm_attr
));
2270 err
= f71882fg_create_sysfs_files(pdev
,
2272 ARRAY_SIZE(f8000_fan_attr
));
2274 goto exit_unregister_sysfs
;
2275 err
= f71882fg_create_sysfs_files(pdev
,
2276 f8000_auto_pwm_attr
,
2277 ARRAY_SIZE(f8000_auto_pwm_attr
));
2280 err
= f71882fg_create_sysfs_files(pdev
,
2281 &fxxxx_auto_pwm_attr
[0][0],
2282 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2285 goto exit_unregister_sysfs
;
2288 for (i
= 0; i
< nr_fans
; i
++)
2289 dev_info(&pdev
->dev
, "Fan: %d is in %s mode\n", i
+ 1,
2290 (data
->pwm_enable
& (1 << 2 * i
)) ?
2291 "duty-cycle" : "RPM");
2294 data
->hwmon_dev
= hwmon_device_register(&pdev
->dev
);
2295 if (IS_ERR(data
->hwmon_dev
)) {
2296 err
= PTR_ERR(data
->hwmon_dev
);
2297 data
->hwmon_dev
= NULL
;
2298 goto exit_unregister_sysfs
;
2303 exit_unregister_sysfs
:
2304 f71882fg_remove(pdev
); /* Will unregister the sysfs files for us */
2305 return err
; /* f71882fg_remove() also frees our data */
2311 static int f71882fg_remove(struct platform_device
*pdev
)
2313 struct f71882fg_data
*data
= platform_get_drvdata(pdev
);
2314 int nr_fans
= f71882fg_nr_fans
[data
->type
];
2315 int nr_temps
= f71882fg_nr_temps
[data
->type
];
2317 u8 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2319 if (data
->hwmon_dev
)
2320 hwmon_device_unregister(data
->hwmon_dev
);
2322 device_remove_file(&pdev
->dev
, &dev_attr_name
);
2324 if (start_reg
& 0x01) {
2325 switch (data
->type
) {
2327 if (data
->temp_config
& 0x10)
2328 f71882fg_remove_sysfs_files(pdev
,
2330 ARRAY_SIZE(f8000_temp_attr
));
2332 f71882fg_remove_sysfs_files(pdev
,
2334 ARRAY_SIZE(f71858fg_temp_attr
));
2337 f71882fg_remove_sysfs_files(pdev
,
2339 ARRAY_SIZE(f8000_temp_attr
));
2342 f71882fg_remove_sysfs_files(pdev
,
2343 &fxxxx_temp_attr
[0][0],
2344 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2346 if (f71882fg_has_beep
[data
->type
]) {
2347 f71882fg_remove_sysfs_files(pdev
,
2348 &fxxxx_temp_beep_attr
[0][0],
2349 ARRAY_SIZE(fxxxx_temp_beep_attr
[0]) * nr_temps
);
2352 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2353 if (f71882fg_has_in
[data
->type
][i
]) {
2354 device_remove_file(&pdev
->dev
,
2355 &fxxxx_in_attr
[i
].dev_attr
);
2358 if (f71882fg_has_in1_alarm
[data
->type
]) {
2359 f71882fg_remove_sysfs_files(pdev
,
2360 fxxxx_in1_alarm_attr
,
2361 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2365 if (start_reg
& 0x02) {
2366 f71882fg_remove_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2367 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2369 if (f71882fg_has_beep
[data
->type
]) {
2370 f71882fg_remove_sysfs_files(pdev
,
2371 fxxxx_fan_beep_attr
, nr_fans
);
2374 switch (data
->type
) {
2376 f71882fg_remove_sysfs_files(pdev
,
2377 f71862fg_auto_pwm_attr
,
2378 ARRAY_SIZE(f71862fg_auto_pwm_attr
));
2382 f71882fg_remove_sysfs_files(pdev
,
2383 f71869_auto_pwm_attr
,
2384 ARRAY_SIZE(f71869_auto_pwm_attr
));
2387 f71882fg_remove_sysfs_files(pdev
,
2389 ARRAY_SIZE(f8000_fan_attr
));
2390 f71882fg_remove_sysfs_files(pdev
,
2391 f8000_auto_pwm_attr
,
2392 ARRAY_SIZE(f8000_auto_pwm_attr
));
2395 f71882fg_remove_sysfs_files(pdev
,
2396 &fxxxx_auto_pwm_attr
[0][0],
2397 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2401 platform_set_drvdata(pdev
, NULL
);
2407 static int __init
f71882fg_find(int sioaddr
, unsigned short *address
,
2408 struct f71882fg_sio_data
*sio_data
)
2411 int err
= superio_enter(sioaddr
);
2415 devid
= superio_inw(sioaddr
, SIO_REG_MANID
);
2416 if (devid
!= SIO_FINTEK_ID
) {
2417 pr_debug("Not a Fintek device\n");
2422 devid
= force_id
? force_id
: superio_inw(sioaddr
, SIO_REG_DEVID
);
2424 case SIO_F71808E_ID
:
2425 sio_data
->type
= f71808e
;
2428 sio_data
->type
= f71858fg
;
2431 sio_data
->type
= f71862fg
;
2434 sio_data
->type
= f71869
;
2437 sio_data
->type
= f71882fg
;
2440 sio_data
->type
= f71889fg
;
2442 case SIO_F71889E_ID
:
2443 sio_data
->type
= f71889ed
;
2445 case SIO_F71889A_ID
:
2446 sio_data
->type
= f71889a
;
2449 sio_data
->type
= f8000
;
2452 sio_data
->type
= f81865f
;
2455 pr_info("Unsupported Fintek device: %04x\n",
2456 (unsigned int)devid
);
2461 if (sio_data
->type
== f71858fg
)
2462 superio_select(sioaddr
, SIO_F71858FG_LD_HWM
);
2464 superio_select(sioaddr
, SIO_F71882FG_LD_HWM
);
2466 if (!(superio_inb(sioaddr
, SIO_REG_ENABLE
) & 0x01)) {
2467 pr_warn("Device not activated\n");
2472 *address
= superio_inw(sioaddr
, SIO_REG_ADDR
);
2473 if (*address
== 0) {
2474 pr_warn("Base address not set\n");
2478 *address
&= ~(REGION_LENGTH
- 1); /* Ignore 3 LSB */
2481 pr_info("Found %s chip at %#x, revision %d\n",
2482 f71882fg_names
[sio_data
->type
], (unsigned int)*address
,
2483 (int)superio_inb(sioaddr
, SIO_REG_DEVREV
));
2485 superio_exit(sioaddr
);
2489 static int __init
f71882fg_device_add(unsigned short address
,
2490 const struct f71882fg_sio_data
*sio_data
)
2492 struct resource res
= {
2494 .end
= address
+ REGION_LENGTH
- 1,
2495 .flags
= IORESOURCE_IO
,
2499 f71882fg_pdev
= platform_device_alloc(DRVNAME
, address
);
2503 res
.name
= f71882fg_pdev
->name
;
2504 err
= acpi_check_resource_conflict(&res
);
2506 goto exit_device_put
;
2508 err
= platform_device_add_resources(f71882fg_pdev
, &res
, 1);
2510 pr_err("Device resource addition failed\n");
2511 goto exit_device_put
;
2514 err
= platform_device_add_data(f71882fg_pdev
, sio_data
,
2515 sizeof(struct f71882fg_sio_data
));
2517 pr_err("Platform data allocation failed\n");
2518 goto exit_device_put
;
2521 err
= platform_device_add(f71882fg_pdev
);
2523 pr_err("Device addition failed\n");
2524 goto exit_device_put
;
2530 platform_device_put(f71882fg_pdev
);
2535 static int __init
f71882fg_init(void)
2538 unsigned short address
;
2539 struct f71882fg_sio_data sio_data
;
2541 memset(&sio_data
, 0, sizeof(sio_data
));
2543 if (f71882fg_find(0x2e, &address
, &sio_data
) &&
2544 f71882fg_find(0x4e, &address
, &sio_data
))
2547 err
= platform_driver_register(&f71882fg_driver
);
2551 err
= f71882fg_device_add(address
, &sio_data
);
2558 platform_driver_unregister(&f71882fg_driver
);
2563 static void __exit
f71882fg_exit(void)
2565 platform_device_unregister(f71882fg_pdev
);
2566 platform_driver_unregister(&f71882fg_driver
);
2569 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2570 MODULE_AUTHOR("Hans Edgington, Hans de Goede (hdegoede@redhat.com)");
2571 MODULE_LICENSE("GPL");
2573 module_init(f71882fg_init
);
2574 module_exit(f71882fg_exit
);