1
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/rendition/vramdac.c,v 1.18 2002/12/11 17:23:33 dawes Exp $ */
18
/* directly accessable RAMDAC registers */
19
#define BT485_WRITE_ADDR 0x00
20
#define BT485_RAMDAC_DATA 0x01
21
#define BT485_PIXEL_MASK 0x02
22
#define BT485_READ_ADDR 0x03
23
#define BT485_CURS_WR_ADDR 0x04
24
#define BT485_CURS_DATA 0x05
25
#define BT485_COMMAND_REG_0 0x06
26
#define BT485_CURS_RD_ADDR 0x07
27
#define BT485_COMMAND_REG_1 0x08
28
#define BT485_COMMAND_REG_2 0x09
29
#define BT485_STATUS_REG 0x0a
30
#define BT485_CURS_RAM_DATA 0x0b
31
#define BT485_CURS_X_LOW 0x0c
32
#define BT485_CURS_X_HIGH 0x0d
33
#define BT485_CURS_Y_LOW 0x0e
34
#define BT485_CURS_Y_HIGH 0x0f
36
/* indirectly accessable ramdac registers */
37
#define BT485_COMMAND_REG_3 0x01
39
/* bits in command register 0 */
40
#define BT485_CR0_EXTENDED_REG_ACCESS 0x80
41
#define BT485_CR0_SCLK_SLEEP_DISABLE 0x40
42
#define BT485_CR0_BLANK_PEDESTAL 0x20
43
#define BT485_CR0_SYNC_ON_BLUE 0x10
44
#define BT485_CR0_SYNC_ON_GREEN 0x08
45
#define BT485_CR0_SYNC_ON_RED 0x04
46
#define BT485_CR0_8_BIT_DAC 0x02
47
#define BT485_CR0_SLEEP_ENABLE 0x01
49
/* bits in command register 1 */
50
#define BT485_CR1_24BPP 0x00
51
#define BT485_CR1_16BPP 0x20
52
#define BT485_CR1_8BPP 0x40
53
#define BT485_CR1_4BPP 0x60
54
#define BT485_CR1_1BPP 0x80
55
#define BT485_CR1_BYPASS_CLUT 0x10
56
#define BT485_CR1_565_16BPP 0x08
57
#define BT485_CR1_555_16BPP 0x00
58
#define BT485_CR1_1_TO_1_16BPP 0x04
59
#define BT485_CR1_2_TO_1_16BPP 0x00
60
#define BT485_CR1_PD7_PIXEL_SWITCH 0x02
61
#define BT485_CR1_PIXEL_PORT_CD 0x01
62
#define BT485_CR1_PIXEL_PORT_AB 0x00
64
/* bits in command register 2 */
65
#define BT485_CR2_SCLK_DISABLE 0x80
66
#define BT485_TEST_PATH_SELECT 0x40
67
#define BT485_PIXEL_INPUT_GATE 0x20
68
#define BT485_PIXEL_CLK_SELECT 0x10
69
#define BT485_INTERLACE_SELECT 0x08
70
#define BT485_16BPP_CLUT_PACKED 0x04
71
#define BT485_X_WINDOW_CURSOR 0x03
72
#define BT485_2_COLOR_CURSOR 0x02
73
#define BT485_3_COLOR_CURSOR 0x01
74
#define BT485_DISABLE_CURSOR 0x00
75
#define BT485_CURSOR_MASK 0x03
77
/* bits in command register 3 */
78
#define BT485_4BPP_NIBBLE_SWAP 0x10
79
#define BT485_CLOCK_DOUBLER 0x08
80
#define BT485_64_BY_64_CURSOR 0x04
81
#define BT485_32_BY_32_CURSOR 0x00
82
#define BT485_SIZE_MASK 0x04
84
/* special constants for the Brooktree BT485 RAMDAC */
85
#define BT485_INPUT_LIMIT 110000000
90
* local function prototypes
93
static void Bt485_write_masked(IOADDRESS port, vu8 reg, vu8 mask, vu8 data);
94
static void Bt485_write_cmd3_masked(IOADDRESS port, vu8 mask, vu8 data);
96
static vu8 Bt485_read_masked(IOADDRESS port, vu8 reg, vu8 mask);
97
static vu8 Bt485_read_cmd3_masked(IOADDRESS port, vu8 mask);
104
static int Cursor_size=0;
113
* int verite_initdac(ScrnInfoPtr pScreenInfo, vu8 bpp, vu8 doubleclock)
115
* Used to initialize the ramdac. Palette-bypass is dis-/enabled with respect
116
* to the color depth, the cursor is disabled by default. If needed (i.e. if
117
* the corresponding field in the verite_board_t struct is set), the clock doubling
122
verite_savedac (ScrnInfoPtr pScreenInfo)
124
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
125
int iob=pRendition->board.io_base + RAMDACBASEADDR;
126
RenditionRegPtr reg = &pRendition->saveRegs;
128
reg->daccmd0 = verite_in8(iob+BT485_COMMAND_REG_0);
129
reg->daccmd1 = verite_in8(iob+BT485_COMMAND_REG_1);
130
reg->daccmd2 = verite_in8(iob+BT485_COMMAND_REG_2);
131
verite_out8(iob+BT485_COMMAND_REG_0,reg->daccmd0
132
| BT485_CR0_EXTENDED_REG_ACCESS);
133
verite_out8(iob+BT485_WRITE_ADDR, BT485_COMMAND_REG_3);
134
reg->daccmd3 = verite_in8(iob+BT485_STATUS_REG);
135
verite_out8(iob+BT485_COMMAND_REG_0,reg->daccmd0);
140
verite_restoredac (ScrnInfoPtr pScreenInfo, RenditionRegPtr reg)
142
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
143
int iob=pRendition->board.io_base + RAMDACBASEADDR;
145
verite_out8(iob+BT485_COMMAND_REG_0, reg->daccmd0
146
| BT485_CR0_EXTENDED_REG_ACCESS);
147
verite_out8(iob+BT485_COMMAND_REG_1, reg->daccmd1);
148
verite_out8(iob+BT485_COMMAND_REG_2, reg->daccmd2);
149
verite_out8(iob+BT485_WRITE_ADDR, BT485_COMMAND_REG_3);
150
verite_out8(iob+BT485_STATUS_REG, reg->daccmd3);
151
verite_out8(iob+BT485_COMMAND_REG_0, reg->daccmd0);
156
verite_initdac(ScrnInfoPtr pScreenInfo, vu8 bpp, vu8 doubleclock)
158
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
159
IOADDRESS iob=pRendition->board.io_base+RAMDACBASEADDR;
164
ErrorF ("Rendition: Debug verite_initdac called\n");
168
cmd3_data|=BT485_CLOCK_DOUBLER;
173
ErrorF("%s %s: color depth %d not (yet ?) supported\n",
174
X_CONFIG, /*vga256InfoRec.name*/"Rendition", bpp);
178
cmd0 = BT485_CR0_EXTENDED_REG_ACCESS |
181
cmd1 = BT485_CR1_8BPP |
182
BT485_CR1_PIXEL_PORT_AB;
184
cmd2 = BT485_PIXEL_INPUT_GATE |
185
BT485_DISABLE_CURSOR;
187
verite_out8(iob+BT485_COMMAND_REG_0, cmd0);
188
verite_out8(iob+BT485_COMMAND_REG_1, cmd1);
189
verite_out8(iob+BT485_COMMAND_REG_2, cmd2);
193
cmd0 = BT485_CR0_EXTENDED_REG_ACCESS |
196
cmd1 = BT485_CR1_16BPP |
197
BT485_CR1_2_TO_1_16BPP |
198
BT485_CR1_PIXEL_PORT_AB;
200
cmd2 = BT485_PIXEL_INPUT_GATE |
201
BT485_DISABLE_CURSOR;
203
if (pScreenInfo->defaultVisual == TrueColor)
204
cmd1 |= BT485_CR1_BYPASS_CLUT;
206
if (pScreenInfo->weight.green == 5)
207
cmd1 |= BT485_CR1_555_16BPP;
209
cmd1 |= BT485_CR1_565_16BPP;
211
verite_out8(iob+BT485_COMMAND_REG_0,cmd0);
212
verite_out8(iob+BT485_COMMAND_REG_1,cmd1);
213
verite_out8(iob+BT485_COMMAND_REG_2,cmd2);
217
cmd0 = BT485_CR0_EXTENDED_REG_ACCESS |
220
cmd1 = BT485_CR1_24BPP |
221
BT485_CR1_PIXEL_PORT_AB;
223
cmd2 = BT485_PIXEL_INPUT_GATE |
224
BT485_DISABLE_CURSOR;
226
if (pScreenInfo->defaultVisual == TrueColor)
227
cmd1 |= BT485_CR1_BYPASS_CLUT;
229
verite_out8(iob+BT485_COMMAND_REG_0,cmd0);
230
verite_out8(iob+BT485_COMMAND_REG_1,cmd1);
231
verite_out8(iob+BT485_COMMAND_REG_2,cmd2);
235
ErrorF( "%s %s: Color depth not supported (%d bpp)\n",
236
X_CONFIG, /*vga256InfoRec.name*/"Rendition", bpp);
241
verite_out8(iob+BT485_WRITE_ADDR, BT485_COMMAND_REG_3);
242
verite_out8(iob+BT485_STATUS_REG, cmd3_data);
244
Bt485_write_masked(iob, BT485_COMMAND_REG_0, 0x7f, 0x00);
246
verite_out8(iob+BT485_PIXEL_MASK, 0xff);
254
* void verite_enablecursor(ScrnInfoPtr pScreenInfo, int type, int size)
256
* Used to enable the hardware cursor. Size indicates, whether to use no cursor
257
* at all, a 32x32 or a 64x64 cursor. The type selects a two-color, three-color
258
* or X-window-like cursor. Valid values are defined in vramdac.h.
262
verite_enablecursor(ScrnInfoPtr pScreenInfo, int type, int size)
264
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
266
static vu8 ctypes[]={ BT485_DISABLE_CURSOR, BT485_2_COLOR_CURSOR,
267
BT485_3_COLOR_CURSOR, BT485_X_WINDOW_CURSOR };
268
static vu8 csizes[]={ BT485_32_BY_32_CURSOR, BT485_64_BY_64_CURSOR };
270
IOADDRESS iob=pRendition->board.io_base+RAMDACBASEADDR;
273
ErrorF ("Rendition: Debug verite_enablecursor called type=0x%x\n",type);
276
/* type goes to command register 2 */
277
Bt485_write_masked(iob, BT485_COMMAND_REG_2, ~BT485_CURSOR_MASK,
280
/* size is in command register 3 */
281
Bt485_write_cmd3_masked(iob, ~BT485_SIZE_MASK, csizes[size]);
284
Cursor_size=(size ? 64 : 32);
287
ErrorF ("Rendition: Debug verite_enablecursor Exit\n");
293
* void verite_movecursor(ScrnInfoPtr pScreenInfo, vu16 x, vu16 y, vu8 xo, vu8 yo)
295
* Moves the cursor to the specified location. To hide the cursor, call
296
* this routine with x=0x0 and y=0x0.
300
verite_movecursor(ScrnInfoPtr pScreenInfo, vu16 x, vu16 y, vu8 xo, vu8 yo)
302
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
303
IOADDRESS iob=pRendition->board.io_base+RAMDACBASEADDR;
308
verite_out8(iob+BT485_CURS_X_LOW, x&0xff);
309
verite_out8(iob+BT485_CURS_X_HIGH, (x>>8)&0x0f);
310
verite_out8(iob+BT485_CURS_Y_LOW, y&0xff);
311
verite_out8(iob+BT485_CURS_Y_HIGH, (y>>8)&0x0f);
317
* void verite_setcursorcolor(ScrnInfoPtr pScreenInfo, vu32 bg, vu32 fg)
319
* Sets the color of the cursor -- should be revised for use with 3 colors!
323
verite_setcursorcolor(ScrnInfoPtr pScreenInfo, vu32 fg, vu32 bg)
325
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
326
IOADDRESS iob=pRendition->board.io_base+RAMDACBASEADDR;
329
ErrorF ("Rendition: Debug verite_setcursorcolor called FG=0x%x BG=0x%x\n",
333
verite_out8(iob+BT485_CURS_WR_ADDR, 0x00);
335
/* load the cursor color 0 */
336
verite_out8(iob+BT485_CURS_DATA, 0x00);
337
verite_out8(iob+BT485_CURS_DATA, 0x00);
338
verite_out8(iob+BT485_CURS_DATA, 0x00);
340
/* load the cursor color 1 */
341
verite_out8(iob+BT485_CURS_DATA, (fg>>16) & 0xff);
342
verite_out8(iob+BT485_CURS_DATA, (fg>>8) & 0xff);
343
verite_out8(iob+BT485_CURS_DATA, fg&0xff );
346
* The V2xxx and the V1xxx with external BT485 behave differently.
347
* If we set color 2 to fg both work correctly.
349
/* load the cursor color 2 */
350
verite_out8(iob+BT485_CURS_DATA, (fg>>16) & 0xff);
351
verite_out8(iob+BT485_CURS_DATA, (fg>>8) & 0xff);
352
verite_out8(iob+BT485_CURS_DATA, fg & 0xff);
354
/* load the cursor color 3 */
355
verite_out8(iob+BT485_CURS_DATA, (bg>>16)&0xff );
356
verite_out8(iob+BT485_CURS_DATA, (bg>>8)&0xff );
357
verite_out8(iob+BT485_CURS_DATA, bg&0xff );
363
* Oh god, this code is quite a mess ... should be re-written soon.
364
* But for now I'm happy it works ;) <ml>
368
verite_loadcursor(ScrnInfoPtr pScreenInfo, vu8 size, vu8 *cursorimage)
371
vu8 *src = cursorimage;
372
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
373
IOADDRESS iob=pRendition->board.io_base+RAMDACBASEADDR;
375
vu8 memend; /* Added for byte-swap fix */
378
ErrorF ("Rendition: Debug verite_loadcursor called\n");
381
if (NULL == cursorimage)
384
/* Following two lines added for the byte-swap fix */
385
memend = verite_in8(pRendition->board.io_base + MEMENDIAN);
386
verite_out8(pRendition->board.io_base + MEMENDIAN, MEMENDIAN_HW);
393
bytes=(bytes*bytes)>>3;
395
if (pRendition->board.chip == V1000_DEVICE) {
396
/* now load the cursor data into the cursor ram */
398
tmp=verite_in8(iob+BT485_COMMAND_REG_0)&0x7f;
399
verite_out8(iob+BT485_COMMAND_REG_0, tmp|0x80);
401
verite_out8(iob+BT485_WRITE_ADDR, BT485_COMMAND_REG_3);
403
tmp=verite_in8(iob+BT485_STATUS_REG)&0xf8;
404
verite_out8(iob+BT485_STATUS_REG, tmp|(size<<2));
405
verite_out8(iob+BT485_WRITE_ADDR, 0x00);
407
/* output cursor image */
410
/* First plane data */
411
for (c=0; c<bytes; c++) {
412
verite_out8(iob+BT485_CURS_RAM_DATA, *src);
416
/* Second plane data */
418
for (c=0; c<bytes; c++) {
419
verite_out8(iob+BT485_CURS_RAM_DATA, *src);
424
/* V2x00 HW-Cursor, supports only 64x64x2 size */
426
verite_out32(iob+CURSORBASE, pRendition->board.hwcursor_membase);
428
/* First plane data */
429
for (row=0; row<64; row++)
430
for (c=0, src=cursorimage+1+16*row; c<8; c++, src+=2)
431
verite_write_memory8(pRendition->board.vmem_base, 16*(63-row)+c,
432
(c&1)?(*(src-2)):(*(src+2)));
433
/* Second plane data */
434
for (row=0; row<64; row++)
435
for (c=0, src=cursorimage+16*row; c<8; c++, src+=2)
436
verite_write_memory8(pRendition->board.vmem_base, 8+16*(63-row)+c,
437
(c&1)?(*(src-2)):(*(src+2)));
440
/* Following line added for the byte-swap fix */
441
verite_out8(pRendition->board.io_base + MEMENDIAN, memend);
446
/* NOTE: count is the actual number of colors decremented by 1 */
449
verite_setpalette(ScrnInfoPtr pScreenInfo, int numColors, int *indices,
450
LOCO *colors, VisualPtr pVisual)
452
renditionPtr pRendition = RENDITIONPTR(pScreenInfo);
453
IOADDRESS iob=pRendition->board.io_base;
458
ErrorF ("Rendition: Debug verite_setpalette called\n");
462
crtc_status=verite_in32(iob+CRTCSTATUS);
463
if (crtc_status & CRTCSTATUS_VERT_SYNC)
469
for (i = 0; i < numColors; i++) {
471
verite_out8(iob+BT485_WRITE_ADDR, index);
473
verite_out8(iob+BT485_RAMDAC_DATA, colors[index].red);
474
verite_out8(iob+BT485_RAMDAC_DATA, colors[index].green);
475
verite_out8(iob+BT485_RAMDAC_DATA, colors[index].blue);
484
* static void Bt485_write_masked(IOADDRESS port, vu8 reg, vu8 mask, vu8 data)
489
Bt485_write_masked(IOADDRESS port, vu8 reg, vu8 mask, vu8 data)
493
tmp=verite_in8(port+reg)&mask;
494
verite_out8(port+reg, tmp|data);
500
* static void Bt485_write_cmd3_masked(IOADDRESS port, vu8 mask, vu8 data)
505
Bt485_write_cmd3_masked(IOADDRESS port, vu8 mask, vu8 data)
508
* Bt485_write_masked(port, BT485_COMMAND_REG_0, 0x7f, 0x80);
510
verite_out8(port+BT485_WRITE_ADDR, BT485_COMMAND_REG_3);
511
Bt485_write_masked(port, BT485_STATUS_REG, mask, data);
513
* Bt485_write_masked(port, BT485_COMMAND_REG_0, 0x7f, 0x00);
521
* static vu8 Bt485_read_masked(IOADDRESS port, vu8 reg, vu8 mask)
526
Bt485_read_masked(IOADDRESS port, vu8 reg, vu8 mask)
528
return verite_in8(port+reg)&mask;
533
* static vu8 Bt485_read_cmd3_masked(IOADDRESS port, vu8 mask)
538
Bt485_read_cmd3_masked(IOADDRESS port, vu8 mask)
542
Bt485_write_masked(port, BT485_COMMAND_REG_0, 0x7f, 0x80);
543
verite_out8(port+BT485_WRITE_ADDR, BT485_COMMAND_REG_3);
544
value=Bt485_read_masked(port, BT485_STATUS_REG, mask);
545
Bt485_write_masked(port, BT485_COMMAND_REG_0, 0x7f, 0x00);
553
* end of file vramdac.c