bwtwo_sbus.c revision 1.11
11.11Sthorpej/*	$NetBSD: bwtwo_sbus.c,v 1.11 2002/10/02 16:52:33 thorpej 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.1Spk * 3. All advertising materials mentioning features or use of this software
611.1Spk *    must display the following acknowledgement:
621.1Spk *	This product includes software developed by the University of
631.1Spk *	California, Berkeley and its contributors.
641.1Spk * 4. Neither the name of the University nor the names of its contributors
651.1Spk *    may be used to endorse or promote products derived from this software
661.1Spk *    without specific prior written permission.
671.1Spk *
681.1Spk * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
691.1Spk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
701.1Spk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
711.1Spk * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
721.1Spk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
731.1Spk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
741.1Spk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
751.1Spk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
761.1Spk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
771.1Spk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
781.1Spk * SUCH DAMAGE.
791.1Spk *
801.1Spk *	@(#)bwtwo.c	8.1 (Berkeley) 6/11/93
811.1Spk */
821.1Spk
831.1Spk/*
841.1Spk * black&white display (bwtwo) driver.
851.1Spk *
861.1Spk * Does not handle interrupts, even though they can occur.
871.1Spk *
881.1Spk * P4 and overlay plane support by Jason R. Thorpe <thorpej@NetBSD.ORG>.
891.1Spk * Overlay plane handling hints and ideas provided by Brad Spencer.
901.1Spk */
911.5Slukem
921.5Slukem#include <sys/cdefs.h>
931.11Sthorpej__KERNEL_RCSID(0, "$NetBSD: bwtwo_sbus.c,v 1.11 2002/10/02 16:52:33 thorpej Exp $");
941.1Spk
951.1Spk#include <sys/param.h>
961.1Spk#include <sys/systm.h>
971.1Spk#include <sys/device.h>
981.1Spk#include <sys/ioctl.h>
991.1Spk#include <sys/malloc.h>
1001.1Spk#include <sys/mman.h>
1011.1Spk#include <sys/tty.h>
1021.1Spk#include <sys/conf.h>
1031.1Spk
1041.1Spk#include <machine/autoconf.h>
1051.1Spk#include <machine/eeprom.h>
1061.1Spk
1071.1Spk#include <dev/sbus/sbusvar.h>
1081.1Spk
1091.1Spk#include <dev/sun/fbio.h>
1101.1Spk#include <dev/sun/fbvar.h>
1111.1Spk#include <dev/sun/btreg.h>
1121.1Spk#include <dev/sun/bwtworeg.h>
1131.1Spk#include <dev/sun/bwtwovar.h>
1141.1Spk#include <dev/sun/pfourreg.h>
1151.1Spk
1161.1Spk/* autoconfiguration driver */
1171.1Spkstatic void	bwtwoattach_sbus (struct device *, struct device *, void *);
1181.1Spkstatic int	bwtwomatch_sbus (struct device *, struct cfdata *, void *);
1191.1Spk
1201.1Spk/* Allocate an `sbusdev' in addition to the bwtwo softc */
1211.1Spkstruct bwtwo_sbus_softc {
1221.1Spk	struct bwtwo_softc bss_softc;
1231.1Spk	struct sbusdev bss_sd;
1241.1Spk};
1251.1Spk
1261.10SthorpejCFATTACH_DECL(bwtwo_sbus, sizeof(struct bwtwo_sbus_softc),
1271.11Sthorpej    bwtwomatch_sbus, bwtwoattach_sbus, NULL, NULL);
1281.1Spk
1291.1Spkstatic int	bwtwo_get_video (struct bwtwo_softc *);
1301.1Spkstatic void	bwtwo_set_video (struct bwtwo_softc *, int);
1311.1Spk
1321.1Spk/*
1331.1Spk * Match a bwtwo.
1341.1Spk */
1351.1Spkstatic int
1361.1Spkbwtwomatch_sbus(parent, cf, aux)
1371.1Spk	struct device *parent;
1381.1Spk	struct cfdata *cf;
1391.1Spk	void *aux;
1401.1Spk{
1411.1Spk	struct sbus_attach_args *sa = aux;
1421.1Spk
1431.8Sthorpej	return (strcmp(cf->cf_name, sa->sa_name) == 0);
1441.1Spk}
1451.1Spk
1461.1Spk
1471.1Spk/*
1481.1Spk * Attach a display.  We need to notice if it is the console, too.
1491.1Spk */
1501.1Spkvoid
1511.1Spkbwtwoattach_sbus(parent, self, args)
1521.1Spk	struct device *parent, *self;
1531.1Spk	void *args;
1541.1Spk{
1551.1Spk	struct bwtwo_softc *sc = (struct bwtwo_softc *)self;
1561.1Spk	struct sbusdev *sd = &((struct bwtwo_sbus_softc *)self)->bss_sd;
1571.1Spk	struct sbus_attach_args *sa = args;
1581.1Spk	struct fbdevice *fb = &sc->sc_fb;
1591.1Spk	bus_space_handle_t bh;
1601.1Spk	int isconsole, node;
1611.1Spk	char *name;
1621.1Spk
1631.1Spk	node = sa->sa_node;
1641.1Spk
1651.1Spk	/* Remember cookies for bwtwo_mmap() */
1661.1Spk	sc->sc_bustag = sa->sa_bustag;
1671.2Seeh	sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset);
1681.1Spk
1691.1Spk	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
1701.1Spk	fb->fb_type.fb_depth = 1;
1711.1Spk	fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
1721.1Spk
1731.1Spk	/*
1741.1Spk	 * When the ROM has mapped in a bwtwo display, the address
1751.1Spk	 * maps only the video RAM, hence we always map the control
1761.1Spk	 * registers ourselves.  We only need the video RAM if we are
1771.1Spk	 * going to print characters via rconsole.
1781.1Spk	 */
1791.6Spk	if (sbus_bus_map(sa->sa_bustag,
1801.6Spk			 sa->sa_slot,
1811.1Spk			 sa->sa_offset + BWREG_REG,
1821.1Spk			 sizeof(struct fbcontrol),
1831.6Spk			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
1841.1Spk		printf("%s: cannot map control registers\n", self->dv_xname);
1851.1Spk		return;
1861.1Spk	}
1871.1Spk	sc->sc_reg = (struct fbcontrol *)bh;
1881.1Spk	fb->fb_pfour = NULL;
1891.1Spk
1901.1Spk	sc->sc_pixeloffset = BWREG_MEM;
1911.1Spk
1921.1Spk	isconsole = fb_is_console(node);
1931.3Seeh	name = PROM_getpropstring(node, "model");
1941.1Spk
1951.1Spk	/* Assume `bwtwo at sbus' only happens at sun4c's */
1961.1Spk	sc->sc_get_video = bwtwo_get_video;
1971.1Spk	sc->sc_set_video = bwtwo_set_video;
1981.1Spk
1991.1Spk	if (sa->sa_npromvaddrs != 0)
2001.4Spooka		sc->sc_fb.fb_pixels = (caddr_t)(u_long)sa->sa_promvaddrs[0];
2011.1Spk	if (isconsole && sc->sc_fb.fb_pixels == NULL) {
2021.1Spk		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
2031.1Spk		if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
2041.1Spk				 sa->sa_offset + sc->sc_pixeloffset,
2051.1Spk				 ramsize,
2061.6Spk				 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
2071.1Spk			printf("%s: cannot map pixels\n", self->dv_xname);
2081.1Spk			return;
2091.1Spk		}
2101.1Spk		sc->sc_fb.fb_pixels = (char *)bh;
2111.1Spk	}
2121.1Spk
2131.1Spk	sbus_establish(sd, &sc->sc_dev);
2141.1Spk	bwtwoattach(sc, name, isconsole);
2151.1Spk}
2161.1Spk
2171.1Spkstatic void
2181.1Spkbwtwo_set_video(sc, enable)
2191.1Spk	struct bwtwo_softc *sc;
2201.1Spk	int enable;
2211.1Spk{
2221.1Spk
2231.1Spk	if (enable)
2241.1Spk		/*
2251.1Spk		 * If the we're the console the PROM will have taken care
2261.1Spk		 * of the FBC_TIMING bit and video control parameters. We
2271.1Spk		 * simply turn on FBC_TIMING; in case other video parameters
2281.1Spk		 * are necessary, here is a set read from an ELC:
2291.1Spk		 * [0xbb,0x2b,0x4,0x14,0xae,0x3,0xa8,0x24,0x1,0x5,0xff,0x1]
2301.1Spk		 */
2311.1Spk		sc->sc_reg->fbc_ctrl |= FBC_VENAB | FBC_TIMING;
2321.1Spk	else
2331.1Spk		sc->sc_reg->fbc_ctrl &= ~FBC_VENAB;
2341.1Spk}
2351.1Spk
2361.1Spkstatic int
2371.1Spkbwtwo_get_video(sc)
2381.1Spk	struct bwtwo_softc *sc;
2391.1Spk{
2401.1Spk
2411.1Spk	return ((sc->sc_reg->fbc_ctrl & FBC_VENAB) != 0);
2421.1Spk}
243