1 /* $NetBSD: bwtwo_obio.c,v 1.14 2005/11/16 00:49:02 uwe 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_obio.c,v 1.14 2005/11/16 00:49:02 uwe 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 #include <machine/ctlreg.h> 103 #include <sparc/sparc/asm.h> 104 105 #include <dev/sun/fbio.h> 106 #include <dev/sun/fbvar.h> 107 #include <dev/sun/btreg.h> 108 #include <dev/sun/bwtworeg.h> 109 #include <dev/sun/bwtwovar.h> 110 #include <dev/sun/pfourreg.h> 111 112 /* autoconfiguration driver */ 113 static void bwtwoattach_obio (struct device *, struct device *, void *); 114 static int bwtwomatch_obio (struct device *, struct cfdata *, void *); 115 116 117 CFATTACH_DECL(bwtwo_obio, sizeof(struct bwtwo_softc), 118 bwtwomatch_obio, bwtwoattach_obio, NULL, NULL); 119 120 static int bwtwo_get_video_sun4(struct bwtwo_softc *); 121 static void bwtwo_set_video_sun4(struct bwtwo_softc *, int); 122 123 extern int fbnode; 124 125 static int 126 bwtwomatch_obio(struct device *parent, struct cfdata *cf, void *aux) 127 { 128 union obio_attach_args *uoba = aux; 129 struct obio4_attach_args *oba; 130 131 if (uoba->uoba_isobio4 == 0) 132 return (0); 133 134 oba = &uoba->uoba_oba4; 135 return (bus_space_probe(oba->oba_bustag, oba->oba_paddr, 136 4, /* probe size */ 137 0, /* offset */ 138 0, /* flags */ 139 bwtwo_pfour_probe, cf)); 140 } 141 142 static void 143 bwtwoattach_obio(struct device *parent, struct device *self, void *aux) 144 { 145 struct bwtwo_softc *sc = (struct bwtwo_softc *)self; 146 union obio_attach_args *uoba = aux; 147 struct obio4_attach_args *oba; 148 struct fbdevice *fb = &sc->sc_fb; 149 struct eeprom *eep = (struct eeprom *)eeprom_va; 150 bus_space_handle_t bh; 151 int constype, isconsole; 152 const char *name; 153 154 oba = &uoba->uoba_oba4; 155 156 /* Remember cookies for bwtwo_mmap() */ 157 sc->sc_bustag = oba->oba_bustag; 158 sc->sc_paddr = (bus_addr_t)oba->oba_paddr; 159 160 fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags; 161 fb->fb_type.fb_depth = 1; 162 fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900); 163 164 constype = (fb->fb_flags & FB_PFOUR) ? EE_CONS_P4OPT : EE_CONS_BW; 165 if (eep == NULL || eep->eeConsole == constype) 166 isconsole = fb_is_console(0); 167 else 168 isconsole = 0; 169 170 if (fb->fb_flags & FB_PFOUR) { 171 /* 172 * Map the pfour control register. 173 * Set pixel offset to appropriate overlay plane. 174 */ 175 name = "bwtwo/p4"; 176 177 if (bus_space_map(oba->oba_bustag, 178 oba->oba_paddr, 179 sizeof(uint32_t), 180 BUS_SPACE_MAP_LINEAR, 181 &bh) != 0) { 182 printf("%s: cannot map pfour register\n", 183 self->dv_xname); 184 return; 185 } 186 fb->fb_pfour = (uint32_t *)bh; 187 sc->sc_reg = NULL; 188 189 /* 190 * Notice if this is an overlay plane on a color 191 * framebuffer. Note that PFOUR_COLOR_OFF_OVERLAY 192 * is the same as PFOUR_BW_OFF, but we use the 193 * different names anyway. 194 */ 195 switch (PFOUR_ID(*fb->fb_pfour)) { 196 case PFOUR_ID_COLOR8P1: 197 sc->sc_ovtype = BWO_CGFOUR; 198 sc->sc_pixeloffset = PFOUR_COLOR_OFF_OVERLAY; 199 break; 200 201 case PFOUR_ID_COLOR24: 202 sc->sc_ovtype = BWO_CGEIGHT; 203 sc->sc_pixeloffset = PFOUR_COLOR_OFF_OVERLAY; 204 break; 205 206 default: 207 sc->sc_ovtype = BWO_NONE; 208 sc->sc_pixeloffset = PFOUR_BW_OFF; 209 break; 210 } 211 212 } else { 213 /* A plain bwtwo */ 214 if (bus_space_map(oba->oba_bustag, 215 oba->oba_paddr + BWREG_REG, 216 sizeof(struct fbcontrol), 217 BUS_SPACE_MAP_LINEAR, 218 &bh) != 0) { 219 printf("%s: cannot map control registers\n", 220 self->dv_xname); 221 return; 222 } 223 sc->sc_reg = (struct fbcontrol *)bh; 224 fb->fb_pfour = NULL; 225 226 name = "bwtwo"; 227 sc->sc_pixeloffset = BWREG_MEM; 228 } 229 sc->sc_get_video = bwtwo_get_video_sun4; 230 sc->sc_set_video = bwtwo_set_video_sun4; 231 232 if (isconsole) { 233 int ramsize = fb->fb_type.fb_height * fb->fb_linebytes; 234 if (bus_space_map(oba->oba_bustag, 235 oba->oba_paddr + sc->sc_pixeloffset, 236 ramsize, 237 BUS_SPACE_MAP_LINEAR, 238 &bh) != 0) { 239 printf("%s: cannot map pixels\n", self->dv_xname); 240 return; 241 } 242 sc->sc_fb.fb_pixels = (char *)bh; 243 } 244 245 bwtwoattach(sc, name, isconsole); 246 } 247 248 static void 249 bwtwo_set_video_sun4(struct bwtwo_softc *sc, int enable) 250 { 251 252 if (sc->sc_fb.fb_flags & FB_PFOUR) { 253 /* 254 * This handles the overlay plane case, too. 255 */ 256 fb_pfour_set_video(&sc->sc_fb, enable); 257 return; 258 } 259 if (enable) 260 stba(AC_SYSENABLE, ASI_CONTROL, 261 lduba(AC_SYSENABLE, ASI_CONTROL) | SYSEN_VIDEO); 262 else 263 stba(AC_SYSENABLE, ASI_CONTROL, 264 lduba(AC_SYSENABLE, ASI_CONTROL) & ~SYSEN_VIDEO); 265 266 return; 267 } 268 269 static int 270 bwtwo_get_video_sun4(struct bwtwo_softc *sc) 271 { 272 273 if (sc->sc_fb.fb_flags & FB_PFOUR) { 274 /* 275 * This handles the overlay plane case, too. 276 */ 277 return (fb_pfour_get_video(&sc->sc_fb)); 278 } else 279 return ((lduba(AC_SYSENABLE, ASI_CONTROL) & SYSEN_VIDEO) != 0); 280 } 281