Home | History | Annotate | Line # | Download | only in dev
cgsix_obio.c revision 1.2
      1 /*	$NetBSD: cgsix_obio.c,v 1.2 1999/03/25 00:41:47 mrg Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Paul Kranenburg.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * color display (cgsix) driver; sun4 obio bus front-end.
     41  */
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/buf.h>
     46 #include <sys/device.h>
     47 #include <machine/fbio.h>
     48 #include <sys/ioctl.h>
     49 #include <sys/malloc.h>
     50 #include <sys/mman.h>
     51 #include <sys/tty.h>
     52 #include <sys/conf.h>
     53 
     54 #ifdef DEBUG
     55 #include <sys/proc.h>
     56 #include <sys/syslog.h>
     57 #endif
     58 
     59 #include <vm/vm.h>
     60 
     61 #include <machine/bus.h>
     62 #include <machine/autoconf.h>
     63 #include <machine/pmap.h>
     64 #include <machine/fbvar.h>
     65 #include <machine/cpu.h>
     66 #include <machine/eeprom.h>
     67 #include <machine/conf.h>
     68 
     69 #include <sparc/dev/btreg.h>
     70 #include <sparc/dev/btvar.h>
     71 #include <sparc/dev/sbusvar.h>
     72 #include <sparc/dev/cgsixreg.h>
     73 #include <sparc/dev/cgsixvar.h>
     74 #include <sparc/dev/pfourreg.h>
     75 
     76 /* autoconfiguration driver */
     77 static int	cgsixmatch __P((struct device *, struct cfdata *, void *));
     78 static void	cgsixattach __P((struct device *, struct device *, void *));
     79 static int	cg6_pfour_probe __P((void *, void *));
     80 
     81 struct cfattach cgsix_obio_ca = {
     82 	sizeof(struct cgsix_softc), cgsixmatch, cgsixattach
     83 };
     84 
     85 /*
     86  * Match a cgsix.
     87  */
     88 int
     89 cgsixmatch(parent, cf, aux)
     90 	struct device *parent;
     91 	struct cfdata *cf;
     92 	void *aux;
     93 {
     94 	union obio_attach_args *uoba = aux;
     95 	struct obio4_attach_args *oba;
     96 
     97 	if (uoba->uoba_isobio4 == 0)
     98 		return (0);
     99 
    100 	oba = &uoba->uoba_oba4;
    101 	return (bus_space_probe(oba->oba_bustag, 0,
    102 				oba->oba_paddr + CGSIX_FHC_OFFSET,
    103 				4,	/* probe size */
    104 				0,	/* offset */
    105 				0,	/* flags */
    106 				cg6_pfour_probe, NULL));
    107 }
    108 
    109 int
    110 cg6_pfour_probe(vaddr, arg)
    111 	void *vaddr;
    112 	void *arg;
    113 {
    114 
    115 	return (fb_pfour_id(vaddr) == PFOUR_ID_FASTCOLOR);
    116 }
    117 
    118 
    119 /*
    120  * Attach a display.
    121  */
    122 void
    123 cgsixattach(parent, self, aux)
    124 	struct device *parent, *self;
    125 	void *aux;
    126 {
    127 	struct cgsix_softc *sc = (struct cgsix_softc *)self;
    128 	union obio_attach_args *uoba = aux;
    129 	struct obio4_attach_args *oba;
    130 	struct eeprom *eep = (struct eeprom *)eeprom_va;
    131 	struct fbdevice *fb = &sc->sc_fb;
    132 	bus_space_handle_t bh;
    133 	int constype, isconsole;
    134 	char *name;
    135 	extern struct tty *fbconstty;
    136 
    137 	if (uoba->uoba_isobio4 == 0) {
    138 		(*cgsix_sbus_ca.ca_attach)(parent, self, aux);
    139 		return;
    140 	}
    141 
    142 	oba = &uoba->uoba_oba4;
    143 
    144 	/* Remember cookies for cgsix_mmap() */
    145 	sc->sc_bustag = oba->oba_bustag;
    146 	sc->sc_btype = (bus_type_t)0;
    147 	sc->sc_paddr = (bus_addr_t)oba->oba_paddr;
    148 
    149 	fb->fb_device = &sc->sc_dev;
    150 	fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR;
    151 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
    152 	fb->fb_type.fb_depth = 8;
    153 
    154 	fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
    155 
    156 	/*
    157 	 * Dunno what the PROM has mapped, though obviously it must have
    158 	 * the video RAM mapped.  Just map what we care about for ourselves
    159 	 * (the FHC, THC, and Brooktree registers).
    160 	 */
    161 	if (bus_space_map2(oba->oba_bustag, 0,
    162 			   oba->oba_paddr + CGSIX_BT_OFFSET,
    163 			   sizeof(*sc->sc_bt),
    164 			   BUS_SPACE_MAP_LINEAR,
    165 			   0, &bh) != 0) {
    166 		printf("%s: cannot map brooktree registers\n", self->dv_xname);
    167 		return;
    168 	}
    169 	sc->sc_bt = (struct bt_regs *)bh;
    170 
    171 	if (bus_space_map2(oba->oba_bustag, 0,
    172 			   oba->oba_paddr + CGSIX_FHC_OFFSET,
    173 			   sizeof(*sc->sc_fhc),
    174 			   BUS_SPACE_MAP_LINEAR,
    175 			   0, &bh) != 0) {
    176 		printf("%s: cannot map FHC registers\n", self->dv_xname);
    177 		return;
    178 	}
    179 	sc->sc_fhc = (int *)bh;
    180 
    181 	if (bus_space_map2(oba->oba_bustag, 0,
    182 			   oba->oba_paddr + CGSIX_THC_OFFSET,
    183 			   sizeof(*sc->sc_thc),
    184 			   BUS_SPACE_MAP_LINEAR,
    185 			   0, &bh) != 0) {
    186 		printf("%s: cannot map THC registers\n", self->dv_xname);
    187 		return;
    188 	}
    189 	sc->sc_thc = (struct cg6_thc *)bh;
    190 
    191 	if (bus_space_map2(oba->oba_bustag, 0,
    192 			   oba->oba_paddr + CGSIX_TEC_OFFSET,
    193 			   sizeof(*sc->sc_tec),
    194 			   BUS_SPACE_MAP_LINEAR,
    195 			   0, &bh) != 0) {
    196 		printf("%s: cannot map TEC registers\n", self->dv_xname);
    197 		return;
    198 	}
    199 	sc->sc_tec = (struct cg6_tec_xxx *)bh;
    200 
    201 
    202 	if (fb_pfour_id((void *)sc->sc_fhc) == PFOUR_ID_FASTCOLOR) {
    203 		fb->fb_flags |= FB_PFOUR;
    204 		name = "cgsix/p4";
    205 	} else
    206 		name = "cgsix";
    207 
    208 	constype = (fb->fb_flags & FB_PFOUR) ? EE_CONS_P4OPT : EE_CONS_COLOR;
    209 
    210 	/*
    211 	 * Assume this is the console if there's no eeprom info
    212 	 * to be found.
    213 	 */
    214 	if (eep == NULL || eep->eeConsole == constype)
    215 		isconsole = (fbconstty != NULL);
    216 	else
    217 		isconsole = 0;
    218 
    219 	if (isconsole && cgsix_use_rasterconsole) {
    220 		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
    221 		if (bus_space_map2(oba->oba_bustag, 0,
    222 				   oba->oba_paddr + CGSIX_RAM_OFFSET,
    223 				   ramsize,
    224 				   BUS_SPACE_MAP_LINEAR,
    225 				   0, &bh) != 0) {
    226 			printf("%s: cannot map pixels\n", self->dv_xname);
    227 			return;
    228 		}
    229 		sc->sc_fb.fb_pixels = (caddr_t)bh;
    230 	}
    231 
    232 	cg6attach(sc, name, isconsole, 1);
    233 }
    234