xref: /netbsd/sys/arch/amiga/dev/grf_cc.c (revision c4a72b64)
1 /*	$NetBSD: grf_cc.c,v 1.34 2002/10/02 04:55:49 thorpej 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 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: grf_cc.c,v 1.34 2002/10/02 04:55:49 thorpej Exp $");
35 
36 #include "grfcc.h"
37 #if NGRFCC > 0
38 /*
39  * currently this is a backward compat hack that interface to
40  * view.c
41  */
42 
43 #include <sys/param.h>
44 #include <sys/proc.h>
45 #include <sys/errno.h>
46 #include <sys/ioctl.h>
47 #include <sys/queue.h>
48 #include <sys/device.h>
49 #include <sys/systm.h>
50 #include <sys/conf.h>
51 #include <machine/cpu.h>
52 #include <amiga/amiga/color.h>	/* DEBUG */
53 #include <amiga/amiga/device.h>
54 #include <amiga/amiga/custom.h>
55 #include <amiga/amiga/cia.h>
56 #include <amiga/dev/grfioctl.h>
57 #include <amiga/dev/grfvar.h>
58 #include <amiga/dev/grf_ccreg.h>
59 #include <amiga/dev/grfabs_reg.h>
60 #include <amiga/dev/viewioctl.h>
61 
62 #include <uvm/uvm_extern.h>
63 
64 #include "view.h"
65 
66 int grfccmatch(struct device *, struct cfdata *, void *);
67 int grfccprint(void *, const char *);
68 void grfccattach(struct device *, struct device *, void *);
69 void grf_cc_on(struct grf_softc *);
70 
71 CFATTACH_DECL(grfcc, sizeof(struct grf_softc),
72     grfccmatch, grfccattach, NULL, NULL);
73 
74 /*
75  * only used in console init
76  */
77 static struct cfdata *cfdata;
78 
79 /*
80  * we make sure to only init things once.  this is somewhat
81  * tricky regarding the console.
82  */
83 int
84 grfccmatch(struct device *pdp, struct cfdata *cfp, void *auxp)
85 {
86 	static int ccconunit = -1;
87 	char *mainbus_name = auxp;
88 	extern const struct cdevsw view_cdevsw;
89 
90 	/*
91 	 * allow only one cc console
92 	 */
93 	if (amiga_realconfig == 0 && ccconunit != -1)
94 		return(0);
95 	if (matchname("grfcc", mainbus_name) == 0)
96 		return(0);
97 	if (amiga_realconfig == 0 || ccconunit != cfp->cf_unit) {
98 		if (grfcc_probe() == 0)
99 			return(0);
100 		viewprobe();
101 		/*
102 		 * XXX nasty hack. opens view[0] and never closes.
103 		 */
104 		if ((*view_cdevsw.d_open)(0, 0, 0, NULL))
105 			return(0);
106 		if (amiga_realconfig == 0) {
107 			ccconunit = cfp->cf_unit;
108 			cfdata = cfp;
109 		}
110 	}
111 	return(1);
112 }
113 
114 /*
115  * attach to the grfbus (mainbus)
116  */
117 void
118 grfccattach(struct device *pdp, struct device *dp, void *auxp)
119 {
120 	static struct grf_softc congrf;
121 	struct grf_softc *gp;
122 
123 	if (dp == NULL)
124 		gp = &congrf;
125 	else
126 		gp = (struct grf_softc *)dp;
127 
128 	if (dp != NULL && congrf.g_regkva != 0) {
129 		/*
130 		 * we inited earlier just copy the info
131 		 * take care not to copy the device struct though.
132 		 */
133 		bcopy(&congrf.g_display, &gp->g_display,
134 		    (char *)&gp[1] - (char *)&gp->g_display);
135 	} else {
136 		gp->g_unit = GRF_CC_UNIT;
137 		gp->g_flags = GF_ALIVE;
138 		gp->g_mode = cc_mode;
139 		gp->g_conpri = grfcc_cnprobe();
140 		grfcc_iteinit(gp);
141 		grf_cc_on(gp);
142 	}
143 	if (dp != NULL)
144 		printf("\n");
145 	/*
146 	 * attach grf
147 	 */
148 	amiga_config_found(cfdata, &gp->g_device, gp, grfccprint);
149 }
150 
151 int
152 grfccprint(void *auxp, const char *pnp)
153 {
154 	if (pnp)
155 		printf("grf%d at %s", ((struct grf_softc *)auxp)->g_unit,
156 			pnp);
157 	return(UNCONF);
158 }
159 
160 /*
161  * Change the mode of the display.
162  * Right now all we can do is grfon/grfoff.
163  * Return a UNIX error number or 0 for success.
164  */
165 /*ARGSUSED*/
166 int
167 cc_mode(struct grf_softc *gp, u_long cmd, void *arg, u_long a2, int a3)
168 {
169 	extern const struct cdevsw view_cdevsw;
170 
171 	switch (cmd) {
172 	case GM_GRFON:
173 		grf_cc_on(gp);
174 		return(0);
175 	case GM_GRFOFF:
176 		(*view_cdevsw.d_ioctl)(0, VIOCREMOVE, NULL, -1, NULL);
177 		return(0);
178 	case GM_GRFCONFIG:
179 	default:
180 		break;
181 	}
182 	return(EPASSTHROUGH);
183 }
184 
185 void
186 grf_cc_on(struct grf_softc *gp)
187 {
188 	struct view_size vs;
189 	bmap_t bm;
190 	struct grfinfo *gi;
191 	extern const struct cdevsw view_cdevsw;
192 
193 	gi = &gp->g_display;
194 
195 	/* XXX type of bm ? */
196 	(*view_cdevsw.d_ioctl)(0, VIOCGBMAP, (caddr_t)&bm, -1, NULL);
197 
198 	gp->g_data = (caddr_t) 0xDeadBeaf; /* not particularly clean.. */
199 
200 	gi->gd_regaddr = (caddr_t) 0xdff000;	/* depricated */
201 	gi->gd_regsize = round_page(sizeof (custom));
202 	gi->gd_fbaddr  = bm.hardware_address;
203 	gi->gd_fbsize  = bm.depth*bm.bytes_per_row*bm.rows;
204 
205 	if ((*view_cdevsw.d_ioctl)(0, VIOCGSIZE, (caddr_t)&vs, -1, NULL)) {
206 		/* XXX type of vs ? */
207 		/* fill in some default values... XXX */
208 		vs.width = 640;
209 		vs.height = 400;
210 		vs.depth = 2;
211 	}
212 	gi->gd_colors = 1 << vs.depth;
213 	gi->gd_planes = vs.depth;
214 
215 	gi->gd_fbwidth = vs.width;
216 	gi->gd_fbheight = vs.height;
217 	gi->gd_fbx = 0;
218 	gi->gd_fby = 0;
219 	gi->gd_dwidth = vs.width;
220 	gi->gd_dheight = vs.height;
221 	gi->gd_dx = 0;
222 	gi->gd_dy = 0;
223 
224 	gp->g_regkva = (void *)0xDeadBeaf;	/* builtin */
225 	gp->g_fbkva = NULL;		/* not needed, view internal */
226 
227 	(*view_cdevsw.d_ioctl)(0, VIOCDISPLAY, NULL, -1, NULL);
228 }
229 #endif
230 
231