Commit 0fbe9caf authored by Richard Drummond's avatar Richard Drummond Committed by Linus Torvalds

[PATCH] Better PLL frequency matching for tdfxfb driver

Improve the PLL frequency matching in the tdfxfb driver.  Instead of
requiring 64260 iterations to obtain the closest supported PLL frequency,
this code does it with the same degree of accuracy in at most 768
iterations.
Signed-off-by: default avatarRichard Drummond <evilrich@rcdrummond.net>
Cc: <linux-fbdev-devel@lists.sourceforge.net>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 7c2f891c
...@@ -317,19 +317,36 @@ static inline void do_setpalentry(struct tdfx_par *par, unsigned regno, u32 c) ...@@ -317,19 +317,36 @@ static inline void do_setpalentry(struct tdfx_par *par, unsigned regno, u32 c)
static u32 do_calc_pll(int freq, int* freq_out) static u32 do_calc_pll(int freq, int* freq_out)
{ {
int m, n, k, best_m, best_n, best_k, f_cur, best_error; int m, n, k, best_m, best_n, best_k, best_error;
int fref = 14318; int fref = 14318;
/* this really could be done with more intelligence --
255*63*4 = 64260 iterations is silly */
best_error = freq; best_error = freq;
best_n = best_m = best_k = 0; best_n = best_m = best_k = 0;
for (n = 1; n < 256; n++) {
for (m = 1; m < 64; m++) { for (k = 3; k >= 0; k--) {
for (k = 0; k < 4; k++) { for (m = 63; m >= 0; m--) {
f_cur = fref*(n + 2)/(m + 2)/(1 << k); /*
if (abs(f_cur - freq) < best_error) { * Estimate value of n that produces target frequency
best_error = abs(f_cur-freq); * with current m and k
*/
int n_estimated = (freq * (m + 2) * (1 << k) / fref) - 2;
/* Search neighborhood of estimated n */
for (n = max(0, n_estimated - 1);
n <= min(255, n_estimated + 1); n++) {
/*
* Calculate PLL freqency with current m, k and
* estimated n
*/
int f = fref * (n + 2) / (m + 2) / (1 << k);
int error = abs (f - freq);
/*
* If this is the closest we've come to the
* target frequency then remember n, m and k
*/
if (error < best_error) {
best_error = error;
best_n = n; best_n = n;
best_m = m; best_m = m;
best_k = k; best_k = k;
...@@ -337,10 +354,12 @@ static u32 do_calc_pll(int freq, int* freq_out) ...@@ -337,10 +354,12 @@ static u32 do_calc_pll(int freq, int* freq_out)
} }
} }
} }
n = best_n; n = best_n;
m = best_m; m = best_m;
k = best_k; k = best_k;
*freq_out = fref*(n + 2)/(m + 2)/(1 << k); *freq_out = fref*(n + 2)/(m + 2)/(1 << k);
return (n << 8) | (m << 2) | k; return (n << 8) | (m << 2) | k;
} }
......
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