Home | History | Annotate | Line # | Download | only in sbus
cgthree_sbus.c revision 1.21.14.1
      1  1.21.14.1       jym /*	$NetBSD: cgthree_sbus.c,v 1.21.14.1 2009/05/13 17:21:22 jym 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  *
     19        1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.1        pk  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.1        pk  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.1        pk  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.1        pk  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.1        pk  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.1        pk  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.1        pk  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.1        pk  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.1        pk  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.1        pk  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1        pk  */
     31        1.1        pk 
     32        1.1        pk /*
     33        1.1        pk  * Copyright (c) 1992, 1993
     34        1.1        pk  *	The Regents of the University of California.  All rights reserved.
     35        1.1        pk  *
     36        1.1        pk  * This software was developed by the Computer Systems Engineering group
     37        1.1        pk  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     38        1.1        pk  * contributed to Berkeley.
     39        1.1        pk  *
     40        1.1        pk  * All advertising materials mentioning features or use of this software
     41        1.1        pk  * must display the following acknowledgement:
     42        1.1        pk  *	This product includes software developed by the University of
     43        1.1        pk  *	California, Lawrence Berkeley Laboratory.
     44        1.1        pk  *
     45        1.1        pk  * Redistribution and use in source and binary forms, with or without
     46        1.1        pk  * modification, are permitted provided that the following conditions
     47        1.1        pk  * are met:
     48        1.1        pk  * 1. Redistributions of source code must retain the above copyright
     49        1.1        pk  *    notice, this list of conditions and the following disclaimer.
     50        1.1        pk  * 2. Redistributions in binary form must reproduce the above copyright
     51        1.1        pk  *    notice, this list of conditions and the following disclaimer in the
     52        1.1        pk  *    documentation and/or other materials provided with the distribution.
     53       1.13       agc  * 3. Neither the name of the University nor the names of its contributors
     54        1.1        pk  *    may be used to endorse or promote products derived from this software
     55        1.1        pk  *    without specific prior written permission.
     56        1.1        pk  *
     57        1.1        pk  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     58        1.1        pk  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     59        1.1        pk  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     60        1.1        pk  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     61        1.1        pk  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     62        1.1        pk  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     63        1.1        pk  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     64        1.1        pk  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     65        1.1        pk  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     66        1.1        pk  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     67        1.1        pk  * SUCH DAMAGE.
     68        1.1        pk  *
     69        1.1        pk  *	@(#)cgthree.c	8.2 (Berkeley) 10/30/93
     70        1.1        pk  */
     71        1.1        pk 
     72        1.1        pk /*
     73        1.1        pk  * color display (cgthree) driver.
     74        1.1        pk  *
     75        1.1        pk  * Does not handle interrupts, even though they can occur.
     76        1.1        pk  *
     77        1.1        pk  * XXX should defer colormap updates to vertical retrace interrupts
     78        1.1        pk  */
     79        1.5     lukem 
     80        1.5     lukem #include <sys/cdefs.h>
     81  1.21.14.1       jym __KERNEL_RCSID(0, "$NetBSD: cgthree_sbus.c,v 1.21.14.1 2009/05/13 17:21:22 jym Exp $");
     82        1.1        pk 
     83        1.1        pk #include <sys/param.h>
     84        1.1        pk #include <sys/systm.h>
     85        1.1        pk #include <sys/buf.h>
     86        1.1        pk #include <sys/device.h>
     87        1.1        pk #include <sys/ioctl.h>
     88        1.1        pk #include <sys/malloc.h>
     89        1.1        pk #include <sys/mman.h>
     90        1.1        pk #include <sys/tty.h>
     91        1.1        pk #include <sys/conf.h>
     92        1.1        pk 
     93       1.19        ad #include <sys/bus.h>
     94        1.1        pk #include <machine/autoconf.h>
     95        1.1        pk 
     96        1.1        pk #include <dev/sun/fbio.h>
     97        1.1        pk #include <dev/sun/fbvar.h>
     98        1.1        pk 
     99        1.1        pk #include <dev/sun/btreg.h>
    100        1.1        pk #include <dev/sun/btvar.h>
    101        1.1        pk #include <dev/sun/cgthreereg.h>
    102        1.1        pk #include <dev/sun/cgthreevar.h>
    103        1.1        pk 
    104        1.1        pk #include <dev/sbus/sbusvar.h>
    105        1.1        pk 
    106        1.1        pk /* Allocate an `sbusdev' in addition to the cgthree softc */
    107        1.1        pk struct cgthree_sbus_softc {
    108        1.1        pk 	struct cgthree_softc bss_softc;
    109        1.1        pk 	struct sbusdev bss_sd;
    110        1.1        pk };
    111        1.1        pk 
    112        1.1        pk 
    113        1.1        pk /* autoconfiguration driver */
    114  1.21.14.1       jym static int	cgthreematch_sbus(device_t, cfdata_t, void *);
    115  1.21.14.1       jym static void	cgthreeattach_sbus(device_t, device_t, void *);
    116        1.1        pk 
    117       1.10   thorpej CFATTACH_DECL(cgthree_sbus, sizeof(struct cgthree_softc),
    118       1.11   thorpej     cgthreematch_sbus, cgthreeattach_sbus, NULL, NULL);
    119        1.1        pk 
    120        1.1        pk /*
    121        1.1        pk  * Match a cgthree.
    122        1.1        pk  */
    123        1.1        pk int
    124  1.21.14.1       jym cgthreematch_sbus(device_t parent, cfdata_t cf, void *aux)
    125        1.1        pk {
    126        1.1        pk 	struct sbus_attach_args *sa = aux;
    127        1.1        pk 
    128        1.8   thorpej 	return (strcmp(cf->cf_name, sa->sa_name) == 0);
    129        1.1        pk }
    130        1.1        pk 
    131        1.1        pk /*
    132        1.1        pk  * Attach a display.  We need to notice if it is the console, too.
    133        1.1        pk  */
    134        1.1        pk void
    135  1.21.14.1       jym cgthreeattach_sbus(device_t parent, device_t self, void *args)
    136        1.1        pk {
    137        1.1        pk 	struct cgthree_softc *sc = (struct cgthree_softc *)self;
    138        1.1        pk 	struct sbusdev *sd = &((struct cgthree_sbus_softc *)self)->bss_sd;
    139        1.1        pk 	struct sbus_attach_args *sa = args;
    140        1.1        pk 	struct fbdevice *fb = &sc->sc_fb;
    141        1.1        pk 	int node = sa->sa_node;
    142        1.1        pk 	int isconsole;
    143       1.15   tsutsui 	const char *name;
    144        1.1        pk 	bus_space_handle_t bh;
    145        1.1        pk 
    146        1.1        pk 	/* Remember cookies for cgthree_mmap() */
    147        1.1        pk 	sc->sc_bustag = sa->sa_bustag;
    148        1.2       eeh 	sc->sc_paddr = sbus_bus_addr(sa->sa_bustag, sa->sa_slot, sa->sa_offset);
    149        1.1        pk 
    150        1.1        pk 	fb->fb_device = &sc->sc_dev;
    151       1.17   thorpej 	fb->fb_flags = device_cfdata(&sc->sc_dev)->cf_flags & FB_USERMASK;
    152        1.1        pk 	fb->fb_type.fb_type = FBTYPE_SUN3COLOR;
    153        1.1        pk 
    154        1.1        pk 	fb->fb_type.fb_depth = 8;
    155        1.1        pk 	fb_setsize_obp(fb, fb->fb_type.fb_depth, 1152, 900, node);
    156        1.1        pk 
    157        1.1        pk 	/*
    158        1.1        pk 	 * When the ROM has mapped in a cgthree display, the address
    159        1.1        pk 	 * maps only the video RAM, so in any case we have to map the
    160        1.1        pk 	 * registers ourselves.  We only need the video RAM if we are
    161        1.1        pk 	 * going to print characters via rconsole.
    162        1.1        pk 	 */
    163        1.6        pk 	if (sbus_bus_map(sa->sa_bustag,
    164        1.6        pk 			 sa->sa_slot,
    165        1.1        pk 			 sa->sa_offset + CG3REG_REG,
    166        1.1        pk 			 sizeof(struct fbcontrol),
    167        1.6        pk 			 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    168       1.20    cegger 		aprint_error_dev(self, "cannot map control registers\n");
    169        1.1        pk 		return;
    170        1.1        pk 	}
    171       1.12    martin 	sc->sc_fbc = (struct fbcontrol *)bus_space_vaddr(sa->sa_bustag, bh);
    172        1.1        pk 
    173        1.1        pk 	isconsole = fb_is_console(node);
    174       1.14        pk 	name = prom_getpropstring(node, "model");
    175        1.7     soren 	if (name == NULL)
    176        1.7     soren 		name = "cgthree";
    177        1.1        pk 
    178        1.1        pk 	if (sa->sa_npromvaddrs != 0)
    179       1.18  christos 		fb->fb_pixels = (void *)(u_long)sa->sa_promvaddrs[0];
    180        1.1        pk 	if (isconsole && fb->fb_pixels == NULL) {
    181        1.1        pk 		int ramsize = fb->fb_type.fb_height * fb->fb_linebytes;
    182        1.6        pk 		if (sbus_bus_map(sa->sa_bustag,
    183        1.6        pk 				 sa->sa_slot,
    184        1.1        pk 				 sa->sa_offset + CG3REG_MEM,
    185        1.1        pk 				 ramsize,
    186        1.6        pk 				 BUS_SPACE_MAP_LINEAR, &bh) != 0) {
    187       1.20    cegger 			aprint_error_dev(self, "cannot map pixels\n");
    188        1.1        pk 			return;
    189        1.1        pk 		}
    190       1.12    martin 		fb->fb_pixels = (char *)bus_space_vaddr(sa->sa_bustag, bh);
    191        1.1        pk 	}
    192        1.1        pk 
    193        1.1        pk 	sbus_establish(sd, &sc->sc_dev);
    194        1.1        pk 	cgthreeattach(sc, name, isconsole);
    195        1.1        pk }
    196