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