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