Commit 86010c98 authored by Jean Delvare's avatar Jean Delvare Committed by Jean Delvare

hwmon: (lm85) Select the closest PWM frequency

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: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarHerbert Poetzl <herbert@13thfloor.at>
parent 34e7dc6c
...@@ -199,10 +199,9 @@ static int FREQ_TO_REG(int freq) ...@@ -199,10 +199,9 @@ static int FREQ_TO_REG(int freq)
{ {
int i; int i;
if (freq >= lm85_freq_map[7]) /* Find the closest match */
return 7;
for (i = 0; i < 7; ++i) 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; break;
return i; return i;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment