bw2.c revision 1.12.2.1 1 /* $NetBSD: bw2.c,v 1.12.2.1 1998/01/27 19:16:35 gwr Exp $ */
2
3 /*
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This software was developed by the Computer Systems Engineering group
8 * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9 * contributed to Berkeley.
10 *
11 * All advertising materials mentioning features or use of this software
12 * must display the following acknowledgement:
13 * This product includes software developed by the University of
14 * California, Lawrence Berkeley Laboratory.
15 *
16 * Redistribution and use in source and binary forms, with or without
17 * modification, are permitted provided that the following conditions
18 * are met:
19 * 1. Redistributions of source code must retain the above copyright
20 * notice, this list of conditions and the following disclaimer.
21 * 2. Redistributions in binary form must reproduce the above copyright
22 * notice, this list of conditions and the following disclaimer in the
23 * documentation and/or other materials provided with the distribution.
24 * 3. All advertising materials mentioning features or use of this software
25 * must display the following acknowledgement:
26 * This product includes software developed by the University of
27 * California, Berkeley and its contributors.
28 * 4. Neither the name of the University nor the names of its contributors
29 * may be used to endorse or promote products derived from this software
30 * without specific prior written permission.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42 * SUCH DAMAGE.
43 *
44 * @(#)bwtwo.c 8.1 (Berkeley) 6/11/93
45 */
46
47 /*
48 * black&white display (bw2) driver.
49 *
50 * Does not handle interrupts, even though they can occur.
51 */
52
53 #include <sys/param.h>
54 #include <sys/systm.h>
55 #include <sys/conf.h>
56 #include <sys/device.h>
57 #include <sys/ioctl.h>
58 #include <sys/malloc.h>
59 #include <sys/mman.h>
60 #include <sys/proc.h>
61 #include <sys/tty.h>
62
63 #include <vm/vm.h>
64
65 #include <machine/autoconf.h>
66 #include <machine/cpu.h>
67 #include <machine/fbio.h>
68 #include <machine/idprom.h>
69 #include <machine/pmap.h>
70
71 #include <sun3/sun3/machdep.h>
72
73 #include "fbvar.h"
74 #include "bw2reg.h"
75
76 cdev_decl(bw2);
77
78 /* per-display variables */
79 struct bw2_softc {
80 struct device sc_dev; /* base device */
81 struct fbdevice sc_fb; /* frame buffer device */
82 int sc_phys; /* display RAM (phys addr) */
83 int sc_pixeloffset; /* offset to framebuffer */
84 /* If using overlay plane of something, it is... */
85 int sc_ovtype; /* ... this type. */
86 int sc_video_on;
87 };
88
89 /* autoconfiguration driver */
90 static void bw2attach __P((struct device *, struct device *, void *));
91 static int bw2match __P((struct device *, struct cfdata *, void *));
92
93 struct cfattach bwtwo_ca = {
94 sizeof(struct bw2_softc), bw2match, bw2attach
95 };
96
97 extern struct cfdriver bwtwo_cd;
98
99 /* XXX we do not handle frame buffer interrupts */
100
101 static int bw2gvideo __P((struct fbdevice *, void *));
102 static int bw2svideo __P((struct fbdevice *, void *));
103
104 static struct fbdriver bw2fbdriver = {
105 bw2open, bw2close, bw2mmap,
106 fb_noioctl,
107 bw2gvideo, bw2svideo,
108 fb_noioctl, fb_noioctl, };
109
110 static int
111 bw2match(parent, cf, args)
112 struct device *parent;
113 struct cfdata *cf;
114 void *args;
115 {
116 struct confargs *ca = args;
117 int x;
118
119 #if 0 /* XXX - Assume only one is in use anyway... */
120 /*
121 * This driver only supports one unit because the
122 * system enable register is used for blanking.
123 */
124 if (cf->cf_unit != 0)
125 return (0);
126 #endif
127
128 if (ca->ca_paddr == -1) {
129 #ifdef _SUN3X_
130 /* Demand an address locator on 3X. */
131 return (0);
132 #else
133 if (cpu_machine_id == SUN3_MACH_50)
134 ca->ca_paddr = BW2_50_PADDR;
135 else
136 ca->ca_paddr = BW2_FB_PADDR;
137 #endif
138 }
139
140 /* The peek returns -1 on bus error. */
141 x = bus_peek(ca->ca_bustype, ca->ca_paddr, 1);
142 return (x != -1);
143 }
144
145 /*
146 * Attach a display. We need to notice if it is the console, too.
147 */
148 static void
149 bw2attach(parent, self, args)
150 struct device *parent, *self;
151 void *args;
152 {
153 struct bw2_softc *sc = (struct bw2_softc *)self;
154 struct fbdevice *fb = &sc->sc_fb;
155 struct confargs *ca = args;
156 struct fbtype *fbt;
157 int tmp;
158
159 sc->sc_phys = ca->ca_paddr;
160
161 fbt = &fb->fb_fbtype;
162 fbt->fb_type = FBTYPE_SUN2BW;
163 fbt->fb_width = 1152; /* default - see below */
164 fbt->fb_height = 900; /* default - see below */
165 fbt->fb_depth = 1;
166 fbt->fb_cmsize = 0;
167 fbt->fb_size = BW2_FBSIZE; /* default - see below */
168 fb->fb_driver = &bw2fbdriver;
169 fb->fb_private = sc;
170 fb->fb_name = sc->sc_dev.dv_xname;
171
172 #ifdef _SUN3_
173 switch (cpu_machine_id) {
174 case SUN3_MACH_60:
175 /*
176 * Only the model 60 can have hi-res.
177 * XXX - Use PROM screen size values?
178 */
179 tmp = bus_peek(BUS_OBMEM, BW2_CR_PADDR, 1);
180 if ((tmp != -1) && (tmp & 0x80) == 0)
181 goto high_res;
182 break;
183
184 case SUN3_MACH_260:
185 /* The Sun3/260 is ALWAYS high-resolution! */
186 high_res:
187 fbt->fb_width = 1600;
188 fbt->fb_height = 1280;
189 fbt->fb_size = BW2_FBSIZE_HIRES;
190 break;
191 }
192 #endif /* SUN3 */
193
194 printf(" (%dx%d)\n", fbt->fb_width, fbt->fb_height);
195 fb_attach(fb, 1);
196 }
197
198 int
199 bw2open(dev, flags, mode, p)
200 dev_t dev;
201 int flags, mode;
202 struct proc *p;
203 {
204 int unit = minor(dev);
205
206 if (unit >= bwtwo_cd.cd_ndevs || bwtwo_cd.cd_devs[unit] == NULL)
207 return (ENXIO);
208 return (0);
209 }
210
211 int
212 bw2close(dev, flags, mode, p)
213 dev_t dev;
214 int flags, mode;
215 struct proc *p;
216 {
217
218 return (0);
219 }
220
221 int
222 bw2ioctl(dev, cmd, data, flags, p)
223 dev_t dev;
224 u_long cmd;
225 caddr_t data;
226 int flags;
227 struct proc *p;
228 {
229 struct bw2_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
230
231 return (fbioctlfb(&sc->sc_fb, cmd, data));
232 }
233
234 /*
235 * Return the address that would map the given device at the given
236 * offset, allowing for the given protection, or return -1 for error.
237 */
238 int
239 bw2mmap(dev, off, prot)
240 dev_t dev;
241 int off, prot;
242 {
243 struct bw2_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
244
245 if (off & PGOFSET)
246 return (-1);
247 if ((unsigned)off >= sc->sc_fb.fb_fbtype.fb_size)
248 return (-1);
249 /*
250 * I turned on PMAP_NC here to disable the cache as I was
251 * getting horribly broken behaviour with it on.
252 */
253 return ((sc->sc_phys + off) | PMAP_NC);
254 }
255
256 /* FBIOGVIDEO: */
257 static int bw2gvideo(fb, data)
258 struct fbdevice *fb;
259 void *data;
260 {
261 struct bw2_softc *sc = fb->fb_private;
262 int *on = data;
263
264 *on = sc->sc_video_on;
265 return (0);
266 }
267
268 /* FBIOSVIDEO */
269 static int bw2svideo(fb, data)
270 struct fbdevice *fb;
271 void *data;
272 {
273 struct bw2_softc *sc = fb->fb_private;
274 int *on = data;
275
276 if (sc->sc_video_on == *on)
277 return (0);
278 sc->sc_video_on = *on;
279
280 /* XXX: P4 support... */
281 enable_video(sc->sc_video_on);
282
283 return(0);
284 }
285