bwtwo_sbus.c revision 1.25
11.25Scegger/* $NetBSD: bwtwo_sbus.c,v 1.25 2009/05/12 14:43:59 cegger Exp $ */ 21.1Spk 31.1Spk/*- 41.1Spk * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc. 51.1Spk * All rights reserved. 61.1Spk * 71.1Spk * This code is derived from software contributed to The NetBSD Foundation 81.1Spk * by Jason R. Thorpe. 91.1Spk * 101.1Spk * Redistribution and use in source and binary forms, with or without 111.1Spk * modification, are permitted provided that the following conditions 121.1Spk * are met: 131.1Spk * 1. Redistributions of source code must retain the above copyright 141.1Spk * notice, this list of conditions and the following disclaimer. 151.1Spk * 2. Redistributions in binary form must reproduce the above copyright 161.1Spk * notice, this list of conditions and the following disclaimer in the 171.1Spk * documentation and/or other materials provided with the distribution. 181.1Spk * 191.1Spk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Spk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Spk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Spk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Spk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Spk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Spk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Spk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Spk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Spk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Spk * POSSIBILITY OF SUCH DAMAGE. 301.1Spk */ 311.1Spk 321.1Spk/* 331.1Spk * Copyright (c) 1992, 1993 341.1Spk * The Regents of the University of California. All rights reserved. 351.1Spk * 361.1Spk * This software was developed by the Computer Systems Engineering group 371.1Spk * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 381.1Spk * contributed to Berkeley. 391.1Spk * 401.1Spk * All advertising materials mentioning features or use of this software 411.1Spk * must display the following acknowledgement: 421.1Spk * This product includes software developed by the University of 431.1Spk * California, Lawrence Berkeley Laboratory. 441.1Spk * 451.1Spk * Redistribution and use in source and binary forms, with or without 461.1Spk * modification, are permitted provided that the following conditions 471.1Spk * are met: 481.1Spk * 1. Redistributions of source code must retain the above copyright 491.1Spk * notice, this list of conditions and the following disclaimer. 501.1Spk * 2. Redistributions in binary form must reproduce the above copyright 511.1Spk * notice, this list of conditions and the following disclaimer in the 521.1Spk * documentation and/or other materials provided with the distribution. 531.13Sagc * 3. Neither the name of the University nor the names of its contributors 541.1Spk * may be used to endorse or promote products derived from this software 551.1Spk * without specific prior written permission. 561.1Spk * 571.1Spk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 581.1Spk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 591.1Spk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 601.1Spk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 611.1Spk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 621.1Spk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 631.1Spk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 641.1Spk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 651.1Spk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 661.1Spk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 671.1Spk * SUCH DAMAGE. 681.1Spk * 691.1Spk * @(#)bwtwo.c 8.1 (Berkeley) 6/11/93 701.1Spk */ 711.1Spk 721.1Spk/* 731.1Spk * black&white display (bwtwo) driver. 741.1Spk * 751.1Spk * Does not handle interrupts, even though they can occur. 761.1Spk * 771.14Skeihan * P4 and overlay plane support by Jason R. Thorpe <thorpej@NetBSD.org>. 781.1Spk * Overlay plane handling hints and ideas provided by Brad Spencer. 791.1Spk */ 801.5Slukem 811.5Slukem#include <sys/cdefs.h> 821.25Scegger__KERNEL_RCSID(0, "$NetBSD: bwtwo_sbus.c,v 1.25 2009/05/12 14:43:59 cegger Exp $"); 831.1Spk 841.1Spk#include <sys/param.h> 851.1Spk#include <sys/systm.h> 861.1Spk#include <sys/device.h> 871.1Spk#include <sys/ioctl.h> 881.1Spk#include <sys/malloc.h> 891.1Spk#include <sys/mman.h> 901.1Spk#include <sys/tty.h> 911.1Spk#include <sys/conf.h> 921.1Spk 931.1Spk#include <machine/autoconf.h> 941.1Spk#include <machine/eeprom.h> 951.1Spk 961.1Spk#include <dev/sbus/sbusvar.h> 971.1Spk 981.1Spk#include <dev/sun/fbio.h> 991.1Spk#include <dev/sun/fbvar.h> 1001.1Spk#include <dev/sun/btreg.h> 1011.1Spk#include <dev/sun/bwtworeg.h> 1021.1Spk#include <dev/sun/bwtwovar.h> 1031.1Spk#include <dev/sun/pfourreg.h> 1041.1Spk 1051.1Spk/* autoconfiguration driver */ 1061.25Sceggerstatic void bwtwoattach_sbus (device_t, device_t, void *); 1071.25Sceggerstatic int bwtwomatch_sbus (device_t, cfdata_t, void *); 1081.1Spk 1091.1Spk/* Allocate an `sbusdev' in addition to the bwtwo softc */ 1101.1Spkstruct bwtwo_sbus_softc { 1111.1Spk struct bwtwo_softc bss_softc; 1121.1Spk struct sbusdev bss_sd; 1131.1Spk}; 1141.1Spk 1151.10SthorpejCFATTACH_DECL(bwtwo_sbus, sizeof(struct bwtwo_sbus_softc), 1161.11Sthorpej bwtwomatch_sbus, bwtwoattach_sbus, NULL, NULL); 1171.1Spk 1181.1Spkstatic int bwtwo_get_video (struct bwtwo_softc *); 1191.1Spkstatic void bwtwo_set_video (struct bwtwo_softc *, int); 1201.1Spk 1211.1Spk/* 1221.1Spk * Match a bwtwo. 1231.1Spk */ 1241.1Spkstatic int 1251.25Sceggerbwtwomatch_sbus(device_t parent, cfdata_t cf, void *aux) 1261.1Spk{ 1271.1Spk struct sbus_attach_args *sa = aux; 1281.1Spk 1291.8Sthorpej return (strcmp(cf->cf_name, sa->sa_name) == 0); 1301.1Spk} 1311.1Spk 1321.1Spk 1331.1Spk/* 1341.1Spk * Attach a display. We need to notice if it is the console, too. 1351.1Spk */ 1361.1Spkvoid 1371.25Sceggerbwtwoattach_sbus(device_t parent, device_t self, void *args) 1381.1Spk{ 1391.1Spk struct bwtwo_softc *sc = (struct bwtwo_softc *)self; 1401.1Spk struct sbusdev *sd = &((struct bwtwo_sbus_softc *)self)->bss_sd; 1411.1Spk struct sbus_attach_args *sa = args; 1421.1Spk struct fbdevice *fb = &sc->sc_fb; 1431.1Spk bus_space_handle_t bh; 1441.1Spk int isconsole, node; 1451.16Stsutsui const char *name; 1461.1Spk 1471.1Spk node = sa->sa_node; 1481.1Spk 1491.1Spk /* Remember cookies for bwtwo_mmap() */ 1501.1Spk sc->sc_bustag = sa->sa_bustag; 1511.2Seeh sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset); 1521.1Spk 1531.18Sthorpej fb->fb_flags = device_cfdata(&sc->sc_dev)->cf_flags; 1541.1Spk fb->fb_type.fb_depth = 1; 1551.1Spk fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node); 1561.1Spk 1571.1Spk /* 1581.1Spk * When the ROM has mapped in a bwtwo display, the address 1591.1Spk * maps only the video RAM, hence we always map the control 1601.1Spk * registers ourselves. We only need the video RAM if we are 1611.1Spk * going to print characters via rconsole. 1621.1Spk */ 1631.6Spk if (sbus_bus_map(sa->sa_bustag, 1641.6Spk sa->sa_slot, 1651.1Spk sa->sa_offset + BWREG_REG, 1661.1Spk sizeof(struct fbcontrol), 1671.6Spk BUS_SPACE_MAP_LINEAR, &bh) != 0) { 1681.20Scegger aprint_error_dev(self, "cannot map control registers\n"); 1691.1Spk return; 1701.1Spk } 1711.12Smartin sc->sc_reg = (struct fbcontrol *)bus_space_vaddr(sa->sa_bustag, bh); 1721.1Spk fb->fb_pfour = NULL; 1731.1Spk 1741.1Spk sc->sc_pixeloffset = BWREG_MEM; 1751.1Spk 1761.1Spk isconsole = fb_is_console(node); 1771.15Spk name = prom_getpropstring(node, "model"); 1781.1Spk 1791.1Spk /* Assume `bwtwo at sbus' only happens at sun4c's */ 1801.1Spk sc->sc_get_video = bwtwo_get_video; 1811.1Spk sc->sc_set_video = bwtwo_set_video; 1821.1Spk 1831.1Spk if (sa->sa_npromvaddrs != 0) 1841.19Schristos sc->sc_fb.fb_pixels = (void *)(u_long)sa->sa_promvaddrs[0]; 1851.1Spk if (isconsole && sc->sc_fb.fb_pixels == NULL) { 1861.1Spk int ramsize = fb->fb_type.fb_height * fb->fb_linebytes; 1871.1Spk if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, 1881.1Spk sa->sa_offset + sc->sc_pixeloffset, 1891.1Spk ramsize, 1901.6Spk BUS_SPACE_MAP_LINEAR, &bh) != 0) { 1911.20Scegger aprint_error_dev(self, "cannot map pixels\n"); 1921.1Spk return; 1931.1Spk } 1941.12Smartin sc->sc_fb.fb_pixels = (char *)bus_space_vaddr(sa->sa_bustag, bh); 1951.1Spk } 1961.1Spk 1971.1Spk sbus_establish(sd, &sc->sc_dev); 1981.1Spk bwtwoattach(sc, name, isconsole); 1991.1Spk} 2001.1Spk 2011.1Spkstatic void 2021.22Sdslbwtwo_set_video(struct bwtwo_softc *sc, int enable) 2031.1Spk{ 2041.1Spk 2051.1Spk if (enable) 2061.1Spk /* 2071.1Spk * If the we're the console the PROM will have taken care 2081.1Spk * of the FBC_TIMING bit and video control parameters. We 2091.1Spk * simply turn on FBC_TIMING; in case other video parameters 2101.1Spk * are necessary, here is a set read from an ELC: 2111.1Spk * [0xbb,0x2b,0x4,0x14,0xae,0x3,0xa8,0x24,0x1,0x5,0xff,0x1] 2121.1Spk */ 2131.1Spk sc->sc_reg->fbc_ctrl |= FBC_VENAB | FBC_TIMING; 2141.1Spk else 2151.1Spk sc->sc_reg->fbc_ctrl &= ~FBC_VENAB; 2161.1Spk} 2171.1Spk 2181.1Spkstatic int 2191.22Sdslbwtwo_get_video(struct bwtwo_softc *sc) 2201.1Spk{ 2211.1Spk 2221.1Spk return ((sc->sc_reg->fbc_ctrl & FBC_VENAB) != 0); 2231.1Spk} 224