1 /* $NetBSD: grf_cv3d.c,v 1.24 2009/03/18 17:06:42 cegger Exp $ */
4 * Copyright (c) 1995 Michael Teske
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Ezra Story, by Kari
18 * Mettinen, and Michael Teske.
19 * 4. The name of the author may not be used to endorse or promote products
20 * derived from this software without specific prior written permission
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "opt_amigacons.h"
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: grf_cv3d.c,v 1.24 2009/03/18 17:06:42 cegger Exp $");
42 * Graphics routines for the CyberVision 64/3D board, using the S3 ViRGE.
44 * Modified for CV64/3D from Michael Teske's CV driver by Tobias Abt 10/97.
45 * Bugfixes by Bernd Ernesti 10/97.
46 * Many thanks to Richard Hartmann who gave us his board so we could make
52 * - Memcheck for 2MB boards (if they exists)
55 /* Thanks to Frank Mariak for these infos
57 +0x4000000 Memorybase start
58 +0x4ffffff Memorybase end
59 +0x5000000 Img TransPort start
60 +0x5007fff Img TransPort end
61 +0x5008000 MMIO Regbase start
62 +0x500ffff MMIO Regbase end
63 +0x5800000 Img TransPort (rot) start
64 +0x5807fff Img TransPort (rot) end
65 +0x7000000 Img TransPort (rot) start
66 +0x7007fff Img TransPort (rot) end
67 +0x8000000 VCodeSwitch start
68 +0x8000fff VCodeSwitch end
69 +0xc000000 IO Regbase start
70 +0xc00ffff IO Regbase end
71 +0xc0e0000 PCI Cfg Base start
72 +0xc0e0fff PCI Cfg Base end
74 Note: IO Regbase is needed fo wakeup of the board otherwise use
78 #include <sys/param.h>
79 #include <sys/errno.h>
80 #include <sys/ioctl.h>
81 #include <sys/device.h>
82 #include <sys/malloc.h>
83 #include <sys/systm.h>
84 #include <machine/cpu.h>
86 #include <amiga/dev/itevar.h>
87 #include <amiga/amiga/device.h>
88 #include <amiga/dev/grfioctl.h>
89 #include <amiga/dev/grfvar.h>
90 #include <amiga/dev/grf_cv3dreg.h>
91 #include <amiga/dev/zbusvar.h>
94 * finish all bus operations, flush pipelines
97 #define cpu_sync() __asm volatile ("nop")
98 #elif defined(__powerpc__)
99 #define cpu_sync() __asm volatile ("sync; isync")
102 int grfcv3dmatch(struct device
*, struct cfdata
*, void *);
103 void grfcv3dattach(struct device
*, struct device
*, void *);
104 int grfcv3dprint(void *, const char *);
106 static int cv3d_has_4mb(volatile void *);
107 static unsigned short cv3d_compute_clock(unsigned long);
108 void cv3d_boardinit(struct grf_softc
*);
109 int cv3d_getvmode(struct grf_softc
*, struct grfvideo_mode
*);
110 int cv3d_setvmode(struct grf_softc
*, unsigned int);
111 int cv3d_blank(struct grf_softc
*, int *);
112 int cv3d_mode(register struct grf_softc
*, u_long
, void *, u_long
, int);
113 int cv3d_ioctl(register struct grf_softc
*gp
, u_long cmd
, void *data
);
114 int cv3d_setmonitor(struct grf_softc
*, struct grfvideo_mode
*);
115 int cv3d_getcmap(struct grf_softc
*, struct grf_colormap
*);
116 int cv3d_putcmap(struct grf_softc
*, struct grf_colormap
*);
117 int cv3d_toggle(struct grf_softc
*);
118 int cv3d_mondefok(struct grfvideo_mode
*);
119 int cv3d_load_mon(struct grf_softc
*, struct grfcv3dtext_mode
*);
120 void cv3d_inittextmode(struct grf_softc
*);
121 static inline void cv3dscreen(int, volatile void *);
122 static inline void cv3d_gfx_on_off(int, volatile void *);
124 #ifdef CV3D_HARDWARE_CURSOR
125 int cv3d_getspritepos(struct grf_softc
*, struct grf_position
*);
126 int cv3d_setspritepos(struct grf_softc
*, struct grf_position
*);
127 int cv3d_getspriteinfo(struct grf_softc
*,struct grf_spriteinfo
*);
128 void cv3d_setup_hwc(struct grf_softc
*);
129 int cv3d_setspriteinfo(struct grf_softc
*,struct grf_spriteinfo
*);
130 int cv3d_getspritemax(struct grf_softc
*,struct grf_position
*);
131 #endif /* CV3D_HARDWARE_CURSOR */
133 /* Graphics display definitions.
134 * These are filled by 'grfconfig' using GRFIOCSETMON.
136 #define monitor_def_max 24
137 static struct grfvideo_mode monitor_def
[24] = {
138 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
139 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
140 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}
142 static struct grfvideo_mode
*monitor_current
= &monitor_def
[0];
143 #define MAXPIXELCLOCK 135000000 /* safety */
145 int cv3d_zorroIII
= 0; /* CV64/3D in ZorroII or ZorroIII mode */
146 unsigned char cv3d_pass_toggle
; /* passthru status tracker */
148 /* Console display definition.
149 * Default hardcoded text mode. This grf_cv3d is set up to
150 * use one text mode only, and this is it. You may use
151 * grfconfig to change the mode after boot.
156 #define S3FONT kernel_font_8x11
159 #define S3FONT kernel_font_8x8
162 extern unsigned char S3FONT
[];
165 * Define default console mode
166 * (Internally, we still have to use hvalues/8!)
168 struct grfcv3dtext_mode cv3dconsole_mode
= {
169 {255, "", 25000000, 640, 480, 4, 640/8, 680/8, 768/8, 800/8,
170 481, 491, 493, 525, 0},
171 8, S3FONTY
, 80, 480 / S3FONTY
, S3FONT
, 32, 255
175 unsigned char cv3dconscolors
[16][3] = { /* background, foreground, hilite */
195 static unsigned char clocks
[]={
196 0x13, 0x61, 0x6b, 0x6d, 0x51, 0x69, 0x54, 0x69,
197 0x4f, 0x68, 0x6b, 0x6b, 0x18, 0x61, 0x7b, 0x6c,
198 0x51, 0x67, 0x24, 0x62, 0x56, 0x67, 0x77, 0x6a,
199 0x1d, 0x61, 0x53, 0x66, 0x6b, 0x68, 0x79, 0x69,
200 0x7c, 0x69, 0x7f, 0x69, 0x22, 0x61, 0x54, 0x65,
201 0x56, 0x65, 0x58, 0x65, 0x67, 0x66, 0x41, 0x63,
202 0x27, 0x61, 0x13, 0x41, 0x37, 0x62, 0x6b, 0x4d,
203 0x23, 0x43, 0x51, 0x49, 0x79, 0x66, 0x54, 0x49,
204 0x7d, 0x66, 0x34, 0x56, 0x4f, 0x63, 0x1f, 0x42,
205 0x6b, 0x4b, 0x7e, 0x4d, 0x18, 0x41, 0x2a, 0x43,
206 0x7b, 0x4c, 0x74, 0x4b, 0x51, 0x47, 0x65, 0x49,
207 0x24, 0x42, 0x68, 0x49, 0x56, 0x47, 0x75, 0x4a,
208 0x77, 0x4a, 0x31, 0x43, 0x1d, 0x41, 0x71, 0x49,
209 0x53, 0x46, 0x29, 0x42, 0x6b, 0x48, 0x1f, 0x41,
210 0x79, 0x49, 0x6f, 0x48, 0x7c, 0x49, 0x38, 0x43,
211 0x7f, 0x49, 0x5d, 0x46, 0x22, 0x41, 0x53, 0x45,
212 0x54, 0x45, 0x55, 0x45, 0x56, 0x45, 0x57, 0x45,
213 0x58, 0x45, 0x25, 0x41, 0x67, 0x46, 0x5b, 0x45,
214 0x41, 0x43, 0x78, 0x47, 0x27, 0x41, 0x51, 0x44,
215 0x13, 0x21, 0x7d, 0x47, 0x37, 0x42, 0x71, 0x46,
216 0x6b, 0x2d, 0x14, 0x21, 0x23, 0x23, 0x7d, 0x2f,
217 0x51, 0x29, 0x61, 0x2b, 0x79, 0x46, 0x1d, 0x22,
218 0x54, 0x29, 0x45, 0x27, 0x7d, 0x46, 0x7f, 0x46,
219 0x4f, 0x43, 0x2f, 0x41, 0x1f, 0x22, 0x6a, 0x2b,
220 0x6b, 0x2b, 0x5b, 0x29, 0x7e, 0x2d, 0x65, 0x44,
221 0x18, 0x21, 0x5e, 0x29, 0x2a, 0x23, 0x45, 0x26,
222 0x7b, 0x2c, 0x19, 0x21, 0x74, 0x2b, 0x75, 0x2b,
223 0x51, 0x27, 0x3f, 0x25, 0x65, 0x29, 0x40, 0x25,
224 0x24, 0x22, 0x41, 0x25, 0x68, 0x29, 0x42, 0x25,
225 0x56, 0x27, 0x7e, 0x2b, 0x75, 0x2a, 0x1c, 0x21,
226 0x77, 0x2a, 0x4f, 0x26, 0x31, 0x23, 0x6f, 0x29,
227 0x1d, 0x21, 0x32, 0x23, 0x71, 0x29, 0x72, 0x29,
228 0x53, 0x26, 0x69, 0x28, 0x29, 0x22, 0x75, 0x29,
229 0x6b, 0x28, 0x1f, 0x21, 0x1f, 0x21, 0x6d, 0x28,
230 0x79, 0x29, 0x2b, 0x22, 0x6f, 0x28, 0x59, 0x26,
231 0x7c, 0x29, 0x7d, 0x29, 0x38, 0x23, 0x21, 0x21,
232 0x7f, 0x29, 0x39, 0x23, 0x5d, 0x26, 0x75, 0x28,
233 0x22, 0x21, 0x77, 0x28, 0x53, 0x25, 0x6c, 0x27,
234 0x54, 0x25, 0x61, 0x26, 0x55, 0x25, 0x30, 0x22,
235 0x56, 0x25, 0x63, 0x26, 0x57, 0x25, 0x71, 0x27,
236 0x58, 0x25, 0x7f, 0x28, 0x25, 0x21, 0x74, 0x27,
237 0x67, 0x26, 0x40, 0x23, 0x5b, 0x25, 0x26, 0x21,
238 0x41, 0x23, 0x34, 0x22, 0x78, 0x27, 0x6b, 0x26,
239 0x27, 0x21, 0x35, 0x22, 0x51, 0x24, 0x7b, 0x27,
240 0x13, 0x1, 0x13, 0x1, 0x7d, 0x27, 0x4c, 0x9,
241 0x37, 0x22, 0x5b, 0xb, 0x71, 0x26, 0x5c, 0xb,
242 0x6b, 0xd, 0x47, 0x23, 0x14, 0x1, 0x4f, 0x9,
243 0x23, 0x3, 0x75, 0x26, 0x7d, 0xf, 0x1c, 0x2,
244 0x51, 0x9, 0x59, 0x24, 0x61, 0xb, 0x69, 0x25,
245 0x79, 0x26, 0x34, 0x5, 0x1d, 0x2, 0x6b, 0x25,
246 0x54, 0x9, 0x35, 0x5, 0x45, 0x7, 0x6d, 0x25,
247 0x7d, 0x26, 0x16, 0x1, 0x7f, 0x26, 0x77, 0xd,
248 0x4f, 0x23, 0x78, 0xd, 0x2f, 0x21, 0x27, 0x3,
249 0x1f, 0x2, 0x59, 0x9, 0x6a, 0xb, 0x73, 0x25,
250 0x6b, 0xb, 0x63, 0x24, 0x5b, 0x9, 0x20, 0x2,
251 0x7e, 0xd, 0x4b, 0x7, 0x65, 0x24, 0x43, 0x22,
252 0x18, 0x1, 0x6f, 0xb, 0x5e, 0x9, 0x70, 0xb,
253 0x2a, 0x3, 0x33, 0x4, 0x45, 0x6, 0x60, 0x9,
254 0x7b, 0xc, 0x19, 0x1, 0x19, 0x1, 0x7d, 0xc,
255 0x74, 0xb, 0x50, 0x7, 0x75, 0xb, 0x63, 0x9,
256 0x51, 0x7, 0x23, 0x2, 0x3f, 0x5, 0x1a, 0x1,
257 0x65, 0x9, 0x2d, 0x3, 0x40, 0x5, 0x0, 0x0,
261 /* Board Address of CV64/3D */
262 static volatile void *cv3d_boardaddr
;
263 static int cv3d_fbsize
;
265 static volatile void *cv3d_memory_io_base
;
266 static volatile void *cv3d_register_base
;
267 static volatile void *cv3d_vcode_switch_base
;
268 static volatile void *cv3d_special_register_base
;
271 * Memory clock (binpatchable).
273 long cv3d_memclk
= 55000000;
275 /* standard driver stuff */
276 CFATTACH_DECL(grfcv3d
, sizeof(struct grf_softc
),
277 grfcv3dmatch
, grfcv3dattach
, NULL
, NULL
);
279 static struct cfdata
*cfdata
;
281 #define CV3D_ULCURSOR 1 /* Underlined Cursor in textmode */
284 * Get frambuffer memory size.
285 * phase5 didn't provide the bit in CR36,
286 * so we have to do it this way.
287 * Return 0 for 2MB, 1 for 4MB
290 cv3d_has_4mb(volatile void *fb
)
293 volatile unsigned long *testfbw
, *testfbr
;
295 /* write patterns in memory and test if they can be read */
296 testfbw
= (volatile unsigned long *)fb
;
297 testfbr
= (volatile unsigned long *)(fb
+ 0x02000000);
298 *testfbw
= 0x87654321;
299 if (*testfbr
!= 0x87654321)
302 /* upper memory region */
303 testfbw
= (volatile unsigned long *)(fb
+ 0x00200000);
304 testfbr
= (volatile unsigned long *)(fb
+ 0x02200000);
305 *testfbw
= 0x87654321;
306 if (*testfbr
!= 0x87654321)
308 *testfbw
= 0xAAAAAAAA;
309 if (*testfbr
!= 0xAAAAAAAA)
311 *testfbw
= 0x55555555;
312 if (*testfbr
!= 0x55555555)
319 grfcv3dmatch(struct device
*pdp
, struct cfdata
*cfp
, void *auxp
)
322 static int cv3dcons_unit
= -1;
324 struct zbus_args
*zap
;
328 if (amiga_realconfig
== 0)
330 if (cv3dcons_unit
!= -1)
335 * Distinct between ZorroII or ZorroIII mode.
336 * Note that iszthreepa(x) is true for the Z2 bus on the DraCo;
337 * therefore we check for the size instead.
339 cv3d_zorroIII
= zap
->size
> 4*1024*1024;
341 /* Lets be Paranoid: Test man and prod id */
342 if (zap
->manid
!= 8512 || zap
->prodid
!= 67)
346 if (!cv3d_zorroIII
) {
351 cv3d_boardaddr
= zap
->va
;
354 if (amiga_realconfig
== 0) {
355 cv3dcons_unit
= cfp
->cf_unit
;
364 grfcv3dattach(struct device
*pdp
, struct device
*dp
, void *auxp
)
366 static struct grf_softc congrf
;
367 struct zbus_args
*zap
;
368 struct grf_softc
*gp
;
369 static char attachflag
= 0;
376 * This function is called twice, once on console init (dp == NULL)
377 * and once on "normal" grf7 init.
380 if (dp
== NULL
) /* console init */
383 gp
= (struct grf_softc
*)dp
;
385 if (dp
!= NULL
&& congrf
.g_regkva
!= 0) {
387 * inited earlier, just copy (not device struct)
390 memcpy(&gp
->g_display
, &congrf
.g_display
,
391 (char *) &gp
[1] - (char *) &gp
->g_display
);
395 (volatile char *)cv3d_boardaddr
+ 0x04800000;
396 cv3d_memory_io_base
=
397 (volatile char *)cv3d_boardaddr
+ 0x05000000;
399 (volatile char *)cv3d_boardaddr
+ 0x05008000;
400 cv3d_vcode_switch_base
=
401 (volatile char *)cv3d_boardaddr
+ 0x08000000;
402 cv3d_special_register_base
=
403 (volatile char *)cv3d_boardaddr
+ 0x0C000000;
406 (volatile char *)cv3d_boardaddr
+ 0x00000000;
407 cv3d_memory_io_base
=
408 (volatile char *)cv3d_boardaddr
+ 0x003E0000;
410 (volatile char *)cv3d_boardaddr
+ 0x003C8000;
411 cv3d_vcode_switch_base
=
412 (volatile char *)cv3d_boardaddr
+ 0x003A0000;
413 cv3d_special_register_base
=
414 (volatile char *)cv3d_boardaddr
+ 0x003C0000;
417 gp
->g_regkva
= (volatile void *)cv3d_register_base
;
419 gp
->g_unit
= GRF_CV3D_UNIT
;
420 gp
->g_mode
= cv3d_mode
;
421 gp
->g_conpri
= grfcv3d_cnprobe();
422 gp
->g_flags
= GF_ALIVE
;
424 /* wakeup the board */
429 (void)cv3d_load_mon(gp
, &cv3dconsole_mode
);
436 if (amiga_config_found(cfdata
, &gp
->g_device
, gp
, grfcv3dprint
)) {
438 printf("%s: CyberVision64/3D with %dMB being used\n",
439 dp
->dv_xname
, cv3d_fbsize
/ 0x100000);
443 /*printf("grfcv3d unattached!!\n")*/;
448 grfcv3dprint(void *auxp
, const char *pnp
)
451 aprint_normal("ite at %s: ", pnp
);
457 * Computes M, N, and R values from
458 * given input frequency. It uses a table of
459 * precomputed values, to keep CPU time low.
461 * The return value consist of:
462 * lower byte: Bits 4-0: N Divider Value
463 * Bits 5-6: R Value for e.g. SR10 or SR12
464 * higher byte: Bits 0-6: M divider value for e.g. SR11 or SR13
467 static unsigned short
468 cv3d_compute_clock(unsigned long freq
)
470 static unsigned char *mnr
, *save
; /* M, N + R vals */
471 unsigned long work_freq
, r
;
475 if (freq
< 12500000 || freq
> MAXPIXELCLOCK
) {
476 printf("grfcv3d: Illegal clock frequency: %ldMHz\n", freq
/1000000);
477 printf("grfcv3d: Using default frequency: 25MHz\n");
478 printf("grfcv3d: See the manpage of grfconfig for more informations.\n");
482 mnr
= clocks
; /* there the vals are stored */
485 while (*mnr
) { /* mnr vals are 0-terminated */
486 work_freq
= (0x37EE * (mnr
[0] + 2)) / ((mnr
[1] & 0x1F) + 2);
488 r
= (mnr
[1] >> 5) & 0x03;
490 work_freq
=work_freq
>> r
; /* r is the freq divider */
492 work_freq
*= 0x3E8; /* 2nd part of OSC */
494 diff
= abs(freq
- work_freq
);
498 /* In save are the vals for minimal diff */
503 erg
= *((unsigned short *)save
);
510 cv3d_boardinit(struct grf_softc
*gp
)
513 volatile char *special
;
515 unsigned int clockpar
;
523 special
= ((volatile char*)cv3d_special_register_base
+
526 special
= ((volatile char*)cv3d_special_register_base
);
528 *((volatile short *)(special
+ 0x10)) = 0;
529 *((volatile long *)(special
+ 0x4)) = 0x02000003;
532 vgawio(cv3d_boardaddr
, SREG_VIDEO_SUBS_ENABLE
, 1);
534 vgaw(ba
, SREG_VIDEO_SUBS_ENABLE
, 0x01);
536 vgaw(ba
, GREG_MISC_OUTPUT_W
, 0x03);
538 WCrt(ba
, CRT_ID_REGISTER_LOCK_1
, 0x48); /* unlock S3 VGA regs */
539 WCrt(ba
, CRT_ID_REGISTER_LOCK_2
, 0xA5); /* unlock syscontrol */
541 WCrt(ba
, CRT_ID_EXT_MISC_CNTL_1
, 0x02);
542 WCrt(ba
, CRT_ID_EXT_MISC_CNTL_1
, 0x00);
544 WSeq(ba
, SEQ_ID_UNLOCK_EXT
, 0x06); /* Unlock extensions */
547 * bit 0=1: enable enhanced mode functions
548 * bit 4=1: enable linear addressing
550 vgaw32(cv3d_memory_io_base
, MR_ADVANCED_FUNCTION_CONTROL
, 0x00000011);
552 /* -hsync and -vsync */
553 vgaw(ba
, GREG_MISC_OUTPUT_W
, 0xC3);
555 /* Reset. This does nothing, but everyone does it:) */
556 WSeq(ba
, SEQ_ID_RESET
, 0x03);
558 WSeq(ba
, SEQ_ID_CLOCKING_MODE
, 0x01); /* 8 Dot Clock */
559 WSeq(ba
, SEQ_ID_MAP_MASK
, 0x0F); /* Enable write planes */
560 WSeq(ba
, SEQ_ID_CHAR_MAP_SELECT
, 0x00); /* Character Font */
562 WSeq(ba
, SEQ_ID_MEMORY_MODE
, 0x02); /* Complete mem access */
563 WSeq(ba
, SEQ_ID_MMIO_SELECT
, 0x00);
565 test
= RSeq(ba
, SEQ_ID_BUS_REQ_CNTL
); /* Bus Request */
567 /* enable 4MB fast Page Mode */
569 WSeq(ba
, SEQ_ID_BUS_REQ_CNTL
, test
);
572 /* faster LUT write */
573 WSeq(ba
, SEQ_ID_RAMDAC_CNTL
, 0xC0);
575 WSeq(ba
, SEQ_ID_UNKNOWN6
, 0x00);
576 WSeq(ba
, SEQ_ID_SIGNAL_SELECT
, 0x02);
579 test
= RSeq(ba
, SEQ_ID_CLKSYN_CNTL_2
); /* Clksyn2 read */
581 /* immediately Clkload bit clear */
584 /* 2 MCLK Memory Write.... */
585 if (cv3d_memclk
>= 55000000)
588 WSeq(ba
, SEQ_ID_CLKSYN_CNTL_2
, test
);
591 clockpar
= cv3d_compute_clock(cv3d_memclk
);
592 test
= (clockpar
& 0xFF00) >> 8;
593 WSeq(ba
, SEQ_ID_MCLK_HI
, test
); /* PLL N-Divider Value */
595 test
= clockpar
& 0xFF;
596 WSeq(ba
, SEQ_ID_MCLK_LO
, test
); /* PLL M-Divider Value */
598 /* We now load an 25 MHz, 31 kHz, 640x480 standard VGA Mode. */
600 WSeq(ba
, SEQ_ID_DCLK_HI
, 0x13);
601 WSeq(ba
, SEQ_ID_DCLK_LO
, 0x41);
603 test
= RSeq (ba
, SEQ_ID_CLKSYN_CNTL_2
);
606 /* DCLK + MCLK Clock immediate load! */
607 WSeq(ba
,SEQ_ID_CLKSYN_CNTL_2
, test
);
610 test
= vgar(ba
, 0x3cc);
612 vgaw(ba
, 0x3c2, test
);
614 /* Clear bit 5 again, prevent further loading. */
615 WSeq(ba
, SEQ_ID_CLKSYN_CNTL_2
, 0x02);
617 WCrt(ba
, CRT_ID_HOR_TOTAL
, 0x5F);
618 WCrt(ba
, CRT_ID_HOR_DISP_ENA_END
, 0x4F);
619 WCrt(ba
, CRT_ID_START_HOR_BLANK
, 0x50);
620 WCrt(ba
, CRT_ID_END_HOR_BLANK
, 0x82);
621 WCrt(ba
, CRT_ID_START_HOR_RETR
, 0x54);
622 WCrt(ba
, CRT_ID_END_HOR_RETR
, 0x80);
623 WCrt(ba
, CRT_ID_VER_TOTAL
, 0xBF);
625 WCrt(ba
, CRT_ID_OVERFLOW
, 0x1F); /* overflow reg */
627 WCrt(ba
, CRT_ID_PRESET_ROW_SCAN
, 0x00); /* no panning */
629 WCrt(ba
, CRT_ID_MAX_SCAN_LINE
, 0x40); /* vscan */
631 WCrt(ba
, CRT_ID_CURSOR_START
, 0x00);
632 WCrt(ba
, CRT_ID_CURSOR_END
, 0x00);
634 /* Display start address */
635 WCrt(ba
, CRT_ID_START_ADDR_HIGH
, 0x00);
636 WCrt(ba
, CRT_ID_START_ADDR_LOW
, 0x00);
638 /* Cursor location */
639 WCrt(ba
, CRT_ID_CURSOR_LOC_HIGH
, 0x00);
640 WCrt(ba
, CRT_ID_CURSOR_LOC_LOW
, 0x00);
642 /* Vertical retrace */
643 WCrt(ba
, CRT_ID_START_VER_RETR
, 0x9C);
644 WCrt(ba
, CRT_ID_END_VER_RETR
, 0x0E);
646 WCrt(ba
, CRT_ID_VER_DISP_ENA_END
, 0x8F);
647 WCrt(ba
, CRT_ID_SCREEN_OFFSET
, 0x50);
649 WCrt(ba
, CRT_ID_UNDERLINE_LOC
, 0x00);
651 WCrt(ba
, CRT_ID_START_VER_BLANK
, 0x96);
652 WCrt(ba
, CRT_ID_END_VER_BLANK
, 0xB9);
654 WCrt(ba
, CRT_ID_MODE_CONTROL
, 0xE3);
656 WCrt(ba
, CRT_ID_LINE_COMPARE
, 0xFF);
658 WCrt(ba
, CRT_ID_SYSTEM_CONFIG
, 0x21);
659 WCrt(ba
, CRT_ID_MEMORY_CONF
, 0x04);
660 WCrt(ba
, CRT_ID_BACKWAD_COMP_1
, 0x00);
661 WCrt(ba
, CRT_ID_BACKWAD_COMP_2
, 0x02);
662 WCrt(ba
, CRT_ID_BACKWAD_COMP_3
, 0x10); /* FIFO enabled */
664 /* Refresh count 1, High speed text font, enhanced color mode */
665 WCrt(ba
, CRT_ID_MISC_1
, 0x35);
667 /* start fifo position */
668 WCrt(ba
, CRT_ID_DISPLAY_FIFO
, 0x5A);
670 WCrt(ba
, CRT_ID_EXT_MEM_CNTL_2
, 0x02);
672 WCrt(ba
, CRT_ID_LAW_POS_LO
, 0x40);
674 WCrt(ba
, CRT_ID_EXT_MISC_CNTL_1
, 0x81);
675 WCrt(ba
, CRT_ID_MISC_1
, 0xB5);
676 WCrt(ba
, CRT_ID_CONFIG_1
, 0x0E);
678 WGfx(ba
, GCT_ID_SET_RESET
, 0x00);
679 WGfx(ba
, GCT_ID_ENABLE_SET_RESET
, 0x00);
680 WGfx(ba
, GCT_ID_COLOR_COMPARE
, 0x00);
681 WGfx(ba
, GCT_ID_DATA_ROTATE
, 0x00);
682 WGfx(ba
, GCT_ID_READ_MAP_SELECT
, 0x00);
683 WGfx(ba
, GCT_ID_GRAPHICS_MODE
, 0x40);
684 WGfx(ba
, GCT_ID_MISC
, 0x01);
685 WGfx(ba
, GCT_ID_COLOR_XCARE
, 0x0F);
686 WGfx(ba
, GCT_ID_BITMASK
, 0xFF);
688 /* colors for text mode */
689 for (i
= 0; i
<= 0xf; i
++)
692 WAttr(ba
, ACT_ID_ATTR_MODE_CNTL
, 0x41);
693 WAttr(ba
, ACT_ID_OVERSCAN_COLOR
, 0x01);
694 WAttr(ba
, ACT_ID_COLOR_PLANE_ENA
, 0x0F);
695 WAttr(ba
, ACT_ID_HOR_PEL_PANNING
, 0x00);
696 WAttr(ba
, ACT_ID_COLOR_SELECT
, 0x00);
698 vgawio(cv3d_boardaddr
, VDAC_MASK
, 0xFF); /* DAC Mask */
700 /* colors initially set to greyscale */
702 vgawio(cv3d_boardaddr
, VDAC_ADDRESS_W
, 0);
704 for (i
= 255; i
>= 0 ; i
--) {
705 vgawio(cv3d_boardaddr
, VDAC_DATA
, i
);
706 vgawio(cv3d_boardaddr
, VDAC_DATA
, i
);
707 vgawio(cv3d_boardaddr
, VDAC_DATA
, i
);
710 /* GFx hardware cursor off */
711 WCrt(ba
, CRT_ID_HWGC_MODE
, 0x00);
713 /* Set first to 4 MB, so test will work */
714 WCrt(ba
, CRT_ID_LAW_CNTL
, 0x13);
716 /* find *correct* fbsize of z3 board */
717 if (cv3d_has_4mb(gp
->g_fbkva
)) {
718 cv3d_fbsize
= 1024 * 1024 * 4;
719 WCrt(ba
, CRT_ID_LAW_CNTL
, 0x13); /* 4 MB */
721 cv3d_fbsize
= 1024 * 1024 * 2;
722 WCrt(ba
, CRT_ID_LAW_CNTL
, 0x12); /* 2 MB */
725 /* Initialize graphics engine */
726 GfxBusyWait(cv3d_memory_io_base
);
727 vgaw32(cv3d_memory_io_base
, BLT_COMMAND_SET
, CMD_NOP
);
728 vgaw32(cv3d_memory_io_base
, BLT_CLIP_LEFT_RIGHT
, 0x000007ff);
729 vgaw32(cv3d_memory_io_base
, BLT_CLIP_TOP_BOTTOM
, 0x000007ff);
730 vgaw32(cv3d_memory_io_base
, L2D_COMMAND_SET
, CMD_NOP
);
731 vgaw32(cv3d_memory_io_base
, L2D_CLIP_LEFT_RIGHT
, 0x000007ff);
732 vgaw32(cv3d_memory_io_base
, L2D_CLIP_TOP_BOTTOM
, 0x000007ff);
733 vgaw32(cv3d_memory_io_base
, P2D_COMMAND_SET
, CMD_NOP
);
734 vgaw32(cv3d_memory_io_base
, P2D_CLIP_LEFT_RIGHT
, 0x000007ff);
735 vgaw32(cv3d_memory_io_base
, P2D_CLIP_TOP_BOTTOM
, 0x000007ff);
737 /* Enable Video Display (Set Bit 5) */
742 gi
->gd_regaddr
= (void *) kvtop (__UNVOLATILE(ba
));
743 gi
->gd_regsize
= 64 * 1024;
744 gi
->gd_fbaddr
= (void *) kvtop (__UNVOLATILE(gp
->g_fbkva
));
745 gi
->gd_fbsize
= cv3d_fbsize
;
750 cv3d_getvmode(struct grf_softc
*gp
, struct grfvideo_mode
*vm
)
752 struct grfvideo_mode
*gv
;
755 /* Handle grabbing console mode */
756 if (vm
->mode_num
== 255) {
757 memcpy(vm
, &cv3dconsole_mode
, sizeof(struct grfvideo_mode
));
758 /* XXX so grfconfig can tell us the correct text dimensions. */
759 vm
->depth
= cv3dconsole_mode
.fy
;
763 if (vm
->mode_num
== 0)
764 vm
->mode_num
= (monitor_current
- monitor_def
) + 1;
765 if (vm
->mode_num
< 1 || vm
->mode_num
> monitor_def_max
)
767 gv
= monitor_def
+ (vm
->mode_num
- 1);
768 if (gv
->mode_num
== 0)
771 memcpy(vm
, gv
, sizeof(struct grfvideo_mode
));
774 /* adjust internal values to pixel values */
776 vm
->hblank_start
*= 8;
777 vm
->hsync_start
*= 8;
786 cv3d_setvmode(struct grf_softc
*gp
, unsigned mode
)
789 if (!mode
|| (mode
> monitor_def_max
) ||
790 monitor_def
[mode
- 1].mode_num
== 0)
793 monitor_current
= monitor_def
+ (mode
- 1);
800 cv3d_blank(struct grf_softc
*gp
, int *on
)
805 cv3d_gfx_on_off(*on
> 0 ? 0 : 1, ba
);
811 * Change the mode of the display.
812 * Return a UNIX error number or 0 for success.
815 cv3d_mode(register struct grf_softc
*gp
, u_long cmd
, void *arg
, u_long a2
,
822 error
= cv3d_load_mon (gp
,
823 (struct grfcv3dtext_mode
*) monitor_current
) ? 0 : EINVAL
;
828 cv3dscreen(1, cv3d_vcode_switch_base
);
830 cv3d_load_mon(gp
, &cv3dconsole_mode
);
831 ite_reinit(gp
->g_itedev
);
839 return (cv3d_getvmode (gp
, (struct grfvideo_mode
*) arg
));
842 error
= cv3d_setvmode (gp
, *(unsigned *) arg
);
843 if (!error
&& (gp
->g_flags
& GF_GRFON
))
845 (struct grfcv3dtext_mode
*) monitor_current
);
849 *(int *)arg
= monitor_def_max
;
853 return (cv3d_ioctl (gp
, a2
, arg
));
859 return (EPASSTHROUGH
);
864 cv3d_ioctl(register struct grf_softc
*gp
, u_long cmd
, void *data
)
867 #ifdef CV3D_HARDWARE_CURSOR
868 case GRFIOCGSPRITEPOS
:
869 return(cv3d_getspritepos (gp
, (struct grf_position
*) data
));
871 case GRFIOCSSPRITEPOS
:
872 return(cv3d_setspritepos (gp
, (struct grf_position
*) data
));
874 case GRFIOCSSPRITEINF
:
875 return(cv3d_setspriteinfo (gp
, (struct grf_spriteinfo
*) data
));
877 case GRFIOCGSPRITEINF
:
878 return(cv3d_getspriteinfo (gp
, (struct grf_spriteinfo
*) data
));
880 case GRFIOCGSPRITEMAX
:
881 return(cv3d_getspritemax (gp
, (struct grf_position
*) data
));
882 #else /* CV3D_HARDWARE_CURSOR */
883 case GRFIOCGSPRITEPOS
:
884 case GRFIOCSSPRITEPOS
:
885 case GRFIOCSSPRITEINF
:
886 case GRFIOCGSPRITEINF
:
887 case GRFIOCGSPRITEMAX
:
889 #endif /* CV3D_HARDWARE_CURSOR */
892 return (cv3d_getcmap (gp
, (struct grf_colormap
*) data
));
895 return (cv3d_putcmap (gp
, (struct grf_colormap
*) data
));
901 return (cv3d_toggle (gp
));
904 return (cv3d_setmonitor (gp
, (struct grfvideo_mode
*)data
));
907 return (cv3d_blank (gp
, (int *)data
));
909 return (EPASSTHROUGH
);
914 cv3d_setmonitor(struct grf_softc
*gp
, struct grfvideo_mode
*gv
)
916 struct grfvideo_mode
*md
;
918 if (!cv3d_mondefok(gv
))
922 /* handle interactive setting of console mode */
923 if (gv
->mode_num
== 255) {
924 memcpy(&cv3dconsole_mode
.gv
, gv
, sizeof(struct grfvideo_mode
));
925 cv3dconsole_mode
.gv
.hblank_start
/= 8;
926 cv3dconsole_mode
.gv
.hsync_start
/= 8;
927 cv3dconsole_mode
.gv
.hsync_stop
/= 8;
928 cv3dconsole_mode
.gv
.htotal
/= 8;
929 cv3dconsole_mode
.rows
= gv
->disp_height
/ cv3dconsole_mode
.fy
;
930 cv3dconsole_mode
.cols
= gv
->disp_width
/ cv3dconsole_mode
.fx
;
931 if (!(gp
->g_flags
& GF_GRFON
))
932 cv3d_load_mon(gp
, &cv3dconsole_mode
);
933 ite_reinit(gp
->g_itedev
);
938 md
= monitor_def
+ (gv
->mode_num
- 1);
941 * Prevent user from crashing the system by using
942 * grfconfig while in X
944 if (gp
->g_flags
& GF_GRFON
)
945 if (md
== monitor_current
) {
946 printf("grfcv3d: Changing the used mode not allowed!\n");
950 memcpy(md
, gv
, sizeof(struct grfvideo_mode
));
952 /* adjust pixel oriented values to internal rep. */
954 md
->hblank_start
/= 8;
955 md
->hsync_start
/= 8;
964 cv3d_getcmap(struct grf_softc
*gfp
, struct grf_colormap
*cmap
)
967 u_char red
[256], green
[256], blue
[256], *rp
, *gp
, *bp
;
972 if (cmap
->count
== 0 || cmap
->index
>= 256)
975 if (cmap
->count
> 256 - cmap
->index
)
976 cmap
->count
= 256 - cmap
->index
;
978 /* first read colors out of the chip, then copyout to userspace */
979 vgawio(cv3d_boardaddr
, VDAC_ADDRESS_W
, cmap
->index
);
982 rp
= red
+ cmap
->index
;
983 gp
= green
+ cmap
->index
;
984 bp
= blue
+ cmap
->index
;
987 *rp
++ = vgario(cv3d_special_register_base
, VDAC_DATA
) << 2;
988 *gp
++ = vgario(cv3d_special_register_base
, VDAC_DATA
) << 2;
989 *bp
++ = vgario(cv3d_special_register_base
, VDAC_DATA
) << 2;
992 if (!(error
= copyout (red
+ cmap
->index
, cmap
->red
, cmap
->count
))
993 && !(error
= copyout (green
+ cmap
->index
, cmap
->green
, cmap
->count
))
994 && !(error
= copyout (blue
+ cmap
->index
, cmap
->blue
, cmap
->count
)))
1002 cv3d_putcmap(struct grf_softc
*gfp
, struct grf_colormap
*cmap
)
1005 u_char red
[256], green
[256], blue
[256], *rp
, *gp
, *bp
;
1010 if (cmap
->count
== 0 || cmap
->index
>= 256)
1013 if (cmap
->index
+ cmap
->count
> 256)
1014 cmap
->count
= 256 - cmap
->index
;
1016 /* first copy the colors into kernelspace */
1017 if (!(error
= copyin (cmap
->red
, red
+ cmap
->index
, cmap
->count
))
1018 && !(error
= copyin (cmap
->green
, green
+ cmap
->index
, cmap
->count
))
1019 && !(error
= copyin (cmap
->blue
, blue
+ cmap
->index
, cmap
->count
))) {
1020 vgawio(cv3d_boardaddr
, VDAC_ADDRESS_W
, cmap
->index
);
1021 x
= cmap
->count
- 1;
1023 rp
= red
+ cmap
->index
;
1024 gp
= green
+ cmap
->index
;
1025 bp
= blue
+ cmap
->index
;
1028 vgawio(cv3d_boardaddr
, VDAC_DATA
, *rp
++ >> 2);
1029 vgawio(cv3d_boardaddr
, VDAC_DATA
, *gp
++ >> 2);
1030 vgawio(cv3d_boardaddr
, VDAC_DATA
, *bp
++ >> 2);
1039 cv3d_toggle(struct grf_softc
*gp
)
1045 cv3d_pass_toggle
= 1;
1046 #endif /* !CV3DCONSOLE */
1048 if (cv3d_pass_toggle
) {
1049 cv3dscreen(0, cv3d_vcode_switch_base
);
1050 cv3d_pass_toggle
= 0;
1052 cv3dscreen(1, cv3d_vcode_switch_base
);
1053 cv3d_pass_toggle
= 1;
1061 cv3d_mondefok(struct grfvideo_mode
*gv
)
1063 unsigned long maxpix
;
1065 if (gv
->mode_num
< 1 || gv
->mode_num
> monitor_def_max
) {
1066 if (gv
->mode_num
!= 255 || gv
->depth
!= 4)
1072 maxpix
= MAXPIXELCLOCK
- 55000000;
1075 maxpix
= MAXPIXELCLOCK
;
1079 #ifdef CV3D_AGGRESSIVE_TIMING
1080 maxpix
= MAXPIXELCLOCK
- 35000000;
1082 maxpix
= MAXPIXELCLOCK
- 55000000;
1087 #ifdef CV3D_AGGRESSIVE_TIMING
1088 maxpix
= MAXPIXELCLOCK
- 75000000;
1090 maxpix
= MAXPIXELCLOCK
- 85000000;
1094 printf("grfcv3d: Illegal depth in mode %d\n",
1095 (int) gv
->mode_num
);
1099 if (gv
->pixel_clock
> maxpix
) {
1100 printf("grfcv3d: Pixelclock too high in mode %d\n",
1101 (int) gv
->mode_num
);
1105 if (gv
->mode_num
== 255) { /* console mode */
1106 if ((gv
->disp_width
/ 8) > MAXCOLS
) {
1107 printf ("grfcv3d: Too many columns for console\n");
1109 } else if ((gv
->disp_height
/ S3FONTY
) > MAXROWS
) {
1110 printf ("grfcv3d: Too many rows for console\n");
1115 if (gv
->disp_flags
& GRF_FLAGS_SYNC_ON_GREEN
) {
1116 printf("grfcv3d: sync-on-green is not supported\n");
1125 cv3d_load_mon(struct grf_softc
*gp
, struct grfcv3dtext_mode
*md
)
1127 struct grfvideo_mode
*gv
;
1129 volatile void *ba
, *fb
;
1131 unsigned short HT
, HDE
, HBS
, HBE
, HSS
, HSE
, VDE
, VBS
, VBE
, VSS
,
1133 int cr50
, cr66
, sr15
, sr18
, clock_mode
, test
;
1134 int hmul
; /* Multiplier for hor. Values */
1135 int fb_flag
= 2; /* default value for 8bit memory access */
1136 unsigned char hvsync_pulse
;
1142 TEXT
= (gv
->depth
== 4);
1143 CONSOLE
= (gv
->mode_num
== 255);
1145 if (!cv3d_mondefok(gv
)) {
1146 printf("grfcv3d: Monitor definition not ok\n");
1153 /* turn gfx off, don't mess up the display */
1154 cv3d_gfx_on_off(1, ba
);
1156 /* provide all needed information in grf device-independent locations */
1157 gp
->g_data
= (void *) gv
;
1158 gi
= &gp
->g_display
;
1159 gi
->gd_colors
= 1 << gv
->depth
;
1160 gi
->gd_planes
= gv
->depth
;
1161 gi
->gd_fbwidth
= gv
->disp_width
;
1162 gi
->gd_fbheight
= gv
->disp_height
;
1166 gi
->gd_dwidth
= md
->fx
* md
->cols
;
1167 gi
->gd_dheight
= md
->fy
* md
->rows
;
1169 gi
->gd_dwidth
= gv
->disp_width
;
1170 gi
->gd_dheight
= gv
->disp_height
;
1175 /* get display mode parameters */
1176 switch (gv
->depth
) {
1186 HBS
= gv
->hblank_start
* hmul
;
1187 HSS
= gv
->hsync_start
* hmul
;
1188 HSE
= gv
->hsync_stop
* hmul
;
1189 HBE
= gv
->htotal
* hmul
- 6;
1190 HT
= gv
->htotal
* hmul
- 5;
1191 VBS
= gv
->vblank_start
- 1;
1192 VSS
= gv
->vsync_start
;
1193 VSE
= gv
->vsync_stop
;
1194 VBE
= gv
->vtotal
- 3;
1195 VT
= gv
->vtotal
- 2;
1198 * Disable enhanced Mode for text display
1200 * XXX You need to set this bit in CRT_ID_EXT_MISC_CNTL_1
1201 * _and_ MR_ADVANCED_FUNCTION_CONTROL, because the same
1202 * function exists in both registers.
1204 cr66
= RCrt(ba
, CRT_ID_EXT_MISC_CNTL_1
);
1207 vgaw32(cv3d_memory_io_base
, MR_ADVANCED_FUNCTION_CONTROL
,
1211 vgaw32(cv3d_memory_io_base
, MR_ADVANCED_FUNCTION_CONTROL
,
1214 WCrt(ba
, CRT_ID_EXT_MISC_CNTL_1
, cr66
);
1217 HDE
= ((gv
->disp_width
+ md
->fx
- 1) / md
->fx
) - 1;
1219 HDE
= (gv
->disp_width
+ 3) * hmul
/ 8 - 1; /*HBS;*/
1220 VDE
= gv
->disp_height
- 1;
1224 if (gv
->disp_flags
& GRF_FLAGS_LACE
) {
1233 /* Horizontal/Vertical Sync Pulse */
1235 * GREG_MISC_OUTPUT_W Register:
1236 * bit description (0/1)
1237 * 0 Monochrome/Color emulation
1238 * 1 Disable/Enable access of the display memory from the CPU
1239 * 5 Select the low/high 64K page of memory
1240 * 6 Select a positive/negative horizontal retrace sync pulse
1241 * 7 Select a positive/negative vertical retrace sync pulse
1243 hvsync_pulse
= vgar(ba
, GREG_MISC_OUTPUT_R
);
1244 if (gv
->disp_flags
& GRF_FLAGS_PHSYNC
)
1245 hvsync_pulse
&= ~0x40;
1247 hvsync_pulse
|= 0x40;
1248 if (gv
->disp_flags
& GRF_FLAGS_PVSYNC
)
1249 hvsync_pulse
&= ~0x80;
1251 hvsync_pulse
|= 0x80;
1252 vgaw(ba
, GREG_MISC_OUTPUT_W
, hvsync_pulse
);
1254 /* GFX hardware cursor off */
1255 WCrt(ba
, CRT_ID_HWGC_MODE
, 0x00);
1256 WCrt(ba
, CRT_ID_EXT_DAC_CNTL
, 0x00);
1258 WSeq(ba
, SEQ_ID_MEMORY_MODE
, (TEXT
|| (gv
->depth
== 1)) ? 0x06 : 0x0e);
1259 WGfx(ba
, GCT_ID_READ_MAP_SELECT
, 0x00);
1260 WSeq(ba
, SEQ_ID_MAP_MASK
, (gv
->depth
== 1) ? 0x01 : 0xff);
1261 WSeq(ba
, SEQ_ID_CHAR_MAP_SELECT
, 0x00);
1265 mnr
= cv3d_compute_clock(gv
->pixel_clock
);
1266 WSeq(ba
, SEQ_ID_DCLK_HI
, ((mnr
& 0xFF00) >> 8));
1267 WSeq(ba
, SEQ_ID_DCLK_LO
, (mnr
& 0xFF));
1269 /* load display parameters into board */
1271 WCrt(ba
, CRT_ID_EXT_HOR_OVF
,
1272 ((HT
& 0x100) ? 0x01 : 0x00) |
1273 ((HDE
& 0x100) ? 0x02 : 0x00) |
1274 ((HBS
& 0x100) ? 0x04 : 0x00) |
1275 /* ((HBE & 0x40) ? 0x08 : 0x00) | */ /* Later... */
1276 ((HSS
& 0x100) ? 0x10 : 0x00) |
1277 /* ((HSE & 0x20) ? 0x20 : 0x00) | */
1278 (((HT
-5) & 0x100) ? 0x40 : 0x00) );
1280 WCrt(ba
, CRT_ID_EXT_VER_OVF
,
1281 0x40 | /* Line compare */
1282 ((VT
& 0x400) ? 0x01 : 0x00) |
1283 ((VDE
& 0x400) ? 0x02 : 0x00) |
1284 ((VBS
& 0x400) ? 0x04 : 0x00) |
1285 ((VSS
& 0x400) ? 0x10 : 0x00) );
1287 WCrt(ba
, CRT_ID_HOR_TOTAL
, HT
);
1288 WCrt(ba
, CRT_ID_DISPLAY_FIFO
, HT
- 5);
1290 WCrt(ba
, CRT_ID_HOR_DISP_ENA_END
, ((HDE
>= HBS
) ? (HBS
- 1) : HDE
));
1291 WCrt(ba
, CRT_ID_START_HOR_BLANK
, HBS
);
1292 WCrt(ba
, CRT_ID_END_HOR_BLANK
, ((HBE
& 0x1f) | 0x80));
1293 WCrt(ba
, CRT_ID_START_HOR_RETR
, HSS
);
1294 WCrt(ba
, CRT_ID_END_HOR_RETR
,
1296 ((HBE
& 0x20) ? 0x80 : 0x00) );
1297 WCrt(ba
, CRT_ID_VER_TOTAL
, VT
);
1298 WCrt(ba
, CRT_ID_OVERFLOW
,
1300 ((VT
& 0x100) ? 0x01 : 0x00) |
1301 ((VDE
& 0x100) ? 0x02 : 0x00) |
1302 ((VSS
& 0x100) ? 0x04 : 0x00) |
1303 ((VBS
& 0x100) ? 0x08 : 0x00) |
1304 ((VT
& 0x200) ? 0x20 : 0x00) |
1305 ((VDE
& 0x200) ? 0x40 : 0x00) |
1306 ((VSS
& 0x200) ? 0x80 : 0x00) );
1308 WCrt(ba
, CRT_ID_MAX_SCAN_LINE
,
1309 0x40 | /* TEXT ? 0x00 ??? */
1310 ((gv
->disp_flags
& GRF_FLAGS_DBLSCAN
) ? 0x80 : 0x00) |
1311 ((VBS
& 0x200) ? 0x20 : 0x00) |
1312 (TEXT
? ((md
->fy
- 1) & 0x1f) : 0x00));
1314 WCrt(ba
, CRT_ID_MODE_CONTROL
, 0xE3);
1320 WCrt(ba
, CRT_ID_CURSOR_START
, (md
->fy
& 0x1f) - 2);
1321 WCrt(ba
, CRT_ID_CURSOR_END
, (md
->fy
& 0x1f) - 1);
1323 WCrt(ba
, CRT_ID_CURSOR_START
, 0x00);
1324 WCrt(ba
, CRT_ID_CURSOR_END
, md
->fy
& 0x1f);
1326 WCrt(ba
, CRT_ID_UNDERLINE_LOC
, (md
->fy
- 1) & 0x1f);
1328 WCrt(ba
, CRT_ID_CURSOR_LOC_HIGH
, 0x00);
1329 WCrt(ba
, CRT_ID_CURSOR_LOC_LOW
, 0x00);
1332 WCrt(ba
, CRT_ID_START_ADDR_HIGH
, 0x00);
1333 WCrt(ba
, CRT_ID_START_ADDR_LOW
, 0x00);
1335 WCrt(ba
, CRT_ID_START_VER_RETR
, VSS
);
1336 WCrt(ba
, CRT_ID_END_VER_RETR
, (VSE
& 0x0f));
1337 WCrt(ba
, CRT_ID_VER_DISP_ENA_END
, VDE
);
1338 WCrt(ba
, CRT_ID_START_VER_BLANK
, VBS
);
1339 WCrt(ba
, CRT_ID_END_VER_BLANK
, VBE
);
1341 WCrt(ba
, CRT_ID_LINE_COMPARE
, 0xff);
1342 WCrt(ba
, CRT_ID_LACE_RETR_START
, HT
/ 2);
1343 WCrt(ba
, CRT_ID_LACE_CONTROL
,
1344 ((gv
->disp_flags
& GRF_FLAGS_LACE
) ? 0x20 : 0x00));
1346 WGfx(ba
, GCT_ID_GRAPHICS_MODE
,
1347 ((TEXT
|| (gv
->depth
== 1)) ? 0x00 : 0x40));
1348 WGfx(ba
, GCT_ID_MISC
, (TEXT
? 0x04 : 0x01));
1350 WSeq (ba
, SEQ_ID_MEMORY_MODE
,
1351 ((TEXT
|| (gv
->depth
== 1)) ? 0x06 : 0x02));
1353 vgawio(cv3d_boardaddr
, VDAC_MASK
, 0xff);
1356 test
= RCrt(ba
, CRT_ID_BACKWAD_COMP_2
);
1357 WCrt(ba
, CRT_ID_BACKWAD_COMP_2
, (test
| 0x20));
1359 sr15
= RSeq(ba
, SEQ_ID_CLKSYN_CNTL_2
);
1361 sr18
= RSeq(ba
, SEQ_ID_RAMDAC_CNTL
);
1366 test
= RCrt(ba
, CRT_ID_EXT_MISC_CNTL_2
);
1369 switch (gv
->depth
) {
1373 HDE
= gv
->disp_width
/ 16;
1377 if (gv
->pixel_clock
> 80000000) {
1379 * CR67 bit 1 is undocumented but needed to prevent
1380 * a white line on the left side of the screen.
1382 clock_mode
= 0x10 | 0x02;
1386 HDE
= gv
->disp_width
/ 8;
1392 HDE
= gv
->disp_width
/ 4;
1398 HDE
= gv
->disp_width
/ 4;
1401 case 24: /* this is really 32 Bit on CV64/3D */
1405 HDE
= (gv
->disp_width
/ 2);
1410 if (cv3d_zorroIII
) {
1411 gp
->g_fbkva
= (volatile char *)cv3d_boardaddr
+ 0x04000000 +
1412 (0x00400000 * fb_flag
);
1414 /* XXX This is totaly untested */
1415 Select_Zorro2_FrameBuffer(fb_flag
);
1418 WCrt(ba
, CRT_ID_EXT_MISC_CNTL_2
, clock_mode
| test
);
1419 WSeq(ba
, SEQ_ID_CLKSYN_CNTL_2
, sr15
);
1420 WSeq(ba
, SEQ_ID_RAMDAC_CNTL
, sr18
);
1421 WCrt(ba
, CRT_ID_SCREEN_OFFSET
, HDE
);
1423 WCrt(ba
, CRT_ID_MISC_1
, (TEXT
? 0x05 : 0x35));
1425 test
= RCrt(ba
, CRT_ID_EXT_SYS_CNTL_2
);
1427 /* HDE Overflow in bits 4-5 */
1428 test
|= (HDE
>> 4) & 0x30;
1429 WCrt(ba
, CRT_ID_EXT_SYS_CNTL_2
, test
);
1432 /* Set up graphics engine */
1433 switch (gv
->disp_width
) {
1452 default: /* XXX The Xserver has to handle this */
1456 WCrt(ba
, CRT_ID_EXT_SYS_CNTL_1
, cr50
);
1460 WAttr(ba
, ACT_ID_ATTR_MODE_CNTL
, (TEXT
? 0x08 : 0x41));
1462 WAttr(ba
, ACT_ID_COLOR_PLANE_ENA
,
1463 (gv
->depth
== 1) ? 0x01 : 0x0f);
1466 /* text initialization */
1469 cv3d_inittextmode(gp
);
1474 vgawio(cv3d_boardaddr
, VDAC_ADDRESS_W
, 0);
1475 for (i
= 0; i
< 16; i
++) {
1476 vgawio(cv3d_boardaddr
, VDAC_DATA
, cv3dconscolors
[i
][0]);
1477 vgawio(cv3d_boardaddr
, VDAC_DATA
, cv3dconscolors
[i
][1]);
1478 vgawio(cv3d_boardaddr
, VDAC_DATA
, cv3dconscolors
[i
][2]);
1482 /* Set display enable flag */
1485 /* turn gfx on again */
1486 cv3d_gfx_on_off(0, ba
);
1489 cv3dscreen(0, cv3d_vcode_switch_base
);
1496 cv3d_inittextmode(struct grf_softc
*gp
)
1498 struct grfcv3dtext_mode
*tm
= (struct grfcv3dtext_mode
*)gp
->g_data
;
1499 volatile void *ba
, *fb
;
1500 volatile unsigned char *c
;
1501 unsigned char *f
, y
;
1507 /* load text font into beginning of display memory.
1508 * Each character cell is 32 bytes long (enough for 4 planes)
1509 * In linear addressing text mode, the memory is organized
1510 * so, that the Bytes of all 4 planes are interleaved.
1511 * 1st byte plane 0, 1st byte plane 1, 1st byte plane 2,
1512 * 1st byte plane 3, 2nd byte plane 0, 2nd byte plane 1,...
1513 * The font is loaded in plane 2.
1516 c
= (volatile unsigned char *) fb
;
1519 for (z
= 0; z
< tm
->cols
* tm
->rows
* 3; z
++) {
1526 c
= (volatile unsigned char *)fb
+ (32 * tm
->fdstart
* 4 + 2);
1528 for (z
= tm
->fdstart
; z
<= tm
->fdend
; z
++, c
+= (32 - tm
->fy
) * 4)
1529 for (y
= 0; y
< tm
->fy
; y
++) {
1534 /* print out a little init msg */
1535 c
= (volatile unsigned char *)fb
+ (tm
->cols
- 9) * 4;
1560 * 0 = CyberVision Signal
1565 cv3dscreen(int toggle
, volatile void *ba
)
1567 *((volatile short *)(ba
)) = (toggle
& 1);
1571 /* 0 = on, 1= off */
1572 /* ba= registerbase */
1574 cv3d_gfx_on_off(int toggle
, volatile void *ba
)
1579 toggle
= toggle
<< 5;
1581 r
= RSeq(ba
, SEQ_ID_CLOCKING_MODE
);
1582 r
&= ~0x20; /* set Bit 5 to 0 */
1584 WSeq(ba
, SEQ_ID_CLOCKING_MODE
, r
| toggle
);
1588 #ifdef CV3D_HARDWARE_CURSOR
1590 static unsigned char cv3d_hotx
= 0, cv3d_hoty
= 0;
1591 static char cv_cursor_on
= 0;
1593 #define HWC_OFF (cv3d_fbsize - 1024*2)
1594 #define HWC_SIZE 1024
1596 /* Hardware Cursor handling routines */
1599 cv3d_getspritepos(struct grf_softc
*gp
, struct grf_position
*pos
)
1602 volatile void *ba
= gp
->g_regkva
;
1604 hi
= RCrt(ba
, CRT_ID_HWGC_ORIGIN_Y_HI
);
1605 lo
= RCrt(ba
, CRT_ID_HWGC_ORIGIN_Y_LO
);
1607 pos
->y
= (hi
<< 8) + lo
;
1608 hi
= RCrt(ba
, CRT_ID_HWGC_ORIGIN_X_HI
);
1609 lo
= RCrt(ba
, CRT_ID_HWGC_ORIGIN_X_LO
);
1610 pos
->x
= (hi
<< 8) + lo
;
1616 cv3d_setspritepos(struct grf_softc
*gp
, struct grf_position
*pos
)
1618 volatile void *ba
= gp
->g_regkva
;
1620 static short savex
, savey
;
1628 } else { /* restore cursor */
1635 xoff
= ((-x
) & 0xFE);
1642 yoff
= ((-y
) & 0xFE);
1648 WCrt(ba
, CRT_ID_HWGC_ORIGIN_X_HI
, (x
>> 8));
1649 WCrt(ba
, CRT_ID_HWGC_ORIGIN_X_LO
, (x
& 0xff));
1651 WCrt(ba
, CRT_ID_HWGC_ORIGIN_Y_LO
, (y
& 0xff));
1652 WCrt(ba
, CRT_ID_HWGC_DSTART_X
, xoff
);
1653 WCrt(ba
, CRT_ID_HWGC_DSTART_Y
, yoff
);
1654 WCrt(ba
, CRT_ID_HWGC_ORIGIN_Y_HI
, (y
>> 8));
1662 return ( ((val
& 0xff00) >> 8) | ((val
& 0xff) << 8));
1666 cv3d_getspriteinfo(struct grf_softc
*gp
, struct grf_spriteinfo
*info
)
1668 volatile void *ba
, fb
;
1673 if (info
->set
& GRFSPRSET_ENABLE
)
1674 info
->enable
= RCrt(ba
, CRT_ID_HWGC_MODE
) & 0x01;
1676 if (info
->set
& GRFSPRSET_POS
)
1677 cv3d_getspritepos (gp
, &info
->pos
);
1680 if (info
->set
& GRFSPRSET_SHAPE
) {
1681 u_char image
[512], mask
[512];
1682 volatile u_long
*hwp
;
1687 for (row
= 0, hwp
= (u_long
*)(fb
+ HWC_OFF
),
1688 mp
= mask
, imp
= image
;
1691 u_long bp10
, bp20
, bp11
, bp21
;
1700 *imp
++ = (~bp10
) & bp11
;
1701 *imp
++ = (~bp20
) & bp21
;
1702 *mp
++ = (~bp10
) | (bp10
& ~bp11
);
1703 *mp
++ = (~bp20
) & (bp20
& ~bp21
);
1705 copyout (image
, info
->image
, sizeof (image
));
1706 copyout (mask
, info
->mask
, sizeof (mask
));
1714 cv3d_setup_hwc(struct grf_softc
*gp
)
1716 volatile void *ba
= gp
->g_regkva
;
1720 if (gp
->g_display
.gd_planes
<= 4)
1721 cv3d_cursor_on
= 0; /* don't enable hwc in text modes */
1722 if (cv3d_cursor_on
== 0)
1725 /* reset colour stack */
1726 #if !defined(__m68k__)
1727 test
= RCrt(ba
, CRT_ID_HWGC_MODE
);
1730 /* do it in assembler, the above does't seem to work */
1731 __asm
volatile ("moveb #0x45, %1@(0x3d4); \
1732 moveb %1@(0x3d5),%0" : "=r" (test
) : "a" (ba
));
1735 WCrt (ba
, CRT_ID_HWGC_FG_STACK
, 0);
1737 hwc
= ba
+ CRT_ADDRESS_W
;
1741 #if !defined(__m68k__)
1742 test
= RCrt(ba
, CRT_ID_HWGC_MODE
);
1745 /* do it in assembler, the above does't seem to work */
1746 __asm
volatile ("moveb #0x45, %1@(0x3d4); \
1747 moveb %1@(0x3d5),%0" : "=r" (test
) : "a" (ba
));
1749 switch (gp
->g_display
.gd_planes
) {
1751 WCrt (ba
, CRT_ID_HWGC_BG_STACK
, 0x1);
1755 WCrt (ba
, CRT_ID_HWGC_BG_STACK
, 0xff);
1760 test
= HWC_OFF
/ HWC_SIZE
;
1761 WCrt (ba
, CRT_ID_HWGC_START_AD_HI
, (test
>> 8));
1762 WCrt (ba
, CRT_ID_HWGC_START_AD_LO
, (test
& 0xff));
1764 WCrt (ba
, CRT_ID_HWGC_DSTART_X
, 0);
1765 WCrt (ba
, CRT_ID_HWGC_DSTART_Y
, 0);
1767 WCrt (ba
, CRT_ID_EXT_DAC_CNTL
, 0x10); /* Cursor X11 Mode */
1769 * Put it into Windoze Mode or you'll see sometimes a white stripe
1770 * on the right side (in double clocking modes with a screen bigger
1773 WCrt (ba
, CRT_ID_EXT_DAC_CNTL
, 0x00); /* Cursor Windoze Mode */
1775 WCrt (ba
, CRT_ID_HWGC_MODE
, 0x01);
1780 * This was the reason why you shouldn't use the HWC in the Kernel:(
1781 * Obsoleted now by use of interrupts :-)
1784 #define VerticalRetraceWait(ba) \
1786 while (vgar(ba, GREG_INPUT_STATUS1_R) == 0x00) ; \
1787 while ((vgar(ba, GREG_INPUT_STATUS1_R) & 0x08) == 0x08) ; \
1788 while ((vgar(ba, GREG_INPUT_STATUS1_R) & 0x08) == 0x00) ; \
1793 cv3d_setspriteinfo(struct grf_softc
*gp
, struct grf_spriteinfo
*info
)
1795 volatile void *ba
, fb
;
1796 int depth
= gp
->g_display
.gd_planes
;
1801 if (info
->set
& GRFSPRSET_SHAPE
) {
1803 * For an explanation of these weird actions here, see above
1804 * when reading the shape. We set the shape directly into
1805 * the video memory, there's no reason to keep 1k on the
1806 * kernel stack just as template
1808 u_char
*image
, *mask
;
1809 volatile u_short
*hwp
;
1814 WCrt (ba
, CRT_ID_HWGC_MODE
, 0x00);
1817 * The Trio64 crashes if the cursor data is written
1818 * while the cursor is displayed.
1819 * Sadly, turning the cursor off is not enough.
1820 * What we have to do is:
1821 * 1. Wait for vertical retrace, to make sure no-one
1822 * has moved the cursor in this sync period (because
1823 * another write then would have no effect, argh!).
1824 * 2. Move the cursor off-screen
1825 * 3. Another wait for v. retrace to make sure the cursor
1827 * 4. Write the data, finally.
1828 * (thanks to Harald Koenig for this tip!)
1832 * Remark 06/06/96: Update in interrupt obsoletes this,
1833 * but the warning should stay there!
1836 VerticalRetraceWait(ba
);
1838 WCrt (ba
, CRT_ID_HWGC_ORIGIN_X_HI
, 0x7);
1839 WCrt (ba
, CRT_ID_HWGC_ORIGIN_X_LO
, 0xff);
1840 WCrt (ba
, CRT_ID_HWGC_ORIGIN_Y_LO
, 0xff);
1841 WCrt (ba
, CRT_ID_HWGC_DSTART_X
, 0x3f);
1842 WCrt (ba
, CRT_ID_HWGC_DSTART_Y
, 0x3f);
1843 WCrt (ba
, CRT_ID_HWGC_ORIGIN_Y_HI
, 0x7);
1845 if (info
->size
.y
> 64)
1847 if (info
->size
.x
> 64)
1849 if (info
->size
.x
< 32)
1852 image
= malloc(HWC_SIZE
, M_TEMP
, M_WAITOK
);
1853 mask
= image
+ HWC_SIZE
/2;
1855 copyin(info
->image
, image
, info
->size
.y
* info
->size
.x
/ 8);
1856 copyin(info
->mask
, mask
, info
->size
.y
* info
->size
.x
/ 8);
1858 hwp
= (u_short
*)(fb
+HWC_OFF
);
1860 /* This is necessary in order not to crash the board */
1861 VerticalRetraceWait(ba
);
1864 * setting it is slightly more difficult, because we can't
1865 * force the application to not pass a *smaller* than
1869 for (row
= 0, mp
= mask
, imp
= image
;
1870 row
< info
->size
.y
; row
++) {
1871 u_short im1
, im2
, im3
, im4
, m1
, m2
, m3
, m4
;
1873 m1
= ~(*(unsigned short *)mp
);
1874 im1
= *(unsigned short *)imp
& *(unsigned short *)mp
;
1878 m2
= ~(*(unsigned short *)mp
);
1879 im2
= *(unsigned short *)imp
& *(unsigned short *)mp
;
1883 if (info
->size
.x
> 32) {
1884 m3
= ~(*(unsigned short *)mp
);
1885 im3
= *(unsigned short *)imp
& *(unsigned short *)mp
;
1888 m4
= ~(*(unsigned short *)mp
);
1889 im4
= *(unsigned short *)imp
& *(unsigned short *)mp
;
1936 for (; row
< 64; row
++) {
1947 for (; row
< 64; row
++) {
1959 free(image
, M_TEMP
);
1960 /* cv3d_setup_hwc(gp); */
1961 cv3d_hotx
= info
->hot
.x
;
1962 cv3d_hoty
= info
->hot
.y
;
1964 /* One must not write twice per vertical blank :-( */
1965 VerticalRetraceWait(ba
);
1966 cv3d_setspritepos(gp
, &info
->pos
);
1968 if (info
->set
& GRFSPRSET_CMAP
) {
1972 /* reset colour stack */
1973 test
= RCrt(ba
, CRT_ID_HWGC_MODE
);
1979 WCrt (ba
, CRT_ID_HWGC_FG_STACK
, 0);
1980 hwc
= ba
+ CRT_ADDRESS_W
;
1985 WCrt (ba
, CRT_ID_HWGC_FG_STACK
, 0);
1986 hwc
= ba
+ CRT_ADDRESS_W
;
1992 test
= RCrt(ba
, CRT_ID_HWGC_MODE
);
1996 WCrt (ba
, CRT_ID_HWGC_BG_STACK
, 1);
1997 hwc
= ba
+ CRT_ADDRESS_W
;
2002 WCrt (ba
, CRT_ID_HWGC_BG_STACK
, 0xff);
2003 hwc
= ba
+ CRT_ADDRESS_W
;
2008 WCrt (ba
, CRT_ID_HWGC_BG_STACK
, 0xff);
2009 hwc
= ba
+ CRT_ADDRESS_W
;
2016 if (info
->set
& GRFSPRSET_ENABLE
) {
2020 /* WCrt(ba, CRT_ID_HWGC_MODE, 0x01); */
2022 WCrt(ba
, CRT_ID_HWGC_MODE
, 0x00);
2024 if (info
->set
& GRFSPRSET_POS
)
2025 cv3d_setspritepos(gp
, &info
->pos
);
2026 if (info
->set
& GRFSPRSET_HOT
) {
2028 cv3d_hotx
= info
->hot
.x
;
2029 cv3d_hoty
= info
->hot
.y
;
2030 cv3d_setspritepos (gp
, &info
->pos
);
2037 cv3d_getspritemax(struct grf_softc
*gp
, struct grf_position
*pos
)
2045 #endif /* CV3D_HARDWARE_CURSOR */
2047 #endif /* NGRFCV3D */