xref: /netbsd-src/sys/arch/amiga/dev/grf_cc.c (revision 2a399c6883d870daece976daec6ffa7bb7f934ce)
1 /*	$NetBSD: grf_cc.c,v 1.23 1996/12/23 09:10:02 veego Exp $	*/
2 
3 /*
4  * Copyright (c) 1994 Christian E. Hopps
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *      This product includes software developed by Christian E. Hopps.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 #include "grfcc.h"
33 #if NGRFCC > 0
34 /*
35  * currently this is a backward compat hack that interface to
36  * view.c
37  */
38 
39 #include <sys/param.h>
40 #include <sys/proc.h>
41 #include <sys/errno.h>
42 #include <sys/ioctl.h>
43 #include <sys/queue.h>
44 #include <sys/device.h>
45 #include <sys/systm.h>
46 #include <vm/vm_param.h>
47 #include <machine/cpu.h>
48 #include <amiga/amiga/color.h>	/* DEBUG */
49 #include <amiga/amiga/device.h>
50 #include <amiga/amiga/custom.h>
51 #include <amiga/amiga/cia.h>
52 #include <amiga/dev/grfioctl.h>
53 #include <amiga/dev/grfvar.h>
54 #include <amiga/dev/grf_ccreg.h>
55 #include <amiga/dev/grfabs_reg.h>
56 #include <amiga/dev/viewioctl.h>
57 
58 #include <sys/conf.h>
59 #include <machine/conf.h>
60 
61 #include "view.h"
62 
63 int grfccmatch __P((struct device *, struct cfdata *, void *));
64 int grfccprint __P((void *, const char *));
65 void grfccattach __P((struct device *, struct device *, void *));
66 void grf_cc_on __P((struct grf_softc *));
67 
68 struct cfattach grfcc_ca = {
69 	sizeof(struct grf_softc), grfccmatch, grfccattach
70 };
71 
72 struct cfdriver grfcc_cd = {
73 	NULL, "grfcc", DV_DULL, NULL, 0
74 };
75 
76 /*
77  * only used in console init
78  */
79 static struct cfdata *cfdata;
80 
81 /*
82  * we make sure to only init things once.  this is somewhat
83  * tricky regarding the console.
84  */
85 int
86 grfccmatch(pdp, cfp, auxp)
87 	struct device *pdp;
88 	struct cfdata *cfp;
89 	void *auxp;
90 {
91 	static int ccconunit = -1;
92 	char *mainbus_name = auxp;
93 
94 	/*
95 	 * allow only one cc console
96 	 */
97 	if (amiga_realconfig == 0 && ccconunit != -1)
98 		return(0);
99 	if (matchname("grfcc", mainbus_name) == 0)
100 		return(0);
101 	if (amiga_realconfig == 0 || ccconunit != cfp->cf_unit) {
102 		if (grfcc_probe() == 0)
103 			return(0);
104 		viewprobe();
105 		/*
106 		 * XXX nasty hack. opens view[0] and never closes.
107 		 */
108 		if (viewopen(0, 0, 0, NULL))
109 			return(0);
110 		if (amiga_realconfig == 0) {
111 			ccconunit = cfp->cf_unit;
112 			cfdata = cfp;
113 		}
114 	}
115 	return(1);
116 }
117 
118 /*
119  * attach to the grfbus (mainbus)
120  */
121 void
122 grfccattach(pdp, dp, auxp)
123 	struct device *pdp, *dp;
124 	void *auxp;
125 {
126 	static struct grf_softc congrf;
127 	struct grf_softc *gp;
128 
129 	if (dp == NULL)
130 		gp = &congrf;
131 	else
132 		gp = (struct grf_softc *)dp;
133 
134 	if (dp != NULL && congrf.g_regkva != 0) {
135 		/*
136 		 * we inited earlier just copy the info
137 		 * take care not to copy the device struct though.
138 		 */
139 		bcopy(&congrf.g_display, &gp->g_display,
140 		    (char *)&gp[1] - (char *)&gp->g_display);
141 	} else {
142 		gp->g_unit = GRF_CC_UNIT;
143 		gp->g_flags = GF_ALIVE;
144 		gp->g_mode = cc_mode;
145 		gp->g_conpri = grfcc_cnprobe();
146 		grfcc_iteinit(gp);
147 		grf_cc_on(gp);
148 	}
149 	if (dp != NULL)
150 		printf("\n");
151 	/*
152 	 * attach grf
153 	 */
154 	amiga_config_found(cfdata, &gp->g_device, gp, grfccprint);
155 }
156 
157 int
158 grfccprint(auxp, pnp)
159 	void *auxp;
160 	const char *pnp;
161 {
162 	if (pnp)
163 		printf("grf%d at %s", ((struct grf_softc *)auxp)->g_unit,
164 			pnp);
165 	return(UNCONF);
166 }
167 
168 /*
169  * Change the mode of the display.
170  * Right now all we can do is grfon/grfoff.
171  * Return a UNIX error number or 0 for success.
172  */
173 /*ARGSUSED*/
174 int
175 cc_mode(gp, cmd, arg, a2, a3)
176 	struct grf_softc *gp;
177 	u_long cmd;
178 	void *arg;
179 	u_long a2;
180 	int a3;
181 {
182 
183 	switch (cmd) {
184 	case GM_GRFON:
185 		grf_cc_on(gp);
186 		return(0);
187 	case GM_GRFOFF:
188 		viewioctl(0, VIOCREMOVE, NULL, -1, NULL);
189 		return(0);
190 	case GM_GRFCONFIG:
191 	default:
192 		break;
193 	}
194 	return(EINVAL);
195 }
196 
197 void
198 grf_cc_on(gp)
199 	struct grf_softc *gp;
200 {
201 	struct view_size vs;
202 	bmap_t bm;
203 	struct grfinfo *gi;
204 
205 	gi = &gp->g_display;
206 
207 	viewioctl(0, VIOCGBMAP, (caddr_t)&bm, -1, NULL); /* XXX type of bm ? */
208 
209 	gp->g_data = (caddr_t) 0xDeadBeaf; /* not particularly clean.. */
210 
211 	gi->gd_regaddr = (caddr_t) 0xdff000;	/* depricated */
212 	gi->gd_regsize = round_page(sizeof (custom));
213 	gi->gd_fbaddr  = bm.hardware_address;
214 	gi->gd_fbsize  = bm.depth*bm.bytes_per_row*bm.rows;
215 
216 	if (viewioctl (0, VIOCGSIZE, (caddr_t)&vs, -1, NULL)) {
217 		/* XXX type of vs ? */
218 		/* fill in some default values... XXX */
219 		vs.width = 640;
220 		vs.height = 400;
221 		vs.depth = 2;
222 	}
223 	gi->gd_colors = 1 << vs.depth;
224 	gi->gd_planes = vs.depth;
225 
226 	gi->gd_fbwidth = vs.width;
227 	gi->gd_fbheight = vs.height;
228 	gi->gd_fbx = 0;
229 	gi->gd_fby = 0;
230 	gi->gd_dwidth = vs.width;
231 	gi->gd_dheight = vs.height;
232 	gi->gd_dx = 0;
233 	gi->gd_dy = 0;
234 
235 	gp->g_regkva = (void *)0xDeadBeaf;	/* builtin */
236 	gp->g_fbkva = NULL;		/* not needed, view internal */
237 
238 	viewioctl(0, VIOCDISPLAY, NULL, -1, NULL);
239 }
240 #endif
241 
242