1 /* $NetBSD: puc.c,v 1.7 2000/07/29 17:43:38 jlam Exp $ */
4 * Copyright (c) 2002 JF Hay. All rights reserved.
5 * Copyright (c) 2000 M. Warner Losh. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * Copyright (c) 1996, 1998, 1999
31 * Christopher G. Demetriou. All rights reserved.
33 * Redistribution and use in source and binary forms, with or without
34 * modification, are permitted provided that the following conditions
36 * 1. Redistributions of source code must retain the above copyright
37 * notice, this list of conditions and the following disclaimer.
38 * 2. Redistributions in binary form must reproduce the above copyright
39 * notice, this list of conditions and the following disclaimer in the
40 * documentation and/or other materials provided with the distribution.
41 * 3. All advertising materials mentioning features or use of this software
42 * must display the following acknowledgement:
43 * This product includes software developed by Christopher G. Demetriou
44 * for the NetBSD Project.
45 * 4. The name of the author may not be used to endorse or promote products
46 * derived from this software without specific prior written permission
48 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
49 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
50 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
51 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
52 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
53 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
54 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
55 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
56 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
57 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
60 #include <sys/cdefs.h>
61 __FBSDID("$FreeBSD$");
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/kernel.h>
68 #include <sys/module.h>
71 #include <sys/malloc.h>
73 #include <machine/bus.h>
74 #include <machine/resource.h>
77 #include <dev/pci/pcireg.h>
78 #include <dev/pci/pcivar.h>
80 #define PUC_ENTRAILS 1
81 #include <dev/puc/pucvar.h>
83 extern const struct puc_device_description puc_devices[];
85 int puc_config_win877(struct puc_softc *);
87 static const struct puc_device_description *
88 puc_find_description(uint32_t vend, uint32_t prod, uint32_t svend,
93 #define checkreg(val, index) \
94 (((val) & puc_devices[i].rmask[(index)]) == puc_devices[i].rval[(index)])
96 for (i = 0; puc_devices[i].name != NULL; i++) {
97 if (checkreg(vend, PUC_REG_VEND) &&
98 checkreg(prod, PUC_REG_PROD) &&
99 checkreg(svend, PUC_REG_SVEND) &&
100 checkreg(sprod, PUC_REG_SPROD))
101 return (&puc_devices[i]);
110 puc_pci_probe(device_t dev)
112 uint32_t v1, v2, d1, d2;
113 const struct puc_device_description *desc;
115 if ((pci_read_config(dev, PCIR_HDRTYPE, 1) & PCIM_HDRTYPE) != 0)
118 v1 = pci_read_config(dev, PCIR_VENDOR, 2);
119 d1 = pci_read_config(dev, PCIR_DEVICE, 2);
120 v2 = pci_read_config(dev, PCIR_SUBVEND_0, 2);
121 d2 = pci_read_config(dev, PCIR_SUBDEV_0, 2);
123 desc = puc_find_description(v1, d1, v2, d2);
126 device_set_desc(dev, desc->name);
127 return (BUS_PROBE_DEFAULT);
131 puc_pci_attach(device_t dev)
133 uint32_t v1, v2, d1, d2;
135 v1 = pci_read_config(dev, PCIR_VENDOR, 2);
136 d1 = pci_read_config(dev, PCIR_DEVICE, 2);
137 v2 = pci_read_config(dev, PCIR_SUBVEND_0, 2);
138 d2 = pci_read_config(dev, PCIR_SUBDEV_0, 2);
139 return (puc_attach(dev, puc_find_description(v1, d1, v2, d2)));
142 static device_method_t puc_pci_methods[] = {
143 /* Device interface */
144 DEVMETHOD(device_probe, puc_pci_probe),
145 DEVMETHOD(device_attach, puc_pci_attach),
147 DEVMETHOD(bus_alloc_resource, puc_alloc_resource),
148 DEVMETHOD(bus_release_resource, puc_release_resource),
149 DEVMETHOD(bus_get_resource, puc_get_resource),
150 DEVMETHOD(bus_read_ivar, puc_read_ivar),
151 DEVMETHOD(bus_setup_intr, puc_setup_intr),
152 DEVMETHOD(bus_teardown_intr, puc_teardown_intr),
153 DEVMETHOD(bus_print_child, bus_generic_print_child),
154 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
158 static driver_t puc_pci_driver = {
161 sizeof(struct puc_softc),
164 DRIVER_MODULE(puc, pci, puc_pci_driver, puc_devclass, 0, 0);
165 DRIVER_MODULE(puc, cardbus, puc_pci_driver, puc_devclass, 0, 0);
168 #define rdspio(indx) (bus_space_write_1(bst, bsh, efir, indx), \
169 bus_space_read_1(bst, bsh, efdr))
170 #define wrspio(indx,data) (bus_space_write_1(bst, bsh, efir, indx), \
171 bus_space_write_1(bst, bsh, efdr, data))
175 puc_print_win877(bus_space_tag_t bst, bus_space_handle_t bsh, u_int efir,
178 u_char cr00, cr01, cr04, cr09, cr0d, cr14, cr15, cr16, cr17;
179 u_char cr18, cr19, cr24, cr25, cr28, cr2c, cr31, cr32;
198 printf("877T: cr00 %x, cr01 %x, cr04 %x, cr09 %x, cr0d %x, cr14 %x, "
199 "cr15 %x, cr16 %x, cr17 %x, cr18 %x, cr19 %x, cr24 %x, cr25 %x, "
200 "cr28 %x, cr2c %x, cr31 %x, cr32 %x\n", cr00, cr01, cr04, cr09,
201 cr0d, cr14, cr15, cr16, cr17,
202 cr18, cr19, cr24, cr25, cr28, cr2c, cr31, cr32);
207 puc_config_win877(struct puc_softc *sc)
212 bus_space_handle_t bsh;
213 struct resource *res;
215 res = sc->sc_bar_mappings[0].res;
217 bst = rman_get_bustag(res);
218 bsh = rman_get_bushandle(res);
220 /* configure the first W83877TF */
221 bus_space_write_1(bst, bsh, 0x250, 0x89);
224 val = rdspio(0x09) & 0x0f;
226 printf("conf_win877: Oops not a W83877TF\n");
232 puc_print_win877(bst, bsh, efir, efdr);
241 wrspio(0x24, 0x2e8 >> 2);
242 wrspio(0x25, 0x2f8 >> 2);
248 puc_print_win877(bst, bsh, efir, efdr);
251 bus_space_write_1(bst, bsh, 0x250, 0xaa);
253 /* configure the second W83877TF */
254 bus_space_write_1(bst, bsh, 0x3f0, 0x87);
255 bus_space_write_1(bst, bsh, 0x3f0, 0x87);
258 val = rdspio(0x09) & 0x0f;
260 printf("conf_win877: Oops not a W83877TF\n");
266 puc_print_win877(bst, bsh, efir, efdr);
275 wrspio(0x24, 0x3e8 >> 2);
276 wrspio(0x25, 0x3f8 >> 2);
282 puc_print_win877(bst, bsh, efir, efdr);
285 bus_space_write_1(bst, bsh, 0x3f0, 0xaa);