Home | History | Annotate | Line # | Download | only in dev
bwtwo_obio.c revision 1.4.8.1
      1  1.4.8.1   nathanw /*	$NetBSD: bwtwo_obio.c,v 1.4.8.1 2002/04/01 07:42:39 nathanw Exp $ */
      2      1.1  christos 
      3      1.1  christos /*-
      4      1.1  christos  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5      1.1  christos  * All rights reserved.
      6      1.1  christos  *
      7      1.1  christos  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1  christos  * by Jason R. Thorpe.
      9      1.1  christos  *
     10      1.1  christos  * Redistribution and use in source and binary forms, with or without
     11      1.1  christos  * modification, are permitted provided that the following conditions
     12      1.1  christos  * are met:
     13      1.1  christos  * 1. Redistributions of source code must retain the above copyright
     14      1.1  christos  *    notice, this list of conditions and the following disclaimer.
     15      1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     17      1.1  christos  *    documentation and/or other materials provided with the distribution.
     18      1.1  christos  * 3. All advertising materials mentioning features or use of this software
     19      1.1  christos  *    must display the following acknowledgement:
     20      1.1  christos  *	This product includes software developed by the NetBSD
     21      1.1  christos  *	Foundation, Inc. and its contributors.
     22      1.1  christos  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1  christos  *    contributors may be used to endorse or promote products derived
     24      1.1  christos  *    from this software without specific prior written permission.
     25      1.1  christos  *
     26      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1  christos  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1  christos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1  christos  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1  christos  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1  christos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1  christos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1  christos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1  christos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1  christos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1  christos  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1  christos  */
     38      1.1  christos 
     39      1.1  christos /*
     40      1.1  christos  * Copyright (c) 1992, 1993
     41      1.1  christos  *	The Regents of the University of California.  All rights reserved.
     42      1.1  christos  *
     43      1.1  christos  * This software was developed by the Computer Systems Engineering group
     44      1.1  christos  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     45      1.1  christos  * contributed to Berkeley.
     46      1.1  christos  *
     47      1.1  christos  * All advertising materials mentioning features or use of this software
     48      1.1  christos  * must display the following acknowledgement:
     49      1.1  christos  *	This product includes software developed by the University of
     50      1.1  christos  *	California, Lawrence Berkeley Laboratory.
     51      1.1  christos  *
     52      1.1  christos  * Redistribution and use in source and binary forms, with or without
     53      1.1  christos  * modification, are permitted provided that the following conditions
     54      1.1  christos  * are met:
     55      1.1  christos  * 1. Redistributions of source code must retain the above copyright
     56      1.1  christos  *    notice, this list of conditions and the following disclaimer.
     57      1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     58      1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     59      1.1  christos  *    documentation and/or other materials provided with the distribution.
     60      1.1  christos  * 3. All advertising materials mentioning features or use of this software
     61      1.1  christos  *    must display the following acknowledgement:
     62      1.1  christos  *	This product includes software developed by the University of
     63      1.1  christos  *	California, Berkeley and its contributors.
     64      1.1  christos  * 4. Neither the name of the University nor the names of its contributors
     65      1.1  christos  *    may be used to endorse or promote products derived from this software
     66      1.1  christos  *    without specific prior written permission.
     67      1.1  christos  *
     68      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     69      1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     70      1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     71      1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     72      1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     73      1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     74      1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     75      1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     76      1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     77      1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     78      1.1  christos  * SUCH DAMAGE.
     79      1.1  christos  *
     80      1.1  christos  *	@(#)bwtwo.c	8.1 (Berkeley) 6/11/93
     81      1.1  christos  */
     82      1.1  christos 
     83      1.1  christos /*
     84      1.1  christos  * black&white display (bwtwo) driver.
     85      1.1  christos  *
     86      1.1  christos  * Does not handle interrupts, even though they can occur.
     87      1.1  christos  *
     88      1.1  christos  * P4 and overlay plane support by Jason R. Thorpe <thorpej (at) NetBSD.ORG>.
     89      1.1  christos  * Overlay plane handling hints and ideas provided by Brad Spencer.
     90      1.1  christos  */
     91      1.1  christos 
     92      1.1  christos #include <sys/param.h>
     93      1.1  christos #include <sys/systm.h>
     94      1.1  christos #include <sys/device.h>
     95      1.1  christos #include <sys/ioctl.h>
     96      1.1  christos #include <sys/malloc.h>
     97      1.1  christos #include <sys/mman.h>
     98      1.1  christos #include <sys/tty.h>
     99      1.1  christos #include <sys/conf.h>
    100      1.1  christos 
    101      1.1  christos #include <machine/autoconf.h>
    102      1.1  christos #include <machine/eeprom.h>
    103      1.1  christos #include <machine/ctlreg.h>
    104      1.1  christos #include <machine/conf.h>
    105      1.1  christos #include <sparc/sparc/asm.h>
    106      1.1  christos 
    107      1.4        pk #include <dev/sun/fbio.h>
    108      1.4        pk #include <dev/sun/fbvar.h>
    109      1.4        pk #include <dev/sun/btreg.h>
    110      1.4        pk #include <dev/sun/bwtworeg.h>
    111      1.4        pk #include <dev/sun/bwtwovar.h>
    112      1.4        pk #include <dev/sun/pfourreg.h>
    113      1.1  christos 
    114      1.1  christos /* autoconfiguration driver */
    115      1.4        pk static void	bwtwoattach_obio (struct device *, struct device *, void *);
    116      1.4        pk static int	bwtwomatch_obio (struct device *, struct cfdata *, void *);
    117      1.1  christos 
    118      1.1  christos 
    119      1.1  christos struct cfattach bwtwo_obio_ca = {
    120      1.1  christos 	sizeof(struct bwtwo_softc), bwtwomatch_obio, bwtwoattach_obio
    121      1.1  christos };
    122      1.1  christos 
    123      1.4        pk static int	bwtwo_get_video_sun4(struct bwtwo_softc *);
    124      1.4        pk static void	bwtwo_set_video_sun4(struct bwtwo_softc *, int);
    125      1.1  christos 
    126      1.1  christos extern int fbnode;
    127      1.1  christos 
    128      1.1  christos static int
    129      1.1  christos bwtwomatch_obio(parent, cf, aux)
    130      1.1  christos 	struct device *parent;
    131      1.1  christos 	struct cfdata *cf;
    132      1.1  christos 	void *aux;
    133      1.1  christos {
    134      1.1  christos 	union obio_attach_args *uoba = aux;
    135      1.1  christos 	struct obio4_attach_args *oba;
    136      1.1  christos 
    137      1.1  christos 	if (uoba->uoba_isobio4 == 0)
    138      1.1  christos 		return (0);
    139      1.1  christos 
    140      1.1  christos 	oba = &uoba->uoba_oba4;
    141  1.4.8.1   nathanw 	return (bus_space_probe(oba->oba_bustag, oba->oba_paddr,
    142      1.1  christos 				4,	/* probe size */
    143      1.1  christos 				0,	/* offset */
    144      1.1  christos 				0,	/* flags */
    145      1.1  christos 				bwtwo_pfour_probe, cf));
    146      1.1  christos }
    147      1.1  christos 
    148      1.1  christos static void
    149      1.1  christos bwtwoattach_obio(parent, self, uax)
    150      1.1  christos 	struct device *parent, *self;
    151      1.1  christos 	void *uax;
    152      1.1  christos {
    153      1.1  christos 	struct bwtwo_softc *sc = (struct bwtwo_softc *)self;
    154      1.1  christos 	union obio_attach_args *uoba = uax;
    155      1.1  christos 	struct obio4_attach_args *oba;
    156      1.1  christos 	struct fbdevice *fb = &sc->sc_fb;
    157      1.1  christos 	struct eeprom *eep = (struct eeprom *)eeprom_va;
    158      1.1  christos 	bus_space_handle_t bh;
    159      1.1  christos 	int constype, isconsole;
    160      1.1  christos 	char *name;
    161      1.1  christos 
    162      1.1  christos 	oba = &uoba->uoba_oba4;
    163      1.1  christos 
    164      1.1  christos 	/* Remember cookies for bwtwo_mmap() */
    165      1.1  christos 	sc->sc_bustag = oba->oba_bustag;
    166      1.1  christos 	sc->sc_paddr = (bus_addr_t)oba->oba_paddr;
    167      1.1  christos 
    168      1.1  christos 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
    169      1.1  christos 	fb->fb_type.fb_depth = 1;
    170      1.1  christos 	fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
    171      1.1  christos 
    172      1.1  christos 	constype = (fb->fb_flags & FB_PFOUR) ? EE_CONS_P4OPT : EE_CONS_BW;
    173      1.1  christos 	if (eep == NULL || eep->eeConsole == constype)
    174      1.2        pk 		isconsole = fb_is_console(0);
    175      1.1  christos 	else
    176      1.1  christos 		isconsole = 0;
    177      1.1  christos 
    178      1.1  christos 	if (fb->fb_flags & FB_PFOUR) {
    179      1.1  christos 		/*
    180      1.1  christos 		 * Map the pfour control register.
    181      1.1  christos 		 * Set pixel offset to appropriate overlay plane.
    182      1.1  christos 		 */
    183      1.1  christos 		name = "bwtwo/p4";
    184      1.1  christos 
    185  1.4.8.1   nathanw 		if (bus_space_map(oba->oba_bustag,
    186  1.4.8.1   nathanw 				  oba->oba_paddr,
    187  1.4.8.1   nathanw 				  sizeof(u_int32_t),
    188  1.4.8.1   nathanw 				  BUS_SPACE_MAP_LINEAR,
    189  1.4.8.1   nathanw 				  &bh) != 0) {
    190      1.1  christos 			printf("%s: cannot map pfour register\n",
    191      1.1  christos 				self->dv_xname);
    192      1.1  christos 			return;
    193      1.1  christos 		}
    194      1.1  christos 		fb->fb_pfour = (u_int32_t *)bh;
    195      1.1  christos 		sc->sc_reg = NULL;
    196      1.1  christos 
    197      1.1  christos 		/*
    198      1.1  christos 		 * Notice if this is an overlay plane on a color
    199      1.1  christos 		 * framebuffer.  Note that PFOUR_COLOR_OFF_OVERLAY
    200      1.1  christos 		 * is the same as PFOUR_BW_OFF, but we use the
    201      1.1  christos 		 * different names anyway.
    202      1.1  christos 		 */
    203      1.1  christos 		switch (PFOUR_ID(*fb->fb_pfour)) {
    204      1.1  christos 		case PFOUR_ID_COLOR8P1:
    205      1.1  christos 			sc->sc_ovtype = BWO_CGFOUR;
    206      1.1  christos 			sc->sc_pixeloffset = PFOUR_COLOR_OFF_OVERLAY;
    207      1.1  christos 			break;
    208      1.1  christos 
    209      1.1  christos 		case PFOUR_ID_COLOR24:
    210      1.1  christos 			sc->sc_ovtype = BWO_CGEIGHT;
    211      1.1  christos 			sc->sc_pixeloffset = PFOUR_COLOR_OFF_OVERLAY;
    212      1.1  christos 			break;
    213      1.1  christos 
    214      1.1  christos 		default:
    215      1.1  christos 			sc->sc_ovtype = BWO_NONE;
    216      1.1  christos 			sc->sc_pixeloffset = PFOUR_BW_OFF;
    217      1.1  christos 			break;
    218      1.1  christos 		}
    219      1.1  christos 
    220      1.1  christos 	} else {
    221      1.1  christos 		/* A plain bwtwo */
    222  1.4.8.1   nathanw 		if (bus_space_map(oba->oba_bustag,
    223  1.4.8.1   nathanw 				  oba->oba_paddr + BWREG_REG,
    224  1.4.8.1   nathanw 				  sizeof(struct fbcontrol),
    225  1.4.8.1   nathanw 				  BUS_SPACE_MAP_LINEAR,
    226  1.4.8.1   nathanw 				  &bh) != 0) {
    227      1.1  christos 			printf("%s: cannot map control registers\n",
    228      1.1  christos 				self->dv_xname);
    229      1.1  christos 			return;
    230      1.1  christos 		}
    231      1.1  christos 		sc->sc_reg = (struct fbcontrol *)bh;
    232      1.1  christos 		fb->fb_pfour = NULL;
    233      1.1  christos 
    234      1.1  christos 		name = "bwtwo";
    235      1.1  christos 		sc->sc_pixeloffset = BWREG_MEM;
    236      1.1  christos 	}
    237      1.1  christos 	sc->sc_get_video = bwtwo_get_video_sun4;
    238      1.1  christos 	sc->sc_set_video = bwtwo_set_video_sun4;
    239      1.1  christos 
    240      1.1  christos 	if (isconsole) {
    241      1.1  christos 		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
    242  1.4.8.1   nathanw 		if (bus_space_map(oba->oba_bustag,
    243  1.4.8.1   nathanw 				  oba->oba_paddr + sc->sc_pixeloffset,
    244  1.4.8.1   nathanw 				  ramsize,
    245  1.4.8.1   nathanw 				  BUS_SPACE_MAP_LINEAR,
    246  1.4.8.1   nathanw 				  &bh) != 0) {
    247      1.1  christos 			printf("%s: cannot map pixels\n", self->dv_xname);
    248      1.1  christos 			return;
    249      1.1  christos 		}
    250      1.1  christos 		sc->sc_fb.fb_pixels = (char *)bh;
    251      1.1  christos 	}
    252      1.1  christos 
    253      1.2        pk 	bwtwoattach(sc, name, isconsole);
    254      1.1  christos }
    255      1.1  christos 
    256      1.1  christos static void
    257      1.1  christos bwtwo_set_video_sun4(sc, enable)
    258      1.1  christos 	struct bwtwo_softc *sc;
    259      1.1  christos 	int enable;
    260      1.1  christos {
    261      1.1  christos 
    262      1.1  christos 	if (sc->sc_fb.fb_flags & FB_PFOUR) {
    263      1.1  christos 		/*
    264      1.1  christos 		 * This handles the overlay plane case, too.
    265      1.1  christos 		 */
    266      1.1  christos 		fb_pfour_set_video(&sc->sc_fb, enable);
    267      1.1  christos 		return;
    268      1.1  christos 	}
    269      1.1  christos 	if (enable)
    270      1.1  christos 		stba(AC_SYSENABLE, ASI_CONTROL,
    271      1.1  christos 		     lduba(AC_SYSENABLE, ASI_CONTROL) | SYSEN_VIDEO);
    272      1.1  christos 	else
    273      1.1  christos 		stba(AC_SYSENABLE, ASI_CONTROL,
    274      1.1  christos 		     lduba(AC_SYSENABLE, ASI_CONTROL) & ~SYSEN_VIDEO);
    275      1.1  christos 
    276      1.1  christos 	return;
    277      1.1  christos }
    278      1.1  christos 
    279      1.1  christos static int
    280      1.1  christos bwtwo_get_video_sun4(sc)
    281      1.1  christos 	struct bwtwo_softc *sc;
    282      1.1  christos {
    283      1.1  christos 
    284      1.1  christos 	if (sc->sc_fb.fb_flags & FB_PFOUR) {
    285      1.1  christos 		/*
    286      1.1  christos 		 * This handles the overlay plane case, too.
    287      1.1  christos 		 */
    288      1.1  christos 		return (fb_pfour_get_video(&sc->sc_fb));
    289      1.1  christos 	} else
    290      1.1  christos 		return ((lduba(AC_SYSENABLE, ASI_CONTROL) & SYSEN_VIDEO) != 0);
    291      1.1  christos }
    292