Home | History | Annotate | Line # | Download | only in dev
bwtwo_any.c revision 1.1
      1  1.1  fredette /*	$NetBSD: bwtwo_any.c,v 1.1 2001/04/06 15:14:39 fredette Exp $ */
      2  1.1  fredette 
      3  1.1  fredette /*-
      4  1.1  fredette  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
      5  1.1  fredette  * All rights reserved.
      6  1.1  fredette  *
      7  1.1  fredette  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1  fredette  * by Jason R. Thorpe and Matthew Fredette.
      9  1.1  fredette  *
     10  1.1  fredette  * Redistribution and use in source and binary forms, with or without
     11  1.1  fredette  * modification, are permitted provided that the following conditions
     12  1.1  fredette  * are met:
     13  1.1  fredette  * 1. Redistributions of source code must retain the above copyright
     14  1.1  fredette  *    notice, this list of conditions and the following disclaimer.
     15  1.1  fredette  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1  fredette  *    notice, this list of conditions and the following disclaimer in the
     17  1.1  fredette  *    documentation and/or other materials provided with the distribution.
     18  1.1  fredette  * 3. All advertising materials mentioning features or use of this software
     19  1.1  fredette  *    must display the following acknowledgement:
     20  1.1  fredette  *	This product includes software developed by the NetBSD
     21  1.1  fredette  *	Foundation, Inc. and its contributors.
     22  1.1  fredette  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1  fredette  *    contributors may be used to endorse or promote products derived
     24  1.1  fredette  *    from this software without specific prior written permission.
     25  1.1  fredette  *
     26  1.1  fredette  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1  fredette  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1  fredette  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1  fredette  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1  fredette  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1  fredette  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1  fredette  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1  fredette  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1  fredette  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1  fredette  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1  fredette  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1  fredette  */
     38  1.1  fredette 
     39  1.1  fredette /*
     40  1.1  fredette  * Copyright (c) 1992, 1993
     41  1.1  fredette  *	The Regents of the University of California.  All rights reserved.
     42  1.1  fredette  *
     43  1.1  fredette  * This software was developed by the Computer Systems Engineering group
     44  1.1  fredette  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     45  1.1  fredette  * contributed to Berkeley.
     46  1.1  fredette  *
     47  1.1  fredette  * All advertising materials mentioning features or use of this software
     48  1.1  fredette  * must display the following acknowledgement:
     49  1.1  fredette  *	This product includes software developed by the University of
     50  1.1  fredette  *	California, Lawrence Berkeley Laboratory.
     51  1.1  fredette  *
     52  1.1  fredette  * Redistribution and use in source and binary forms, with or without
     53  1.1  fredette  * modification, are permitted provided that the following conditions
     54  1.1  fredette  * are met:
     55  1.1  fredette  * 1. Redistributions of source code must retain the above copyright
     56  1.1  fredette  *    notice, this list of conditions and the following disclaimer.
     57  1.1  fredette  * 2. Redistributions in binary form must reproduce the above copyright
     58  1.1  fredette  *    notice, this list of conditions and the following disclaimer in the
     59  1.1  fredette  *    documentation and/or other materials provided with the distribution.
     60  1.1  fredette  * 3. All advertising materials mentioning features or use of this software
     61  1.1  fredette  *    must display the following acknowledgement:
     62  1.1  fredette  *	This product includes software developed by the University of
     63  1.1  fredette  *	California, Berkeley and its contributors.
     64  1.1  fredette  * 4. Neither the name of the University nor the names of its contributors
     65  1.1  fredette  *    may be used to endorse or promote products derived from this software
     66  1.1  fredette  *    without specific prior written permission.
     67  1.1  fredette  *
     68  1.1  fredette  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     69  1.1  fredette  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     70  1.1  fredette  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     71  1.1  fredette  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     72  1.1  fredette  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     73  1.1  fredette  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     74  1.1  fredette  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     75  1.1  fredette  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     76  1.1  fredette  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     77  1.1  fredette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     78  1.1  fredette  * SUCH DAMAGE.
     79  1.1  fredette  *
     80  1.1  fredette  *	@(#)bwtwo.c	8.1 (Berkeley) 6/11/93
     81  1.1  fredette  */
     82  1.1  fredette 
     83  1.1  fredette /*
     84  1.1  fredette  * black&white display (bwtwo) driver.
     85  1.1  fredette  *
     86  1.1  fredette  * Does not handle interrupts, even though they can occur.
     87  1.1  fredette  *
     88  1.1  fredette  * P4 and overlay plane support by Jason R. Thorpe <thorpej (at) NetBSD.ORG>.
     89  1.1  fredette  * Overlay plane handling hints and ideas provided by Brad Spencer.
     90  1.1  fredette  */
     91  1.1  fredette 
     92  1.1  fredette #include <sys/param.h>
     93  1.1  fredette #include <sys/systm.h>
     94  1.1  fredette #include <sys/device.h>
     95  1.1  fredette #include <sys/ioctl.h>
     96  1.1  fredette #include <sys/malloc.h>
     97  1.1  fredette #include <sys/mman.h>
     98  1.1  fredette #include <sys/tty.h>
     99  1.1  fredette #include <sys/conf.h>
    100  1.1  fredette 
    101  1.1  fredette #include <machine/autoconf.h>
    102  1.1  fredette #include <machine/conf.h>
    103  1.1  fredette #include <sun2/sun2/control.h>
    104  1.1  fredette 
    105  1.1  fredette #include <dev/sun/fbio.h>
    106  1.1  fredette #include <dev/sun/fbvar.h>
    107  1.1  fredette #include <dev/sun/btreg.h>
    108  1.1  fredette #include <sun2/dev/bwtworeg.h>
    109  1.1  fredette #include <dev/sun/bwtwovar.h>
    110  1.1  fredette 
    111  1.1  fredette /* autoconfiguration driver */
    112  1.1  fredette static void	bwtwoattach_any (struct device *, struct device *, void *);
    113  1.1  fredette static int	bwtwomatch_any (struct device *, struct cfdata *, void *);
    114  1.1  fredette 
    115  1.1  fredette struct bwtwosun2_softc {
    116  1.1  fredette 	struct bwtwo_softc sc;
    117  1.1  fredette 	bus_space_handle_t bh;
    118  1.1  fredette };
    119  1.1  fredette 
    120  1.1  fredette struct cfattach bwtwo_obio_ca = {
    121  1.1  fredette 	sizeof(struct bwtwosun2_softc), bwtwomatch_any, bwtwoattach_any
    122  1.1  fredette };
    123  1.1  fredette 
    124  1.1  fredette struct cfattach bwtwo_obmem_ca = {
    125  1.1  fredette 	sizeof(struct bwtwosun2_softc), bwtwomatch_any, bwtwoattach_any
    126  1.1  fredette };
    127  1.1  fredette 
    128  1.1  fredette static int	bwtwo_get_video_sun2 __P((struct bwtwo_softc *));
    129  1.1  fredette static void	bwtwo_set_video_sun2 __P((struct bwtwo_softc *, int));
    130  1.1  fredette 
    131  1.1  fredette extern int fbnode;
    132  1.1  fredette 
    133  1.1  fredette static int
    134  1.1  fredette bwtwomatch_any(parent, cf, aux)
    135  1.1  fredette 	struct device *parent;
    136  1.1  fredette 	struct cfdata *cf;
    137  1.1  fredette 	void *aux;
    138  1.1  fredette {
    139  1.1  fredette 	struct confargs *ca = aux;
    140  1.1  fredette 
    141  1.1  fredette 	return (bus_space_probe(ca->ca_bustag, 0, ca->ca_paddr,
    142  1.1  fredette 				4,	/* probe size */
    143  1.1  fredette 				0,	/* offset */
    144  1.1  fredette 				0,	/* flags */
    145  1.1  fredette 				NULL, NULL));
    146  1.1  fredette }
    147  1.1  fredette 
    148  1.1  fredette static void
    149  1.1  fredette bwtwoattach_any(parent, self, aux)
    150  1.1  fredette 	struct device *parent, *self;
    151  1.1  fredette 	void *aux;
    152  1.1  fredette {
    153  1.1  fredette 	struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)self;
    154  1.1  fredette 	struct bwtwo_softc *sc = &scsun2->sc;
    155  1.1  fredette 	struct confargs *ca = aux;
    156  1.1  fredette 	struct fbdevice *fb = &sc->sc_fb;
    157  1.1  fredette 	bus_space_handle_t bh;
    158  1.1  fredette 	int isconsole;
    159  1.1  fredette 	char *name;
    160  1.1  fredette 
    161  1.1  fredette 	/* Remember cookies for bwtwo_mmap() */
    162  1.1  fredette 	sc->sc_bustag = ca->ca_bustag;
    163  1.1  fredette 	sc->sc_btype = (bus_type_t)0;
    164  1.1  fredette 	sc->sc_paddr = (bus_addr_t)ca->ca_paddr;
    165  1.1  fredette 
    166  1.1  fredette 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags;
    167  1.1  fredette 	fb->fb_type.fb_depth = 1;
    168  1.1  fredette 	fb->fb_type.fb_width = 1152;
    169  1.1  fredette 	fb->fb_type.fb_height = 900;
    170  1.1  fredette 
    171  1.1  fredette 	isconsole = fb_is_console(0);
    172  1.1  fredette 
    173  1.1  fredette 	/* A plain bwtwo */
    174  1.1  fredette 	sc->sc_reg = NULL;
    175  1.1  fredette 	fb->fb_pfour = NULL;
    176  1.1  fredette 	name = "bwtwo";
    177  1.1  fredette 	sc->sc_pixeloffset = BWREG_MEM;
    178  1.1  fredette 	sc->sc_get_video = bwtwo_get_video_sun2;
    179  1.1  fredette 	sc->sc_set_video = bwtwo_set_video_sun2;
    180  1.1  fredette 
    181  1.1  fredette 	/* Map the registers. */
    182  1.1  fredette 	if (bus_space_map(ca->ca_bustag, ca->ca_paddr + BWREG_REG, sizeof(struct bwtworeg),
    183  1.1  fredette 	    		  0, &scsun2->bh)) {
    184  1.1  fredette 		printf("%s: cannot map regs\n", self->dv_xname);
    185  1.1  fredette 		return;
    186  1.1  fredette 	}
    187  1.1  fredette 
    188  1.1  fredette 	if (isconsole) {
    189  1.1  fredette 		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
    190  1.1  fredette 		if (bus_space_map(ca->ca_bustag, ca->ca_paddr + sc->sc_pixeloffset,
    191  1.1  fredette 				  ramsize,
    192  1.1  fredette 				  BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    193  1.1  fredette 			printf("%s: cannot map pixels\n", self->dv_xname);
    194  1.1  fredette 			return;
    195  1.1  fredette 		}
    196  1.1  fredette 		sc->sc_fb.fb_pixels = (char *)bh;
    197  1.1  fredette 	}
    198  1.1  fredette 
    199  1.1  fredette 	bwtwoattach(sc, name, isconsole);
    200  1.1  fredette }
    201  1.1  fredette 
    202  1.1  fredette static void
    203  1.1  fredette bwtwo_set_video_sun2(sc, enable)
    204  1.1  fredette 	struct bwtwo_softc *sc;
    205  1.1  fredette 	int enable;
    206  1.1  fredette {
    207  1.1  fredette 	struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)sc;
    208  1.1  fredette 	unsigned char cr;
    209  1.1  fredette 
    210  1.1  fredette 	cr = bus_space_read_1(sc->sc_bustag, scsun2->bh, 0);
    211  1.1  fredette 	bus_space_write_1(sc->sc_bustag, scsun2->bh, 0, (enable ?
    212  1.1  fredette 							 (cr | BW2_CR_ENABLE_VIDEO) :
    213  1.1  fredette 	    						 (cr & ~BW2_CR_ENABLE_VIDEO)));
    214  1.1  fredette 	return;
    215  1.1  fredette }
    216  1.1  fredette 
    217  1.1  fredette static int
    218  1.1  fredette bwtwo_get_video_sun2(sc)
    219  1.1  fredette 	struct bwtwo_softc *sc;
    220  1.1  fredette {
    221  1.1  fredette 	struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)sc;
    222  1.1  fredette 
    223  1.1  fredette 	return ((bus_space_read_1(sc->sc_bustag, scsun2->bh, 0) & BW2_CR_ENABLE_VIDEO) != 0);
    224  1.1  fredette }
    225