1 /* $NetBSD: cgsix_sbus.c,v 1.6 2001/11/13 06:58:17 lukem 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 * 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 * color display (cgsix) driver; Sbus bus front-end. 41 */ 42 43 #include <sys/cdefs.h> 44 __KERNEL_RCSID(0, "$NetBSD: cgsix_sbus.c,v 1.6 2001/11/13 06:58:17 lukem Exp $"); 45 46 #include <sys/param.h> 47 #include <sys/systm.h> 48 #include <sys/buf.h> 49 #include <sys/device.h> 50 #include <sys/ioctl.h> 51 #include <sys/malloc.h> 52 #include <sys/mman.h> 53 #include <sys/tty.h> 54 #include <sys/conf.h> 55 56 #ifdef DEBUG 57 #include <sys/proc.h> 58 #include <sys/syslog.h> 59 #endif 60 61 #include <machine/bus.h> 62 #include <machine/autoconf.h> 63 64 #include <dev/sbus/sbusvar.h> 65 66 #include <dev/sun/fbio.h> 67 #include <dev/sun/fbvar.h> 68 #include <dev/sun/btreg.h> 69 #include <dev/sun/btvar.h> 70 #include <dev/sun/cgsixreg.h> 71 #include <dev/sun/cgsixvar.h> 72 73 /* autoconfiguration driver */ 74 static int cgsixmatch __P((struct device *, struct cfdata *, void *)); 75 static void cgsixattach __P((struct device *, struct device *, void *)); 76 77 /* Allocate an `sbusdev' in addition to the cgsix softc */ 78 struct cgsix_sbus_softc { 79 struct cgsix_softc bss_softc; 80 struct sbusdev bss_sd; 81 }; 82 83 struct cfattach cgsix_sbus_ca = { 84 sizeof(struct cgsix_sbus_softc), cgsixmatch, cgsixattach 85 }; 86 87 88 /* 89 * Match a cgsix. 90 */ 91 int 92 cgsixmatch(parent, cf, aux) 93 struct device *parent; 94 struct cfdata *cf; 95 void *aux; 96 { 97 struct sbus_attach_args *sa = aux; 98 99 return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0); 100 } 101 102 103 /* 104 * Attach a cgsix. 105 */ 106 void 107 cgsixattach(parent, self, aux) 108 struct device *parent, *self; 109 void *aux; 110 { 111 struct cgsix_softc *sc = (struct cgsix_softc *)self; 112 struct sbusdev *sd = &((struct cgsix_sbus_softc *)self)->bss_sd; 113 struct sbus_attach_args *sa = aux; 114 struct fbdevice *fb = &sc->sc_fb; 115 int node, isconsole; 116 char *name; 117 bus_space_handle_t bh; 118 119 /* Remember cookies for cgsix_mmap() */ 120 sc->sc_bustag = sa->sa_bustag; 121 sc->sc_btype = (bus_type_t)sa->sa_slot; /* Should be deprecated */ 122 sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset); 123 124 node = sa->sa_node; 125 126 fb->fb_device = &sc->sc_dev; 127 fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR; 128 fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK; 129 fb->fb_type.fb_depth = 8; 130 131 fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node); 132 133 /* 134 * Dunno what the PROM has mapped, though obviously it must have 135 * the video RAM mapped. Just map what we care about for ourselves 136 * (the FHC, THC, and Brooktree registers). 137 */ 138 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, 139 sa->sa_offset + CGSIX_BT_OFFSET, 140 sizeof(*sc->sc_bt), 141 BUS_SPACE_MAP_LINEAR, 142 0, &bh) != 0) { 143 printf("%s: cannot map brooktree registers\n", self->dv_xname); 144 return; 145 } 146 sc->sc_bt = (struct bt_regs *)(u_long)bh; 147 148 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, 149 sa->sa_offset + CGSIX_FHC_OFFSET, 150 sizeof(*sc->sc_fhc), 151 BUS_SPACE_MAP_LINEAR, 152 0, &bh) != 0) { 153 printf("%s: cannot map FHC registers\n", self->dv_xname); 154 return; 155 } 156 sc->sc_fhc = (int *)(u_long)bh; 157 158 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, 159 sa->sa_offset + CGSIX_THC_OFFSET, 160 sizeof(*sc->sc_thc), 161 BUS_SPACE_MAP_LINEAR, 162 0, &bh) != 0) { 163 printf("%s: cannot map THC registers\n", self->dv_xname); 164 return; 165 } 166 sc->sc_thc = (struct cg6_thc *)(u_long)bh; 167 168 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, 169 sa->sa_offset + CGSIX_TEC_OFFSET, 170 sizeof(*sc->sc_tec), 171 BUS_SPACE_MAP_LINEAR, 172 0, &bh) != 0) { 173 printf("%s: cannot map TEC registers\n", self->dv_xname); 174 return; 175 } 176 sc->sc_tec = (struct cg6_tec_xxx *)(u_long)bh; 177 178 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, 179 sa->sa_offset + CGSIX_FBC_OFFSET, 180 sizeof(*sc->sc_fbc), 181 BUS_SPACE_MAP_LINEAR, 182 0, &bh) != 0) { 183 printf("%s: cannot map FBC registers\n", self->dv_xname); 184 return; 185 } 186 sc->sc_fbc = (struct cg6_fbc *)(u_long)bh; 187 188 sbus_establish(sd, &sc->sc_dev); 189 name = PROM_getpropstring(node, "model"); 190 191 isconsole = fb_is_console(node); 192 if (isconsole && cgsix_use_rasterconsole) { 193 int ramsize = fb->fb_type.fb_height * fb->fb_linebytes; 194 if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, 195 sa->sa_offset + CGSIX_RAM_OFFSET, 196 ramsize, 197 BUS_SPACE_MAP_LINEAR, 198 0, &bh) != 0) { 199 printf("%s: cannot map pixels\n", self->dv_xname); 200 return; 201 } 202 sc->sc_fb.fb_pixels = (caddr_t)(u_long)bh; 203 } 204 205 cg6attach(sc, name, isconsole); 206 } 207