Home | History | Annotate | Line # | Download | only in sbus
cgsix_sbus.c revision 1.5
      1 /*	$NetBSD: cgsix_sbus.c,v 1.5 2001/09/26 20:53:14 eeh 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; Sbus 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 
     61 #include <dev/sbus/sbusvar.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 
     70 /* autoconfiguration driver */
     71 static int	cgsixmatch __P((struct device *, struct cfdata *, void *));
     72 static void	cgsixattach __P((struct device *, struct device *, void *));
     73 
     74 /* Allocate an `sbusdev' in addition to the cgsix softc */
     75 struct cgsix_sbus_softc {
     76 	struct cgsix_softc bss_softc;
     77 	struct sbusdev bss_sd;
     78 };
     79 
     80 struct cfattach cgsix_sbus_ca = {
     81 	sizeof(struct cgsix_sbus_softc), cgsixmatch, cgsixattach
     82 };
     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 	struct sbus_attach_args *sa = aux;
     95 
     96 	return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
     97 }
     98 
     99 
    100 /*
    101  * Attach a cgsix.
    102  */
    103 void
    104 cgsixattach(parent, self, aux)
    105 	struct device *parent, *self;
    106 	void *aux;
    107 {
    108 	struct cgsix_softc *sc = (struct cgsix_softc *)self;
    109 	struct sbusdev *sd = &((struct cgsix_sbus_softc *)self)->bss_sd;
    110 	struct sbus_attach_args *sa = aux;
    111 	struct fbdevice *fb = &sc->sc_fb;
    112 	int node, isconsole;
    113 	char *name;
    114 	bus_space_handle_t bh;
    115 
    116 	/* Remember cookies for cgsix_mmap() */
    117 	sc->sc_bustag = sa->sa_bustag;
    118 	sc->sc_btype = (bus_type_t)sa->sa_slot; /* Should be deprecated */
    119 	sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset);
    120 
    121 	node = sa->sa_node;
    122 
    123 	fb->fb_device = &sc->sc_dev;
    124 	fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR;
    125 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
    126 	fb->fb_type.fb_depth = 8;
    127 
    128 	fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
    129 
    130 	/*
    131 	 * Dunno what the PROM has mapped, though obviously it must have
    132 	 * the video RAM mapped.  Just map what we care about for ourselves
    133 	 * (the FHC, THC, and Brooktree registers).
    134 	 */
    135 	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    136 			 sa->sa_offset + CGSIX_BT_OFFSET,
    137 			 sizeof(*sc->sc_bt),
    138 			 BUS_SPACE_MAP_LINEAR,
    139 			 0, &bh) != 0) {
    140 		printf("%s: cannot map brooktree registers\n", self->dv_xname);
    141 		return;
    142 	}
    143 	sc->sc_bt = (struct bt_regs *)(u_long)bh;
    144 
    145 	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    146 			 sa->sa_offset + CGSIX_FHC_OFFSET,
    147 			 sizeof(*sc->sc_fhc),
    148 			 BUS_SPACE_MAP_LINEAR,
    149 			 0, &bh) != 0) {
    150 		printf("%s: cannot map FHC registers\n", self->dv_xname);
    151 		return;
    152 	}
    153 	sc->sc_fhc = (int *)(u_long)bh;
    154 
    155 	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    156 			 sa->sa_offset + CGSIX_THC_OFFSET,
    157 			 sizeof(*sc->sc_thc),
    158 			 BUS_SPACE_MAP_LINEAR,
    159 			 0, &bh) != 0) {
    160 		printf("%s: cannot map THC registers\n", self->dv_xname);
    161 		return;
    162 	}
    163 	sc->sc_thc = (struct cg6_thc *)(u_long)bh;
    164 
    165 	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    166 			 sa->sa_offset + CGSIX_TEC_OFFSET,
    167 			 sizeof(*sc->sc_tec),
    168 			 BUS_SPACE_MAP_LINEAR,
    169 			 0, &bh) != 0) {
    170 		printf("%s: cannot map TEC registers\n", self->dv_xname);
    171 		return;
    172 	}
    173 	sc->sc_tec = (struct cg6_tec_xxx *)(u_long)bh;
    174 
    175 	if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    176 			 sa->sa_offset + CGSIX_FBC_OFFSET,
    177 			 sizeof(*sc->sc_fbc),
    178 			 BUS_SPACE_MAP_LINEAR,
    179 			 0, &bh) != 0) {
    180 		printf("%s: cannot map FBC registers\n", self->dv_xname);
    181 		return;
    182 	}
    183 	sc->sc_fbc = (struct cg6_fbc *)(u_long)bh;
    184 
    185 	sbus_establish(sd, &sc->sc_dev);
    186 	name = PROM_getpropstring(node, "model");
    187 
    188 	isconsole = fb_is_console(node);
    189 	if (isconsole && cgsix_use_rasterconsole) {
    190 		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
    191 		if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
    192 				 sa->sa_offset + CGSIX_RAM_OFFSET,
    193 				 ramsize,
    194 				 BUS_SPACE_MAP_LINEAR,
    195 				 0, &bh) != 0) {
    196 			printf("%s: cannot map pixels\n", self->dv_xname);
    197 			return;
    198 		}
    199 		sc->sc_fb.fb_pixels = (caddr_t)(u_long)bh;
    200 	}
    201 
    202 	cg6attach(sc, name, isconsole);
    203 }
    204