linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* patch better-pll-frequency-matching-for-tdfxfb-driver.patch added to -mm tree
@ 2005-04-29 23:18 akpm
  0 siblings, 0 replies; only message in thread
From: akpm @ 2005-04-29 23:18 UTC (permalink / raw)
  To: evilrich, linux-fbdev-devel


This is a note to let you know that I've just added the patch titled

     Better PLL frequency matching for tdfxfb driver

to the -mm tree.  Its filename is

     better-pll-frequency-matching-for-tdfxfb-driver.patch

Patches currently in -mm which might be from evilrich@rcdrummond.net are

better-pll-frequency-matching-for-tdfxfb-driver.patch



From: Richard Drummond <evilrich@rcdrummond.net>

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: Richard Drummond <evilrich@rcdrummond.net>
Cc: <linux-fbdev-devel@lists.sourceforge.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
---

 drivers/video/tdfxfb.c |   43 +++++++++++++++++++++++++++++++------------
 1 files changed, 31 insertions(+), 12 deletions(-)

diff -puN drivers/video/tdfxfb.c~better-pll-frequency-matching-for-tdfxfb-driver drivers/video/tdfxfb.c
--- 25/drivers/video/tdfxfb.c~better-pll-frequency-matching-for-tdfxfb-driver	Fri Apr 29 16:17:28 2005
+++ 25-akpm/drivers/video/tdfxfb.c	Fri Apr 29 16:18:27 2005
@@ -317,30 +317,49 @@ static inline void do_setpalentry(struct
 
 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;
 }
 
_


-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games.
Get your fingers limbered up and give it your best shot. 4 great events, 4
opportunities to win big! Highest score wins.NEC IT Guy Games. Play to
win an NEC 61 plasma display. Visit http://www.necitguy.com/?r=20

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2005-04-29 23:18 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-04-29 23:18 patch better-pll-frequency-matching-for-tdfxfb-driver.patch added to -mm tree akpm

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).