aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/f71805f.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/f71805f.c')
-rw-r--r--drivers/hwmon/f71805f.c336
1 files changed, 221 insertions, 115 deletions
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index fd72440faf76..de17a72149d9 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -1,7 +1,7 @@
1/* 1/*
2 * f71805f.c - driver for the Fintek F71805F/FG Super-I/O chip integrated 2 * f71805f.c - driver for the Fintek F71805F/FG Super-I/O chip integrated
3 * hardware monitoring features 3 * hardware monitoring features
4 * Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> 4 * Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
5 * 5 *
6 * The F71805F/FG is a LPC Super-I/O chip made by Fintek. It integrates 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 7 * complete hardware monitoring features: voltage, fan and temperature
@@ -31,6 +31,7 @@
31#include <linux/hwmon-sysfs.h> 31#include <linux/hwmon-sysfs.h>
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/mutex.h> 33#include <linux/mutex.h>
34#include <linux/sysfs.h>
34#include <asm/io.h> 35#include <asm/io.h>
35 36
36static struct platform_device *pdev; 37static struct platform_device *pdev;
@@ -147,7 +148,7 @@ struct f71805f_data {
147 u8 temp_high[3]; 148 u8 temp_high[3];
148 u8 temp_hyst[3]; 149 u8 temp_hyst[3];
149 u8 temp_mode; 150 u8 temp_mode;
150 u8 alarms[3]; 151 unsigned long alarms;
151}; 152};
152 153
153static inline long in_from_reg(u8 reg) 154static inline long in_from_reg(u8 reg)
@@ -311,10 +312,9 @@ static struct f71805f_data *f71805f_update_device(struct device *dev)
311 data->temp[nr] = f71805f_read8(data, 312 data->temp[nr] = f71805f_read8(data,
312 F71805F_REG_TEMP(nr)); 313 F71805F_REG_TEMP(nr));
313 } 314 }
314 for (nr = 0; nr < 3; nr++) { 315 data->alarms = f71805f_read8(data, F71805F_REG_STATUS(0))
315 data->alarms[nr] = f71805f_read8(data, 316 + (f71805f_read8(data, F71805F_REG_STATUS(1)) << 8)
316 F71805F_REG_STATUS(nr)); 317 + (f71805f_read8(data, F71805F_REG_STATUS(2)) << 16);
317 }
318 318
319 data->last_updated = jiffies; 319 data->last_updated = jiffies;
320 data->valid = 1; 320 data->valid = 1;
@@ -557,8 +557,7 @@ static ssize_t show_alarms_in(struct device *dev, struct device_attribute
557{ 557{
558 struct f71805f_data *data = f71805f_update_device(dev); 558 struct f71805f_data *data = f71805f_update_device(dev);
559 559
560 return sprintf(buf, "%d\n", data->alarms[0] | 560 return sprintf(buf, "%lu\n", data->alarms & 0x1ff);
561 ((data->alarms[1] & 0x01) << 8));
562} 561}
563 562
564static ssize_t show_alarms_fan(struct device *dev, struct device_attribute 563static ssize_t show_alarms_fan(struct device *dev, struct device_attribute
@@ -566,7 +565,7 @@ static ssize_t show_alarms_fan(struct device *dev, struct device_attribute
566{ 565{
567 struct f71805f_data *data = f71805f_update_device(dev); 566 struct f71805f_data *data = f71805f_update_device(dev);
568 567
569 return sprintf(buf, "%d\n", data->alarms[2] & 0x07); 568 return sprintf(buf, "%lu\n", (data->alarms >> 16) & 0x07);
570} 569}
571 570
572static ssize_t show_alarms_temp(struct device *dev, struct device_attribute 571static ssize_t show_alarms_temp(struct device *dev, struct device_attribute
@@ -574,7 +573,17 @@ static ssize_t show_alarms_temp(struct device *dev, struct device_attribute
574{ 573{
575 struct f71805f_data *data = f71805f_update_device(dev); 574 struct f71805f_data *data = f71805f_update_device(dev);
576 575
577 return sprintf(buf, "%d\n", (data->alarms[1] >> 3) & 0x07); 576 return sprintf(buf, "%lu\n", (data->alarms >> 11) & 0x07);
577}
578
579static ssize_t show_alarm(struct device *dev, struct device_attribute
580 *devattr, char *buf)
581{
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;
585
586 return sprintf(buf, "%lu\n", (data->alarms >> bitnr) & 1);
578} 587}
579 588
580static ssize_t show_name(struct device *dev, struct device_attribute 589static ssize_t show_name(struct device *dev, struct device_attribute
@@ -585,88 +594,189 @@ static ssize_t show_name(struct device *dev, struct device_attribute
585 return sprintf(buf, "%s\n", data->name); 594 return sprintf(buf, "%s\n", data->name);
586} 595}
587 596
588static struct device_attribute f71805f_dev_attr[] = { 597static DEVICE_ATTR(in0_input, S_IRUGO, show_in0, NULL);
589 __ATTR(in0_input, S_IRUGO, show_in0, NULL), 598static DEVICE_ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max);
590 __ATTR(in0_max, S_IRUGO| S_IWUSR, show_in0_max, set_in0_max), 599static DEVICE_ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min);
591 __ATTR(in0_min, S_IRUGO| S_IWUSR, show_in0_min, set_in0_min), 600static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, show_in, NULL, 1);
592 __ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL), 601static SENSOR_DEVICE_ATTR(in1_max, S_IRUGO | S_IWUSR,
593 __ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL), 602 show_in_max, set_in_max, 1);
594 __ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL), 603static SENSOR_DEVICE_ATTR(in1_min, S_IRUGO | S_IWUSR,
595 __ATTR(name, S_IRUGO, show_name, NULL), 604 show_in_min, set_in_min, 1);
605static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, show_in, NULL, 2);
606static SENSOR_DEVICE_ATTR(in2_max, S_IRUGO | S_IWUSR,
607 show_in_max, set_in_max, 2);
608static SENSOR_DEVICE_ATTR(in2_min, S_IRUGO | S_IWUSR,
609 show_in_min, set_in_min, 2);
610static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, show_in, NULL, 3);
611static SENSOR_DEVICE_ATTR(in3_max, S_IRUGO | S_IWUSR,
612 show_in_max, set_in_max, 3);
613static SENSOR_DEVICE_ATTR(in3_min, S_IRUGO | S_IWUSR,
614 show_in_min, set_in_min, 3);
615static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, show_in, NULL, 4);
616static SENSOR_DEVICE_ATTR(in4_max, S_IRUGO | S_IWUSR,
617 show_in_max, set_in_max, 4);
618static SENSOR_DEVICE_ATTR(in4_min, S_IRUGO | S_IWUSR,
619 show_in_min, set_in_min, 4);
620static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, show_in, NULL, 5);
621static SENSOR_DEVICE_ATTR(in5_max, S_IRUGO | S_IWUSR,
622 show_in_max, set_in_max, 5);
623static SENSOR_DEVICE_ATTR(in5_min, S_IRUGO | S_IWUSR,
624 show_in_min, set_in_min, 5);
625static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, show_in, NULL, 6);
626static SENSOR_DEVICE_ATTR(in6_max, S_IRUGO | S_IWUSR,
627 show_in_max, set_in_max, 6);
628static SENSOR_DEVICE_ATTR(in6_min, S_IRUGO | S_IWUSR,
629 show_in_min, set_in_min, 6);
630static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, show_in, NULL, 7);
631static SENSOR_DEVICE_ATTR(in7_max, S_IRUGO | S_IWUSR,
632 show_in_max, set_in_max, 7);
633static SENSOR_DEVICE_ATTR(in7_min, S_IRUGO | S_IWUSR,
634 show_in_min, set_in_min, 7);
635static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, show_in, NULL, 8);
636static SENSOR_DEVICE_ATTR(in8_max, S_IRUGO | S_IWUSR,
637 show_in_max, set_in_max, 8);
638static SENSOR_DEVICE_ATTR(in8_min, S_IRUGO | S_IWUSR,
639 show_in_min, set_in_min, 8);
640
641static SENSOR_DEVICE_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0);
642static SENSOR_DEVICE_ATTR(fan1_min, S_IRUGO | S_IWUSR,
643 show_fan_min, set_fan_min, 0);
644static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
645static SENSOR_DEVICE_ATTR(fan2_min, S_IRUGO | S_IWUSR,
646 show_fan_min, set_fan_min, 1);
647static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
648static SENSOR_DEVICE_ATTR(fan3_min, S_IRUGO | S_IWUSR,
649 show_fan_min, set_fan_min, 2);
650
651static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0);
652static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR,
653 show_temp_max, set_temp_max, 0);
654static SENSOR_DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
655 show_temp_hyst, set_temp_hyst, 0);
656static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0);
657static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1);
658static SENSOR_DEVICE_ATTR(temp2_max, S_IRUGO | S_IWUSR,
659 show_temp_max, set_temp_max, 1);
660static SENSOR_DEVICE_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
661 show_temp_hyst, set_temp_hyst, 1);
662static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1);
663static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2);
664static SENSOR_DEVICE_ATTR(temp3_max, S_IRUGO | S_IWUSR,
665 show_temp_max, set_temp_max, 2);
666static SENSOR_DEVICE_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
667 show_temp_hyst, set_temp_hyst, 2);
668static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2);
669
670static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
671static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
672static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
673static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
674static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 4);
675static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 5);
676static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6);
677static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7);
678static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 8);
679static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 11);
680static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 12);
681static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13);
682static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 16);
683static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 17);
684static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 18);
685static DEVICE_ATTR(alarms_in, S_IRUGO, show_alarms_in, NULL);
686static DEVICE_ATTR(alarms_fan, S_IRUGO, show_alarms_fan, NULL);
687static DEVICE_ATTR(alarms_temp, S_IRUGO, show_alarms_temp, NULL);
688
689static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
690
691static 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,
719
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,
732
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,
748
749 &dev_attr_name.attr,
750 NULL
596}; 751};
597 752
598static struct sensor_device_attribute f71805f_sensor_attr[] = { 753static const struct attribute_group f71805f_group = {
599 SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1), 754 .attrs = f71805f_attributes,
600 SENSOR_ATTR(in1_max, S_IRUGO | S_IWUSR,
601 show_in_max, set_in_max, 1),
602 SENSOR_ATTR(in1_min, S_IRUGO | S_IWUSR,
603 show_in_min, set_in_min, 1),
604 SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2),
605 SENSOR_ATTR(in2_max, S_IRUGO | S_IWUSR,
606 show_in_max, set_in_max, 2),
607 SENSOR_ATTR(in2_min, S_IRUGO | S_IWUSR,
608 show_in_min, set_in_min, 2),
609 SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3),
610 SENSOR_ATTR(in3_max, S_IRUGO | S_IWUSR,
611 show_in_max, set_in_max, 3),
612 SENSOR_ATTR(in3_min, S_IRUGO | S_IWUSR,
613 show_in_min, set_in_min, 3),
614 SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4),
615 SENSOR_ATTR(in4_max, S_IRUGO | S_IWUSR,
616 show_in_max, set_in_max, 4),
617 SENSOR_ATTR(in4_min, S_IRUGO | S_IWUSR,
618 show_in_min, set_in_min, 4),
619 SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5),
620 SENSOR_ATTR(in5_max, S_IRUGO | S_IWUSR,
621 show_in_max, set_in_max, 5),
622 SENSOR_ATTR(in5_min, S_IRUGO | S_IWUSR,
623 show_in_min, set_in_min, 5),
624 SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6),
625 SENSOR_ATTR(in6_max, S_IRUGO | S_IWUSR,
626 show_in_max, set_in_max, 6),
627 SENSOR_ATTR(in6_min, S_IRUGO | S_IWUSR,
628 show_in_min, set_in_min, 6),
629 SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7),
630 SENSOR_ATTR(in7_max, S_IRUGO | S_IWUSR,
631 show_in_max, set_in_max, 7),
632 SENSOR_ATTR(in7_min, S_IRUGO | S_IWUSR,
633 show_in_min, set_in_min, 7),
634 SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8),
635 SENSOR_ATTR(in8_max, S_IRUGO | S_IWUSR,
636 show_in_max, set_in_max, 8),
637 SENSOR_ATTR(in8_min, S_IRUGO | S_IWUSR,
638 show_in_min, set_in_min, 8),
639
640 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0),
641 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR,
642 show_temp_max, set_temp_max, 0),
643 SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR,
644 show_temp_hyst, set_temp_hyst, 0),
645 SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0),
646 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1),
647 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR,
648 show_temp_max, set_temp_max, 1),
649 SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR,
650 show_temp_hyst, set_temp_hyst, 1),
651 SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1),
652 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2),
653 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR,
654 show_temp_max, set_temp_max, 2),
655 SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR,
656 show_temp_hyst, set_temp_hyst, 2),
657 SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2),
658}; 755};
659 756
660static struct sensor_device_attribute f71805f_fan_attr[] = { 757static struct attribute *f71805f_attributes_fan[3][4] = {
661 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0), 758 {
662 SENSOR_ATTR(fan1_min, S_IRUGO | S_IWUSR, 759 &sensor_dev_attr_fan1_input.dev_attr.attr,
663 show_fan_min, set_fan_min, 0), 760 &sensor_dev_attr_fan1_min.dev_attr.attr,
664 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1), 761 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
665 SENSOR_ATTR(fan2_min, S_IRUGO | S_IWUSR, 762 NULL
666 show_fan_min, set_fan_min, 1), 763 }, {
667 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2), 764 &sensor_dev_attr_fan2_input.dev_attr.attr,
668 SENSOR_ATTR(fan3_min, S_IRUGO | S_IWUSR, 765 &sensor_dev_attr_fan2_min.dev_attr.attr,
669 show_fan_min, set_fan_min, 2), 766 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
767 NULL
768 }, {
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,
772 NULL
773 }
774};
775
776static 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] },
670}; 780};
671 781
672/* 782/*
@@ -714,43 +824,35 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
714 824
715 platform_set_drvdata(pdev, data); 825 platform_set_drvdata(pdev, data);
716 826
717 data->class_dev = hwmon_device_register(&pdev->dev);
718 if (IS_ERR(data->class_dev)) {
719 err = PTR_ERR(data->class_dev);
720 dev_err(&pdev->dev, "Class registration failed (%d)\n", err);
721 goto exit_free;
722 }
723
724 /* Initialize the F71805F chip */ 827 /* Initialize the F71805F chip */
725 f71805f_init_device(data); 828 f71805f_init_device(data);
726 829
727 /* Register sysfs interface files */ 830 /* Register sysfs interface files */
728 for (i = 0; i < ARRAY_SIZE(f71805f_dev_attr); i++) { 831 if ((err = sysfs_create_group(&pdev->dev.kobj, &f71805f_group)))
729 err = device_create_file(&pdev->dev, &f71805f_dev_attr[i]); 832 goto exit_free;
730 if (err) 833 for (i = 0; i < 3; i++) {
731 goto exit_class; 834 if (!(data->fan_enabled & (1 << i)))
732 }
733 for (i = 0; i < ARRAY_SIZE(f71805f_sensor_attr); i++) {
734 err = device_create_file(&pdev->dev,
735 &f71805f_sensor_attr[i].dev_attr);
736 if (err)
737 goto exit_class;
738 }
739 for (i = 0; i < ARRAY_SIZE(f71805f_fan_attr); i++) {
740 if (!(data->fan_enabled & (1 << (i / 2))))
741 continue; 835 continue;
742 err = device_create_file(&pdev->dev, 836 if ((err = sysfs_create_group(&pdev->dev.kobj,
743 &f71805f_fan_attr[i].dev_attr); 837 &f71805f_group_fan[i])))
744 if (err) 838 goto exit_remove_files;
745 goto exit_class; 839 }
840
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;
746 } 846 }
747 847
748 return 0; 848 return 0;
749 849
750exit_class: 850exit_remove_files:
751 dev_err(&pdev->dev, "Sysfs interface creation failed\n"); 851 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group);
752 hwmon_device_unregister(data->class_dev); 852 for (i = 0; i < 3; i++)
853 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]);
753exit_free: 854exit_free:
855 platform_set_drvdata(pdev, NULL);
754 kfree(data); 856 kfree(data);
755exit: 857exit:
756 return err; 858 return err;
@@ -759,9 +861,13 @@ exit:
759static int __devexit f71805f_remove(struct platform_device *pdev) 861static int __devexit f71805f_remove(struct platform_device *pdev)
760{ 862{
761 struct f71805f_data *data = platform_get_drvdata(pdev); 863 struct f71805f_data *data = platform_get_drvdata(pdev);
864 int i;
762 865
763 platform_set_drvdata(pdev, NULL); 866 platform_set_drvdata(pdev, NULL);
764 hwmon_device_unregister(data->class_dev); 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]);
765 kfree(data); 871 kfree(data);
766 872
767 return 0; 873 return 0;