Home | History | Annotate | Line # | Download | only in dev
cgsix_obio.c revision 1.9
      1 /*	$NetBSD: cgsix_obio.c,v 1.9 2002/03/11 16:27:01 pk 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 <sys/ioctl.h>
     48 #include <sys/malloc.h>
     49 #include <sys/mman.h>
     50 #include <sys/tty.h>
     51 #include <sys/conf.h>
     52 
     53 #ifdef DEBUG
     54 #include <sys/proc.h>
     55 #include <sys/syslog.h>
     56 #endif
     57 
     58 #include <machine/bus.h>
     59 #include <machine/autoconf.h>
     60 #include <machine/eeprom.h>
     61 #include <machine/conf.h>
     62 
     63 #include <dev/sun/fbio.h>
     64 #include <dev/sun/fbvar.h>
     65 #include <dev/sun/btreg.h>
     66 #include <dev/sun/btvar.h>
     67 #include <dev/sun/cgsixreg.h>
     68 #include <dev/sun/cgsixvar.h>
     69 #include <dev/sun/pfourreg.h>
     70 
     71 /* autoconfiguration driver */
     72 static int	cgsixmatch __P((struct device *, struct cfdata *, void *));
     73 static void	cgsixattach __P((struct device *, struct device *, void *));
     74 static int	cg6_pfour_probe __P((void *, void *));
     75 
     76 struct cfattach cgsix_obio_ca = {
     77 	sizeof(struct cgsix_softc), cgsixmatch, cgsixattach
     78 };
     79 
     80 /*
     81  * Match a cgsix.
     82  */
     83 static int
     84 cgsixmatch(parent, cf, aux)
     85 	struct device *parent;
     86 	struct cfdata *cf;
     87 	void *aux;
     88 {
     89 	union obio_attach_args *uoba = aux;
     90 	struct obio4_attach_args *oba;
     91 
     92 	if (uoba->uoba_isobio4 == 0)
     93 		return (0);
     94 
     95 	oba = &uoba->uoba_oba4;
     96 	return (bus_space_probe(oba->oba_bustag,
     97 				oba->oba_paddr + CGSIX_FHC_OFFSET,
     98 				4,	/* probe size */
     99 				0,	/* offset */
    100 				0,	/* flags */
    101 				cg6_pfour_probe, NULL));
    102 }
    103 
    104 static int
    105 cg6_pfour_probe(vaddr, arg)
    106 	void *vaddr;
    107 	void *arg;
    108 {
    109 
    110 	return (fb_pfour_id(vaddr) == PFOUR_ID_FASTCOLOR);
    111 }
    112 
    113 
    114 /*
    115  * Attach a display.
    116  */
    117 static void
    118 cgsixattach(parent, self, aux)
    119 	struct device *parent, *self;
    120 	void *aux;
    121 {
    122 	struct cgsix_softc *sc = (struct cgsix_softc *)self;
    123 	union obio_attach_args *uoba = aux;
    124 	struct obio4_attach_args *oba;
    125 	struct eeprom *eep = (struct eeprom *)eeprom_va;
    126 	struct fbdevice *fb = &sc->sc_fb;
    127 	bus_space_handle_t bh;
    128 	int constype, isconsole;
    129 	char *name;
    130 
    131 	oba = &uoba->uoba_oba4;
    132 
    133 	/* Remember cookies for cgsix_mmap() */
    134 	sc->sc_bustag = oba->oba_bustag;
    135 	sc->sc_paddr = (bus_addr_t)oba->oba_paddr;
    136 
    137 	fb->fb_device = &sc->sc_dev;
    138 	fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR;
    139 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
    140 	fb->fb_type.fb_depth = 8;
    141 
    142 	fb_setsize_eeprom(fb, fb->fb_type.fb_depth, 1152, 900);
    143 
    144 	/*
    145 	 * Dunno what the PROM has mapped, though obviously it must have
    146 	 * the video RAM mapped.  Just map what we care about for ourselves
    147 	 * (the FHC, THC, and Brooktree registers).
    148 	 */
    149 	if (bus_space_map(oba->oba_bustag,
    150 			  oba->oba_paddr + CGSIX_BT_OFFSET,
    151 			  sizeof(*sc->sc_bt),
    152 			  BUS_SPACE_MAP_LINEAR,
    153 			  &bh) != 0) {
    154 		printf("%s: cannot map brooktree registers\n", self->dv_xname);
    155 		return;
    156 	}
    157 	sc->sc_bt = (struct bt_regs *)bh;
    158 
    159 	if (bus_space_map(oba->oba_bustag,
    160 			  oba->oba_paddr + CGSIX_FHC_OFFSET,
    161 			  sizeof(*sc->sc_fhc),
    162 			  BUS_SPACE_MAP_LINEAR,
    163 			  &bh) != 0) {
    164 		printf("%s: cannot map FHC registers\n", self->dv_xname);
    165 		return;
    166 	}
    167 	sc->sc_fhc = (int *)bh;
    168 
    169 	if (bus_space_map(oba->oba_bustag,
    170 			  oba->oba_paddr + CGSIX_THC_OFFSET,
    171 			  sizeof(*sc->sc_thc),
    172 			  BUS_SPACE_MAP_LINEAR,
    173 			  &bh) != 0) {
    174 		printf("%s: cannot map THC registers\n", self->dv_xname);
    175 		return;
    176 	}
    177 	sc->sc_thc = (struct cg6_thc *)bh;
    178 
    179 	if (bus_space_map(oba->oba_bustag,
    180 			  oba->oba_paddr + CGSIX_TEC_OFFSET,
    181 			  sizeof(*sc->sc_tec),
    182 			  BUS_SPACE_MAP_LINEAR,
    183 			  &bh) != 0) {
    184 		printf("%s: cannot map TEC registers\n", self->dv_xname);
    185 		return;
    186 	}
    187 	sc->sc_tec = (struct cg6_tec_xxx *)bh;
    188 
    189 	if (bus_space_map(oba->oba_bustag,
    190 			  oba->oba_paddr + CGSIX_FBC_OFFSET,
    191 			  sizeof(*sc->sc_fbc),
    192 			  BUS_SPACE_MAP_LINEAR,
    193 			  &bh) != 0) {
    194 		printf("%s: cannot map FBC registers\n", self->dv_xname);
    195 		return;
    196 	}
    197 	sc->sc_fbc = (struct cg6_fbc *)bh;
    198 
    199 
    200 	if (fb_pfour_id((void *)sc->sc_fhc) == PFOUR_ID_FASTCOLOR) {
    201 		fb->fb_flags |= FB_PFOUR;
    202 		name = "cgsix/p4";
    203 	} else
    204 		name = "cgsix";
    205 
    206 	constype = (fb->fb_flags & FB_PFOUR) ? EE_CONS_P4OPT : EE_CONS_COLOR;
    207 
    208 	/*
    209 	 * Assume this is the console if there's no eeprom info
    210 	 * to be found.
    211 	 */
    212 	if (eep == NULL || eep->eeConsole == constype)
    213 		isconsole = fb_is_console(0);
    214 	else
    215 		isconsole = 0;
    216 
    217 	if (isconsole && cgsix_use_rasterconsole) {
    218 		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
    219 		if (bus_space_map(oba->oba_bustag,
    220 				  oba->oba_paddr + CGSIX_RAM_OFFSET,
    221 				  ramsize,
    222 				  BUS_SPACE_MAP_LINEAR,
    223 				  &bh) != 0) {
    224 			printf("%s: cannot map pixels\n", self->dv_xname);
    225 			return;
    226 		}
    227 		sc->sc_fb.fb_pixels = (caddr_t)bh;
    228 	}
    229 
    230 	cg6attach(sc, name, isconsole);
    231 }
    232