* [lm-sensors] [PATCH 09/10] hwmon: (lm85) Select the closest PWM
@ 2008-04-12 18:05 Jean Delvare
0 siblings, 0 replies; only message in thread
From: Jean Delvare @ 2008-04-12 18:05 UTC (permalink / raw)
To: lm-sensors
The LM85 and compatible chips only support 8 arbitrary PWM frequencies.
The algorithm to pick one of them based on the user input is not
optimum. Improve it to always pick the closest supported frequency.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
---
The new algorithm is exactly the same as the one used in
RANGE_TO_REG().
drivers/hwmon/lm85.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
--- linux-2.6.25-rc8.orig/drivers/hwmon/lm85.c 2008-04-03 18:16:31.000000000 +0200
+++ linux-2.6.25-rc8/drivers/hwmon/lm85.c 2008-04-03 18:45:54.000000000 +0200
@@ -202,10 +202,18 @@ static int FREQ_TO_REG(int freq)
if (freq >= lm85_freq_map[7])
return 7;
- for (i = 0; i < 7; ++i)
- if (freq <= lm85_freq_map[i])
- break;
- return i;
+
+ /* Find the closest match */
+ for (i = 6; i >= 0; --i) {
+ if (freq >= lm85_freq_map[i]) {
+ if ((lm85_freq_map[i + 1] - freq) <
+ (freq - lm85_freq_map[i]))
+ return i + 1;
+ return i;
+ }
+ }
+
+ return 0;
}
#define FREQ_FROM_REG(val) lm85_freq_map[(val) & 0x07]
--
Jean Delvare
_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2008-04-12 18:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-12 18:05 [lm-sensors] [PATCH 09/10] hwmon: (lm85) Select the closest PWM Jean Delvare
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.