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