xref: /netbsd-src/sys/arch/amiga/dev/grf_cc.c (revision ae1bfcddc410612bc8c58b807e1830becb69a24c)
1 /*
2  *	$Id: grf_cc.c,v 1.12 1994/05/08 05:53:04 chopps Exp $
3  */
4 
5 #include "grf.h"
6 #if NGRF > 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_mode = cc_mode;
108 		gp->g_conpri = grfcc_cnprobe();
109 		grfcc_iteinit(gp);
110 		grf_cc_on(gp);
111 	}
112 	if (dp != NULL)
113 		printf("\n");
114 	/*
115 	 * attach grf
116 	 */
117 	amiga_config_found(cfdata, &gp->g_device, gp, grfccprint);
118 }
119 
120 int
121 grfccprint(auxp, pnp)
122 	void *auxp;
123 	char *pnp;
124 {
125 	if (pnp)
126 		printf("grf%d at %s", ((struct grf_softc *)auxp)->g_unit,
127 			pnp);
128 	return(UNCONF);
129 }
130 
131 /*
132  * Change the mode of the display.
133  * Right now all we can do is grfon/grfoff.
134  * Return a UNIX error number or 0 for success.
135  */
136 /*ARGSUSED*/
137 int
138 cc_mode(gp, cmd, arg, a2, a3)
139 	struct grf_softc *gp;
140 	int cmd, a2, a3;
141 	void *arg;
142 {
143 	switch (cmd) {
144 	case GM_GRFON:
145 		grf_cc_on(gp);
146 		return(0);
147 	case GM_GRFOFF:
148 		viewioctl(0, VIOCREMOVE, NULL, 0, -1);
149 		return(0);
150 	case GM_GRFCONFIG:
151 	default:
152 		break;
153 	}
154 	return(EINVAL);
155 }
156 
157 void
158 grf_cc_on(gp)
159 	struct grf_softc *gp;
160 {
161 	struct view_size vs;
162 	bmap_t bm;
163 	struct grfinfo *gi;
164 
165 	gi = &gp->g_display;
166 
167 	viewioctl(0, VIOCGBMAP, &bm, 0, -1);
168 
169 	gp->g_data = (caddr_t) 0xDeadBeaf; /* not particularly clean.. */
170 
171 	gi->gd_regaddr = (caddr_t) 0xdff000;	/* depricated */
172 	gi->gd_regsize = round_page(sizeof (custom));
173 	gi->gd_fbaddr  = bm.hardware_address;
174 	gi->gd_fbsize  = bm.depth*bm.bytes_per_row*bm.rows;
175 
176 	if (viewioctl (0, VIOCGSIZE, &vs, 0, -1)) {
177 		/* fill in some default values... XXX */
178 		vs.width = 640;
179 		vs.height = 400;
180 		vs.depth = 2;
181 	}
182 	gi->gd_colors = 1 << vs.depth;
183 	gi->gd_planes = vs.depth;
184 
185 	gi->gd_fbwidth = vs.width;
186 	gi->gd_fbheight = vs.height;
187 	gi->gd_fbx = 0;
188 	gi->gd_fby = 0;
189 	gi->gd_dwidth = vs.width;
190 	gi->gd_dheight = vs.height;
191 	gi->gd_dx = 0;
192 	gi->gd_dy = 0;
193 
194 	gp->g_regkva = (void *)0xDeadBeaf;	/* builtin */
195 	gp->g_fbkva = NULL;		/* not needed, view internal */
196 
197 	viewioctl(0, VIOCDISPLAY, NULL, 0, -1);
198 }
199 #endif
200 
201