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