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