Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 777
b: refs/heads/master
c: 0fbe9ca
h: refs/heads/master
i:
  775: 6c024d3
v: v3
  • Loading branch information
Richard Drummond authored and Linus Torvalds committed May 1, 2005
1 parent d91dd17 commit a7284d3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7c2f891cb64b0b9c8d389da97c221ee4288f1307
refs/heads/master: 0fbe9cafff72799700713e6a9d5a4ec7191e8d19
43 changes: 31 additions & 12 deletions trunk/drivers/video/tdfxfb.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,30 +317,49 @@ static inline void do_setpalentry(struct tdfx_par *par, unsigned regno, u32 c)

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;

/* this really could be done with more intelligence --
255*63*4 = 64260 iterations is silly */
best_error = freq;
best_n = best_m = best_k = 0;
for (n = 1; n < 256; n++) {
for (m = 1; m < 64; m++) {
for (k = 0; k < 4; k++) {
f_cur = fref*(n + 2)/(m + 2)/(1 << k);
if (abs(f_cur - freq) < best_error) {
best_error = abs(f_cur-freq);
best_n = n;
best_m = m;
best_k = k;

for (k = 3; k >= 0; k--) {
for (m = 63; m >= 0; m--) {
/*
* Estimate value of n that produces target frequency
* 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_m = m;
best_k = k;
}
}
}
}

n = best_n;
m = best_m;
k = best_k;
*freq_out = fref*(n + 2)/(m + 2)/(1 << k);

return (n << 8) | (m << 2) | k;
}

Expand Down

0 comments on commit a7284d3

Please sign in to comment.