1 /* $NetBSD: cgsix_obio.c,v 1.23 2008/12/12 18:50:13 macallan 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; sun4 obio bus front-end. 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: cgsix_obio.c,v 1.23 2008/12/12 18:50:13 macallan 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/malloc.h> 45 #include <sys/mman.h> 46 #include <sys/tty.h> 47 #include <sys/conf.h> 48 49 #ifdef DEBUG 50 #include <sys/proc.h> 51 #include <sys/syslog.h> 52 #endif 53 54 #include <machine/bus.h> 55 #include <machine/autoconf.h> 56 #include <machine/eeprom.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 #include <dev/sun/pfourreg.h> 65 66 /* autoconfiguration driver */ 67 static int cgsixmatch(device_t, struct cfdata *, void *); 68 static void cgsixattach(device_t, device_t, void *); 69 static int cg6_pfour_probe(void *, void *); 70 71 CFATTACH_DECL(cgsix_obio, sizeof(struct cgsix_softc), 72 cgsixmatch, cgsixattach, NULL, NULL); 73 74 /* 75 * Match a cgsix. 76 */ 77 static int 78 cgsixmatch(device_t parent, struct cfdata *cf, void *aux) 79 { 80 union obio_attach_args *uoba = aux; 81 struct obio4_attach_args *oba; 82 83 if (uoba->uoba_isobio4 == 0) 84 return (0); 85 86 oba = &uoba->uoba_oba4; 87 return (bus_space_probe(oba->oba_bustag, 88 oba->oba_paddr + CGSIX_FHC_OFFSET, 89 4, /* probe size */ 90 0, /* offset */ 91 0, /* flags */ 92 cg6_pfour_probe, NULL)); 93 } 94 95 static int 96 cg6_pfour_probe(void *vaddr, void *arg) 97 { 98 99 return (fb_pfour_id(vaddr) == PFOUR_ID_FASTCOLOR); 100 } 101 102 103 /* 104 * Attach a display. 105 */ 106 static void 107 cgsixattach(device_t parent, device_t self, void *aux) 108 { 109 struct cgsix_softc *sc = device_private(self); 110 union obio_attach_args *uoba = aux; 111 struct obio4_attach_args *oba; 112 struct eeprom *eep = (struct eeprom *)eeprom_va; 113 struct fbdevice *fb = &sc->sc_fb; 114 bus_space_handle_t bh; 115 int constype, isconsole; 116 const char *name; 117 118 sc->sc_dev = self; 119 oba = &uoba->uoba_oba4; 120 121 /* Remember cookies for cgsix_mmap() */ 122 sc->sc_bustag = oba->oba_bustag; 123 sc->sc_paddr = (bus_addr_t)oba->oba_paddr; 124 125 fb->fb_device = sc->sc_dev; 126 fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR; 127 fb->fb_flags = device_cfdata(sc->sc_dev)->cf_flags & FB_USERMASK; 128 fb->fb_type.fb_depth = 8; 129 130 fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900); 131 132 sc->sc_ramsize = 1024 * 1024; /* All our cgsix's are 1MB */ 133 134 /* 135 * Dunno what the PROM has mapped, though obviously it must have 136 * the video RAM mapped. Just map what we care about for ourselves 137 * (the FHC, THC, and Brooktree registers). 138 */ 139 if (bus_space_map(oba->oba_bustag, 140 oba->oba_paddr + CGSIX_BT_OFFSET, 141 sizeof(*sc->sc_bt), 142 BUS_SPACE_MAP_LINEAR, 143 &bh) != 0) { 144 printf("%s: cannot map brooktree registers\n", self->dv_xname); 145 return; 146 } 147 sc->sc_bt = (struct bt_regs *)bh; 148 149 if (bus_space_map(oba->oba_bustag, 150 oba->oba_paddr + CGSIX_FHC_OFFSET, 151 sizeof(*sc->sc_fhc), 152 BUS_SPACE_MAP_LINEAR, 153 &bh) != 0) { 154 printf("%s: cannot map FHC registers\n", self->dv_xname); 155 return; 156 } 157 sc->sc_fhc = (int *)bh; 158 159 if (bus_space_map(oba->oba_bustag, 160 oba->oba_paddr + CGSIX_THC_OFFSET, 161 sizeof(*sc->sc_thc), 162 BUS_SPACE_MAP_LINEAR, 163 &bh) != 0) { 164 printf("%s: cannot map THC registers\n", self->dv_xname); 165 return; 166 } 167 sc->sc_thc = (struct cg6_thc *)bh; 168 169 if (bus_space_map(oba->oba_bustag, 170 oba->oba_paddr + CGSIX_TEC_OFFSET, 171 sizeof(*sc->sc_tec), 172 BUS_SPACE_MAP_LINEAR, 173 &bh) != 0) { 174 printf("%s: cannot map TEC registers\n", self->dv_xname); 175 return; 176 } 177 sc->sc_tec = (struct cg6_tec_xxx *)bh; 178 179 if (bus_space_map(oba->oba_bustag, 180 oba->oba_paddr + CGSIX_FBC_OFFSET, 181 sizeof(*sc->sc_fbc), 182 BUS_SPACE_MAP_LINEAR, 183 &bh) != 0) { 184 printf("%s: cannot map FBC registers\n", self->dv_xname); 185 return; 186 } 187 sc->sc_fbc = (struct cg6_fbc *)bh; 188 189 190 if (fb_pfour_id(sc->sc_fhc) == PFOUR_ID_FASTCOLOR) { 191 fb->fb_flags |= FB_PFOUR; 192 name = "cgsix/p4"; 193 } else 194 name = "cgsix"; 195 196 constype = (fb->fb_flags & FB_PFOUR) ? EE_CONS_P4OPT : EE_CONS_COLOR; 197 198 /* 199 * Check to see if this is the console if there's no eeprom info 200 * to be found, or if it's the correct framebuffer type. 201 */ 202 if (eep == NULL || eep->eeConsole == constype) 203 isconsole = fb_is_console(0); 204 else 205 isconsole = 0; 206 207 if (isconsole && cgsix_use_rasterconsole) { 208 if (bus_space_map(oba->oba_bustag, 209 oba->oba_paddr + CGSIX_RAM_OFFSET, 210 sc->sc_ramsize, 211 BUS_SPACE_MAP_LINEAR, 212 &bh) != 0) { 213 printf("%s: cannot map pixels\n", self->dv_xname); 214 return; 215 } 216 sc->sc_fb.fb_pixels = (void *)bh; 217 } 218 219 cg6attach(sc, name, isconsole); 220 } 221