aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm87.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lm87.c')
-rw-r--r--drivers/hwmon/lm87.c83
1 files changed, 69 insertions, 14 deletions
diff --git a/drivers/hwmon/lm87.c b/drivers/hwmon/lm87.c
index 988ae1c4aad..28cdff0c556 100644
--- a/drivers/hwmon/lm87.c
+++ b/drivers/hwmon/lm87.c
@@ -58,6 +58,7 @@
58#include <linux/jiffies.h> 58#include <linux/jiffies.h>
59#include <linux/i2c.h> 59#include <linux/i2c.h>
60#include <linux/hwmon.h> 60#include <linux/hwmon.h>
61#include <linux/hwmon-sysfs.h>
61#include <linux/hwmon-vid.h> 62#include <linux/hwmon-vid.h>
62#include <linux/err.h> 63#include <linux/err.h>
63#include <linux/mutex.h> 64#include <linux/mutex.h>
@@ -129,7 +130,7 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C };
129 (((val) < 0 ? (val)-500 : (val)+500) / 1000)) 130 (((val) < 0 ? (val)-500 : (val)+500) / 1000))
130 131
131#define FAN_FROM_REG(reg,div) ((reg) == 255 || (reg) == 0 ? 0 : \ 132#define FAN_FROM_REG(reg,div) ((reg) == 255 || (reg) == 0 ? 0 : \
132 1350000 + (reg)*(div) / 2) / ((reg)*(div)) 133 (1350000 + (reg)*(div) / 2) / ((reg)*(div)))
133#define FAN_TO_REG(val,div) ((val)*(div) * 255 <= 1350000 ? 255 : \ 134#define FAN_TO_REG(val,div) ((val)*(div) * 255 <= 1350000 ? 255 : \
134 (1350000 + (val)*(div) / 2) / ((val)*(div))) 135 (1350000 + (val)*(div) / 2) / ((val)*(div)))
135 136
@@ -145,7 +146,7 @@ static u8 LM87_REG_TEMP_LOW[3] = { 0x3A, 0x38, 0x2C };
145#define CHAN_NO_FAN(nr) (1 << (nr)) 146#define CHAN_NO_FAN(nr) (1 << (nr))
146#define CHAN_TEMP3 (1 << 2) 147#define CHAN_TEMP3 (1 << 2)
147#define CHAN_VCC_5V (1 << 3) 148#define CHAN_VCC_5V (1 << 3)
148#define CHAN_NO_VID (1 << 8) 149#define CHAN_NO_VID (1 << 7)
149 150
150/* 151/*
151 * Functions declaration 152 * Functions declaration
@@ -176,7 +177,7 @@ static struct i2c_driver lm87_driver = {
176 177
177struct lm87_data { 178struct lm87_data {
178 struct i2c_client client; 179 struct i2c_client client;
179 struct class_device *class_dev; 180 struct device *hwmon_dev;
180 struct mutex update_lock; 181 struct mutex update_lock;
181 char valid; /* zero until following fields are valid */ 182 char valid; /* zero until following fields are valid */
182 unsigned long last_updated; /* In jiffies */ 183 unsigned long last_updated; /* In jiffies */
@@ -500,7 +501,7 @@ static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
500 501
501static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf) 502static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
502{ 503{
503 struct lm87_data *data = lm87_update_device(dev); 504 struct lm87_data *data = dev_get_drvdata(dev);
504 return sprintf(buf, "%d\n", data->vrm); 505 return sprintf(buf, "%d\n", data->vrm);
505} 506}
506static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 507static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
@@ -531,6 +532,29 @@ static ssize_t set_aout(struct device *dev, struct device_attribute *attr, const
531} 532}
532static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout); 533static DEVICE_ATTR(aout_output, S_IRUGO | S_IWUSR, show_aout, set_aout);
533 534
535static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
536 char *buf)
537{
538 struct lm87_data *data = lm87_update_device(dev);
539 int bitnr = to_sensor_dev_attr(attr)->index;
540 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
541}
542static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
543static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
544static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2);
545static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
546static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
547static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9);
548static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 6);
549static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 7);
550static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
551static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5);
552static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 5);
553static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
554static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
555static SENSOR_DEVICE_ATTR(temp2_fault, S_IRUGO, show_alarm, NULL, 14);
556static SENSOR_DEVICE_ATTR(temp3_fault, S_IRUGO, show_alarm, NULL, 15);
557
534/* 558/*
535 * Real code 559 * Real code
536 */ 560 */
@@ -546,24 +570,31 @@ static struct attribute *lm87_attributes[] = {
546 &dev_attr_in1_input.attr, 570 &dev_attr_in1_input.attr,
547 &dev_attr_in1_min.attr, 571 &dev_attr_in1_min.attr,
548 &dev_attr_in1_max.attr, 572 &dev_attr_in1_max.attr,
573 &sensor_dev_attr_in1_alarm.dev_attr.attr,
549 &dev_attr_in2_input.attr, 574 &dev_attr_in2_input.attr,
550 &dev_attr_in2_min.attr, 575 &dev_attr_in2_min.attr,
551 &dev_attr_in2_max.attr, 576 &dev_attr_in2_max.attr,
577 &sensor_dev_attr_in2_alarm.dev_attr.attr,
552 &dev_attr_in3_input.attr, 578 &dev_attr_in3_input.attr,
553 &dev_attr_in3_min.attr, 579 &dev_attr_in3_min.attr,
554 &dev_attr_in3_max.attr, 580 &dev_attr_in3_max.attr,
581 &sensor_dev_attr_in3_alarm.dev_attr.attr,
555 &dev_attr_in4_input.attr, 582 &dev_attr_in4_input.attr,
556 &dev_attr_in4_min.attr, 583 &dev_attr_in4_min.attr,
557 &dev_attr_in4_max.attr, 584 &dev_attr_in4_max.attr,
585 &sensor_dev_attr_in4_alarm.dev_attr.attr,
558 586
559 &dev_attr_temp1_input.attr, 587 &dev_attr_temp1_input.attr,
560 &dev_attr_temp1_max.attr, 588 &dev_attr_temp1_max.attr,
561 &dev_attr_temp1_min.attr, 589 &dev_attr_temp1_min.attr,
562 &dev_attr_temp1_crit.attr, 590 &dev_attr_temp1_crit.attr,
591 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
563 &dev_attr_temp2_input.attr, 592 &dev_attr_temp2_input.attr,
564 &dev_attr_temp2_max.attr, 593 &dev_attr_temp2_max.attr,
565 &dev_attr_temp2_min.attr, 594 &dev_attr_temp2_min.attr,
566 &dev_attr_temp2_crit.attr, 595 &dev_attr_temp2_crit.attr,
596 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
597 &sensor_dev_attr_temp2_fault.dev_attr.attr,
567 598
568 &dev_attr_alarms.attr, 599 &dev_attr_alarms.attr,
569 &dev_attr_aout_output.attr, 600 &dev_attr_aout_output.attr,
@@ -579,30 +610,38 @@ static struct attribute *lm87_attributes_opt[] = {
579 &dev_attr_in6_input.attr, 610 &dev_attr_in6_input.attr,
580 &dev_attr_in6_min.attr, 611 &dev_attr_in6_min.attr,
581 &dev_attr_in6_max.attr, 612 &dev_attr_in6_max.attr,
613 &sensor_dev_attr_in6_alarm.dev_attr.attr,
582 614
583 &dev_attr_fan1_input.attr, 615 &dev_attr_fan1_input.attr,
584 &dev_attr_fan1_min.attr, 616 &dev_attr_fan1_min.attr,
585 &dev_attr_fan1_div.attr, 617 &dev_attr_fan1_div.attr,
618 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
586 619
587 &dev_attr_in7_input.attr, 620 &dev_attr_in7_input.attr,
588 &dev_attr_in7_min.attr, 621 &dev_attr_in7_min.attr,
589 &dev_attr_in7_max.attr, 622 &dev_attr_in7_max.attr,
623 &sensor_dev_attr_in7_alarm.dev_attr.attr,
590 624
591 &dev_attr_fan2_input.attr, 625 &dev_attr_fan2_input.attr,
592 &dev_attr_fan2_min.attr, 626 &dev_attr_fan2_min.attr,
593 &dev_attr_fan2_div.attr, 627 &dev_attr_fan2_div.attr,
628 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
594 629
595 &dev_attr_temp3_input.attr, 630 &dev_attr_temp3_input.attr,
596 &dev_attr_temp3_max.attr, 631 &dev_attr_temp3_max.attr,
597 &dev_attr_temp3_min.attr, 632 &dev_attr_temp3_min.attr,
598 &dev_attr_temp3_crit.attr, 633 &dev_attr_temp3_crit.attr,
634 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
635 &sensor_dev_attr_temp3_fault.dev_attr.attr,
599 636
600 &dev_attr_in0_input.attr, 637 &dev_attr_in0_input.attr,
601 &dev_attr_in0_min.attr, 638 &dev_attr_in0_min.attr,
602 &dev_attr_in0_max.attr, 639 &dev_attr_in0_max.attr,
640 &sensor_dev_attr_in0_alarm.dev_attr.attr,
603 &dev_attr_in5_input.attr, 641 &dev_attr_in5_input.attr,
604 &dev_attr_in5_min.attr, 642 &dev_attr_in5_min.attr,
605 &dev_attr_in5_max.attr, 643 &dev_attr_in5_max.attr,
644 &sensor_dev_attr_in5_alarm.dev_attr.attr,
606 645
607 &dev_attr_cpu0_vid.attr, 646 &dev_attr_cpu0_vid.attr,
608 &dev_attr_vrm.attr, 647 &dev_attr_vrm.attr,
@@ -690,7 +729,9 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
690 || (err = device_create_file(&new_client->dev, 729 || (err = device_create_file(&new_client->dev,
691 &dev_attr_in6_min)) 730 &dev_attr_in6_min))
692 || (err = device_create_file(&new_client->dev, 731 || (err = device_create_file(&new_client->dev,
693 &dev_attr_in6_max))) 732 &dev_attr_in6_max))
733 || (err = device_create_file(&new_client->dev,
734 &sensor_dev_attr_in6_alarm.dev_attr)))
694 goto exit_remove; 735 goto exit_remove;
695 } else { 736 } else {
696 if ((err = device_create_file(&new_client->dev, 737 if ((err = device_create_file(&new_client->dev,
@@ -698,7 +739,9 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
698 || (err = device_create_file(&new_client->dev, 739 || (err = device_create_file(&new_client->dev,
699 &dev_attr_fan1_min)) 740 &dev_attr_fan1_min))
700 || (err = device_create_file(&new_client->dev, 741 || (err = device_create_file(&new_client->dev,
701 &dev_attr_fan1_div))) 742 &dev_attr_fan1_div))
743 || (err = device_create_file(&new_client->dev,
744 &sensor_dev_attr_fan1_alarm.dev_attr)))
702 goto exit_remove; 745 goto exit_remove;
703 } 746 }
704 747
@@ -708,7 +751,9 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
708 || (err = device_create_file(&new_client->dev, 751 || (err = device_create_file(&new_client->dev,
709 &dev_attr_in7_min)) 752 &dev_attr_in7_min))
710 || (err = device_create_file(&new_client->dev, 753 || (err = device_create_file(&new_client->dev,
711 &dev_attr_in7_max))) 754 &dev_attr_in7_max))
755 || (err = device_create_file(&new_client->dev,
756 &sensor_dev_attr_in7_alarm.dev_attr)))
712 goto exit_remove; 757 goto exit_remove;
713 } else { 758 } else {
714 if ((err = device_create_file(&new_client->dev, 759 if ((err = device_create_file(&new_client->dev,
@@ -716,7 +761,9 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
716 || (err = device_create_file(&new_client->dev, 761 || (err = device_create_file(&new_client->dev,
717 &dev_attr_fan2_min)) 762 &dev_attr_fan2_min))
718 || (err = device_create_file(&new_client->dev, 763 || (err = device_create_file(&new_client->dev,
719 &dev_attr_fan2_div))) 764 &dev_attr_fan2_div))
765 || (err = device_create_file(&new_client->dev,
766 &sensor_dev_attr_fan2_alarm.dev_attr)))
720 goto exit_remove; 767 goto exit_remove;
721 } 768 }
722 769
@@ -728,7 +775,11 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
728 || (err = device_create_file(&new_client->dev, 775 || (err = device_create_file(&new_client->dev,
729 &dev_attr_temp3_min)) 776 &dev_attr_temp3_min))
730 || (err = device_create_file(&new_client->dev, 777 || (err = device_create_file(&new_client->dev,
731 &dev_attr_temp3_crit))) 778 &dev_attr_temp3_crit))
779 || (err = device_create_file(&new_client->dev,
780 &sensor_dev_attr_temp3_alarm.dev_attr))
781 || (err = device_create_file(&new_client->dev,
782 &sensor_dev_attr_temp3_fault.dev_attr)))
732 goto exit_remove; 783 goto exit_remove;
733 } else { 784 } else {
734 if ((err = device_create_file(&new_client->dev, 785 if ((err = device_create_file(&new_client->dev,
@@ -738,11 +789,15 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
738 || (err = device_create_file(&new_client->dev, 789 || (err = device_create_file(&new_client->dev,
739 &dev_attr_in0_max)) 790 &dev_attr_in0_max))
740 || (err = device_create_file(&new_client->dev, 791 || (err = device_create_file(&new_client->dev,
792 &sensor_dev_attr_in0_alarm.dev_attr))
793 || (err = device_create_file(&new_client->dev,
741 &dev_attr_in5_input)) 794 &dev_attr_in5_input))
742 || (err = device_create_file(&new_client->dev, 795 || (err = device_create_file(&new_client->dev,
743 &dev_attr_in5_min)) 796 &dev_attr_in5_min))
744 || (err = device_create_file(&new_client->dev, 797 || (err = device_create_file(&new_client->dev,
745 &dev_attr_in5_max))) 798 &dev_attr_in5_max))
799 || (err = device_create_file(&new_client->dev,
800 &sensor_dev_attr_in5_alarm.dev_attr)))
746 goto exit_remove; 801 goto exit_remove;
747 } 802 }
748 803
@@ -755,9 +810,9 @@ static int lm87_detect(struct i2c_adapter *adapter, int address, int kind)
755 goto exit_remove; 810 goto exit_remove;
756 } 811 }
757 812
758 data->class_dev = hwmon_device_register(&new_client->dev); 813 data->hwmon_dev = hwmon_device_register(&new_client->dev);
759 if (IS_ERR(data->class_dev)) { 814 if (IS_ERR(data->hwmon_dev)) {
760 err = PTR_ERR(data->class_dev); 815 err = PTR_ERR(data->hwmon_dev);
761 goto exit_remove; 816 goto exit_remove;
762 } 817 }
763 818
@@ -816,7 +871,7 @@ static int lm87_detach_client(struct i2c_client *client)
816 struct lm87_data *data = i2c_get_clientdata(client); 871 struct lm87_data *data = i2c_get_clientdata(client);
817 int err; 872 int err;
818 873
819 hwmon_device_unregister(data->class_dev); 874 hwmon_device_unregister(data->hwmon_dev);
820 sysfs_remove_group(&client->dev.kobj, &lm87_group); 875 sysfs_remove_group(&client->dev.kobj, &lm87_group);
821 sysfs_remove_group(&client->dev.kobj, &lm87_group_opt); 876 sysfs_remove_group(&client->dev.kobj, &lm87_group_opt);
822 877