aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2015-03-26 23:01:24 -0400
committerGuenter Roeck <linux@roeck-us.net>2015-04-05 09:00:42 -0400
commitf56c9c0aa66034b0de4f6fdeb0d41d38cdbb6dc1 (patch)
tree4a798aa16bc89938aa684edab0f9b8b6372c95b4
parent1696d1deb05710f246f62e810034fb5d8d7713bd (diff)
hwmon: (it87) Fix PWM frequency display for chips with newer PWM control
On chips with newer PWM control, the PWM frequency divider is 256 instead of 128. Since the base PWM frequency remained the same, the actual PWM frequency is half of what it used to be with the older PWM control mechanism. Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/it87.c34
1 files changed, 25 insertions, 9 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c
index 81a43db371f7..5f6c3ad4f3dd 100644
--- a/drivers/hwmon/it87.c
+++ b/drivers/hwmon/it87.c
@@ -502,15 +502,25 @@ static int DIV_TO_REG(int val)
502} 502}
503#define DIV_FROM_REG(val) (1 << (val)) 503#define DIV_FROM_REG(val) (1 << (val))
504 504
505/*
506 * PWM base frequencies. The frequency has to be divided by either 128 or 256,
507 * depending on the chip type, to calculate the actual PWM frequency.
508 *
509 * Some of the chip datasheets suggest a base frequency of 51 kHz instead
510 * of 750 kHz for the slowest base frequency, resulting in a PWM frequency
511 * of 200 Hz. Sometimes both PWM frequency select registers are affected,
512 * sometimes just one. It is unknown if this is a datasheet error or real,
513 * so this is ignored for now.
514 */
505static const unsigned int pwm_freq[8] = { 515static const unsigned int pwm_freq[8] = {
506 48000000 / 128, 516 48000000,
507 24000000 / 128, 517 24000000,
508 12000000 / 128, 518 12000000,
509 8000000 / 128, 519 8000000,
510 6000000 / 128, 520 6000000,
511 3000000 / 128, 521 3000000,
512 1500000 / 128, 522 1500000,
513 750000 / 128, 523 750000,
514}; 524};
515 525
516static int it87_probe(struct platform_device *pdev); 526static int it87_probe(struct platform_device *pdev);
@@ -828,8 +838,11 @@ static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
828{ 838{
829 struct it87_data *data = it87_update_device(dev); 839 struct it87_data *data = it87_update_device(dev);
830 int index = (data->fan_ctl >> 4) & 0x07; 840 int index = (data->fan_ctl >> 4) & 0x07;
841 unsigned int freq;
831 842
832 return sprintf(buf, "%u\n", pwm_freq[index]); 843 freq = pwm_freq[index] / (has_newer_autopwm(data) ? 256 : 128);
844
845 return sprintf(buf, "%u\n", freq);
833} 846}
834 847
835static ssize_t set_fan(struct device *dev, struct device_attribute *attr, 848static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
@@ -1051,6 +1064,9 @@ static ssize_t set_pwm_freq(struct device *dev,
1051 if (kstrtoul(buf, 10, &val) < 0) 1064 if (kstrtoul(buf, 10, &val) < 0)
1052 return -EINVAL; 1065 return -EINVAL;
1053 1066
1067 val = clamp_val(val, 0, 1000000);
1068 val *= has_newer_autopwm(data) ? 256 : 128;
1069
1054 /* Search for the nearest available frequency */ 1070 /* Search for the nearest available frequency */
1055 for (i = 0; i < 7; i++) { 1071 for (i = 0; i < 7; i++) {
1056 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2) 1072 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)