1 /* $NetBSD: grf_cl.c,v 1.44 2009/03/18 17:06:42 cegger Exp $ */
4 * Copyright (c) 1997 Klaus Burkert
5 * Copyright (c) 1995 Ezra Story
6 * Copyright (c) 1995 Kari Mettinen
7 * Copyright (c) 1994 Markus Wild
8 * Copyright (c) 1994 Lutz Vieweg
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by Lutz Vieweg.
22 * 4. The name of the author may not be used to endorse or promote products
23 * derived from this software without specific prior written permission
25 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
26 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
29 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
31 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
32 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
34 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include "opt_amigacons.h"
38 #include <sys/cdefs.h>
39 __KERNEL_RCSID(0, "$NetBSD: grf_cl.c,v 1.44 2009/03/18 17:06:42 cegger Exp $");
45 * Graphics routines for Cirrus CL GD 5426 boards,
47 * This code offers low-level routines to access Cirrus Cl GD 5426
48 * graphics-boards from within NetBSD for the Amiga.
49 * No warranties for any kind of function at all - this
50 * code may crash your hardware and scratch your harddisk. Use at your
51 * own risk. Freely distributable.
53 * Modified for Cirrus CL GD 5426 from
54 * Lutz Vieweg's retina driver by Kari Mettinen 08/94
55 * Contributions by Ill, ScottE, MiL
56 * Extensively hacked and rewritten by Ezra Story (Ezy) 01/95
57 * Picasso/040 patches (wee!) by crest 01/96
59 * PicassoIV support bz Klaus "crest" Burkert.
60 * Fixed interlace and doublescan, added clockdoubling and
61 * HiColor&TrueColor suuport by crest 01/97
63 * Thanks to Village Tronic Marketing Gmbh for providing me with
65 * Thanks for Integrated Electronics Oy Ab for providing me with
66 * Cirrus CL GD 542x family documentation.
69 * Mouse support (almost there! :-))
74 #include <sys/param.h>
75 #include <sys/systm.h>
76 #include <sys/errno.h>
77 #include <sys/ioctl.h>
78 #include <sys/device.h>
79 #include <sys/malloc.h>
81 #include <machine/cpu.h>
83 #include <amiga/dev/itevar.h>
84 #include <amiga/amiga/device.h>
85 #include <amiga/dev/grfioctl.h>
86 #include <amiga/dev/grfvar.h>
87 #include <amiga/dev/grf_clreg.h>
88 #include <amiga/dev/zbusvar.h>
90 int cl_mondefok(struct grfvideo_mode
*);
91 void cl_boardinit(struct grf_softc
*);
92 static void cl_CompFQ(u_int
, u_char
*, u_char
*, u_char
*);
93 int cl_getvmode(struct grf_softc
*, struct grfvideo_mode
*);
94 int cl_setvmode(struct grf_softc
*, unsigned int);
95 int cl_toggle(struct grf_softc
*, unsigned short);
96 int cl_getcmap(struct grf_softc
*, struct grf_colormap
*);
97 int cl_putcmap(struct grf_softc
*, struct grf_colormap
*);
99 void cl_off(struct grf_softc
*);
101 void cl_inittextmode(struct grf_softc
*);
102 int cl_ioctl(register struct grf_softc
*, u_long
, void *);
103 int cl_getmousepos(struct grf_softc
*, struct grf_position
*);
104 int cl_setmousepos(struct grf_softc
*, struct grf_position
*);
105 static int cl_setspriteinfo(struct grf_softc
*, struct grf_spriteinfo
*);
106 int cl_getspriteinfo(struct grf_softc
*, struct grf_spriteinfo
*);
107 static int cl_getspritemax(struct grf_softc
*, struct grf_position
*);
108 int cl_blank(struct grf_softc
*, int *);
109 int cl_setmonitor(struct grf_softc
*, struct grfvideo_mode
*);
110 void cl_writesprpos(volatile char *, short, short);
111 void writeshifted(volatile char *, signed char, signed char);
113 static void RegWakeup(volatile void *);
114 static void RegOnpass(volatile void *);
115 static void RegOffpass(volatile void *);
117 void grfclattach(struct device
*, struct device
*, void *);
118 int grfclprint(void *, const char *);
119 int grfclmatch(struct device
*, struct cfdata
*, void *);
120 void cl_memset(unsigned char *, unsigned char, int);
122 /* Graphics display definitions.
123 * These are filled by 'grfconfig' using GRFIOCSETMON.
125 #define monitor_def_max 24
126 static struct grfvideo_mode monitor_def
[24] = {
127 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
128 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0},
129 {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}
131 static struct grfvideo_mode
*monitor_current
= &monitor_def
[0];
133 /* Patchable maximum pixel clock */
134 unsigned long cl_maxpixelclock
= 86000000;
136 /* Console display definition.
137 * Default hardcoded text mode. This grf_cl is set up to
138 * use one text mode only, and this is it. You may use
139 * grfconfig to change the mode after boot.
143 #define CIRRUSFONT kernel_font_8x11
144 #define CIRRUSFONTY 11
146 #define CIRRUSFONT kernel_font_8x8
147 #define CIRRUSFONTY 8
149 extern unsigned char CIRRUSFONT
[];
151 struct grfcltext_mode clconsole_mode
= {
152 {255, "", 25000000, 640, 480, 4, 640/8, 680/8, 768/8, 800/8,
153 481, 490, 498, 522, 0},
154 8, CIRRUSFONTY
, 80, 480 / CIRRUSFONTY
, CIRRUSFONT
, 32, 255
157 unsigned char clconscolors
[3][3] = { /* background, foreground, hilite */
158 {0, 0x40, 0x50}, {152, 152, 152}, {255, 255, 255}
161 int cltype
= 0; /* Picasso, Spectrum or Piccolo */
162 int cl_64bit
= 0; /* PiccoloSD64 or PicassoIV */
163 unsigned char cl_pass_toggle
; /* passthru status tracker */
166 * because all 542x-boards have 2 configdev entries, one for
167 * framebuffer mem and the other for regs, we have to hold onto
168 * the pointers globally until we match on both. This and 'cltype'
169 * are the primary obsticles to multiple board support, but if you
170 * have multiple boards you have bigger problems than grf_cl.
172 static void *cl_fbaddr
= 0; /* framebuffer */
173 static void *cl_regaddr
= 0; /* registers */
174 static int cl_fbsize
; /* framebuffer size */
175 static int cl_fbautosize
; /* framebuffer autoconfig size */
179 * current sprite info, if you add support for multiple boards
180 * make this an array or something
182 struct grf_spriteinfo cl_cursprite
;
184 /* sprite bitmaps in kernel stack, you'll need to arrayize these too if
185 * you add multiple board support
187 static unsigned char cl_imageptr
[8 * 64], cl_maskptr
[8 * 64];
188 static unsigned char cl_sprred
[2], cl_sprgreen
[2], cl_sprblue
[2];
190 /* standard driver stuff */
191 CFATTACH_DECL(grfcl
, sizeof(struct grf_softc
),
192 grfclmatch
, grfclattach
, NULL
, NULL
);
194 static struct cfdata
*cfdata
;
197 grfclmatch(struct device
*pdp
, struct cfdata
*cfp
, void *auxp
)
199 struct zbus_args
*zap
;
200 static int regprod
, fbprod
, fbprod2
;
206 #ifndef CL5426CONSOLE
207 if (amiga_realconfig
== 0)
211 /* Grab the first board we encounter as the preferred one. This will
212 * allow one board to work in a multiple 5426 board system, but not
213 * multiple boards at the same time. */
215 switch (zap
->manid
) {
217 switch (zap
->prodid
) {
250 if (zap
->prodid
!= 2 && zap
->prodid
!= 1)
256 switch (zap
->prodid
) {
283 if (cltype
!= zap
->manid
) {
288 /* Configure either registers or framebuffer in any order */
289 if ((cltype
== PICASSO
) && (cl_64bit
== 1)) {
290 switch (zap
->prodid
) {
293 cl_fbautosize
= zap
->size
;
296 cl_fbautosize
+= zap
->size
;
299 cl_regaddr
= (void *)((unsigned long)(zap
->va
) + 0x10000);
302 cl_regaddr
= (void *)((unsigned long)(zap
->va
) + 0x600000);
303 /* check for PicassoIV with 64MB config and handle it */
304 if (zap
->size
== 0x04000000) {
305 cl_fbaddr
= (void *)((unsigned long)(zap
->va
) + 0x02000000);
307 cl_fbaddr
= (void *)((unsigned long)(zap
->va
) + 0x01000000);
309 cl_fbautosize
= 0x400000;
316 if (zap
->prodid
== regprod
)
317 cl_regaddr
= zap
->va
;
319 if (zap
->prodid
== fbprod
) {
321 cl_fbautosize
= zap
->size
;
327 if (amiga_realconfig
== 0) {
336 grfclattach(struct device
*pdp
, struct device
*dp
, void *auxp
)
338 static struct grf_softc congrf
;
339 struct zbus_args
*zap
;
340 struct grf_softc
*gp
;
341 static char attachflag
= 0;
347 /* make sure both halves have matched */
348 if (!cl_regaddr
|| !cl_fbaddr
)
351 /* do all that messy console/grf stuff */
355 gp
= (struct grf_softc
*) dp
;
357 if (dp
!= NULL
&& congrf
.g_regkva
!= 0) {
359 * inited earlier, just copy (not device struct)
361 memcpy(&gp
->g_display
, &congrf
.g_display
,
362 (char *) &gp
[1] - (char *) &gp
->g_display
);
364 gp
->g_regkva
= (volatile void *) cl_regaddr
;
365 gp
->g_fbkva
= (volatile void *) cl_fbaddr
;
367 gp
->g_unit
= GRF_CL5426_UNIT
;
368 gp
->g_mode
= cl_mode
;
369 gp
->g_conpri
= grfcl_cnprobe();
370 gp
->g_flags
= GF_ALIVE
;
372 /* wakeup the board */
376 (void) cl_load_mon(gp
, &clconsole_mode
);
384 if (amiga_config_found(cfdata
, &gp
->g_device
, gp
, grfclprint
)) {
386 printf("grfcl: %dMB ", cl_fbsize
/ 0x100000);
390 printf("Picasso IV");
391 /* 135MHz will be supported if we
392 * have a palette doubling mode.
394 cl_maxpixelclock
= 86000000;
397 printf("Picasso II");
399 /* check for PicassoII+ (crest) */
400 if(zap
->serno
== 0x00100000)
403 /* determine used Gfx/chipset (crest) */
404 vgaw(gp
->g_regkva
, CRT_ADDRESS
, 0x27); /* Chip ID */
405 switch(vgar(gp
->g_regkva
, CRT_ADDRESS_R
)>>2) {
407 printf(" (with CL-GD5426)");
410 printf(" (with CL-GD5428)");
413 printf(" (with CL-GD5429)");
416 cl_maxpixelclock
= 86000000;
421 cl_maxpixelclock
= 90000000;
425 printf("Piccolo SD64");
426 /* 110MHz will be supported if we
427 * have a palette doubling mode.
429 cl_maxpixelclock
= 90000000;
432 cl_maxpixelclock
= 90000000;
436 printf(" being used\n");
438 cl_maxpixelclock
= 115000000;
442 printf("grfcl unattached!!\n");
447 grfclprint(void *auxp
, const char *pnp
)
450 aprint_normal("ite at %s: ", pnp
);
455 cl_boardinit(struct grf_softc
*gp
)
457 volatile unsigned char *ba
= gp
->g_regkva
;
460 if ((cltype
== PICASSO
) && (cl_64bit
== 1)) { /* PicassoIV */
461 WCrt(ba
, 0x51, 0x00); /* disable capture (FlickerFixer) */
462 delay(200000); /* wait some time (two frames as of now) */
463 WGfx(ba
, 0x2f, 0x00); /* get Blitter into 542x */
464 WGfx(ba
, GCT_ID_RESERVED
, 0x00); /* compatibility mode */
465 WGfx(ba
, GCT_ID_BLT_STAT_START
, 0x00); /* or at least, try so... */
466 cl_fbsize
= cl_fbautosize
;
469 /* wakeup board and flip passthru OFF */
473 vgaw(ba
, 0x46e8, 0x16);
475 vgaw(ba
, 0x46e8, 0x0e);
479 cl_fbsize
= cl_fbautosize
;
481 /* setup initial unchanging parameters */
483 WSeq(ba
, SEQ_ID_CLOCKING_MODE
, 0x21); /* 8 dot - display off */
484 vgaw(ba
, GREG_MISC_OUTPUT_W
, 0xed); /* mem disable */
486 WGfx(ba
, GCT_ID_OFFSET_1
, 0xec); /* magic cookie */
487 WSeq(ba
, SEQ_ID_UNLOCK_EXT
, 0x12); /* yum! cookies! */
490 WSeq(ba
, SEQ_ID_CONF_RBACK
, 0x00);
491 WSeq(ba
, SEQ_ID_DRAM_CNTL
, (cl_fbsize
/ 0x100000 == 2) ? 0x38 : 0xb8);
493 WSeq(ba
, SEQ_ID_DRAM_CNTL
, 0xb0);
495 WSeq(ba
, SEQ_ID_RESET
, 0x03);
496 WSeq(ba
, SEQ_ID_MAP_MASK
, 0xff);
497 WSeq(ba
, SEQ_ID_CHAR_MAP_SELECT
, 0x00);
498 WSeq(ba
, SEQ_ID_MEMORY_MODE
, 0x0e); /* a or 6? */
499 WSeq(ba
, SEQ_ID_EXT_SEQ_MODE
, (cltype
== PICASSO
) ? 0x21 : 0x81);
500 WSeq(ba
, SEQ_ID_EEPROM_CNTL
, 0x00);
502 WSeq(ba
, SEQ_ID_PERF_TUNE
, 0x5a);
504 WSeq(ba
, SEQ_ID_PERF_TUNE
, 0x0a); /* mouse 0a fa */
505 WSeq(ba
, SEQ_ID_SIG_CNTL
, 0x02);
506 WSeq(ba
, SEQ_ID_CURSOR_ATTR
, 0x04);
509 WSeq(ba
, SEQ_ID_MCLK_SELECT
, 0x1c);
511 WSeq(ba
, SEQ_ID_MCLK_SELECT
, 0x22);
513 WCrt(ba
, CRT_ID_PRESET_ROW_SCAN
, 0x00);
514 WCrt(ba
, CRT_ID_CURSOR_START
, 0x00);
515 WCrt(ba
, CRT_ID_CURSOR_END
, 0x08);
516 WCrt(ba
, CRT_ID_START_ADDR_HIGH
, 0x00);
517 WCrt(ba
, CRT_ID_START_ADDR_LOW
, 0x00);
518 WCrt(ba
, CRT_ID_CURSOR_LOC_HIGH
, 0x00);
519 WCrt(ba
, CRT_ID_CURSOR_LOC_LOW
, 0x00);
521 WCrt(ba
, CRT_ID_UNDERLINE_LOC
, 0x07);
522 WCrt(ba
, CRT_ID_MODE_CONTROL
, 0xe3);
523 WCrt(ba
, CRT_ID_LINE_COMPARE
, 0xff); /* ff */
524 WCrt(ba
, CRT_ID_EXT_DISP_CNTL
, 0x22);
526 WCrt(ba
, CRT_ID_SYNC_ADJ_GENLOCK
, 0x00);
527 WCrt(ba
, CRT_ID_OVERLAY_EXT_CTRL_REG
, 0x40);
529 WSeq(ba
, SEQ_ID_CURSOR_STORE
, 0x3c); /* mouse 0x00 */
531 WGfx(ba
, GCT_ID_SET_RESET
, 0x00);
532 WGfx(ba
, GCT_ID_ENABLE_SET_RESET
, 0x00);
533 WGfx(ba
, GCT_ID_DATA_ROTATE
, 0x00);
534 WGfx(ba
, GCT_ID_READ_MAP_SELECT
, 0x00);
535 WGfx(ba
, GCT_ID_GRAPHICS_MODE
, 0x00);
536 WGfx(ba
, GCT_ID_MISC
, 0x01);
537 WGfx(ba
, GCT_ID_COLOR_XCARE
, 0x0f);
538 WGfx(ba
, GCT_ID_BITMASK
, 0xff);
539 WGfx(ba
, GCT_ID_MODE_EXT
, 0x28);
541 for (x
= 0; x
< 0x10; x
++)
543 WAttr(ba
, ACT_ID_ATTR_MODE_CNTL
, 0x01);
544 WAttr(ba
, ACT_ID_OVERSCAN_COLOR
, 0x00);
545 WAttr(ba
, ACT_ID_COLOR_PLANE_ENA
, 0x0f);
546 WAttr(ba
, ACT_ID_HOR_PEL_PANNING
, 0x00);
547 WAttr(ba
, ACT_ID_COLOR_SELECT
, 0x00);
548 WAttr(ba
, 0x34, 0x00);
550 vgaw(ba
, VDAC_MASK
, 0xff);
551 vgaw(ba
, GREG_MISC_OUTPUT_W
, 0xef);
553 WGfx(ba
, GCT_ID_BLT_STAT_START
, 0x04);
554 WGfx(ba
, GCT_ID_BLT_STAT_START
, 0x00);
557 /* colors initially set to greyscale */
558 vgaw(ba
, VDAC_ADDRESS_W
, 0);
559 for (x
= 255; x
>= 0; x
--) {
560 vgaw(ba
, VDAC_DATA
, x
);
561 vgaw(ba
, VDAC_DATA
, x
);
562 vgaw(ba
, VDAC_DATA
, x
);
564 /* set sprite bitmap pointers */
565 cl_cursprite
.image
= cl_imageptr
;
566 cl_cursprite
.mask
= cl_maskptr
;
567 cl_cursprite
.cmap
.red
= cl_sprred
;
568 cl_cursprite
.cmap
.green
= cl_sprgreen
;
569 cl_cursprite
.cmap
.blue
= cl_sprblue
;
573 /* check for 1MB or 2MB board (crest) */
574 volatile unsigned long *cl_fbtestaddr
;
575 cl_fbtestaddr
= (volatile unsigned long *)gp
->g_fbkva
;
577 WGfx(ba
, GCT_ID_OFFSET_0
, 0x40);
578 *cl_fbtestaddr
= 0x12345678;
580 if (*cl_fbtestaddr
!= 0x12345678) {
581 WSeq(ba
, SEQ_ID_DRAM_CNTL
, 0x30);
582 cl_fbsize
= 0x100000;
586 cl_fbsize
= 0x200000;
589 WGfx(ba
, GCT_ID_OFFSET_0
, 0x00);
594 cl_getvmode(struct grf_softc
*gp
, struct grfvideo_mode
*vm
)
596 struct grfvideo_mode
*gv
;
599 /* Handle grabbing console mode */
600 if (vm
->mode_num
== 255) {
601 memcpy(vm
, &clconsole_mode
, sizeof(struct grfvideo_mode
));
602 /* XXX so grfconfig can tell us the correct text dimensions. */
603 vm
->depth
= clconsole_mode
.fy
;
607 if (vm
->mode_num
== 0)
608 vm
->mode_num
= (monitor_current
- monitor_def
) + 1;
609 if (vm
->mode_num
< 1 || vm
->mode_num
> monitor_def_max
)
611 gv
= monitor_def
+ (vm
->mode_num
- 1);
612 if (gv
->mode_num
== 0)
615 memcpy(vm
, gv
, sizeof(struct grfvideo_mode
));
618 /* adjust internal values to pixel values */
620 vm
->hblank_start
*= 8;
621 vm
->hsync_start
*= 8;
630 cl_setvmode(struct grf_softc
*gp
, unsigned mode
)
632 if (!mode
|| (mode
> monitor_def_max
) ||
633 monitor_def
[mode
- 1].mode_num
== 0)
636 monitor_current
= monitor_def
+ (mode
- 1);
641 #ifndef CL5426CONSOLE
643 cl_off(struct grf_softc
*gp
)
645 char *ba
= gp
->g_regkva
;
648 * we'll put the pass-through on for cc ite and set Full Bandwidth bit
649 * on just in case it didn't work...but then it doesn't matter does
653 vgaw(ba
, SEQ_ADDRESS
, SEQ_ID_CLOCKING_MODE
);
654 vgaw(ba
, SEQ_ADDRESS_W
, vgar(ba
, SEQ_ADDRESS_W
) | 0x20);
659 cl_blank(struct grf_softc
*gp
, int *on
)
661 WSeq(gp
->g_regkva
, SEQ_ID_CLOCKING_MODE
, *on
> 0 ? 0x01 : 0x21);
666 * Change the mode of the display.
667 * Return a UNIX error number or 0 for success.
670 cl_mode(register struct grf_softc
*gp
, u_long cmd
, void *arg
, u_long a2
, int a3
)
676 error
= cl_load_mon(gp
,
677 (struct grfcltext_mode
*) monitor_current
) ? 0 : EINVAL
;
681 #ifndef CL5426CONSOLE
684 cl_load_mon(gp
, &clconsole_mode
);
692 return (cl_getvmode(gp
, (struct grfvideo_mode
*) arg
));
695 error
= cl_setvmode(gp
, *(unsigned *) arg
);
696 if (!error
&& (gp
->g_flags
& GF_GRFON
))
698 (struct grfcltext_mode
*) monitor_current
);
702 *(int *) arg
= monitor_def_max
;
706 return (cl_ioctl(gp
, a2
, arg
));
712 return (EPASSTHROUGH
);
716 cl_ioctl(register struct grf_softc
*gp
, u_long cmd
, void *data
)
719 case GRFIOCGSPRITEPOS
:
720 return (cl_getmousepos(gp
, (struct grf_position
*) data
));
722 case GRFIOCSSPRITEPOS
:
723 return (cl_setmousepos(gp
, (struct grf_position
*) data
));
725 case GRFIOCSSPRITEINF
:
726 return (cl_setspriteinfo(gp
, (struct grf_spriteinfo
*) data
));
728 case GRFIOCGSPRITEINF
:
729 return (cl_getspriteinfo(gp
, (struct grf_spriteinfo
*) data
));
731 case GRFIOCGSPRITEMAX
:
732 return (cl_getspritemax(gp
, (struct grf_position
*) data
));
735 return (cl_getcmap(gp
, (struct grf_colormap
*) data
));
738 return (cl_putcmap(gp
, (struct grf_colormap
*) data
));
744 return (cl_toggle(gp
, 0));
747 return (cl_setmonitor(gp
, (struct grfvideo_mode
*) data
));
750 return (cl_blank(gp
, (int *)data
));
753 return (EPASSTHROUGH
);
757 cl_getmousepos(struct grf_softc
*gp
, struct grf_position
*data
)
759 data
->x
= cl_cursprite
.pos
.x
;
760 data
->y
= cl_cursprite
.pos
.y
;
765 cl_writesprpos(volatile char *ba
, short x
, short y
)
767 /* we want to use a 16-bit write to 3c4 so no macros used */
768 volatile unsigned char *cwp
;
769 volatile unsigned short *wp
;
772 wp
= (volatile unsigned short *)cwp
;
775 * don't ask me why, but apparently you can't do a 16-bit write with
776 * x-position like with y-position below (dagge)
778 cwp
[0] = 0x10 | ((x
<< 5) & 0xff);
779 cwp
[1] = (x
>> 3) & 0xff;
781 *wp
= 0x1100 | ((y
& 7) << 13) | ((y
>> 3) & 0xff);
785 writeshifted(volatile char *to
, signed char shiftx
, signed char shifty
)
788 unsigned long long *tptr
, *iptr
, *mptr
, line
;
790 tptr
= (unsigned long long *) __UNVOLATILE(to
);
791 iptr
= (unsigned long long *) cl_cursprite
.image
;
792 mptr
= (unsigned long long *) cl_cursprite
.mask
;
794 shiftx
= shiftx
< 0 ? 0 : shiftx
;
795 shifty
= shifty
< 0 ? 0 : shifty
;
797 /* start reading shifty lines down, and
798 * shift each line in by shiftx
800 for (y
= shifty
; y
< 64; y
++) {
804 *tptr
++ = line
<< shiftx
;
808 *tptr
++ = line
<< shiftx
;
811 /* clear the remainder */
812 for (y
= shifty
; y
> 0; y
--) {
819 cl_setmousepos(struct grf_softc
*gp
, struct grf_position
*data
)
821 volatile char *ba
= gp
->g_regkva
;
822 short rx
, ry
, prx
, pry
;
823 #ifdef CL_SHIFTSPRITE
824 volatile char *fb
= gp
->g_fbkva
;
825 volatile char *sprite
= fb
+ (cl_fbsize
- 1024);
829 if (cl_cursprite
.pos
.x
== data
->x
&& cl_cursprite
.pos
.y
== data
->y
)
832 /* current and previous real coordinates */
833 rx
= data
->x
- cl_cursprite
.hot
.x
;
834 ry
= data
->y
- cl_cursprite
.hot
.y
;
835 prx
= cl_cursprite
.pos
.x
- cl_cursprite
.hot
.x
;
836 pry
= cl_cursprite
.pos
.y
- cl_cursprite
.hot
.y
;
839 * if we are/were on an edge, create (un)shifted bitmap --
840 * ripped out optimization (not extremely worthwhile,
841 * and kind of buggy anyhow).
843 #ifdef CL_SHIFTSPRITE
844 if (rx
< 0 || ry
< 0 || prx
< 0 || pry
< 0) {
845 writeshifted(sprite
, rx
< 0 ? -rx
: 0, ry
< 0 ? -ry
: 0);
849 /* do movement, save position */
850 cl_writesprpos(ba
, rx
< 0 ? 0 : rx
, ry
< 0 ? 0 : ry
);
851 cl_cursprite
.pos
.x
= data
->x
;
852 cl_cursprite
.pos
.y
= data
->y
;
858 cl_getspriteinfo(struct grf_softc
*gp
, struct grf_spriteinfo
*data
)
860 copyout(&cl_cursprite
, data
, sizeof(struct grf_spriteinfo
));
861 copyout(cl_cursprite
.image
, data
->image
, 64 * 8);
862 copyout(cl_cursprite
.mask
, data
->mask
, 64 * 8);
867 cl_setspriteinfo(struct grf_softc
*gp
, struct grf_spriteinfo
*data
)
869 volatile unsigned char *ba
= gp
->g_regkva
, *fb
= gp
->g_fbkva
;
870 volatile char *sprite
= fb
+ (cl_fbsize
- 1024);
872 if (data
->set
& GRFSPRSET_SHAPE
) {
874 unsigned short dsx
, dsy
, i
;
875 unsigned long *di
, *dm
, *si
, *sm
;
876 unsigned long ssi
[128], ssm
[128];
877 struct grf_position gpos
;
880 /* check for a too large sprite (no clipping!) */
883 if (dsy
> 64 || dsx
> 64)
886 /* prepare destination */
887 di
= (unsigned long *)cl_cursprite
.image
;
888 dm
= (unsigned long *)cl_cursprite
.mask
;
889 cl_memset((unsigned char *)di
, 0, 8*64);
890 cl_memset((unsigned char *)dm
, 0, 8*64);
892 /* two alternatives: 64 across, then it's
893 * the same format we use, just copy. Otherwise,
894 * copy into tmp buf and recopy skipping the
897 if ((dsx
- 1) / 32) {
898 copyin(data
->image
, di
, 8 * dsy
);
899 copyin(data
->mask
, dm
, 8 * dsy
);
902 copyin(data
->image
, si
, 4 * dsy
);
903 copyin(data
->mask
, sm
, 4 * dsy
);
904 for (i
= 0; i
< dsy
; i
++) {
913 cl_cursprite
.size
.x
= data
->size
.x
;
914 cl_cursprite
.size
.y
= data
->size
.y
;
916 /* forcably load into board */
917 gpos
.x
= cl_cursprite
.pos
.x
;
918 gpos
.y
= cl_cursprite
.pos
.y
;
919 cl_cursprite
.pos
.x
= -1;
920 cl_cursprite
.pos
.y
= -1;
921 writeshifted(sprite
, 0, 0);
922 cl_setmousepos(gp
, &gpos
);
925 if (data
->set
& GRFSPRSET_HOT
) {
927 cl_cursprite
.hot
= data
->hot
;
930 if (data
->set
& GRFSPRSET_CMAP
) {
932 u_char red
[2], green
[2], blue
[2];
934 copyin(data
->cmap
.red
, red
, 2);
935 copyin(data
->cmap
.green
, green
, 2);
936 copyin(data
->cmap
.blue
, blue
, 2);
937 memcpy(cl_cursprite
.cmap
.red
, red
, 2);
938 memcpy(cl_cursprite
.cmap
.green
, green
, 2);
939 memcpy(cl_cursprite
.cmap
.blue
, blue
, 2);
941 /* enable and load colors 256 & 257 */
942 WSeq(ba
, SEQ_ID_CURSOR_ATTR
, 0x06);
945 vgaw(ba
, VDAC_ADDRESS_W
, 0x00);
946 if (cltype
== PICASSO
) {
947 vgaw(ba
, VDAC_DATA
, (u_char
) (red
[0] >> 2));
948 vgaw(ba
, VDAC_DATA
, (u_char
) (green
[0] >> 2));
949 vgaw(ba
, VDAC_DATA
, (u_char
) (blue
[0] >> 2));
951 vgaw(ba
, VDAC_DATA
, (u_char
) (blue
[0] >> 2));
952 vgaw(ba
, VDAC_DATA
, (u_char
) (green
[0] >> 2));
953 vgaw(ba
, VDAC_DATA
, (u_char
) (red
[0] >> 2));
957 vgaw(ba
, VDAC_ADDRESS_W
, 0x0f);
958 if (cltype
== PICASSO
) {
959 vgaw(ba
, VDAC_DATA
, (u_char
) (red
[1] >> 2));
960 vgaw(ba
, VDAC_DATA
, (u_char
) (green
[1] >> 2));
961 vgaw(ba
, VDAC_DATA
, (u_char
) (blue
[1] >> 2));
963 vgaw(ba
, VDAC_DATA
, (u_char
) (blue
[1] >> 2));
964 vgaw(ba
, VDAC_DATA
, (u_char
) (green
[1] >> 2));
965 vgaw(ba
, VDAC_DATA
, (u_char
) (red
[1] >> 2));
968 /* turn on/off sprite */
969 if (cl_cursprite
.enable
) {
970 WSeq(ba
, SEQ_ID_CURSOR_ATTR
, 0x05);
972 WSeq(ba
, SEQ_ID_CURSOR_ATTR
, 0x04);
976 if (data
->set
& GRFSPRSET_ENABLE
) {
978 if (data
->enable
== 1) {
979 WSeq(ba
, SEQ_ID_CURSOR_ATTR
, 0x05);
980 cl_cursprite
.enable
= 1;
982 WSeq(ba
, SEQ_ID_CURSOR_ATTR
, 0x04);
983 cl_cursprite
.enable
= 0;
987 if (data
->set
& GRFSPRSET_POS
) {
989 /* force placement */
990 cl_cursprite
.pos
.x
= -1;
991 cl_cursprite
.pos
.y
= -1;
994 cl_setmousepos(gp
, &data
->pos
);
1001 cl_getspritemax(struct grf_softc
*gp
, struct grf_position
*data
)
1003 if (gp
->g_display
.gd_planes
== 24)
1011 cl_setmonitor(struct grf_softc
*gp
, struct grfvideo_mode
*gv
)
1013 struct grfvideo_mode
*md
;
1015 if (!cl_mondefok(gv
))
1018 #ifdef CL5426CONSOLE
1019 /* handle interactive setting of console mode */
1020 if (gv
->mode_num
== 255) {
1021 memcpy(&clconsole_mode
.gv
, gv
, sizeof(struct grfvideo_mode
));
1022 clconsole_mode
.gv
.hblank_start
/= 8;
1023 clconsole_mode
.gv
.hsync_start
/= 8;
1024 clconsole_mode
.gv
.hsync_stop
/= 8;
1025 clconsole_mode
.gv
.htotal
/= 8;
1026 clconsole_mode
.rows
= gv
->disp_height
/ clconsole_mode
.fy
;
1027 clconsole_mode
.cols
= gv
->disp_width
/ clconsole_mode
.fx
;
1028 if (!(gp
->g_flags
& GF_GRFON
))
1029 cl_load_mon(gp
, &clconsole_mode
);
1030 ite_reinit(gp
->g_itedev
);
1035 md
= monitor_def
+ (gv
->mode_num
- 1);
1036 memcpy(md
, gv
, sizeof(struct grfvideo_mode
));
1038 /* adjust pixel oriented values to internal rep. */
1040 md
->hblank_start
/= 8;
1041 md
->hsync_start
/= 8;
1042 md
->hsync_stop
/= 8;
1049 cl_getcmap(struct grf_softc
*gfp
, struct grf_colormap
*cmap
)
1051 volatile unsigned char *ba
;
1052 u_char red
[256], green
[256], blue
[256], *rp
, *gp
, *bp
;
1056 if (cmap
->count
== 0 || cmap
->index
>= 256)
1059 if (cmap
->count
> 256 - cmap
->index
)
1060 cmap
->count
= 256 - cmap
->index
;
1063 /* first read colors out of the chip, then copyout to userspace */
1064 vgaw(ba
, VDAC_ADDRESS_R
, cmap
->index
);
1065 x
= cmap
->count
- 1;
1068 * Some sort 'o Magic. Spectrum has some changes on the board to speed
1069 * up 15 and 16Bit modes. They can access these modes with easy-to-programm
1070 * rgbrgbrgb instead of rrrgggbbb. Side effect: when in 8Bit mode, rgb
1071 * is swapped to bgr. I wonder if we need to check for 8Bit though, ill
1075 * The source for the above comment is somewhat unknow to me.
1076 * The Spectrum, Piccolo and PiccoloSD64 have the analog Red and Blue
1077 * lines swapped. In 24BPP this provides RGB instead of BGR as it would
1078 * be native to the chipset. This requires special programming for the
1079 * CLUT in 8BPP to compensate and avoid false colors.
1080 * I didn't find any special stuff for 15 and 16BPP though, crest.
1086 rp
= blue
+ cmap
->index
;
1087 gp
= green
+ cmap
->index
;
1088 bp
= red
+ cmap
->index
;
1091 rp
= red
+ cmap
->index
;
1092 gp
= green
+ cmap
->index
;
1093 bp
= blue
+ cmap
->index
;
1101 *rp
++ = vgar(ba
, VDAC_DATA
) << 2;
1102 *gp
++ = vgar(ba
, VDAC_DATA
) << 2;
1103 *bp
++ = vgar(ba
, VDAC_DATA
) << 2;
1106 if (!(error
= copyout(red
+ cmap
->index
, cmap
->red
, cmap
->count
))
1107 && !(error
= copyout(green
+ cmap
->index
, cmap
->green
, cmap
->count
))
1108 && !(error
= copyout(blue
+ cmap
->index
, cmap
->blue
, cmap
->count
)))
1115 cl_putcmap(struct grf_softc
*gfp
, struct grf_colormap
*cmap
)
1117 volatile unsigned char *ba
;
1118 u_char red
[256], green
[256], blue
[256], *rp
, *gp
, *bp
;
1122 if (cmap
->count
== 0 || cmap
->index
>= 256)
1125 if (cmap
->count
> 256 - cmap
->index
)
1126 cmap
->count
= 256 - cmap
->index
;
1128 /* first copy the colors into kernelspace */
1129 if (!(error
= copyin(cmap
->red
, red
+ cmap
->index
, cmap
->count
))
1130 && !(error
= copyin(cmap
->green
, green
+ cmap
->index
, cmap
->count
))
1131 && !(error
= copyin(cmap
->blue
, blue
+ cmap
->index
, cmap
->count
))) {
1133 vgaw(ba
, VDAC_ADDRESS_W
, cmap
->index
);
1134 x
= cmap
->count
- 1;
1139 rp
= blue
+ cmap
->index
;
1140 gp
= green
+ cmap
->index
;
1141 bp
= red
+ cmap
->index
;
1144 rp
= red
+ cmap
->index
;
1145 gp
= green
+ cmap
->index
;
1146 bp
= blue
+ cmap
->index
;
1154 vgaw(ba
, VDAC_DATA
, *rp
++ >> 2);
1155 vgaw(ba
, VDAC_DATA
, *gp
++ >> 2);
1156 vgaw(ba
, VDAC_DATA
, *bp
++ >> 2);
1165 cl_toggle(struct grf_softc
*gp
, unsigned short wopp
)
1166 /* wopp: don't need that one yet, ill */
1172 if (cl_pass_toggle
) {
1181 cl_CompFQ(u_int fq
, u_char
*num
, u_char
*denom
, u_char
*clkdoub
)
1183 #define OSC 14318180
1184 /* OK, here's what we're doing here:
1187 * VCLK = ------------------- Hz
1188 * DENOMINATOR * (1+P)
1190 * so we're given VCLK and we should give out some useful
1193 * NUMERATOR is 7 bits wide
1194 * DENOMINATOR is 5 bits wide with bit P in the same char as bit 0.
1196 * We run through all the possible combinations and
1197 * return the values which deviate the least from the chosen frequency.
1200 #define OSC 14318180
1201 #define count(n,d,p) ((OSC * n)/(d * (1+p)))
1203 unsigned char n
, d
, p
, minn
, mind
, minp
= 0;
1204 unsigned long err
, minerr
;
1208 denom = 0x00 - 0x1f (1) 0x20 - 0x3e (even)
1211 /* find lowest error in 6144 iterations. */
1217 if ((cl_64bit
== 1) && (fq
>= 86000000))
1219 for (d
= 1; d
< 0x20; d
++) {
1220 for (n
= 1; n
< 0x80; n
++) {
1221 err
= abs(count(n
, d
, 0) - fq
);
1233 for (d
= 1; d
< 0x20; d
++) {
1234 for (n
= 1; n
< 0x80; n
++) {
1235 err
= abs(count(n
, d
, p
) - fq
);
1243 if (d
== 0x1f && p
== 0) {
1252 *denom
= (mind
<< 1) | minp
;
1253 if (minerr
> 500000)
1254 printf("Warning: CompFQ minimum error = %ld\n", minerr
);
1259 cl_mondefok(struct grfvideo_mode
*gv
)
1261 unsigned long maxpix
;
1263 if (gv
->mode_num
< 1 || gv
->mode_num
> monitor_def_max
)
1264 if (gv
->mode_num
!= 255 || gv
->depth
!= 4)
1267 switch (gv
->depth
) {
1269 if (gv
->mode_num
!= 255)
1273 maxpix
= cl_maxpixelclock
;
1276 if (cltype
== PICASSO
) /* Picasso IV */
1278 else /* Piccolo SD64 */
1287 maxpix
= cl_maxpixelclock
- (cl_maxpixelclock
/ 3);
1290 if ((cltype
== PICASSO
) && (cl_64bit
== 1))
1293 maxpix
= cl_maxpixelclock
/ 3;
1296 if ((cltype
== PICCOLO
) && (cl_64bit
== 1))
1302 printf("grfcl: Illegal depth in mode %d\n",
1303 (int) gv
->mode_num
);
1307 if (gv
->pixel_clock
> maxpix
) {
1308 printf("grfcl: Pixelclock too high in mode %d\n",
1309 (int) gv
->mode_num
);
1313 if (gv
->disp_flags
& GRF_FLAGS_SYNC_ON_GREEN
) {
1314 printf("grfcl: sync-on-green is not supported\n");
1322 cl_load_mon(struct grf_softc
*gp
, struct grfcltext_mode
*md
)
1324 struct grfvideo_mode
*gv
;
1326 volatile void *ba
, *fb
;
1327 unsigned char num0
, denom0
, clkdoub
;
1328 unsigned short HT
, HDE
, HBS
, HBE
, HSS
, HSE
, VDE
, VBS
, VBE
, VSS
,
1330 int clkmul
, offsmul
, clkmode
;
1333 unsigned char hvsync_pulse
;
1338 TEXT
= (gv
->depth
== 4);
1340 if (!cl_mondefok(gv
)) {
1341 printf("grfcl: Monitor definition not ok\n");
1348 /* provide all needed information in grf device-independent locations */
1349 gp
->g_data
= (void *) gv
;
1350 gi
= &gp
->g_display
;
1351 gi
->gd_regaddr
= (void *) kvtop(__UNVOLATILE(ba
));
1352 gi
->gd_regsize
= 64 * 1024;
1353 gi
->gd_fbaddr
= (void *) kvtop(__UNVOLATILE(fb
));
1354 gi
->gd_fbsize
= cl_fbsize
;
1355 gi
->gd_colors
= 1 << gv
->depth
;
1356 gi
->gd_planes
= gv
->depth
;
1357 gi
->gd_fbwidth
= gv
->disp_width
;
1358 gi
->gd_fbheight
= gv
->disp_height
;
1362 gi
->gd_dwidth
= md
->fx
* md
->cols
;
1363 gi
->gd_dheight
= md
->fy
* md
->rows
;
1365 gi
->gd_dwidth
= gv
->disp_width
;
1366 gi
->gd_dheight
= gv
->disp_height
;
1371 /* get display mode parameters */
1373 HBS
= gv
->hblank_start
;
1374 HSS
= gv
->hsync_start
;
1375 HSE
= gv
->hsync_stop
;
1376 HBE
= gv
->htotal
- 1;
1378 VBS
= gv
->vblank_start
;
1379 VSS
= gv
->vsync_start
;
1380 VSE
= gv
->vsync_stop
;
1381 VBE
= gv
->vtotal
- 1;
1385 HDE
= ((gv
->disp_width
+ md
->fx
- 1) / md
->fx
) - 1;
1387 HDE
= (gv
->disp_width
+ 3) / 8 - 1; /* HBS; */
1388 VDE
= gv
->disp_height
- 1;
1391 switch (gv
->depth
) {
1404 if ((cltype
== PICASSO
) && (cl_64bit
== 1)) /* Picasso IV */
1423 if ((VT
> 1023) && (!(gv
->disp_flags
& GRF_FLAGS_LACE
))) {
1424 WCrt(ba
, CRT_ID_MODE_CONTROL
, 0xe7);
1426 WCrt(ba
, CRT_ID_MODE_CONTROL
, 0xe3);
1429 if ((VT
> 1023) || (gv
->disp_flags
& GRF_FLAGS_LACE
))
1431 if (gv
->disp_flags
& GRF_FLAGS_DBLSCAN
)
1434 VDE
= VDE
* vmul
/ 2;
1435 VBS
= VBS
* vmul
/ 2;
1436 VSS
= VSS
* vmul
/ 2;
1437 VSE
= VSE
* vmul
/ 2;
1438 VBE
= VBE
* vmul
/ 2;
1441 WSeq(ba
, SEQ_ID_MEMORY_MODE
, (TEXT
|| (gv
->depth
== 1)) ? 0x06 : 0x0e);
1442 if (cl_64bit
== 1) {
1443 if (TEXT
|| (gv
->depth
== 1))
1446 sr15
= ((cl_fbsize
/ 0x100000 == 2) ? 0x38 : 0xb8);
1447 WSeq(ba
, SEQ_ID_CONF_RBACK
, 0x00);
1449 sr15
= (TEXT
|| (gv
->depth
== 1)) ? 0xd0 : 0xb0;
1450 sr15
&= ((cl_fbsize
/ 0x100000) == 2) ? 0xff : 0x7f;
1452 WSeq(ba
, SEQ_ID_DRAM_CNTL
, sr15
);
1453 WGfx(ba
, GCT_ID_READ_MAP_SELECT
, 0x00);
1454 WSeq(ba
, SEQ_ID_MAP_MASK
, (gv
->depth
== 1) ? 0x01 : 0xff);
1455 WSeq(ba
, SEQ_ID_CHAR_MAP_SELECT
, 0x00);
1459 cl_CompFQ(gv
->pixel_clock
* clkmul
, &num0
, &denom0
, &clkdoub
);
1461 /* Horizontal/Vertical Sync Pulse */
1462 hvsync_pulse
= vgar(ba
, GREG_MISC_OUTPUT_R
);
1463 if (gv
->disp_flags
& GRF_FLAGS_PHSYNC
)
1464 hvsync_pulse
&= ~0x40;
1466 hvsync_pulse
|= 0x40;
1467 if (gv
->disp_flags
& GRF_FLAGS_PVSYNC
)
1468 hvsync_pulse
&= ~0x80;
1470 hvsync_pulse
|= 0x80;
1471 vgaw(ba
, GREG_MISC_OUTPUT_W
, hvsync_pulse
);
1483 WSeq(ba
, SEQ_ID_VCLK_3_NUM
, num0
);
1484 WSeq(ba
, SEQ_ID_VCLK_3_DENOM
, denom0
);
1486 /* load display parameters into board */
1488 WCrt(ba
, CRT_ID_HOR_TOTAL
, HT
);
1489 WCrt(ba
, CRT_ID_HOR_DISP_ENA_END
, ((HDE
>= HBS
) ? HBS
- 1 : HDE
));
1490 WCrt(ba
, CRT_ID_START_HOR_BLANK
, HBS
);
1491 WCrt(ba
, CRT_ID_END_HOR_BLANK
, (HBE
& 0x1f) | 0x80); /* | 0x80? */
1492 WCrt(ba
, CRT_ID_START_HOR_RETR
, HSS
);
1493 WCrt(ba
, CRT_ID_END_HOR_RETR
,
1495 ((HBE
& 0x20) ? 0x80 : 0x00));
1496 WCrt(ba
, CRT_ID_VER_TOTAL
, VT
);
1497 WCrt(ba
, CRT_ID_OVERFLOW
,
1499 ((VT
& 0x100) ? 0x01 : 0x00) |
1500 ((VDE
& 0x100) ? 0x02 : 0x00) |
1501 ((VSS
& 0x100) ? 0x04 : 0x00) |
1502 ((VBS
& 0x100) ? 0x08 : 0x00) |
1503 ((VT
& 0x200) ? 0x20 : 0x00) |
1504 ((VDE
& 0x200) ? 0x40 : 0x00) |
1505 ((VSS
& 0x200) ? 0x80 : 0x00));
1507 WCrt(ba
, CRT_ID_CHAR_HEIGHT
,
1508 0x40 | /* TEXT ? 0x00 ??? */
1509 ((gv
->disp_flags
& GRF_FLAGS_DBLSCAN
) ? 0x80 : 0x00) |
1510 ((VBS
& 0x200) ? 0x20 : 0x00) |
1511 (TEXT
? ((md
->fy
- 1) & 0x1f) : 0x00));
1517 WCrt(ba
, CRT_ID_CURSOR_START
, (md
->fy
& 0x1f) - 2);
1518 WCrt(ba
, CRT_ID_CURSOR_END
, (md
->fy
& 0x1f) - 1);
1520 WCrt(ba
, CRT_ID_CURSOR_START
, 0x00);
1521 WCrt(ba
, CRT_ID_CURSOR_END
, md
->fy
& 0x1f);
1523 WCrt(ba
, CRT_ID_UNDERLINE_LOC
, (md
->fy
- 1) & 0x1f);
1525 WCrt(ba
, CRT_ID_CURSOR_LOC_HIGH
, 0x00);
1526 WCrt(ba
, CRT_ID_CURSOR_LOC_LOW
, 0x00);
1528 WCrt(ba
, CRT_ID_START_ADDR_HIGH
, 0x00);
1529 WCrt(ba
, CRT_ID_START_ADDR_LOW
, 0x00);
1531 WCrt(ba
, CRT_ID_START_VER_RETR
, VSS
);
1532 WCrt(ba
, CRT_ID_END_VER_RETR
, (VSE
& 0x0f) | 0x20);
1533 WCrt(ba
, CRT_ID_VER_DISP_ENA_END
, VDE
);
1534 WCrt(ba
, CRT_ID_START_VER_BLANK
, VBS
);
1535 WCrt(ba
, CRT_ID_END_VER_BLANK
, VBE
);
1537 WCrt(ba
, CRT_ID_LINE_COMPARE
, 0xff);
1538 WCrt(ba
, CRT_ID_LACE_END
, HT
/ 2); /* MW/16 */
1539 WCrt(ba
, CRT_ID_LACE_CNTL
,
1540 ((gv
->disp_flags
& GRF_FLAGS_LACE
) ? 0x01 : 0x00) |
1541 ((HBE
& 0x40) ? 0x10 : 0x00) |
1542 ((HBE
& 0x80) ? 0x20 : 0x00) |
1543 ((VBE
& 0x100) ? 0x40 : 0x00) |
1544 ((VBE
& 0x200) ? 0x80 : 0x00));
1546 WGfx(ba
, GCT_ID_GRAPHICS_MODE
,
1547 ((TEXT
|| (gv
->depth
== 1)) ? 0x00 : 0x40));
1548 WGfx(ba
, GCT_ID_MISC
, (TEXT
? 0x04 : 0x01));
1550 WSeq(ba
, SEQ_ID_EXT_SEQ_MODE
,
1551 ((TEXT
|| (gv
->depth
== 1)) ? 0x00 : 0x01) |
1552 ((cltype
== PICASSO
) ? 0x20 : 0x80) | clkmode
);
1554 /* write 0x00 to VDAC_MASK before accessing HDR this helps
1555 sometimes, out of "secret" application note (crest) */
1556 vgaw(ba
, VDAC_MASK
, 0);
1557 /* reset HDR "magic" access counter (crest) */
1558 vgar(ba
, VDAC_ADDRESS
);
1561 vgar(ba
, VDAC_MASK
);
1563 vgar(ba
, VDAC_MASK
);
1565 vgar(ba
, VDAC_MASK
);
1567 vgar(ba
, VDAC_MASK
);
1569 switch (gv
->depth
) {
1572 vgaw(ba
, VDAC_MASK
, 0);
1573 HDE
= gv
->disp_width
/ 16;
1577 vgaw(ba
, VDAC_MASK
, 0x4a); /* Clockdouble Magic */
1579 vgaw(ba
, VDAC_MASK
, 0);
1580 HDE
= gv
->disp_width
/ 8;
1583 vgaw(ba
, VDAC_MASK
, 0xd0);
1584 HDE
= gv
->disp_width
/ 4;
1587 vgaw(ba
, VDAC_MASK
, 0xc1);
1588 HDE
= gv
->disp_width
/ 4;
1591 vgaw(ba
, VDAC_MASK
, 0xc5);
1592 HDE
= (gv
->disp_width
/ 8) * 3;
1595 vgaw(ba
, VDAC_MASK
, 0xc5);
1596 HDE
= (gv
->disp_width
/ 4);
1600 /* reset HDR "magic" access counter (crest) */
1601 vgar(ba
, VDAC_ADDRESS
);
1602 /* then enable all bit in VDAC_MASK afterwards (crest) */
1603 vgaw(ba
, VDAC_MASK
, 0xff);
1605 WCrt(ba
, CRT_ID_OFFSET
, HDE
);
1606 if (cl_64bit
== 1) {
1607 WCrt(ba
, CRT_ID_SYNC_ADJ_GENLOCK
, 0x00);
1608 WCrt(ba
, CRT_ID_OVERLAY_EXT_CTRL_REG
, 0x40);
1610 WCrt(ba
, CRT_ID_EXT_DISP_CNTL
,
1611 ((TEXT
&& gv
->pixel_clock
> 29000000) ? 0x40 : 0x00) |
1613 ((HDE
> 0xff) ? 0x10 : 0x00));
1615 WAttr(ba
, ACT_ID_ATTR_MODE_CNTL
, (TEXT
? 0x0a : 0x01));
1616 WAttr(ba
, 0x20 | ACT_ID_COLOR_PLANE_ENA
,
1617 (gv
->depth
== 1) ? 0x01 : 0x0f);
1619 /* text initialization */
1622 cl_inittextmode(gp
);
1624 WSeq(ba
, SEQ_ID_CURSOR_ATTR
, 0x14);
1625 WSeq(ba
, SEQ_ID_CLOCKING_MODE
, 0x01);
1635 cl_inittextmode(struct grf_softc
*gp
)
1637 struct grfcltext_mode
*tm
= (struct grfcltext_mode
*) gp
->g_data
;
1638 volatile unsigned char *ba
= gp
->g_regkva
;
1639 unsigned char *fb
= __UNVOLATILE(gp
->g_fbkva
);
1640 unsigned char *c
, *f
, y
;
1644 /* load text font into beginning of display memory. Each character
1645 * cell is 32 bytes long (enough for 4 planes) */
1647 SetTextPlane(ba
, 0x02);
1648 cl_memset(fb
, 0, 256 * 32);
1649 c
= (unsigned char *) (fb
) + (32 * tm
->fdstart
);
1651 for (z
= tm
->fdstart
; z
<= tm
->fdend
; z
++, c
+= (32 - tm
->fy
))
1652 for (y
= 0; y
< tm
->fy
; y
++)
1655 /* clear out text/attr planes (three screens worth) */
1657 SetTextPlane(ba
, 0x01);
1658 cl_memset(fb
, 0x07, tm
->cols
* tm
->rows
* 3);
1659 SetTextPlane(ba
, 0x00);
1660 cl_memset(fb
, 0x20, tm
->cols
* tm
->rows
* 3);
1662 /* print out a little init msg */
1664 c
= (unsigned char *) (fb
) + (tm
->cols
- 16);
1665 strcpy(c
, "CIRRUS");
1668 /* set colors (B&W) */
1670 vgaw(ba
, VDAC_ADDRESS_W
, 0);
1671 for (z
= 0; z
< 256; z
++) {
1672 unsigned char r
, g
, b
;
1674 y
= (z
& 1) ? ((z
> 7) ? 2 : 1) : 0;
1676 if (cltype
== PICASSO
) {
1677 r
= clconscolors
[y
][0];
1678 g
= clconscolors
[y
][1];
1679 b
= clconscolors
[y
][2];
1681 b
= clconscolors
[y
][0];
1682 g
= clconscolors
[y
][1];
1683 r
= clconscolors
[y
][2];
1685 vgaw(ba
, VDAC_DATA
, r
>> 2);
1686 vgaw(ba
, VDAC_DATA
, g
>> 2);
1687 vgaw(ba
, VDAC_DATA
, b
>> 2);
1692 cl_memset(unsigned char *d
, unsigned char c
, int l
)
1699 * Special wakeup/passthrough registers on graphics boards
1701 * The methods have diverged a bit for each board, so
1702 * WPass(P) has been converted into a set of specific
1706 RegWakeup(volatile void *ba
)
1711 vgaw(ba
, PASS_ADDRESS_W
, 0x1f);
1714 /* Picasso needs no wakeup */
1718 vgaw(ba
, PASS_ADDRESS_W
, 0x1f);
1720 vgaw(ba
, PASS_ADDRESS_W
, vgar(ba
, PASS_ADDRESS
) | 0x10);
1727 RegOnpass(volatile void *ba
)
1732 vgaw(ba
, PASS_ADDRESS_W
, 0x4f);
1736 vgaw(ba
, PASS_ADDRESS_WP
, 0x01);
1740 vgaw(ba
, PASS_ADDRESS_W
, 0x4f);
1742 vgaw(ba
, PASS_ADDRESS_W
, vgar(ba
, PASS_ADDRESS
) & 0xdf);
1750 RegOffpass(volatile void *ba
)
1755 vgaw(ba
, PASS_ADDRESS_W
, 0x6f);
1759 vgaw(ba
, PASS_ADDRESS_W
, 0xff);
1763 vgaw(ba
, PASS_ADDRESS_W
, 0x6f);
1765 vgaw(ba
, PASS_ADDRESS_W
, vgar(ba
, PASS_ADDRESS
) | 0x20);