xref: /original-bsd/sys/hp300/dev/grf_gb.c (revision 94e7bb75)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1990 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: grf_gb.c 1.17 92/01/21$
13  *
14  *	@(#)grf_gb.c	7.5 (Berkeley) 06/05/92
15  */
16 
17 #include "grf.h"
18 #if NGRF > 0
19 
20 /*
21  * Graphics routines for the Gatorbox.
22  *
23  * Note: In the context of this system, "gator" and "gatorbox" both refer to
24  *       HP 987x0 graphics systems.  "Gator" is not used for high res mono.
25  *       (as in 9837 Gator systems)
26  */
27 #include "sys/param.h"
28 #include "sys/errno.h"
29 
30 #include "hp/dev/grfioctl.h"
31 #include "hp/dev/grfvar.h"
32 #include "grf_gbreg.h"
33 
34 #include "../include/cpu.h"
35 
36 #define CRTC_DATA_LENGTH  0x0e
37 u_char crtc_init_data[CRTC_DATA_LENGTH] = {
38     0x29, 0x20, 0x23, 0x04, 0x30, 0x0b, 0x30,
39     0x30, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00
40 };
41 
42 /*
43  * Initialize hardware.
44  * Must point g_display at a grfinfo structure describing the hardware.
45  * Returns 0 if hardware not present, non-zero ow.
46  */
47 gb_init(gp, addr)
48 	struct grf_softc *gp;
49 	caddr_t addr;
50 {
51 	register struct gboxfb *gbp;
52 	struct grfinfo *gi = &gp->g_display;
53 	u_char *fbp, save;
54 	int fboff;
55 	extern caddr_t sctopa(), iomap();
56 
57 	gbp = (struct gboxfb *) addr;
58 	if (ISIIOVA(addr))
59 		gi->gd_regaddr = (caddr_t) IIOP(addr);
60 	else
61 		gi->gd_regaddr = sctopa(vatosc(addr));
62 	gi->gd_regsize = 0x10000;
63 	gi->gd_fbwidth = 1024;		/* XXX */
64 	gi->gd_fbheight = 1024;		/* XXX */
65 	gi->gd_fbsize = gi->gd_fbwidth * gi->gd_fbheight;
66 	fboff = (gbp->fbomsb << 8) | gbp->fbolsb;
67 	gi->gd_fbaddr = (caddr_t) (*((u_char *)addr + fboff) << 16);
68 	gp->g_regkva = addr;
69 	gp->g_fbkva = iomap(gi->gd_fbaddr, gi->gd_fbsize);
70 	gi->gd_dwidth = 1024;		/* XXX */
71 	gi->gd_dheight = 768;		/* XXX */
72 	gi->gd_planes = 0;		/* how do we do this? */
73 	/*
74 	 * The minimal register info here is from the Gatorbox X driver.
75 	 */
76 	fbp = (u_char *) gp->g_fbkva;
77 	gbp->write_protect = 0;
78 	gbp->interrupt = 4;		/** fb_enable ? **/
79 	gbp->rep_rule = 3;		/* GXcopy */
80 	gbp->blink1 = 0xff;
81 	gbp->blink2 = 0xff;
82 
83 	gb_microcode(gbp);
84 
85 	/*
86 	 * Find out how many colors are available by determining
87 	 * which planes are installed.  That is, write all ones to
88 	 * a frame buffer location, see how many ones are read back.
89 	 */
90 	save = *fbp;
91 	*fbp = 0xFF;
92 	gi->gd_colors = *fbp + 1;
93 	*fbp = save;
94 	return(1);
95 }
96 
97 /*
98  * Program the 6845.
99  */
100 gb_microcode(gbp)
101 	register struct gboxfb *gbp;
102 {
103 	register int i;
104 
105 	for (i = 0; i < CRTC_DATA_LENGTH; i++) {
106 		gbp->crtc_address = i;
107 		gbp->crtc_data = crtc_init_data[i];
108 	}
109 }
110 
111 /*
112  * Change the mode of the display.
113  * Right now all we can do is grfon/grfoff.
114  * Return a UNIX error number or 0 for success.
115  */
116 gb_mode(gp, cmd)
117 	register struct grf_softc *gp;
118 {
119 	struct gboxfb *gbp;
120 	int error = 0;
121 
122 	gbp = (struct gboxfb *) gp->g_regkva;
123 	switch (cmd) {
124 	case GM_GRFON:
125 		gbp->sec_interrupt = 1;
126 		break;
127 	case GM_GRFOFF:
128 		break;
129 	default:
130 		error = EINVAL;
131 		break;
132 	}
133 	return(error);
134 }
135 
136 #endif
137