aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2006-12-12 12:18:27 -0500
committerJean Delvare <khali@arrakis.delvare>2006-12-12 12:18:27 -0500
commite196783d54a75bea05580ce692126532ac54ee24 (patch)
tree10a587a83e1429dee1eb7007904696e080084653 /drivers
parent6e2bc17b0793297b38aef1bba39f2cb634d66208 (diff)
hwmon/f71805f: Support DC fan speed control mode
In DC mode, the pwmN_freq files are not created. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/hwmon/f71805f.c46
1 files changed, 43 insertions, 3 deletions
diff --git a/drivers/hwmon/f71805f.c b/drivers/hwmon/f71805f.c
index 173e2d2cb49c..29a3984af738 100644
--- a/drivers/hwmon/f71805f.c
+++ b/drivers/hwmon/f71805f.c
@@ -126,6 +126,7 @@ superio_exit(int base)
126 126
127/* individual register bits */ 127/* individual register bits */
128#define FAN_CTRL_SKIP 0x80 128#define FAN_CTRL_SKIP 0x80
129#define FAN_CTRL_DC_MODE 0x10
129#define FAN_CTRL_MODE_MASK 0x03 130#define FAN_CTRL_MODE_MASK 0x03
130#define FAN_CTRL_MODE_SPEED 0x00 131#define FAN_CTRL_MODE_SPEED 0x00
131#define FAN_CTRL_MODE_TEMPERATURE 0x01 132#define FAN_CTRL_MODE_TEMPERATURE 0x01
@@ -233,6 +234,11 @@ static inline u8 pwm_freq_to_reg(unsigned long val)
233 return 1000000UL / (val << 8); 234 return 1000000UL / (val << 8);
234} 235}
235 236
237static inline int pwm_mode_from_reg(u8 reg)
238{
239 return !(reg & FAN_CTRL_DC_MODE);
240}
241
236static inline long temp_from_reg(u8 reg) 242static inline long temp_from_reg(u8 reg)
237{ 243{
238 return (reg * 1000); 244 return (reg * 1000);
@@ -562,6 +568,16 @@ static ssize_t show_pwm_freq(struct device *dev, struct device_attribute
562 return sprintf(buf, "%lu\n", pwm_freq_from_reg(data->pwm_freq[nr])); 568 return sprintf(buf, "%lu\n", pwm_freq_from_reg(data->pwm_freq[nr]));
563} 569}
564 570
571static ssize_t show_pwm_mode(struct device *dev, struct device_attribute
572 *devattr, char *buf)
573{
574 struct f71805f_data *data = f71805f_update_device(dev);
575 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
576 int nr = attr->index;
577
578 return sprintf(buf, "%d\n", pwm_mode_from_reg(data->fan_ctrl[nr]));
579}
580
565static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, 581static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr,
566 const char *buf, size_t count) 582 const char *buf, size_t count)
567{ 583{
@@ -839,16 +855,19 @@ static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
839 show_pwm_enable, set_pwm_enable, 0); 855 show_pwm_enable, set_pwm_enable, 0);
840static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, 856static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR,
841 show_pwm_freq, set_pwm_freq, 0); 857 show_pwm_freq, set_pwm_freq, 0);
858static SENSOR_DEVICE_ATTR(pwm1_mode, S_IRUGO, show_pwm_mode, NULL, 0);
842static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO, show_pwm, set_pwm, 1); 859static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO, show_pwm, set_pwm, 1);
843static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, 860static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
844 show_pwm_enable, set_pwm_enable, 1); 861 show_pwm_enable, set_pwm_enable, 1);
845static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO | S_IWUSR, 862static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO | S_IWUSR,
846 show_pwm_freq, set_pwm_freq, 1); 863 show_pwm_freq, set_pwm_freq, 1);
864static SENSOR_DEVICE_ATTR(pwm2_mode, S_IRUGO, show_pwm_mode, NULL, 1);
847static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO, show_pwm, set_pwm, 2); 865static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO, show_pwm, set_pwm, 2);
848static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, 866static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
849 show_pwm_enable, set_pwm_enable, 2); 867 show_pwm_enable, set_pwm_enable, 2);
850static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO | S_IWUSR, 868static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO | S_IWUSR,
851 show_pwm_freq, set_pwm_freq, 2); 869 show_pwm_freq, set_pwm_freq, 2);
870static SENSOR_DEVICE_ATTR(pwm3_mode, S_IRUGO, show_pwm_mode, NULL, 2);
852 871
853static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); 872static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0);
854static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); 873static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1);
@@ -944,7 +963,7 @@ static struct attribute *f71805f_attributes_fan[3][7] = {
944 &sensor_dev_attr_fan1_alarm.dev_attr.attr, 963 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
945 &sensor_dev_attr_pwm1.dev_attr.attr, 964 &sensor_dev_attr_pwm1.dev_attr.attr,
946 &sensor_dev_attr_pwm1_enable.dev_attr.attr, 965 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
947 &sensor_dev_attr_pwm1_freq.dev_attr.attr, 966 &sensor_dev_attr_pwm1_mode.dev_attr.attr,
948 NULL 967 NULL
949 }, { 968 }, {
950 &sensor_dev_attr_fan2_input.dev_attr.attr, 969 &sensor_dev_attr_fan2_input.dev_attr.attr,
@@ -952,7 +971,7 @@ static struct attribute *f71805f_attributes_fan[3][7] = {
952 &sensor_dev_attr_fan2_alarm.dev_attr.attr, 971 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
953 &sensor_dev_attr_pwm2.dev_attr.attr, 972 &sensor_dev_attr_pwm2.dev_attr.attr,
954 &sensor_dev_attr_pwm2_enable.dev_attr.attr, 973 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
955 &sensor_dev_attr_pwm2_freq.dev_attr.attr, 974 &sensor_dev_attr_pwm2_mode.dev_attr.attr,
956 NULL 975 NULL
957 }, { 976 }, {
958 &sensor_dev_attr_fan3_input.dev_attr.attr, 977 &sensor_dev_attr_fan3_input.dev_attr.attr,
@@ -960,7 +979,7 @@ static struct attribute *f71805f_attributes_fan[3][7] = {
960 &sensor_dev_attr_fan3_alarm.dev_attr.attr, 979 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
961 &sensor_dev_attr_pwm3.dev_attr.attr, 980 &sensor_dev_attr_pwm3.dev_attr.attr,
962 &sensor_dev_attr_pwm3_enable.dev_attr.attr, 981 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
963 &sensor_dev_attr_pwm3_freq.dev_attr.attr, 982 &sensor_dev_attr_pwm3_mode.dev_attr.attr,
964 NULL 983 NULL
965 } 984 }
966}; 985};
@@ -971,6 +990,19 @@ static const struct attribute_group f71805f_group_fan[3] = {
971 { .attrs = f71805f_attributes_fan[2] }, 990 { .attrs = f71805f_attributes_fan[2] },
972}; 991};
973 992
993/* We don't include pwm_freq files in the arrays above, because they must be
994 created conditionally (only if pwm_mode is 1 == PWM) */
995static struct attribute *f71805f_attributes_pwm_freq[] = {
996 &sensor_dev_attr_pwm1_freq.dev_attr.attr,
997 &sensor_dev_attr_pwm2_freq.dev_attr.attr,
998 &sensor_dev_attr_pwm3_freq.dev_attr.attr,
999 NULL
1000};
1001
1002static const struct attribute_group f71805f_group_pwm_freq = {
1003 .attrs = f71805f_attributes_pwm_freq,
1004};
1005
974/* We also need an indexed access to pwmN files to toggle writability */ 1006/* We also need an indexed access to pwmN files to toggle writability */
975static struct attribute *f71805f_attr_pwm[] = { 1007static struct attribute *f71805f_attr_pwm[] = {
976 &sensor_dev_attr_pwm1.dev_attr.attr, 1008 &sensor_dev_attr_pwm1.dev_attr.attr,
@@ -1034,6 +1066,12 @@ static int __devinit f71805f_probe(struct platform_device *pdev)
1034 if ((err = sysfs_create_group(&pdev->dev.kobj, 1066 if ((err = sysfs_create_group(&pdev->dev.kobj,
1035 &f71805f_group_fan[i]))) 1067 &f71805f_group_fan[i])))
1036 goto exit_remove_files; 1068 goto exit_remove_files;
1069 /* If control mode is PWM, create pwm_freq file */
1070 if (!(data->fan_ctrl[i] & FAN_CTRL_DC_MODE)) {
1071 if ((err = sysfs_create_file(&pdev->dev.kobj,
1072 f71805f_attributes_pwm_freq[i])))
1073 goto exit_remove_files;
1074 }
1037 /* If PWM is in manual mode, add write permission */ 1075 /* If PWM is in manual mode, add write permission */
1038 if (data->fan_ctrl[i] & FAN_CTRL_MODE_MANUAL) { 1076 if (data->fan_ctrl[i] & FAN_CTRL_MODE_MANUAL) {
1039 if ((err = sysfs_chmod_file(&pdev->dev.kobj, 1077 if ((err = sysfs_chmod_file(&pdev->dev.kobj,
@@ -1059,6 +1097,7 @@ exit_remove_files:
1059 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group); 1097 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group);
1060 for (i = 0; i < 3; i++) 1098 for (i = 0; i < 3; i++)
1061 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]); 1099 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]);
1100 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq);
1062exit_free: 1101exit_free:
1063 platform_set_drvdata(pdev, NULL); 1102 platform_set_drvdata(pdev, NULL);
1064 kfree(data); 1103 kfree(data);
@@ -1076,6 +1115,7 @@ static int __devexit f71805f_remove(struct platform_device *pdev)
1076 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group); 1115 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group);
1077 for (i = 0; i < 3; i++) 1116 for (i = 0; i < 3; i++)
1078 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]); 1117 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_fan[i]);
1118 sysfs_remove_group(&pdev->dev.kobj, &f71805f_group_pwm_freq);
1079 kfree(data); 1119 kfree(data);
1080 1120
1081 return 0; 1121 return 0;