1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
|
#include <u.h>
#include <libc.h>
#include <bio.h>
#include "pci.h"
#include "vga.h"
/*
* IBM RGB524.
* 170/220MHz High Performance Palette DAC.
*
* Assumes hooked up to an S3 Vision96[48].
*/
enum {
IndexLo = 0x00,
IndexHi = 0x01,
Data = 0x02,
IndexCtl = 0x03,
};
enum { /* index registers */
MiscClock = 0x02,
PixelFormat = 0x0A,
PLLControl1 = 0x10,
PLLControl2 = 0x11,
PLLReference = 0x14,
Frequency0 = 0x20,
MiscControl1 = 0x70,
MiscControl2 = 0x71,
};
static uchar
setrs2(void)
{
uchar rs2;
rs2 = vgaxi(Crtx, 0x55);
vgaxo(Crtx, 0x55, (rs2 & 0xFC)|0x01);
return rs2;
}
static uchar
rgb524xi(int index)
{
outportb(dacxreg[IndexLo], index & 0xFF);
outportb(dacxreg[IndexHi], (index>>8) & 0xFF);
return inportb(dacxreg[Data]);
}
static void
rgb524xo(int index, uchar data)
{
outportb(dacxreg[IndexLo], index & 0xFF);
outportb(dacxreg[IndexHi], (index>>8) & 0xFF);
outportb(dacxreg[Data], data);
}
static void
restorers2(uchar rs2)
{
vgaxo(Crtx, 0x55, rs2);
}
static void
clock(Vga* vga, Ctlr* ctlr)
{
if(vga->f[0] >= 16250000 && vga->f[0] <= 32000000){
vga->f[0] = (vga->f[0]/250000)*250000;
vga->d[0] = (4*vga->f[0])/1000000 - 65;
}
else if(vga->f[0] >= 32500000 && vga->f[0] <= 64000000){
vga->f[0] = (vga->f[0]/500000)*500000;
vga->d[0] = 0x40|((2*vga->f[0])/1000000 - 65);
}
else if(vga->f[0] >= 65000000 && vga->f[0] <= 128000000){
vga->f[0] = (vga->f[0]/1000000)*1000000;
vga->d[0] = 0x80|(vga->f[0]/1000000 - 65);
}
else if(vga->f[0] >= 130000000 && vga->f[0] <= 220000000){
vga->f[0] = (vga->f[0]/2000000)*2000000;
vga->d[0] = 0xC0|((vga->f[0]/2)/1000000 - 65);
}
else
error("%s: pclk %lud out of range\n",
ctlr->name, vga->f[0]);
}
static void
init(Vga* vga, Ctlr* ctlr)
{
ulong pclk;
char *p;
/*
* Part comes in -170 and -220MHz speed-grades.
*/
pclk = 170000000;
if(p = strrchr(ctlr->name, '-'))
pclk = strtoul(p+1, 0, 0) * 1000000;
/*
* If we don't already have a desired pclk,
* take it from the mode.
* Check it's within range.
*/
if(vga->f[0] == 0)
vga->f[0] = vga->mode->frequency;
if(vga->f[0] > pclk)
error("%s: invalid pclk - %ld\n", ctlr->name, vga->f[0]);
/*
* Determine whether to use clock-doubler or not.
*/
if((ctlr->flag & Uclk2) == 0 && vga->mode->z == 8)
resyncinit(vga, ctlr, Uclk2, 0);
/*
* Clock bits. If the desired video clock is
* one of the two standard VGA clocks it can just be
* set using bits <3:2> of vga->misc, otherwise we
* need to programme the PLL.
*/
vga->misc &= ~0x0C;
if(vga->mode->z == 8 || (vga->f[0] != VgaFreq0 && vga->f[0] != VgaFreq1)){
/*
* Initialise the PLL parameters.
* Use internal FS3 fixed-reference divider.
*/
clock(vga, ctlr);
vga->i[0] = 0x03;
}
else if(vga->f[0] == VgaFreq0)
vga->i[0] = 0;
else if(vga->f[0] == VgaFreq1){
vga->misc |= 0x04;
vga->i[0] = 1;
}
ctlr->flag |= Finit;
}
static void
load(Vga* vga, Ctlr* ctlr)
{
uchar mc2, rs2, x;
char *val;
int f;
rs2 = setrs2();
/*
* Set VgaFreq[01].
*/
rgb524xo(PLLControl1, 0x00);
rgb524xo(Frequency0, 0x24);
rgb524xo(Frequency0+1, 0x30);
if(val = dbattr(vga->attr, "rgb524refclk")){
f = strtol(val, 0, 0);
if(f > 1000000)
f /= 1000000;
rgb524xo(PLLReference, f/2);
}
/*
* Enable pixel programming and clock divide
* factor.
*/
x = rgb524xi(MiscClock) & ~0x0E;
x |= 0x01;
if(ctlr->flag & Uclk2)
x |= 0x02;
rgb524xo(MiscClock, x);
if(vga->mode->z == 1)
rgb524xo(PixelFormat, 0x02);
else if(vga->mode->z == 8)
rgb524xo(PixelFormat, 0x03);
x = rgb524xi(MiscControl1) & ~0x41;
x |= 0x01;
rgb524xo(MiscControl1, x);
mc2 = rgb524xi(MiscControl2) & ~0x41;
vga->crt[0x22] &= ~0x08;
if(vga->i[0] == 3){
rgb524xo(Frequency0+3, vga->d[0]);
rgb524xo(PLLControl1, 0x02);
rgb524xo(PLLControl2, vga->i[0]);
mc2 |= 0x41;
vga->crt[0x22] |= 0x08;
}
rgb524xo(MiscControl2, mc2);
vgaxo(Crtx, 0x22, vga->crt[0x22]);
restorers2(rs2);
ctlr->flag |= Fload;
}
static void
dump(Vga*, Ctlr* ctlr)
{
uchar rs2, r, x[256];
char buf[32];
int df, i, maxf, vcodc, vf;
rs2 = setrs2();
printitem(ctlr->name, "index00");
for(i = 0x00; i < 0x0F; i++){
x[i] = rgb524xi(i);
printreg(x[i]);
}
printitem(ctlr->name, "index10");
for(i = 0x10; i < 0x17; i++){
x[i] = rgb524xi(i);
printreg(x[i]);
}
printitem(ctlr->name, "index20");
for(i = 0x20; i < 0x30; i++){
x[i] = rgb524xi(i);
printreg(x[i]);
}
printitem(ctlr->name, "index30");
for(i = 0x30; i < 0x37; i++){
x[i] = rgb524xi(i);
printreg(x[i]);
}
printitem(ctlr->name, "index40");
for(i = 0x40; i < 0x49; i++){
x[i] = rgb524xi(i);
printreg(x[i]);
}
printitem(ctlr->name, "index60");
for(i = 0x60; i < 0x63; i++){
x[i] = rgb524xi(i);
printreg(x[i]);
}
printitem(ctlr->name, "index70");
for(i = 0x70; i < 0x73; i++){
x[i] = rgb524xi(i);
printreg(x[i]);
}
printitem(ctlr->name, "index8E");
for(i = 0x8E; i < 0x92; i++){
x[i] = rgb524xi(i);
printreg(x[i]);
}
restorers2(rs2);
/*
* x[0x10] pixel clock frequency selection
* 0, 2 for direct programming
* x[0x20-0x2F] pixel frequency 0-15
*/
printitem(ctlr->name, "refclk");
Bprint(&stdout, "%12ud\n", x[PLLReference]*2*1000000);
if((i = (x[0x10] & 0x07)) == 0x00 || i == 0x02){
/*
* Direct programming, external frequency select.
* F[0-4] are probably tied directly to the 2 clock-select
* bits in the VGA Misc register.
*/
if(i == 0)
maxf = 4;
else
maxf = 16;
for(i = 0; i < maxf; i++){
if((r = x[0x20+i]) == 0)
continue;
sprint(buf, "direct F%X", i);
printitem(ctlr->name, buf);
df = (r>>6) & 0x03;
vcodc = r & 0x3F;
vf = 0;
switch(df){
case 0:
vf = (vcodc+65)/4;
break;
case 1:
vf = (vcodc+65)/2;
break;
case 2:
vf = (vcodc+65);
break;
case 3:
vf = (vcodc+65)*2;
break;
}
Bprint(&stdout, "%12ud\n", vf);
}
}
}
Ctlr rgb524 = {
"rgb524", /* name */
0, /* snarf */
0, /* options */
init, /* init */
load, /* load */
dump, /* dump */
};
|