diff options
author | Constantine Shulyupin <const@MakeLinux.com> | 2015-07-04 14:49:51 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2015-08-09 16:44:25 -0400 |
commit | ea33597c6f9862d7b926bdb9c3ac25012f307dd5 (patch) | |
tree | 545cc9e7ccf7a46a6a8408f0242a323adfdc544a | |
parent | fcdc5739dce03d8050ebfa7153412c2efcdee94f (diff) |
hwmon: (nct7802) Add pwm control
Added fan output control registers.
Modes of operation are PWM (default) and DC.
Introduced show_pwm, store_pwm, nct7802_pwm_attrs, nct7802_pwm_group.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/nct7802.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c index 344cbec79802..457b0f2678a4 100644 --- a/drivers/hwmon/nct7802.c +++ b/drivers/hwmon/nct7802.c | |||
@@ -102,6 +102,36 @@ static ssize_t store_temp_type(struct device *dev, | |||
102 | return err ? : count; | 102 | return err ? : count; |
103 | } | 103 | } |
104 | 104 | ||
105 | static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, | ||
106 | char *buf) | ||
107 | { | ||
108 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
109 | struct nct7802_data *data = dev_get_drvdata(dev); | ||
110 | unsigned int val; | ||
111 | int ret; | ||
112 | |||
113 | ret = regmap_read(data->regmap, attr->index, &val); | ||
114 | if (ret < 0) | ||
115 | return ret; | ||
116 | |||
117 | return sprintf(buf, "%d\n", val); | ||
118 | } | ||
119 | |||
120 | static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr, | ||
121 | const char *buf, size_t count) | ||
122 | { | ||
123 | struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); | ||
124 | struct nct7802_data *data = dev_get_drvdata(dev); | ||
125 | int err; | ||
126 | u8 val; | ||
127 | |||
128 | err = kstrtou8(buf, 0, &val); | ||
129 | if (err < 0) | ||
130 | return err; | ||
131 | |||
132 | err = regmap_write(data->regmap, attr->index, val); | ||
133 | return err ? : count; | ||
134 | } | ||
105 | 135 | ||
106 | static int nct7802_read_temp(struct nct7802_data *data, | 136 | static int nct7802_read_temp(struct nct7802_data *data, |
107 | u8 reg_temp, u8 reg_temp_low, int *temp) | 137 | u8 reg_temp, u8 reg_temp_low, int *temp) |
@@ -735,6 +765,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 2); | |||
735 | static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, store_beep, | 765 | static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, store_beep, |
736 | 0x5b, 2); | 766 | 0x5b, 2); |
737 | 767 | ||
768 | /* 7.2.91... Fan Control Output Value */ | ||
769 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60); | ||
770 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61); | ||
771 | static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62); | ||
772 | |||
738 | static struct attribute *nct7802_fan_attrs[] = { | 773 | static struct attribute *nct7802_fan_attrs[] = { |
739 | &sensor_dev_attr_fan1_input.dev_attr.attr, | 774 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
740 | &sensor_dev_attr_fan1_min.dev_attr.attr, | 775 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
@@ -773,10 +808,22 @@ static struct attribute_group nct7802_fan_group = { | |||
773 | .is_visible = nct7802_fan_is_visible, | 808 | .is_visible = nct7802_fan_is_visible, |
774 | }; | 809 | }; |
775 | 810 | ||
811 | static struct attribute *nct7802_pwm_attrs[] = { | ||
812 | &sensor_dev_attr_pwm1.dev_attr.attr, | ||
813 | &sensor_dev_attr_pwm2.dev_attr.attr, | ||
814 | &sensor_dev_attr_pwm3.dev_attr.attr, | ||
815 | NULL | ||
816 | }; | ||
817 | |||
818 | static struct attribute_group nct7802_pwm_group = { | ||
819 | .attrs = nct7802_pwm_attrs, | ||
820 | }; | ||
821 | |||
776 | static const struct attribute_group *nct7802_groups[] = { | 822 | static const struct attribute_group *nct7802_groups[] = { |
777 | &nct7802_temp_group, | 823 | &nct7802_temp_group, |
778 | &nct7802_in_group, | 824 | &nct7802_in_group, |
779 | &nct7802_fan_group, | 825 | &nct7802_fan_group, |
826 | &nct7802_pwm_group, | ||
780 | NULL | 827 | NULL |
781 | }; | 828 | }; |
782 | 829 | ||