2 * f71805f.c - driver for the Fintek F71805F/FG Super-I/O chip integrated
3 * hardware monitoring features
4 * Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
6 * The F71805F/FG is a LPC Super-I/O chip made by Fintek. It integrates
7 * complete hardware monitoring features: voltage, fan and temperature
8 * sensors, and manual and automatic fan speed control.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <linux/jiffies.h>
29 #include <linux/platform_device.h>
30 #include <linux/hwmon.h>
31 #include <linux/hwmon-sysfs.h>
32 #include <linux/err.h>
33 #include <linux/mutex.h>
34 #include <linux/sysfs.h>
37 static struct platform_device
*pdev
;
39 #define DRVNAME "f71805f"
42 * Super-I/O constants and functions
45 #define F71805F_LD_HWM 0x04
47 #define SIO_REG_LDSEL 0x07 /* Logical device select */
48 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
49 #define SIO_REG_DEVREV 0x22 /* Device revision */
50 #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
51 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
52 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
54 #define SIO_FINTEK_ID 0x1934
55 #define SIO_F71805F_ID 0x0406
58 superio_inb(int base
, int reg
)
65 superio_inw(int base
, int reg
)
69 val
= inb(base
+ 1) << 8;
76 superio_select(int base
, int ld
)
78 outb(SIO_REG_LDSEL
, base
);
83 superio_enter(int base
)
90 superio_exit(int base
)
99 #define REGION_LENGTH 2
100 #define ADDR_REG_OFFSET 0
101 #define DATA_REG_OFFSET 1
107 /* in nr from 0 to 8 (8-bit values) */
108 #define F71805F_REG_IN(nr) (0x10 + (nr))
109 #define F71805F_REG_IN_HIGH(nr) (0x40 + 2 * (nr))
110 #define F71805F_REG_IN_LOW(nr) (0x41 + 2 * (nr))
111 /* fan nr from 0 to 2 (12-bit values, two registers) */
112 #define F71805F_REG_FAN(nr) (0x20 + 2 * (nr))
113 #define F71805F_REG_FAN_LOW(nr) (0x28 + 2 * (nr))
114 #define F71805F_REG_FAN_CTRL(nr) (0x60 + 16 * (nr))
115 /* temp nr from 0 to 2 (8-bit values) */
116 #define F71805F_REG_TEMP(nr) (0x1B + (nr))
117 #define F71805F_REG_TEMP_HIGH(nr) (0x54 + 2 * (nr))
118 #define F71805F_REG_TEMP_HYST(nr) (0x55 + 2 * (nr))
119 #define F71805F_REG_TEMP_MODE 0x01
121 #define F71805F_REG_START 0x00
122 /* status nr from 0 to 2 */
123 #define F71805F_REG_STATUS(nr) (0x36 + (nr))
126 * Data structures and manipulation thereof
129 struct f71805f_data
{
133 struct class_device
*class_dev
;
135 struct mutex update_lock
;
136 char valid
; /* !=0 if following fields are valid */
137 unsigned long last_updated
; /* In jiffies */
138 unsigned long last_limits
; /* In jiffies */
140 /* Register values */
146 u8 fan_enabled
; /* Read once at init time */
151 unsigned long alarms
;
154 static inline long in_from_reg(u8 reg
)
159 /* The 2 least significant bits are not used */
160 static inline u8
in_to_reg(long val
)
166 return (((val
+ 16) / 32) << 2);
169 /* in0 is downscaled by a factor 2 internally */
170 static inline long in0_from_reg(u8 reg
)
175 static inline u8
in0_to_reg(long val
)
181 return (((val
+ 32) / 64) << 2);
184 /* The 4 most significant bits are not used */
185 static inline long fan_from_reg(u16 reg
)
188 if (!reg
|| reg
== 0xfff)
190 return (1500000 / reg
);
193 static inline u16
fan_to_reg(long rpm
)
195 /* If the low limit is set below what the chip can measure,
196 store the largest possible 12-bit value in the registers,
197 so that no alarm will ever trigger. */
200 return (1500000 / rpm
);
203 static inline long temp_from_reg(u8 reg
)
208 static inline u8
temp_to_reg(long val
)
212 else if (val
> 1000 * 0xff)
214 return ((val
+ 500) / 1000);
221 static u8
f71805f_read8(struct f71805f_data
*data
, u8 reg
)
225 mutex_lock(&data
->lock
);
226 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
227 val
= inb(data
->addr
+ DATA_REG_OFFSET
);
228 mutex_unlock(&data
->lock
);
233 static void f71805f_write8(struct f71805f_data
*data
, u8 reg
, u8 val
)
235 mutex_lock(&data
->lock
);
236 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
237 outb(val
, data
->addr
+ DATA_REG_OFFSET
);
238 mutex_unlock(&data
->lock
);
241 /* It is important to read the MSB first, because doing so latches the
242 value of the LSB, so we are sure both bytes belong to the same value. */
243 static u16
f71805f_read16(struct f71805f_data
*data
, u8 reg
)
247 mutex_lock(&data
->lock
);
248 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
249 val
= inb(data
->addr
+ DATA_REG_OFFSET
) << 8;
250 outb(++reg
, data
->addr
+ ADDR_REG_OFFSET
);
251 val
|= inb(data
->addr
+ DATA_REG_OFFSET
);
252 mutex_unlock(&data
->lock
);
257 static void f71805f_write16(struct f71805f_data
*data
, u8 reg
, u16 val
)
259 mutex_lock(&data
->lock
);
260 outb(reg
, data
->addr
+ ADDR_REG_OFFSET
);
261 outb(val
>> 8, data
->addr
+ DATA_REG_OFFSET
);
262 outb(++reg
, data
->addr
+ ADDR_REG_OFFSET
);
263 outb(val
& 0xff, data
->addr
+ DATA_REG_OFFSET
);
264 mutex_unlock(&data
->lock
);
267 static struct f71805f_data
*f71805f_update_device(struct device
*dev
)
269 struct f71805f_data
*data
= dev_get_drvdata(dev
);
272 mutex_lock(&data
->update_lock
);
274 /* Limit registers cache is refreshed after 60 seconds */
275 if (time_after(jiffies
, data
->last_updated
+ 60 * HZ
)
277 for (nr
= 0; nr
< 9; nr
++) {
278 data
->in_high
[nr
] = f71805f_read8(data
,
279 F71805F_REG_IN_HIGH(nr
));
280 data
->in_low
[nr
] = f71805f_read8(data
,
281 F71805F_REG_IN_LOW(nr
));
283 for (nr
= 0; nr
< 3; nr
++) {
284 if (data
->fan_enabled
& (1 << nr
))
285 data
->fan_low
[nr
] = f71805f_read16(data
,
286 F71805F_REG_FAN_LOW(nr
));
288 for (nr
= 0; nr
< 3; nr
++) {
289 data
->temp_high
[nr
] = f71805f_read8(data
,
290 F71805F_REG_TEMP_HIGH(nr
));
291 data
->temp_hyst
[nr
] = f71805f_read8(data
,
292 F71805F_REG_TEMP_HYST(nr
));
294 data
->temp_mode
= f71805f_read8(data
, F71805F_REG_TEMP_MODE
);
296 data
->last_limits
= jiffies
;
299 /* Measurement registers cache is refreshed after 1 second */
300 if (time_after(jiffies
, data
->last_updated
+ HZ
)
302 for (nr
= 0; nr
< 9; nr
++) {
303 data
->in
[nr
] = f71805f_read8(data
,
306 for (nr
= 0; nr
< 3; nr
++) {
307 if (data
->fan_enabled
& (1 << nr
))
308 data
->fan
[nr
] = f71805f_read16(data
,
309 F71805F_REG_FAN(nr
));
311 for (nr
= 0; nr
< 3; nr
++) {
312 data
->temp
[nr
] = f71805f_read8(data
,
313 F71805F_REG_TEMP(nr
));
315 data
->alarms
= f71805f_read8(data
, F71805F_REG_STATUS(0))
316 + (f71805f_read8(data
, F71805F_REG_STATUS(1)) << 8)
317 + (f71805f_read8(data
, F71805F_REG_STATUS(2)) << 16);
319 data
->last_updated
= jiffies
;
323 mutex_unlock(&data
->update_lock
);
332 static ssize_t
show_in0(struct device
*dev
, struct device_attribute
*devattr
,
335 struct f71805f_data
*data
= f71805f_update_device(dev
);
337 return sprintf(buf
, "%ld\n", in0_from_reg(data
->in
[0]));
340 static ssize_t
show_in0_max(struct device
*dev
, struct device_attribute
343 struct f71805f_data
*data
= f71805f_update_device(dev
);
345 return sprintf(buf
, "%ld\n", in0_from_reg(data
->in_high
[0]));
348 static ssize_t
show_in0_min(struct device
*dev
, struct device_attribute
351 struct f71805f_data
*data
= f71805f_update_device(dev
);
353 return sprintf(buf
, "%ld\n", in0_from_reg(data
->in_low
[0]));
356 static ssize_t
set_in0_max(struct device
*dev
, struct device_attribute
357 *devattr
, const char *buf
, size_t count
)
359 struct f71805f_data
*data
= dev_get_drvdata(dev
);
360 long val
= simple_strtol(buf
, NULL
, 10);
362 mutex_lock(&data
->update_lock
);
363 data
->in_high
[0] = in0_to_reg(val
);
364 f71805f_write8(data
, F71805F_REG_IN_HIGH(0), data
->in_high
[0]);
365 mutex_unlock(&data
->update_lock
);
370 static ssize_t
set_in0_min(struct device
*dev
, struct device_attribute
371 *devattr
, const char *buf
, size_t count
)
373 struct f71805f_data
*data
= dev_get_drvdata(dev
);
374 long val
= simple_strtol(buf
, NULL
, 10);
376 mutex_lock(&data
->update_lock
);
377 data
->in_low
[0] = in0_to_reg(val
);
378 f71805f_write8(data
, F71805F_REG_IN_LOW(0), data
->in_low
[0]);
379 mutex_unlock(&data
->update_lock
);
384 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*devattr
,
387 struct f71805f_data
*data
= f71805f_update_device(dev
);
388 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
389 int nr
= attr
->index
;
391 return sprintf(buf
, "%ld\n", in_from_reg(data
->in
[nr
]));
394 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
397 struct f71805f_data
*data
= f71805f_update_device(dev
);
398 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
399 int nr
= attr
->index
;
401 return sprintf(buf
, "%ld\n", in_from_reg(data
->in_high
[nr
]));
404 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
407 struct f71805f_data
*data
= f71805f_update_device(dev
);
408 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
409 int nr
= attr
->index
;
411 return sprintf(buf
, "%ld\n", in_from_reg(data
->in_low
[nr
]));
414 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
415 *devattr
, const char *buf
, size_t count
)
417 struct f71805f_data
*data
= dev_get_drvdata(dev
);
418 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
419 int nr
= attr
->index
;
420 long val
= simple_strtol(buf
, NULL
, 10);
422 mutex_lock(&data
->update_lock
);
423 data
->in_high
[nr
] = in_to_reg(val
);
424 f71805f_write8(data
, F71805F_REG_IN_HIGH(nr
), data
->in_high
[nr
]);
425 mutex_unlock(&data
->update_lock
);
430 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
431 *devattr
, const char *buf
, size_t count
)
433 struct f71805f_data
*data
= dev_get_drvdata(dev
);
434 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
435 int nr
= attr
->index
;
436 long val
= simple_strtol(buf
, NULL
, 10);
438 mutex_lock(&data
->update_lock
);
439 data
->in_low
[nr
] = in_to_reg(val
);
440 f71805f_write8(data
, F71805F_REG_IN_LOW(nr
), data
->in_low
[nr
]);
441 mutex_unlock(&data
->update_lock
);
446 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*devattr
,
449 struct f71805f_data
*data
= f71805f_update_device(dev
);
450 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
451 int nr
= attr
->index
;
453 return sprintf(buf
, "%ld\n", fan_from_reg(data
->fan
[nr
]));
456 static ssize_t
show_fan_min(struct device
*dev
, struct device_attribute
459 struct f71805f_data
*data
= f71805f_update_device(dev
);
460 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
461 int nr
= attr
->index
;
463 return sprintf(buf
, "%ld\n", fan_from_reg(data
->fan_low
[nr
]));
466 static ssize_t
set_fan_min(struct device
*dev
, struct device_attribute
467 *devattr
, const char *buf
, size_t count
)
469 struct f71805f_data
*data
= dev_get_drvdata(dev
);
470 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
471 int nr
= attr
->index
;
472 long val
= simple_strtol(buf
, NULL
, 10);
474 mutex_lock(&data
->update_lock
);
475 data
->fan_low
[nr
] = fan_to_reg(val
);
476 f71805f_write16(data
, F71805F_REG_FAN_LOW(nr
), data
->fan_low
[nr
]);
477 mutex_unlock(&data
->update_lock
);
482 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*devattr
,
485 struct f71805f_data
*data
= f71805f_update_device(dev
);
486 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
487 int nr
= attr
->index
;
489 return sprintf(buf
, "%ld\n", temp_from_reg(data
->temp
[nr
]));
492 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
495 struct f71805f_data
*data
= f71805f_update_device(dev
);
496 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
497 int nr
= attr
->index
;
499 return sprintf(buf
, "%ld\n", temp_from_reg(data
->temp_high
[nr
]));
502 static ssize_t
show_temp_hyst(struct device
*dev
, struct device_attribute
505 struct f71805f_data
*data
= f71805f_update_device(dev
);
506 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
507 int nr
= attr
->index
;
509 return sprintf(buf
, "%ld\n", temp_from_reg(data
->temp_hyst
[nr
]));
512 static ssize_t
show_temp_type(struct device
*dev
, struct device_attribute
515 struct f71805f_data
*data
= f71805f_update_device(dev
);
516 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
517 int nr
= attr
->index
;
519 /* 3 is diode, 4 is thermistor */
520 return sprintf(buf
, "%u\n", (data
->temp_mode
& (1 << nr
)) ? 3 : 4);
523 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
524 *devattr
, const char *buf
, size_t count
)
526 struct f71805f_data
*data
= dev_get_drvdata(dev
);
527 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
528 int nr
= attr
->index
;
529 long val
= simple_strtol(buf
, NULL
, 10);
531 mutex_lock(&data
->update_lock
);
532 data
->temp_high
[nr
] = temp_to_reg(val
);
533 f71805f_write8(data
, F71805F_REG_TEMP_HIGH(nr
), data
->temp_high
[nr
]);
534 mutex_unlock(&data
->update_lock
);
539 static ssize_t
set_temp_hyst(struct device
*dev
, struct device_attribute
540 *devattr
, const char *buf
, size_t count
)
542 struct f71805f_data
*data
= dev_get_drvdata(dev
);
543 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
544 int nr
= attr
->index
;
545 long val
= simple_strtol(buf
, NULL
, 10);
547 mutex_lock(&data
->update_lock
);
548 data
->temp_hyst
[nr
] = temp_to_reg(val
);
549 f71805f_write8(data
, F71805F_REG_TEMP_HYST(nr
), data
->temp_hyst
[nr
]);
550 mutex_unlock(&data
->update_lock
);
555 static ssize_t
show_alarms_in(struct device
*dev
, struct device_attribute
558 struct f71805f_data
*data
= f71805f_update_device(dev
);
560 return sprintf(buf
, "%lu\n", data
->alarms
& 0x1ff);
563 static ssize_t
show_alarms_fan(struct device
*dev
, struct device_attribute
566 struct f71805f_data
*data
= f71805f_update_device(dev
);
568 return sprintf(buf
, "%lu\n", (data
->alarms
>> 16) & 0x07);
571 static ssize_t
show_alarms_temp(struct device
*dev
, struct device_attribute
574 struct f71805f_data
*data
= f71805f_update_device(dev
);
576 return sprintf(buf
, "%lu\n", (data
->alarms
>> 11) & 0x07);
579 static ssize_t
show_alarm(struct device
*dev
, struct device_attribute
582 struct f71805f_data
*data
= f71805f_update_device(dev
);
583 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
584 int bitnr
= attr
->index
;
586 return sprintf(buf
, "%lu\n", (data
->alarms
>> bitnr
) & 1);
589 static ssize_t
show_name(struct device
*dev
, struct device_attribute
592 struct f71805f_data
*data
= dev_get_drvdata(dev
);
594 return sprintf(buf
, "%s\n", data
->name
);
597 static DEVICE_ATTR(in0_input
, S_IRUGO
, show_in0
, NULL
);
598 static DEVICE_ATTR(in0_max
, S_IRUGO
| S_IWUSR
, show_in0_max
, set_in0_max
);
599 static DEVICE_ATTR(in0_min
, S_IRUGO
| S_IWUSR
, show_in0_min
, set_in0_min
);
600 static SENSOR_DEVICE_ATTR(in1_input
, S_IRUGO
, show_in
, NULL
, 1);
601 static SENSOR_DEVICE_ATTR(in1_max
, S_IRUGO
| S_IWUSR
,
602 show_in_max
, set_in_max
, 1);
603 static SENSOR_DEVICE_ATTR(in1_min
, S_IRUGO
| S_IWUSR
,
604 show_in_min
, set_in_min
, 1);
605 static SENSOR_DEVICE_ATTR(in2_input
, S_IRUGO
, show_in
, NULL
, 2);
606 static SENSOR_DEVICE_ATTR(in2_max
, S_IRUGO
| S_IWUSR
,
607 show_in_max
, set_in_max
, 2);
608 static SENSOR_DEVICE_ATTR(in2_min
, S_IRUGO
| S_IWUSR
,
609 show_in_min
, set_in_min
, 2);
610 static SENSOR_DEVICE_ATTR(in3_input
, S_IRUGO
, show_in
, NULL
, 3);
611 static SENSOR_DEVICE_ATTR(in3_max
, S_IRUGO
| S_IWUSR
,
612 show_in_max
, set_in_max
, 3);
613 static SENSOR_DEVICE_ATTR(in3_min
, S_IRUGO
| S_IWUSR
,
614 show_in_min
, set_in_min
, 3);
615 static SENSOR_DEVICE_ATTR(in4_input
, S_IRUGO
, show_in
, NULL
, 4);
616 static SENSOR_DEVICE_ATTR(in4_max
, S_IRUGO
| S_IWUSR
,
617 show_in_max
, set_in_max
, 4);
618 static SENSOR_DEVICE_ATTR(in4_min
, S_IRUGO
| S_IWUSR
,
619 show_in_min
, set_in_min
, 4);
620 static SENSOR_DEVICE_ATTR(in5_input
, S_IRUGO
, show_in
, NULL
, 5);
621 static SENSOR_DEVICE_ATTR(in5_max
, S_IRUGO
| S_IWUSR
,
622 show_in_max
, set_in_max
, 5);
623 static SENSOR_DEVICE_ATTR(in5_min
, S_IRUGO
| S_IWUSR
,
624 show_in_min
, set_in_min
, 5);
625 static SENSOR_DEVICE_ATTR(in6_input
, S_IRUGO
, show_in
, NULL
, 6);
626 static SENSOR_DEVICE_ATTR(in6_max
, S_IRUGO
| S_IWUSR
,
627 show_in_max
, set_in_max
, 6);
628 static SENSOR_DEVICE_ATTR(in6_min
, S_IRUGO
| S_IWUSR
,
629 show_in_min
, set_in_min
, 6);
630 static SENSOR_DEVICE_ATTR(in7_input
, S_IRUGO
, show_in
, NULL
, 7);
631 static SENSOR_DEVICE_ATTR(in7_max
, S_IRUGO
| S_IWUSR
,
632 show_in_max
, set_in_max
, 7);
633 static SENSOR_DEVICE_ATTR(in7_min
, S_IRUGO
| S_IWUSR
,
634 show_in_min
, set_in_min
, 7);
635 static SENSOR_DEVICE_ATTR(in8_input
, S_IRUGO
, show_in
, NULL
, 8);
636 static SENSOR_DEVICE_ATTR(in8_max
, S_IRUGO
| S_IWUSR
,
637 show_in_max
, set_in_max
, 8);
638 static SENSOR_DEVICE_ATTR(in8_min
, S_IRUGO
| S_IWUSR
,
639 show_in_min
, set_in_min
, 8);
641 static SENSOR_DEVICE_ATTR(fan1_input
, S_IRUGO
, show_fan
, NULL
, 0);
642 static SENSOR_DEVICE_ATTR(fan1_min
, S_IRUGO
| S_IWUSR
,
643 show_fan_min
, set_fan_min
, 0);
644 static SENSOR_DEVICE_ATTR(fan2_input
, S_IRUGO
, show_fan
, NULL
, 1);
645 static SENSOR_DEVICE_ATTR(fan2_min
, S_IRUGO
| S_IWUSR
,
646 show_fan_min
, set_fan_min
, 1);
647 static SENSOR_DEVICE_ATTR(fan3_input
, S_IRUGO
, show_fan
, NULL
, 2);
648 static SENSOR_DEVICE_ATTR(fan3_min
, S_IRUGO
| S_IWUSR
,
649 show_fan_min
, set_fan_min
, 2);
651 static SENSOR_DEVICE_ATTR(temp1_input
, S_IRUGO
, show_temp
, NULL
, 0);
652 static SENSOR_DEVICE_ATTR(temp1_max
, S_IRUGO
| S_IWUSR
,
653 show_temp_max
, set_temp_max
, 0);
654 static SENSOR_DEVICE_ATTR(temp1_max_hyst
, S_IRUGO
| S_IWUSR
,
655 show_temp_hyst
, set_temp_hyst
, 0);
656 static SENSOR_DEVICE_ATTR(temp1_type
, S_IRUGO
, show_temp_type
, NULL
, 0);
657 static SENSOR_DEVICE_ATTR(temp2_input
, S_IRUGO
, show_temp
, NULL
, 1);
658 static SENSOR_DEVICE_ATTR(temp2_max
, S_IRUGO
| S_IWUSR
,
659 show_temp_max
, set_temp_max
, 1);
660 static SENSOR_DEVICE_ATTR(temp2_max_hyst
, S_IRUGO
| S_IWUSR
,
661 show_temp_hyst
, set_temp_hyst
, 1);
662 static SENSOR_DEVICE_ATTR(temp2_type
, S_IRUGO
, show_temp_type
, NULL
, 1);
663 static SENSOR_DEVICE_ATTR(temp3_input
, S_IRUGO
, show_temp
, NULL
, 2);
664 static SENSOR_DEVICE_ATTR(temp3_max
, S_IRUGO
| S_IWUSR
,
665 show_temp_max
, set_temp_max
, 2);
666 static SENSOR_DEVICE_ATTR(temp3_max_hyst
, S_IRUGO
| S_IWUSR
,
667 show_temp_hyst
, set_temp_hyst
, 2);
668 static SENSOR_DEVICE_ATTR(temp3_type
, S_IRUGO
, show_temp_type
, NULL
, 2);
670 static SENSOR_DEVICE_ATTR(in0_alarm
, S_IRUGO
, show_alarm
, NULL
, 0);
671 static SENSOR_DEVICE_ATTR(in1_alarm
, S_IRUGO
, show_alarm
, NULL
, 1);
672 static SENSOR_DEVICE_ATTR(in2_alarm
, S_IRUGO
, show_alarm
, NULL
, 2);
673 static SENSOR_DEVICE_ATTR(in3_alarm
, S_IRUGO
, show_alarm
, NULL
, 3);
674 static SENSOR_DEVICE_ATTR(in4_alarm
, S_IRUGO
, show_alarm
, NULL
, 4);
675 static SENSOR_DEVICE_ATTR(in5_alarm
, S_IRUGO
, show_alarm
, NULL
, 5);
676 static SENSOR_DEVICE_ATTR(in6_alarm
, S_IRUGO
, show_alarm
, NULL
, 6);
677 static SENSOR_DEVICE_ATTR(in7_alarm
, S_IRUGO
, show_alarm
, NULL
, 7);
678 static SENSOR_DEVICE_ATTR(in8_alarm
, S_IRUGO
, show_alarm
, NULL
, 8);
679 static SENSOR_DEVICE_ATTR(temp1_alarm
, S_IRUGO
, show_alarm
, NULL
, 11);
680 static SENSOR_DEVICE_ATTR(temp2_alarm
, S_IRUGO
, show_alarm
, NULL
, 12);
681 static SENSOR_DEVICE_ATTR(temp3_alarm
, S_IRUGO
, show_alarm
, NULL
, 13);
682 static SENSOR_DEVICE_ATTR(fan1_alarm
, S_IRUGO
, show_alarm
, NULL
, 16);
683 static SENSOR_DEVICE_ATTR(fan2_alarm
, S_IRUGO
, show_alarm
, NULL
, 17);
684 static SENSOR_DEVICE_ATTR(fan3_alarm
, S_IRUGO
, show_alarm
, NULL
, 18);
685 static DEVICE_ATTR(alarms_in
, S_IRUGO
, show_alarms_in
, NULL
);
686 static DEVICE_ATTR(alarms_fan
, S_IRUGO
, show_alarms_fan
, NULL
);
687 static DEVICE_ATTR(alarms_temp
, S_IRUGO
, show_alarms_temp
, NULL
);
689 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
691 static struct attribute
*f71805f_attributes
[] = {
692 &dev_attr_in0_input
.attr
,
693 &dev_attr_in0_max
.attr
,
694 &dev_attr_in0_min
.attr
,
695 &sensor_dev_attr_in1_input
.dev_attr
.attr
,
696 &sensor_dev_attr_in1_max
.dev_attr
.attr
,
697 &sensor_dev_attr_in1_min
.dev_attr
.attr
,
698 &sensor_dev_attr_in2_input
.dev_attr
.attr
,
699 &sensor_dev_attr_in2_max
.dev_attr
.attr
,
700 &sensor_dev_attr_in2_min
.dev_attr
.attr
,
701 &sensor_dev_attr_in3_input
.dev_attr
.attr
,
702 &sensor_dev_attr_in3_max
.dev_attr
.attr
,
703 &sensor_dev_attr_in3_min
.dev_attr
.attr
,
704 &sensor_dev_attr_in4_input
.dev_attr
.attr
,
705 &sensor_dev_attr_in4_max
.dev_attr
.attr
,
706 &sensor_dev_attr_in4_min
.dev_attr
.attr
,
707 &sensor_dev_attr_in5_input
.dev_attr
.attr
,
708 &sensor_dev_attr_in5_max
.dev_attr
.attr
,
709 &sensor_dev_attr_in5_min
.dev_attr
.attr
,
710 &sensor_dev_attr_in6_input
.dev_attr
.attr
,
711 &sensor_dev_attr_in6_max
.dev_attr
.attr
,
712 &sensor_dev_attr_in6_min
.dev_attr
.attr
,
713 &sensor_dev_attr_in7_input
.dev_attr
.attr
,
714 &sensor_dev_attr_in7_max
.dev_attr
.attr
,
715 &sensor_dev_attr_in7_min
.dev_attr
.attr
,
716 &sensor_dev_attr_in8_input
.dev_attr
.attr
,
717 &sensor_dev_attr_in8_max
.dev_attr
.attr
,
718 &sensor_dev_attr_in8_min
.dev_attr
.attr
,
720 &sensor_dev_attr_temp1_input
.dev_attr
.attr
,
721 &sensor_dev_attr_temp1_max
.dev_attr
.attr
,
722 &sensor_dev_attr_temp1_max_hyst
.dev_attr
.attr
,
723 &sensor_dev_attr_temp1_type
.dev_attr
.attr
,
724 &sensor_dev_attr_temp2_input
.dev_attr
.attr
,
725 &sensor_dev_attr_temp2_max
.dev_attr
.attr
,
726 &sensor_dev_attr_temp2_max_hyst
.dev_attr
.attr
,
727 &sensor_dev_attr_temp2_type
.dev_attr
.attr
,
728 &sensor_dev_attr_temp3_input
.dev_attr
.attr
,
729 &sensor_dev_attr_temp3_max
.dev_attr
.attr
,
730 &sensor_dev_attr_temp3_max_hyst
.dev_attr
.attr
,
731 &sensor_dev_attr_temp3_type
.dev_attr
.attr
,
733 &sensor_dev_attr_in0_alarm
.dev_attr
.attr
,
734 &sensor_dev_attr_in1_alarm
.dev_attr
.attr
,
735 &sensor_dev_attr_in2_alarm
.dev_attr
.attr
,
736 &sensor_dev_attr_in3_alarm
.dev_attr
.attr
,
737 &sensor_dev_attr_in4_alarm
.dev_attr
.attr
,
738 &sensor_dev_attr_in5_alarm
.dev_attr
.attr
,
739 &sensor_dev_attr_in6_alarm
.dev_attr
.attr
,
740 &sensor_dev_attr_in7_alarm
.dev_attr
.attr
,
741 &sensor_dev_attr_in8_alarm
.dev_attr
.attr
,
742 &dev_attr_alarms_in
.attr
,
743 &sensor_dev_attr_temp1_alarm
.dev_attr
.attr
,
744 &sensor_dev_attr_temp2_alarm
.dev_attr
.attr
,
745 &sensor_dev_attr_temp3_alarm
.dev_attr
.attr
,
746 &dev_attr_alarms_temp
.attr
,
747 &dev_attr_alarms_fan
.attr
,
753 static const struct attribute_group f71805f_group
= {
754 .attrs
= f71805f_attributes
,
757 static struct attribute
*f71805f_attributes_fan
[3][4] = {
759 &sensor_dev_attr_fan1_input
.dev_attr
.attr
,
760 &sensor_dev_attr_fan1_min
.dev_attr
.attr
,
761 &sensor_dev_attr_fan1_alarm
.dev_attr
.attr
,
764 &sensor_dev_attr_fan2_input
.dev_attr
.attr
,
765 &sensor_dev_attr_fan2_min
.dev_attr
.attr
,
766 &sensor_dev_attr_fan2_alarm
.dev_attr
.attr
,
769 &sensor_dev_attr_fan3_input
.dev_attr
.attr
,
770 &sensor_dev_attr_fan3_min
.dev_attr
.attr
,
771 &sensor_dev_attr_fan3_alarm
.dev_attr
.attr
,
776 static const struct attribute_group f71805f_group_fan
[3] = {
777 { .attrs
= f71805f_attributes_fan
[0] },
778 { .attrs
= f71805f_attributes_fan
[1] },
779 { .attrs
= f71805f_attributes_fan
[2] },
783 * Device registration and initialization
786 static void __devinit
f71805f_init_device(struct f71805f_data
*data
)
791 reg
= f71805f_read8(data
, F71805F_REG_START
);
792 if ((reg
& 0x41) != 0x01) {
793 printk(KERN_DEBUG DRVNAME
": Starting monitoring "
795 f71805f_write8(data
, F71805F_REG_START
, (reg
| 0x01) & ~0x40);
798 /* Fan monitoring can be disabled. If it is, we won't be polling
799 the register values, and won't create the related sysfs files. */
800 for (i
= 0; i
< 3; i
++) {
801 reg
= f71805f_read8(data
, F71805F_REG_FAN_CTRL(i
));
803 data
->fan_enabled
|= (1 << i
);
807 static int __devinit
f71805f_probe(struct platform_device
*pdev
)
809 struct f71805f_data
*data
;
810 struct resource
*res
;
813 if (!(data
= kzalloc(sizeof(struct f71805f_data
), GFP_KERNEL
))) {
815 printk(KERN_ERR DRVNAME
": Out of memory\n");
819 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
820 data
->addr
= res
->start
;
821 mutex_init(&data
->lock
);
822 data
->name
= "f71805f";
823 mutex_init(&data
->update_lock
);
825 platform_set_drvdata(pdev
, data
);
827 /* Initialize the F71805F chip */
828 f71805f_init_device(data
);
830 /* Register sysfs interface files */
831 if ((err
= sysfs_create_group(&pdev
->dev
.kobj
, &f71805f_group
)))
833 for (i
= 0; i
< 3; i
++) {
834 if (!(data
->fan_enabled
& (1 << i
)))
836 if ((err
= sysfs_create_group(&pdev
->dev
.kobj
,
837 &f71805f_group_fan
[i
])))
838 goto exit_remove_files
;
841 data
->class_dev
= hwmon_device_register(&pdev
->dev
);
842 if (IS_ERR(data
->class_dev
)) {
843 err
= PTR_ERR(data
->class_dev
);
844 dev_err(&pdev
->dev
, "Class registration failed (%d)\n", err
);
845 goto exit_remove_files
;
851 sysfs_remove_group(&pdev
->dev
.kobj
, &f71805f_group
);
852 for (i
= 0; i
< 3; i
++)
853 sysfs_remove_group(&pdev
->dev
.kobj
, &f71805f_group_fan
[i
]);
855 platform_set_drvdata(pdev
, NULL
);
861 static int __devexit
f71805f_remove(struct platform_device
*pdev
)
863 struct f71805f_data
*data
= platform_get_drvdata(pdev
);
866 platform_set_drvdata(pdev
, NULL
);
867 hwmon_device_unregister(data
->class_dev
);
868 sysfs_remove_group(&pdev
->dev
.kobj
, &f71805f_group
);
869 for (i
= 0; i
< 3; i
++)
870 sysfs_remove_group(&pdev
->dev
.kobj
, &f71805f_group_fan
[i
]);
876 static struct platform_driver f71805f_driver
= {
878 .owner
= THIS_MODULE
,
881 .probe
= f71805f_probe
,
882 .remove
= __devexit_p(f71805f_remove
),
885 static int __init
f71805f_device_add(unsigned short address
)
887 struct resource res
= {
889 .end
= address
+ REGION_LENGTH
- 1,
890 .flags
= IORESOURCE_IO
,
894 pdev
= platform_device_alloc(DRVNAME
, address
);
897 printk(KERN_ERR DRVNAME
": Device allocation failed\n");
901 res
.name
= pdev
->name
;
902 err
= platform_device_add_resources(pdev
, &res
, 1);
904 printk(KERN_ERR DRVNAME
": Device resource addition failed "
906 goto exit_device_put
;
909 err
= platform_device_add(pdev
);
911 printk(KERN_ERR DRVNAME
": Device addition failed (%d)\n",
913 goto exit_device_put
;
919 platform_device_put(pdev
);
924 static int __init
f71805f_find(int sioaddr
, unsigned short *address
)
929 superio_enter(sioaddr
);
931 devid
= superio_inw(sioaddr
, SIO_REG_MANID
);
932 if (devid
!= SIO_FINTEK_ID
)
935 devid
= superio_inw(sioaddr
, SIO_REG_DEVID
);
936 if (devid
!= SIO_F71805F_ID
) {
937 printk(KERN_INFO DRVNAME
": Unsupported Fintek device, "
942 superio_select(sioaddr
, F71805F_LD_HWM
);
943 if (!(superio_inb(sioaddr
, SIO_REG_ENABLE
) & 0x01)) {
944 printk(KERN_WARNING DRVNAME
": Device not activated, "
949 *address
= superio_inw(sioaddr
, SIO_REG_ADDR
);
951 printk(KERN_WARNING DRVNAME
": Base address not set, "
957 printk(KERN_INFO DRVNAME
": Found F71805F chip at %#x, revision %u\n",
958 *address
, superio_inb(sioaddr
, SIO_REG_DEVREV
));
961 superio_exit(sioaddr
);
965 static int __init
f71805f_init(void)
968 unsigned short address
;
970 if (f71805f_find(0x2e, &address
)
971 && f71805f_find(0x4e, &address
))
974 err
= platform_driver_register(&f71805f_driver
);
978 /* Sets global pdev as a side effect */
979 err
= f71805f_device_add(address
);
986 platform_driver_unregister(&f71805f_driver
);
991 static void __exit
f71805f_exit(void)
993 platform_device_unregister(pdev
);
994 platform_driver_unregister(&f71805f_driver
);
997 MODULE_AUTHOR("Jean Delvare <khali@linux-fr>");
998 MODULE_LICENSE("GPL");
999 MODULE_DESCRIPTION("F71805F hardware monitoring driver");
1001 module_init(f71805f_init
);
1002 module_exit(f71805f_exit
);