]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
hwmon: (lm85) Select the closest PWM frequency
authorJean Delvare <khali@linux-fr.org>
Fri, 17 Oct 2008 15:51:13 +0000 (17:51 +0200)
committerJean Delvare <khali@mahadeva.delvare>
Fri, 17 Oct 2008 15:51:13 +0000 (17:51 +0200)
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>
Acked-by: Herbert Poetzl <herbert@13thfloor.at>
drivers/hwmon/lm85.c

index 6b676df3547bc4052d50815fa23d6c4fec925ba8..c323c2b8980809600e80130a615f8811e5737a49 100644 (file)
@@ -199,10 +199,9 @@ static int FREQ_TO_REG(int freq)
 {
        int i;
 
-       if (freq >= lm85_freq_map[7])
-               return 7;
+       /* Find the closest match */
        for (i = 0; i < 7; ++i)
-               if (freq <= lm85_freq_map[i])
+               if (freq <= (lm85_freq_map[i] + lm85_freq_map[i + 1]) / 2)
                        break;
        return i;
 }