From: Richard Drummond <evilrich@rcdrummond.net>
To: linux-fbdev-devel@lists.sourceforge.net
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] Better PLL frequency matching for tdfxfb driver
Date: Thu, 21 Apr 2005 22:58:00 -0500 [thread overview]
Message-ID: <200504212258.00570.evilrich@rcdrummond.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 326 bytes --]
Attached is a patch against 2.6.11.7 which improves 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: Richard Drummond <evilrich@rcdrummond.net>
[-- Attachment #2: tdfxfb_pll_fix.diff --]
[-- Type: text/x-diff, Size: 1657 bytes --]
--- drivers/video/tdfxfb.c_orig 2005-04-20 15:04:23.000000000 -0500
+++ drivers/video/tdfxfb.c 2005-04-21 09:26:18.000000000 -0500
@@ -320,30 +320,40 @@
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;
}
reply other threads:[~2005-04-22 4:09 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200504212258.00570.evilrich@rcdrummond.net \
--to=evilrich@rcdrummond.net \
--cc=linux-fbdev-devel@lists.sourceforge.net \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).