bwtwo_sbus.c revision 1.29
11.29Stsutsui/*	$NetBSD: bwtwo_sbus.c,v 1.29 2009/09/19 04:52:44 tsutsui 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.29Stsutsui__KERNEL_RCSID(0, "$NetBSD: bwtwo_sbus.c,v 1.29 2009/09/19 04:52:44 tsutsui 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.29StsutsuiCFATTACH_DECL_NEW(bwtwo_sbus, sizeof(struct bwtwo_softc),
1101.11Sthorpej    bwtwomatch_sbus, bwtwoattach_sbus, NULL, NULL);
1111.1Spk
1121.1Spkstatic int	bwtwo_get_video (struct bwtwo_softc *);
1131.1Spkstatic void	bwtwo_set_video (struct bwtwo_softc *, int);
1141.1Spk
1151.1Spk/*
1161.1Spk * Match a bwtwo.
1171.1Spk */
1181.1Spkstatic int
1191.25Sceggerbwtwomatch_sbus(device_t parent, cfdata_t cf, void *aux)
1201.1Spk{
1211.1Spk	struct sbus_attach_args *sa = aux;
1221.1Spk
1231.28Stsutsui	if (strcmp(cf->cf_name, sa->sa_name) == 0)
1241.28Stsutsui		return 100;	/* beat genfb(4) */
1251.28Stsutsui
1261.28Stsutsui	return 0;
1271.1Spk}
1281.1Spk
1291.1Spk
1301.1Spk/*
1311.1Spk * Attach a display.  We need to notice if it is the console, too.
1321.1Spk */
1331.1Spkvoid
1341.25Sceggerbwtwoattach_sbus(device_t parent, device_t self, void *args)
1351.1Spk{
1361.27Stsutsui	struct bwtwo_softc *sc = device_private(self);
1371.1Spk	struct sbus_attach_args *sa = args;
1381.1Spk	struct fbdevice *fb = &sc->sc_fb;
1391.1Spk	bus_space_handle_t bh;
1401.1Spk	int isconsole, node;
1411.16Stsutsui	const char *name;
1421.1Spk
1431.29Stsutsui	sc->sc_dev = self;
1441.1Spk	node = sa->sa_node;
1451.1Spk
1461.1Spk	/* Remember cookies for bwtwo_mmap() */
1471.1Spk	sc->sc_bustag = sa->sa_bustag;
1481.2Seeh	sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset);
1491.1Spk
1501.27Stsutsui	fb->fb_flags = device_cfdata(self)->cf_flags;
1511.1Spk	fb->fb_type.fb_depth = 1;
1521.1Spk	fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
1531.1Spk
1541.1Spk	/*
1551.1Spk	 * When the ROM has mapped in a bwtwo display, the address
1561.1Spk	 * maps only the video RAM, hence we always map the control
1571.1Spk	 * registers ourselves.  We only need the video RAM if we are
1581.1Spk	 * going to print characters via rconsole.
1591.1Spk	 */
1601.6Spk	if (sbus_bus_map(sa->sa_bustag,
1611.6Spk			 sa->sa_slot,
1621.1Spk			 sa->sa_offset + BWREG_REG,
1631.1Spk			 sizeof(struct fbcontrol),
1641.6Spk			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
1651.20Scegger		aprint_error_dev(self, "cannot map control registers\n");
1661.1Spk		return;
1671.1Spk	}
1681.12Smartin	sc->sc_reg = (struct fbcontrol *)bus_space_vaddr(sa->sa_bustag, bh);
1691.1Spk	fb->fb_pfour = NULL;
1701.1Spk
1711.1Spk	sc->sc_pixeloffset = BWREG_MEM;
1721.1Spk
1731.1Spk	isconsole = fb_is_console(node);
1741.15Spk	name = prom_getpropstring(node, "model");
1751.1Spk
1761.1Spk	/* Assume `bwtwo at sbus' only happens at sun4c's */
1771.1Spk	sc->sc_get_video = bwtwo_get_video;
1781.1Spk	sc->sc_set_video = bwtwo_set_video;
1791.1Spk
1801.1Spk	if (sa->sa_npromvaddrs != 0)
1811.19Schristos		sc->sc_fb.fb_pixels = (void *)(u_long)sa->sa_promvaddrs[0];
1821.1Spk	if (isconsole && sc->sc_fb.fb_pixels == NULL) {
1831.1Spk		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
1841.1Spk		if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
1851.1Spk				 sa->sa_offset + sc->sc_pixeloffset,
1861.1Spk				 ramsize,
1871.6Spk				 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
1881.20Scegger			aprint_error_dev(self, "cannot map pixels\n");
1891.1Spk			return;
1901.1Spk		}
1911.12Smartin		sc->sc_fb.fb_pixels = (char *)bus_space_vaddr(sa->sa_bustag, bh);
1921.1Spk	}
1931.1Spk
1941.1Spk	bwtwoattach(sc, name, isconsole);
1951.1Spk}
1961.1Spk
1971.1Spkstatic void
1981.22Sdslbwtwo_set_video(struct bwtwo_softc *sc, int enable)
1991.1Spk{
2001.1Spk
2011.1Spk	if (enable)
2021.1Spk		/*
2031.1Spk		 * If the we're the console the PROM will have taken care
2041.1Spk		 * of the FBC_TIMING bit and video control parameters. We
2051.1Spk		 * simply turn on FBC_TIMING; in case other video parameters
2061.1Spk		 * are necessary, here is a set read from an ELC:
2071.1Spk		 * [0xbb,0x2b,0x4,0x14,0xae,0x3,0xa8,0x24,0x1,0x5,0xff,0x1]
2081.1Spk		 */
2091.1Spk		sc->sc_reg->fbc_ctrl |= FBC_VENAB | FBC_TIMING;
2101.1Spk	else
2111.1Spk		sc->sc_reg->fbc_ctrl &= ~FBC_VENAB;
2121.1Spk}
2131.1Spk
2141.1Spkstatic int
2151.22Sdslbwtwo_get_video(struct bwtwo_softc *sc)
2161.1Spk{
2171.1Spk
2181.1Spk	return ((sc->sc_reg->fbc_ctrl & FBC_VENAB) != 0);
2191.1Spk}
220