1 1.8 thorpej /* $NetBSD: cgtwelve.c,v 1.8 2021/08/07 16:19:15 thorpej Exp $ */ 2 1.1 macallan 3 1.1 macallan /*- 4 1.1 macallan * Copyright (c) 2010 Michael Lorenz 5 1.1 macallan * All rights reserved. 6 1.1 macallan * 7 1.1 macallan * Redistribution and use in source and binary forms, with or without 8 1.1 macallan * modification, are permitted provided that the following conditions 9 1.1 macallan * are met: 10 1.1 macallan * 1. Redistributions of source code must retain the above copyright 11 1.1 macallan * notice, this list of conditions and the following disclaimer. 12 1.1 macallan * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 macallan * notice, this list of conditions and the following disclaimer in the 14 1.1 macallan * documentation and/or other materials provided with the distribution. 15 1.1 macallan * 16 1.1 macallan * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 1.1 macallan * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 1.1 macallan * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 1.1 macallan * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 1.1 macallan * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 1.1 macallan * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 1.1 macallan * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 1.1 macallan * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 1.1 macallan * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 1.1 macallan * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 1.1 macallan * POSSIBILITY OF SUCH DAMAGE. 27 1.1 macallan */ 28 1.1 macallan 29 1.1 macallan /* a console driver for the Sun CG12 / Matrox SG3 graphics board */ 30 1.1 macallan 31 1.1 macallan #include <sys/cdefs.h> 32 1.8 thorpej __KERNEL_RCSID(0, "$NetBSD: cgtwelve.c,v 1.8 2021/08/07 16:19:15 thorpej Exp $"); 33 1.1 macallan 34 1.1 macallan #include <sys/param.h> 35 1.1 macallan #include <sys/systm.h> 36 1.1 macallan #include <sys/buf.h> 37 1.1 macallan #include <sys/device.h> 38 1.1 macallan #include <sys/ioctl.h> 39 1.1 macallan #include <sys/conf.h> 40 1.2 macallan #include <sys/kmem.h> 41 1.1 macallan 42 1.1 macallan #include <sys/bus.h> 43 1.1 macallan #include <machine/autoconf.h> 44 1.1 macallan 45 1.1 macallan #include <dev/sbus/sbusvar.h> 46 1.1 macallan #include <dev/sun/fbio.h> 47 1.1 macallan #include <dev/sun/fbvar.h> 48 1.1 macallan 49 1.1 macallan #include <dev/wscons/wsdisplayvar.h> 50 1.1 macallan #include <dev/wscons/wsconsio.h> 51 1.1 macallan #include <dev/wsfont/wsfont.h> 52 1.1 macallan #include <dev/rasops/rasops.h> 53 1.1 macallan 54 1.1 macallan #include <dev/wscons/wsdisplay_vconsvar.h> 55 1.1 macallan 56 1.1 macallan #include <dev/sbus/cgtwelvereg.h> 57 1.4 macallan #include <dev/ic/bt462reg.h> 58 1.1 macallan 59 1.1 macallan #include "opt_wsemul.h" 60 1.1 macallan #include "opt_cgtwelve.h" 61 1.1 macallan 62 1.1 macallan 63 1.1 macallan struct cgtwelve_softc { 64 1.1 macallan device_t sc_dev; 65 1.1 macallan bus_space_tag_t sc_tag; 66 1.3 macallan bus_space_handle_t sc_regh; 67 1.3 macallan bus_addr_t sc_paddr; 68 1.1 macallan void *sc_fbaddr; 69 1.2 macallan void *sc_shadow; 70 1.3 macallan uint8_t *sc_wids; 71 1.3 macallan void *sc_int; 72 1.1 macallan int sc_width; 73 1.1 macallan int sc_height; 74 1.1 macallan int sc_stride; 75 1.1 macallan int sc_fbsize; 76 1.1 macallan int sc_mode; 77 1.1 macallan struct vcons_data vd; 78 1.1 macallan }; 79 1.1 macallan 80 1.1 macallan static int cgtwelve_match(device_t, cfdata_t, void *); 81 1.1 macallan static void cgtwelve_attach(device_t, device_t, void *); 82 1.1 macallan static int cgtwelve_ioctl(void *, void *, u_long, void *, int, 83 1.1 macallan struct lwp*); 84 1.1 macallan static paddr_t cgtwelve_mmap(void *, void *, off_t, int); 85 1.1 macallan static void cgtwelve_init_screen(void *, struct vcons_screen *, int, 86 1.1 macallan long *); 87 1.3 macallan static void cgtwelve_write_wid(struct cgtwelve_softc *, int, uint8_t); 88 1.3 macallan static void cgtwelve_select_ovl(struct cgtwelve_softc *, int); 89 1.3 macallan #define CG12_SEL_OVL 0 90 1.3 macallan #define CG12_SEL_ENABLE 1 91 1.3 macallan #define CG12_SEL_8BIT 2 92 1.3 macallan #define CG12_SEL_24BIT 3 93 1.3 macallan #define CG12_SEL_WID 4 94 1.3 macallan static void cgtwelve_write_dac(struct cgtwelve_softc *, int, int, int, int); 95 1.3 macallan static void cgtwelve_setup(struct cgtwelve_softc *, int); 96 1.1 macallan 97 1.1 macallan CFATTACH_DECL_NEW(cgtwelve, sizeof(struct cgtwelve_softc), 98 1.1 macallan cgtwelve_match, cgtwelve_attach, NULL, NULL); 99 1.1 macallan 100 1.1 macallan struct wsscreen_descr cgtwelve_defscreendesc = { 101 1.1 macallan "default", 102 1.1 macallan 0, 0, 103 1.1 macallan NULL, 104 1.1 macallan 8, 16, 105 1.1 macallan 0, 106 1.1 macallan }; 107 1.1 macallan 108 1.1 macallan static struct vcons_screen cgtwelve_console_screen; 109 1.1 macallan 110 1.1 macallan const struct wsscreen_descr *_cgtwelve_scrlist[] = { 111 1.1 macallan &cgtwelve_defscreendesc, 112 1.1 macallan /* XXX other formats, graphics screen? */ 113 1.1 macallan }; 114 1.1 macallan 115 1.1 macallan struct wsscreen_list cgtwelve_screenlist = { 116 1.1 macallan sizeof(_cgtwelve_scrlist) / sizeof(struct wsscreen_descr *), 117 1.1 macallan _cgtwelve_scrlist 118 1.1 macallan }; 119 1.1 macallan 120 1.1 macallan struct wsdisplay_accessops cgtwelve_accessops = { 121 1.1 macallan cgtwelve_ioctl, 122 1.1 macallan cgtwelve_mmap, 123 1.1 macallan NULL, /* vcons_alloc_screen */ 124 1.1 macallan NULL, /* vcons_free_screen */ 125 1.1 macallan NULL, /* vcons_show_screen */ 126 1.1 macallan NULL, /* load_font */ 127 1.1 macallan NULL, /* polls */ 128 1.1 macallan NULL, /* scroll */ 129 1.1 macallan }; 130 1.1 macallan 131 1.4 macallan extern const u_char rasops_cmap[768]; 132 1.4 macallan 133 1.1 macallan static int 134 1.1 macallan cgtwelve_match(device_t parent, cfdata_t cf, void *aux) 135 1.1 macallan { 136 1.1 macallan struct sbus_attach_args *sa = aux; 137 1.1 macallan 138 1.1 macallan if (strcmp("cgtwelve", sa->sa_name) == 0) 139 1.1 macallan return 100; 140 1.1 macallan return 0; 141 1.1 macallan } 142 1.1 macallan 143 1.1 macallan /* 144 1.1 macallan * Attach a display. We need to notice if it is the console, too. 145 1.1 macallan */ 146 1.1 macallan static void 147 1.1 macallan cgtwelve_attach(device_t parent, device_t self, void *args) 148 1.1 macallan { 149 1.1 macallan struct cgtwelve_softc *sc = device_private(self); 150 1.1 macallan struct sbus_attach_args *sa = args; 151 1.1 macallan struct wsemuldisplaydev_attach_args aa; 152 1.1 macallan struct rasops_info *ri; 153 1.1 macallan unsigned long defattr; 154 1.1 macallan bus_space_handle_t bh; 155 1.1 macallan int node = sa->sa_node; 156 1.1 macallan int isconsole; 157 1.1 macallan 158 1.1 macallan aprint_normal("\n"); 159 1.1 macallan sc->sc_dev = self; 160 1.1 macallan sc->sc_tag = sa->sa_bustag; 161 1.1 macallan 162 1.3 macallan sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset); 163 1.3 macallan 164 1.1 macallan /* read geometry information from the device tree */ 165 1.1 macallan sc->sc_width = prom_getpropint(sa->sa_node, "width", 1152); 166 1.1 macallan sc->sc_height = prom_getpropint(sa->sa_node, "height", 900); 167 1.4 macallan #ifdef CG12_COLOR 168 1.4 macallan sc->sc_stride = sc->sc_width; 169 1.4 macallan #else 170 1.1 macallan sc->sc_stride = (sc->sc_width + 7) >> 3; 171 1.4 macallan #endif 172 1.4 macallan sc->sc_fbsize = sc->sc_height * sc->sc_stride; 173 1.1 macallan 174 1.1 macallan sc->sc_fbaddr = (void *)prom_getpropint(sa->sa_node, "address", 0); 175 1.1 macallan if (sc->sc_fbaddr == NULL) { 176 1.1 macallan if (sbus_bus_map(sa->sa_bustag, 177 1.1 macallan sa->sa_slot, 178 1.1 macallan sa->sa_offset + CG12_FB_MONO, 179 1.1 macallan sc->sc_fbsize, 180 1.1 macallan BUS_SPACE_MAP_LINEAR, &bh) != 0) { 181 1.1 macallan aprint_error_dev(self, "cannot map framebuffer\n"); 182 1.1 macallan return; 183 1.1 macallan } 184 1.1 macallan sc->sc_fbaddr = bus_space_vaddr(sa->sa_bustag, bh); 185 1.1 macallan } 186 1.1 macallan 187 1.1 macallan aprint_normal_dev(self, "%d x %d\n", sc->sc_width, sc->sc_height); 188 1.1 macallan 189 1.3 macallan if (sbus_bus_map(sa->sa_bustag, 190 1.3 macallan sa->sa_slot, 191 1.3 macallan sa->sa_offset + CG12_OFF_REGISTERS, 192 1.3 macallan 0xc0000, 0, &sc->sc_regh) != 0) { 193 1.3 macallan aprint_error("%s: couldn't map registers\n", 194 1.3 macallan device_xname(sc->sc_dev)); 195 1.3 macallan return; 196 1.3 macallan } 197 1.3 macallan 198 1.3 macallan if (sbus_bus_map(sa->sa_bustag, 199 1.3 macallan sa->sa_slot, 200 1.3 macallan sa->sa_offset + CG12_OFF_WID, 0x100000, 201 1.3 macallan BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE, 202 1.3 macallan &bh) != 0) { 203 1.3 macallan aprint_error("%s: couldn't map WID\n", 204 1.3 macallan device_xname(sc->sc_dev)); 205 1.3 macallan return; 206 1.3 macallan } 207 1.3 macallan sc->sc_wids = bus_space_vaddr(sa->sa_bustag, bh); 208 1.3 macallan 209 1.3 macallan if (sbus_bus_map(sa->sa_bustag, 210 1.3 macallan sa->sa_slot, 211 1.3 macallan sa->sa_offset + CG12_OFF_INTEN, 0x400000, 212 1.3 macallan BUS_SPACE_MAP_LINEAR | BUS_SPACE_MAP_LARGE, 213 1.3 macallan &bh) != 0) { 214 1.3 macallan aprint_error("%s: couldn't map colour fb\n", 215 1.3 macallan device_xname(sc->sc_dev)); 216 1.3 macallan return; 217 1.3 macallan } 218 1.3 macallan sc->sc_int = bus_space_vaddr(sa->sa_bustag, bh); 219 1.3 macallan 220 1.4 macallan #ifdef CG12_COLOR 221 1.4 macallan cgtwelve_setup(sc, 8); 222 1.4 macallan #else 223 1.3 macallan cgtwelve_setup(sc, 1); 224 1.4 macallan #endif 225 1.4 macallan #ifdef CG12_SHADOW 226 1.4 macallan sc->sc_shadow = kmem_alloc(sc->sc_fbsize, KM_SLEEP); 227 1.4 macallan #else 228 1.4 macallan sc->sc_shadow = NULL; 229 1.4 macallan #endif 230 1.3 macallan 231 1.1 macallan isconsole = fb_is_console(node); 232 1.1 macallan 233 1.1 macallan sc->sc_mode = WSDISPLAYIO_MODE_EMUL; 234 1.1 macallan wsfont_init(); 235 1.1 macallan 236 1.1 macallan vcons_init(&sc->vd, sc, &cgtwelve_defscreendesc, &cgtwelve_accessops); 237 1.1 macallan sc->vd.init_screen = cgtwelve_init_screen; 238 1.1 macallan 239 1.1 macallan vcons_init_screen(&sc->vd, &cgtwelve_console_screen, 1, &defattr); 240 1.1 macallan cgtwelve_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC; 241 1.1 macallan 242 1.1 macallan ri = &cgtwelve_console_screen.scr_ri; 243 1.1 macallan 244 1.1 macallan cgtwelve_defscreendesc.nrows = ri->ri_rows; 245 1.1 macallan cgtwelve_defscreendesc.ncols = ri->ri_cols; 246 1.1 macallan cgtwelve_defscreendesc.textops = &ri->ri_ops; 247 1.1 macallan cgtwelve_defscreendesc.capabilities = ri->ri_caps; 248 1.1 macallan 249 1.1 macallan if(isconsole) { 250 1.1 macallan wsdisplay_cnattach(&cgtwelve_defscreendesc, ri, 0, 0, defattr); 251 1.1 macallan vcons_replay_msgbuf(&cgtwelve_console_screen); 252 1.1 macallan } 253 1.1 macallan 254 1.1 macallan aa.console = isconsole; 255 1.1 macallan aa.scrdata = &cgtwelve_screenlist; 256 1.1 macallan aa.accessops = &cgtwelve_accessops; 257 1.1 macallan aa.accesscookie = &sc->vd; 258 1.1 macallan 259 1.8 thorpej config_found(self, &aa, wsemuldisplaydevprint, CFARGS_NONE); 260 1.4 macallan #ifdef CG12_DEBUG 261 1.3 macallan { 262 1.4 macallan int i; 263 1.4 macallan for (i = 0; i < 0x10; i++) { 264 1.4 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 265 1.4 macallan CG12DAC_ADDR0, (i << 16) | (i << 8) | i); 266 1.4 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 267 1.4 macallan CG12DAC_ADDR1, 0x010101); 268 1.4 macallan printf("%02x: %08x\n", i, bus_space_read_4(sc->sc_tag, 269 1.4 macallan sc->sc_regh, CG12DAC_CTRL)); 270 1.2 macallan } 271 1.2 macallan } 272 1.2 macallan #endif 273 1.1 macallan } 274 1.1 macallan 275 1.3 macallan /* 0 - overlay plane, 1 - enable plane, 2 - 8bit fb, 3 - 24bit fb, 4 - WIDs */ 276 1.3 macallan static void 277 1.3 macallan cgtwelve_select_ovl(struct cgtwelve_softc *sc, int which) 278 1.3 macallan { 279 1.3 macallan switch(which) { 280 1.3 macallan case 0: 281 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 282 1.3 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_OVERLAY); 283 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 284 1.3 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_OVERLAY); 285 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 286 1.3 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_OVERLAY); 287 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 288 1.3 macallan CG12APU_HPAGE, CG12_HPAGE_OVERLAY); 289 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 290 1.3 macallan CG12APU_HACCESS, CG12_HACCESS_OVERLAY); 291 1.3 macallan break; 292 1.3 macallan case 1: 293 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 294 1.3 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_ENABLE); 295 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 296 1.3 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_ENABLE); 297 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 298 1.3 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_ENABLE); 299 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 300 1.3 macallan CG12APU_HPAGE, CG12_HPAGE_ENABLE); 301 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 302 1.3 macallan CG12APU_HACCESS, CG12_HACCESS_ENABLE); 303 1.3 macallan break; 304 1.3 macallan case 2: 305 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 306 1.3 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_8BIT); 307 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 308 1.3 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_8BIT); 309 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 310 1.3 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_8BIT); 311 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 312 1.3 macallan CG12APU_HPAGE, CG12_HPAGE_8BIT); 313 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 314 1.3 macallan CG12APU_HACCESS, CG12_HACCESS_8BIT); 315 1.3 macallan break; 316 1.3 macallan case 3: 317 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 318 1.3 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_24BIT); 319 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 320 1.3 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_24BIT); 321 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 322 1.3 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_24BIT); 323 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 324 1.3 macallan CG12APU_HPAGE, CG12_HPAGE_24BIT); 325 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 326 1.3 macallan CG12APU_HACCESS, CG12_HACCESS_24BIT); 327 1.3 macallan break; 328 1.3 macallan case 4: 329 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 330 1.3 macallan CG12DPU_PLN_RDMSK_HOST, CG12_PLN_RD_WID); 331 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 332 1.3 macallan CG12DPU_PLN_WRMSK_HOST, CG12_PLN_WR_WID); 333 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 334 1.3 macallan CG12DPU_PLN_SL_HOST, CG12_PLN_SL_WID); 335 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 336 1.3 macallan CG12APU_HPAGE, CG12_HPAGE_WID); 337 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, 338 1.3 macallan CG12APU_HACCESS, CG12_HACCESS_WID); 339 1.3 macallan break; 340 1.3 macallan } 341 1.3 macallan } 342 1.3 macallan 343 1.3 macallan static void 344 1.3 macallan cgtwelve_write_wid(struct cgtwelve_softc *sc, int idx, uint8_t wid) 345 1.3 macallan { 346 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12_WSC_ADDR, idx << 16); 347 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12_WSC_DATA, 348 1.3 macallan ((uint32_t)wid) << 16); 349 1.3 macallan } 350 1.3 macallan 351 1.3 macallan static void 352 1.3 macallan cgtwelve_write_dac(struct cgtwelve_softc *sc, int idx, int r, int g, int b) 353 1.3 macallan { 354 1.3 macallan uint32_t lo = (idx & 0xff); 355 1.3 macallan uint32_t hi = (idx >> 8) & 0xff; 356 1.3 macallan 357 1.3 macallan lo |= lo << 8 | lo << 16; 358 1.3 macallan hi |= hi << 8 | hi << 16; 359 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12DAC_ADDR0, lo); 360 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12DAC_ADDR1, hi); 361 1.3 macallan bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12DAC_DATA, 362 1.3 macallan b << 16 | g << 8 | r); 363 1.3 macallan } 364 1.3 macallan 365 1.3 macallan static void 366 1.3 macallan cgtwelve_setup(struct cgtwelve_softc *sc, int depth) 367 1.3 macallan { 368 1.4 macallan int i, j; 369 1.3 macallan 370 1.3 macallan /* first let's put some stuff into the WID table */ 371 1.3 macallan cgtwelve_write_wid(sc, 0, CG12_WID_8_BIT); 372 1.3 macallan cgtwelve_write_wid(sc, 1, CG12_WID_24_BIT); 373 1.3 macallan 374 1.3 macallan /* a linear ramp for the gamma table */ 375 1.3 macallan for (i = 0; i < 256; i++) 376 1.4 macallan cgtwelve_write_dac(sc, i + 0x100, i, i, i); 377 1.4 macallan 378 1.4 macallan j = 0; 379 1.4 macallan /* rasops' ANSI colour map */ 380 1.4 macallan for (i = 0; i < 256; i++) { 381 1.4 macallan cgtwelve_write_dac(sc, i, 382 1.4 macallan rasops_cmap[j], 383 1.4 macallan rasops_cmap[j + 1], 384 1.4 macallan rasops_cmap[j + 2]); 385 1.4 macallan j += 3; 386 1.4 macallan } 387 1.3 macallan 388 1.3 macallan switch(depth) { 389 1.3 macallan case 1: 390 1.3 macallan /* setup the console */ 391 1.3 macallan 392 1.3 macallan /* first, make the overlay all opaque */ 393 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_ENABLE); 394 1.3 macallan memset(sc->sc_fbaddr, 0xff, 0x20000); 395 1.3 macallan 396 1.3 macallan /* now write the right thing into the WID plane */ 397 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_WID); 398 1.3 macallan memset(sc->sc_wids, 0, 0x100000); 399 1.3 macallan 400 1.3 macallan /* now clean the plane */ 401 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_OVL); 402 1.3 macallan memset(sc->sc_fbaddr, 0, 0x20000); 403 1.3 macallan break; 404 1.4 macallan case 8: 405 1.4 macallan /* setup the 8bit fb */ 406 1.4 macallan /* 407 1.4 macallan * first clean the 8bit fb - for aesthetic reasons do it while 408 1.4 macallan * it's still not visible ( we hope... ) 409 1.4 macallan */ 410 1.4 macallan cgtwelve_select_ovl(sc, CG12_SEL_8BIT); 411 1.4 macallan memset(sc->sc_int, 0x00, 0x100000); 412 1.4 macallan 413 1.4 macallan /* now write the right thing into the WID plane */ 414 1.4 macallan cgtwelve_select_ovl(sc, CG12_SEL_WID); 415 1.4 macallan memset(sc->sc_wids, 0, 0x100000); 416 1.4 macallan 417 1.4 macallan /* hide the overlay */ 418 1.4 macallan cgtwelve_select_ovl(sc, CG12_SEL_ENABLE); 419 1.4 macallan memset(sc->sc_fbaddr, 0, 0x20000); 420 1.4 macallan 421 1.4 macallan /* now clean the plane */ 422 1.4 macallan cgtwelve_select_ovl(sc, CG12_SEL_OVL); 423 1.4 macallan memset(sc->sc_fbaddr, 0, 0x20000); 424 1.4 macallan 425 1.6 macallan /* and make sure we can write the 8bit fb */ 426 1.4 macallan cgtwelve_select_ovl(sc, CG12_SEL_8BIT); 427 1.4 macallan break; 428 1.3 macallan case 24: 429 1.3 macallan case 32: 430 1.3 macallan /* setup the 24bit fb for X */ 431 1.3 macallan /* 432 1.3 macallan * first clean the 24bit fb - for aesthetic reasons do it while 433 1.3 macallan * it's still not visible ( we hope... ) 434 1.3 macallan */ 435 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_24BIT); 436 1.3 macallan memset(sc->sc_int, 0x80, 0x400000); 437 1.3 macallan 438 1.3 macallan /* now write the right thing into the WID plane */ 439 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_WID); 440 1.3 macallan memset(sc->sc_wids, 1, 0x100000); 441 1.3 macallan 442 1.3 macallan /* hide the overlay */ 443 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_ENABLE); 444 1.3 macallan memset(sc->sc_fbaddr, 0, 0x20000); 445 1.3 macallan 446 1.3 macallan /* now clean the plane */ 447 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_OVL); 448 1.3 macallan memset(sc->sc_fbaddr, 0, 0x20000); 449 1.3 macallan 450 1.3 macallan /* and make sure we can write the 24bit fb */ 451 1.3 macallan cgtwelve_select_ovl(sc, CG12_SEL_24BIT); 452 1.3 macallan break; 453 1.3 macallan } 454 1.3 macallan } 455 1.1 macallan 456 1.1 macallan static void 457 1.1 macallan cgtwelve_init_screen(void *cookie, struct vcons_screen *scr, 458 1.1 macallan int existing, long *defattr) 459 1.1 macallan { 460 1.1 macallan struct cgtwelve_softc *sc = cookie; 461 1.1 macallan struct rasops_info *ri = &scr->scr_ri; 462 1.1 macallan 463 1.4 macallan #ifdef CG12_COLOR 464 1.4 macallan ri->ri_depth = 8; 465 1.4 macallan #else 466 1.1 macallan ri->ri_depth = 1; 467 1.4 macallan #endif 468 1.1 macallan ri->ri_width = sc->sc_width; 469 1.1 macallan ri->ri_height = sc->sc_height; 470 1.1 macallan ri->ri_stride = sc->sc_stride; 471 1.1 macallan ri->ri_flg = RI_CENTER; 472 1.1 macallan 473 1.2 macallan if (sc->sc_shadow == NULL) { 474 1.4 macallan #ifdef CG12_COLOR 475 1.4 macallan ri->ri_bits = sc->sc_int; 476 1.4 macallan #else 477 1.2 macallan ri->ri_bits = sc->sc_fbaddr; 478 1.4 macallan #endif 479 1.4 macallan scr->scr_flags |= VCONS_DONT_READ; 480 1.2 macallan } else { 481 1.4 macallan #ifdef CG12_COLOR 482 1.4 macallan ri->ri_hwbits = sc->sc_int; 483 1.4 macallan #else 484 1.2 macallan ri->ri_hwbits = sc->sc_fbaddr; 485 1.4 macallan #endif 486 1.2 macallan ri->ri_bits = sc->sc_shadow; 487 1.2 macallan } 488 1.1 macallan 489 1.5 macallan rasops_init(ri, 0, 0); 490 1.4 macallan #ifdef CG12_COLOR 491 1.4 macallan ri->ri_caps = WSSCREEN_REVERSE | WSSCREEN_WSCOLORS; 492 1.4 macallan #else 493 1.1 macallan ri->ri_caps = WSSCREEN_REVERSE; 494 1.4 macallan #endif 495 1.1 macallan rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight, 496 1.1 macallan ri->ri_width / ri->ri_font->fontwidth); 497 1.1 macallan } 498 1.1 macallan 499 1.1 macallan static int 500 1.1 macallan cgtwelve_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, 501 1.1 macallan struct lwp *l) 502 1.1 macallan { 503 1.3 macallan struct vcons_data *vd = v; 504 1.3 macallan struct cgtwelve_softc *sc = vd->cookie; 505 1.3 macallan struct wsdisplay_fbinfo *wdf; 506 1.3 macallan struct vcons_screen *ms = vd->active; 507 1.1 macallan 508 1.1 macallan switch (cmd) { 509 1.1 macallan case WSDISPLAYIO_GTYPE: 510 1.1 macallan *(u_int *)data = WSDISPLAY_TYPE_SUNCG12; 511 1.1 macallan return 0; 512 1.3 macallan 513 1.3 macallan case WSDISPLAYIO_GINFO: 514 1.3 macallan wdf = (void *)data; 515 1.3 macallan wdf->height = sc->sc_height; 516 1.3 macallan wdf->width = sc->sc_width; 517 1.3 macallan wdf->depth = 32; 518 1.3 macallan wdf->cmsize = 256; 519 1.3 macallan return 0; 520 1.3 macallan 521 1.3 macallan case FBIOGVIDEO: 522 1.3 macallan case WSDISPLAYIO_GVIDEO: 523 1.3 macallan *(int *)data = 1; 524 1.3 macallan return 0; 525 1.3 macallan 526 1.3 macallan case WSDISPLAYIO_SVIDEO: 527 1.3 macallan case FBIOSVIDEO: 528 1.3 macallan /* when we figure out how to do this... */ 529 1.3 macallan /*cgtwelve_set_video(sc, *(int *)data);*/ 530 1.3 macallan return 0; 531 1.3 macallan 532 1.3 macallan case WSDISPLAYIO_LINEBYTES: 533 1.3 macallan { 534 1.3 macallan int *ret = (int *)data; 535 1.3 macallan *ret = sc->sc_width << 2; 536 1.3 macallan } 537 1.3 macallan return 0; 538 1.3 macallan 539 1.3 macallan case WSDISPLAYIO_SMODE: 540 1.3 macallan { 541 1.3 macallan int new_mode = *(int*)data; 542 1.3 macallan if (new_mode != sc->sc_mode) 543 1.3 macallan { 544 1.3 macallan sc->sc_mode = new_mode; 545 1.3 macallan if (new_mode == WSDISPLAYIO_MODE_EMUL) 546 1.3 macallan { 547 1.4 macallan #ifdef CG12_COLOR 548 1.4 macallan cgtwelve_setup(sc, 8); 549 1.4 macallan #else 550 1.3 macallan cgtwelve_setup(sc, 1); 551 1.4 macallan #endif 552 1.3 macallan vcons_redraw_screen(ms); 553 1.3 macallan } else { 554 1.3 macallan cgtwelve_setup(sc, 32); 555 1.3 macallan } 556 1.3 macallan } 557 1.3 macallan } 558 1.1 macallan } 559 1.1 macallan 560 1.1 macallan return EPASSTHROUGH; 561 1.1 macallan } 562 1.1 macallan 563 1.1 macallan static paddr_t 564 1.1 macallan cgtwelve_mmap(void *v, void *vs, off_t offset, int prot) 565 1.1 macallan { 566 1.3 macallan struct vcons_data *vd = v; 567 1.3 macallan struct cgtwelve_softc *sc = vd->cookie; 568 1.1 macallan 569 1.1 macallan /* regular fb mapping at 0 */ 570 1.3 macallan if ((offset >= 0) && (offset < 0x400000)) { 571 1.3 macallan return bus_space_mmap(sc->sc_tag, sc->sc_paddr + CG12_OFF_INTEN, 572 1.3 macallan offset, prot, BUS_SPACE_MAP_LINEAR); 573 1.1 macallan } 574 1.1 macallan 575 1.1 macallan return -1; 576 1.1 macallan } 577