Home | History | Annotate | Line # | Download | only in sbus
cgsix_sbus.c revision 1.7
      1 /*	$NetBSD: cgsix_sbus.c,v 1.7 2002/03/11 16:00:55 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; Sbus bus front-end.
     41  */
     42 
     43 #include <sys/cdefs.h>
     44 __KERNEL_RCSID(0, "$NetBSD: cgsix_sbus.c,v 1.7 2002/03/11 16:00:55 pk Exp $");
     45 
     46 #include <sys/param.h>
     47 #include <sys/systm.h>
     48 #include <sys/buf.h>
     49 #include <sys/device.h>
     50 #include <sys/ioctl.h>
     51 #include <sys/malloc.h>
     52 #include <sys/mman.h>
     53 #include <sys/tty.h>
     54 #include <sys/conf.h>
     55 
     56 #ifdef DEBUG
     57 #include <sys/proc.h>
     58 #include <sys/syslog.h>
     59 #endif
     60 
     61 #include <machine/bus.h>
     62 #include <machine/autoconf.h>
     63 
     64 #include <dev/sbus/sbusvar.h>
     65 
     66 #include <dev/sun/fbio.h>
     67 #include <dev/sun/fbvar.h>
     68 #include <dev/sun/btreg.h>
     69 #include <dev/sun/btvar.h>
     70 #include <dev/sun/cgsixreg.h>
     71 #include <dev/sun/cgsixvar.h>
     72 
     73 /* autoconfiguration driver */
     74 static int	cgsixmatch __P((struct device *, struct cfdata *, void *));
     75 static void	cgsixattach __P((struct device *, struct device *, void *));
     76 
     77 /* Allocate an `sbusdev' in addition to the cgsix softc */
     78 struct cgsix_sbus_softc {
     79 	struct cgsix_softc bss_softc;
     80 	struct sbusdev bss_sd;
     81 };
     82 
     83 struct cfattach cgsix_sbus_ca = {
     84 	sizeof(struct cgsix_sbus_softc), cgsixmatch, cgsixattach
     85 };
     86 
     87 
     88 /*
     89  * Match a cgsix.
     90  */
     91 int
     92 cgsixmatch(parent, cf, aux)
     93 	struct device *parent;
     94 	struct cfdata *cf;
     95 	void *aux;
     96 {
     97 	struct sbus_attach_args *sa = aux;
     98 
     99 	return (strcmp(cf->cf_driver->cd_name, sa->sa_name) == 0);
    100 }
    101 
    102 
    103 /*
    104  * Attach a cgsix.
    105  */
    106 void
    107 cgsixattach(parent, self, aux)
    108 	struct device *parent, *self;
    109 	void *aux;
    110 {
    111 	struct cgsix_softc *sc = (struct cgsix_softc *)self;
    112 	struct sbusdev *sd = &((struct cgsix_sbus_softc *)self)->bss_sd;
    113 	struct sbus_attach_args *sa = aux;
    114 	struct fbdevice *fb = &sc->sc_fb;
    115 	int node, isconsole;
    116 	char *name;
    117 	bus_space_handle_t bh;
    118 
    119 	/* Remember cookies for cgsix_mmap() */
    120 	sc->sc_bustag = sa->sa_bustag;
    121 	sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset);
    122 
    123 	node = sa->sa_node;
    124 
    125 	fb->fb_device = &sc->sc_dev;
    126 	fb->fb_type.fb_type = FBTYPE_SUNFAST_COLOR;
    127 	fb->fb_flags = sc->sc_dev.dv_cfdata->cf_flags & FB_USERMASK;
    128 	fb->fb_type.fb_depth = 8;
    129 
    130 	fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
    131 
    132 	/*
    133 	 * Dunno what the PROM has mapped, though obviously it must have
    134 	 * the video RAM mapped.  Just map what we care about for ourselves
    135 	 * (the FHC, THC, and Brooktree registers).
    136 	 */
    137 	if (sbus_bus_map(sa->sa_bustag,
    138 			 sa->sa_slot,
    139 			 sa->sa_offset + CGSIX_BT_OFFSET,
    140 			 sizeof(*sc->sc_bt),
    141 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    142 		printf("%s: cannot map brooktree registers\n", self->dv_xname);
    143 		return;
    144 	}
    145 	sc->sc_bt = (struct bt_regs *)(u_long)bh;
    146 
    147 	if (sbus_bus_map(sa->sa_bustag,
    148 			 sa->sa_slot,
    149 			 sa->sa_offset + CGSIX_FHC_OFFSET,
    150 			 sizeof(*sc->sc_fhc),
    151 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    152 		printf("%s: cannot map FHC registers\n", self->dv_xname);
    153 		return;
    154 	}
    155 	sc->sc_fhc = (int *)(u_long)bh;
    156 
    157 	if (sbus_bus_map(sa->sa_bustag,
    158 			 sa->sa_slot,
    159 			 sa->sa_offset + CGSIX_THC_OFFSET,
    160 			 sizeof(*sc->sc_thc),
    161 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    162 		printf("%s: cannot map THC registers\n", self->dv_xname);
    163 		return;
    164 	}
    165 	sc->sc_thc = (struct cg6_thc *)(u_long)bh;
    166 
    167 	if (sbus_bus_map(sa->sa_bustag,
    168 			 sa->sa_slot,
    169 			 sa->sa_offset + CGSIX_TEC_OFFSET,
    170 			 sizeof(*sc->sc_tec),
    171 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    172 		printf("%s: cannot map TEC registers\n", self->dv_xname);
    173 		return;
    174 	}
    175 	sc->sc_tec = (struct cg6_tec_xxx *)(u_long)bh;
    176 
    177 	if (sbus_bus_map(sa->sa_bustag,
    178 			 sa->sa_slot,
    179 			 sa->sa_offset + CGSIX_FBC_OFFSET,
    180 			 sizeof(*sc->sc_fbc),
    181 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    182 		printf("%s: cannot map FBC registers\n", self->dv_xname);
    183 		return;
    184 	}
    185 	sc->sc_fbc = (struct cg6_fbc *)(u_long)bh;
    186 
    187 	sbus_establish(sd, &sc->sc_dev);
    188 	name = PROM_getpropstring(node, "model");
    189 
    190 	isconsole = fb_is_console(node);
    191 	if (isconsole && cgsix_use_rasterconsole) {
    192 		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
    193 		if (sbus_bus_map(sa->sa_bustag,
    194 				 sa->sa_slot,
    195 				 sa->sa_offset + CGSIX_RAM_OFFSET,
    196 				 ramsize,
    197 				 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    198 			printf("%s: cannot map pixels\n", self->dv_xname);
    199 			return;
    200 		}
    201 		sc->sc_fb.fb_pixels = (caddr_t)(u_long)bh;
    202 	}
    203 
    204 	cg6attach(sc, name, isconsole);
    205 }
    206