Home | History | Annotate | Line # | Download | only in obio
grf_obio.c revision 1.25
      1 /*	$NetBSD: grf_obio.c,v 1.25 1997/10/08 19:54:04 briggs 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/dev/nubus.h>
     53 #include <mac68k/dev/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 caddr_t	grfiv_phys __P((struct grf_softc *gp));
     64 static int	grfiv_match __P((struct device *, struct cfdata *, void *));
     65 static void	grfiv_attach __P((struct device *, struct device *, void *));
     66 
     67 struct cfdriver intvid_cd = {
     68 	NULL, "intvid", DV_DULL
     69 };
     70 
     71 struct cfattach intvid_ca = {
     72 	sizeof(struct grfbus_softc), grfiv_match, grfiv_attach
     73 };
     74 
     75 #define QUADRA_DAFB_BASE	0xF9800000
     76 #define CIVIC_CONTROL_BASE	0x50036000
     77 
     78 static int
     79 grfiv_match(parent, cf, aux)
     80 	struct device *parent;
     81 	struct cfdata *cf;
     82 	void *aux;
     83 {
     84 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
     85 	bus_space_handle_t bsh;
     86 	int found, sense;
     87 
     88 	found = 1;
     89 
     90         switch (current_mac_model->class) {
     91 	case MACH_CLASSQ:
     92 	case MACH_CLASSQ2:
     93 		/*
     94 		 * Assume DAFB for all of these, unless we can't
     95 		 * access the memory.
     96 		 */
     97 
     98 		if (bus_space_map(oa->oa_tag, QUADRA_DAFB_BASE, 0x1000,
     99 					0, &bsh)) {
    100 			panic("failed to map space for DAFB regs.\n");
    101 		}
    102 
    103 		if (bus_probe(oa->oa_tag, bsh, 0x1C, 4) == 0) {
    104 			bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    105 			found = 0;
    106 			goto nodafb;
    107 		}
    108 
    109 		sense = (bus_space_read_4(oa->oa_tag, bsh, 0x1C) & 7);
    110 
    111 		if (sense == 0)
    112 			found = 0;
    113 
    114 		/* Set "Turbo SCSI" configuration to default */
    115 		bus_space_write_4(oa->oa_tag, bsh, 0x24, 0x1d1); /* ch0 */
    116 		bus_space_write_4(oa->oa_tag, bsh, 0x28, 0x1d1); /* ch1 */
    117 
    118 		/* Disable interrupts */
    119 		bus_space_write_4(oa->oa_tag, bsh, 0x104, 0);
    120 
    121 		/* Clear any interrupts */
    122 		bus_space_write_4(oa->oa_tag, bsh, 0x10C, 0);
    123 		bus_space_write_4(oa->oa_tag, bsh, 0x110, 0);
    124 		bus_space_write_4(oa->oa_tag, bsh, 0x114, 0);
    125 
    126 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    127 		break;
    128 
    129         case MACH_CLASSAV:
    130 		if (bus_space_map(oa->oa_tag, CIVIC_CONTROL_BASE, 0x1000,
    131 					0, &bsh)) {
    132 			panic("failed to map space for CIVIC control regs.\n");
    133 		}
    134 		/* Disable interrupts */
    135 		bus_space_write_1(oa->oa_tag, bsh, 0x120, 0);
    136 		bus_space_unmap(oa->oa_tag, bsh, 0x1000);
    137 		break;
    138 
    139 	default:
    140 nodafb:
    141 		if (mac68k_vidlog == 0) {
    142 			found = 0;
    143 		}
    144 		break;
    145 	}
    146 
    147 	return found;
    148 }
    149 
    150 #define R4(sc, o) (bus_space_read_4((sc)->sc_tag, (sc)->sc_regh, o) & 0xfff)
    151 
    152 static void
    153 grfiv_attach(parent, self, aux)
    154 	struct device *parent, *self;
    155 	void   *aux;
    156 {
    157 	struct obio_attach_args *oa = (struct obio_attach_args *)aux;
    158 	struct grfbus_softc *sc;
    159 	struct grfmode *gm;
    160 
    161 	sc = (struct grfbus_softc *)self;
    162 
    163 	sc->card_id = 0;
    164 
    165         switch (current_mac_model->class) {
    166         case MACH_CLASSQ:
    167         case MACH_CLASSQ2:
    168 		sc->sc_tag = oa->oa_tag;
    169 		if (bus_space_map(sc->sc_tag, QUADRA_DAFB_BASE, 0x1000,
    170 					0, &sc->sc_regh)) {
    171 			panic("failed to map space for DAFB regs.\n");
    172 		}
    173 		printf(": DAFB: Monitor sense %x.\n", R4(sc,0x1C)&7);
    174 		bus_space_unmap(sc->sc_tag, sc->sc_regh, 0x1000);
    175 		break;
    176 	default:
    177 		printf(": Internal Video\n");
    178 		break;
    179 	}
    180 
    181 	gm = &(sc->curr_mode);
    182 	gm->mode_id = 0;
    183 	gm->psize = videobitdepth;
    184 	gm->ptype = 0;
    185 	gm->width = videosize & 0xffff;
    186 	gm->height = (videosize >> 16) & 0xffff;
    187 	gm->rowbytes = videorowbytes;
    188 	gm->hres = 80;		/* XXX Hack */
    189 	gm->vres = 80;		/* XXX Hack */
    190 	gm->fbsize = gm->rowbytes * gm->height;
    191 	gm->fbbase = (caddr_t)m68k_trunc_page(mac68k_vidlog);
    192 	gm->fboff = mac68k_vidlog & PGOFSET;
    193 
    194 	/* Perform common video attachment. */
    195 	grf_establish(sc, NULL, grfiv_mode, grfiv_phys);
    196 }
    197 
    198 static int
    199 grfiv_mode(sc, cmd, arg)
    200 	struct grf_softc *sc;
    201 	int cmd;
    202 	void *arg;
    203 {
    204 	switch (cmd) {
    205 	case GM_GRFON:
    206 	case GM_GRFOFF:
    207 		return 0;
    208 	case GM_CURRMODE:
    209 		break;
    210 	case GM_NEWMODE:
    211 		break;
    212 	case GM_LISTMODES:
    213 		break;
    214 	}
    215 	return EINVAL;
    216 }
    217 
    218 static caddr_t
    219 grfiv_phys(gp)
    220 	struct grf_softc *gp;
    221 {
    222 	/*
    223 	 * If we're using IIsi or similar, this will be 0.
    224 	 * If we're using IIvx or similar, this will be correct.
    225 	 */
    226 	return (caddr_t)mac68k_vidphys;
    227 }
    228