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