bwtwo.c revision 1.6 1 1.6 jdolecek /* $NetBSD: bwtwo.c,v 1.6 2002/10/23 09:13:53 jdolecek Exp $ */
2 1.1 pk
3 1.1 pk /*-
4 1.1 pk * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
5 1.1 pk * All rights reserved.
6 1.1 pk *
7 1.1 pk * This code is derived from software contributed to The NetBSD Foundation
8 1.1 pk * by Jason R. Thorpe.
9 1.1 pk *
10 1.1 pk * Redistribution and use in source and binary forms, with or without
11 1.1 pk * modification, are permitted provided that the following conditions
12 1.1 pk * are met:
13 1.1 pk * 1. Redistributions of source code must retain the above copyright
14 1.1 pk * notice, this list of conditions and the following disclaimer.
15 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pk * notice, this list of conditions and the following disclaimer in the
17 1.1 pk * documentation and/or other materials provided with the distribution.
18 1.1 pk * 3. All advertising materials mentioning features or use of this software
19 1.1 pk * must display the following acknowledgement:
20 1.1 pk * This product includes software developed by the NetBSD
21 1.1 pk * Foundation, Inc. and its contributors.
22 1.1 pk * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 pk * contributors may be used to endorse or promote products derived
24 1.1 pk * from this software without specific prior written permission.
25 1.1 pk *
26 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 pk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 pk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 pk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 pk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 pk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 pk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 pk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 pk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 pk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 pk * POSSIBILITY OF SUCH DAMAGE.
37 1.1 pk */
38 1.1 pk
39 1.1 pk /*
40 1.1 pk * Copyright (c) 1992, 1993
41 1.1 pk * The Regents of the University of California. All rights reserved.
42 1.1 pk *
43 1.1 pk * This software was developed by the Computer Systems Engineering group
44 1.1 pk * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
45 1.1 pk * contributed to Berkeley.
46 1.1 pk *
47 1.1 pk * All advertising materials mentioning features or use of this software
48 1.1 pk * must display the following acknowledgement:
49 1.1 pk * This product includes software developed by the University of
50 1.1 pk * California, Lawrence Berkeley Laboratory.
51 1.1 pk *
52 1.1 pk * Redistribution and use in source and binary forms, with or without
53 1.1 pk * modification, are permitted provided that the following conditions
54 1.1 pk * are met:
55 1.1 pk * 1. Redistributions of source code must retain the above copyright
56 1.1 pk * notice, this list of conditions and the following disclaimer.
57 1.1 pk * 2. Redistributions in binary form must reproduce the above copyright
58 1.1 pk * notice, this list of conditions and the following disclaimer in the
59 1.1 pk * documentation and/or other materials provided with the distribution.
60 1.1 pk * 3. All advertising materials mentioning features or use of this software
61 1.1 pk * must display the following acknowledgement:
62 1.1 pk * This product includes software developed by the University of
63 1.1 pk * California, Berkeley and its contributors.
64 1.1 pk * 4. Neither the name of the University nor the names of its contributors
65 1.1 pk * may be used to endorse or promote products derived from this software
66 1.1 pk * without specific prior written permission.
67 1.1 pk *
68 1.1 pk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
69 1.1 pk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
70 1.1 pk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
71 1.1 pk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
72 1.1 pk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
73 1.1 pk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
74 1.1 pk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
75 1.1 pk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
76 1.1 pk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
77 1.1 pk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
78 1.1 pk * SUCH DAMAGE.
79 1.1 pk *
80 1.1 pk * @(#)bwtwo.c 8.1 (Berkeley) 6/11/93
81 1.1 pk */
82 1.1 pk
83 1.1 pk /*
84 1.1 pk * black & white display (bwtwo) driver.
85 1.1 pk *
86 1.1 pk * Does not handle interrupts, even though they can occur.
87 1.1 pk *
88 1.1 pk * P4 and overlay plane support by Jason R. Thorpe <thorpej (at) NetBSD.ORG>.
89 1.1 pk * Overlay plane handling hints and ideas provided by Brad Spencer.
90 1.1 pk */
91 1.4 lukem
92 1.4 lukem #include <sys/cdefs.h>
93 1.6 jdolecek __KERNEL_RCSID(0, "$NetBSD: bwtwo.c,v 1.6 2002/10/23 09:13:53 jdolecek Exp $");
94 1.1 pk
95 1.1 pk #include <sys/param.h>
96 1.1 pk #include <sys/systm.h>
97 1.1 pk #include <sys/device.h>
98 1.1 pk #include <sys/ioctl.h>
99 1.1 pk #include <sys/malloc.h>
100 1.1 pk #include <sys/mman.h>
101 1.1 pk #include <sys/tty.h>
102 1.1 pk #include <sys/conf.h>
103 1.1 pk
104 1.1 pk #include <machine/autoconf.h>
105 1.1 pk #include <machine/eeprom.h>
106 1.1 pk
107 1.2 pk #include <dev/sun/fbio.h>
108 1.2 pk #include <dev/sun/fbvar.h>
109 1.1 pk #include <dev/sun/btreg.h>
110 1.1 pk #include <dev/sun/bwtworeg.h>
111 1.1 pk #include <dev/sun/bwtwovar.h>
112 1.1 pk #include <dev/sun/pfourreg.h>
113 1.1 pk
114 1.5 gehenna extern struct cfdriver bwtwo_cd;
115 1.1 pk
116 1.5 gehenna dev_type_open(bwtwoopen);
117 1.5 gehenna dev_type_ioctl(bwtwoioctl);
118 1.5 gehenna dev_type_mmap(bwtwommap);
119 1.5 gehenna
120 1.5 gehenna const struct cdevsw bwtwo_cdevsw = {
121 1.5 gehenna bwtwoopen, nullclose, noread, nowrite, bwtwoioctl,
122 1.6 jdolecek nostop, notty, nopoll, bwtwommap, nokqfilter,
123 1.5 gehenna };
124 1.1 pk
125 1.1 pk /* XXX we do not handle frame buffer interrupts (do not know how) */
126 1.1 pk static void bwtwounblank(struct device *);
127 1.1 pk
128 1.1 pk /* frame buffer generic driver */
129 1.1 pk static struct fbdriver bwtwofbdriver = {
130 1.6 jdolecek bwtwounblank, bwtwoopen, nullclose, bwtwoioctl, nopoll, bwtwommap,
131 1.6 jdolecek nokqfilter
132 1.1 pk };
133 1.1 pk
134 1.1 pk int
135 1.1 pk bwtwo_pfour_probe(vaddr, arg)
136 1.1 pk void *vaddr;
137 1.1 pk void *arg;
138 1.1 pk {
139 1.1 pk struct cfdata *cf = arg;
140 1.1 pk
141 1.1 pk switch (fb_pfour_id(vaddr)) {
142 1.1 pk case PFOUR_ID_BW:
143 1.1 pk case PFOUR_ID_COLOR8P1: /* bwtwo in ... */
144 1.1 pk case PFOUR_ID_COLOR24: /* ...overlay plane */
145 1.1 pk /* This is wrong; should be done in bwtwo_attach() */
146 1.1 pk cf->cf_flags |= FB_PFOUR;
147 1.1 pk /* FALLTHROUGH */
148 1.1 pk case PFOUR_NOTPFOUR:
149 1.1 pk return (1);
150 1.1 pk }
151 1.1 pk return (0);
152 1.1 pk }
153 1.1 pk
154 1.1 pk void
155 1.1 pk bwtwoattach(sc, name, isconsole)
156 1.1 pk struct bwtwo_softc *sc;
157 1.1 pk char *name;
158 1.1 pk int isconsole;
159 1.1 pk {
160 1.1 pk struct fbdevice *fb = &sc->sc_fb;
161 1.1 pk
162 1.1 pk /* Fill in the remaining fbdevice values */
163 1.1 pk fb->fb_driver = &bwtwofbdriver;
164 1.1 pk fb->fb_device = &sc->sc_dev;
165 1.1 pk fb->fb_type.fb_type = FBTYPE_SUN2BW;
166 1.1 pk fb->fb_type.fb_cmsize = 0;
167 1.1 pk fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
168 1.1 pk printf(": %s, %d x %d", name,
169 1.1 pk fb->fb_type.fb_width, fb->fb_type.fb_height);
170 1.1 pk
171 1.1 pk /* Insure video is enabled */
172 1.1 pk sc->sc_set_video(sc, 1);
173 1.1 pk
174 1.1 pk if (isconsole) {
175 1.1 pk printf(" (console)\n");
176 1.1 pk #ifdef RASTERCONSOLE
177 1.1 pk /*
178 1.1 pk * XXX rcons doesn't seem to work properly on the overlay
179 1.1 pk * XXX plane. This is a temporary kludge until someone
180 1.1 pk * XXX fixes it.
181 1.1 pk */
182 1.1 pk if ((fb->fb_flags & FB_PFOUR) == 0 ||
183 1.1 pk (sc->sc_ovtype == BWO_NONE))
184 1.1 pk fbrcons_init(fb);
185 1.1 pk #endif
186 1.1 pk } else
187 1.1 pk printf("\n");
188 1.1 pk
189 1.1 pk if ((fb->fb_flags & FB_PFOUR) && (sc->sc_ovtype != BWO_NONE)) {
190 1.1 pk char *ovnam;
191 1.1 pk
192 1.1 pk switch (sc->sc_ovtype) {
193 1.1 pk case BWO_CGFOUR:
194 1.1 pk ovnam = "cgfour";
195 1.1 pk break;
196 1.1 pk
197 1.1 pk case BWO_CGEIGHT:
198 1.1 pk ovnam = "cgeight";
199 1.1 pk break;
200 1.1 pk
201 1.1 pk default:
202 1.1 pk ovnam = "unknown";
203 1.1 pk break;
204 1.1 pk }
205 1.1 pk printf("%s: %s overlay plane\n", sc->sc_dev.dv_xname, ovnam);
206 1.1 pk }
207 1.1 pk
208 1.1 pk /*
209 1.1 pk * If we're on an overlay plane of a color framebuffer,
210 1.1 pk * then we don't force the issue in fb_attach() because
211 1.1 pk * we'd like the color framebuffer to actually be the
212 1.1 pk * "console framebuffer". We're only around to speed
213 1.1 pk * up rconsole.
214 1.1 pk */
215 1.1 pk if ((fb->fb_flags & FB_PFOUR) && (sc->sc_ovtype != BWO_NONE ))
216 1.1 pk fb_attach(fb, 0);
217 1.1 pk else
218 1.1 pk fb_attach(fb, isconsole);
219 1.1 pk }
220 1.1 pk
221 1.1 pk int
222 1.1 pk bwtwoopen(dev, flags, mode, p)
223 1.1 pk dev_t dev;
224 1.1 pk int flags, mode;
225 1.1 pk struct proc *p;
226 1.1 pk {
227 1.1 pk int unit = minor(dev);
228 1.1 pk
229 1.1 pk if (unit >= bwtwo_cd.cd_ndevs || bwtwo_cd.cd_devs[unit] == NULL)
230 1.1 pk return (ENXIO);
231 1.1 pk
232 1.1 pk return (0);
233 1.1 pk }
234 1.1 pk
235 1.1 pk int
236 1.1 pk bwtwoioctl(dev, cmd, data, flags, p)
237 1.1 pk dev_t dev;
238 1.1 pk u_long cmd;
239 1.1 pk caddr_t data;
240 1.1 pk int flags;
241 1.1 pk struct proc *p;
242 1.1 pk {
243 1.1 pk struct bwtwo_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
244 1.1 pk
245 1.1 pk switch (cmd) {
246 1.1 pk
247 1.1 pk case FBIOGTYPE:
248 1.1 pk *(struct fbtype *)data = sc->sc_fb.fb_type;
249 1.1 pk break;
250 1.1 pk
251 1.1 pk case FBIOGVIDEO:
252 1.1 pk *(int *)data = sc->sc_get_video(sc);
253 1.1 pk break;
254 1.1 pk
255 1.1 pk case FBIOSVIDEO:
256 1.1 pk sc->sc_set_video(sc, (*(int *)data));
257 1.1 pk break;
258 1.1 pk
259 1.1 pk default:
260 1.1 pk return (ENOTTY);
261 1.1 pk }
262 1.1 pk return (0);
263 1.1 pk }
264 1.1 pk
265 1.1 pk static void
266 1.1 pk bwtwounblank(dev)
267 1.1 pk struct device *dev;
268 1.1 pk {
269 1.1 pk struct bwtwo_softc *sc = (struct bwtwo_softc *)dev;
270 1.1 pk
271 1.1 pk sc->sc_set_video(sc, 1);
272 1.1 pk }
273 1.1 pk
274 1.1 pk /*
275 1.1 pk * Return the address that would map the given device at the given
276 1.1 pk * offset, allowing for the given protection, or return -1 for error.
277 1.1 pk */
278 1.1 pk paddr_t
279 1.1 pk bwtwommap(dev, off, prot)
280 1.1 pk dev_t dev;
281 1.1 pk off_t off;
282 1.1 pk int prot;
283 1.1 pk {
284 1.1 pk struct bwtwo_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
285 1.1 pk
286 1.1 pk if (off & PGOFSET)
287 1.1 pk panic("bwtwommap");
288 1.1 pk
289 1.1 pk if (off >= sc->sc_fb.fb_type.fb_size)
290 1.1 pk return (-1);
291 1.1 pk
292 1.3 eeh return (bus_space_mmap(sc->sc_bustag,
293 1.3 eeh sc->sc_paddr, sc->sc_pixeloffset + off,
294 1.3 eeh prot, BUS_SPACE_MAP_LINEAR));
295 1.1 pk }
296