bwtwo_sbus.c revision 1.20
11.20Scegger/* $NetBSD: bwtwo_sbus.c,v 1.20 2008/04/05 18:35:31 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 * 3. All advertising materials mentioning features or use of this software 191.1Spk * must display the following acknowledgement: 201.1Spk * This product includes software developed by the NetBSD 211.1Spk * Foundation, Inc. and its contributors. 221.1Spk * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Spk * contributors may be used to endorse or promote products derived 241.1Spk * from this software without specific prior written permission. 251.1Spk * 261.1Spk * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Spk * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Spk * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Spk * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Spk * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Spk * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Spk * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Spk * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Spk * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Spk * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Spk * POSSIBILITY OF SUCH DAMAGE. 371.1Spk */ 381.1Spk 391.1Spk/* 401.1Spk * Copyright (c) 1992, 1993 411.1Spk * The Regents of the University of California. All rights reserved. 421.1Spk * 431.1Spk * This software was developed by the Computer Systems Engineering group 441.1Spk * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 451.1Spk * contributed to Berkeley. 461.1Spk * 471.1Spk * All advertising materials mentioning features or use of this software 481.1Spk * must display the following acknowledgement: 491.1Spk * This product includes software developed by the University of 501.1Spk * California, Lawrence Berkeley Laboratory. 511.1Spk * 521.1Spk * Redistribution and use in source and binary forms, with or without 531.1Spk * modification, are permitted provided that the following conditions 541.1Spk * are met: 551.1Spk * 1. Redistributions of source code must retain the above copyright 561.1Spk * notice, this list of conditions and the following disclaimer. 571.1Spk * 2. Redistributions in binary form must reproduce the above copyright 581.1Spk * notice, this list of conditions and the following disclaimer in the 591.1Spk * documentation and/or other materials provided with the distribution. 601.13Sagc * 3. Neither the name of the University nor the names of its contributors 611.1Spk * may be used to endorse or promote products derived from this software 621.1Spk * without specific prior written permission. 631.1Spk * 641.1Spk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 651.1Spk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 661.1Spk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 671.1Spk * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 681.1Spk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 691.1Spk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 701.1Spk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 711.1Spk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 721.1Spk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 731.1Spk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 741.1Spk * SUCH DAMAGE. 751.1Spk * 761.1Spk * @(#)bwtwo.c 8.1 (Berkeley) 6/11/93 771.1Spk */ 781.1Spk 791.1Spk/* 801.1Spk * black&white display (bwtwo) driver. 811.1Spk * 821.1Spk * Does not handle interrupts, even though they can occur. 831.1Spk * 841.14Skeihan * P4 and overlay plane support by Jason R. Thorpe <thorpej@NetBSD.org>. 851.1Spk * Overlay plane handling hints and ideas provided by Brad Spencer. 861.1Spk */ 871.5Slukem 881.5Slukem#include <sys/cdefs.h> 891.20Scegger__KERNEL_RCSID(0, "$NetBSD: bwtwo_sbus.c,v 1.20 2008/04/05 18:35:31 cegger Exp $"); 901.1Spk 911.1Spk#include <sys/param.h> 921.1Spk#include <sys/systm.h> 931.1Spk#include <sys/device.h> 941.1Spk#include <sys/ioctl.h> 951.1Spk#include <sys/malloc.h> 961.1Spk#include <sys/mman.h> 971.1Spk#include <sys/tty.h> 981.1Spk#include <sys/conf.h> 991.1Spk 1001.1Spk#include <machine/autoconf.h> 1011.1Spk#include <machine/eeprom.h> 1021.1Spk 1031.1Spk#include <dev/sbus/sbusvar.h> 1041.1Spk 1051.1Spk#include <dev/sun/fbio.h> 1061.1Spk#include <dev/sun/fbvar.h> 1071.1Spk#include <dev/sun/btreg.h> 1081.1Spk#include <dev/sun/bwtworeg.h> 1091.1Spk#include <dev/sun/bwtwovar.h> 1101.1Spk#include <dev/sun/pfourreg.h> 1111.1Spk 1121.1Spk/* autoconfiguration driver */ 1131.1Spkstatic void bwtwoattach_sbus (struct device *, struct device *, void *); 1141.1Spkstatic int bwtwomatch_sbus (struct device *, struct cfdata *, void *); 1151.1Spk 1161.1Spk/* Allocate an `sbusdev' in addition to the bwtwo softc */ 1171.1Spkstruct bwtwo_sbus_softc { 1181.1Spk struct bwtwo_softc bss_softc; 1191.1Spk struct sbusdev bss_sd; 1201.1Spk}; 1211.1Spk 1221.10SthorpejCFATTACH_DECL(bwtwo_sbus, sizeof(struct bwtwo_sbus_softc), 1231.11Sthorpej bwtwomatch_sbus, bwtwoattach_sbus, NULL, NULL); 1241.1Spk 1251.1Spkstatic int bwtwo_get_video (struct bwtwo_softc *); 1261.1Spkstatic void bwtwo_set_video (struct bwtwo_softc *, int); 1271.1Spk 1281.1Spk/* 1291.1Spk * Match a bwtwo. 1301.1Spk */ 1311.1Spkstatic int 1321.1Spkbwtwomatch_sbus(parent, cf, aux) 1331.1Spk struct device *parent; 1341.1Spk struct cfdata *cf; 1351.1Spk void *aux; 1361.1Spk{ 1371.1Spk struct sbus_attach_args *sa = aux; 1381.1Spk 1391.8Sthorpej return (strcmp(cf->cf_name, sa->sa_name) == 0); 1401.1Spk} 1411.1Spk 1421.1Spk 1431.1Spk/* 1441.1Spk * Attach a display. We need to notice if it is the console, too. 1451.1Spk */ 1461.1Spkvoid 1471.1Spkbwtwoattach_sbus(parent, self, args) 1481.1Spk struct device *parent, *self; 1491.1Spk void *args; 1501.1Spk{ 1511.1Spk struct bwtwo_softc *sc = (struct bwtwo_softc *)self; 1521.1Spk struct sbusdev *sd = &((struct bwtwo_sbus_softc *)self)->bss_sd; 1531.1Spk struct sbus_attach_args *sa = args; 1541.1Spk struct fbdevice *fb = &sc->sc_fb; 1551.1Spk bus_space_handle_t bh; 1561.1Spk int isconsole, node; 1571.16Stsutsui const char *name; 1581.1Spk 1591.1Spk node = sa->sa_node; 1601.1Spk 1611.1Spk /* Remember cookies for bwtwo_mmap() */ 1621.1Spk sc->sc_bustag = sa->sa_bustag; 1631.2Seeh sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset); 1641.1Spk 1651.18Sthorpej fb->fb_flags = device_cfdata(&sc->sc_dev)->cf_flags; 1661.1Spk fb->fb_type.fb_depth = 1; 1671.1Spk fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node); 1681.1Spk 1691.1Spk /* 1701.1Spk * When the ROM has mapped in a bwtwo display, the address 1711.1Spk * maps only the video RAM, hence we always map the control 1721.1Spk * registers ourselves. We only need the video RAM if we are 1731.1Spk * going to print characters via rconsole. 1741.1Spk */ 1751.6Spk if (sbus_bus_map(sa->sa_bustag, 1761.6Spk sa->sa_slot, 1771.1Spk sa->sa_offset + BWREG_REG, 1781.1Spk sizeof(struct fbcontrol), 1791.6Spk BUS_SPACE_MAP_LINEAR, &bh) != 0) { 1801.20Scegger aprint_error_dev(self, "cannot map control registers\n"); 1811.1Spk return; 1821.1Spk } 1831.12Smartin sc->sc_reg = (struct fbcontrol *)bus_space_vaddr(sa->sa_bustag, bh); 1841.1Spk fb->fb_pfour = NULL; 1851.1Spk 1861.1Spk sc->sc_pixeloffset = BWREG_MEM; 1871.1Spk 1881.1Spk isconsole = fb_is_console(node); 1891.15Spk name = prom_getpropstring(node, "model"); 1901.1Spk 1911.1Spk /* Assume `bwtwo at sbus' only happens at sun4c's */ 1921.1Spk sc->sc_get_video = bwtwo_get_video; 1931.1Spk sc->sc_set_video = bwtwo_set_video; 1941.1Spk 1951.1Spk if (sa->sa_npromvaddrs != 0) 1961.19Schristos sc->sc_fb.fb_pixels = (void *)(u_long)sa->sa_promvaddrs[0]; 1971.1Spk if (isconsole && sc->sc_fb.fb_pixels == NULL) { 1981.1Spk int ramsize = fb->fb_type.fb_height * fb->fb_linebytes; 1991.1Spk if (sbus_bus_map(sa->sa_bustag, sa->sa_slot, 2001.1Spk sa->sa_offset + sc->sc_pixeloffset, 2011.1Spk ramsize, 2021.6Spk BUS_SPACE_MAP_LINEAR, &bh) != 0) { 2031.20Scegger aprint_error_dev(self, "cannot map pixels\n"); 2041.1Spk return; 2051.1Spk } 2061.12Smartin sc->sc_fb.fb_pixels = (char *)bus_space_vaddr(sa->sa_bustag, bh); 2071.1Spk } 2081.1Spk 2091.1Spk sbus_establish(sd, &sc->sc_dev); 2101.1Spk bwtwoattach(sc, name, isconsole); 2111.1Spk} 2121.1Spk 2131.1Spkstatic void 2141.1Spkbwtwo_set_video(sc, enable) 2151.1Spk struct bwtwo_softc *sc; 2161.1Spk int enable; 2171.1Spk{ 2181.1Spk 2191.1Spk if (enable) 2201.1Spk /* 2211.1Spk * If the we're the console the PROM will have taken care 2221.1Spk * of the FBC_TIMING bit and video control parameters. We 2231.1Spk * simply turn on FBC_TIMING; in case other video parameters 2241.1Spk * are necessary, here is a set read from an ELC: 2251.1Spk * [0xbb,0x2b,0x4,0x14,0xae,0x3,0xa8,0x24,0x1,0x5,0xff,0x1] 2261.1Spk */ 2271.1Spk sc->sc_reg->fbc_ctrl |= FBC_VENAB | FBC_TIMING; 2281.1Spk else 2291.1Spk sc->sc_reg->fbc_ctrl &= ~FBC_VENAB; 2301.1Spk} 2311.1Spk 2321.1Spkstatic int 2331.1Spkbwtwo_get_video(sc) 2341.1Spk struct bwtwo_softc *sc; 2351.1Spk{ 2361.1Spk 2371.1Spk return ((sc->sc_reg->fbc_ctrl & FBC_VENAB) != 0); 2381.1Spk} 239