diff options
author | Constantine Shulyupin <const@MakeLinux.com> | 2015-07-07 17:40:10 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2015-08-09 16:44:26 -0400 |
commit | 5102f022688ccd59b1fe4efc8a46ec3aca02dfc5 (patch) | |
tree | e9e4c217bbdb746119877625e656c2965e9366e9 | |
parent | 3e40b8602aa5309e0b117701c36971367af40682 (diff) |
hwmon: (nct7802) Add pwmX_enable attribute
Introduced REG_SMARTFAN_EN, SMARTFAN_EN_SHIFT, pwmX_enable,
show_pwm_enable, store_pwm_enable.
Signed-off-by: Constantine Shulyupin <const@MakeLinux.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r-- | drivers/hwmon/nct7802.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/drivers/hwmon/nct7802.c b/drivers/hwmon/nct7802.c index 1c80aa48ee04..f4908bb228b8 100644 --- a/drivers/hwmon/nct7802.c +++ b/drivers/hwmon/nct7802.c | |||
@@ -53,6 +53,8 @@ static const u8 REG_VOLTAGE_LIMIT_MSB_SHIFT[2][5] = { | |||
53 | #define REG_PECI_ENABLE 0x23 | 53 | #define REG_PECI_ENABLE 0x23 |
54 | #define REG_FAN_ENABLE 0x24 | 54 | #define REG_FAN_ENABLE 0x24 |
55 | #define REG_VMON_ENABLE 0x25 | 55 | #define REG_VMON_ENABLE 0x25 |
56 | #define REG_SMARTFAN_EN(x) (0x64 + (x) / 2) | ||
57 | #define SMARTFAN_EN_SHIFT(x) ((x) % 2 * 4) | ||
56 | #define REG_VENDOR_ID 0xfd | 58 | #define REG_VENDOR_ID 0xfd |
57 | #define REG_CHIP_ID 0xfe | 59 | #define REG_CHIP_ID 0xfe |
58 | #define REG_VERSION_ID 0xff | 60 | #define REG_VERSION_ID 0xff |
@@ -151,6 +153,41 @@ static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr, | |||
151 | return err ? : count; | 153 | return err ? : count; |
152 | } | 154 | } |
153 | 155 | ||
156 | static ssize_t show_pwm_enable(struct device *dev, | ||
157 | struct device_attribute *attr, char *buf) | ||
158 | { | ||
159 | struct nct7802_data *data = dev_get_drvdata(dev); | ||
160 | struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); | ||
161 | unsigned int reg, enabled; | ||
162 | int ret; | ||
163 | |||
164 | ret = regmap_read(data->regmap, REG_SMARTFAN_EN(sattr->index), ®); | ||
165 | if (ret < 0) | ||
166 | return ret; | ||
167 | enabled = reg >> SMARTFAN_EN_SHIFT(sattr->index) & 1; | ||
168 | return sprintf(buf, "%u\n", enabled + 1); | ||
169 | } | ||
170 | |||
171 | static ssize_t store_pwm_enable(struct device *dev, | ||
172 | struct device_attribute *attr, | ||
173 | const char *buf, size_t count) | ||
174 | { | ||
175 | struct nct7802_data *data = dev_get_drvdata(dev); | ||
176 | struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); | ||
177 | u8 val; | ||
178 | int ret; | ||
179 | |||
180 | ret = kstrtou8(buf, 0, &val); | ||
181 | if (ret < 0) | ||
182 | return ret; | ||
183 | if (val < 1 || val > 2) | ||
184 | return -EINVAL; | ||
185 | ret = regmap_update_bits(data->regmap, REG_SMARTFAN_EN(sattr->index), | ||
186 | 1 << SMARTFAN_EN_SHIFT(sattr->index), | ||
187 | (val - 1) << SMARTFAN_EN_SHIFT(sattr->index)); | ||
188 | return ret ? : count; | ||
189 | } | ||
190 | |||
154 | static int nct7802_read_temp(struct nct7802_data *data, | 191 | static int nct7802_read_temp(struct nct7802_data *data, |
155 | u8 reg_temp, u8 reg_temp_low, int *temp) | 192 | u8 reg_temp, u8 reg_temp_low, int *temp) |
156 | { | 193 | { |
@@ -793,6 +830,14 @@ static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60); | |||
793 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61); | 830 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61); |
794 | static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62); | 831 | static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x62); |
795 | 832 | ||
833 | /* 7.2.95... Temperature to Fan mapping Relationships Register */ | ||
834 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, show_pwm_enable, | ||
835 | store_pwm_enable, 0); | ||
836 | static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, show_pwm_enable, | ||
837 | store_pwm_enable, 1); | ||
838 | static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, show_pwm_enable, | ||
839 | store_pwm_enable, 2); | ||
840 | |||
796 | static struct attribute *nct7802_fan_attrs[] = { | 841 | static struct attribute *nct7802_fan_attrs[] = { |
797 | &sensor_dev_attr_fan1_input.dev_attr.attr, | 842 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
798 | &sensor_dev_attr_fan1_min.dev_attr.attr, | 843 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
@@ -832,10 +877,13 @@ static struct attribute_group nct7802_fan_group = { | |||
832 | }; | 877 | }; |
833 | 878 | ||
834 | static struct attribute *nct7802_pwm_attrs[] = { | 879 | static struct attribute *nct7802_pwm_attrs[] = { |
880 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, | ||
835 | &sensor_dev_attr_pwm1_mode.dev_attr.attr, | 881 | &sensor_dev_attr_pwm1_mode.dev_attr.attr, |
836 | &sensor_dev_attr_pwm1.dev_attr.attr, | 882 | &sensor_dev_attr_pwm1.dev_attr.attr, |
883 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, | ||
837 | &sensor_dev_attr_pwm2_mode.dev_attr.attr, | 884 | &sensor_dev_attr_pwm2_mode.dev_attr.attr, |
838 | &sensor_dev_attr_pwm2.dev_attr.attr, | 885 | &sensor_dev_attr_pwm2.dev_attr.attr, |
886 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, | ||
839 | &sensor_dev_attr_pwm3_mode.dev_attr.attr, | 887 | &sensor_dev_attr_pwm3_mode.dev_attr.attr, |
840 | &sensor_dev_attr_pwm3.dev_attr.attr, | 888 | &sensor_dev_attr_pwm3.dev_attr.attr, |
841 | NULL | 889 | NULL |