xref: /plan9-contrib/sys/src/cmd/aux/vga/ics2494.c (revision 219b2ee8daee37f4aad58d63f21287faa8e4ffdc)
1 /*
2  * Integrated Circuit Systems, Inc.
3  * ICS2494[A] Dual Video/Memory Clock Generator.
4  */
5 #include <u.h>
6 #include <libc.h>
7 
8 #include "vga.h"
9 
10 typedef struct {
11 	char*	name[2];
12 	ulong	frequency[16];
13 } Pattern;
14 
15 static Pattern patterns[] = {
16 	{ "237", "304",
17 	 50350000,  56644000,  65000000,  72000000,  80000000,  89800000,  63000000,  75000000,
18 	 25175000,  28322000,  31500000,  36000000,  40000000,  44900000,  50000000,  65000000,
19 	},
20 
21 	{ "324", 0,
22 	 50350000,  56644000,  65000000,  72000000,  80000000,  89800000,  63000000,  75000000,
23 	 83078000,  93463000, 100000000, 104000000, 108000000, 120000000, 130000000, 134700000,
24 	},
25 
26 	{ 0,
27 	},
28 };
29 
30 static void
31 init(Vga *vga, Ctlr *ctlr)
32 {
33 	Pattern *pattern;
34 	char *p;
35 	int f, divisor, index;
36 
37 	verbose("%s->init\n", ctlr->name);
38 	if(ctlr->flag & Finit)
39 		return;
40 
41 	if(vga->f == 0)
42 		vga->f = vga->mode->frequency;
43 
44 	if((p = strchr(ctlr->name, '-')) == 0)
45 		error("%s: unknown pattern\n", ctlr->name);
46 	p++;
47 
48 	for(pattern = patterns; pattern->name[0]; pattern++){
49 		if(strcmp(pattern->name[0], p) == 0)
50 			break;
51 		if(pattern->name[1] && strcmp(pattern->name[1], p) == 0)
52 			break;
53 	}
54 	if(pattern->name[0] == 0)
55 		error("%s: unknown pattern\n", ctlr->name);
56 
57 	for(index = 0; index < 16; index++){
58 		for(divisor = 1; divisor < 8; divisor <<= 1){
59 			f = vga->f - pattern->frequency[index]/divisor;
60 			if(f < 0)
61 				f = -f;
62 			if(f < 1000000){
63 				/*vga->f = pattern->frequency[index];*/
64 				vga->d = divisor;
65 				vga->i = index;
66 
67 				ctlr->flag |= Finit;
68 				return;
69 			}
70 		}
71 	}
72 	error("%s: can't find frequency %ld\n", ctlr->name, vga->f);
73 }
74 
75 Ctlr ics2494 = {
76 	"ics2494",			/* name */
77 	0,				/* snarf */
78 	0,				/* options */
79 	init,				/* init */
80 	0,				/* load */
81 	0,				/* dump */
82 };
83 
84 Ctlr ics2494a = {
85 	"ics2494a",			/* name */
86 	0,				/* snarf */
87 	0,				/* options */
88 	init,				/* init */
89 	0,				/* load */
90 	0,				/* dump */
91 };
92