Skip to contentSkip to conversation

hwmon: (it87) Fix pwm frequency display for chips with newer pwm control

PATCH In review Guenter Roeck 2 participants 5 messages Mar 30, 2015

Subsystems (2)
lore
Share & tools
lore

Guenter Roeck

author maintainer
#0 lore raw

PATCH 1/15 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.

---
 drivers/hwmon/it87.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)
drivers/hwmon/it87.c +25 -9
index ab12dc2eb896..7ab5bd026e91 100644
@@ -502,15 +502,25 @@ static int DIV_TO_REG(int val)
 }
 #define DIV_FROM_REG(val) (1 << (val))
 
+/*
+ * pwm base frequencies. The frequency has to be divided by either 128 or 256,
+ * depending on the chip type, to calculate the actual pwm frequency.
+ *
+ * Some of the chip datasheets suggest a base frequency of 51kHz instead
+ * of 750kHz for the slowest base frequency, resulting in a pwm frequency
+ * of 200Hz. Sometimes both pwm frequency select registers are affected,
+ * sometimes just one. It is unknown if this is a datasheet error or real,
+ * so this is ignored for now.
+ */
 static const unsigned int pwm_freq[8] = {
-	48000000 / 128,
-	24000000 / 128,
-	12000000 / 128,
-	8000000 / 128,
-	6000000 / 128,
-	3000000 / 128,
-	1500000 / 128,
-	750000 / 128,
+	48000000,
+	24000000,
+	12000000,
+	8000000,
+	6000000,
+	3000000,
+	1500000,
+	750000,
 };
 
 static int it87_probe(struct platform_device *pdev);
@@ -828,8 +838,11 @@ static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
 {
 	struct it87_data *data = it87_update_device(dev);
 	int index = (data->fan_ctl >> 4) & 0x07;
+	unsigned int freq;
 
-	return sprintf(buf, "%u\n", pwm_freq[index]);
+	freq = pwm_freq[index] / has_newer_autopwm(data) ? 256 : 128;
+
+	return sprintf(buf, "%u\n", freq);
 }
 
 static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
@@ -1051,6 +1064,9 @@ static ssize_t set_pwm_freq(struct device *dev,
 	if (kstrtoul(buf, 10, &val) < 0)
 		return -EINVAL;
 
+	val = clamp_val(val, 0, 1000000);
+	val *= has_newer_autopwm(data) ? 256 : 128;
+
 	/* Search for the nearest available frequency */
 	for (i = 0; i < 7; i++) {
 		if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
Signature · 7 lines
2.1.0


_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#1 lore raw

Re: [lm-sensors] [PATCH 01/15] hwmon: (it87) Fix pwm frequency display for chips with newer pwm cont

Hi Guenter,

Quoted 17 lines · Guenter Roeck

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.

---
 drivers/hwmon/it87.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)
drivers/hwmon/it87.c +0 -0
index ab12dc2eb896..7ab5bd026e91 100644
@@ -502,15 +502,25 @@ static int DIV_TO_REG(int val)
 }
 #define DIV_FROM_REG(val) (1 << (val))

drivers/hwmon/it87.c static int DIV_TO_REG(int val) · line 513

Quoted 10 lines
drivers/hwmon/it87.c +9 -0
 
+/*
+ * pwm base frequencies. The frequency has to be divided by either 128 or 256,
+ * depending on the chip type, to calculate the actual pwm frequency.
+ *
+ * Some of the chip datasheets suggest a base frequency of 51kHz instead
+ * of 750kHz for the slowest base frequency, resulting in a pwm frequency
+ * of 200Hz. Sometimes both pwm frequency select registers are affected,
+ * sometimes just one. It is unknown if this is a datasheet error or real,
+ * so this is ignored for now.

Leaving a space between the number and kHz or Hz makes it easier to read IMHO. I would also capitalize PWM everywhere.

Other than these minor suggestions, this looks good, good catch! I never noticed this difference between the various chips.

Jean

Signature · 7 lines
Jean Delvare
SUSE L3 Support

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
author maintainer
#2 lore raw

Re: [lm-sensors] [PATCH 01/15] hwmon: (it87) Fix pwm frequency display for chips with newer pwm cont

In reply to Guenter Roeck
Quoted 34 lines · Jean Delvare

Hi Guenter,

Quoted 17 lines · Guenter Roeck

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.

---
  drivers/hwmon/it87.c | 34 +++++++++++++++++++++++++---------
  1 file changed, 25 insertions(+), 9 deletions(-)
drivers/hwmon/it87.c +0 -0
index ab12dc2eb896..7ab5bd026e91 100644
@@ -502,15 +502,25 @@ static int DIV_TO_REG(int val)
  }
  #define DIV_FROM_REG(val) (1 << (val))

drivers/hwmon/it87.c static int DIV_TO_REG(int val) · line 513

Quoted 10 lines
drivers/hwmon/it87.c +9 -0
 
+/*
+ * pwm base frequencies. The frequency has to be divided by either 128 or 256,
+ * depending on the chip type, to calculate the actual pwm frequency.
+ *
+ * Some of the chip datasheets suggest a base frequency of 51kHz instead
+ * of 750kHz for the slowest base frequency, resulting in a pwm frequency
+ * of 200Hz. Sometimes both pwm frequency select registers are affected,
+ * sometimes just one. It is unknown if this is a datasheet error or real,
+ * so this is ignored for now.

Leaving a space between the number and kHz or Hz makes it easier to read IMHO. I would also capitalize PWM everywhere.

Quoted 3 lines

Other than these minor suggestions, this looks good, good catch! I never noticed this difference between the various chips.

Hi Jean,

I made those changes. Should I resubmit, or do I have your Reviewed-by: ?

Thanks,
Guenter

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#3 lore raw

Re: [lm-sensors] [PATCH 01/15] hwmon: (it87) Fix pwm frequency display for chips with newer pwm cont

In reply to Guenter Roeck

TGUgTW9uZGF5IDMwIE1hcmNoIDIwMTUgw6AgMDg6MTAgLTA3MDAsIEd1ZW50ZXIgUm9lY2sgYSDD qWNyaXQgOgo+IE9uIDAzLzMwLzIwMTUgMDQ6MDcgQU0sIEplY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dGNoISBJIG5ldmVyCj4gPiBub3RpY2VkIHRoaXMgZGlmZmVyZW5jZSBiZXR3ZWVuIHRoZSB2 YXJpb3VzIGNoaXBzLgo+ID4KPiAKPiBIaSBKZWFuLAo+IAo+IEkgbWFkZSB0aG9zZSBjaGFuZ2Vz LiBTaG91bGQgSSByZXN1Ym1pdCwgb3IgZG8gSSBoYXZlIHlvdXIgUmV2aWV3ZWQtYnk6ID8KCllv dSBoYXZlIGl0IG9mIGNvdXJzZSwgc29ycnkgSSB0aG91Z2h0IEkgaGFkIHB1dCBpdCBhbHJlYWR5 IGJ1dCBpdCBzZWVtcwpub3QuCgpSZXZpZXdlZC1ieTogSmVhbiBEZWx2YXJlIDxqZGVsdmFyZUBz dXNlLmRlPgoKCi0tIApKZWFuIERlbHZhcmUKU1VTRSBMMyBTdXBwb3J0CgoKX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KbG0tc2Vuc29ycyBtYWlsaW5nIGxp c3QKbG0tc2Vuc29yc0BsbS1zZW5zb3JzLm9yZwpodHRwOi8vbGlzdHMubG0tc2Vuc29ycy5vcmcv bWFpbG1hbi9saXN0aW5mby9sbS1zZW5zb3Jz

author maintainer
#4 lore raw

Re: [lm-sensors] [PATCH 01/15] hwmon: (it87) Fix pwm frequency display for chips with newer pwm cont

In reply to Guenter Roeck

T24gMDMvMzAvMjAxNSAwOTozNSBBTSwgSmVhbiBEZWx2YXJlIHdyb3RlOgo+IExlIE1vbmRheSAz MCBNYXJjaCAyMDE1IMOgIDA4OjEwIC0wNzAwLCBHdWVudGVyIFJvZWNrIGEgw6ljcml0IDoKClsg Li4uIF0KPj4+Pgo+Pj4+ICsvKgo+Pj4+ICsgKiBwd20gYmFzZSBmcmVxdWVuY2llcy4gVGhlIGZy ZXF1ZW5jeSBoYXMgdG8gYmUgZGl2aWRlZCBieSBlaXRoZXIgMTI4IG9yIDI1NiwKPj4+PiArICog ZGVwZW5kaW5nIG9uIHRoZSBjaGlw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