Home | History | Annotate | Line # | Download | only in pci
igsfb_pci.c revision 1.3
      1 /*	$NetBSD: igsfb_pci.c,v 1.3 2002/07/21 02:56:35 uwe Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2002 Valeriy E. Ushakov
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. The name of the author may not be used to endorse or promote products
     16  *    derived from this software without specific prior written permission
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 /*
     31  * Integraphics Systems IGA 168x and CyberPro series.
     32  * Only tested on IGA 1682 in Krups JavaStation-NC.
     33  */
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: igsfb_pci.c,v 1.3 2002/07/21 02:56:35 uwe Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/kernel.h>
     40 #include <sys/device.h>
     41 #include <sys/malloc.h>
     42 #include <sys/buf.h>
     43 
     44 #include <machine/autoconf.h>
     45 #include <machine/bus.h>
     46 #include <machine/intr.h>
     47 
     48 #include <dev/pci/pcivar.h>
     49 #include <dev/pci/pcireg.h>
     50 #include <dev/pci/pcidevs.h>
     51 
     52 #include <dev/wscons/wsconsio.h>
     53 #include <dev/ic/igsfbreg.h>
     54 #include <dev/ic/igsfbvar.h>
     55 
     56 
     57 static int	igsfb_pci_match(struct device *, struct cfdata *, void *);
     58 static void	igsfb_pci_attach(struct device *, struct device *, void *);
     59 
     60 const struct cfattach igsfb_pci_ca = {
     61 	sizeof(struct igsfb_softc), igsfb_pci_match, igsfb_pci_attach,
     62 };
     63 
     64 
     65 static int
     66 igsfb_pci_match(parent, match, aux)
     67 	struct device *parent;
     68 	struct cfdata *match;
     69 	void *aux;
     70 {
     71 	struct pci_attach_args *pa = aux;
     72 
     73 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEGRAPHICS)
     74 		return (0);
     75 
     76 	/* probably can drive iga1680 and cyberpro cards as well */
     77 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
     78 		return (1);
     79 
     80 	return (0);
     81 }
     82 
     83 
     84 /*
     85  * Note, that the chip may still be not enabled (e.g. JavaStation PROM
     86  * doesn't bother to init the chip if PROM output goes to serial).
     87  */
     88 static void
     89 igsfb_pci_attach(parent, self, aux)
     90 	struct device *parent, *self;
     91 	void *aux;
     92 {
     93 	struct igsfb_softc *sc = (struct igsfb_softc *)self;
     94 	struct pci_attach_args *pa = aux;
     95 	bus_addr_t iobase;
     96 	int ioflags;
     97 	int isconsole;
     98 	char devinfo[256];
     99 
    100 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    101 	printf(": %s, revision 0x%02x\n", devinfo, PCI_REVISION(pa->pa_class));
    102 
    103 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
    104 		sc->sc_is2k = 0;
    105 	else
    106 		sc->sc_is2k = 1;
    107 
    108 	/*
    109 	 * Enable the chip.  This always goes through i/o space
    110 	 * because that's the only way that is guaranteed to enable
    111 	 * completely uninitialized card.
    112 	 */
    113 	if (igsfb_enable(pa->pa_iot) != 0)
    114 		return;
    115 
    116 	/*
    117 	 * Configure memory space first since for CyberPro we use
    118 	 * memory-mapped i/o access.  Note that we are NOT mapping any
    119 	 * of it yet.  (XXX: search for memory BAR)
    120 	 */
    121 #define IGS_MEM_MAPREG (PCI_MAPREG_START + 0)
    122 
    123 	sc->sc_memt = pa->pa_memt;
    124 	if (pci_mapreg_info(pa->pa_pc, pa->pa_tag,
    125 		IGS_MEM_MAPREG, PCI_MAPREG_TYPE_MEM,
    126 		&sc->sc_memaddr, &sc->sc_memsz, &sc->sc_memflags) != 0)
    127 	{
    128 		printf("unable to configure memory space\n");
    129 		return;
    130 	}
    131 
    132 	/*
    133 	 * Configure I/O space.  On CyberPro use MMIO.  IGS 168x
    134 	 * doesn't have a BAR for its i/o, so we have to hardcode it.
    135 	 */
    136 	if (sc->sc_is2k) {
    137 		sc->sc_iot = sc->sc_memt;
    138 		iobase = IGS_MEM_MMIO_SELECT | sc->sc_memaddr;
    139 		ioflags = sc->sc_memflags;
    140 	} else {
    141 		/* feh, 1682 config denies having io space registers */
    142 		sc->sc_iot = pa->pa_iot;
    143 		iobase = 0;
    144 		ioflags = 0;
    145 	}
    146 
    147 	/*
    148 	 * Map I/O registers.  This is done in bus glue, not in common
    149 	 * code because on e.g. ISA bus we'd need to access registers
    150 	 * to obtain/program linear memory location.
    151 	 */
    152 	if (bus_space_map(sc->sc_iot,
    153 			  iobase + IGS_REG_BASE, IGS_REG_SIZE, ioflags,
    154 			  &sc->sc_ioh) != 0)
    155 	{
    156 		printf("unable to map I/O registers\n");
    157 		return;
    158 	}
    159 
    160 	/* TODO: Map CRTC???  This simple driver doesn't use it so far. */
    161 
    162 	/*
    163 	 * TODO: Map graphic coprocessor registers.  not sure if this
    164 	 * needs to be done in bus glue or can be moved to common
    165 	 * attach code.
    166 	 */
    167 
    168 	isconsole = 0;
    169 #ifdef __sparc__  /* XXX: this doesn't belong here */
    170 	if (PCITAG_NODE(pa->pa_tag) == prom_instance_to_package(prom_stdout()))
    171 		isconsole = 1;
    172 #endif
    173 
    174 	igsfb_common_attach(sc, isconsole);
    175 }
    176