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