Skip to content

Commit

Permalink
hwmon: (lm85) Select the closest PWM frequency
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jean Delvare authored and Jean Delvare committed Oct 17, 2008
1 parent 34e7dc6 commit 86010c9
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/hwmon/lm85.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 86010c9

Please sign in to comment.