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>
36 static struct platform_device *pdev;
38 #define DRVNAME "f71805f"
41 * Super-I/O constants and functions
44 #define F71805F_LD_HWM 0x04
46 #define SIO_REG_LDSEL 0x07 /* Logical device select */
47 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
48 #define SIO_REG_DEVREV 0x22 /* Device revision */
49 #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
50 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
51 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
53 #define SIO_FINTEK_ID 0x1934
54 #define SIO_F71805F_ID 0x0406
57 superio_inb(int base, int reg)
64 superio_inw(int base, int reg)
68 val = inb(base + 1) << 8;
75 superio_select(int base, int ld)
77 outb(SIO_REG_LDSEL, base);
82 superio_enter(int base)
89 superio_exit(int base)
98 #define REGION_LENGTH 2
99 #define ADDR_REG_OFFSET 0
100 #define DATA_REG_OFFSET 1
106 /* in nr from 0 to 8 (8-bit values) */
107 #define F71805F_REG_IN(nr) (0x10 + (nr))
108 #define F71805F_REG_IN_HIGH(nr) (0x40 + 2 * (nr))
109 #define F71805F_REG_IN_LOW(nr) (0x41 + 2 * (nr))
110 /* fan nr from 0 to 2 (12-bit values, two registers) */
111 #define F71805F_REG_FAN(nr) (0x20 + 2 * (nr))
112 #define F71805F_REG_FAN_LOW(nr) (0x28 + 2 * (nr))
113 #define F71805F_REG_FAN_CTRL(nr) (0x60 + 16 * (nr))
114 /* temp nr from 0 to 2 (8-bit values) */
115 #define F71805F_REG_TEMP(nr) (0x1B + (nr))
116 #define F71805F_REG_TEMP_HIGH(nr) (0x54 + 2 * (nr))
117 #define F71805F_REG_TEMP_HYST(nr) (0x55 + 2 * (nr))
118 #define F71805F_REG_TEMP_MODE 0x01
120 #define F71805F_REG_START 0x00
121 /* status nr from 0 to 2 */
122 #define F71805F_REG_STATUS(nr) (0x36 + (nr))
125 * Data structures and manipulation thereof
128 struct f71805f_data {
132 struct class_device *class_dev;
134 struct mutex update_lock;
135 char valid; /* !=0 if following fields are valid */
136 unsigned long last_updated; /* In jiffies */
137 unsigned long last_limits; /* In jiffies */
139 /* Register values */
145 u8 fan_enabled; /* Read once at init time */
150 unsigned long alarms;
153 static inline long in_from_reg(u8 reg)
158 /* The 2 least significant bits are not used */
159 static inline u8 in_to_reg(long val)
165 return (((val + 16) / 32) << 2);
168 /* in0 is downscaled by a factor 2 internally */
169 static inline long in0_from_reg(u8 reg)
174 static inline u8 in0_to_reg(long val)
180 return (((val + 32) / 64) << 2);
183 /* The 4 most significant bits are not used */
184 static inline long fan_from_reg(u16 reg)
187 if (!reg || reg == 0xfff)
189 return (1500000 / reg);
192 static inline u16 fan_to_reg(long rpm)
194 /* If the low limit is set below what the chip can measure,
195 store the largest possible 12-bit value in the registers,
196 so that no alarm will ever trigger. */
199 return (1500000 / rpm);
202 static inline long temp_from_reg(u8 reg)
207 static inline u8 temp_to_reg(long val)
211 else if (val > 1000 * 0xff)
213 return ((val + 500) / 1000);
220 static u8 f71805f_read8(struct f71805f_data *data, u8 reg)
224 mutex_lock(&data->lock);
225 outb(reg, data->addr + ADDR_REG_OFFSET);
226 val = inb(data->addr + DATA_REG_OFFSET);
227 mutex_unlock(&data->lock);
232 static void f71805f_write8(struct f71805f_data *data, u8 reg, u8 val)
234 mutex_lock(&data->lock);
235 outb(reg, data->addr + ADDR_REG_OFFSET);
236 outb(val, data->addr + DATA_REG_OFFSET);
237 mutex_unlock(&data->lock);
240 /* It is important to read the MSB first, because doing so latches the
241 value of the LSB, so we are sure both bytes belong to the same value. */
242 static u16 f71805f_read16(struct f71805f_data *data, u8 reg)
246 mutex_lock(&data->lock);
247 outb(reg, data->addr + ADDR_REG_OFFSET);
248 val = inb(data->addr + DATA_REG_OFFSET) << 8;
249 outb(++reg, data->addr + ADDR_REG_OFFSET);
250 val |= inb(data->addr + DATA_REG_OFFSET);
251 mutex_unlock(&data->lock);
256 static void f71805f_write16(struct f71805f_data *data, u8 reg, u16 val)
258 mutex_lock(&data->lock);
259 outb(reg, data->addr + ADDR_REG_OFFSET);
260 outb(val >> 8, data->addr + DATA_REG_OFFSET);
261 outb(++reg, data->addr + ADDR_REG_OFFSET);
262 outb(val & 0xff, data->addr + DATA_REG_OFFSET);
263 mutex_unlock(&data->lock);
266 static struct f71805f_data *f71805f_update_device(struct device *dev)
268 struct f71805f_data *data = dev_get_drvdata(dev);
271 mutex_lock(&data->update_lock);
273 /* Limit registers cache is refreshed after 60 seconds */
274 if (time_after(jiffies, data->last_updated + 60 * HZ)
276 for (nr = 0; nr < 9; nr++) {
277 data->in_high[nr] = f71805f_read8(data,
278 F71805F_REG_IN_HIGH(nr));
279 data->in_low[nr] = f71805f_read8(data,
280 F71805F_REG_IN_LOW(nr));
282 for (nr = 0; nr < 3; nr++) {
283 if (data->fan_enabled & (1 << nr))
284 data->fan_low[nr] = f71805f_read16(data,
285 F71805F_REG_FAN_LOW(nr));
287 for (nr = 0; nr < 3; nr++) {
288 data->temp_high[nr] = f71805f_read8(data,
289 F71805F_REG_TEMP_HIGH(nr));
290 data->temp_hyst[nr] = f71805f_read8(data,
291 F71805F_REG_TEMP_HYST(nr));
293 data->temp_mode = f71805f_read8(data, F71805F_REG_TEMP_MODE);
295 data->last_limits = jiffies;
298 /* Measurement registers cache is refreshed after 1 second */
299 if (time_after(jiffies, data->last_updated + HZ)
301 for (nr = 0; nr < 9; nr++) {
302 data->in[nr] = f71805f_read8(data,
305 for (nr = 0; nr < 3; nr++) {
306 if (data->fan_enabled & (1 << nr))
307 data->fan[nr] = f71805f_read16(data,
308 F71805F_REG_FAN(nr));
310 for (nr = 0; nr < 3; nr++) {
311 data->temp[nr] = f71805f_read8(data,
312 F71805F_REG_TEMP(nr));
314 data->alarms = f71805f_read8(data, F71805F_REG_STATUS(0))
315 + (f71805f_read8(data, F71805F_REG_STATUS(1)) << 8)
316 + (f71805f_read8(data, F71805F_REG_STATUS(2)) << 16);
318 data->last_updated = jiffies;
322 mutex_unlock(&data->update_lock);
331 static ssize_t show_in0(struct device *dev, struct device_attribute *devattr,
334 struct f71805f_data *data = f71805f_update_device(dev);
336 return sprintf(buf, "%ld\n", in0_from_reg(data->in[0]));
339 static ssize_t show_in0_max(struct device *dev, struct device_attribute
342 struct f71805f_data *data = f71805f_update_device(dev);
344 return sprintf(buf, "%ld\n", in0_from_reg(data->in_high[0]));
347 static ssize_t show_in0_min(struct device *dev, struct device_attribute
350 struct f71805f_data *data = f71805f_update_device(dev);
352 return sprintf(buf, "%ld\n", in0_from_reg(data->in_low[0]));
355 static ssize_t set_in0_max(struct device *dev, struct device_attribute
356 *devattr, const char *buf, size_t count)
358 struct f71805f_data *data = dev_get_drvdata(dev);
359 long val = simple_strtol(buf, NULL, 10);
361 mutex_lock(&data->update_lock);
362 data->in_high[0] = in0_to_reg(val);
363 f71805f_write8(data, F71805F_REG_IN_HIGH(0), data->in_high[0]);
364 mutex_unlock(&data->update_lock);
369 static ssize_t set_in0_min(struct device *dev, struct device_attribute
370 *devattr, const char *buf, size_t count)
372 struct f71805f_data *data = dev_get_drvdata(dev);
373 long val = simple_strtol(buf, NULL, 10);
375 mutex_lock(&data->update_lock);
376 data->in_low[0] = in0_to_reg(val);
377 f71805f_write8(data, F71805F_REG_IN_LOW(0), data->in_low[0]);
378 mutex_unlock(&data->update_lock);
383 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
386 struct f71805f_data *data = f71805f_update_device(dev);
387 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
388 int nr = attr->index;
390 return sprintf(buf, "%ld\n", in_from_reg(data->in[nr]));
393 static ssize_t show_in_max(struct device *dev, struct device_attribute
396 struct f71805f_data *data = f71805f_update_device(dev);
397 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
398 int nr = attr->index;
400 return sprintf(buf, "%ld\n", in_from_reg(data->in_high[nr]));
403 static ssize_t show_in_min(struct device *dev, struct device_attribute
406 struct f71805f_data *data = f71805f_update_device(dev);
407 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
408 int nr = attr->index;
410 return sprintf(buf, "%ld\n", in_from_reg(data->in_low[nr]));
413 static ssize_t set_in_max(struct device *dev, struct device_attribute
414 *devattr, const char *buf, size_t count)
416 struct f71805f_data *data = dev_get_drvdata(dev);
417 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
418 int nr = attr->index;
419 long val = simple_strtol(buf, NULL, 10);
421 mutex_lock(&data->update_lock);
422 data->in_high[nr] = in_to_reg(val);
423 f71805f_write8(data, F71805F_REG_IN_HIGH(nr), data->in_high[nr]);
424 mutex_unlock(&data->update_lock);
429 static ssize_t set_in_min(struct device *dev, struct device_attribute
430 *devattr, const char *buf, size_t count)
432 struct f71805f_data *data = dev_get_drvdata(dev);
433 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
434 int nr = attr->index;
435 long val = simple_strtol(buf, NULL, 10);
437 mutex_lock(&data->update_lock);
438 data->in_low[nr] = in_to_reg(val);
439 f71805f_write8(data, F71805F_REG_IN_LOW(nr), data->in_low[nr]);
440 mutex_unlock(&data->update_lock);
445 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
448 struct f71805f_data *data = f71805f_update_device(dev);
449 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
450 int nr = attr->index;
452 return sprintf(buf, "%ld\n", fan_from_reg(data->fan[nr]));
455 static ssize_t show_fan_min(struct device *dev, struct device_attribute
458 struct f71805f_data *data = f71805f_update_device(dev);
459 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
460 int nr = attr->index;
462 return sprintf(buf, "%ld\n", fan_from_reg(data->fan_low[nr]));
465 static ssize_t set_fan_min(struct device *dev, struct device_attribute
466 *devattr, const char *buf, size_t count)
468 struct f71805f_data *data = dev_get_drvdata(dev);
469 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
470 int nr = attr->index;
471 long val = simple_strtol(buf, NULL, 10);
473 mutex_lock(&data->update_lock);
474 data->fan_low[nr] = fan_to_reg(val);
475 f71805f_write16(data, F71805F_REG_FAN_LOW(nr), data->fan_low[nr]);
476 mutex_unlock(&data->update_lock);
481 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
484 struct f71805f_data *data = f71805f_update_device(dev);
485 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
486 int nr = attr->index;
488 return sprintf(buf, "%ld\n", temp_from_reg(data->temp[nr]));
491 static ssize_t show_temp_max(struct device *dev, struct device_attribute
494 struct f71805f_data *data = f71805f_update_device(dev);
495 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
496 int nr = attr->index;
498 return sprintf(buf, "%ld\n", temp_from_reg(data->temp_high[nr]));
501 static ssize_t show_temp_hyst(struct device *dev, struct device_attribute
504 struct f71805f_data *data = f71805f_update_device(dev);
505 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
506 int nr = attr->index;
508 return sprintf(buf, "%ld\n", temp_from_reg(data->temp_hyst[nr]));
511 static ssize_t show_temp_type(struct device *dev, struct device_attribute
514 struct f71805f_data *data = f71805f_update_device(dev);
515 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
516 int nr = attr->index;
518 /* 3 is diode, 4 is thermistor */
519 return sprintf(buf, "%u\n", (data->temp_mode & (1 << nr)) ? 3 : 4);
522 static ssize_t set_temp_max(struct device *dev, struct device_attribute
523 *devattr, const char *buf, size_t count)
525 struct f71805f_data *data = dev_get_drvdata(dev);
526 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
527 int nr = attr->index;
528 long val = simple_strtol(buf, NULL, 10);
530 mutex_lock(&data->update_lock);
531 data->temp_high[nr] = temp_to_reg(val);
532 f71805f_write8(data, F71805F_REG_TEMP_HIGH(nr), data->temp_high[nr]);
533 mutex_unlock(&data->update_lock);
538 static ssize_t set_temp_hyst(struct device *dev, struct device_attribute
539 *devattr, const char *buf, size_t count)
541 struct f71805f_data *data = dev_get_drvdata(dev);
542 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
543 int nr = attr->index;
544 long val = simple_strtol(buf, NULL, 10);
546 mutex_lock(&data->update_lock);
547 data->temp_hyst[nr] = temp_to_reg(val);
548 f71805f_write8(data, F71805F_REG_TEMP_HYST(nr), data->temp_hyst[nr]);
549 mutex_unlock(&data->update_lock);
554 static ssize_t show_alarms_in(struct device *dev, struct device_attribute
557 struct f71805f_data *data = f71805f_update_device(dev);
559 return sprintf(buf, "%lu\n", data->alarms & 0x1ff);
562 static ssize_t show_alarms_fan(struct device *dev, struct device_attribute
565 struct f71805f_data *data = f71805f_update_device(dev);
567 return sprintf(buf, "%lu\n", (data->alarms >> 16) & 0x07);
570 static ssize_t show_alarms_temp(struct device *dev, struct device_attribute
573 struct f71805f_data *data = f71805f_update_device(dev);
575 return sprintf(buf, "%lu\n", (data->alarms >> 11) & 0x07);
578 static ssize_t show_alarm(struct device *dev, struct device_attribute
581 struct f71805f_data *data = f71805f_update_device(dev);
582 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
583 int bitnr = attr->index;
585 return sprintf(buf, "%lu\n", (data->alarms >> bitnr) & 1);
588 static ssize_t show_name(struct device *dev, struct device_attribute
591 struct f71805f_data *data = dev_get_drvdata(dev);
593 return sprintf(buf, "%s\n", data->name);
596 static struct device_attribute f71805f_dev_attr[] = {
597 __ATTR(in0_input, S_IRUGO, show_in0, NULL),
598 __ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max),
599 __ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min),
600 __ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL),
601 __ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL),
602 __ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL),
603 __ATTR(name, S_IRUGO, show_name, NULL),
606 static struct sensor_device_attribute f71805f_sensor_attr[] = {
607 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1),
608 SENSOR_ATTR(in1_max, S_IRUGO | S_IWUSR,
609 show_in_max, set_in_max, 1),
610 SENSOR_ATTR(in1_min, S_IRUGO | S_IWUSR,
611 show_in_min, set_in_min, 1),
612 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
613 SENSOR_ATTR(in2_max, S_IRUGO | S_IWUSR,
614 show_in_max, set_in_max, 2),
615 SENSOR_ATTR(in2_min, S_IRUGO | S_IWUSR,
616 show_in_min, set_in_min, 2),
617 SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
618 SENSOR_ATTR(in3_max, S_IRUGO | S_IWUSR,
619 show_in_max, set_in_max, 3),
620 SENSOR_ATTR(in3_min, S_IRUGO | S_IWUSR,
621 show_in_min, set_in_min, 3),
622 SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
623 SENSOR_ATTR(in4_max, S_IRUGO | S_IWUSR,
624 show_in_max, set_in_max, 4),
625 SENSOR_ATTR(in4_min, S_IRUGO | S_IWUSR,
626 show_in_min, set_in_min, 4),
627 SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
628 SENSOR_ATTR(in5_max, S_IRUGO | S_IWUSR,
629 show_in_max, set_in_max, 5),
630 SENSOR_ATTR(in5_min, S_IRUGO | S_IWUSR,
631 show_in_min, set_in_min, 5),
632 SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
633 SENSOR_ATTR(in6_max, S_IRUGO | S_IWUSR,
634 show_in_max, set_in_max, 6),
635 SENSOR_ATTR(in6_min, S_IRUGO | S_IWUSR,
636 show_in_min, set_in_min, 6),
637 SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
638 SENSOR_ATTR(in7_max, S_IRUGO | S_IWUSR,
639 show_in_max, set_in_max, 7),
640 SENSOR_ATTR(in7_min, S_IRUGO | S_IWUSR,
641 show_in_min, set_in_min, 7),
642 SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
643 SENSOR_ATTR(in8_max, S_IRUGO | S_IWUSR,
644 show_in_max, set_in_max, 8),
645 SENSOR_ATTR(in8_min, S_IRUGO | S_IWUSR,
646 show_in_min, set_in_min, 8),
648 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0),
649 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR,
650 show_temp_max, set_temp_max, 0),
651 SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
652 show_temp_hyst, set_temp_hyst, 0),
653 SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0),
654 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1),
655 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR,
656 show_temp_max, set_temp_max, 1),
657 SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
658 show_temp_hyst, set_temp_hyst, 1),
659 SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1),
660 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2),
661 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR,
662 show_temp_max, set_temp_max, 2),
663 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
664 show_temp_hyst, set_temp_hyst, 2),
665 SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
667 SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0),
668 SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1),
669 SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2),
670 SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3),
671 SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4),
672 SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5),
673 SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6),
674 SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7),
675 SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8),
676 SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 11),
677 SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 12),
678 SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13),
681 static struct sensor_device_attribute f71805f_fan_attr[] = {
682 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0),
683 SENSOR_ATTR(fan1_min, S_IRUGO | S_IWUSR,
684 show_fan_min, set_fan_min, 0),
685 SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16),
686 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1),
687 SENSOR_ATTR(fan2_min, S_IRUGO | S_IWUSR,
688 show_fan_min, set_fan_min, 1),
689 SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17),
690 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2),
691 SENSOR_ATTR(fan3_min, S_IRUGO | S_IWUSR,
692 show_fan_min, set_fan_min, 2),
693 SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18),
697 * Device registration and initialization
700 static void __devinit f71805f_init_device(struct f71805f_data *data)
705 reg = f71805f_read8(data, F71805F_REG_START);
706 if ((reg & 0x41) != 0x01) {
707 printk(KERN_DEBUG DRVNAME ": Starting monitoring "
709 f71805f_write8(data, F71805F_REG_START, (reg | 0x01) & ~0x40);
712 /* Fan monitoring can be disabled. If it is, we won't be polling
713 the register values, and won't create the related sysfs files. */
714 for (i = 0; i < 3; i++) {
715 reg = f71805f_read8(data, F71805F_REG_FAN_CTRL(i));
717 data->fan_enabled |= (1 << i);
721 static int __devinit f71805f_probe(struct platform_device *pdev)
723 struct f71805f_data *data;
724 struct resource *res;
727 if (!(data = kzalloc(sizeof(struct f71805f_data), GFP_KERNEL))) {
729 printk(KERN_ERR DRVNAME ": Out of memory\n");
733 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
734 data->addr = res->start;
735 mutex_init(&data->lock);
736 data->name = "f71805f";
737 mutex_init(&data->update_lock);
739 platform_set_drvdata(pdev, data);
741 data->class_dev = hwmon_device_register(&pdev->dev);
742 if (IS_ERR(data->class_dev)) {
743 err = PTR_ERR(data->class_dev);
744 dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
748 /* Initialize the F71805F chip */
749 f71805f_init_device(data);
751 /* Register sysfs interface files */
752 for (i = 0; i < ARRAY_SIZE(f71805f_dev_attr); i++) {
753 err = device_create_file(&pdev->dev, &f71805f_dev_attr[i]);
757 for (i = 0; i < ARRAY_SIZE(f71805f_sensor_attr); i++) {
758 err = device_create_file(&pdev->dev,
759 &f71805f_sensor_attr[i].dev_attr);
763 for (i = 0; i < ARRAY_SIZE(f71805f_fan_attr); i++) {
764 if (!(data->fan_enabled & (1 << (i / 3))))
766 err = device_create_file(&pdev->dev,
767 &f71805f_fan_attr[i].dev_attr);
775 dev_err(&pdev->dev, "Sysfs interface creation failed\n");
776 hwmon_device_unregister(data->class_dev);
783 static int __devexit f71805f_remove(struct platform_device *pdev)
785 struct f71805f_data *data = platform_get_drvdata(pdev);
787 platform_set_drvdata(pdev, NULL);
788 hwmon_device_unregister(data->class_dev);
794 static struct platform_driver f71805f_driver = {
796 .owner = THIS_MODULE,
799 .probe = f71805f_probe,
800 .remove = __devexit_p(f71805f_remove),
803 static int __init f71805f_device_add(unsigned short address)
805 struct resource res = {
807 .end = address + REGION_LENGTH - 1,
808 .flags = IORESOURCE_IO,
812 pdev = platform_device_alloc(DRVNAME, address);
815 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
819 res.name = pdev->name;
820 err = platform_device_add_resources(pdev, &res, 1);
822 printk(KERN_ERR DRVNAME ": Device resource addition failed "
824 goto exit_device_put;
827 err = platform_device_add(pdev);
829 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
831 goto exit_device_put;
837 platform_device_put(pdev);
842 static int __init f71805f_find(int sioaddr, unsigned short *address)
847 superio_enter(sioaddr);
849 devid = superio_inw(sioaddr, SIO_REG_MANID);
850 if (devid != SIO_FINTEK_ID)
853 devid = superio_inw(sioaddr, SIO_REG_DEVID);
854 if (devid != SIO_F71805F_ID) {
855 printk(KERN_INFO DRVNAME ": Unsupported Fintek device, "
860 superio_select(sioaddr, F71805F_LD_HWM);
861 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
862 printk(KERN_WARNING DRVNAME ": Device not activated, "
867 *address = superio_inw(sioaddr, SIO_REG_ADDR);
869 printk(KERN_WARNING DRVNAME ": Base address not set, "
875 printk(KERN_INFO DRVNAME ": Found F71805F chip at %#x, revision %u\n",
876 *address, superio_inb(sioaddr, SIO_REG_DEVREV));
879 superio_exit(sioaddr);
883 static int __init f71805f_init(void)
886 unsigned short address;
888 if (f71805f_find(0x2e, &address)
889 && f71805f_find(0x4e, &address))
892 err = platform_driver_register(&f71805f_driver);
896 /* Sets global pdev as a side effect */
897 err = f71805f_device_add(address);
904 platform_driver_unregister(&f71805f_driver);
909 static void __exit f71805f_exit(void)
911 platform_device_unregister(pdev);
912 platform_driver_unregister(&f71805f_driver);
915 MODULE_AUTHOR("Jean Delvare <khali@linux-fr>");
916 MODULE_LICENSE("GPL");
917 MODULE_DESCRIPTION("F71805F hardware monitoring driver");
919 module_init(f71805f_init);
920 module_exit(f71805f_exit);