grf_cl.c revision 1.3 1 1.1 chopps
2 1.1 chopps /*
3 1.1 chopps * Copyright (c) 1995 Ezra Story
4 1.1 chopps * Copyright (c) 1995 Kari Mettinen
5 1.1 chopps * Copyright (c) 1994 Markus Wild
6 1.1 chopps * Copyright (c) 1994 Lutz Vieweg
7 1.1 chopps * All rights reserved.
8 1.1 chopps *
9 1.1 chopps * Redistribution and use in source and binary forms, with or without
10 1.1 chopps * modification, are permitted provided that the following conditions
11 1.1 chopps * are met:
12 1.1 chopps * 1. Redistributions of source code must retain the above copyright
13 1.1 chopps * notice, this list of conditions and the following disclaimer.
14 1.1 chopps * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 chopps * notice, this list of conditions and the following disclaimer in the
16 1.1 chopps * documentation and/or other materials provided with the distribution.
17 1.1 chopps * 3. All advertising materials mentioning features or use of this software
18 1.1 chopps * must display the following acknowledgement:
19 1.1 chopps * This product includes software developed by Lutz Vieweg.
20 1.1 chopps * 4. The name of the author may not be used to endorse or promote products
21 1.1 chopps * derived from this software without specific prior written permission
22 1.1 chopps *
23 1.1 chopps * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 chopps * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 chopps * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 chopps * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 chopps * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 chopps * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 chopps * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 chopps * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 chopps * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 chopps * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 chopps */
34 1.1 chopps
35 1.1 chopps #ifdef GRF_CL5426
36 1.1 chopps /*
37 1.1 chopps * Graphics routines for Cirrus CL GD 5426 boards,
38 1.1 chopps *
39 1.1 chopps * This code offers low-level routines to access Cirrus Cl GD 5426
40 1.1 chopps * graphics-boards from within NetBSD for the Amiga.
41 1.1 chopps * No warranties for any kind of function at all - this
42 1.1 chopps * code may crash your hardware and scratch your harddisk. Use at your
43 1.1 chopps * own risk. Freely distributable.
44 1.1 chopps *
45 1.1 chopps * Modified for Cirrus CL GD 5426 from
46 1.1 chopps * Lutz Vieweg's retina driver by Kari Mettinen 08/94
47 1.1 chopps * Contributions by Ill, ScottE, MiL
48 1.1 chopps * Extensively hacked and rewritten by Ezra Story (Ezy) 01/95
49 1.1 chopps *
50 1.1 chopps * Thanks to Village Tronic Marketing Gmbh for providing me with
51 1.1 chopps * a Picasso-II board.
52 1.1 chopps * Thanks for Integrated Electronics Oy Ab for providing me with
53 1.1 chopps * Cirrus CL GD 542x family documentation.
54 1.1 chopps *
55 1.1 chopps * TODO:
56 1.1 chopps * Mouse support
57 1.1 chopps * Blitter support
58 1.1 chopps *
59 1.1 chopps */
60 1.1 chopps
61 1.1 chopps #include <sys/param.h>
62 1.1 chopps #include <sys/errno.h>
63 1.1 chopps #include <sys/ioctl.h>
64 1.1 chopps #include <sys/device.h>
65 1.1 chopps #include <sys/malloc.h>
66 1.1 chopps #include <machine/cpu.h>
67 1.1 chopps #include <dev/cons.h>
68 1.1 chopps #include <amiga/amiga/device.h>
69 1.1 chopps #include <amiga/dev/grfioctl.h>
70 1.1 chopps #include <amiga/dev/grfvar.h>
71 1.1 chopps #include <amiga/dev/grf_clreg.h>
72 1.1 chopps #include <amiga/dev/zbusvar.h>
73 1.1 chopps
74 1.1 chopps static int cl_mondefok __P((struct grfvideo_mode *mdp));
75 1.1 chopps static void cl_boardinit();
76 1.1 chopps static void CompFQ __P((u_int fq, u_char *num, u_char *denom));
77 1.1 chopps static int cl_getvmode __P((struct grf_softc *gp, struct grfvideo_mode *vm));
78 1.1 chopps static int cl_setvmode __P((struct grf_softc *gp, unsigned int mode));
79 1.1 chopps static int cl_toggle __P((struct grf_softc *gp,unsigned short));
80 1.1 chopps static int cl_getcmap __P((struct grf_softc *gfp, struct grf_colormap *cmap));
81 1.1 chopps static int cl_putcmap __P((struct grf_softc *gfp, struct grf_colormap *cmap));
82 1.1 chopps static void cl_off __P((struct grf_softc *gp));
83 1.1 chopps static void cl_inittextmode __P((struct grf_softc *gp));
84 1.1 chopps static int cl_ioctl __P((register struct grf_softc *gp, int cmd, void *data));
85 1.1 chopps
86 1.1 chopps void grfclattach __P((struct device *, struct device *, void *));
87 1.1 chopps int grfclprint __P((void *, char *));
88 1.1 chopps int grfclmatch __P((struct device *, struct cfdata *, void *));
89 1.1 chopps void memset __P((unsigned char *d, unsigned char c, int l));
90 1.1 chopps
91 1.1 chopps /* Graphics display definitions.
92 1.1 chopps * These are filled by 'grfconfig' using GRFIOCSETMON.
93 1.1 chopps */
94 1.1 chopps #define monitor_def_max 8
95 1.1 chopps static struct grfvideo_mode monitor_def[8] = {
96 1.1 chopps {0}, {0}, {0}, {0}, {0}, {0}, {0}, {0}
97 1.1 chopps };
98 1.1 chopps static struct grfvideo_mode *monitor_current = &monitor_def[0];
99 1.1 chopps
100 1.1 chopps /* Patchable maximum pixel clock */
101 1.1 chopps unsigned long cl_maxpixelclock = 115000000;
102 1.1 chopps
103 1.1 chopps /* Console display definition.
104 1.1 chopps * Default hardcoded text mode. This grf_cl is set up to
105 1.1 chopps * use one text mode only, and this is it. You may use
106 1.1 chopps * grfconfig to change the mode after boot.
107 1.1 chopps */
108 1.1 chopps /* Console font */
109 1.2 chopps #ifdef KFONT_8X11
110 1.2 chopps #define CIRRUSFONT kernel_font_8x11
111 1.2 chopps #define CIRRUSFONTY 11
112 1.2 chopps #else
113 1.1 chopps #define CIRRUSFONT kernel_font_8x8
114 1.1 chopps #define CIRRUSFONTY 8
115 1.2 chopps #endif
116 1.1 chopps extern unsigned char CIRRUSFONT[];
117 1.1 chopps
118 1.1 chopps struct grfcltext_mode clconsole_mode = {
119 1.1 chopps {255, "", 25200000, 640, 480, 4, 80, 94, 99, 100, 100, 481, 490,
120 1.1 chopps 498, 522, 522},
121 1.1 chopps 8, CIRRUSFONTY, 80, 480/CIRRUSFONTY, CIRRUSFONT, 32, 255
122 1.1 chopps };
123 1.1 chopps
124 1.1 chopps /* Console colors */
125 1.1 chopps unsigned char clconscolors[3][3] = { /* background, foreground, hilite */
126 1.1 chopps {0,0x40,0x50}, {152,152,152}, {255,255,255}
127 1.1 chopps };
128 1.1 chopps
129 1.1 chopps int cltype = 0; /* Picasso, Spectrum or Piccolo */
130 1.1 chopps unsigned char pass_toggle; /* passthru status tracker */
131 1.1 chopps
132 1.1 chopps /* because all 5426-boards have 2 configdev entries, one for
133 1.1 chopps * framebuffer mem and the other for regs, we have to hold onto
134 1.1 chopps * the pointers globally until we match on both. This and 'cltype'
135 1.1 chopps * are the primary obsticles to multiple board support, but if you
136 1.1 chopps * have multiple boards you have bigger problems than grf_cl.
137 1.1 chopps */
138 1.1 chopps static void *cl_fbaddr = 0; /* framebuffer */
139 1.1 chopps static void *cl_regaddr = 0; /* registers */
140 1.1 chopps static int cl_fbsize; /* framebuffer size */
141 1.1 chopps
142 1.1 chopps /* standard driver stuff */
143 1.1 chopps struct cfdriver grfclcd = {
144 1.1 chopps NULL, "grfcl", (cfmatch_t)grfclmatch, grfclattach,
145 1.1 chopps DV_DULL, sizeof(struct grf_softc), NULL, 0
146 1.1 chopps };
147 1.1 chopps static struct cfdata *cfdata;
148 1.1 chopps
149 1.1 chopps int
150 1.1 chopps grfclmatch(pdp, cfp, auxp)
151 1.1 chopps struct device *pdp;
152 1.1 chopps struct cfdata *cfp;
153 1.1 chopps void *auxp;
154 1.1 chopps {
155 1.1 chopps struct zbus_args *zap;
156 1.1 chopps static int regprod, fbprod;
157 1.1 chopps
158 1.1 chopps zap = auxp;
159 1.1 chopps
160 1.1 chopps #ifndef CL5426CONSOLE
161 1.1 chopps if (amiga_realconfig == 0)
162 1.1 chopps return(0);
163 1.1 chopps #endif
164 1.1 chopps
165 1.1 chopps /* Grab the first board we encounter as the preferred one.
166 1.1 chopps * This will allow one board to work in a multiple 5426 board
167 1.1 chopps * system, but not multiple boards at the same time.
168 1.1 chopps */
169 1.1 chopps if (cltype == 0) {
170 1.1 chopps switch (zap->manid) {
171 1.1 chopps case PICASSO:
172 1.3 chopps if (zap->prodid != 12 && zap->prodid != 11)
173 1.3 chopps return (0);
174 1.1 chopps regprod = 12;
175 1.1 chopps fbprod = 11;
176 1.1 chopps break;
177 1.1 chopps case SPECTRUM:
178 1.3 chopps if (zap->prodid != 2 && zap->prodid != 1)
179 1.3 chopps return (0);
180 1.1 chopps regprod = 2;
181 1.1 chopps fbprod = 1;
182 1.1 chopps break;
183 1.1 chopps case PICCOLO:
184 1.3 chopps if (zap->prodid != 6 && zap->prodid != 5)
185 1.3 chopps return (0);
186 1.1 chopps regprod = 6;
187 1.1 chopps fbprod = 5;
188 1.1 chopps break;
189 1.1 chopps default:
190 1.1 chopps return(0);
191 1.1 chopps }
192 1.1 chopps cltype = zap->manid;
193 1.1 chopps } else {
194 1.1 chopps if (cltype != zap->manid) {
195 1.1 chopps return(0);
196 1.1 chopps }
197 1.1 chopps }
198 1.1 chopps
199 1.1 chopps /* Configure either registers or framebuffer in any order
200 1.1 chopps */
201 1.1 chopps if (zap->prodid == regprod)
202 1.1 chopps cl_regaddr = zap->va;
203 1.1 chopps else if (zap->prodid == fbprod) {
204 1.1 chopps cl_fbaddr = zap->va;
205 1.1 chopps cl_fbsize = zap->size;
206 1.1 chopps } else {
207 1.1 chopps printf("grfcl: Bad product id\n");
208 1.1 chopps return(0);
209 1.1 chopps }
210 1.1 chopps
211 1.1 chopps #ifdef CL5426CONSOLE
212 1.1 chopps if (amiga_realconfig == 0) {
213 1.1 chopps cfdata = cfp;
214 1.1 chopps }
215 1.1 chopps
216 1.1 chopps #endif
217 1.1 chopps
218 1.1 chopps return(1);
219 1.1 chopps }
220 1.1 chopps
221 1.1 chopps void
222 1.1 chopps grfclattach(pdp, dp, auxp)
223 1.1 chopps struct device *pdp, *dp;
224 1.1 chopps void *auxp;
225 1.1 chopps {
226 1.1 chopps static struct grf_softc congrf;
227 1.1 chopps struct zbus_args *zap;
228 1.1 chopps struct grf_softc *gp;
229 1.1 chopps int x;
230 1.1 chopps static char attachflag = 0;
231 1.1 chopps
232 1.1 chopps zap = auxp;
233 1.1 chopps
234 1.1 chopps printf("\n");
235 1.1 chopps
236 1.1 chopps /* make sure both halves have matched */
237 1.1 chopps if (!cl_regaddr || !cl_fbaddr)
238 1.1 chopps return;
239 1.1 chopps
240 1.1 chopps /* do all that messy console/grf stuff */
241 1.1 chopps if (dp == NULL)
242 1.1 chopps gp = &congrf;
243 1.1 chopps else
244 1.1 chopps gp = (struct grf_softc *)dp;
245 1.1 chopps
246 1.1 chopps if (dp != NULL && congrf.g_regkva != 0) {
247 1.1 chopps /*
248 1.1 chopps * inited earlier, just copy (not device struct)
249 1.1 chopps */
250 1.1 chopps bcopy(&congrf.g_display, &gp->g_display,
251 1.1 chopps (char *)&gp[1] - (char *)&gp->g_display);
252 1.1 chopps } else {
253 1.1 chopps gp->g_regkva = (volatile caddr_t)cl_regaddr;
254 1.1 chopps gp->g_fbkva = (volatile caddr_t)cl_fbaddr;
255 1.1 chopps
256 1.1 chopps gp->g_unit = GRF_CL5426_UNIT;
257 1.1 chopps gp->g_mode = cl_mode;
258 1.1 chopps gp->g_conpri = grfcl_cnprobe();
259 1.1 chopps gp->g_flags = GF_ALIVE;
260 1.1 chopps
261 1.1 chopps /* wakeup the board */
262 1.1 chopps cl_boardinit(gp);
263 1.1 chopps
264 1.1 chopps #ifdef CL5426CONSOLE
265 1.1 chopps grfcl_iteinit(gp);
266 1.1 chopps (void)cl_load_mon(gp, &clconsole_mode);
267 1.1 chopps #endif
268 1.1 chopps
269 1.1 chopps }
270 1.1 chopps
271 1.1 chopps /*
272 1.1 chopps * attach grf (once)
273 1.1 chopps */
274 1.1 chopps if (amiga_config_found(cfdata, &gp->g_device, gp, grfclprint)) {
275 1.1 chopps attachflag = 1;
276 1.1 chopps printf("grfcl: %dMB ", cl_fbsize/0x100000);
277 1.1 chopps switch (cltype) {
278 1.1 chopps case PICASSO:
279 1.1 chopps printf("Picasso II");
280 1.1 chopps break;
281 1.1 chopps case SPECTRUM:
282 1.1 chopps printf("Spectrum");
283 1.1 chopps break;
284 1.1 chopps case PICCOLO:
285 1.1 chopps printf("Piccolo");
286 1.1 chopps break;
287 1.1 chopps }
288 1.1 chopps printf(" being used\n");
289 1.1 chopps } else {
290 1.1 chopps if (!attachflag)
291 1.1 chopps printf("grfcl unattached!!\n");
292 1.1 chopps }
293 1.1 chopps }
294 1.1 chopps
295 1.1 chopps int
296 1.1 chopps grfclprint(auxp, pnp)
297 1.1 chopps void *auxp;
298 1.1 chopps char *pnp;
299 1.1 chopps {
300 1.1 chopps if (pnp)
301 1.1 chopps printf("ite at %s: ", pnp);
302 1.1 chopps return(UNCONF);
303 1.1 chopps }
304 1.1 chopps
305 1.1 chopps void
306 1.1 chopps cl_boardinit(gp)
307 1.1 chopps struct grf_softc *gp;
308 1.1 chopps {
309 1.1 chopps unsigned char *ba = gp->g_regkva;
310 1.1 chopps int x;
311 1.1 chopps void *bah;
312 1.1 chopps
313 1.1 chopps /* wakeup board and flip passthru OFF */
314 1.1 chopps
315 1.1 chopps RegWakeup(ba);
316 1.1 chopps RegOnpass(ba);
317 1.1 chopps
318 1.1 chopps vgaw(ba, 0x46e8, 0x16);
319 1.1 chopps vgaw(ba, 0x102, 1);
320 1.1 chopps vgaw(ba, 0x46e8, 0x0e);
321 1.1 chopps vgaw(ba, 0x3c3, 1);
322 1.1 chopps
323 1.1 chopps /* setup initial unchanging parameters */
324 1.1 chopps
325 1.1 chopps WSeq(ba, SEQ_ID_CLOCKING_MODE, 0x21); /* 8 dot - display off */
326 1.1 chopps vgaw(ba, GREG_MISC_OUTPUT_W, 0xe1); /* mem disable */
327 1.1 chopps
328 1.1 chopps WGfx(ba, GCT_ID_OFFSET_1, 0xec); /* magic cookie */
329 1.1 chopps WSeq(ba, SEQ_ID_UNLOCK_EXT, 0x12); /* yum! cookies! */
330 1.1 chopps
331 1.1 chopps WSeq(ba, SEQ_ID_DRAM_CNTL, 0xb0);
332 1.1 chopps WSeq(ba, SEQ_ID_RESET, 0x03);
333 1.1 chopps WSeq(ba, SEQ_ID_MAP_MASK, 0xff);
334 1.1 chopps WSeq(ba, SEQ_ID_CHAR_MAP_SELECT, 0x00);
335 1.1 chopps WSeq(ba, SEQ_ID_MEMORY_MODE, 0x0e); /* a or 6? */
336 1.1 chopps WSeq(ba, SEQ_ID_EXT_SEQ_MODE, (cltype == PICASSO) ? 0x20 : 0x80);
337 1.1 chopps WSeq(ba, SEQ_ID_EEPROM_CNTL, 0x00);
338 1.1 chopps WSeq(ba, SEQ_ID_PERF_TUNE, 0x0a);
339 1.1 chopps WSeq(ba, SEQ_ID_SIG_CNTL, 0x02);
340 1.1 chopps
341 1.1 chopps WSeq(ba, SEQ_ID_MCLK_SELECT, 0x22);
342 1.1 chopps
343 1.1 chopps WCrt(ba, CRT_ID_PRESET_ROW_SCAN, 0x00);
344 1.1 chopps WCrt(ba, CRT_ID_CURSOR_START, 0x00);
345 1.1 chopps WCrt(ba, CRT_ID_CURSOR_END, 0x08);
346 1.1 chopps WCrt(ba, CRT_ID_START_ADDR_HIGH, 0x00);
347 1.1 chopps WCrt(ba, CRT_ID_START_ADDR_LOW, 0x00);
348 1.1 chopps WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
349 1.1 chopps WCrt(ba, CRT_ID_CURSOR_LOC_LOW, 0x00);
350 1.1 chopps
351 1.1 chopps WCrt(ba, CRT_ID_UNDERLINE_LOC, 0x07);
352 1.1 chopps WCrt(ba, CRT_ID_MODE_CONTROL, 0xa3); /* c3 */
353 1.1 chopps WCrt(ba, CRT_ID_LINE_COMPARE, 0xff); /* ff */
354 1.1 chopps WCrt(ba, CRT_ID_EXT_DISP_CNTL, 0x22);
355 1.1 chopps WSeq(ba, SEQ_ID_CURSOR_STORE, 0x00);
356 1.1 chopps
357 1.1 chopps WGfx(ba, GCT_ID_SET_RESET, 0x00);
358 1.1 chopps WGfx(ba, GCT_ID_ENABLE_SET_RESET, 0x00);
359 1.1 chopps WGfx(ba, GCT_ID_DATA_ROTATE, 0x00);
360 1.1 chopps WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
361 1.1 chopps WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x00);
362 1.1 chopps WGfx(ba, GCT_ID_MISC, 0x01);
363 1.1 chopps WGfx(ba, GCT_ID_COLOR_XCARE, 0x0f);
364 1.1 chopps WGfx(ba, GCT_ID_BITMASK, 0xff);
365 1.1 chopps WGfx(ba, GCT_ID_MODE_EXT, 0x28);
366 1.1 chopps
367 1.1 chopps for (x=0; x< 0x10; x++)
368 1.1 chopps WAttr(ba, x, x);
369 1.1 chopps WAttr(ba, ACT_ID_ATTR_MODE_CNTL, 0x01);
370 1.1 chopps WAttr(ba, ACT_ID_OVERSCAN_COLOR, 0x00);
371 1.1 chopps WAttr(ba, ACT_ID_COLOR_PLANE_ENA, 0x0f);
372 1.1 chopps WAttr(ba, ACT_ID_HOR_PEL_PANNING, 0x00);
373 1.1 chopps WAttr(ba, ACT_ID_COLOR_SELECT, 0x00);
374 1.1 chopps
375 1.1 chopps delay(200000);
376 1.1 chopps WAttr(ba, 0x34, 0x00);
377 1.1 chopps delay(200000);
378 1.1 chopps
379 1.1 chopps vgaw(ba, VDAC_MASK, 0xff);
380 1.1 chopps delay(200000);
381 1.1 chopps vgaw(ba, GREG_MISC_OUTPUT_W, 0xe3); /* c3 */
382 1.1 chopps
383 1.1 chopps WGfx(ba, GCT_ID_BLT_STAT_START, 0x40);
384 1.1 chopps WGfx(ba, GCT_ID_BLT_STAT_START, 0x00);
385 1.1 chopps
386 1.1 chopps /* colors initially set to greyscale */
387 1.1 chopps
388 1.1 chopps vgaw(ba, VDAC_ADDRESS_W, 0);
389 1.1 chopps for (x = 255; x >= 0 ; x--) {
390 1.1 chopps vgaw(ba, VDAC_DATA, x);
391 1.1 chopps vgaw(ba, VDAC_DATA, x);
392 1.1 chopps vgaw(ba, VDAC_DATA, x);
393 1.1 chopps }
394 1.1 chopps }
395 1.1 chopps
396 1.1 chopps
397 1.1 chopps int
398 1.1 chopps cl_getvmode(gp, vm)
399 1.1 chopps struct grf_softc *gp;
400 1.1 chopps struct grfvideo_mode *vm;
401 1.1 chopps {
402 1.1 chopps struct grfvideo_mode *gv;
403 1.1 chopps
404 1.1 chopps #ifdef CL5426CONSOLE
405 1.1 chopps /* Handle grabbing console mode */
406 1.1 chopps if (vm->mode_num == 255) {
407 1.1 chopps bcopy(&clconsole_mode, vm, sizeof(struct grfvideo_mode));
408 1.1 chopps /* XXX so grfconfig can tell us the correct text
409 1.1 chopps * dimensions.
410 1.1 chopps */
411 1.1 chopps vm->depth = clconsole_mode.fy;
412 1.1 chopps return(0);
413 1.1 chopps }
414 1.1 chopps #endif
415 1.1 chopps if (vm->mode_num && vm->mode_num > monitor_def_max)
416 1.1 chopps return(EINVAL);
417 1.1 chopps
418 1.1 chopps if (!vm->mode_num)
419 1.1 chopps vm->mode_num = (monitor_current - monitor_def) + 1;
420 1.1 chopps
421 1.1 chopps gv = monitor_def + (vm->mode_num - 1);
422 1.1 chopps if (gv->mode_num == 0)
423 1.1 chopps return(EINVAL);
424 1.1 chopps
425 1.1 chopps bcopy(gv, vm, sizeof(struct grfvideo_mode));
426 1.1 chopps return(0);
427 1.1 chopps }
428 1.1 chopps
429 1.1 chopps
430 1.1 chopps int
431 1.1 chopps cl_setvmode(gp, mode)
432 1.1 chopps struct grf_softc *gp;
433 1.1 chopps unsigned mode;
434 1.1 chopps {
435 1.1 chopps struct grfvideo_mode *gv;
436 1.1 chopps
437 1.1 chopps if (!mode || (mode > monitor_def_max) ||
438 1.1 chopps monitor_def[mode-1].mode_num == 0)
439 1.1 chopps return(EINVAL);
440 1.1 chopps
441 1.1 chopps monitor_current = monitor_def + (mode - 1);
442 1.1 chopps
443 1.1 chopps
444 1.1 chopps return(0);
445 1.1 chopps }
446 1.1 chopps
447 1.1 chopps void
448 1.1 chopps cl_off(gp)
449 1.1 chopps struct grf_softc *gp;
450 1.1 chopps {
451 1.1 chopps char *ba = gp->g_regkva;
452 1.1 chopps
453 1.1 chopps /* we'll put the pass-through on for cc ite and set Full Bandwidth
454 1.1 chopps * bit on just in case it didn't work...but then it doesn't matter
455 1.1 chopps * does it? =)
456 1.1 chopps */
457 1.1 chopps RegOnpass(ba);
458 1.1 chopps WSeq(ba, SEQ_ID_CLOCKING_MODE, 0x21);
459 1.1 chopps }
460 1.1 chopps
461 1.1 chopps /*
462 1.1 chopps * Change the mode of the display.
463 1.1 chopps * Return a UNIX error number or 0 for success.
464 1.1 chopps */
465 1.1 chopps cl_mode(gp, cmd, arg, a2, a3)
466 1.1 chopps register struct grf_softc *gp;
467 1.1 chopps int cmd;
468 1.1 chopps void *arg;
469 1.1 chopps int a2, a3;
470 1.1 chopps {
471 1.1 chopps int error;
472 1.1 chopps
473 1.1 chopps switch (cmd) {
474 1.1 chopps case GM_GRFON:
475 1.1 chopps error = cl_load_mon (gp,
476 1.1 chopps (struct grfcltext_mode *) monitor_current) ? 0 : EINVAL;
477 1.1 chopps return(error);
478 1.1 chopps
479 1.1 chopps case GM_GRFOFF:
480 1.1 chopps #ifndef CL5426CONSOLE
481 1.1 chopps cl_off(gp);
482 1.1 chopps #else
483 1.1 chopps cl_load_mon(gp, &clconsole_mode);
484 1.1 chopps #endif
485 1.1 chopps return(0);
486 1.1 chopps
487 1.1 chopps case GM_GRFCONFIG:
488 1.1 chopps return(0);
489 1.1 chopps
490 1.1 chopps case GM_GRFGETVMODE:
491 1.1 chopps return(cl_getvmode (gp, (struct grfvideo_mode *) arg));
492 1.1 chopps
493 1.1 chopps case GM_GRFSETVMODE:
494 1.1 chopps error = cl_setvmode (gp, *(unsigned *) arg);
495 1.1 chopps if (!error && (gp->g_flags & GF_GRFON))
496 1.1 chopps cl_load_mon(gp,
497 1.1 chopps (struct grfcltext_mode *) monitor_current);
498 1.1 chopps return(error);
499 1.1 chopps
500 1.1 chopps case GM_GRFGETNUMVM:
501 1.1 chopps *(int *)arg = monitor_def_max;
502 1.1 chopps return(0);
503 1.1 chopps
504 1.1 chopps case GM_GRFIOCTL:
505 1.1 chopps return(cl_ioctl (gp, (int) arg, (caddr_t) a2));
506 1.1 chopps
507 1.1 chopps default:
508 1.1 chopps break;
509 1.1 chopps }
510 1.1 chopps
511 1.1 chopps return(EINVAL);
512 1.1 chopps }
513 1.1 chopps
514 1.1 chopps int
515 1.1 chopps cl_ioctl (gp, cmd, data)
516 1.1 chopps register struct grf_softc *gp;
517 1.1 chopps int cmd;
518 1.1 chopps void *data;
519 1.1 chopps {
520 1.1 chopps switch (cmd) {
521 1.1 chopps case GRFIOCGSPRITEPOS:
522 1.1 chopps case GRFIOCSSPRITEPOS:
523 1.1 chopps case GRFIOCSSPRITEINF:
524 1.1 chopps case GRFIOCGSPRITEINF:
525 1.1 chopps case GRFIOCGSPRITEMAX:
526 1.1 chopps break;
527 1.1 chopps
528 1.1 chopps case GRFIOCGETCMAP:
529 1.1 chopps return(cl_getcmap (gp, (struct grf_colormap *) data));
530 1.1 chopps
531 1.1 chopps case GRFIOCPUTCMAP:
532 1.1 chopps return(cl_putcmap (gp, (struct grf_colormap *) data));
533 1.1 chopps
534 1.1 chopps case GRFIOCBITBLT:
535 1.1 chopps break;
536 1.1 chopps
537 1.1 chopps case GRFTOGGLE:
538 1.1 chopps return(cl_toggle (gp,0));
539 1.1 chopps
540 1.1 chopps case GRFIOCSETMON:
541 1.1 chopps return(cl_setmonitor (gp, (struct grfvideo_mode *)data));
542 1.1 chopps
543 1.1 chopps }
544 1.1 chopps return(EINVAL);
545 1.1 chopps }
546 1.1 chopps
547 1.1 chopps int
548 1.1 chopps cl_setmonitor(gp, gv)
549 1.1 chopps struct grf_softc *gp;
550 1.1 chopps struct grfvideo_mode *gv;
551 1.1 chopps {
552 1.1 chopps struct grfvideo_mode *md;
553 1.1 chopps unsigned long maxpix;
554 1.1 chopps
555 1.1 chopps #ifdef CL5426CONSOLE
556 1.1 chopps /* handle interactive setting of console mode */
557 1.1 chopps if (gv->mode_num == 255 && gv->depth == 4) {
558 1.1 chopps bcopy(gv, &clconsole_mode.gv, sizeof(struct grfvideo_mode));
559 1.1 chopps clconsole_mode.rows = gv->disp_height / clconsole_mode.fy;
560 1.1 chopps clconsole_mode.cols = gv->disp_width / clconsole_mode.fx;
561 1.1 chopps if (!(gp->g_flags & GF_GRFON))
562 1.1 chopps cl_load_mon(gp, &clconsole_mode);
563 1.1 chopps ite_reinit(gp->g_itedev);
564 1.1 chopps return(0);
565 1.1 chopps }
566 1.1 chopps #endif
567 1.1 chopps
568 1.1 chopps /* text mode not valid for other than console */
569 1.1 chopps if (gv->depth == 4)
570 1.1 chopps return(EINVAL);
571 1.1 chopps
572 1.1 chopps if (!gv->mode_num || gv->mode_num > monitor_def_max)
573 1.1 chopps return(EINVAL);
574 1.1 chopps
575 1.1 chopps if ((gv->depth == 24 && (gv->pixel_clock*3) > cl_maxpixelclock) ||
576 1.1 chopps (gv->pixel_clock > cl_maxpixelclock))
577 1.1 chopps return(EINVAL);
578 1.1 chopps
579 1.1 chopps md = monitor_def + (gv->mode_num-1);
580 1.1 chopps
581 1.1 chopps bcopy(gv, md, sizeof(struct grfvideo_mode));
582 1.1 chopps return(0);
583 1.1 chopps }
584 1.1 chopps
585 1.1 chopps int
586 1.1 chopps cl_getcmap (gfp, cmap)
587 1.1 chopps struct grf_softc *gfp;
588 1.1 chopps struct grf_colormap *cmap;
589 1.1 chopps {
590 1.1 chopps volatile unsigned char *ba;
591 1.1 chopps u_char red[256], green[256], blue[256], *rp, *gp, *bp;
592 1.1 chopps short x;
593 1.1 chopps int error;
594 1.1 chopps
595 1.1 chopps if (cmap->count == 0 || cmap->index >= 256)
596 1.1 chopps return 0;
597 1.1 chopps
598 1.1 chopps if (cmap->index + cmap->count > 256)
599 1.1 chopps cmap->count = 256 - cmap->index;
600 1.1 chopps
601 1.1 chopps ba = gfp->g_regkva;
602 1.1 chopps /* first read colors out of the chip, then copyout to userspace */
603 1.1 chopps vgaw (ba, VDAC_ADDRESS_W, cmap->index);
604 1.1 chopps x = cmap->count - 1;
605 1.1 chopps
606 1.1 chopps /* Some sort 'o Magic. Spectrum has some changes on the board to speed
607 1.1 chopps * up 15 and 16Bit modes. They can access these modes with easy-to-programm
608 1.1 chopps * rgbrgbrgb instead of rrrgggbbb. Side effect: when in 8Bit mode, rgb
609 1.1 chopps * is swapped to bgr. I wonder if we need to check for 8Bit though, ill
610 1.1 chopps */
611 1.1 chopps
612 1.1 chopps switch (cltype) {
613 1.1 chopps case SPECTRUM:
614 1.1 chopps case PICCOLO:
615 1.1 chopps rp = blue + cmap->index;
616 1.1 chopps gp = green + cmap->index;
617 1.1 chopps bp = red + cmap->index;
618 1.1 chopps break;
619 1.1 chopps case PICASSO:
620 1.1 chopps rp = red + cmap->index;
621 1.1 chopps gp = green + cmap->index;
622 1.1 chopps bp = blue + cmap->index;
623 1.1 chopps break;
624 1.1 chopps }
625 1.1 chopps
626 1.1 chopps do {
627 1.1 chopps *rp++ = vgar (ba, VDAC_DATA) << 2;
628 1.1 chopps *gp++ = vgar (ba, VDAC_DATA) << 2;
629 1.1 chopps *bp++ = vgar (ba, VDAC_DATA) << 2;
630 1.1 chopps } while (x-- > 0);
631 1.1 chopps
632 1.1 chopps if (!(error = copyout (red + cmap->index, cmap->red, cmap->count))
633 1.1 chopps && !(error = copyout (green + cmap->index, cmap->green, cmap->count))
634 1.1 chopps && !(error = copyout (blue + cmap->index, cmap->blue, cmap->count)))
635 1.1 chopps return(0);
636 1.1 chopps
637 1.1 chopps return(error);
638 1.1 chopps }
639 1.1 chopps
640 1.1 chopps int
641 1.1 chopps cl_putcmap (gfp, cmap)
642 1.1 chopps struct grf_softc *gfp;
643 1.1 chopps struct grf_colormap *cmap;
644 1.1 chopps {
645 1.1 chopps volatile unsigned char *ba;
646 1.1 chopps u_char red[256], green[256], blue[256], *rp, *gp, *bp;
647 1.1 chopps short x;
648 1.1 chopps int error;
649 1.1 chopps
650 1.1 chopps if (cmap->count == 0 || cmap->index >= 256)
651 1.1 chopps return(0);
652 1.1 chopps
653 1.1 chopps if (cmap->index + cmap->count > 256)
654 1.1 chopps cmap->count = 256 - cmap->index;
655 1.1 chopps
656 1.1 chopps /* first copy the colors into kernelspace */
657 1.1 chopps if (!(error = copyin (cmap->red, red + cmap->index, cmap->count))
658 1.1 chopps && !(error = copyin (cmap->green, green + cmap->index, cmap->count))
659 1.1 chopps && !(error = copyin (cmap->blue, blue + cmap->index, cmap->count))) {
660 1.1 chopps ba = gfp->g_regkva;
661 1.1 chopps vgaw (ba, VDAC_ADDRESS_W, cmap->index);
662 1.1 chopps x = cmap->count - 1;
663 1.1 chopps
664 1.1 chopps switch (cltype) {
665 1.1 chopps case SPECTRUM:
666 1.1 chopps case PICCOLO:
667 1.1 chopps rp = blue + cmap->index;
668 1.1 chopps gp = green + cmap->index;
669 1.1 chopps bp = red + cmap->index;
670 1.1 chopps break;
671 1.1 chopps case PICASSO:
672 1.1 chopps rp = red + cmap->index;
673 1.1 chopps gp = green + cmap->index;
674 1.1 chopps bp = blue + cmap->index;
675 1.1 chopps break;
676 1.1 chopps }
677 1.1 chopps
678 1.1 chopps do {
679 1.1 chopps vgaw (ba, VDAC_DATA, *rp++ >> 2);
680 1.1 chopps vgaw (ba, VDAC_DATA, *gp++ >> 2);
681 1.1 chopps vgaw (ba, VDAC_DATA, *bp++ >> 2);
682 1.1 chopps } while (x-- > 0);
683 1.1 chopps return(0);
684 1.1 chopps }
685 1.1 chopps else
686 1.1 chopps return(error);
687 1.1 chopps }
688 1.1 chopps
689 1.1 chopps
690 1.1 chopps int
691 1.1 chopps cl_toggle(gp,wopp)
692 1.1 chopps struct grf_softc *gp;
693 1.1 chopps unsigned short wopp; /* don't need that one yet, ill */
694 1.1 chopps {
695 1.1 chopps volatile unsigned char *ba;
696 1.1 chopps
697 1.1 chopps ba = gp->g_regkva;
698 1.1 chopps
699 1.1 chopps if (pass_toggle) {
700 1.1 chopps RegOffpass(ba);
701 1.1 chopps } else {
702 1.1 chopps /* This was in the original.. is it needed? */
703 1.1 chopps if (cltype == PICASSO || cltype == PICCOLO)
704 1.1 chopps RegWakeup(ba);
705 1.1 chopps RegOnpass(ba);
706 1.1 chopps }
707 1.1 chopps return(0);
708 1.1 chopps }
709 1.1 chopps
710 1.1 chopps static void
711 1.1 chopps CompFQ(fq,num,denom)
712 1.1 chopps u_int fq;
713 1.1 chopps u_char *num;
714 1.1 chopps u_char *denom;
715 1.1 chopps {
716 1.1 chopps #define OSC 14318180
717 1.1 chopps /* OK, here's what we're doing here:
718 1.1 chopps *
719 1.1 chopps * OSC * NUMERATOR
720 1.1 chopps * VCLK = ------------------- Hz
721 1.1 chopps * DENOMINATOR * (1+P)
722 1.1 chopps *
723 1.1 chopps * so we're given VCLK and we should give out some useful
724 1.1 chopps * values....
725 1.1 chopps *
726 1.1 chopps * NUMERATOR is 6 bits wide
727 1.1 chopps * DENOMINATOR is 5 bits wide with bit P in the same char as bit 0.
728 1.1 chopps *
729 1.1 chopps * We run through all the possible combinations and
730 1.1 chopps * return the values which deviate the least from the chosen frequency.
731 1.1 chopps *
732 1.1 chopps */
733 1.1 chopps #define OSC 14318180
734 1.1 chopps #define count(n,d,p) ((OSC * n)/(d * (1+p)))
735 1.1 chopps
736 1.1 chopps unsigned char n, d, p, minn, mind, minp;
737 1.1 chopps unsigned long err, minerr;
738 1.1 chopps
739 1.1 chopps /*
740 1.1 chopps numer = 0x00 - 0x7f (7 bit!)
741 1.1 chopps denom = 0x00 - 0x1f (1) 0x20 - 0x3e (even)
742 1.1 chopps */
743 1.1 chopps
744 1.1 chopps /* find lowest error in 6144 iterations.
745 1.1 chopps */
746 1.1 chopps minerr = fq;
747 1.1 chopps minn = 0;
748 1.1 chopps mind = 0;
749 1.1 chopps p = 0;
750 1.1 chopps
751 1.1 chopps for (d=1; d < 0x20; d++) {
752 1.1 chopps for (n=1; n < 0x80; n++) {
753 1.1 chopps err = abs(count(n, d, p) - fq);
754 1.1 chopps if (err < minerr) {
755 1.1 chopps minerr = err;
756 1.1 chopps minn = n;
757 1.1 chopps mind = d;
758 1.1 chopps minp = p;
759 1.1 chopps }
760 1.1 chopps }
761 1.1 chopps if (d == 0x1f && p == 0) {
762 1.1 chopps p = 1;
763 1.1 chopps d = 0x0f;
764 1.1 chopps }
765 1.1 chopps }
766 1.1 chopps
767 1.1 chopps *num = minn;
768 1.1 chopps *denom = (mind << 1) | minp;
769 1.1 chopps if (minerr > 500000)
770 1.1 chopps printf("Warning: CompFQ minimum error = %d\n", minerr);
771 1.1 chopps return;
772 1.1 chopps }
773 1.1 chopps
774 1.1 chopps int
775 1.1 chopps cl_mondefok(mdp)
776 1.1 chopps struct grfvideo_mode *mdp;
777 1.1 chopps {
778 1.1 chopps if (mdp->mode_num == 0 || (mdp->depth == 24 ?
779 1.1 chopps mdp->pixel_clock * 3 : mdp->pixel_clock) > cl_maxpixelclock)
780 1.1 chopps return(0);
781 1.1 chopps
782 1.1 chopps switch(mdp->depth) {
783 1.1 chopps case 1:
784 1.1 chopps case 4:
785 1.1 chopps case 8:
786 1.1 chopps case 15:
787 1.1 chopps case 16:
788 1.1 chopps case 24:
789 1.1 chopps return(1);
790 1.1 chopps default:
791 1.1 chopps return(0);
792 1.1 chopps }
793 1.1 chopps }
794 1.1 chopps
795 1.1 chopps int
796 1.1 chopps cl_load_mon(gp, md)
797 1.1 chopps struct grf_softc *gp;
798 1.1 chopps struct grfcltext_mode *md;
799 1.1 chopps {
800 1.1 chopps struct grfvideo_mode *gv;
801 1.1 chopps struct grfinfo *gi;
802 1.1 chopps volatile unsigned char *ba;
803 1.1 chopps volatile unsigned char *fb;
804 1.1 chopps unsigned char num0,denom0;
805 1.1 chopps unsigned short HT,HDE,HBS,HBE,HSS,HSE,VDE,VBS,VBE,VSS,VSE,VT;
806 1.1 chopps char LACE, DBLSCAN, TEXT;
807 1.1 chopps unsigned short clkdiv, clksel;
808 1.1 chopps int uplim, lowlim;
809 1.1 chopps
810 1.1 chopps /* identity */
811 1.1 chopps gv = &md->gv;
812 1.1 chopps TEXT = (gv->depth == 4);
813 1.1 chopps
814 1.1 chopps if (!cl_mondefok(gv)) {
815 1.1 chopps printf("mondef not ok\n");
816 1.1 chopps return(0);
817 1.1 chopps }
818 1.1 chopps
819 1.1 chopps ba = gp->g_regkva;
820 1.1 chopps fb = gp->g_fbkva;
821 1.1 chopps
822 1.1 chopps /* provide all needed information in grf device-independant
823 1.1 chopps * locations
824 1.1 chopps */
825 1.1 chopps gp->g_data = (caddr_t) gv;
826 1.1 chopps gi = &gp->g_display;
827 1.1 chopps gi->gd_regaddr = (caddr_t) ztwopa (ba);
828 1.1 chopps gi->gd_regsize = 64*1024;
829 1.1 chopps gi->gd_fbaddr = (caddr_t) kvtop (fb);
830 1.1 chopps gi->gd_fbsize = cl_fbsize;
831 1.1 chopps gi->gd_colors = 1 << gv->depth;
832 1.1 chopps gi->gd_planes = gv->depth;
833 1.1 chopps gi->gd_fbwidth = gv->disp_width;
834 1.1 chopps gi->gd_fbheight = gv->disp_height;
835 1.1 chopps gi->gd_fbx = 0;
836 1.1 chopps gi->gd_fby = 0;
837 1.1 chopps if (TEXT) {
838 1.1 chopps gi->gd_dwidth = md->fx * md->cols;
839 1.1 chopps gi->gd_dheight = md->fy * md->rows;
840 1.1 chopps } else {
841 1.1 chopps gi->gd_dwidth = gv->disp_width;
842 1.1 chopps gi->gd_dheight = gv->disp_height;
843 1.1 chopps }
844 1.1 chopps gi->gd_dx = 0;
845 1.1 chopps gi->gd_dy = 0;
846 1.1 chopps
847 1.1 chopps /* get display mode parameters */
848 1.1 chopps
849 1.1 chopps HBS = gv->hblank_start;
850 1.1 chopps HBE = gv->hblank_stop;
851 1.1 chopps HSS = gv->hsync_start;
852 1.1 chopps HSE = gv->hsync_stop;
853 1.1 chopps HT = gv->htotal;
854 1.1 chopps VBS = gv->vblank_start;
855 1.1 chopps VSS = gv->vsync_start;
856 1.1 chopps VSE = gv->vsync_stop;
857 1.1 chopps VBE = gv->vblank_stop;
858 1.1 chopps VT = gv->vtotal;
859 1.1 chopps
860 1.1 chopps if (TEXT)
861 1.1 chopps HDE = ((gv->disp_width+md->fx-1)/md->fx) - 1;
862 1.1 chopps else
863 1.1 chopps HDE = (gv->disp_width+3)/8 - 1; /*HBS;*/
864 1.1 chopps VDE = gv->disp_height-1;
865 1.1 chopps
866 1.1 chopps /* figure out whether lace or dblscan is needed */
867 1.1 chopps
868 1.1 chopps uplim = gv->disp_height + (gv->disp_height / 4);
869 1.1 chopps lowlim = gv->disp_height - (gv->disp_height / 4);
870 1.1 chopps LACE = (((VT*2) > lowlim) && ((VT*2) < uplim)) ? 1 : 0;
871 1.1 chopps DBLSCAN = (((VT/2) > lowlim) && ((VT/2) < uplim)) ? 1 : 0;
872 1.1 chopps
873 1.1 chopps /* adjustments */
874 1.1 chopps
875 1.1 chopps if (LACE)
876 1.1 chopps VDE /= 2;
877 1.1 chopps
878 1.1 chopps WSeq(ba, SEQ_ID_MEMORY_MODE, (TEXT || (gv->depth == 1)) ? 0x06 : 0x0e);
879 1.1 chopps WSeq(ba, SEQ_ID_DRAM_CNTL, (TEXT || (gv->depth == 1)) ? 0x90 : 0xb0);
880 1.1 chopps WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
881 1.1 chopps WSeq(ba, SEQ_ID_MAP_MASK, (gv->depth == 1) ? 0x01 : 0xff);
882 1.1 chopps WSeq(ba, SEQ_ID_CHAR_MAP_SELECT, 0x00);
883 1.1 chopps
884 1.1 chopps /* Set clock */
885 1.1 chopps
886 1.1 chopps CompFQ((gv->depth == 24) ? gv->pixel_clock*3 : gv->pixel_clock,
887 1.1 chopps &num0, &denom0);
888 1.1 chopps WSeq(ba, SEQ_ID_VCLK_0_NUM, num0);
889 1.1 chopps WSeq(ba, SEQ_ID_VCLK_0_DENOM, denom0);
890 1.1 chopps
891 1.1 chopps /* load display parameters into board */
892 1.1 chopps
893 1.1 chopps WCrt(ba, CRT_ID_HOR_TOTAL, HT);
894 1.1 chopps WCrt(ba, CRT_ID_HOR_DISP_ENA_END, ((HDE >= HBS) ? HBS-1 : HDE));
895 1.1 chopps WCrt(ba, CRT_ID_START_HOR_BLANK, HBS);
896 1.1 chopps WCrt(ba, CRT_ID_END_HOR_BLANK, (HBE & 0x1f) | 0x80); /* | 0x80? */
897 1.1 chopps WCrt(ba, CRT_ID_START_HOR_RETR, HSS);
898 1.1 chopps WCrt(ba, CRT_ID_END_HOR_RETR,
899 1.1 chopps (HSE & 0x1f) |
900 1.1 chopps ((HBE & 0x20) ? 0x80 : 0x00) );
901 1.1 chopps WCrt(ba, CRT_ID_VER_TOTAL, VT);
902 1.1 chopps WCrt(ba, CRT_ID_OVERFLOW,
903 1.1 chopps 0x10 |
904 1.1 chopps ((VT & 0x100) ? 0x01 : 0x00) |
905 1.1 chopps ((VDE & 0x100) ? 0x02 : 0x00) |
906 1.1 chopps ((VSS & 0x100) ? 0x04 : 0x00) |
907 1.1 chopps ((VBS & 0x100) ? 0x08 : 0x00) |
908 1.1 chopps ((VT & 0x200) ? 0x20 : 0x00) |
909 1.1 chopps ((VDE & 0x200) ? 0x40 : 0x00) |
910 1.1 chopps ((VSS & 0x200) ? 0x80 : 0x00) );
911 1.1 chopps
912 1.1 chopps
913 1.1 chopps WCrt(ba, CRT_ID_CHAR_HEIGHT,
914 1.1 chopps 0x40 | /* TEXT ? 0x00 ??? */
915 1.1 chopps (DBLSCAN ? 0x80 : 0x00) |
916 1.1 chopps ((VBS & 0x200) ? 0x20 : 0x00) |
917 1.1 chopps (TEXT ? ((md->fy-1) & 0x1f) : 0x00));
918 1.1 chopps WCrt(ba, CRT_ID_MODE_CONTROL,
919 1.1 chopps ((TEXT || (gv->depth == 1)) ? 0xc3 : 0xa3));
920 1.1 chopps
921 1.1 chopps /* text cursor */
922 1.1 chopps
923 1.1 chopps if (TEXT) {
924 1.1 chopps #if 0
925 1.1 chopps WCrt(ba, CRT_ID_CURSOR_START, (md->fy & 0x1f) - 2);
926 1.1 chopps WCrt(ba, CRT_ID_CURSOR_END, (md->fy & 0x1f) - 1);
927 1.1 chopps #else
928 1.1 chopps WCrt(ba, CRT_ID_CURSOR_START, 0x00);
929 1.1 chopps WCrt(ba, CRT_ID_CURSOR_END, md->fy & 0x1f);
930 1.1 chopps #endif
931 1.1 chopps WCrt(ba, CRT_ID_UNDERLINE_LOC, md->fy-1 & 0x1f);
932 1.1 chopps
933 1.1 chopps WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
934 1.1 chopps WCrt(ba, CRT_ID_CURSOR_LOC_LOW, 0x00);
935 1.1 chopps }
936 1.1 chopps
937 1.1 chopps WCrt(ba, CRT_ID_START_ADDR_HIGH, 0x00);
938 1.1 chopps WCrt(ba, CRT_ID_START_ADDR_LOW, 0x00);
939 1.1 chopps
940 1.1 chopps WCrt(ba, CRT_ID_START_VER_RETR, VSS);
941 1.1 chopps WCrt(ba, CRT_ID_END_VER_RETR, (VSE & 0x0f) | 0x30);
942 1.1 chopps WCrt(ba, CRT_ID_VER_DISP_ENA_END, VDE);
943 1.1 chopps WCrt(ba, CRT_ID_START_VER_BLANK, VBS);
944 1.1 chopps WCrt(ba, CRT_ID_END_VER_BLANK, VBE);
945 1.1 chopps
946 1.1 chopps WCrt(ba, CRT_ID_LINE_COMPARE, 0xff);
947 1.1 chopps WCrt(ba, CRT_ID_LACE_END, HT/2); /* MW/16 */
948 1.1 chopps WCrt(ba, CRT_ID_LACE_CNTL,
949 1.1 chopps (LACE ? 0x01 : 0x00) |
950 1.1 chopps ((HBE & 0x40) ? 0x10 : 0x00) |
951 1.1 chopps ((HBE & 0x80) ? 0x20 : 0x00) |
952 1.1 chopps ((VBE & 0x100) ? 0x40 : 0x00) |
953 1.1 chopps ((VBE & 0x200) ? 0x80 : 0x00) );
954 1.1 chopps
955 1.1 chopps /* depth dependent stuff */
956 1.1 chopps
957 1.1 chopps switch (gv->depth) {
958 1.1 chopps case 1:
959 1.1 chopps case 4:
960 1.1 chopps case 8:
961 1.1 chopps clkdiv = 0;
962 1.1 chopps break;
963 1.1 chopps case 15:
964 1.1 chopps case 16:
965 1.1 chopps clkdiv = 3;
966 1.1 chopps break;
967 1.1 chopps case 24:
968 1.1 chopps clkdiv = 2;
969 1.1 chopps break;
970 1.1 chopps }
971 1.1 chopps
972 1.1 chopps WGfx(ba, GCT_ID_GRAPHICS_MODE,
973 1.1 chopps ((TEXT || (gv->depth == 1)) ? 0x00 : 0x40));
974 1.1 chopps WGfx(ba, GCT_ID_MISC, (TEXT ? 0x04 : 0x01));
975 1.1 chopps
976 1.1 chopps WSeq(ba, SEQ_ID_EXT_SEQ_MODE,
977 1.1 chopps ((TEXT || (gv->depth == 1)) ? 0x00 : 0x01) |
978 1.1 chopps ((cltype == PICASSO) ? 0x20: 0x80) |
979 1.1 chopps (clkdiv << 1) );
980 1.1 chopps
981 1.1 chopps delay(200000);
982 1.1 chopps vgaw(ba, VDAC_MASK, 0xff);
983 1.1 chopps delay(200000);
984 1.1 chopps vgar(ba, VDAC_MASK);
985 1.1 chopps delay(200000);
986 1.1 chopps vgar(ba, VDAC_MASK);
987 1.1 chopps delay(200000);
988 1.1 chopps vgar(ba, VDAC_MASK);
989 1.1 chopps delay(200000);
990 1.1 chopps vgar(ba, VDAC_MASK);
991 1.1 chopps delay(200000);
992 1.1 chopps switch (gv->depth) {
993 1.1 chopps case 1:
994 1.1 chopps case 4: /* text */
995 1.1 chopps vgaw(ba, VDAC_MASK, 0);
996 1.1 chopps HDE = gv->disp_width / 16;
997 1.1 chopps break;
998 1.1 chopps case 8:
999 1.1 chopps vgaw(ba, VDAC_MASK, 0);
1000 1.1 chopps HDE = gv->disp_width / 8;
1001 1.1 chopps break;
1002 1.1 chopps case 15:
1003 1.1 chopps vgaw(ba, VDAC_MASK, 0xd0);
1004 1.1 chopps HDE = gv->disp_width / 4;
1005 1.1 chopps break;
1006 1.1 chopps case 16:
1007 1.1 chopps vgaw(ba, VDAC_MASK, 0xc1);
1008 1.1 chopps HDE = gv->disp_width / 4;
1009 1.1 chopps break;
1010 1.1 chopps case 24:
1011 1.1 chopps vgaw(ba, VDAC_MASK, 0xc5);
1012 1.1 chopps HDE = (gv->disp_width / 8) * 3;
1013 1.1 chopps break;
1014 1.1 chopps }
1015 1.1 chopps delay(200000);
1016 1.1 chopps
1017 1.1 chopps WCrt(ba, CRT_ID_OFFSET, HDE);
1018 1.1 chopps WCrt(ba, CRT_ID_EXT_DISP_CNTL,
1019 1.1 chopps ((TEXT && gv->pixel_clock > 29000000) ? 0x40 : 0x00) |
1020 1.1 chopps 0x22 |
1021 1.1 chopps ((HDE > 0xff) ? 0x10 : 0x00)); /* text? */
1022 1.1 chopps
1023 1.1 chopps delay(200000);
1024 1.1 chopps WAttr(ba, ACT_ID_ATTR_MODE_CNTL, (TEXT ? 0x0a : 0x01));
1025 1.1 chopps delay(200000);
1026 1.1 chopps WAttr(ba, 0x20 | ACT_ID_COLOR_PLANE_ENA,
1027 1.1 chopps (gv->depth == 1) ? 0x01 : 0x0f);
1028 1.1 chopps delay(200000);
1029 1.1 chopps
1030 1.1 chopps /* text initialization */
1031 1.1 chopps
1032 1.1 chopps if (TEXT) {
1033 1.1 chopps cl_inittextmode(gp);
1034 1.1 chopps }
1035 1.1 chopps
1036 1.1 chopps WSeq(ba, SEQ_ID_CURSOR_ATTR, 0x14);
1037 1.1 chopps WSeq(ba, SEQ_ID_CLOCKING_MODE, 0x01);
1038 1.1 chopps
1039 1.1 chopps /* Pass-through */
1040 1.1 chopps
1041 1.1 chopps RegOffpass(ba);
1042 1.1 chopps
1043 1.1 chopps return(1);
1044 1.1 chopps }
1045 1.1 chopps
1046 1.1 chopps void
1047 1.1 chopps cl_inittextmode(gp)
1048 1.1 chopps struct grf_softc *gp;
1049 1.1 chopps {
1050 1.1 chopps struct grfcltext_mode *tm = (struct grfcltext_mode *)gp->g_data;
1051 1.1 chopps volatile unsigned char *ba = gp->g_regkva;
1052 1.1 chopps unsigned char *fb = gp->g_fbkva;
1053 1.1 chopps unsigned char *c, *f, y;
1054 1.1 chopps unsigned short z;
1055 1.1 chopps
1056 1.1 chopps
1057 1.1 chopps /* load text font into beginning of display memory.
1058 1.1 chopps * Each character cell is 32 bytes long (enough for
1059 1.1 chopps * 4 planes)
1060 1.1 chopps */
1061 1.1 chopps
1062 1.1 chopps SetTextPlane(ba, 0x02);
1063 1.1 chopps c = (unsigned char *)(fb);
1064 1.1 chopps f = tm->fdata;
1065 1.1 chopps for (z = 0; z < tm->fdstart; z++, c+=(32-tm->fy))
1066 1.1 chopps for (y=0; y < tm->fy; y++)
1067 1.1 chopps *c++ = 0;
1068 1.1 chopps for (; z <= tm->fdend; z++, c+=(32-tm->fy))
1069 1.1 chopps for (y=0; y < tm->fy; y++)
1070 1.1 chopps *c++ = *f++;
1071 1.1 chopps for (; z < 256; z++, c+=(32-tm->fy))
1072 1.1 chopps for (y=0; y < tm->fy; y++)
1073 1.1 chopps *c++ = 0;
1074 1.1 chopps
1075 1.1 chopps /* clear out text/attr planes (three screens worth) */
1076 1.1 chopps
1077 1.1 chopps SetTextPlane(ba, 0x01);
1078 1.1 chopps memset(fb, 0x07, tm->cols*tm->rows*3);
1079 1.1 chopps SetTextPlane(ba, 0x00);
1080 1.1 chopps memset(fb, 0x20, tm->cols*tm->rows*3);
1081 1.1 chopps
1082 1.1 chopps /* print out a little init msg */
1083 1.1 chopps
1084 1.1 chopps c = (unsigned char *)(fb) + (tm->cols-16);
1085 1.1 chopps strcpy(c, "CIRRUS");
1086 1.1 chopps c[6] = 0x20;
1087 1.1 chopps
1088 1.1 chopps /* set colors (B&W) */
1089 1.1 chopps
1090 1.1 chopps
1091 1.1 chopps vgaw(ba, VDAC_ADDRESS_W, 0);
1092 1.1 chopps for (z=0; z<256; z++) {
1093 1.1 chopps unsigned char r, g, b;
1094 1.1 chopps
1095 1.1 chopps y = (z & 1) ? ((z > 7) ? 2 : 1) : 0;
1096 1.1 chopps
1097 1.1 chopps if (cltype == PICASSO) {
1098 1.1 chopps r = clconscolors[y][0];
1099 1.1 chopps g = clconscolors[y][1];
1100 1.1 chopps b = clconscolors[y][2];
1101 1.1 chopps } else {
1102 1.1 chopps b = clconscolors[y][0];
1103 1.1 chopps g = clconscolors[y][1];
1104 1.1 chopps r = clconscolors[y][2];
1105 1.1 chopps }
1106 1.1 chopps vgaw(ba, VDAC_DATA, r >> 2);
1107 1.1 chopps vgaw(ba, VDAC_DATA, g >> 2);
1108 1.1 chopps vgaw(ba, VDAC_DATA, b >> 2);
1109 1.1 chopps }
1110 1.1 chopps }
1111 1.1 chopps
1112 1.1 chopps void
1113 1.1 chopps memset(d, c, l)
1114 1.1 chopps unsigned char *d;
1115 1.1 chopps unsigned char c;
1116 1.1 chopps int l;
1117 1.1 chopps {
1118 1.1 chopps for(; l>0; l--)
1119 1.1 chopps *d++ = c;
1120 1.1 chopps }
1121 1.1 chopps
1122 1.1 chopps #endif /* GRF_CL5426 */
1123 1.1 chopps
1124