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