diff options
author | Jean Delvare <khali@linux-fr.org> | 2008-10-17 11:51:13 -0400 |
---|---|---|
committer | Jean Delvare <khali@mahadeva.delvare> | 2008-10-17 11:51:13 -0400 |
commit | 34e7dc6ca4a663a1bb0a0a4e118426849dccd72d (patch) | |
tree | eaf36724303f94d320990799f768bf86cd5b3b6e | |
parent | 69fc1feba2d5856ff74dedb6ae9d8c490210825c (diff) |
hwmon: (lm85) Implement the standard PWM frequency interface
Implement the standard PWM frequency interface: pwm[1-*]_freq in
units of 1 Hz, instead of the non-standard pwm[1-*]_auto_pwm_freq
in units of 0.1 Hz. The old naming was not only non-standard, it was
also confusing, because it suggested that the frequency value only
applied in automatic fan speed mode, which isn't true.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Acked-by: Herbert Poetzl <herbert@13thfloor.at>
-rw-r--r-- | Documentation/hwmon/lm85 | 10 | ||||
-rw-r--r-- | drivers/hwmon/lm85.c | 77 |
2 files changed, 38 insertions, 49 deletions
diff --git a/Documentation/hwmon/lm85 b/Documentation/hwmon/lm85 index 6d41db7f17f8..400620741290 100644 --- a/Documentation/hwmon/lm85 +++ b/Documentation/hwmon/lm85 | |||
@@ -163,16 +163,6 @@ configured individually according to the following options. | |||
163 | * pwm#_auto_pwm_min - this specifies the PWM value for temp#_auto_temp_off | 163 | * pwm#_auto_pwm_min - this specifies the PWM value for temp#_auto_temp_off |
164 | temperature. (PWM value from 0 to 255) | 164 | temperature. (PWM value from 0 to 255) |
165 | 165 | ||
166 | * pwm#_auto_pwm_freq - select base frequency of PWM output. You can select | ||
167 | in range of 10.0 to 94.0 Hz in .1 Hz units. | ||
168 | (Values 100 to 940). | ||
169 | |||
170 | The pwm#_auto_pwm_freq can be set to one of the following 8 values. Setting the | ||
171 | frequency to a value not on this list, will result in the next higher frequency | ||
172 | being selected. The actual device frequency may vary slightly from this | ||
173 | specification as designed by the manufacturer. Consult the datasheet for more | ||
174 | details. (PWM Frequency values: 100, 150, 230, 300, 380, 470, 620, 940) | ||
175 | |||
176 | * pwm#_auto_pwm_minctl - this flags selects for temp#_auto_temp_off temperature | 166 | * pwm#_auto_pwm_minctl - this flags selects for temp#_auto_temp_off temperature |
177 | the bahaviour of fans. Write 1 to let fans spinning at | 167 | the bahaviour of fans. Write 1 to let fans spinning at |
178 | pwm#_auto_pwm_min or write 0 to let them off. | 168 | pwm#_auto_pwm_min or write 0 to let them off. |
diff --git a/drivers/hwmon/lm85.c b/drivers/hwmon/lm85.c index 3594a02f281b..6b676df3547b 100644 --- a/drivers/hwmon/lm85.c +++ b/drivers/hwmon/lm85.c | |||
@@ -191,8 +191,8 @@ static int RANGE_TO_REG(int range) | |||
191 | #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] | 191 | #define RANGE_FROM_REG(val) lm85_range_map[(val) & 0x0f] |
192 | 192 | ||
193 | /* These are the PWM frequency encodings */ | 193 | /* These are the PWM frequency encodings */ |
194 | static const int lm85_freq_map[] = { /* .1 Hz */ | 194 | static const int lm85_freq_map[8] = { /* 1 Hz */ |
195 | 100, 150, 230, 300, 380, 470, 620, 940 | 195 | 10, 15, 23, 30, 38, 47, 62, 94 |
196 | }; | 196 | }; |
197 | 197 | ||
198 | static int FREQ_TO_REG(int freq) | 198 | static int FREQ_TO_REG(int freq) |
@@ -275,7 +275,6 @@ struct lm85_zone { | |||
275 | 275 | ||
276 | struct lm85_autofan { | 276 | struct lm85_autofan { |
277 | u8 config; /* Register value */ | 277 | u8 config; /* Register value */ |
278 | u8 freq; /* PWM frequency, encoded */ | ||
279 | u8 min_pwm; /* Minimum PWM value, encoded */ | 278 | u8 min_pwm; /* Minimum PWM value, encoded */ |
280 | u8 min_off; /* Min PWM or OFF below "limit", flag */ | 279 | u8 min_off; /* Min PWM or OFF below "limit", flag */ |
281 | }; | 280 | }; |
@@ -301,6 +300,7 @@ struct lm85_data { | |||
301 | u16 fan[4]; /* Register value */ | 300 | u16 fan[4]; /* Register value */ |
302 | u16 fan_min[4]; /* Register value */ | 301 | u16 fan_min[4]; /* Register value */ |
303 | u8 pwm[3]; /* Register value */ | 302 | u8 pwm[3]; /* Register value */ |
303 | u8 pwm_freq[3]; /* Register encoding */ | ||
304 | u8 temp_ext[3]; /* Decoded values */ | 304 | u8 temp_ext[3]; /* Decoded values */ |
305 | u8 in_ext[8]; /* Decoded values */ | 305 | u8 in_ext[8]; /* Decoded values */ |
306 | u8 vid; /* Register value */ | 306 | u8 vid; /* Register value */ |
@@ -528,11 +528,38 @@ static ssize_t set_pwm_enable(struct device *dev, struct device_attribute | |||
528 | return count; | 528 | return count; |
529 | } | 529 | } |
530 | 530 | ||
531 | static ssize_t show_pwm_freq(struct device *dev, | ||
532 | struct device_attribute *attr, char *buf) | ||
533 | { | ||
534 | int nr = to_sensor_dev_attr(attr)->index; | ||
535 | struct lm85_data *data = lm85_update_device(dev); | ||
536 | return sprintf(buf, "%d\n", FREQ_FROM_REG(data->pwm_freq[nr])); | ||
537 | } | ||
538 | |||
539 | static ssize_t set_pwm_freq(struct device *dev, | ||
540 | struct device_attribute *attr, const char *buf, size_t count) | ||
541 | { | ||
542 | int nr = to_sensor_dev_attr(attr)->index; | ||
543 | struct i2c_client *client = to_i2c_client(dev); | ||
544 | struct lm85_data *data = i2c_get_clientdata(client); | ||
545 | long val = simple_strtol(buf, NULL, 10); | ||
546 | |||
547 | mutex_lock(&data->update_lock); | ||
548 | data->pwm_freq[nr] = FREQ_TO_REG(val); | ||
549 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | ||
550 | (data->zone[nr].range << 4) | ||
551 | | data->pwm_freq[nr]); | ||
552 | mutex_unlock(&data->update_lock); | ||
553 | return count; | ||
554 | } | ||
555 | |||
531 | #define show_pwm_reg(offset) \ | 556 | #define show_pwm_reg(offset) \ |
532 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ | 557 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ |
533 | show_pwm, set_pwm, offset - 1); \ | 558 | show_pwm, set_pwm, offset - 1); \ |
534 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ | 559 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ |
535 | show_pwm_enable, set_pwm_enable, offset - 1) | 560 | show_pwm_enable, set_pwm_enable, offset - 1); \ |
561 | static SENSOR_DEVICE_ATTR(pwm##offset##_freq, S_IRUGO | S_IWUSR, \ | ||
562 | show_pwm_freq, set_pwm_freq, offset - 1) | ||
536 | 563 | ||
537 | show_pwm_reg(1); | 564 | show_pwm_reg(1); |
538 | show_pwm_reg(2); | 565 | show_pwm_reg(2); |
@@ -761,31 +788,6 @@ static ssize_t set_pwm_auto_pwm_minctl(struct device *dev, | |||
761 | return count; | 788 | return count; |
762 | } | 789 | } |
763 | 790 | ||
764 | static ssize_t show_pwm_auto_pwm_freq(struct device *dev, | ||
765 | struct device_attribute *attr, char *buf) | ||
766 | { | ||
767 | int nr = to_sensor_dev_attr(attr)->index; | ||
768 | struct lm85_data *data = lm85_update_device(dev); | ||
769 | return sprintf(buf, "%d\n", FREQ_FROM_REG(data->autofan[nr].freq)); | ||
770 | } | ||
771 | |||
772 | static ssize_t set_pwm_auto_pwm_freq(struct device *dev, | ||
773 | struct device_attribute *attr, const char *buf, size_t count) | ||
774 | { | ||
775 | int nr = to_sensor_dev_attr(attr)->index; | ||
776 | struct i2c_client *client = to_i2c_client(dev); | ||
777 | struct lm85_data *data = i2c_get_clientdata(client); | ||
778 | long val = simple_strtol(buf, NULL, 10); | ||
779 | |||
780 | mutex_lock(&data->update_lock); | ||
781 | data->autofan[nr].freq = FREQ_TO_REG(val); | ||
782 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | ||
783 | (data->zone[nr].range << 4) | ||
784 | | data->autofan[nr].freq); | ||
785 | mutex_unlock(&data->update_lock); | ||
786 | return count; | ||
787 | } | ||
788 | |||
789 | #define pwm_auto(offset) \ | 791 | #define pwm_auto(offset) \ |
790 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \ | 792 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels, \ |
791 | S_IRUGO | S_IWUSR, show_pwm_auto_channels, \ | 793 | S_IRUGO | S_IWUSR, show_pwm_auto_channels, \ |
@@ -795,10 +797,7 @@ static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_min, \ | |||
795 | set_pwm_auto_pwm_min, offset - 1); \ | 797 | set_pwm_auto_pwm_min, offset - 1); \ |
796 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \ | 798 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_minctl, \ |
797 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \ | 799 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_minctl, \ |
798 | set_pwm_auto_pwm_minctl, offset - 1); \ | 800 | set_pwm_auto_pwm_minctl, offset - 1) |
799 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_pwm_freq, \ | ||
800 | S_IRUGO | S_IWUSR, show_pwm_auto_pwm_freq, \ | ||
801 | set_pwm_auto_pwm_freq, offset - 1); | ||
802 | 801 | ||
803 | pwm_auto(1); | 802 | pwm_auto(1); |
804 | pwm_auto(2); | 803 | pwm_auto(2); |
@@ -867,7 +866,7 @@ static ssize_t set_temp_auto_temp_min(struct device *dev, | |||
867 | TEMP_FROM_REG(data->zone[nr].limit)); | 866 | TEMP_FROM_REG(data->zone[nr].limit)); |
868 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | 867 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
869 | ((data->zone[nr].range & 0x0f) << 4) | 868 | ((data->zone[nr].range & 0x0f) << 4) |
870 | | (data->autofan[nr].freq & 0x07)); | 869 | | (data->pwm_freq[nr] & 0x07)); |
871 | 870 | ||
872 | /* Update temp_auto_hyst and temp_auto_off */ | 871 | /* Update temp_auto_hyst and temp_auto_off */ |
873 | data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG( | 872 | data->zone[nr].hyst = HYST_TO_REG(TEMP_FROM_REG( |
@@ -910,7 +909,7 @@ static ssize_t set_temp_auto_temp_max(struct device *dev, | |||
910 | val - min); | 909 | val - min); |
911 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), | 910 | lm85_write_value(client, LM85_REG_AFAN_RANGE(nr), |
912 | ((data->zone[nr].range & 0x0f) << 4) | 911 | ((data->zone[nr].range & 0x0f) << 4) |
913 | | (data->autofan[nr].freq & 0x07)); | 912 | | (data->pwm_freq[nr] & 0x07)); |
914 | mutex_unlock(&data->update_lock); | 913 | mutex_unlock(&data->update_lock); |
915 | return count; | 914 | return count; |
916 | } | 915 | } |
@@ -984,6 +983,9 @@ static struct attribute *lm85_attributes[] = { | |||
984 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, | 983 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
985 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, | 984 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
986 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, | 985 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
986 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, | ||
987 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, | ||
988 | &sensor_dev_attr_pwm3_freq.dev_attr.attr, | ||
987 | 989 | ||
988 | &sensor_dev_attr_in0_input.dev_attr.attr, | 990 | &sensor_dev_attr_in0_input.dev_attr.attr, |
989 | &sensor_dev_attr_in1_input.dev_attr.attr, | 991 | &sensor_dev_attr_in1_input.dev_attr.attr, |
@@ -1026,9 +1028,6 @@ static struct attribute *lm85_attributes[] = { | |||
1026 | &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr, | 1028 | &sensor_dev_attr_pwm1_auto_pwm_minctl.dev_attr.attr, |
1027 | &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr, | 1029 | &sensor_dev_attr_pwm2_auto_pwm_minctl.dev_attr.attr, |
1028 | &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr, | 1030 | &sensor_dev_attr_pwm3_auto_pwm_minctl.dev_attr.attr, |
1029 | &sensor_dev_attr_pwm1_auto_pwm_freq.dev_attr.attr, | ||
1030 | &sensor_dev_attr_pwm2_auto_pwm_freq.dev_attr.attr, | ||
1031 | &sensor_dev_attr_pwm3_auto_pwm_freq.dev_attr.attr, | ||
1032 | 1031 | ||
1033 | &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr, | 1032 | &sensor_dev_attr_temp1_auto_temp_off.dev_attr.attr, |
1034 | &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr, | 1033 | &sensor_dev_attr_temp2_auto_temp_off.dev_attr.attr, |
@@ -1458,7 +1457,7 @@ static struct lm85_data *lm85_update_device(struct device *dev) | |||
1458 | data->autofan[i].config = | 1457 | data->autofan[i].config = |
1459 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); | 1458 | lm85_read_value(client, LM85_REG_AFAN_CONFIG(i)); |
1460 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); | 1459 | val = lm85_read_value(client, LM85_REG_AFAN_RANGE(i)); |
1461 | data->autofan[i].freq = val & 0x07; | 1460 | data->pwm_freq[i] = val & 0x07; |
1462 | data->zone[i].range = val >> 4; | 1461 | data->zone[i].range = val >> 4; |
1463 | data->autofan[i].min_pwm = | 1462 | data->autofan[i].min_pwm = |
1464 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); | 1463 | lm85_read_value(client, LM85_REG_AFAN_MINPWM(i)); |