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