1 /* $NetBSD: cgsix_sbus.c,v 1.32 2022/09/25 18:03:04 thorpej Exp $ */ 2 3 /*- 4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Paul Kranenburg. 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 * color display (cgsix) driver; Sbus bus front-end. 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: cgsix_sbus.c,v 1.32 2022/09/25 18:03:04 thorpej Exp $"); 38 39 #include <sys/param.h> 40 #include <sys/systm.h> 41 #include <sys/buf.h> 42 #include <sys/device.h> 43 #include <sys/ioctl.h> 44 #include <sys/mman.h> 45 #include <sys/tty.h> 46 #include <sys/conf.h> 47 48 #ifdef DEBUG 49 #include <sys/proc.h> 50 #include <sys/syslog.h> 51 #endif 52 53 #include <sys/bus.h> 54 #include <machine/autoconf.h> 55 56 #include <dev/sbus/sbusvar.h> 57 58 #include <dev/sun/fbio.h> 59 #include <dev/sun/fbvar.h> 60 #include <dev/sun/btreg.h> 61 #include <dev/sun/btvar.h> 62 #include <dev/sun/cgsixreg.h> 63 #include <dev/sun/cgsixvar.h> 64 65 /* autoconfiguration driver */ 66 static int cgsixmatch(device_t, cfdata_t, void *); 67 static void cgsixattach(device_t, device_t, void *); 68 69 CFATTACH_DECL_NEW(cgsix_sbus, sizeof(struct cgsix_softc), 70 cgsixmatch, cgsixattach, NULL, NULL); 71 72 /* 73 * Match a cgsix. 74 */ 75 int 76 cgsixmatch(device_t parent, cfdata_t cf, void *aux) 77 { 78 struct sbus_attach_args *sa = aux; 79 80 return (strcmp(cf->cf_name, sa->sa_name) == 0) ? 100 : 0; 81 } 82 83 84 /* 85 * Attach a cgsix. 86 */ 87 void 88 cgsixattach(device_t parent, device_t self, void *aux) 89 { 90 struct cgsix_softc *sc = device_private(self); 91 struct sbus_attach_args *sa = aux; 92 struct fbdevice *fb = &sc->sc_fb; 93 int node, isconsole; 94 const char *name; 95 bus_space_handle_t bh; 96 97 /* Remember cookies for cgsix_mmap() */ 98 sc->sc_bustag = sa->sa_bustag; 99 sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset); 100 sc->sc_dev = self; 101 102 node = sa->sa_node; 103 104 fb->fb_device = sc->sc_dev; 105 fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR; 106 fb->fb_flags = device_cfdata(sc->sc_dev)->cf_flags & FB_USERMASK; 107 fb->fb_type.fb_depth = 8; 108 109 fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node); 110 111 /* 112 * Dunno what the PROM has mapped, though obviously it must have 113 * the video RAM mapped. Just map what we care about for ourselves 114 * (the FHC, THC, and Brooktree registers). 115 */ 116 if (sbus_bus_map(sa->sa_bustag, 117 sa->sa_slot, 118 sa->sa_offset + CGSIX_BT_OFFSET, 119 sizeof(*sc->sc_bt), 120 BUS_SPACE_MAP_LINEAR, &bh) != 0) { 121 aprint_error_dev(self, "cannot map brooktree registers\n"); 122 return; 123 } 124 sc->sc_bt = (struct bt_regs *)bus_space_vaddr(sa->sa_bustag, bh); 125 126 if (sbus_bus_map(sa->sa_bustag, 127 sa->sa_slot, 128 sa->sa_offset + CGSIX_FHC_OFFSET, 129 sizeof(*sc->sc_fhc), 130 BUS_SPACE_MAP_LINEAR, &bh) != 0) { 131 aprint_error_dev(self, "cannot map FHC registers\n"); 132 return; 133 } 134 sc->sc_fhc = (int *)bus_space_vaddr(sa->sa_bustag, bh); 135 136 if (sbus_bus_map(sa->sa_bustag, 137 sa->sa_slot, 138 sa->sa_offset + CGSIX_THC_OFFSET, 139 sizeof(*sc->sc_thc), 140 BUS_SPACE_MAP_LINEAR, &bh) != 0) { 141 aprint_error_dev(self, "cannot map THC registers\n"); 142 return; 143 } 144 sc->sc_thc = (struct cg6_thc *)bus_space_vaddr(sa->sa_bustag, bh); 145 146 if (sbus_bus_map(sa->sa_bustag, 147 sa->sa_slot, 148 sa->sa_offset + CGSIX_TEC_OFFSET, 149 sizeof(*sc->sc_tec), 150 BUS_SPACE_MAP_LINEAR, &bh) != 0) { 151 aprint_error_dev(self, "cannot map TEC registers\n"); 152 return; 153 } 154 sc->sc_tec = (struct cg6_tec_xxx *)bus_space_vaddr(sa->sa_bustag, bh); 155 156 if (sbus_bus_map(sa->sa_bustag, 157 sa->sa_slot, 158 sa->sa_offset + CGSIX_FBC_OFFSET, 159 sizeof(*sc->sc_fbc), 160 BUS_SPACE_MAP_LINEAR, &bh) != 0) { 161 aprint_error_dev(self, "cannot map FBC registers\n"); 162 return; 163 } 164 sc->sc_fbc = (struct cg6_fbc *)bus_space_vaddr(sa->sa_bustag, bh); 165 166 name = prom_getpropstring(node, "model"); 167 168 isconsole = fb_is_console(node); 169 170 /* 171 * we need the address of the framebuffer, no matter if we're console or 172 * not. 173 */ 174 sc->sc_ramsize = prom_getpropint(node, "vmsize", 1) * 1024 * 1024; 175 if (sbus_bus_map(sa->sa_bustag, 176 sa->sa_slot, 177 sa->sa_offset + CGSIX_RAM_OFFSET, 178 sc->sc_ramsize, 179 BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE, 180 &bh) != 0) { 181 aprint_error_dev(self, "cannot map pixels\n"); 182 return; 183 } 184 sc->sc_fb.fb_pixels = (void *)bus_space_vaddr(sa->sa_bustag, bh); 185 186 cg6attach(sc, name, isconsole); 187 } 188