[PATCH] tridentfb: more precise clock calculation

From
Krzysztof Helt <hidden>
Date
2007-11-01 14:07:02
From: Krzysztof Helt <redacted>

The pixclock calculation is done in kHz instead in MHz. This allow
much more precise pixclock matching.

Additionally, the vclk field is removed from the par structure
and calculation of pixclock prefer now lower k values.

Signed-off-by: Krzysztof Helt <redacted>

---
This patch requires previous tridentfb patches sent to this list.

diff -urp linux-ref/drivers/video/tridentfb.c linux-2.6.23/drivers/video/tridentfb.c
--- linux-ref/drivers/video/tridentfb.c	2007-11-01 15:10:03.674079571 +0100
+++ linux-2.6.23/drivers/video/tridentfb.c	2007-11-01 15:02:17.622078751 +0100
@@ -27,7 +27,6 @@
 #define VERSION		"0.7.8-NEWAPI"
 
 struct tridentfb_par {
-	int vclk;		/* in MHz */
 	void __iomem *io_virt;	/* iospace virtual memory address */
 };
 
@@ -676,18 +675,18 @@ static void set_screen_start(int base)
 		 (read3X4(CRTHiOrd) & 0xF8) | ((base & 0xE0000) >> 17));
 }
 
-/* Use 20.12 fixed-point for NTSC value and frequency calculation */
-#define calc_freq(n, m, k)  ( ((unsigned long)0xE517 * (n + 8) / ((m + 2) * (1 << k))) >> 12 )
+/* NTSC value and frequency calculation */
+#define calc_freq(n, m, k)  (((14318L * (n + 8)) / (m + 2) ) >> k)
 
 /* Set dotclock frequency */
-static void set_vclk(int freq)
+static void set_vclk(unsigned long freq)
 {
 	int m, n, k;
-	int f, fi, d, di;
+	unsigned long f, fi, d, di;
 	unsigned char lo = 0, hi = 0;
 
-	d = 20;
-	for (k = 2; k >= 0; k--)
+	d = 50000;
+	for (k = 0; k < 3; k++)
 		for (m = 0; m < 63; m++)
 			for (n = 0; n < 128; n++) {
 				fi = calc_freq(n, m, k);
@@ -894,6 +893,8 @@ static int tridentfb_set_par(struct fb_i
 	struct fb_var_screeninfo *var = &info->var;
 	int bpp = var->bits_per_pixel;
 	unsigned char tmp;
+	unsigned long vclk;
+
 	debug("enter\n");
 	hdispend = var->xres / 8 - 1;
 	hsyncstart = (var->xres + var->right_margin) / 8;
@@ -1020,11 +1021,10 @@ static int tridentfb_set_par(struct fb_i
 	write3X4(Performance, 0x92);
 	write3X4(PCIReg, 0x07);		/* MMIO & PCI read and write burst enable */
 
-	/* convert from picoseconds to MHz */
-	par->vclk = 1000000 / info->var.pixclock;
+	vclk = PICOS2KHZ(info->var.pixclock);
 	if (bpp == 32)
-		par->vclk *= 2;
-	set_vclk(par->vclk);
+		vclk *= 2;
+	set_vclk(vclk);
 
 	write3C4(0, 3);
 	write3C4(1, 1);		/* set char clock 8 dots wide */

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help