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