hwmon: (nct7802) Add pwm mode
PATCH 1/1 hwmon: (nct7802) Add pwm mode
Introduced: show_pwm_mode, pwm1_mode, pwm2_mode, pwm2_mode
Signed-off-by Constantine Shulyupin <[email protected]>
--- drivers/hwmon/nct7802.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
drivers/hwmon/nct7802.c +26 -0
@@ -102,6 +102,24 @@ static ssize_t store_temp_type(struct device *dev,return err ? : count; } +static ssize_t show_pwm_mode (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute_2 *sattr =to_sensor_dev_attr_2 (attr); +struct nct7802_data *data =dev_get_drvdata (dev); +unsigned int regval; +int ret; + +if (sattr->index >1 ) +return sprintf (buf,"1\n" ); + + ret =regmap_read (data->regmap, sattr->nr, ®val); +if (ret <0 ) +return ret; + +return sprintf (buf,"%u\n" , !(regval & (1 << sattr->index))); +} +static ssize_t show_pwm (struct device *dev,struct device_attribute *devattr,char *buf) {
@@ -765,6 +783,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 2); static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, store_beep, 0x5b, 2); +/* 7.2.89 Fan Control Output Type */ +static SENSOR_DEVICE_ATTR_2(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0x5E, 0); +static SENSOR_DEVICE_ATTR_2(pwm2_mode, S_IRUGO, show_pwm_mode, NULL, 0x5E, 1); +static SENSOR_DEVICE_ATTR_2(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 0, 2); +/* 7.2.91... Fan Control Output Value */ static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x60); static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, store_pwm, 0x61);
@@ -809,8 +832,11 @@ static struct attribute_group nct7802_fan_group = { };static struct attribute *nct7802_pwm_attrs[] = { + &sensor_dev_attr_pwm1_mode.dev_attr.attr, &sensor_dev_attr_pwm1.dev_attr.attr, + &sensor_dev_attr_pwm2_mode.dev_attr.attr, &sensor_dev_attr_pwm2.dev_attr.attr, + &sensor_dev_attr_pwm3_mode.dev_attr.attr, &sensor_dev_attr_pwm3.dev_attr.attr,NULL };
Signature · 7 lines
1.9.1 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerHi Constantine,
Quoted 36 lines · Constantine Shulyupin
Introduced:
show_pwm_mode,pwm1_mode,pwm2_mode,pwm2_modeSigned-off-by Constantine Shulyupin <[email protected]>--- drivers/hwmon/nct7802.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)drivers/hwmon/nct7802.c +18
-0@@ -102,6 +102,24 @@ static ssize_t store_temp_type(struct device *dev,return err ? : count; } +static ssize_t show_pwm_mode (struct device *dev,struct device_attribute *attr, +char *buf) +{ +struct sensor_device_attribute_2 *sattr =to_sensor_dev_attr_2 (attr); +struct nct7802_data *data =dev_get_drvdata (dev); +unsigned int regval; +int ret; + +if (sattr->index >1 ) +return sprintf (buf,"1\n" ); + + ret =regmap_read (data->regmap, sattr->nr, ®val); +if (ret <0 ) +return ret; + +return sprintf (buf,"%u\n" , !(regval & (1 << sattr->index))); +} +static ssize_t show_pwm (struct device *dev,struct device_attribute *devattr,char *buf) {
drivers/hwmon/nct7802.c static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 2); · line 789
Quoted 7 lines
drivers/hwmon/nct7802.c +4
-0@@ -765,6 +783,11 @@ static SENSOR_DEVICE_ATTR_2(fan3_alarm, S_IRUGO, show_alarm, NULL, 0x1a, 2); static SENSOR_DEVICE_ATTR_2(fan3_beep, S_IRUGO | S_IWUSR, show_beep, store_beep, 0x5b, 2); +/* 7.2.89 Fan Control Output Type */ +static SENSOR_DEVICE_ATTR_2(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0x5E, 0); +static SENSOR_DEVICE_ATTR_2(pwm2_mode, S_IRUGO, show_pwm_mode, NULL, 0x5E, 1); +static SENSOR_DEVICE_ATTR_2(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 0, 2);
You don't really need SENSOR_DEVICE_ATTR_2 here; SENSOR_DEVICE_ATTR is good enough. The register address doesn't change, and isn't used for index = 2 anyway, so you can just hard-code it in show_pwm_mode().
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors