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