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