xref: /netbsd/sys/dev/sun/bwtwo.c (revision c4a72b64)
1 /*	$NetBSD: bwtwo.c,v 1.6 2002/10/23 09:13:53 jdolecek 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@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.6 2002/10/23 09:13:53 jdolecek 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, nokqfilter,
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 	nokqfilter
132 };
133 
134 int
135 bwtwo_pfour_probe(vaddr, arg)
136 	void *vaddr;
137 	void *arg;
138 {
139 	struct cfdata *cf = arg;
140 
141 	switch (fb_pfour_id(vaddr)) {
142 	case PFOUR_ID_BW:
143 	case PFOUR_ID_COLOR8P1:		/* bwtwo in ... */
144 	case PFOUR_ID_COLOR24:		/* ...overlay plane */
145 		/* This is wrong; should be done in bwtwo_attach() */
146 		cf->cf_flags |= FB_PFOUR;
147 		/* FALLTHROUGH */
148 	case PFOUR_NOTPFOUR:
149 		return (1);
150 	}
151 	return (0);
152 }
153 
154 void
155 bwtwoattach(sc, name, isconsole)
156 	struct	bwtwo_softc *sc;
157 	char	*name;
158 	int	isconsole;
159 {
160 	struct fbdevice *fb = &sc->sc_fb;
161 
162 	/* Fill in the remaining fbdevice values */
163 	fb->fb_driver = &bwtwofbdriver;
164 	fb->fb_device = &sc->sc_dev;
165 	fb->fb_type.fb_type = FBTYPE_SUN2BW;
166 	fb->fb_type.fb_cmsize = 0;
167 	fb->fb_type.fb_size = fb->fb_type.fb_height * fb->fb_linebytes;
168 	printf(": %s, %d x %d", name,
169 	       fb->fb_type.fb_width, fb->fb_type.fb_height);
170 
171 	/* Insure video is enabled */
172 	sc->sc_set_video(sc, 1);
173 
174 	if (isconsole) {
175 		printf(" (console)\n");
176 #ifdef RASTERCONSOLE
177 		/*
178 		 * XXX rcons doesn't seem to work properly on the overlay
179 		 * XXX plane.  This is a temporary kludge until someone
180 		 * XXX fixes it.
181 		 */
182 		if ((fb->fb_flags & FB_PFOUR) == 0 ||
183 		    (sc->sc_ovtype == BWO_NONE))
184 			fbrcons_init(fb);
185 #endif
186 	} else
187 		printf("\n");
188 
189 	if ((fb->fb_flags & FB_PFOUR) && (sc->sc_ovtype != BWO_NONE)) {
190 		char *ovnam;
191 
192 		switch (sc->sc_ovtype) {
193 		case BWO_CGFOUR:
194 			ovnam = "cgfour";
195 			break;
196 
197 		case BWO_CGEIGHT:
198 			ovnam = "cgeight";
199 			break;
200 
201 		default:
202 			ovnam = "unknown";
203 			break;
204 		}
205 		printf("%s: %s overlay plane\n", sc->sc_dev.dv_xname, ovnam);
206 	}
207 
208 	/*
209 	 * If we're on an overlay plane of a color framebuffer,
210 	 * then we don't force the issue in fb_attach() because
211 	 * we'd like the color framebuffer to actually be the
212 	 * "console framebuffer".  We're only around to speed
213 	 * up rconsole.
214 	 */
215 	if ((fb->fb_flags & FB_PFOUR) && (sc->sc_ovtype != BWO_NONE ))
216 		fb_attach(fb, 0);
217 	else
218 		fb_attach(fb, isconsole);
219 }
220 
221 int
222 bwtwoopen(dev, flags, mode, p)
223 	dev_t dev;
224 	int flags, mode;
225 	struct proc *p;
226 {
227 	int unit = minor(dev);
228 
229 	if (unit >= bwtwo_cd.cd_ndevs || bwtwo_cd.cd_devs[unit] == NULL)
230 		return (ENXIO);
231 
232 	return (0);
233 }
234 
235 int
236 bwtwoioctl(dev, cmd, data, flags, p)
237 	dev_t dev;
238 	u_long cmd;
239 	caddr_t data;
240 	int flags;
241 	struct proc *p;
242 {
243 	struct bwtwo_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
244 
245 	switch (cmd) {
246 
247 	case FBIOGTYPE:
248 		*(struct fbtype *)data = sc->sc_fb.fb_type;
249 		break;
250 
251 	case FBIOGVIDEO:
252 		*(int *)data = sc->sc_get_video(sc);
253 		break;
254 
255 	case FBIOSVIDEO:
256 		sc->sc_set_video(sc, (*(int *)data));
257 		break;
258 
259 	default:
260 		return (ENOTTY);
261 	}
262 	return (0);
263 }
264 
265 static void
266 bwtwounblank(dev)
267 	struct device *dev;
268 {
269 	struct bwtwo_softc *sc = (struct bwtwo_softc *)dev;
270 
271 	sc->sc_set_video(sc, 1);
272 }
273 
274 /*
275  * Return the address that would map the given device at the given
276  * offset, allowing for the given protection, or return -1 for error.
277  */
278 paddr_t
279 bwtwommap(dev, off, prot)
280 	dev_t dev;
281 	off_t off;
282 	int prot;
283 {
284 	struct bwtwo_softc *sc = bwtwo_cd.cd_devs[minor(dev)];
285 
286 	if (off & PGOFSET)
287 		panic("bwtwommap");
288 
289 	if (off >= sc->sc_fb.fb_type.fb_size)
290 		return (-1);
291 
292 	return (bus_space_mmap(sc->sc_bustag,
293 		sc->sc_paddr, sc->sc_pixeloffset + off,
294 		prot, BUS_SPACE_MAP_LINEAR));
295 }
296