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
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
|
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/rendition/vramdac.c,v 1.8 2000/01/18 16:35:53 tsi Exp $ */
/*
* includes
*/
#include "rendition.h"
#include "vramdac.h"
#include "vos.h"
#include "v1kregs.h"
#include "v2kregs.h"
/*
* defines
*/
/* directly accessable RAMDAC registers */
#define BT485_WRITE_ADDR 0x00
#define BT485_RAMDAC_DATA 0x01
#define BT485_PIXEL_MASK 0x02
#define BT485_READ_ADDR 0x03
#define BT485_CURS_WR_ADDR 0x04
#define BT485_CURS_DATA 0x05
#define BT485_COMMAND_REG_0 0x06
#define BT485_CURS_RD_ADDR 0x07
#define BT485_COMMAND_REG_1 0x08
#define BT485_COMMAND_REG_2 0x09
#define BT485_STATUS_REG 0x0a
#define BT485_CURS_RAM_DATA 0x0b
#define BT485_CURS_X_LOW 0x0c
#define BT485_CURS_X_HIGH 0x0d
#define BT485_CURS_Y_LOW 0x0e
#define BT485_CURS_Y_HIGH 0x0f
/* indirectly accessable ramdac registers */
#define BT485_COMMAND_REG_3 0x01
/* bits in command register 0 */
#define BT485_CR0_EXTENDED_REG_ACCESS 0x80
#define BT485_CR0_SCLK_SLEEP_DISABLE 0x40
#define BT485_CR0_BLANK_PEDESTAL 0x20
#define BT485_CR0_SYNC_ON_BLUE 0x10
#define BT485_CR0_SYNC_ON_GREEN 0x08
#define BT485_CR0_SYNC_ON_RED 0x04
#define BT485_CR0_8_BIT_DAC 0x02
#define BT485_CR0_SLEEP_ENABLE 0x01
/* bits in command register 1 */
#define BT485_CR1_24BPP 0x00
#define BT485_CR1_16BPP 0x20
#define BT485_CR1_8BPP 0x40
#define BT485_CR1_4BPP 0x60
#define BT485_CR1_1BPP 0x80
#define BT485_CR1_BYPASS_CLUT 0x10
#define BT485_CR1_565_16BPP 0x08
#define BT485_CR1_555_16BPP 0x00
#define BT485_CR1_1_TO_1_16BPP 0x04
#define BT485_CR1_2_TO_1_16BPP 0x00
#define BT485_CR1_PD7_PIXEL_SWITCH 0x02
#define BT485_CR1_PIXEL_PORT_CD 0x01
#define BT485_CR1_PIXEL_PORT_AB 0x00
/* bits in command register 2 */
#define BT485_CR2_SCLK_DISABLE 0x80
#define BT485_TEST_PATH_SELECT 0x40
#define BT485_PIXEL_INPUT_GATE 0x20
#define BT485_PIXEL_CLK_SELECT 0x10
#define BT485_INTERLACE_SELECT 0x08
#define BT485_16BPP_CLUT_PACKED 0x04
#define BT485_X_WINDOW_CURSOR 0x03
#define BT485_2_COLOR_CURSOR 0x02
#define BT485_3_COLOR_CURSOR 0x01
#define BT485_DISABLE_CURSOR 0x00
#define BT485_CURSOR_MASK 0x03
/* bits in command register 3 */
#define BT485_4BPP_NIBBLE_SWAP 0x10
#define BT485_CLOCK_DOUBLER 0x08
#define BT485_64_BY_64_CURSOR 0x04
#define BT485_32_BY_32_CURSOR 0x00
#define BT485_SIZE_MASK 0x04
/* special constants for the Brooktree BT485 RAMDAC */
#define BT485_INPUT_LIMIT 110000000
/*
* local function prototypes
*/
static void Bt485_write_masked(vu16 port, vu8 reg, vu8 mask, vu8 data);
static void Bt485_write_cmd3_masked(vu16 port, vu8 mask, vu8 data);
static vu8 Bt485_read_masked(vu16 port, vu8 reg, vu8 mask);
static vu8 Bt485_read_cmd3_masked(vu16 port, vu8 mask);
/*
* global data
*/
int Cursor_size=0;
/*
* functions
*/
/*
* int v_initdac(ScrnInfoPtr pScreenInfo, vu8 bpp, vu8 doubleclock)
*
* Used to initialize the ramdac. Palette-bypass is dis-/enabled with respect
* to the color depth, the cursor is disabled by default. If needed (i.e. if
* the corresponding field in the v_board_t struct is set), the clock doubling
* is turned on.
*/
int v_initdac(ScrnInfoPtr pScreenInfo, vu8 bpp, vu8 doubleclock)
{
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
vu16 iob=pRendition->board.io_base+RAMDACBASEADDR;
vu8 cmd3_data=0;
if (doubleclock)
cmd3_data|=BT485_CLOCK_DOUBLER;
switch (bpp) {
case 1:
case 4:
ErrorF("%s %s: color depth %d not (yet ?) supported\n",
X_CONFIG, /*vga256InfoRec.name*/"Rendition", bpp);
return -1;
case 8:
v_out8(iob+BT485_COMMAND_REG_0, BT485_CR0_EXTENDED_REG_ACCESS |
BT485_CR0_8_BIT_DAC);
v_out8(iob+BT485_COMMAND_REG_1, BT485_CR1_8BPP |
BT485_CR1_PIXEL_PORT_AB);
v_out8(iob+BT485_COMMAND_REG_2, BT485_PIXEL_INPUT_GATE |
BT485_DISABLE_CURSOR);
break;
case 15:
v_out8(iob+BT485_COMMAND_REG_0, BT485_CR0_EXTENDED_REG_ACCESS |
BT485_CR0_8_BIT_DAC);
v_out8(iob+BT485_COMMAND_REG_1, BT485_CR1_16BPP |
BT485_CR1_BYPASS_CLUT |
BT485_CR1_555_16BPP |
BT485_CR1_2_TO_1_16BPP |
BT485_CR1_PIXEL_PORT_AB);
v_out8(iob+BT485_COMMAND_REG_2, BT485_PIXEL_INPUT_GATE |
BT485_DISABLE_CURSOR);
break;
case 16:
v_out8(iob+BT485_COMMAND_REG_0, BT485_CR0_EXTENDED_REG_ACCESS |
BT485_CR0_8_BIT_DAC);
v_out8(iob+BT485_COMMAND_REG_1, BT485_CR1_16BPP |
BT485_CR1_BYPASS_CLUT |
BT485_CR1_565_16BPP |
BT485_CR1_2_TO_1_16BPP |
BT485_CR1_PIXEL_PORT_AB);
v_out8(iob+BT485_COMMAND_REG_2, BT485_PIXEL_INPUT_GATE |
BT485_DISABLE_CURSOR);
break;
case 32:
v_out8(iob+BT485_COMMAND_REG_0, BT485_CR0_EXTENDED_REG_ACCESS |
BT485_CR0_8_BIT_DAC);
v_out8(iob+BT485_COMMAND_REG_1, BT485_CR1_24BPP |
BT485_CR1_BYPASS_CLUT |
BT485_CR1_PIXEL_PORT_AB);
v_out8(iob+BT485_COMMAND_REG_2, BT485_PIXEL_INPUT_GATE |
BT485_DISABLE_CURSOR);
break;
default:
ErrorF( "%s %s: Color depth not supported (%d bpp)\n",
X_CONFIG, /*vga256InfoRec.name*/"Rendition", bpp);
return -1;
break;
}
v_out8(iob+BT485_WRITE_ADDR, BT485_COMMAND_REG_3);
v_out8(iob+BT485_STATUS_REG, cmd3_data);
/*
Bt485_write_masked(iob, BT485_COMMAND_REG_0, 0x7f, 0x00);
*/
v_out8(iob+BT485_PIXEL_MASK, 0xff);
return 0;
}
/*
* void v_enablecursor(ScrnInfoPtr pScreenInfo, int type, int size)
*
* Used to enable the hardware cursor. Size indicates, whether to use no cursor
* at all, a 32x32 or a 64x64 cursor. The type selects a two-color, three-color
* or X-window-like cursor. Valid values are defined in vramdac.h.
*
*/
void v_enablecursor(ScrnInfoPtr pScreenInfo, int type, int size)
{
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
static vu8 ctypes[]={ BT485_DISABLE_CURSOR, BT485_2_COLOR_CURSOR,
BT485_3_COLOR_CURSOR, BT485_X_WINDOW_CURSOR };
static vu8 csizes[]={ BT485_32_BY_32_CURSOR, BT485_64_BY_64_CURSOR };
vu16 iob=pRendition->board.io_base+RAMDACBASEADDR;
#ifdef DEBUG
/* ensure proper ranges */
size=1; /* Enforce 64x64 Cursor */
#endif
/* type goes to command register 2 */
Bt485_write_masked(iob, BT485_COMMAND_REG_2, ~BT485_CURSOR_MASK,
ctypes[type]);
/* size is in command register 3 */
Bt485_write_cmd3_masked(iob, ~BT485_SIZE_MASK, csizes[size]);
if (type)
Cursor_size=(size ? 64 : 32);
}
/*
* void v_movecursor(ScrnInfoPtr pScreenInfo, vu16 x, vu16 y, vu8 xo, vu8 yo)
*
* Moves the cursor to the specified location. To hide the cursor, call
* this routine with x=0x0 and y=0x0.
*
*/
void v_movecursor(ScrnInfoPtr pScreenInfo, vu16 x, vu16 y, vu8 xo, vu8 yo)
{
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
vu16 iob=pRendition->board.io_base+RAMDACBASEADDR;
x+=Cursor_size-xo;
y+=Cursor_size-yo;
v_out8(iob+BT485_CURS_X_LOW, x&0xff);
v_out8(iob+BT485_CURS_X_HIGH, (x>>8)&0x0f);
v_out8(iob+BT485_CURS_Y_LOW, y&0xff);
v_out8(iob+BT485_CURS_Y_HIGH, (y>>8)&0x0f);
}
/*
* void v_setcursorcolor(ScrnInfoPtr pScreenInfo, vu32 fg, vu32 bg)
*
* Sets the color of the cursor -- should be revised for use with 3 colors!
*
*/
void v_setcursorcolor(ScrnInfoPtr pScreenInfo, vu32 fg, vu32 bg)
{
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
vu16 iob=pRendition->board.io_base+RAMDACBASEADDR;
v_out8(iob+BT485_CURS_WR_ADDR, 0x00);
/* load the cursor color 0 */
v_out8(iob+BT485_CURS_DATA, bg&0xff);
v_out8(iob+BT485_CURS_DATA, (bg>>8)&0xff);
v_out8(iob+BT485_CURS_DATA, (bg>>16)&0xff);
/* load the cursor color 1 */
v_out8(iob+BT485_CURS_DATA, fg&0xff);
v_out8(iob+BT485_CURS_DATA, (fg>>8)&0xff);
v_out8(iob+BT485_CURS_DATA, (fg>>16)&0xff);
/* load the cursor color 2 (not used) */
v_out8(iob+BT485_CURS_DATA, 0x00);
v_out8(iob+BT485_CURS_DATA, 0x00);
v_out8(iob+BT485_CURS_DATA, 0x00);
}
/*
* Oh god, this code is quite a mess ... should be re-written soon.
* But for now I'm happy it works ;) <ml>
*
*/
void v_loadcursor(ScrnInfoPtr pScreenInfo, vu8 size, vu8 *cursorimage)
{
int c, bytes, row;
vu8 *src = cursorimage;
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
vu16 iob=pRendition->board.io_base+RAMDACBASEADDR;
vu8 tmp;
vu8 memend; /* Added for byte-swap fix */
if (NULL == cursorimage)
return;
/* Following two lines added for the byte-swap fix */
memend = v_in8(pRendition->board.io_base + MEMENDIAN);
v_out8(pRendition->board.io_base + MEMENDIAN, MEMENDIAN_HW);
size&=1;
if (size)
bytes=64;
else
bytes=32;
bytes=(bytes*bytes)/8;
if (pRendition->board.chip == V1000_DEVICE) {
/* now load the cursor data into the cursor ram */
tmp=v_in8(iob+BT485_COMMAND_REG_0)&0x7f;
v_out8(iob+BT485_COMMAND_REG_0, tmp|0x80);
v_out8(iob+BT485_WRITE_ADDR, BT485_COMMAND_REG_3);
tmp=v_in8(iob+BT485_STATUS_REG)&0xf8;
v_out8(iob+BT485_STATUS_REG, tmp|(size<<2));
v_out8(iob+BT485_WRITE_ADDR, 0x00);
/* output cursor image */
src=cursorimage;
/* First plane data */
for (c=0; c<bytes; c++) {
v_out8(iob+BT485_CURS_RAM_DATA, *src);
src+=2;
}
/* Second plane data */
src=cursorimage+1;
for (c=0; c<bytes; c++) {
v_out8(iob+BT485_CURS_RAM_DATA, *src);
src+=2;
}
}
else {
/* V2x00 HW-Cursor, supports only 64x64x2 size */
v_out32(iob+CURSORBASE, pRendition->board.hwcursor_membase);
/* First plane data */
for (row=0; row<64; row++)
for (c=0, src=cursorimage+1+16*row; c<8; c++, src+=2)
v_write_memory8(pRendition->board.vmem_base, 16*(63-row)+c,
(c&1)?(*(src-2)):(*(src+2)));
/* Second plane data */
for (row=0; row<64; row++)
for (c=0, src=cursorimage+16*row; c<8; c++, src+=2)
v_write_memory8(pRendition->board.vmem_base, 8+16*(63-row)+c,
(c&1)?(*(src-2)):(*(src+2)));
}
#ifdef DEBUG
/* Following line added for the byte-swap fix */
v_out8(pRendition->board.io_base + MEMENDIAN, memend);
#endif
}
/* NOTE: count is the actual number of colors decremented by 1 */
void v_setpalette(ScrnInfoPtr pScreenInfo, vu8 start, vu8 count, vu8 *table)
{
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
vu16 iob=pRendition->board.io_base;
vu32 crtc_status;
int c;
while (1) {
crtc_status=v_in32(iob+CRTCSTATUS);
if (crtc_status & CRTCSTATUS_VERT_SYNC)
break;
};
iob+=RAMDACBASEADDR;
if (((int)start+count) > 255)
count=255-start;
v_out8(iob+BT485_WRITE_ADDR, start);
for (c=0; c<=count; c++) {
v_out8(iob+BT485_RAMDAC_DATA, *table++);
v_out8(iob+BT485_RAMDAC_DATA, *table++);
v_out8(iob+BT485_RAMDAC_DATA, *table++);
}
}
/*
* local functions
*/
/*
* static void Bt485_write_masked(vu16 port, vu8 reg, vu8 mask, vu8 data)
*
*
*/
static void Bt485_write_masked(vu16 port, vu8 reg, vu8 mask, vu8 data)
{
vu8 tmp;
tmp=v_in8(port+reg)&mask;
v_out8(port+reg, tmp|data);
}
/*
* static void Bt485_write_cmd3_masked(vu16 port, vu8 mask, vu8 data)
*
*
*/
static void Bt485_write_cmd3_masked(vu16 port, vu8 mask, vu8 data)
{
/*
Bt485_write_masked(port, BT485_COMMAND_REG_0, 0x7f, 0x80);
*/
v_out8(port+BT485_WRITE_ADDR, BT485_COMMAND_REG_3);
Bt485_write_masked(port, BT485_STATUS_REG, mask, data);
/*
Bt485_write_masked(port, BT485_COMMAND_REG_0, 0x7f, 0x00);
*/
}
/*
* static vu8 Bt485_read_masked(vu16 port, vu8 reg, vu8 mask)
*
*
*/
static vu8 Bt485_read_masked(vu16 port, vu8 reg, vu8 mask)
{
return v_in8(port+reg)&mask;
}
/*
* static vu8 Bt485_read_cmd3_masked(vu16 port, vu8 mask)
*
*
*/
static vu8 Bt485_read_cmd3_masked(vu16 port, vu8 mask)
{
vu8 value;
Bt485_write_masked(port, BT485_COMMAND_REG_0, 0x7f, 0x80);
v_out8(port+BT485_WRITE_ADDR, BT485_COMMAND_REG_3);
value=Bt485_read_masked(port, BT485_STATUS_REG, mask);
Bt485_write_masked(port, BT485_COMMAND_REG_0, 0x7f, 0x00);
return value;
}
/*
* end of file vramdac.c
*/
|