diff options
author | Krzysztof Helt <krzysztof.h1@wp.pl> | 2008-07-24 00:31:44 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2008-07-24 13:47:41 -0400 |
commit | 7fc80b7bd682b47825e806018cca8ff7dc6bb55a (patch) | |
tree | d408bf73887f4788e0d5e70c91320fff1391f624 /drivers/video | |
parent | 5798712d608f5ebad994487748a2ccf3cc613d78 (diff) |
neofb: simplify clock calculation
There is nothing to gain by converting value in kHz to fixed point MHz.
Just calculate everything in kHz.
A reorder of the loop allows reducing number of iterations (check if
frequency is not too high already).
Signed-off-by: Krzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/video')
-rw-r--r-- | drivers/video/neofb.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/drivers/video/neofb.c b/drivers/video/neofb.c index 5246b0402d76..b033e5a4dc86 100644 --- a/drivers/video/neofb.c +++ b/drivers/video/neofb.c | |||
@@ -201,7 +201,6 @@ static int neoFindMode(int xres, int yres, int depth) | |||
201 | * | 201 | * |
202 | * Determine the closest clock frequency to the one requested. | 202 | * Determine the closest clock frequency to the one requested. |
203 | */ | 203 | */ |
204 | #define REF_FREQ 0xe517 /* 14.31818 in 20.12 fixed point */ | ||
205 | #define MAX_N 127 | 204 | #define MAX_N 127 |
206 | #define MAX_D 31 | 205 | #define MAX_D 31 |
207 | #define MAX_F 1 | 206 | #define MAX_F 1 |
@@ -211,27 +210,24 @@ static void neoCalcVCLK(const struct fb_info *info, | |||
211 | { | 210 | { |
212 | int n, d, f; | 211 | int n, d, f; |
213 | int n_best = 0, d_best = 0, f_best = 0; | 212 | int n_best = 0, d_best = 0, f_best = 0; |
214 | long f_best_diff = (0x7ffff << 12); /* 20.12 */ | 213 | long f_best_diff = 0x7ffff; |
215 | long f_target = (freq << 12) / 1000; /* 20.12 */ | ||
216 | 214 | ||
217 | for (f = 0; f <= MAX_F; f++) | 215 | for (f = 0; f <= MAX_F; f++) |
218 | for (n = 0; n <= MAX_N; n++) | 216 | for (d = 0; d <= MAX_D; d++) |
219 | for (d = 0; d <= MAX_D; d++) { | 217 | for (n = 0; n <= MAX_N; n++) { |
220 | long f_out; /* 20.12 */ | 218 | long f_out; |
221 | long f_diff; /* 20.12 */ | 219 | long f_diff; |
222 | 220 | ||
223 | f_out = | 221 | f_out = ((14318 * (n + 1)) / (d + 1)) >> f; |
224 | ((((n + 1) << 12) / ((d + | 222 | f_diff = abs(f_out - freq); |
225 | 1) * | 223 | if (f_diff <= f_best_diff) { |
226 | (1 << f))) >> 12) | ||
227 | * REF_FREQ; | ||
228 | f_diff = abs(f_out - f_target); | ||
229 | if (f_diff < f_best_diff) { | ||
230 | f_best_diff = f_diff; | 224 | f_best_diff = f_diff; |
231 | n_best = n; | 225 | n_best = n; |
232 | d_best = d; | 226 | d_best = d; |
233 | f_best = f; | 227 | f_best = f; |
234 | } | 228 | } |
229 | if (f_out > freq) | ||
230 | break; | ||
235 | } | 231 | } |
236 | 232 | ||
237 | if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 || | 233 | if (info->fix.accel == FB_ACCEL_NEOMAGIC_NM2200 || |
@@ -248,11 +244,11 @@ static void neoCalcVCLK(const struct fb_info *info, | |||
248 | par->VCLK3Denominator = d_best; | 244 | par->VCLK3Denominator = d_best; |
249 | 245 | ||
250 | #ifdef NEOFB_DEBUG | 246 | #ifdef NEOFB_DEBUG |
251 | printk("neoVCLK: f:%d NumLow=%d NumHi=%d Den=%d Df=%d\n", | 247 | printk(KERN_DEBUG "neoVCLK: f:%ld NumLow=%d NumHi=%d Den=%d Df=%ld\n", |
252 | f_target >> 12, | 248 | freq, |
253 | par->VCLK3NumeratorLow, | 249 | par->VCLK3NumeratorLow, |
254 | par->VCLK3NumeratorHigh, | 250 | par->VCLK3NumeratorHigh, |
255 | par->VCLK3Denominator, f_best_diff >> 12); | 251 | par->VCLK3Denominator, f_best_diff); |
256 | #endif | 252 | #endif |
257 | } | 253 | } |
258 | 254 | ||