2002-10-02 20:51:16 +04:00
|
|
|
/* $NetBSD: igsfb_pci.c,v 1.6 2002/10/02 16:51:38 thorpej Exp $ */
|
2002-03-30 22:48:55 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Valeriy E. Ushakov
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2002-07-21 06:56:35 +04:00
|
|
|
* Integraphics Systems IGA 168x and CyberPro series.
|
|
|
|
* Only tested on IGA 1682 in Krups JavaStation-NC.
|
2002-03-30 22:48:55 +03:00
|
|
|
*/
|
|
|
|
#include <sys/cdefs.h>
|
2002-10-02 20:51:16 +04:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: igsfb_pci.c,v 1.6 2002/10/02 16:51:38 thorpej Exp $");
|
2002-03-30 22:48:55 +03:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
|
2002-09-24 22:17:24 +04:00
|
|
|
#ifdef __sparc__ /* XXX: this doesn't belong here */
|
2002-03-30 22:48:55 +03:00
|
|
|
#include <machine/autoconf.h>
|
2002-09-24 22:17:24 +04:00
|
|
|
#endif
|
2002-03-30 22:48:55 +03:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/intr.h>
|
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcidevs.h>
|
|
|
|
|
|
|
|
#include <dev/wscons/wsconsio.h>
|
|
|
|
#include <dev/ic/igsfbreg.h>
|
|
|
|
#include <dev/ic/igsfbvar.h>
|
|
|
|
|
|
|
|
|
|
|
|
static int igsfb_pci_match(struct device *, struct cfdata *, void *);
|
|
|
|
static void igsfb_pci_attach(struct device *, struct device *, void *);
|
|
|
|
|
2002-10-01 00:37:04 +04:00
|
|
|
CFATTACH_DECL(igsfb_pci, sizeof(struct igsfb_softc),
|
2002-10-02 20:51:16 +04:00
|
|
|
igsfb_pci_match, igsfb_pci_attach, NULL, NULL);
|
2002-03-30 22:48:55 +03:00
|
|
|
|
|
|
|
static int
|
|
|
|
igsfb_pci_match(parent, match, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *match;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
|
|
|
|
if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEGRAPHICS)
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
/* probably can drive iga1680 and cyberpro cards as well */
|
|
|
|
if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
|
|
|
|
return (1);
|
|
|
|
|
2002-09-24 22:17:24 +04:00
|
|
|
if (PCI_PRODUCT(pa->pa_id) == 0x2000) /* XXX */
|
|
|
|
return (1);
|
|
|
|
|
2002-03-30 22:48:55 +03:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note, that the chip may still be not enabled (e.g. JavaStation PROM
|
|
|
|
* doesn't bother to init the chip if PROM output goes to serial).
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
igsfb_pci_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
|
|
|
{
|
|
|
|
struct igsfb_softc *sc = (struct igsfb_softc *)self;
|
|
|
|
struct pci_attach_args *pa = aux;
|
|
|
|
bus_addr_t iobase;
|
|
|
|
int ioflags;
|
|
|
|
int isconsole;
|
|
|
|
char devinfo[256];
|
|
|
|
|
|
|
|
pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
|
2002-09-24 22:17:24 +04:00
|
|
|
printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
|
2002-03-30 22:48:55 +03:00
|
|
|
|
|
|
|
if (PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_INTEGRAPHICS_IGA1682)
|
|
|
|
sc->sc_is2k = 0;
|
|
|
|
else
|
|
|
|
sc->sc_is2k = 1;
|
|
|
|
|
|
|
|
/*
|
2002-07-21 06:56:35 +04:00
|
|
|
* Configure memory space first since for CyberPro we use
|
|
|
|
* memory-mapped i/o access. Note that we are NOT mapping any
|
2002-09-24 22:17:24 +04:00
|
|
|
* of it yet. (XXX: search for memory BAR?)
|
2002-03-30 22:48:55 +03:00
|
|
|
*/
|
|
|
|
#define IGS_MEM_MAPREG (PCI_MAPREG_START + 0)
|
|
|
|
|
|
|
|
sc->sc_memt = pa->pa_memt;
|
|
|
|
if (pci_mapreg_info(pa->pa_pc, pa->pa_tag,
|
|
|
|
IGS_MEM_MAPREG, PCI_MAPREG_TYPE_MEM,
|
|
|
|
&sc->sc_memaddr, &sc->sc_memsz, &sc->sc_memflags) != 0)
|
|
|
|
{
|
|
|
|
printf("unable to configure memory space\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2002-07-21 06:56:35 +04:00
|
|
|
* Configure I/O space. On CyberPro use MMIO. IGS 168x
|
|
|
|
* doesn't have a BAR for its i/o, so we have to hardcode it.
|
2002-03-30 22:48:55 +03:00
|
|
|
*/
|
2002-07-21 06:56:35 +04:00
|
|
|
if (sc->sc_is2k) {
|
2002-03-30 22:48:55 +03:00
|
|
|
sc->sc_iot = sc->sc_memt;
|
2002-07-21 06:56:35 +04:00
|
|
|
iobase = IGS_MEM_MMIO_SELECT | sc->sc_memaddr;
|
2002-03-30 22:48:55 +03:00
|
|
|
ioflags = sc->sc_memflags;
|
2002-09-24 22:17:24 +04:00
|
|
|
printf("mem = 0x%08x, io = 0x%08x\n",
|
|
|
|
(u_int32_t)sc->sc_memaddr,
|
|
|
|
(u_int32_t)iobase);
|
2002-03-30 22:48:55 +03:00
|
|
|
} else {
|
2002-07-21 06:56:35 +04:00
|
|
|
/* feh, 1682 config denies having io space registers */
|
2002-03-30 22:48:55 +03:00
|
|
|
sc->sc_iot = pa->pa_iot;
|
2002-04-04 22:50:28 +04:00
|
|
|
iobase = 0;
|
2002-03-30 22:48:55 +03:00
|
|
|
ioflags = 0;
|
|
|
|
}
|
|
|
|
|
2002-07-21 06:56:35 +04:00
|
|
|
/*
|
|
|
|
* Map I/O registers. This is done in bus glue, not in common
|
|
|
|
* code because on e.g. ISA bus we'd need to access registers
|
|
|
|
* to obtain/program linear memory location.
|
|
|
|
*/
|
|
|
|
if (bus_space_map(sc->sc_iot,
|
|
|
|
iobase + IGS_REG_BASE, IGS_REG_SIZE, ioflags,
|
2002-03-30 22:48:55 +03:00
|
|
|
&sc->sc_ioh) != 0)
|
|
|
|
{
|
2002-07-21 06:56:35 +04:00
|
|
|
printf("unable to map I/O registers\n");
|
2002-03-30 22:48:55 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-09-24 22:17:24 +04:00
|
|
|
/*
|
|
|
|
* Enable the chip.
|
|
|
|
*
|
|
|
|
* XXX: for CyberPro sc->sc_iot is actually MMIO. Make sure
|
|
|
|
* that the card responds to memory cycles first?
|
|
|
|
*/
|
|
|
|
if (igsfb_enable(sc->sc_iot) != 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
#ifdef __arm__ /* XXX: uwe: netwinder */
|
|
|
|
/*
|
|
|
|
* On Netwinder the card is absolutely out of whack.
|
|
|
|
* Program the registers to bring the card into a usable state.
|
|
|
|
* On Krups we rely on OFW to program the card correctly
|
|
|
|
* (XXX: re-check the case when the console is on serial).
|
|
|
|
*/
|
|
|
|
igsfb_hw_setup(sc);
|
|
|
|
#endif
|
2002-03-30 22:48:55 +03:00
|
|
|
|
2002-07-21 06:56:35 +04:00
|
|
|
/*
|
|
|
|
* TODO: Map graphic coprocessor registers. not sure if this
|
|
|
|
* needs to be done in bus glue or can be moved to common
|
|
|
|
* attach code.
|
|
|
|
*/
|
2002-03-30 22:48:55 +03:00
|
|
|
|
2002-09-24 22:17:24 +04:00
|
|
|
|
2002-07-21 06:56:35 +04:00
|
|
|
isconsole = 0;
|
2002-09-24 22:17:24 +04:00
|
|
|
#ifdef __arm__
|
|
|
|
isconsole = 1; /* XXX */
|
|
|
|
#endif
|
|
|
|
|
2002-07-21 06:56:35 +04:00
|
|
|
#ifdef __sparc__ /* XXX: this doesn't belong here */
|
2002-03-30 22:48:55 +03:00
|
|
|
if (PCITAG_NODE(pa->pa_tag) == prom_instance_to_package(prom_stdout()))
|
|
|
|
isconsole = 1;
|
2002-07-21 06:56:35 +04:00
|
|
|
#endif
|
2002-03-30 22:48:55 +03:00
|
|
|
|
|
|
|
igsfb_common_attach(sc, isconsole);
|
|
|
|
}
|