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_F8000_ID 0x0581 /* Chipset ID */
59 #define REGION_LENGTH 8
60 #define ADDR_REG_OFFSET 5
61 #define DATA_REG_OFFSET 6
63 #define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */
64 #define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */
65 #define F71882FG_REG_IN(nr) (0x20 + (nr))
66 #define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */
68 #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
69 #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
70 #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
71 #define F71882FG_REG_FAN_STATUS 0x92
72 #define F71882FG_REG_FAN_BEEP 0x93
74 #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
75 #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
76 #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
77 #define F71882FG_REG_TEMP_STATUS 0x62
78 #define F71882FG_REG_TEMP_BEEP 0x63
79 #define F71882FG_REG_TEMP_CONFIG 0x69
80 #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
81 #define F71882FG_REG_TEMP_TYPE 0x6B
82 #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
84 #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
85 #define F71882FG_REG_PWM_TYPE 0x94
86 #define F71882FG_REG_PWM_ENABLE 0x96
88 #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
90 #define F71882FG_REG_FAN_FAULT_T 0x9F
91 #define F71882FG_FAN_NEG_TEMP_EN 0x20
92 #define F71882FG_FAN_PROG_SEL 0x80
94 #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
95 #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
96 #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
98 #define F71882FG_REG_START 0x01
100 #define F71882FG_MAX_INS 9
102 #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
104 static unsigned short force_id
;
105 module_param(force_id
, ushort
, 0);
106 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
108 enum chips
{ f71808e
, f71858fg
, f71862fg
, f71869
, f71882fg
, f71889fg
,
111 static const char *f71882fg_names
[] = {
115 "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
122 static const char f71882fg_has_in
[8][F71882FG_MAX_INS
] = {
123 { 1, 1, 1, 1, 1, 1, 0, 1, 1 }, /* f71808e */
124 { 1, 1, 1, 0, 0, 0, 0, 0, 0 }, /* f71858fg */
125 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71862fg */
126 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71869 */
127 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71882fg */
128 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71889fg */
129 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71889ed */
130 { 1, 1, 1, 0, 0, 0, 0, 0, 0 }, /* f8000 */
133 static const char f71882fg_has_in1_alarm
[8] = {
144 static const char f71882fg_has_beep
[8] = {
155 static struct platform_device
*f71882fg_pdev
;
157 /* Super-I/O Function prototypes */
158 static inline int superio_inb(int base
, int reg
);
159 static inline int superio_inw(int base
, int reg
);
160 static inline int superio_enter(int base
);
161 static inline void superio_select(int base
, int ld
);
162 static inline void superio_exit(int base
);
164 struct f71882fg_sio_data
{
168 struct f71882fg_data
{
171 struct device
*hwmon_dev
;
173 struct mutex update_lock
;
174 int temp_start
; /* temp numbering start (0 or 1) */
175 char valid
; /* !=0 if following fields are valid */
176 char auto_point_temp_signed
;
177 unsigned long last_updated
; /* In jiffies */
178 unsigned long last_limits
; /* In jiffies */
180 /* Register Values */
181 u8 in
[F71882FG_MAX_INS
];
187 u16 fan_full_speed
[4];
190 /* Note: all models have max 3 temperature channels, but on some
191 they are addressed as 0-2 and on others as 1-3, so for coding
192 convenience we reserve space for 4 channels */
196 u8 temp_hyst
[2]; /* 2 hysts stored per reg */
204 u8 pwm_auto_point_hyst
[2];
205 u8 pwm_auto_point_mapping
[4];
206 u8 pwm_auto_point_pwm
[4][5];
207 s8 pwm_auto_point_temp
[4][4];
211 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
213 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
214 *devattr
, char *buf
);
215 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
216 *devattr
, const char *buf
, size_t count
);
217 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
218 *devattr
, char *buf
);
219 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
220 *devattr
, const char *buf
, size_t count
);
221 static ssize_t
show_in_alarm(struct device
*dev
, struct device_attribute
222 *devattr
, char *buf
);
224 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
226 static ssize_t
show_fan_full_speed(struct device
*dev
,
227 struct device_attribute
*devattr
, char *buf
);
228 static ssize_t
store_fan_full_speed(struct device
*dev
,
229 struct device_attribute
*devattr
, const char *buf
, size_t count
);
230 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
231 *devattr
, char *buf
);
232 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
233 *devattr
, const char *buf
, size_t count
);
234 static ssize_t
show_fan_alarm(struct device
*dev
, struct device_attribute
235 *devattr
, char *buf
);
237 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
238 *devattr
, char *buf
);
239 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
240 *devattr
, char *buf
);
241 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
242 *devattr
, const char *buf
, size_t count
);
243 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
244 *devattr
, char *buf
);
245 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
246 *devattr
, const char *buf
, size_t count
);
247 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
248 *devattr
, char *buf
);
249 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
250 *devattr
, const char *buf
, size_t count
);
251 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
252 *devattr
, char *buf
);
253 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
254 *devattr
, char *buf
);
255 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
256 *devattr
, char *buf
);
257 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
258 *devattr
, const char *buf
, size_t count
);
259 static ssize_t
show_temp_alarm(struct device
*dev
, struct device_attribute
260 *devattr
, char *buf
);
261 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
262 *devattr
, char *buf
);
263 /* PWM and Auto point control */
264 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*devattr
,
266 static ssize_t
store_pwm(struct device
*dev
, struct device_attribute
*devattr
,
267 const char *buf
, size_t count
);
268 static ssize_t
show_pwm_enable(struct device
*dev
,
269 struct device_attribute
*devattr
, char *buf
);
270 static ssize_t
store_pwm_enable(struct device
*dev
,
271 struct device_attribute
*devattr
, const char *buf
, size_t count
);
272 static ssize_t
show_pwm_interpolate(struct device
*dev
,
273 struct device_attribute
*devattr
, char *buf
);
274 static ssize_t
store_pwm_interpolate(struct device
*dev
,
275 struct device_attribute
*devattr
, const char *buf
, size_t count
);
276 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
277 struct device_attribute
*devattr
, char *buf
);
278 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
279 struct device_attribute
*devattr
, const char *buf
, size_t count
);
280 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
281 struct device_attribute
*devattr
, char *buf
);
282 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
283 struct device_attribute
*devattr
, const char *buf
, size_t count
);
284 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
285 struct device_attribute
*devattr
, char *buf
);
286 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
287 struct device_attribute
*devattr
, const char *buf
, size_t count
);
288 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
289 struct device_attribute
*devattr
, char *buf
);
290 static ssize_t
store_pwm_auto_point_temp(struct device
*dev
,
291 struct device_attribute
*devattr
, const char *buf
, size_t count
);
293 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
296 static int __devinit
f71882fg_probe(struct platform_device
* pdev
);
297 static int f71882fg_remove(struct platform_device
*pdev
);
299 static struct platform_driver f71882fg_driver
= {
301 .owner
= THIS_MODULE
,
304 .probe
= f71882fg_probe
,
305 .remove
= f71882fg_remove
,
308 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
310 /* Temp attr for the f71858fg, the f71858fg is special as it has its
311 temperature indexes start at 0 (the others start at 1) */
312 static struct sensor_device_attribute_2 f71858fg_temp_attr
[] = {
313 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
314 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
315 store_temp_max
, 0, 0),
316 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
317 store_temp_max_hyst
, 0, 0),
318 SENSOR_ATTR_2(temp1_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 0),
319 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
320 store_temp_crit
, 0, 0),
321 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
323 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
324 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
325 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
326 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
327 store_temp_max
, 0, 1),
328 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
329 store_temp_max_hyst
, 0, 1),
330 SENSOR_ATTR_2(temp2_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
331 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
332 store_temp_crit
, 0, 1),
333 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
335 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
336 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
337 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
338 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
339 store_temp_max
, 0, 2),
340 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
341 store_temp_max_hyst
, 0, 2),
342 SENSOR_ATTR_2(temp3_max_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
343 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
344 store_temp_crit
, 0, 2),
345 SENSOR_ATTR_2(temp3_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
347 SENSOR_ATTR_2(temp3_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
348 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
351 /* Temp attr for the standard models */
352 static struct sensor_device_attribute_2 fxxxx_temp_attr
[3][9] = { {
353 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
354 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
355 store_temp_max
, 0, 1),
356 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
357 store_temp_max_hyst
, 0, 1),
358 /* Should really be temp1_max_alarm, but older versions did not handle
359 the max and crit alarms separately and lm_sensors v2 depends on the
360 presence of temp#_alarm files. The same goes for temp2/3 _alarm. */
361 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 1),
362 SENSOR_ATTR_2(temp1_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
363 store_temp_crit
, 0, 1),
364 SENSOR_ATTR_2(temp1_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
366 SENSOR_ATTR_2(temp1_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
367 SENSOR_ATTR_2(temp1_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 1),
368 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
370 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
371 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
372 store_temp_max
, 0, 2),
373 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
374 store_temp_max_hyst
, 0, 2),
375 /* Should be temp2_max_alarm, see temp1_alarm note */
376 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 2),
377 SENSOR_ATTR_2(temp2_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
378 store_temp_crit
, 0, 2),
379 SENSOR_ATTR_2(temp2_crit_hyst
, S_IRUGO
, show_temp_crit_hyst
, NULL
,
381 SENSOR_ATTR_2(temp2_crit_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
382 SENSOR_ATTR_2(temp2_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 2),
383 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
385 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 3),
386 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_max
,
387 store_temp_max
, 0, 3),
388 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max_hyst
,
389 store_temp_max_hyst
, 0, 3),
390 /* Should be temp3_max_alarm, see temp1_alarm note */
391 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 3),
392 SENSOR_ATTR_2(temp3_crit
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
393 store_temp_crit
, 0, 3),
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, 7),
397 SENSOR_ATTR_2(temp3_type
, S_IRUGO
, show_temp_type
, NULL
, 0, 3),
398 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 3),
401 /* Temp attr for models which can beep on temp alarm */
402 static struct sensor_device_attribute_2 fxxxx_temp_beep_attr
[3][2] = { {
403 SENSOR_ATTR_2(temp1_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
404 store_temp_beep
, 0, 1),
405 SENSOR_ATTR_2(temp1_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
406 store_temp_beep
, 0, 5),
408 SENSOR_ATTR_2(temp2_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
409 store_temp_beep
, 0, 2),
410 SENSOR_ATTR_2(temp2_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
411 store_temp_beep
, 0, 6),
413 SENSOR_ATTR_2(temp3_max_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
414 store_temp_beep
, 0, 3),
415 SENSOR_ATTR_2(temp3_crit_beep
, S_IRUGO
|S_IWUSR
, show_temp_beep
,
416 store_temp_beep
, 0, 7),
419 /* Temp attr for the f8000
420 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
421 is used as hysteresis value to clear alarms
422 Also like the f71858fg its temperature indexes start at 0
424 static struct sensor_device_attribute_2 f8000_temp_attr
[] = {
425 SENSOR_ATTR_2(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0, 0),
426 SENSOR_ATTR_2(temp1_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
427 store_temp_crit
, 0, 0),
428 SENSOR_ATTR_2(temp1_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
429 store_temp_max
, 0, 0),
430 SENSOR_ATTR_2(temp1_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 4),
431 SENSOR_ATTR_2(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 0),
432 SENSOR_ATTR_2(temp2_input
, S_IRUGO
, show_temp
, NULL
, 0, 1),
433 SENSOR_ATTR_2(temp2_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
434 store_temp_crit
, 0, 1),
435 SENSOR_ATTR_2(temp2_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
436 store_temp_max
, 0, 1),
437 SENSOR_ATTR_2(temp2_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 5),
438 SENSOR_ATTR_2(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 1),
439 SENSOR_ATTR_2(temp3_input
, S_IRUGO
, show_temp
, NULL
, 0, 2),
440 SENSOR_ATTR_2(temp3_max
, S_IRUGO
|S_IWUSR
, show_temp_crit
,
441 store_temp_crit
, 0, 2),
442 SENSOR_ATTR_2(temp3_max_hyst
, S_IRUGO
|S_IWUSR
, show_temp_max
,
443 store_temp_max
, 0, 2),
444 SENSOR_ATTR_2(temp3_alarm
, S_IRUGO
, show_temp_alarm
, NULL
, 0, 6),
445 SENSOR_ATTR_2(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0, 2),
448 /* in attr for all models */
449 static struct sensor_device_attribute_2 fxxxx_in_attr
[] = {
450 SENSOR_ATTR_2(in0_input
, S_IRUGO
, show_in
, NULL
, 0, 0),
451 SENSOR_ATTR_2(in1_input
, S_IRUGO
, show_in
, NULL
, 0, 1),
452 SENSOR_ATTR_2(in2_input
, S_IRUGO
, show_in
, NULL
, 0, 2),
453 SENSOR_ATTR_2(in3_input
, S_IRUGO
, show_in
, NULL
, 0, 3),
454 SENSOR_ATTR_2(in4_input
, S_IRUGO
, show_in
, NULL
, 0, 4),
455 SENSOR_ATTR_2(in5_input
, S_IRUGO
, show_in
, NULL
, 0, 5),
456 SENSOR_ATTR_2(in6_input
, S_IRUGO
, show_in
, NULL
, 0, 6),
457 SENSOR_ATTR_2(in7_input
, S_IRUGO
, show_in
, NULL
, 0, 7),
458 SENSOR_ATTR_2(in8_input
, S_IRUGO
, show_in
, NULL
, 0, 8),
461 /* For models with in1 alarm capability */
462 static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr
[] = {
463 SENSOR_ATTR_2(in1_max
, S_IRUGO
|S_IWUSR
, show_in_max
, store_in_max
,
465 SENSOR_ATTR_2(in1_beep
, S_IRUGO
|S_IWUSR
, show_in_beep
, store_in_beep
,
467 SENSOR_ATTR_2(in1_alarm
, S_IRUGO
, show_in_alarm
, NULL
, 0, 1),
470 /* Fan / PWM attr common to all models */
471 static struct sensor_device_attribute_2 fxxxx_fan_attr
[4][6] = { {
472 SENSOR_ATTR_2(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0, 0),
473 SENSOR_ATTR_2(fan1_full_speed
, S_IRUGO
|S_IWUSR
,
475 store_fan_full_speed
, 0, 0),
476 SENSOR_ATTR_2(fan1_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 0),
477 SENSOR_ATTR_2(pwm1
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 0),
478 SENSOR_ATTR_2(pwm1_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
479 store_pwm_enable
, 0, 0),
480 SENSOR_ATTR_2(pwm1_interpolate
, S_IRUGO
|S_IWUSR
,
481 show_pwm_interpolate
, store_pwm_interpolate
, 0, 0),
483 SENSOR_ATTR_2(fan2_input
, S_IRUGO
, show_fan
, NULL
, 0, 1),
484 SENSOR_ATTR_2(fan2_full_speed
, S_IRUGO
|S_IWUSR
,
486 store_fan_full_speed
, 0, 1),
487 SENSOR_ATTR_2(fan2_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 1),
488 SENSOR_ATTR_2(pwm2
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 1),
489 SENSOR_ATTR_2(pwm2_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
490 store_pwm_enable
, 0, 1),
491 SENSOR_ATTR_2(pwm2_interpolate
, S_IRUGO
|S_IWUSR
,
492 show_pwm_interpolate
, store_pwm_interpolate
, 0, 1),
494 SENSOR_ATTR_2(fan3_input
, S_IRUGO
, show_fan
, NULL
, 0, 2),
495 SENSOR_ATTR_2(fan3_full_speed
, S_IRUGO
|S_IWUSR
,
497 store_fan_full_speed
, 0, 2),
498 SENSOR_ATTR_2(fan3_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 2),
499 SENSOR_ATTR_2(pwm3
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 2),
500 SENSOR_ATTR_2(pwm3_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
501 store_pwm_enable
, 0, 2),
502 SENSOR_ATTR_2(pwm3_interpolate
, S_IRUGO
|S_IWUSR
,
503 show_pwm_interpolate
, store_pwm_interpolate
, 0, 2),
505 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
506 SENSOR_ATTR_2(fan4_full_speed
, S_IRUGO
|S_IWUSR
,
508 store_fan_full_speed
, 0, 3),
509 SENSOR_ATTR_2(fan4_alarm
, S_IRUGO
, show_fan_alarm
, NULL
, 0, 3),
510 SENSOR_ATTR_2(pwm4
, S_IRUGO
|S_IWUSR
, show_pwm
, store_pwm
, 0, 3),
511 SENSOR_ATTR_2(pwm4_enable
, S_IRUGO
|S_IWUSR
, show_pwm_enable
,
512 store_pwm_enable
, 0, 3),
513 SENSOR_ATTR_2(pwm4_interpolate
, S_IRUGO
|S_IWUSR
,
514 show_pwm_interpolate
, store_pwm_interpolate
, 0, 3),
517 /* Attr for models which can beep on Fan alarm */
518 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr
[] = {
519 SENSOR_ATTR_2(fan1_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
520 store_fan_beep
, 0, 0),
521 SENSOR_ATTR_2(fan2_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
522 store_fan_beep
, 0, 1),
523 SENSOR_ATTR_2(fan3_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
524 store_fan_beep
, 0, 2),
525 SENSOR_ATTR_2(fan4_beep
, S_IRUGO
|S_IWUSR
, show_fan_beep
,
526 store_fan_beep
, 0, 3),
529 /* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
531 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr
[] = {
532 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
533 show_pwm_auto_point_channel
,
534 store_pwm_auto_point_channel
, 0, 0),
535 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
536 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
538 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
539 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
541 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
542 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
544 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
545 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
547 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
548 show_pwm_auto_point_temp_hyst
,
549 store_pwm_auto_point_temp_hyst
,
551 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
552 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
554 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
555 show_pwm_auto_point_channel
,
556 store_pwm_auto_point_channel
, 0, 1),
557 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
558 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
560 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
561 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
563 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
564 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
566 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
567 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
569 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
570 show_pwm_auto_point_temp_hyst
,
571 store_pwm_auto_point_temp_hyst
,
573 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
574 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
576 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
577 show_pwm_auto_point_channel
,
578 store_pwm_auto_point_channel
, 0, 2),
579 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
580 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
582 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
583 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
585 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
586 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
588 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
589 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
591 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
592 show_pwm_auto_point_temp_hyst
,
593 store_pwm_auto_point_temp_hyst
,
595 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
596 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
599 /* PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
600 pwm setting when the temperature is above the pwmX_auto_point1_temp can be
601 programmed instead of being hardcoded to 0xff */
602 static struct sensor_device_attribute_2 f71869_auto_pwm_attr
[] = {
603 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
604 show_pwm_auto_point_channel
,
605 store_pwm_auto_point_channel
, 0, 0),
606 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
607 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
609 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
610 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
612 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
613 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
615 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
616 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
618 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
619 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
621 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
622 show_pwm_auto_point_temp_hyst
,
623 store_pwm_auto_point_temp_hyst
,
625 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
626 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
628 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
629 show_pwm_auto_point_channel
,
630 store_pwm_auto_point_channel
, 0, 1),
631 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
632 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
634 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
635 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
637 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
638 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
640 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
641 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
643 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
644 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
646 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
647 show_pwm_auto_point_temp_hyst
,
648 store_pwm_auto_point_temp_hyst
,
650 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
651 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
653 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
654 show_pwm_auto_point_channel
,
655 store_pwm_auto_point_channel
, 0, 2),
656 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
657 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
659 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
660 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
662 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
663 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
665 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
666 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
668 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
669 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
671 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
672 show_pwm_auto_point_temp_hyst
,
673 store_pwm_auto_point_temp_hyst
,
675 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
676 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
679 /* PWM attr for the standard models */
680 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr
[4][14] = { {
681 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
682 show_pwm_auto_point_channel
,
683 store_pwm_auto_point_channel
, 0, 0),
684 SENSOR_ATTR_2(pwm1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
685 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
687 SENSOR_ATTR_2(pwm1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
688 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
690 SENSOR_ATTR_2(pwm1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
691 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
693 SENSOR_ATTR_2(pwm1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
694 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
696 SENSOR_ATTR_2(pwm1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
697 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
699 SENSOR_ATTR_2(pwm1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
700 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
702 SENSOR_ATTR_2(pwm1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
703 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
705 SENSOR_ATTR_2(pwm1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
706 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
708 SENSOR_ATTR_2(pwm1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
709 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
711 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
712 show_pwm_auto_point_temp_hyst
,
713 store_pwm_auto_point_temp_hyst
,
715 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst
, S_IRUGO
,
716 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
717 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst
, S_IRUGO
,
718 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
719 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst
, S_IRUGO
,
720 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
722 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
723 show_pwm_auto_point_channel
,
724 store_pwm_auto_point_channel
, 0, 1),
725 SENSOR_ATTR_2(pwm2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
726 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
728 SENSOR_ATTR_2(pwm2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
729 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
731 SENSOR_ATTR_2(pwm2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
732 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
734 SENSOR_ATTR_2(pwm2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
735 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
737 SENSOR_ATTR_2(pwm2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
738 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
740 SENSOR_ATTR_2(pwm2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
741 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
743 SENSOR_ATTR_2(pwm2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
744 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
746 SENSOR_ATTR_2(pwm2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
747 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
749 SENSOR_ATTR_2(pwm2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
750 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
752 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
753 show_pwm_auto_point_temp_hyst
,
754 store_pwm_auto_point_temp_hyst
,
756 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst
, S_IRUGO
,
757 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
758 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst
, S_IRUGO
,
759 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
760 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst
, S_IRUGO
,
761 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
763 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
764 show_pwm_auto_point_channel
,
765 store_pwm_auto_point_channel
, 0, 2),
766 SENSOR_ATTR_2(pwm3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
767 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
769 SENSOR_ATTR_2(pwm3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
770 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
772 SENSOR_ATTR_2(pwm3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
773 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
775 SENSOR_ATTR_2(pwm3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
776 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
778 SENSOR_ATTR_2(pwm3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
779 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
781 SENSOR_ATTR_2(pwm3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
782 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
784 SENSOR_ATTR_2(pwm3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
785 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
787 SENSOR_ATTR_2(pwm3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
788 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
790 SENSOR_ATTR_2(pwm3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
791 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
793 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
794 show_pwm_auto_point_temp_hyst
,
795 store_pwm_auto_point_temp_hyst
,
797 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst
, S_IRUGO
,
798 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
799 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst
, S_IRUGO
,
800 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
801 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst
, S_IRUGO
,
802 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
804 SENSOR_ATTR_2(pwm4_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
805 show_pwm_auto_point_channel
,
806 store_pwm_auto_point_channel
, 0, 3),
807 SENSOR_ATTR_2(pwm4_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
808 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
810 SENSOR_ATTR_2(pwm4_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
811 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
813 SENSOR_ATTR_2(pwm4_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
814 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
816 SENSOR_ATTR_2(pwm4_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
817 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
819 SENSOR_ATTR_2(pwm4_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
820 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
822 SENSOR_ATTR_2(pwm4_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
823 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
825 SENSOR_ATTR_2(pwm4_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
826 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
828 SENSOR_ATTR_2(pwm4_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
829 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
831 SENSOR_ATTR_2(pwm4_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
832 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
834 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
835 show_pwm_auto_point_temp_hyst
,
836 store_pwm_auto_point_temp_hyst
,
838 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst
, S_IRUGO
,
839 show_pwm_auto_point_temp_hyst
, NULL
, 1, 3),
840 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst
, S_IRUGO
,
841 show_pwm_auto_point_temp_hyst
, NULL
, 2, 3),
842 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst
, S_IRUGO
,
843 show_pwm_auto_point_temp_hyst
, NULL
, 3, 3),
846 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
847 static struct sensor_device_attribute_2 f8000_fan_attr
[] = {
848 SENSOR_ATTR_2(fan4_input
, S_IRUGO
, show_fan
, NULL
, 0, 3),
851 /* PWM attr for the f8000, zones mapped to temp instead of to pwm!
852 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
853 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
854 static struct sensor_device_attribute_2 f8000_auto_pwm_attr
[] = {
855 SENSOR_ATTR_2(pwm1_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
856 show_pwm_auto_point_channel
,
857 store_pwm_auto_point_channel
, 0, 0),
858 SENSOR_ATTR_2(temp1_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
859 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
861 SENSOR_ATTR_2(temp1_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
862 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
864 SENSOR_ATTR_2(temp1_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
865 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
867 SENSOR_ATTR_2(temp1_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
868 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
870 SENSOR_ATTR_2(temp1_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
871 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
873 SENSOR_ATTR_2(temp1_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
874 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
876 SENSOR_ATTR_2(temp1_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
877 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
879 SENSOR_ATTR_2(temp1_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
880 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
882 SENSOR_ATTR_2(temp1_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
883 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
885 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
886 show_pwm_auto_point_temp_hyst
,
887 store_pwm_auto_point_temp_hyst
,
889 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst
, S_IRUGO
,
890 show_pwm_auto_point_temp_hyst
, NULL
, 1, 2),
891 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst
, S_IRUGO
,
892 show_pwm_auto_point_temp_hyst
, NULL
, 2, 2),
893 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst
, S_IRUGO
,
894 show_pwm_auto_point_temp_hyst
, NULL
, 3, 2),
896 SENSOR_ATTR_2(pwm2_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
897 show_pwm_auto_point_channel
,
898 store_pwm_auto_point_channel
, 0, 1),
899 SENSOR_ATTR_2(temp2_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
900 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
902 SENSOR_ATTR_2(temp2_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
903 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
905 SENSOR_ATTR_2(temp2_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
906 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
908 SENSOR_ATTR_2(temp2_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
909 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
911 SENSOR_ATTR_2(temp2_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
912 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
914 SENSOR_ATTR_2(temp2_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
915 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
917 SENSOR_ATTR_2(temp2_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
918 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
920 SENSOR_ATTR_2(temp2_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
921 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
923 SENSOR_ATTR_2(temp2_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
924 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
926 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
927 show_pwm_auto_point_temp_hyst
,
928 store_pwm_auto_point_temp_hyst
,
930 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst
, S_IRUGO
,
931 show_pwm_auto_point_temp_hyst
, NULL
, 1, 0),
932 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst
, S_IRUGO
,
933 show_pwm_auto_point_temp_hyst
, NULL
, 2, 0),
934 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst
, S_IRUGO
,
935 show_pwm_auto_point_temp_hyst
, NULL
, 3, 0),
937 SENSOR_ATTR_2(pwm3_auto_channels_temp
, S_IRUGO
|S_IWUSR
,
938 show_pwm_auto_point_channel
,
939 store_pwm_auto_point_channel
, 0, 2),
940 SENSOR_ATTR_2(temp3_auto_point1_pwm
, S_IRUGO
|S_IWUSR
,
941 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
943 SENSOR_ATTR_2(temp3_auto_point2_pwm
, S_IRUGO
|S_IWUSR
,
944 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
946 SENSOR_ATTR_2(temp3_auto_point3_pwm
, S_IRUGO
|S_IWUSR
,
947 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
949 SENSOR_ATTR_2(temp3_auto_point4_pwm
, S_IRUGO
|S_IWUSR
,
950 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
952 SENSOR_ATTR_2(temp3_auto_point5_pwm
, S_IRUGO
|S_IWUSR
,
953 show_pwm_auto_point_pwm
, store_pwm_auto_point_pwm
,
955 SENSOR_ATTR_2(temp3_auto_point1_temp
, S_IRUGO
|S_IWUSR
,
956 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
958 SENSOR_ATTR_2(temp3_auto_point2_temp
, S_IRUGO
|S_IWUSR
,
959 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
961 SENSOR_ATTR_2(temp3_auto_point3_temp
, S_IRUGO
|S_IWUSR
,
962 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
964 SENSOR_ATTR_2(temp3_auto_point4_temp
, S_IRUGO
|S_IWUSR
,
965 show_pwm_auto_point_temp
, store_pwm_auto_point_temp
,
967 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst
, S_IRUGO
|S_IWUSR
,
968 show_pwm_auto_point_temp_hyst
,
969 store_pwm_auto_point_temp_hyst
,
971 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst
, S_IRUGO
,
972 show_pwm_auto_point_temp_hyst
, NULL
, 1, 1),
973 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst
, S_IRUGO
,
974 show_pwm_auto_point_temp_hyst
, NULL
, 2, 1),
975 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst
, S_IRUGO
,
976 show_pwm_auto_point_temp_hyst
, NULL
, 3, 1),
979 /* Super I/O functions */
980 static inline int superio_inb(int base
, int reg
)
983 return inb(base
+ 1);
986 static int superio_inw(int base
, int reg
)
989 val
= superio_inb(base
, reg
) << 8;
990 val
|= superio_inb(base
, reg
+ 1);
994 static inline int superio_enter(int base
)
996 /* Don't step on other drivers' I/O space by accident */
997 if (!request_muxed_region(base
, 2, DRVNAME
)) {
998 pr_err("I/O address 0x%04x already in use\n", base
);
1002 /* according to the datasheet the key must be send twice! */
1003 outb(SIO_UNLOCK_KEY
, base
);
1004 outb(SIO_UNLOCK_KEY
, base
);
1009 static inline void superio_select(int base
, int ld
)
1011 outb(SIO_REG_LDSEL
, base
);
1015 static inline void superio_exit(int base
)
1017 outb(SIO_LOCK_KEY
, base
);
1018 release_region(base
, 2);
1021 static inline int fan_from_reg(u16 reg
)
1023 return reg
? (1500000 / reg
) : 0;
1026 static inline u16
fan_to_reg(int fan
)
1028 return fan
? (1500000 / fan
) : 0;
1031 static u8
f71882fg_read8(struct f71882fg_data
*data
, u8 reg
)
1035 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
1036 val
= inb(data
->addr
+ DATA_REG_OFFSET
);
1041 static u16
f71882fg_read16(struct f71882fg_data
*data
, u8 reg
)
1045 val
= f71882fg_read8(data
, reg
) << 8;
1046 val
|= f71882fg_read8(data
, reg
+ 1);
1051 static void f71882fg_write8(struct f71882fg_data
*data
, u8 reg
, u8 val
)
1053 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
1054 outb(val
, data
->addr
+ DATA_REG_OFFSET
);
1057 static void f71882fg_write16(struct f71882fg_data
*data
, u8 reg
, u16 val
)
1059 f71882fg_write8(data
, reg
, val
>> 8);
1060 f71882fg_write8(data
, reg
+ 1, val
& 0xff);
1063 static u16
f71882fg_read_temp(struct f71882fg_data
*data
, int nr
)
1065 if (data
->type
== f71858fg
)
1066 return f71882fg_read16(data
, F71882FG_REG_TEMP(nr
));
1068 return f71882fg_read8(data
, F71882FG_REG_TEMP(nr
));
1071 static struct f71882fg_data
*f71882fg_update_device(struct device
*dev
)
1073 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1075 int nr_fans
= (data
->type
== f71882fg
) ? 4 : 3;
1076 int nr_temps
= (data
->type
== f71808e
) ? 2 : 3;
1078 mutex_lock(&data
->update_lock
);
1080 /* Update once every 60 seconds */
1081 if (time_after(jiffies
, data
->last_limits
+ 60 * HZ
) ||
1083 if (f71882fg_has_in1_alarm
[data
->type
]) {
1085 f71882fg_read8(data
, F71882FG_REG_IN1_HIGH
);
1087 f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1090 /* Get High & boundary temps*/
1091 for (nr
= data
->temp_start
; nr
< nr_temps
+ data
->temp_start
;
1093 data
->temp_ovt
[nr
] = f71882fg_read8(data
,
1094 F71882FG_REG_TEMP_OVT(nr
));
1095 data
->temp_high
[nr
] = f71882fg_read8(data
,
1096 F71882FG_REG_TEMP_HIGH(nr
));
1099 if (data
->type
!= f8000
) {
1100 data
->temp_hyst
[0] = f71882fg_read8(data
,
1101 F71882FG_REG_TEMP_HYST(0));
1102 data
->temp_hyst
[1] = f71882fg_read8(data
,
1103 F71882FG_REG_TEMP_HYST(1));
1105 /* All but the f71858fg / f8000 have this register */
1106 if ((data
->type
!= f71858fg
) && (data
->type
!= f8000
)) {
1107 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_TYPE
);
1108 data
->temp_type
[1] = (reg
& 0x02) ? 2 : 4;
1109 data
->temp_type
[2] = (reg
& 0x04) ? 2 : 4;
1110 data
->temp_type
[3] = (reg
& 0x08) ? 2 : 4;
1113 if (f71882fg_has_beep
[data
->type
]) {
1114 data
->fan_beep
= f71882fg_read8(data
,
1115 F71882FG_REG_FAN_BEEP
);
1116 data
->temp_beep
= f71882fg_read8(data
,
1117 F71882FG_REG_TEMP_BEEP
);
1120 data
->pwm_enable
= f71882fg_read8(data
,
1121 F71882FG_REG_PWM_ENABLE
);
1122 data
->pwm_auto_point_hyst
[0] =
1123 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(0));
1124 data
->pwm_auto_point_hyst
[1] =
1125 f71882fg_read8(data
, F71882FG_REG_FAN_HYST(1));
1127 for (nr
= 0; nr
< nr_fans
; nr
++) {
1128 data
->pwm_auto_point_mapping
[nr
] =
1129 f71882fg_read8(data
,
1130 F71882FG_REG_POINT_MAPPING(nr
));
1132 switch (data
->type
) {
1134 for (point
= 0; point
< 5; point
++) {
1135 data
->pwm_auto_point_pwm
[nr
][point
] =
1136 f71882fg_read8(data
,
1137 F71882FG_REG_POINT_PWM
1140 for (point
= 0; point
< 4; point
++) {
1141 data
->pwm_auto_point_temp
[nr
][point
] =
1142 f71882fg_read8(data
,
1143 F71882FG_REG_POINT_TEMP
1149 data
->pwm_auto_point_pwm
[nr
][0] =
1150 f71882fg_read8(data
,
1151 F71882FG_REG_POINT_PWM(nr
, 0));
1154 data
->pwm_auto_point_pwm
[nr
][1] =
1155 f71882fg_read8(data
,
1156 F71882FG_REG_POINT_PWM
1158 data
->pwm_auto_point_pwm
[nr
][4] =
1159 f71882fg_read8(data
,
1160 F71882FG_REG_POINT_PWM
1162 data
->pwm_auto_point_temp
[nr
][0] =
1163 f71882fg_read8(data
,
1164 F71882FG_REG_POINT_TEMP
1166 data
->pwm_auto_point_temp
[nr
][3] =
1167 f71882fg_read8(data
,
1168 F71882FG_REG_POINT_TEMP
1173 data
->last_limits
= jiffies
;
1176 /* Update every second */
1177 if (time_after(jiffies
, data
->last_updated
+ HZ
) || !data
->valid
) {
1178 data
->temp_status
= f71882fg_read8(data
,
1179 F71882FG_REG_TEMP_STATUS
);
1180 data
->temp_diode_open
= f71882fg_read8(data
,
1181 F71882FG_REG_TEMP_DIODE_OPEN
);
1182 for (nr
= data
->temp_start
; nr
< nr_temps
+ data
->temp_start
;
1184 data
->temp
[nr
] = f71882fg_read_temp(data
, nr
);
1186 data
->fan_status
= f71882fg_read8(data
,
1187 F71882FG_REG_FAN_STATUS
);
1188 for (nr
= 0; nr
< nr_fans
; nr
++) {
1189 data
->fan
[nr
] = f71882fg_read16(data
,
1190 F71882FG_REG_FAN(nr
));
1191 data
->fan_target
[nr
] =
1192 f71882fg_read16(data
, F71882FG_REG_FAN_TARGET(nr
));
1193 data
->fan_full_speed
[nr
] =
1194 f71882fg_read16(data
,
1195 F71882FG_REG_FAN_FULL_SPEED(nr
));
1197 f71882fg_read8(data
, F71882FG_REG_PWM(nr
));
1199 /* The f8000 can monitor 1 more fan, but has no pwm for it */
1200 if (data
->type
== f8000
)
1201 data
->fan
[3] = f71882fg_read16(data
,
1202 F71882FG_REG_FAN(3));
1204 if (f71882fg_has_in1_alarm
[data
->type
])
1205 data
->in_status
= f71882fg_read8(data
,
1206 F71882FG_REG_IN_STATUS
);
1207 for (nr
= 0; nr
< F71882FG_MAX_INS
; nr
++)
1208 if (f71882fg_has_in
[data
->type
][nr
])
1209 data
->in
[nr
] = f71882fg_read8(data
,
1210 F71882FG_REG_IN(nr
));
1212 data
->last_updated
= jiffies
;
1216 mutex_unlock(&data
->update_lock
);
1221 /* Sysfs Interface */
1222 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
1225 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1226 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1227 int speed
= fan_from_reg(data
->fan
[nr
]);
1229 if (speed
== FAN_MIN_DETECT
)
1232 return sprintf(buf
, "%d\n", speed
);
1235 static ssize_t
show_fan_full_speed(struct device
*dev
,
1236 struct device_attribute
*devattr
, char *buf
)
1238 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1239 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1240 int speed
= fan_from_reg(data
->fan_full_speed
[nr
]);
1241 return sprintf(buf
, "%d\n", speed
);
1244 static ssize_t
store_fan_full_speed(struct device
*dev
,
1245 struct device_attribute
*devattr
,
1246 const char *buf
, size_t count
)
1248 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1249 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1252 err
= strict_strtol(buf
, 10, &val
);
1256 val
= SENSORS_LIMIT(val
, 23, 1500000);
1257 val
= fan_to_reg(val
);
1259 mutex_lock(&data
->update_lock
);
1260 f71882fg_write16(data
, F71882FG_REG_FAN_FULL_SPEED(nr
), val
);
1261 data
->fan_full_speed
[nr
] = val
;
1262 mutex_unlock(&data
->update_lock
);
1267 static ssize_t
show_fan_beep(struct device
*dev
, struct device_attribute
1268 *devattr
, char *buf
)
1270 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1271 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1273 if (data
->fan_beep
& (1 << nr
))
1274 return sprintf(buf
, "1\n");
1276 return sprintf(buf
, "0\n");
1279 static ssize_t
store_fan_beep(struct device
*dev
, struct device_attribute
1280 *devattr
, const char *buf
, size_t count
)
1282 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1283 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1286 err
= strict_strtoul(buf
, 10, &val
);
1290 mutex_lock(&data
->update_lock
);
1291 data
->fan_beep
= f71882fg_read8(data
, F71882FG_REG_FAN_BEEP
);
1293 data
->fan_beep
|= 1 << nr
;
1295 data
->fan_beep
&= ~(1 << nr
);
1297 f71882fg_write8(data
, F71882FG_REG_FAN_BEEP
, data
->fan_beep
);
1298 mutex_unlock(&data
->update_lock
);
1303 static ssize_t
show_fan_alarm(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_status
& (1 << nr
))
1310 return sprintf(buf
, "1\n");
1312 return sprintf(buf
, "0\n");
1315 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
1318 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1319 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1321 return sprintf(buf
, "%d\n", data
->in
[nr
] * 8);
1324 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
1325 *devattr
, char *buf
)
1327 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1329 return sprintf(buf
, "%d\n", data
->in1_max
* 8);
1332 static ssize_t
store_in_max(struct device
*dev
, struct device_attribute
1333 *devattr
, const char *buf
, size_t count
)
1335 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1339 err
= strict_strtol(buf
, 10, &val
);
1344 val
= SENSORS_LIMIT(val
, 0, 255);
1346 mutex_lock(&data
->update_lock
);
1347 f71882fg_write8(data
, F71882FG_REG_IN1_HIGH
, val
);
1348 data
->in1_max
= val
;
1349 mutex_unlock(&data
->update_lock
);
1354 static ssize_t
show_in_beep(struct device
*dev
, struct device_attribute
1355 *devattr
, char *buf
)
1357 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1358 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1360 if (data
->in_beep
& (1 << nr
))
1361 return sprintf(buf
, "1\n");
1363 return sprintf(buf
, "0\n");
1366 static ssize_t
store_in_beep(struct device
*dev
, struct device_attribute
1367 *devattr
, const char *buf
, size_t count
)
1369 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1370 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1373 err
= strict_strtoul(buf
, 10, &val
);
1377 mutex_lock(&data
->update_lock
);
1378 data
->in_beep
= f71882fg_read8(data
, F71882FG_REG_IN_BEEP
);
1380 data
->in_beep
|= 1 << nr
;
1382 data
->in_beep
&= ~(1 << nr
);
1384 f71882fg_write8(data
, F71882FG_REG_IN_BEEP
, data
->in_beep
);
1385 mutex_unlock(&data
->update_lock
);
1390 static ssize_t
show_in_alarm(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_status
& (1 << nr
))
1397 return sprintf(buf
, "1\n");
1399 return sprintf(buf
, "0\n");
1402 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*devattr
,
1405 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1406 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1409 if (data
->type
== f71858fg
) {
1410 /* TEMP_TABLE_SEL 1 or 3 ? */
1411 if (data
->temp_config
& 1) {
1412 sign
= data
->temp
[nr
] & 0x0001;
1413 temp
= (data
->temp
[nr
] >> 5) & 0x7ff;
1415 sign
= data
->temp
[nr
] & 0x8000;
1416 temp
= (data
->temp
[nr
] >> 5) & 0x3ff;
1422 temp
= data
->temp
[nr
] * 1000;
1424 return sprintf(buf
, "%d\n", temp
);
1427 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
1428 *devattr
, char *buf
)
1430 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1431 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1433 return sprintf(buf
, "%d\n", data
->temp_high
[nr
] * 1000);
1436 static ssize_t
store_temp_max(struct device
*dev
, struct device_attribute
1437 *devattr
, const char *buf
, size_t count
)
1439 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1440 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1443 err
= strict_strtol(buf
, 10, &val
);
1448 val
= SENSORS_LIMIT(val
, 0, 255);
1450 mutex_lock(&data
->update_lock
);
1451 f71882fg_write8(data
, F71882FG_REG_TEMP_HIGH(nr
), val
);
1452 data
->temp_high
[nr
] = val
;
1453 mutex_unlock(&data
->update_lock
);
1458 static ssize_t
show_temp_max_hyst(struct device
*dev
, struct device_attribute
1459 *devattr
, char *buf
)
1461 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1462 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1465 mutex_lock(&data
->update_lock
);
1467 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1469 temp_max_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1470 temp_max_hyst
= (data
->temp_high
[nr
] - temp_max_hyst
) * 1000;
1471 mutex_unlock(&data
->update_lock
);
1473 return sprintf(buf
, "%d\n", temp_max_hyst
);
1476 static ssize_t
store_temp_max_hyst(struct device
*dev
, struct device_attribute
1477 *devattr
, const char *buf
, size_t count
)
1479 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1480 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1481 ssize_t ret
= count
;
1485 err
= strict_strtol(buf
, 10, &val
);
1491 mutex_lock(&data
->update_lock
);
1493 /* convert abs to relative and check */
1494 data
->temp_high
[nr
] = f71882fg_read8(data
, F71882FG_REG_TEMP_HIGH(nr
));
1495 val
= SENSORS_LIMIT(val
, data
->temp_high
[nr
] - 15,
1496 data
->temp_high
[nr
]);
1497 val
= data
->temp_high
[nr
] - val
;
1499 /* convert value to register contents */
1500 reg
= f71882fg_read8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2));
1502 reg
= (reg
& 0x0f) | (val
<< 4);
1504 reg
= (reg
& 0xf0) | val
;
1505 f71882fg_write8(data
, F71882FG_REG_TEMP_HYST(nr
/ 2), reg
);
1506 data
->temp_hyst
[nr
/ 2] = reg
;
1508 mutex_unlock(&data
->update_lock
);
1512 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
1513 *devattr
, char *buf
)
1515 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1516 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1518 return sprintf(buf
, "%d\n", data
->temp_ovt
[nr
] * 1000);
1521 static ssize_t
store_temp_crit(struct device
*dev
, struct device_attribute
1522 *devattr
, const char *buf
, size_t count
)
1524 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1525 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1528 err
= strict_strtol(buf
, 10, &val
);
1533 val
= SENSORS_LIMIT(val
, 0, 255);
1535 mutex_lock(&data
->update_lock
);
1536 f71882fg_write8(data
, F71882FG_REG_TEMP_OVT(nr
), val
);
1537 data
->temp_ovt
[nr
] = val
;
1538 mutex_unlock(&data
->update_lock
);
1543 static ssize_t
show_temp_crit_hyst(struct device
*dev
, struct device_attribute
1544 *devattr
, char *buf
)
1546 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1547 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1550 mutex_lock(&data
->update_lock
);
1552 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] >> 4;
1554 temp_crit_hyst
= data
->temp_hyst
[nr
/ 2] & 0x0f;
1555 temp_crit_hyst
= (data
->temp_ovt
[nr
] - temp_crit_hyst
) * 1000;
1556 mutex_unlock(&data
->update_lock
);
1558 return sprintf(buf
, "%d\n", temp_crit_hyst
);
1561 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
1562 *devattr
, char *buf
)
1564 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1565 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1567 return sprintf(buf
, "%d\n", data
->temp_type
[nr
]);
1570 static ssize_t
show_temp_beep(struct device
*dev
, struct device_attribute
1571 *devattr
, char *buf
)
1573 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1574 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1576 if (data
->temp_beep
& (1 << nr
))
1577 return sprintf(buf
, "1\n");
1579 return sprintf(buf
, "0\n");
1582 static ssize_t
store_temp_beep(struct device
*dev
, struct device_attribute
1583 *devattr
, const char *buf
, size_t count
)
1585 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1586 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1589 err
= strict_strtoul(buf
, 10, &val
);
1593 mutex_lock(&data
->update_lock
);
1594 data
->temp_beep
= f71882fg_read8(data
, F71882FG_REG_TEMP_BEEP
);
1596 data
->temp_beep
|= 1 << nr
;
1598 data
->temp_beep
&= ~(1 << nr
);
1600 f71882fg_write8(data
, F71882FG_REG_TEMP_BEEP
, data
->temp_beep
);
1601 mutex_unlock(&data
->update_lock
);
1606 static ssize_t
show_temp_alarm(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_status
& (1 << nr
))
1613 return sprintf(buf
, "1\n");
1615 return sprintf(buf
, "0\n");
1618 static ssize_t
show_temp_fault(struct device
*dev
, struct device_attribute
1619 *devattr
, char *buf
)
1621 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1622 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1624 if (data
->temp_diode_open
& (1 << nr
))
1625 return sprintf(buf
, "1\n");
1627 return sprintf(buf
, "0\n");
1630 static ssize_t
show_pwm(struct device
*dev
,
1631 struct device_attribute
*devattr
, char *buf
)
1633 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1634 int val
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1635 mutex_lock(&data
->update_lock
);
1636 if (data
->pwm_enable
& (1 << (2 * nr
)))
1638 val
= data
->pwm
[nr
];
1641 val
= 255 * fan_from_reg(data
->fan_target
[nr
])
1642 / fan_from_reg(data
->fan_full_speed
[nr
]);
1644 mutex_unlock(&data
->update_lock
);
1645 return sprintf(buf
, "%d\n", val
);
1648 static ssize_t
store_pwm(struct device
*dev
,
1649 struct device_attribute
*devattr
, const char *buf
,
1652 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1653 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1656 err
= strict_strtol(buf
, 10, &val
);
1660 val
= SENSORS_LIMIT(val
, 0, 255);
1662 mutex_lock(&data
->update_lock
);
1663 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1664 if ((data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 3) != 2) ||
1665 (data
->type
!= f8000
&& !((data
->pwm_enable
>> 2 * nr
) & 2))) {
1669 if (data
->pwm_enable
& (1 << (2 * nr
))) {
1671 f71882fg_write8(data
, F71882FG_REG_PWM(nr
), val
);
1672 data
->pwm
[nr
] = val
;
1675 int target
, full_speed
;
1676 full_speed
= f71882fg_read16(data
,
1677 F71882FG_REG_FAN_FULL_SPEED(nr
));
1678 target
= fan_to_reg(val
* fan_from_reg(full_speed
) / 255);
1679 f71882fg_write16(data
, F71882FG_REG_FAN_TARGET(nr
), target
);
1680 data
->fan_target
[nr
] = target
;
1681 data
->fan_full_speed
[nr
] = full_speed
;
1684 mutex_unlock(&data
->update_lock
);
1689 static ssize_t
show_pwm_enable(struct device
*dev
,
1690 struct device_attribute
*devattr
, char *buf
)
1693 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1694 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1696 switch ((data
->pwm_enable
>> 2 * nr
) & 3) {
1699 result
= 2; /* Normal auto mode */
1702 result
= 1; /* Manual mode */
1705 if (data
->type
== f8000
)
1706 result
= 3; /* Thermostat mode */
1708 result
= 1; /* Manual mode */
1712 return sprintf(buf
, "%d\n", result
);
1715 static ssize_t
store_pwm_enable(struct device
*dev
, struct device_attribute
1716 *devattr
, const char *buf
, size_t count
)
1718 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1719 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1722 err
= strict_strtol(buf
, 10, &val
);
1726 /* Special case for F8000 pwm channel 3 which only does auto mode */
1727 if (data
->type
== f8000
&& nr
== 2 && val
!= 2)
1730 mutex_lock(&data
->update_lock
);
1731 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1732 /* Special case for F8000 auto PWM mode / Thermostat mode */
1733 if (data
->type
== f8000
&& ((data
->pwm_enable
>> 2 * nr
) & 1)) {
1736 data
->pwm_enable
&= ~(2 << (2 * nr
));
1737 break; /* Normal auto mode */
1739 data
->pwm_enable
|= 2 << (2 * nr
);
1740 break; /* Thermostat mode */
1748 /* The f71858fg does not support manual RPM mode */
1749 if (data
->type
== f71858fg
&&
1750 ((data
->pwm_enable
>> (2 * nr
)) & 1)) {
1754 data
->pwm_enable
|= 2 << (2 * nr
);
1757 data
->pwm_enable
&= ~(2 << (2 * nr
));
1758 break; /* Normal auto mode */
1764 f71882fg_write8(data
, F71882FG_REG_PWM_ENABLE
, data
->pwm_enable
);
1766 mutex_unlock(&data
->update_lock
);
1771 static ssize_t
show_pwm_auto_point_pwm(struct device
*dev
,
1772 struct device_attribute
*devattr
,
1776 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1777 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1778 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1780 mutex_lock(&data
->update_lock
);
1781 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1783 result
= data
->pwm_auto_point_pwm
[pwm
][point
];
1786 result
= 32 * 255 / (32 + data
->pwm_auto_point_pwm
[pwm
][point
]);
1788 mutex_unlock(&data
->update_lock
);
1790 return sprintf(buf
, "%d\n", result
);
1793 static ssize_t
store_pwm_auto_point_pwm(struct device
*dev
,
1794 struct device_attribute
*devattr
,
1795 const char *buf
, size_t count
)
1797 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1798 int err
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1799 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1802 err
= strict_strtol(buf
, 10, &val
);
1806 val
= SENSORS_LIMIT(val
, 0, 255);
1808 mutex_lock(&data
->update_lock
);
1809 data
->pwm_enable
= f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
1810 if (data
->pwm_enable
& (1 << (2 * pwm
))) {
1814 if (val
< 29) /* Prevent negative numbers */
1817 val
= (255 - val
) * 32 / val
;
1819 f71882fg_write8(data
, F71882FG_REG_POINT_PWM(pwm
, point
), val
);
1820 data
->pwm_auto_point_pwm
[pwm
][point
] = val
;
1821 mutex_unlock(&data
->update_lock
);
1826 static ssize_t
show_pwm_auto_point_temp_hyst(struct device
*dev
,
1827 struct device_attribute
*devattr
,
1831 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1832 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1833 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1835 mutex_lock(&data
->update_lock
);
1837 result
= data
->pwm_auto_point_hyst
[nr
/ 2] >> 4;
1839 result
= data
->pwm_auto_point_hyst
[nr
/ 2] & 0x0f;
1840 result
= 1000 * (data
->pwm_auto_point_temp
[nr
][point
] - result
);
1841 mutex_unlock(&data
->update_lock
);
1843 return sprintf(buf
, "%d\n", result
);
1846 static ssize_t
store_pwm_auto_point_temp_hyst(struct device
*dev
,
1847 struct device_attribute
*devattr
,
1848 const char *buf
, size_t count
)
1850 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1851 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1852 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1856 err
= strict_strtol(buf
, 10, &val
);
1862 mutex_lock(&data
->update_lock
);
1863 data
->pwm_auto_point_temp
[nr
][point
] =
1864 f71882fg_read8(data
, F71882FG_REG_POINT_TEMP(nr
, point
));
1865 val
= SENSORS_LIMIT(val
, data
->pwm_auto_point_temp
[nr
][point
] - 15,
1866 data
->pwm_auto_point_temp
[nr
][point
]);
1867 val
= data
->pwm_auto_point_temp
[nr
][point
] - val
;
1869 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_HYST(nr
/ 2));
1871 reg
= (reg
& 0x0f) | (val
<< 4);
1873 reg
= (reg
& 0xf0) | val
;
1875 f71882fg_write8(data
, F71882FG_REG_FAN_HYST(nr
/ 2), reg
);
1876 data
->pwm_auto_point_hyst
[nr
/ 2] = reg
;
1877 mutex_unlock(&data
->update_lock
);
1882 static ssize_t
show_pwm_interpolate(struct device
*dev
,
1883 struct device_attribute
*devattr
, char *buf
)
1886 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1887 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1889 result
= (data
->pwm_auto_point_mapping
[nr
] >> 4) & 1;
1891 return sprintf(buf
, "%d\n", result
);
1894 static ssize_t
store_pwm_interpolate(struct device
*dev
,
1895 struct device_attribute
*devattr
,
1896 const char *buf
, size_t count
)
1898 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1899 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1902 err
= strict_strtoul(buf
, 10, &val
);
1906 mutex_lock(&data
->update_lock
);
1907 data
->pwm_auto_point_mapping
[nr
] =
1908 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
1910 val
= data
->pwm_auto_point_mapping
[nr
] | (1 << 4);
1912 val
= data
->pwm_auto_point_mapping
[nr
] & (~(1 << 4));
1913 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
1914 data
->pwm_auto_point_mapping
[nr
] = val
;
1915 mutex_unlock(&data
->update_lock
);
1920 static ssize_t
show_pwm_auto_point_channel(struct device
*dev
,
1921 struct device_attribute
*devattr
,
1925 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1926 int nr
= to_sensor_dev_attr_2(devattr
)->index
;
1928 result
= 1 << ((data
->pwm_auto_point_mapping
[nr
] & 3) -
1931 return sprintf(buf
, "%d\n", result
);
1934 static ssize_t
store_pwm_auto_point_channel(struct device
*dev
,
1935 struct device_attribute
*devattr
,
1936 const char *buf
, size_t count
)
1938 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
1939 int err
, nr
= to_sensor_dev_attr_2(devattr
)->index
;
1942 err
= strict_strtol(buf
, 10, &val
);
1959 val
+= data
->temp_start
;
1960 mutex_lock(&data
->update_lock
);
1961 data
->pwm_auto_point_mapping
[nr
] =
1962 f71882fg_read8(data
, F71882FG_REG_POINT_MAPPING(nr
));
1963 val
= (data
->pwm_auto_point_mapping
[nr
] & 0xfc) | val
;
1964 f71882fg_write8(data
, F71882FG_REG_POINT_MAPPING(nr
), val
);
1965 data
->pwm_auto_point_mapping
[nr
] = val
;
1966 mutex_unlock(&data
->update_lock
);
1971 static ssize_t
show_pwm_auto_point_temp(struct device
*dev
,
1972 struct device_attribute
*devattr
,
1976 struct f71882fg_data
*data
= f71882fg_update_device(dev
);
1977 int pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1978 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1980 result
= data
->pwm_auto_point_temp
[pwm
][point
];
1981 return sprintf(buf
, "%d\n", 1000 * result
);
1984 static ssize_t
store_pwm_auto_point_temp(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
, pwm
= to_sensor_dev_attr_2(devattr
)->index
;
1990 int point
= to_sensor_dev_attr_2(devattr
)->nr
;
1993 err
= strict_strtol(buf
, 10, &val
);
1999 if (data
->auto_point_temp_signed
)
2000 val
= SENSORS_LIMIT(val
, -128, 127);
2002 val
= SENSORS_LIMIT(val
, 0, 127);
2004 mutex_lock(&data
->update_lock
);
2005 f71882fg_write8(data
, F71882FG_REG_POINT_TEMP(pwm
, point
), val
);
2006 data
->pwm_auto_point_temp
[pwm
][point
] = val
;
2007 mutex_unlock(&data
->update_lock
);
2012 static ssize_t
show_name(struct device
*dev
, struct device_attribute
*devattr
,
2015 struct f71882fg_data
*data
= dev_get_drvdata(dev
);
2016 return sprintf(buf
, "%s\n", f71882fg_names
[data
->type
]);
2019 static int __devinit
f71882fg_create_sysfs_files(struct platform_device
*pdev
,
2020 struct sensor_device_attribute_2
*attr
, int count
)
2024 for (i
= 0; i
< count
; i
++) {
2025 err
= device_create_file(&pdev
->dev
, &attr
[i
].dev_attr
);
2032 static void f71882fg_remove_sysfs_files(struct platform_device
*pdev
,
2033 struct sensor_device_attribute_2
*attr
, int count
)
2037 for (i
= 0; i
< count
; i
++)
2038 device_remove_file(&pdev
->dev
, &attr
[i
].dev_attr
);
2041 static int __devinit
f71882fg_probe(struct platform_device
*pdev
)
2043 struct f71882fg_data
*data
;
2044 struct f71882fg_sio_data
*sio_data
= pdev
->dev
.platform_data
;
2045 int err
, i
, nr_fans
= (sio_data
->type
== f71882fg
) ? 4 : 3;
2046 int nr_temps
= (sio_data
->type
== f71808e
) ? 2 : 3;
2049 data
= kzalloc(sizeof(struct f71882fg_data
), GFP_KERNEL
);
2053 data
->addr
= platform_get_resource(pdev
, IORESOURCE_IO
, 0)->start
;
2054 data
->type
= sio_data
->type
;
2056 (data
->type
== f71858fg
|| data
->type
== f8000
) ? 0 : 1;
2057 mutex_init(&data
->update_lock
);
2058 platform_set_drvdata(pdev
, data
);
2060 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2061 if (start_reg
& 0x04) {
2062 dev_warn(&pdev
->dev
, "Hardware monitor is powered down\n");
2066 if (!(start_reg
& 0x03)) {
2067 dev_warn(&pdev
->dev
, "Hardware monitoring not activated\n");
2072 /* Register sysfs interface files */
2073 err
= device_create_file(&pdev
->dev
, &dev_attr_name
);
2075 goto exit_unregister_sysfs
;
2077 if (start_reg
& 0x01) {
2078 switch (data
->type
) {
2081 f71882fg_read8(data
, F71882FG_REG_TEMP_CONFIG
);
2082 if (data
->temp_config
& 0x10)
2083 /* The f71858fg temperature alarms behave as
2084 the f8000 alarms in this mode */
2085 err
= f71882fg_create_sysfs_files(pdev
,
2087 ARRAY_SIZE(f8000_temp_attr
));
2089 err
= f71882fg_create_sysfs_files(pdev
,
2091 ARRAY_SIZE(f71858fg_temp_attr
));
2094 err
= f71882fg_create_sysfs_files(pdev
,
2096 ARRAY_SIZE(f8000_temp_attr
));
2099 err
= f71882fg_create_sysfs_files(pdev
,
2100 &fxxxx_temp_attr
[0][0],
2101 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2104 goto exit_unregister_sysfs
;
2106 if (f71882fg_has_beep
[data
->type
]) {
2107 err
= f71882fg_create_sysfs_files(pdev
,
2108 &fxxxx_temp_beep_attr
[0][0],
2109 ARRAY_SIZE(fxxxx_temp_beep_attr
[0])
2112 goto exit_unregister_sysfs
;
2115 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2116 if (f71882fg_has_in
[data
->type
][i
]) {
2117 err
= device_create_file(&pdev
->dev
,
2118 &fxxxx_in_attr
[i
].dev_attr
);
2120 goto exit_unregister_sysfs
;
2123 if (f71882fg_has_in1_alarm
[data
->type
]) {
2124 err
= f71882fg_create_sysfs_files(pdev
,
2125 fxxxx_in1_alarm_attr
,
2126 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2128 goto exit_unregister_sysfs
;
2132 if (start_reg
& 0x02) {
2133 switch (data
->type
) {
2136 /* These always have signed auto point temps */
2137 data
->auto_point_temp_signed
= 1;
2138 /* Fall through to select correct fan/pwm reg bank! */
2141 reg
= f71882fg_read8(data
, F71882FG_REG_FAN_FAULT_T
);
2142 if (reg
& F71882FG_FAN_NEG_TEMP_EN
)
2143 data
->auto_point_temp_signed
= 1;
2144 /* Ensure banked pwm registers point to right bank */
2145 reg
&= ~F71882FG_FAN_PROG_SEL
;
2146 f71882fg_write8(data
, F71882FG_REG_FAN_FAULT_T
, reg
);
2153 f71882fg_read8(data
, F71882FG_REG_PWM_ENABLE
);
2155 /* Sanity check the pwm settings */
2156 switch (data
->type
) {
2159 for (i
= 0; i
< nr_fans
; i
++)
2160 if (((data
->pwm_enable
>> (i
* 2)) & 3) == 3)
2164 err
= (data
->pwm_enable
& 0x15) != 0x15;
2174 err
= data
->pwm_enable
& 0x20;
2179 "Invalid (reserved) pwm settings: 0x%02x\n",
2180 (unsigned int)data
->pwm_enable
);
2182 goto exit_unregister_sysfs
;
2185 err
= f71882fg_create_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2186 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2188 goto exit_unregister_sysfs
;
2190 if (f71882fg_has_beep
[data
->type
]) {
2191 err
= f71882fg_create_sysfs_files(pdev
,
2192 fxxxx_fan_beep_attr
, nr_fans
);
2194 goto exit_unregister_sysfs
;
2197 switch (data
->type
) {
2202 for (i
= 0; i
< nr_fans
; i
++) {
2203 data
->pwm_auto_point_mapping
[i
] =
2204 f71882fg_read8(data
,
2205 F71882FG_REG_POINT_MAPPING(i
));
2206 if ((data
->pwm_auto_point_mapping
[i
] & 0x80) ||
2207 (data
->pwm_auto_point_mapping
[i
] & 3) == 0)
2211 dev_warn(&pdev
->dev
,
2212 "Auto pwm controlled by raw digital "
2213 "data, disabling pwm auto_point "
2214 "sysfs attributes\n");
2215 goto no_pwm_auto_point
;
2222 switch (data
->type
) {
2224 err
= f71882fg_create_sysfs_files(pdev
,
2225 f71862fg_auto_pwm_attr
,
2226 ARRAY_SIZE(f71862fg_auto_pwm_attr
));
2230 err
= f71882fg_create_sysfs_files(pdev
,
2231 f71869_auto_pwm_attr
,
2232 ARRAY_SIZE(f71869_auto_pwm_attr
));
2235 err
= f71882fg_create_sysfs_files(pdev
,
2237 ARRAY_SIZE(f8000_fan_attr
));
2239 goto exit_unregister_sysfs
;
2240 err
= f71882fg_create_sysfs_files(pdev
,
2241 f8000_auto_pwm_attr
,
2242 ARRAY_SIZE(f8000_auto_pwm_attr
));
2245 err
= f71882fg_create_sysfs_files(pdev
,
2246 &fxxxx_auto_pwm_attr
[0][0],
2247 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2250 goto exit_unregister_sysfs
;
2253 for (i
= 0; i
< nr_fans
; i
++)
2254 dev_info(&pdev
->dev
, "Fan: %d is in %s mode\n", i
+ 1,
2255 (data
->pwm_enable
& (1 << 2 * i
)) ?
2256 "duty-cycle" : "RPM");
2259 data
->hwmon_dev
= hwmon_device_register(&pdev
->dev
);
2260 if (IS_ERR(data
->hwmon_dev
)) {
2261 err
= PTR_ERR(data
->hwmon_dev
);
2262 data
->hwmon_dev
= NULL
;
2263 goto exit_unregister_sysfs
;
2268 exit_unregister_sysfs
:
2269 f71882fg_remove(pdev
); /* Will unregister the sysfs files for us */
2270 return err
; /* f71882fg_remove() also frees our data */
2276 static int f71882fg_remove(struct platform_device
*pdev
)
2278 struct f71882fg_data
*data
= platform_get_drvdata(pdev
);
2279 int i
, nr_fans
= (data
->type
== f71882fg
) ? 4 : 3;
2280 int nr_temps
= (data
->type
== f71808e
) ? 2 : 3;
2281 u8 start_reg
= f71882fg_read8(data
, F71882FG_REG_START
);
2283 if (data
->hwmon_dev
)
2284 hwmon_device_unregister(data
->hwmon_dev
);
2286 device_remove_file(&pdev
->dev
, &dev_attr_name
);
2288 if (start_reg
& 0x01) {
2289 switch (data
->type
) {
2291 if (data
->temp_config
& 0x10)
2292 f71882fg_remove_sysfs_files(pdev
,
2294 ARRAY_SIZE(f8000_temp_attr
));
2296 f71882fg_remove_sysfs_files(pdev
,
2298 ARRAY_SIZE(f71858fg_temp_attr
));
2301 f71882fg_remove_sysfs_files(pdev
,
2303 ARRAY_SIZE(f8000_temp_attr
));
2306 f71882fg_remove_sysfs_files(pdev
,
2307 &fxxxx_temp_attr
[0][0],
2308 ARRAY_SIZE(fxxxx_temp_attr
[0]) * nr_temps
);
2310 if (f71882fg_has_beep
[data
->type
]) {
2311 f71882fg_remove_sysfs_files(pdev
,
2312 &fxxxx_temp_beep_attr
[0][0],
2313 ARRAY_SIZE(fxxxx_temp_beep_attr
[0]) * nr_temps
);
2316 for (i
= 0; i
< F71882FG_MAX_INS
; i
++) {
2317 if (f71882fg_has_in
[data
->type
][i
]) {
2318 device_remove_file(&pdev
->dev
,
2319 &fxxxx_in_attr
[i
].dev_attr
);
2322 if (f71882fg_has_in1_alarm
[data
->type
]) {
2323 f71882fg_remove_sysfs_files(pdev
,
2324 fxxxx_in1_alarm_attr
,
2325 ARRAY_SIZE(fxxxx_in1_alarm_attr
));
2329 if (start_reg
& 0x02) {
2330 f71882fg_remove_sysfs_files(pdev
, &fxxxx_fan_attr
[0][0],
2331 ARRAY_SIZE(fxxxx_fan_attr
[0]) * nr_fans
);
2333 if (f71882fg_has_beep
[data
->type
]) {
2334 f71882fg_remove_sysfs_files(pdev
,
2335 fxxxx_fan_beep_attr
, nr_fans
);
2338 switch (data
->type
) {
2340 f71882fg_remove_sysfs_files(pdev
,
2341 f71862fg_auto_pwm_attr
,
2342 ARRAY_SIZE(f71862fg_auto_pwm_attr
));
2346 f71882fg_remove_sysfs_files(pdev
,
2347 f71869_auto_pwm_attr
,
2348 ARRAY_SIZE(f71869_auto_pwm_attr
));
2351 f71882fg_remove_sysfs_files(pdev
,
2353 ARRAY_SIZE(f8000_fan_attr
));
2354 f71882fg_remove_sysfs_files(pdev
,
2355 f8000_auto_pwm_attr
,
2356 ARRAY_SIZE(f8000_auto_pwm_attr
));
2359 f71882fg_remove_sysfs_files(pdev
,
2360 &fxxxx_auto_pwm_attr
[0][0],
2361 ARRAY_SIZE(fxxxx_auto_pwm_attr
[0]) * nr_fans
);
2365 platform_set_drvdata(pdev
, NULL
);
2371 static int __init
f71882fg_find(int sioaddr
, unsigned short *address
,
2372 struct f71882fg_sio_data
*sio_data
)
2375 int err
= superio_enter(sioaddr
);
2379 devid
= superio_inw(sioaddr
, SIO_REG_MANID
);
2380 if (devid
!= SIO_FINTEK_ID
) {
2381 pr_debug("Not a Fintek device\n");
2386 devid
= force_id
? force_id
: superio_inw(sioaddr
, SIO_REG_DEVID
);
2388 case SIO_F71808E_ID
:
2389 sio_data
->type
= f71808e
;
2392 sio_data
->type
= f71858fg
;
2395 sio_data
->type
= f71862fg
;
2398 sio_data
->type
= f71869
;
2401 sio_data
->type
= f71882fg
;
2404 sio_data
->type
= f71889fg
;
2406 case SIO_F71889E_ID
:
2407 sio_data
->type
= f71889ed
;
2410 sio_data
->type
= f8000
;
2413 pr_info("Unsupported Fintek device: %04x\n",
2414 (unsigned int)devid
);
2419 if (sio_data
->type
== f71858fg
)
2420 superio_select(sioaddr
, SIO_F71858FG_LD_HWM
);
2422 superio_select(sioaddr
, SIO_F71882FG_LD_HWM
);
2424 if (!(superio_inb(sioaddr
, SIO_REG_ENABLE
) & 0x01)) {
2425 pr_warn("Device not activated\n");
2430 *address
= superio_inw(sioaddr
, SIO_REG_ADDR
);
2431 if (*address
== 0) {
2432 pr_warn("Base address not set\n");
2436 *address
&= ~(REGION_LENGTH
- 1); /* Ignore 3 LSB */
2439 pr_info("Found %s chip at %#x, revision %d\n",
2440 f71882fg_names
[sio_data
->type
], (unsigned int)*address
,
2441 (int)superio_inb(sioaddr
, SIO_REG_DEVREV
));
2443 superio_exit(sioaddr
);
2447 static int __init
f71882fg_device_add(unsigned short address
,
2448 const struct f71882fg_sio_data
*sio_data
)
2450 struct resource res
= {
2452 .end
= address
+ REGION_LENGTH
- 1,
2453 .flags
= IORESOURCE_IO
,
2457 f71882fg_pdev
= platform_device_alloc(DRVNAME
, address
);
2461 res
.name
= f71882fg_pdev
->name
;
2462 err
= acpi_check_resource_conflict(&res
);
2464 goto exit_device_put
;
2466 err
= platform_device_add_resources(f71882fg_pdev
, &res
, 1);
2468 pr_err("Device resource addition failed\n");
2469 goto exit_device_put
;
2472 err
= platform_device_add_data(f71882fg_pdev
, sio_data
,
2473 sizeof(struct f71882fg_sio_data
));
2475 pr_err("Platform data allocation failed\n");
2476 goto exit_device_put
;
2479 err
= platform_device_add(f71882fg_pdev
);
2481 pr_err("Device addition failed\n");
2482 goto exit_device_put
;
2488 platform_device_put(f71882fg_pdev
);
2493 static int __init
f71882fg_init(void)
2496 unsigned short address
;
2497 struct f71882fg_sio_data sio_data
;
2499 memset(&sio_data
, 0, sizeof(sio_data
));
2501 if (f71882fg_find(0x2e, &address
, &sio_data
) &&
2502 f71882fg_find(0x4e, &address
, &sio_data
))
2505 err
= platform_driver_register(&f71882fg_driver
);
2509 err
= f71882fg_device_add(address
, &sio_data
);
2516 platform_driver_unregister(&f71882fg_driver
);
2521 static void __exit
f71882fg_exit(void)
2523 platform_device_unregister(f71882fg_pdev
);
2524 platform_driver_unregister(&f71882fg_driver
);
2527 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2528 MODULE_AUTHOR("Hans Edgington, Hans de Goede (hdegoede@redhat.com)");
2529 MODULE_LICENSE("GPL");
2531 module_init(f71882fg_init
);
2532 module_exit(f71882fg_exit
);