xref: /original-bsd/sys/hp300/dev/grf_gb.c (revision 9b5efc43)
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.1 90/07/09$
13  *
14  *	@(#)grf_gb.c	7.3 (Berkeley) 12/16/90
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 "grfioctl.h"
31 #include "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 	u_char *addr;
50 {
51 	register struct gboxfb *gbp;
52 	struct grfinfo *gi = &gp->g_display;
53 	u_char *fbp, save;
54 	int fboff;
55 
56 	gbp = (struct gboxfb *) addr;
57 	gi->gd_regaddr = (caddr_t) UNIOV(addr);
58 	gi->gd_regsize = 0x10000;
59 	gi->gd_fbwidth = 1024;		/* XXX */
60 	gi->gd_fbheight = 1024;		/* XXX */
61 	fboff = (gbp->fbomsb << 8) | gbp->fbolsb;
62 	gi->gd_fbaddr = (caddr_t) (*(addr + fboff) << 16);
63 	gi->gd_fbsize = gi->gd_fbwidth * gi->gd_fbheight;
64 	gi->gd_dwidth = 1024;		/* XXX */
65 	gi->gd_dheight = 768;		/* XXX */
66 	gi->gd_planes = 0;		/* how do we do this? */
67 	/*
68 	 * The minimal register info here is from the Gatorbox X driver.
69 	 */
70 	fbp = (u_char *) IOV(gi->gd_fbaddr);
71 	gbp->write_protect = 0;
72 	gbp->interrupt = 4;		/** fb_enable ? **/
73 	gbp->rep_rule = 3;		/* GXcopy */
74 	gbp->blink1 = 0xff;
75 	gbp->blink2 = 0xff;
76 
77 	gb_microcode(gbp);
78 
79 	/*
80 	 * Find out how many colors are available by determining
81 	 * which planes are installed.  That is, write all ones to
82 	 * a frame buffer location, see how many ones are read back.
83 	 */
84 	save = *fbp;
85 	*fbp = 0xFF;
86 	gi->gd_colors = *fbp + 1;
87 	*fbp = save;
88 	return(1);
89 }
90 
91 /*
92  * Program the 6845.
93  */
94 gb_microcode(gbp)
95 	register struct gboxfb *gbp;
96 {
97 	register int i;
98 
99 	for (i = 0; i < CRTC_DATA_LENGTH; i++) {
100 		gbp->crtc_address = i;
101 		gbp->crtc_data = crtc_init_data[i];
102 	}
103 }
104 
105 /*
106  * Change the mode of the display.
107  * Right now all we can do is grfon/grfoff.
108  * Return a UNIX error number or 0 for success.
109  */
110 gb_mode(gp, cmd)
111 	register struct grf_softc *gp;
112 {
113 	struct gboxfb *gbp;
114 	int error = 0;
115 
116 	gbp = (struct gboxfb *) IOV(gp->g_display.gd_regaddr);
117 	switch (cmd) {
118 	case GM_GRFON:
119 		gbp->sec_interrupt = 1;
120 		break;
121 	case GM_GRFOFF:
122 		break;
123 	default:
124 		error = EINVAL;
125 		break;
126 	}
127 	return(error);
128 }
129 
130 #endif
131