Home | History | Annotate | Line # | Download | only in dev
bwtwo_any.c revision 1.8
      1  1.8   thorpej /*	$NetBSD: bwtwo_any.c,v 1.8 2002/10/02 16:02:22 thorpej 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 <sun2/sun2/control.h>
    103  1.1  fredette 
    104  1.1  fredette #include <dev/sun/fbio.h>
    105  1.1  fredette #include <dev/sun/fbvar.h>
    106  1.1  fredette #include <dev/sun/btreg.h>
    107  1.1  fredette #include <sun2/dev/bwtworeg.h>
    108  1.1  fredette #include <dev/sun/bwtwovar.h>
    109  1.1  fredette 
    110  1.1  fredette /* autoconfiguration driver */
    111  1.1  fredette static void	bwtwoattach_any (struct device *, struct device *, void *);
    112  1.1  fredette static int	bwtwomatch_any (struct device *, struct cfdata *, void *);
    113  1.1  fredette 
    114  1.1  fredette struct bwtwosun2_softc {
    115  1.1  fredette 	struct bwtwo_softc sc;
    116  1.1  fredette 	bus_space_handle_t bh;
    117  1.1  fredette };
    118  1.1  fredette 
    119  1.7   thorpej CFATTACH_DECL(bwtwo_obio, sizeof(struct bwtwosun2_softc),
    120  1.8   thorpej     bwtwomatch_any, bwtwoattach_any, NULL, NULL);
    121  1.1  fredette 
    122  1.7   thorpej CFATTACH_DECL(bwtwo_obmem, sizeof(struct bwtwosun2_softc),
    123  1.8   thorpej     bwtwomatch_any, bwtwoattach_any, NULL, NULL);
    124  1.1  fredette 
    125  1.1  fredette static int	bwtwo_get_video_sun2 __P((struct bwtwo_softc *));
    126  1.1  fredette static void	bwtwo_set_video_sun2 __P((struct bwtwo_softc *, int));
    127  1.1  fredette 
    128  1.1  fredette extern int fbnode;
    129  1.1  fredette 
    130  1.1  fredette static int
    131  1.1  fredette bwtwomatch_any(parent, cf, aux)
    132  1.1  fredette 	struct device *parent;
    133  1.1  fredette 	struct cfdata *cf;
    134  1.1  fredette 	void *aux;
    135  1.1  fredette {
    136  1.3  fredette 	struct mainbus_attach_args *ma = aux;
    137  1.3  fredette 	bus_space_handle_t bh;
    138  1.3  fredette 	int matched;
    139  1.1  fredette 
    140  1.3  fredette 	/* Make sure there is something there... */
    141  1.3  fredette 	if (bus_space_map(ma->ma_bustag, ma->ma_paddr + BWREG_REG, sizeof(struct bwtworeg),
    142  1.3  fredette 			  0, &bh))
    143  1.3  fredette 		return (0);
    144  1.3  fredette 	matched = (bus_space_peek_1(ma->ma_bustag, bh, 0, NULL) == 0);
    145  1.3  fredette 	bus_space_unmap(ma->ma_bustag, bh, sizeof(struct bwtworeg));
    146  1.3  fredette 	return (matched);
    147  1.1  fredette }
    148  1.1  fredette 
    149  1.1  fredette static void
    150  1.1  fredette bwtwoattach_any(parent, self, aux)
    151  1.1  fredette 	struct device *parent, *self;
    152  1.1  fredette 	void *aux;
    153  1.1  fredette {
    154  1.1  fredette 	struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)self;
    155  1.1  fredette 	struct bwtwo_softc *sc = &scsun2->sc;
    156  1.3  fredette 	struct mainbus_attach_args *ma = aux;
    157  1.1  fredette 	struct fbdevice *fb = &sc->sc_fb;
    158  1.1  fredette 	bus_space_handle_t bh;
    159  1.1  fredette 	int isconsole;
    160  1.1  fredette 	char *name;
    161  1.1  fredette 
    162  1.1  fredette 	/* Remember cookies for bwtwo_mmap() */
    163  1.3  fredette 	sc->sc_bustag = ma->ma_bustag;
    164  1.3  fredette 	sc->sc_paddr = ma->ma_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.2  fredette 	fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
    169  1.1  fredette 
    170  1.1  fredette 	isconsole = fb_is_console(0);
    171  1.1  fredette 
    172  1.1  fredette 	/* A plain bwtwo */
    173  1.1  fredette 	sc->sc_reg = NULL;
    174  1.1  fredette 	fb->fb_pfour = NULL;
    175  1.1  fredette 	name = "bwtwo";
    176  1.1  fredette 	sc->sc_pixeloffset = BWREG_MEM;
    177  1.1  fredette 	sc->sc_get_video = bwtwo_get_video_sun2;
    178  1.1  fredette 	sc->sc_set_video = bwtwo_set_video_sun2;
    179  1.1  fredette 
    180  1.1  fredette 	/* Map the registers. */
    181  1.3  fredette 	if (bus_space_map(ma->ma_bustag, ma->ma_paddr + BWREG_REG, sizeof(struct bwtworeg),
    182  1.1  fredette 	    		  0, &scsun2->bh)) {
    183  1.1  fredette 		printf("%s: cannot map regs\n", self->dv_xname);
    184  1.1  fredette 		return;
    185  1.1  fredette 	}
    186  1.1  fredette 
    187  1.1  fredette 	if (isconsole) {
    188  1.1  fredette 		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
    189  1.3  fredette 		if (bus_space_map(ma->ma_bustag, ma->ma_paddr + sc->sc_pixeloffset,
    190  1.1  fredette 				  ramsize,
    191  1.1  fredette 				  BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    192  1.1  fredette 			printf("%s: cannot map pixels\n", self->dv_xname);
    193  1.1  fredette 			return;
    194  1.1  fredette 		}
    195  1.1  fredette 		sc->sc_fb.fb_pixels = (char *)bh;
    196  1.1  fredette 	}
    197  1.1  fredette 
    198  1.1  fredette 	bwtwoattach(sc, name, isconsole);
    199  1.1  fredette }
    200  1.1  fredette 
    201  1.1  fredette static void
    202  1.1  fredette bwtwo_set_video_sun2(sc, enable)
    203  1.1  fredette 	struct bwtwo_softc *sc;
    204  1.1  fredette 	int enable;
    205  1.1  fredette {
    206  1.1  fredette 	struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)sc;
    207  1.1  fredette 	unsigned char cr;
    208  1.1  fredette 
    209  1.1  fredette 	cr = bus_space_read_1(sc->sc_bustag, scsun2->bh, 0);
    210  1.1  fredette 	bus_space_write_1(sc->sc_bustag, scsun2->bh, 0, (enable ?
    211  1.1  fredette 							 (cr | BW2_CR_ENABLE_VIDEO) :
    212  1.1  fredette 	    						 (cr & ~BW2_CR_ENABLE_VIDEO)));
    213  1.1  fredette 	return;
    214  1.1  fredette }
    215  1.1  fredette 
    216  1.1  fredette static int
    217  1.1  fredette bwtwo_get_video_sun2(sc)
    218  1.1  fredette 	struct bwtwo_softc *sc;
    219  1.1  fredette {
    220  1.1  fredette 	struct bwtwosun2_softc *scsun2 = (struct bwtwosun2_softc *)sc;
    221  1.1  fredette 
    222  1.1  fredette 	return ((bus_space_read_1(sc->sc_bustag, scsun2->bh, 0) & BW2_CR_ENABLE_VIDEO) != 0);
    223  1.1  fredette }
    224