Home | History | Annotate | Line # | Download | only in obio
grf_obio.c revision 1.34
      1 /*	$NetBSD: grf_obio.c,v 1.34 1998/06/02 03:21:42 scottr Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1995 Allen Briggs.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Allen Briggs.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 /*
     32  * Graphics display driver for the Macintosh internal video for machines
     33  * that don't map it into a fake nubus card.
     34  */
     35 
     36 #include <sys/param.h>
     37 
     38 #include <sys/device.h>
     39 #include <sys/ioctl.h>
     40 #include <sys/file.h>
     41 #include <sys/malloc.h>
     42 #include <sys/mman.h>
     43 #include <sys/proc.h>
     44 #include <sys/systm.h>
     45 
     46 #include <machine/autoconf.h>
     47 #include <machine/bus.h>
     48 #include <machine/cpu.h>
     49 #include <machine/grfioctl.h>
     50 #include <machine/viareg.h>
     51 
     52 #include <mac68k/nubus/nubus.h>
     53 #include <mac68k/obio/obiovar.h>
     54 #include <mac68k/dev/grfvar.h>
     55 
     56 extern u_int32_t	mac68k_vidlog;
     57 extern u_int32_t	mac68k_vidphys;
     58 extern long		videorowbytes;
     59 extern long		videobitdepth;
     60 extern u_long		videosize;
     61 
     62 static int	grfiv_mode __P((struct grf_softc *gp, int cmd, void *arg));
     63 static int	grfiv_match __P((struct device *, struct cfdata *, void *));
     64 static void	grfiv_attach __P((struct device *, struct device *, void *));
     65 
     66 struct cfattach intvid_ca = {
     67 	sizeof(struct grfbus_softc), grfiv_match, grfiv_attach
     68 };
     69 
     70 #define QUADRA_DAFB_BASE	0xf9800000
     71 #define CIVIC_CONTROL_BASE	0x50036000
     72 #define VALKYRIE_CONTROL_BASE	0x50f2a000
     73 
     74 static int
     75 grfiv_match(parent, cf, aux)
     76 	struct device *parent;
     77 	struct cfdata *cf;
     78 	void *aux;
     79 {
     80 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
     81 	bus_space_handle_t bsh;
     82 	int found;
     83 	u_int base;
     84 
     85 	found = 1;
     86 
     87 	switch (current_mac_model->class) {
     88 	case MACH_CLASSQ:
     89 		/*
     90 		 * Assume DAFB for all of these, unless we can't
     91 		 * access the memory.
     92 		 */
     93 		base = QUADRA_DAFB_BASE;
     94 
     95 		if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh)) {
     96 			panic("failed to map space for DAFB regs.\n");
     97 		}
     98 
     99 		if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0x1C, 4) == 0) {
    100 			bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    101 			found = 0;
    102 			goto nodafb;
    103 		}
    104 
    105 		/* Set "Turbo SCSI" configuration to default */
    106 		bus_space_write_4(oa->oa_tag, bsh, 0x24, 0x1d1); /* ch0 */
    107 		bus_space_write_4(oa->oa_tag, bsh, 0x28, 0x1d1); /* ch1 */
    108 
    109 		/* Disable interrupts */
    110 		bus_space_write_4(oa->oa_tag, bsh, 0x104, 0);
    111 
    112 		/* Clear any interrupts */
    113 		bus_space_write_4(oa->oa_tag, bsh, 0x10C, 0);
    114 		bus_space_write_4(oa->oa_tag, bsh, 0x110, 0);
    115 		bus_space_write_4(oa->oa_tag, bsh, 0x114, 0);
    116 
    117 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    118 		break;
    119 
    120 	case MACH_CLASSAV:
    121 		base = CIVIC_CONTROL_BASE;
    122 
    123 		if (bus_space_map(oa->oa_tag, base, 0x1000, 0, &bsh)) {
    124 			panic("failed to map space for CIVIC control regs.\n");
    125 		}
    126 
    127 		/* Disable interrupts */
    128 		bus_space_write_1(oa->oa_tag, bsh, 0x120, 0);
    129 
    130 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    131 		break;
    132 
    133 	case MACH_CLASSQ2:
    134 		if (current_mac_model->machineid == MACH_MACQ630) {
    135 			base = VALKYRIE_CONTROL_BASE;
    136 
    137 			if (bus_space_map(oa->oa_tag, base, 0x40, 0, &bsh)) {
    138 				panic("failed to map space for Valkyrie regs.\n");
    139 			}
    140 
    141 			/* Disable interrupts */
    142 			bus_space_write_1(oa->oa_tag, bsh, 0x18, 0x1);
    143 		}
    144 		break;
    145 
    146 	default:
    147 nodafb:
    148 		if (mac68k_vidlog == 0) {
    149 			found = 0;
    150 		}
    151 		break;
    152 	}
    153 
    154 	return found;
    155 }
    156 
    157 #define R4(sc, o) (bus_space_read_4((sc)->sc_tag, (sc)->sc_regh, o) & 0xfff)
    158 
    159 static void
    160 grfiv_attach(parent, self, aux)
    161 	struct device *parent, *self;
    162 	void   *aux;
    163 {
    164 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    165 	struct grfbus_softc *sc;
    166 	struct grfmode *gm;
    167 	u_int base;
    168 
    169 	sc = (struct grfbus_softc *)self;
    170 
    171 	sc->card_id = 0;
    172 	sc->sc_bufpa = (caddr_t)mac68k_vidphys;
    173 
    174 	switch (current_mac_model->class) {
    175 	case MACH_CLASSQ:
    176 		base = QUADRA_DAFB_BASE;
    177 		sc->sc_tag = oa->oa_tag;
    178 		if (bus_space_map(sc->sc_tag, base, 0x1000, 0, &sc->sc_regh)) {
    179 			panic("failed to map space for DAFB regs.\n");
    180 		}
    181 		printf(": DAFB: Monitor sense %x.\n", R4(sc,0x1C)&7);
    182 		bus_space_unmap(sc->sc_tag, sc->sc_regh, 0x1000);
    183 		break;
    184 	case MACH_CLASSQ2:
    185 	case MACH_CLASSAV:
    186 	default:
    187 		printf(": Internal Video\n");
    188 		break;
    189 	}
    190 
    191 	gm = &(sc->curr_mode);
    192 	gm->mode_id = 0;
    193 	gm->psize = videobitdepth;
    194 	gm->ptype = 0;
    195 	gm->width = videosize & 0xffff;
    196 	gm->height = (videosize >> 16) & 0xffff;
    197 	gm->rowbytes = videorowbytes;
    198 	gm->hres = 80;		/* XXX Hack */
    199 	gm->vres = 80;		/* XXX Hack */
    200 	gm->fbsize = gm->rowbytes * gm->height;
    201 	gm->fbbase = (caddr_t)m68k_trunc_page(mac68k_vidlog);
    202 	gm->fboff = mac68k_vidlog & PGOFSET;
    203 
    204 	/* Perform common video attachment. */
    205 	grf_establish(sc, NULL, grfiv_mode);
    206 }
    207 
    208 static int
    209 grfiv_mode(sc, cmd, arg)
    210 	struct grf_softc *sc;
    211 	int cmd;
    212 	void *arg;
    213 {
    214 	switch (cmd) {
    215 	case GM_GRFON:
    216 	case GM_GRFOFF:
    217 		return 0;
    218 	case GM_CURRMODE:
    219 		break;
    220 	case GM_NEWMODE:
    221 		break;
    222 	case GM_LISTMODES:
    223 		break;
    224 	}
    225 	return EINVAL;
    226 }
    227