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