1 /* $NetBSD: ga.c,v 1.4 2008/04/28 20:23:18 martin Exp $ */
4 * Copyright (c) 2004, 2005 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 /* Graphic Adaptor (350, 360) */
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: ga.c,v 1.4 2008/04/28 20:23:18 martin Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
41 #include <lib/libsa/stand.h>
42 #include <lib/libkern/libkern.h>
46 #include <uvm/uvm_extern.h>
47 #include <machine/vmparam.h>
49 #include <machine/gareg.h>
50 #include <machine/gavar.h>
52 bool ga_map(struct ga
*);
53 void ga_clut_init(struct ga
*);
54 void ga_vblank_start(const struct ga
*);
55 void ga_bt463_reg(const struct ga
*, int);
56 void ga_bt463_data(const struct ga
*, int);
57 void ga_bt463_reg_data(const struct ga
*, int, int);
59 void ga_dda_busy(const struct ga
*);
60 void ga_ovl_init(const struct ga
*);
61 void ga_id_init(const struct ga
*);
62 void ga_block_clear(const struct ga
*);
63 void ga_plane_mask_test(const struct ga
*);
66 #define ga_reg_write(ga, ofs, val) \
67 (*(volatile uint32_t *)((ga)->reg_addr + (ofs)) = (val))
68 #define ga_reg_read(ga, ofs) \
69 (*(volatile uint32_t *)((ga)->reg_addr + (ofs)))
72 ga_init(struct ga
*ga
)
76 /* Map GA register and buffers */
77 if (ga
->reg_addr
== 0 && ga_map(ga
) != 0)
80 /* This is 350 GA-ROM initialization sequence. */
81 if (ga
->flags
== 0x0000) {
82 ga_bt463_reg_data(ga
, 0x201, 0x40);
83 ga_bt463_reg_data(ga
, 0x202, 0x40);
84 ga_bt463_reg_data(ga
, 0x203,
85 ((ga_reg_read(ga
, 0xe00) & 2) << 6) | 0x40);
86 } else if (ga
->flags
== 0x0001) {
87 ga_bt463_reg_data(ga
, 0x201, 0x40);
88 ga_bt463_reg_data(ga
, 0x202, 0);
89 ga_bt463_reg_data(ga
, 0x203,
90 ((ga_reg_read(ga
, 0xe00) & 2) << 6) | 0x40);
91 ga_bt463_reg_data(ga
, 0x204, 0xff); /* Display ON/OFF ? */
92 ga_bt463_reg_data(ga
, 0x206, 0);
93 ga_bt463_reg_data(ga
, 0x20a, 0);
96 /* Window type table */
97 ga_bt463_reg(ga
, 0x300);
98 for (i
= 0; i
< 16; i
++) {
99 ga_bt463_data(ga
, 0x00);
100 ga_bt463_data(ga
, 0xe1);
101 ga_bt463_data(ga
, 0x01);
107 ga_bt463_reg(ga
, 0x302);
108 for (i
= 0; i
< 2; i
++) {
109 ga_bt463_data(ga
, 0x00);
110 ga_bt463_data(ga
, 0xe3);
111 ga_bt463_data(ga
, 0x21);
114 /* Read mask P0-P7 */
115 if (ga
->flags
!= 0x0001) {
116 /* TR2A display blinks if this was done.. */
117 ga_bt463_reg(ga
, 0x205);
118 for (i
= 0; i
< 4; i
++)
119 ga_bt463_data(ga
, 0xff);
122 /* Blink mask P0-P7 */
123 ga_bt463_reg(ga
, 0x209);
124 for (i
= 0; i
< 4; i
++)
125 ga_bt463_data(ga
, 0x00);
130 ga_bt463_reg(ga
, 0x200);
131 for (i
= 0; i
< 0xff; i
++) {
132 ga_reg_write(ga
, 0xc8c, 0);
133 ga_reg_write(ga
, 0xc8c, 0);
134 ga_reg_write(ga
, 0xc8c, 0);
137 if (ga_reg_read(ga
, 0xe00) & 2)
138 ga_reg_write(ga
, 0xe08, 0x790); /* 71Hz */
140 ga_reg_write(ga
, 0xe08, 0x670); /* 60Hz */
146 /* Cursor RAM clear */
147 ga_reg_write(ga
, 0xc90, 0);
148 ga_reg_write(ga
, 0xc94, 0);
149 ga_reg_write(ga
, 0xca0, 0);
150 ga_reg_write(ga
, 0xca4, 0);
151 for (i
= 0; i
< 512; i
++) {
152 ga_reg_write(ga
, 0xc98, 0);
153 ga_reg_write(ga
, 0xca8, 0);
160 ga_map(struct ga
*ga
)
163 /* IPL maps register region using 16Mpage */
164 ga
->reg_addr
= GA_REG_ADDR
;
170 pa
= (paddr_t
)GA_REG_ADDR
;
171 epa
= pa
+ GA_REG_SIZE
;
173 if (!(va
= uvm_km_alloc(kernel_map
, epa
- pa
, 0, UVM_KMF_VAONLY
))) {
174 printf("can't map GA register.\n");
178 for (tva
= va
; pa
< epa
; pa
+= PAGE_SIZE
, tva
+= PAGE_SIZE
)
179 pmap_kenter_pa(tva
, pa
, VM_PROT_READ
| VM_PROT_WRITE
, 0);
181 pmap_update(pmap_kernel());
183 ga
->reg_addr
= (uint32_t)va
;
190 ga_vblank_start(const struct ga
*ga
)
193 while ((ga_reg_read(ga
, 0xe00) & 0x1) == 0) /* V-blank */
195 while ((ga_reg_read(ga
, 0xe00) & 0x1) == 1)
202 ga_bt463_reg(const struct ga
*ga
, int r
)
205 ga_reg_write(ga
, 0xc80, r
& 0xff);
206 ga_reg_write(ga
, 0xc84, (r
>> 8) & 0xff);
210 ga_bt463_data(const struct ga
*ga
, int v
)
213 ga_reg_write(ga
, 0xc88, v
& 0xff);
217 ga_bt463_reg_data(const struct ga
*ga
, int r
, int v
)
221 ga_bt463_data(ga
, v
);
226 ga_clut_init(struct ga
*ga
)
228 const uint8_t compo6
[6] = { 0, 51, 102, 153, 204, 255 };
229 const uint8_t ansi_color
[16][3] = {
230 { 0x00, 0x00, 0x00 },
231 { 0xff, 0x00, 0x00 },
232 { 0x00, 0xff, 0x00 },
233 { 0xff, 0xff, 0x00 },
234 { 0x00, 0x00, 0xff },
235 { 0xff, 0x00, 0xff },
236 { 0x00, 0xff, 0xff },
237 { 0xff, 0xff, 0xff },
238 { 0x00, 0x00, 0x00 },
239 { 0x80, 0x00, 0x00 },
240 { 0x00, 0x80, 0x00 },
241 { 0x80, 0x80, 0x00 },
242 { 0x00, 0x00, 0x80 },
243 { 0x80, 0x00, 0x80 },
244 { 0x00, 0x80, 0x80 },
245 { 0x80, 0x80, 0x80 },
250 /* ANSI escape sequence */
251 for (i
= 0; i
< 16; i
++) {
252 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][0] = ansi_color
[i
][0]);
253 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][1] = ansi_color
[i
][1]);
254 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][2] = ansi_color
[i
][2]);
257 /* 16 - 31, gray scale */
258 for ( ; i
< 32; i
++) {
260 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][0] = j
);
261 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][1] = j
);
262 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][2] = j
);
265 /* 32 - 247, RGB color */
266 for (r
= 0; r
< 6; r
++) {
267 for (g
= 0; g
< 6; g
++) {
268 for (b
= 0; b
< 6; b
++, i
++) {
269 ga_reg_write(ga
, 0xc8c,
270 ga
->clut
[i
][0] = compo6
[r
]);
271 ga_reg_write(ga
, 0xc8c,
272 ga
->clut
[i
][1] = compo6
[g
]);
273 ga_reg_write(ga
, 0xc8c,
274 ga
->clut
[i
][2] = compo6
[b
]);
279 /* 248 - 256, white */
280 for ( ; i
< 256; i
++) {
281 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][0] = 0xff);
282 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][1] = 0xff);
283 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][2] = 0xff);
286 /* 257 - 528, black */
287 for ( ; i
< 528; i
++) {
288 ga_reg_write(ga
, 0xc8c, 0);
289 ga_reg_write(ga
, 0xc8c, 0);
290 ga_reg_write(ga
, 0xc8c, 0);
295 ga_clut_get(struct ga
*ga
)
300 for (i
= 0; i
< 256; i
++) {
301 ga
->clut
[i
][0] = ga_reg_read(ga
, 0xc8c);
302 ga
->clut
[i
][1] = ga_reg_read(ga
, 0xc8c);
303 ga
->clut
[i
][2] = ga_reg_read(ga
, 0xc8c);
308 ga_clut_set(const struct ga
*ga
)
313 for (i
= 0; i
< 256; i
++) {
314 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][0]);
315 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][1]);
316 ga_reg_write(ga
, 0xc8c, ga
->clut
[i
][2]);
320 /* Not yet analyzed. */
323 ga_dda_busy(const struct ga
*ga
)
326 while ((ga_reg_read(ga
, 0xf00) & 0x8000) == 0)
331 ga_ovl_init(const struct ga
*ga
)
335 ga_reg_write(ga
, 0x400, 0xffffffff);
336 p0
= (uint32_t *)0xf2000000;
337 p1
= (uint32_t *)0xf2200000;
343 ga_id_init(const struct ga
*ga
)
347 p0
= (uint32_t *)0xf3000000;
348 p1
= (uint32_t *)0xf3040000;
354 ga_block_clear(const struct ga
*ga
)
358 ga_reg_write(ga
, 0xe80, 0);
359 ga_reg_write(ga
, 0x400, 0xffffff);
361 p0
= (uint32_t *)0xf0c00000;
362 p1
= (uint32_t *)0xf0c80000;
368 ga_plane_mask_test(const struct ga
*ga
)
372 ga_reg_write(ga
, 0x400, 0xffffff);
373 *(volatile uint32_t *)0xf1000000 = 0;
375 ga_reg_write(ga
, 0x400, 0xaaaaaa);
376 *(volatile uint32_t *)0xf1000000 = 0xffffff;
378 if ((*(volatile uint32_t *)0xf1000000 & 0xffffff) != 0xaaaaaa)
380 ga_reg_write(ga
, 0x400, 0xffffff);
381 *(volatile uint32_t *)0xf1000000 = 0;
384 *(volatile uint32_t *)0xf1080008 = 0;
385 ga_reg_write(ga
, 0x400, 0x555555);
386 *(volatile uint32_t *)0xf1080008 = 0xffffff;
387 if ((*(volatile uint32_t *)0xf1080008 & 0xffffff) != 0x555555)
389 ga_reg_write(ga
, 0x400, 0xffffff);
390 *(volatile uint32_t *)0xf1080008 = 0;
392 *(volatile uint32_t *)0xf1100000 = 0;
393 *(volatile uint32_t *)0xf1100000 = 0xffffff;
394 if ((*(volatile uint32_t *)0xf1100000 & 0xffffff) != 0xffffff)
397 ga_reg_write(ga
, 0x400, 0xaaaaaa);
398 *(volatile uint32_t *)0xf1100000 = 0;
399 if ((*(volatile uint32_t *)0xf1100000 & 0xffffff) != 0x555555)
402 ga_reg_write(ga
, 0x400, 0);
403 *(volatile uint32_t *)0xf1100000 = 0xffffff;
404 if ((*(volatile uint32_t *)0xf1100000 & 0xffffff) != 0x555555)
407 ga_reg_write(ga
, 0x400, 0xffffff);
408 *(volatile uint32_t *)0xf1100000 = 0;
410 ga_reg_write(ga
, 0xe80, 0xffffff);
411 ga_reg_write(ga
, 0x400, 0xffffff);
412 *(volatile uint32_t *)0xf0c00000 = 0xffffffff;
413 for (i
= 0; i
< 32; i
++)
414 if ((*(volatile uint32_t *)(0xf1000000 + i
* 4) & 0xffffff) !=
418 ga_reg_write(ga
, 0xe80, 0);
419 ga_reg_write(ga
, 0x400, 0xaaaaaa);
420 *(volatile uint32_t *)0xf0c00000 = 0xffffffff;
421 for (i
= 0; i
< 32; i
++)
422 if ((*(volatile uint32_t *)(0xf1000000 + i
* 4) & 0xffffff) !=
425 ga_reg_write(ga
, 0x400, 0x555555);
426 *(volatile uint32_t *)0xf0c00000 = 0xffffffff;
427 for (i
= 0; i
< 32; i
++)
428 if ((*(volatile uint32_t *)(0xf1000000 + i
* 4) & 0xffffff) !=
437 #endif /* _STANDALONE */