Home | History | Annotate | Line # | Download | only in pci
igsfb_pci.c revision 1.4
      1 /*	$NetBSD: igsfb_pci.c,v 1.4 2002/09/24 18:17:25 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.4 2002/09/24 18:17:25 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 #ifdef __sparc__  /* XXX: this doesn't belong here */
     45 #include <machine/autoconf.h>
     46 #endif
     47 #include <machine/bus.h>
     48 #include <machine/intr.h>
     49 
     50 #include <dev/pci/pcivar.h>
     51 #include <dev/pci/pcireg.h>
     52 #include <dev/pci/pcidevs.h>
     53 
     54 #include <dev/wscons/wsconsio.h>
     55 #include <dev/ic/igsfbreg.h>
     56 #include <dev/ic/igsfbvar.h>
     57 
     58 
     59 static int	igsfb_pci_match(struct device *, struct cfdata *, void *);
     60 static void	igsfb_pci_attach(struct device *, struct device *, void *);
     61 
     62 const struct cfattach igsfb_pci_ca = {
     63 	sizeof(struct igsfb_softc), igsfb_pci_match, igsfb_pci_attach,
     64 };
     65 
     66 
     67 static int
     68 igsfb_pci_match(parent, match, aux)
     69 	struct device *parent;
     70 	struct cfdata *match;
     71 	void *aux;
     72 {
     73 	struct pci_attach_args *pa = aux;
     74 
     75 	if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEGRAPHICS)
     76 		return (0);
     77 
     78 	/* probably can drive iga1680 and cyberpro cards as well */
     79 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
     80 		return (1);
     81 
     82 	if (PCI_PRODUCT(pa->pa_id) == 0x2000) /* XXX */
     83 		return (1);
     84 
     85 	return (0);
     86 }
     87 
     88 
     89 /*
     90  * Note, that the chip may still be not enabled (e.g. JavaStation PROM
     91  * doesn't bother to init the chip if PROM output goes to serial).
     92  */
     93 static void
     94 igsfb_pci_attach(parent, self, aux)
     95 	struct device *parent, *self;
     96 	void *aux;
     97 {
     98 	struct igsfb_softc *sc = (struct igsfb_softc *)self;
     99 	struct pci_attach_args *pa = aux;
    100 	bus_addr_t iobase;
    101 	int ioflags;
    102 	int isconsole;
    103 	char devinfo[256];
    104 
    105 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
    106 	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
    107 
    108 	if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
    109 		sc->sc_is2k = 0;
    110 	else
    111 		sc->sc_is2k = 1;
    112 
    113 	/*
    114 	 * Configure memory space first since for CyberPro we use
    115 	 * memory-mapped i/o access.  Note that we are NOT mapping any
    116 	 * of it yet.  (XXX: search for memory BAR?)
    117 	 */
    118 #define IGS_MEM_MAPREG (PCI_MAPREG_START + 0)
    119 
    120 	sc->sc_memt = pa->pa_memt;
    121 	if (pci_mapreg_info(pa->pa_pc, pa->pa_tag,
    122 		IGS_MEM_MAPREG, PCI_MAPREG_TYPE_MEM,
    123 		&sc->sc_memaddr, &sc->sc_memsz, &sc->sc_memflags) != 0)
    124 	{
    125 		printf("unable to configure memory space\n");
    126 		return;
    127 	}
    128 
    129 	/*
    130 	 * Configure I/O space.  On CyberPro use MMIO.  IGS 168x
    131 	 * doesn't have a BAR for its i/o, so we have to hardcode it.
    132 	 */
    133 	if (sc->sc_is2k) {
    134 		sc->sc_iot = sc->sc_memt;
    135 		iobase = IGS_MEM_MMIO_SELECT | sc->sc_memaddr;
    136 		ioflags = sc->sc_memflags;
    137 		printf("mem = 0x%08x, io = 0x%08x\n",
    138 		       (u_int32_t)sc->sc_memaddr,
    139 		       (u_int32_t)iobase);
    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 	/*
    161 	 * Enable the chip.
    162 	 *
    163 	 * XXX: for CyberPro sc->sc_iot is actually MMIO.  Make sure
    164 	 * that the card responds to memory cycles first?
    165 	 */
    166 	if (igsfb_enable(sc->sc_iot) != 0)
    167 		return;
    168 
    169 #ifdef __arm__ /* XXX: uwe: netwinder */
    170 	/*
    171 	 * On Netwinder the card is absolutely out of whack.
    172 	 * Program the registers to bring the card into a usable state.
    173 	 * On Krups we rely on OFW to program the card correctly
    174 	 * (XXX: re-check the case when the console is on serial).
    175 	 */
    176 	igsfb_hw_setup(sc);
    177 #endif
    178 
    179 	/*
    180 	 * TODO: Map graphic coprocessor registers.  not sure if this
    181 	 * needs to be done in bus glue or can be moved to common
    182 	 * attach code.
    183 	 */
    184 
    185 
    186 	isconsole = 0;
    187 #ifdef __arm__
    188 	isconsole = 1;		/* XXX */
    189 #endif
    190 
    191 #ifdef __sparc__  /* XXX: this doesn't belong here */
    192 	if (PCITAG_NODE(pa->pa_tag) == prom_instance_to_package(prom_stdout()))
    193 		isconsole = 1;
    194 #endif
    195 
    196 	igsfb_common_attach(sc, isconsole);
    197 }
    198