1 /* $NetBSD: cgsix_obio.c,v 1.14 2003/07/15 00:04:53 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; sun4 obio bus front-end. 41 */ 42 43 #include <sys/cdefs.h> 44 __KERNEL_RCSID(0, "$NetBSD: cgsix_obio.c,v 1.14 2003/07/15 00:04:53 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 #include <machine/eeprom.h> 64 65 #include <dev/sun/fbio.h> 66 #include <dev/sun/fbvar.h> 67 #include <dev/sun/btreg.h> 68 #include <dev/sun/btvar.h> 69 #include <dev/sun/cgsixreg.h> 70 #include <dev/sun/cgsixvar.h> 71 #include <dev/sun/pfourreg.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 static int cg6_pfour_probe __P((void *, void *)); 77 78 CFATTACH_DECL(cgsix_obio, sizeof(struct cgsix_softc), 79 cgsixmatch, cgsixattach, NULL, NULL); 80 81 /* 82 * Match a cgsix. 83 */ 84 static int 85 cgsixmatch(parent, cf, aux) 86 struct device *parent; 87 struct cfdata *cf; 88 void *aux; 89 { 90 union obio_attach_args *uoba = aux; 91 struct obio4_attach_args *oba; 92 93 if (uoba->uoba_isobio4 == 0) 94 return (0); 95 96 oba = &uoba->uoba_oba4; 97 return (bus_space_probe(oba->oba_bustag, 98 oba->oba_paddr + CGSIX_FHC_OFFSET, 99 4, /* probe size */ 100 0, /* offset */ 101 0, /* flags */ 102 cg6_pfour_probe, NULL)); 103 } 104 105 static int 106 cg6_pfour_probe(vaddr, arg) 107 void *vaddr; 108 void *arg; 109 { 110 111 return (fb_pfour_id(vaddr) == PFOUR_ID_FASTCOLOR); 112 } 113 114 115 /* 116 * Attach a display. 117 */ 118 static void 119 cgsixattach(parent, self, aux) 120 struct device *parent, *self; 121 void *aux; 122 { 123 struct cgsix_softc *sc = (struct cgsix_softc *)self; 124 union obio_attach_args *uoba = aux; 125 struct obio4_attach_args *oba; 126 struct eeprom *eep = (struct eeprom *)eeprom_va; 127 struct fbdevice *fb = &sc->sc_fb; 128 bus_space_handle_t bh; 129 int constype, isconsole; 130 char *name; 131 132 oba = &uoba->uoba_oba4; 133 134 /* Remember cookies for cgsix_mmap() */ 135 sc->sc_bustag = oba->oba_bustag; 136 sc->sc_paddr = (bus_addr_t)oba->oba_paddr; 137 138 fb->fb_device = &sc->sc_dev; 139 fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR; 140 fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK; 141 fb->fb_type.fb_depth = 8; 142 143 fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900); 144 145 /* 146 * Dunno what the PROM has mapped, though obviously it must have 147 * the video RAM mapped. Just map what we care about for ourselves 148 * (the FHC, THC, and Brooktree registers). 149 */ 150 if (bus_space_map(oba->oba_bustag, 151 oba->oba_paddr + CGSIX_BT_OFFSET, 152 sizeof(*sc->sc_bt), 153 BUS_SPACE_MAP_LINEAR, 154 &bh) != 0) { 155 printf("%s: cannot map brooktree registers\n", self->dv_xname); 156 return; 157 } 158 sc->sc_bt = (struct bt_regs *)bh; 159 160 if (bus_space_map(oba->oba_bustag, 161 oba->oba_paddr + CGSIX_FHC_OFFSET, 162 sizeof(*sc->sc_fhc), 163 BUS_SPACE_MAP_LINEAR, 164 &bh) != 0) { 165 printf("%s: cannot map FHC registers\n", self->dv_xname); 166 return; 167 } 168 sc->sc_fhc = (int *)bh; 169 170 if (bus_space_map(oba->oba_bustag, 171 oba->oba_paddr + CGSIX_THC_OFFSET, 172 sizeof(*sc->sc_thc), 173 BUS_SPACE_MAP_LINEAR, 174 &bh) != 0) { 175 printf("%s: cannot map THC registers\n", self->dv_xname); 176 return; 177 } 178 sc->sc_thc = (struct cg6_thc *)bh; 179 180 if (bus_space_map(oba->oba_bustag, 181 oba->oba_paddr + CGSIX_TEC_OFFSET, 182 sizeof(*sc->sc_tec), 183 BUS_SPACE_MAP_LINEAR, 184 &bh) != 0) { 185 printf("%s: cannot map TEC registers\n", self->dv_xname); 186 return; 187 } 188 sc->sc_tec = (struct cg6_tec_xxx *)bh; 189 190 if (bus_space_map(oba->oba_bustag, 191 oba->oba_paddr + CGSIX_FBC_OFFSET, 192 sizeof(*sc->sc_fbc), 193 BUS_SPACE_MAP_LINEAR, 194 &bh) != 0) { 195 printf("%s: cannot map FBC registers\n", self->dv_xname); 196 return; 197 } 198 sc->sc_fbc = (struct cg6_fbc *)bh; 199 200 201 if (fb_pfour_id((void *)sc->sc_fhc) == PFOUR_ID_FASTCOLOR) { 202 fb->fb_flags |= FB_PFOUR; 203 name = "cgsix/p4"; 204 } else 205 name = "cgsix"; 206 207 constype = (fb->fb_flags & FB_PFOUR) ? EE_CONS_P4OPT : EE_CONS_COLOR; 208 209 /* 210 * Assume this is the console if there's no eeprom info 211 * to be found. 212 */ 213 if (eep == NULL || eep->eeConsole == constype) 214 isconsole = fb_is_console(0); 215 else 216 isconsole = 0; 217 218 if (isconsole && cgsix_use_rasterconsole) { 219 int ramsize = fb->fb_type.fb_height * fb->fb_linebytes; 220 if (bus_space_map(oba->oba_bustag, 221 oba->oba_paddr + CGSIX_RAM_OFFSET, 222 ramsize, 223 BUS_SPACE_MAP_LINEAR, 224 &bh) != 0) { 225 printf("%s: cannot map pixels\n", self->dv_xname); 226 return; 227 } 228 sc->sc_fb.fb_pixels = (caddr_t)bh; 229 } 230 231 cg6attach(sc, name, isconsole); 232 } 233