1 1.18 thorpej /* $NetBSD: bwtwo_any.c,v 1.18 2023/12/20 05:13:35 thorpej Exp $ */ 2 1.1 fredette 3 1.1 fredette /*- 4 1.1 fredette * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. 5 1.1 fredette * All rights reserved. 6 1.1 fredette * 7 1.1 fredette * This code is derived from software contributed to The NetBSD Foundation 8 1.1 fredette * by Jason R. Thorpe and Matthew Fredette. 9 1.1 fredette * 10 1.1 fredette * Redistribution and use in source and binary forms, with or without 11 1.1 fredette * modification, are permitted provided that the following conditions 12 1.1 fredette * are met: 13 1.1 fredette * 1. Redistributions of source code must retain the above copyright 14 1.1 fredette * notice, this list of conditions and the following disclaimer. 15 1.1 fredette * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 fredette * notice, this list of conditions and the following disclaimer in the 17 1.1 fredette * documentation and/or other materials provided with the distribution. 18 1.1 fredette * 19 1.1 fredette * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.1 fredette * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.1 fredette * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.1 fredette * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.1 fredette * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.1 fredette * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.1 fredette * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.1 fredette * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.1 fredette * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.1 fredette * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.1 fredette * POSSIBILITY OF SUCH DAMAGE. 30 1.1 fredette */ 31 1.1 fredette 32 1.1 fredette /* 33 1.1 fredette * Copyright (c) 1992, 1993 34 1.1 fredette * The Regents of the University of California. All rights reserved. 35 1.1 fredette * 36 1.1 fredette * This software was developed by the Computer Systems Engineering group 37 1.1 fredette * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 38 1.1 fredette * contributed to Berkeley. 39 1.1 fredette * 40 1.1 fredette * All advertising materials mentioning features or use of this software 41 1.1 fredette * must display the following acknowledgement: 42 1.1 fredette * This product includes software developed by the University of 43 1.1 fredette * California, Lawrence Berkeley Laboratory. 44 1.1 fredette * 45 1.1 fredette * Redistribution and use in source and binary forms, with or without 46 1.1 fredette * modification, are permitted provided that the following conditions 47 1.1 fredette * are met: 48 1.1 fredette * 1. Redistributions of source code must retain the above copyright 49 1.1 fredette * notice, this list of conditions and the following disclaimer. 50 1.1 fredette * 2. Redistributions in binary form must reproduce the above copyright 51 1.1 fredette * notice, this list of conditions and the following disclaimer in the 52 1.1 fredette * documentation and/or other materials provided with the distribution. 53 1.10 agc * 3. Neither the name of the University nor the names of its contributors 54 1.1 fredette * may be used to endorse or promote products derived from this software 55 1.1 fredette * without specific prior written permission. 56 1.1 fredette * 57 1.1 fredette * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 58 1.1 fredette * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 59 1.1 fredette * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 60 1.1 fredette * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 61 1.1 fredette * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 62 1.1 fredette * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 63 1.1 fredette * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 64 1.1 fredette * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 65 1.1 fredette * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 66 1.1 fredette * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 67 1.1 fredette * SUCH DAMAGE. 68 1.1 fredette * 69 1.1 fredette * @(#)bwtwo.c 8.1 (Berkeley) 6/11/93 70 1.1 fredette */ 71 1.1 fredette 72 1.1 fredette /* 73 1.1 fredette * black&white display (bwtwo) driver. 74 1.1 fredette * 75 1.1 fredette * Does not handle interrupts, even though they can occur. 76 1.1 fredette * 77 1.11 keihan * P4 and overlay plane support by Jason R. Thorpe <thorpej (at) NetBSD.org>. 78 1.1 fredette * Overlay plane handling hints and ideas provided by Brad Spencer. 79 1.1 fredette */ 80 1.9 lukem 81 1.9 lukem #include <sys/cdefs.h> 82 1.18 thorpej __KERNEL_RCSID(0, "$NetBSD: bwtwo_any.c,v 1.18 2023/12/20 05:13:35 thorpej Exp $"); 83 1.1 fredette 84 1.1 fredette #include <sys/param.h> 85 1.1 fredette #include <sys/systm.h> 86 1.1 fredette #include <sys/device.h> 87 1.1 fredette #include <sys/ioctl.h> 88 1.1 fredette #include <sys/mman.h> 89 1.1 fredette #include <sys/tty.h> 90 1.1 fredette #include <sys/conf.h> 91 1.1 fredette 92 1.1 fredette #include <machine/autoconf.h> 93 1.1 fredette #include <sun2/sun2/control.h> 94 1.1 fredette 95 1.1 fredette #include <dev/sun/fbio.h> 96 1.1 fredette #include <dev/sun/fbvar.h> 97 1.1 fredette #include <dev/sun/btreg.h> 98 1.1 fredette #include <sun2/dev/bwtworeg.h> 99 1.1 fredette #include <dev/sun/bwtwovar.h> 100 1.1 fredette 101 1.1 fredette /* autoconfiguration driver */ 102 1.17 tsutsui static int bwtwomatch_any(device_t, cfdata_t, void *); 103 1.17 tsutsui static void bwtwoattach_any(device_t, device_t, void *); 104 1.1 fredette 105 1.1 fredette struct bwtwosun2_softc { 106 1.1 fredette struct bwtwo_softc sc; 107 1.1 fredette bus_space_handle_t bh; 108 1.1 fredette }; 109 1.1 fredette 110 1.17 tsutsui CFATTACH_DECL_NEW(bwtwo_obio, sizeof(struct bwtwosun2_softc), 111 1.8 thorpej bwtwomatch_any, bwtwoattach_any, NULL, NULL); 112 1.1 fredette 113 1.17 tsutsui CFATTACH_DECL_NEW(bwtwo_obmem, sizeof(struct bwtwosun2_softc), 114 1.8 thorpej bwtwomatch_any, bwtwoattach_any, NULL, NULL); 115 1.1 fredette 116 1.12 chs static int bwtwo_get_video_sun2(struct bwtwo_softc *); 117 1.12 chs static void bwtwo_set_video_sun2(struct bwtwo_softc *, int); 118 1.1 fredette 119 1.1 fredette extern int fbnode; 120 1.1 fredette 121 1.12 chs static int 122 1.17 tsutsui bwtwomatch_any(device_t parent, cfdata_t cf, void *aux) 123 1.1 fredette { 124 1.3 fredette struct mainbus_attach_args *ma = aux; 125 1.3 fredette bus_space_handle_t bh; 126 1.3 fredette int matched; 127 1.1 fredette 128 1.3 fredette /* Make sure there is something there... */ 129 1.12 chs if (bus_space_map(ma->ma_bustag, ma->ma_paddr + BWREG_REG, 130 1.12 chs sizeof(struct bwtworeg), 0, &bh)) 131 1.3 fredette return (0); 132 1.3 fredette matched = (bus_space_peek_1(ma->ma_bustag, bh, 0, NULL) == 0); 133 1.3 fredette bus_space_unmap(ma->ma_bustag, bh, sizeof(struct bwtworeg)); 134 1.3 fredette return (matched); 135 1.1 fredette } 136 1.1 fredette 137 1.12 chs static void 138 1.17 tsutsui bwtwoattach_any(device_t parent, device_t self, void *aux) 139 1.1 fredette { 140 1.17 tsutsui struct bwtwosun2_softc *scsun2 = device_private(self); 141 1.1 fredette struct bwtwo_softc *sc = &scsun2->sc; 142 1.3 fredette struct mainbus_attach_args *ma = aux; 143 1.1 fredette struct fbdevice *fb = &sc->sc_fb; 144 1.1 fredette bus_space_handle_t bh; 145 1.1 fredette int isconsole; 146 1.13 tsutsui const char *name; 147 1.1 fredette 148 1.17 tsutsui sc->sc_dev = self; 149 1.17 tsutsui 150 1.1 fredette /* Remember cookies for bwtwo_mmap() */ 151 1.3 fredette sc->sc_bustag = ma->ma_bustag; 152 1.3 fredette sc->sc_paddr = ma->ma_paddr; 153 1.1 fredette 154 1.17 tsutsui fb->fb_flags = device_cfdata(self)->cf_flags; 155 1.1 fredette fb->fb_type.fb_depth = 1; 156 1.2 fredette fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900); 157 1.1 fredette 158 1.1 fredette isconsole = fb_is_console(0); 159 1.1 fredette 160 1.1 fredette /* A plain bwtwo */ 161 1.1 fredette sc->sc_reg = NULL; 162 1.1 fredette fb->fb_pfour = NULL; 163 1.1 fredette name = "bwtwo"; 164 1.1 fredette sc->sc_pixeloffset = BWREG_MEM; 165 1.1 fredette sc->sc_get_video = bwtwo_get_video_sun2; 166 1.1 fredette sc->sc_set_video = bwtwo_set_video_sun2; 167 1.1 fredette 168 1.1 fredette /* Map the registers. */ 169 1.12 chs if (bus_space_map(ma->ma_bustag, ma->ma_paddr + BWREG_REG, 170 1.12 chs sizeof(struct bwtworeg), 0, &scsun2->bh)) { 171 1.17 tsutsui printf("%s: cannot map regs\n", device_xname(self)); 172 1.1 fredette return; 173 1.1 fredette } 174 1.1 fredette 175 1.1 fredette if (isconsole) { 176 1.1 fredette int ramsize = fb->fb_type.fb_height * fb->fb_linebytes; 177 1.12 chs if (bus_space_map(ma->ma_bustag, 178 1.12 chs ma->ma_paddr + sc->sc_pixeloffset, 179 1.1 fredette ramsize, 180 1.1 fredette BUS_SPACE_MAP_LINEAR, &bh) != 0) { 181 1.17 tsutsui printf("%s: cannot map pixels\n", device_xname(self)); 182 1.1 fredette return; 183 1.1 fredette } 184 1.1 fredette sc->sc_fb.fb_pixels = (char *)bh; 185 1.1 fredette } 186 1.1 fredette 187 1.1 fredette bwtwoattach(sc, name, isconsole); 188 1.1 fredette } 189 1.1 fredette 190 1.12 chs static void 191 1.12 chs bwtwo_set_video_sun2(struct bwtwo_softc *sc, int enable) 192 1.1 fredette { 193 1.1 fredette struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)sc; 194 1.1 fredette unsigned char cr; 195 1.1 fredette 196 1.1 fredette cr = bus_space_read_1(sc->sc_bustag, scsun2->bh, 0); 197 1.12 chs bus_space_write_1(sc->sc_bustag, scsun2->bh, 0, 198 1.12 chs (enable ? 199 1.12 chs (cr | BW2_CR_ENABLE_VIDEO) : 200 1.12 chs (cr & ~BW2_CR_ENABLE_VIDEO))); 201 1.1 fredette return; 202 1.1 fredette } 203 1.1 fredette 204 1.12 chs static int 205 1.12 chs bwtwo_get_video_sun2(struct bwtwo_softc *sc) 206 1.1 fredette { 207 1.1 fredette struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)sc; 208 1.1 fredette 209 1.12 chs return ((bus_space_read_1(sc->sc_bustag, scsun2->bh, 0) & 210 1.12 chs BW2_CR_ENABLE_VIDEO) != 0); 211 1.1 fredette } 212