xref: /original-bsd/sys/hp300/dev/grf_gb.c (revision 95ecee29)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1990, 1993
4  *	The Regents of the University of California.  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.18 93/08/13$
13  *
14  *	@(#)grf_gb.c	8.2 (Berkeley) 09/09/93
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 
33 #include <hp300/dev/grf_gbreg.h>
34 #include <machine/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, data)
117 	register struct grf_softc *gp;
118 	caddr_t data;
119 {
120 	struct gboxfb *gbp;
121 	int error = 0;
122 
123 	gbp = (struct gboxfb *) gp->g_regkva;
124 	switch (cmd) {
125 	case GM_GRFON:
126 		gbp->sec_interrupt = 1;
127 		break;
128 
129 	case GM_GRFOFF:
130 		break;
131 
132 	/*
133 	 * Remember UVA of mapping for GCDESCRIBE.
134 	 * XXX this should be per-process.
135 	 */
136 	case GM_MAP:
137 		gp->g_data = data;
138 		break;
139 
140 	case GM_UNMAP:
141 		gp->g_data = 0;
142 		break;
143 
144 #ifdef HPUXCOMPAT
145 	case GM_DESCRIBE:
146 	{
147 		struct grf_fbinfo *fi = (struct grf_fbinfo *)data;
148 		struct grfinfo *gi = &gp->g_display;
149 		int i, j;
150 
151 		/* feed it what HP-UX expects */
152 		fi->id = gi->gd_id;
153 		fi->mapsize = gi->gd_fbsize;
154 		fi->dwidth = gi->gd_dwidth;
155 		fi->dlength = gi->gd_dheight;
156 		fi->width = gi->gd_fbwidth;
157 		fi->length = gi->gd_fbheight;
158 		fi->bpp = NBBY;
159 		fi->xlen = (fi->width * fi->bpp) / NBBY;
160 		fi->npl = gi->gd_planes;
161 		fi->bppu = fi->npl;
162 		fi->nplbytes = fi->xlen * ((fi->length * fi->bpp) / NBBY);
163 		bcopy("HP98700", fi->name, 8);
164 		fi->attr = 2;	/* HW block mover */
165 		/*
166 		 * If mapped, return the UVA where mapped.
167 		 */
168 		if (gp->g_data) {
169 			fi->regbase = gp->g_data;
170 			fi->fbbase = fi->regbase + gp->g_display.gd_regsize;
171 		} else {
172 			fi->fbbase = 0;
173 			fi->regbase = 0;
174 		}
175 		for (i = 0; i < 6; i++)
176 			fi->regions[i] = 0;
177 		break;
178 	}
179 #endif
180 
181 	default:
182 		error = EINVAL;
183 		break;
184 	}
185 	return(error);
186 }
187 
188 #endif
189