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 unmodified, this list of conditions, and the following
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
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>
70 #include <sys/malloc.h>
72 #include <machine/bus.h>
73 #include <machine/resource.h>
76 #include <dev/pci/pcireg.h>
77 #include <dev/pci/pcivar.h>
79 #define PUC_ENTRAILS 1
80 #include <dev/puc/pucvar.h>
83 puc_pci_probe(device_t dev)
85 uint32_t v1, v2, d1, d2;
86 const struct puc_device_description *desc;
88 if ((pci_read_config(dev, PCIR_HEADERTYPE, 1) & 0x7f) != 0)
91 v1 = pci_read_config(dev, PCIR_VENDOR, 2);
92 d1 = pci_read_config(dev, PCIR_DEVICE, 2);
93 v2 = pci_read_config(dev, PCIR_SUBVEND_0, 2);
94 d2 = pci_read_config(dev, PCIR_SUBDEV_0, 2);
96 desc = puc_find_description(v1, d1, v2, d2);
99 device_set_desc(dev, desc->name);
104 puc_pci_attach(device_t dev)
106 uint32_t v1, v2, d1, d2;
108 v1 = pci_read_config(dev, PCIR_VENDOR, 2);
109 d1 = pci_read_config(dev, PCIR_DEVICE, 2);
110 v2 = pci_read_config(dev, PCIR_SUBVEND_0, 2);
111 d2 = pci_read_config(dev, PCIR_SUBDEV_0, 2);
112 return (puc_attach(dev, puc_find_description(v1, d1, v2, d2)));
115 static device_method_t puc_pci_methods[] = {
116 /* Device interface */
117 DEVMETHOD(device_probe, puc_pci_probe),
118 DEVMETHOD(device_attach, puc_pci_attach),
120 DEVMETHOD(bus_alloc_resource, puc_alloc_resource),
121 DEVMETHOD(bus_release_resource, puc_release_resource),
122 DEVMETHOD(bus_get_resource, puc_get_resource),
123 DEVMETHOD(bus_read_ivar, puc_read_ivar),
124 DEVMETHOD(bus_setup_intr, puc_setup_intr),
125 DEVMETHOD(bus_teardown_intr, puc_teardown_intr),
126 DEVMETHOD(bus_print_child, bus_generic_print_child),
127 DEVMETHOD(bus_driver_added, bus_generic_driver_added),
131 static driver_t puc_pci_driver = {
134 sizeof(struct puc_softc),
137 DRIVER_MODULE(puc, pci, puc_pci_driver, puc_devclass, 0, 0);
138 DRIVER_MODULE(puc, cardbus, puc_pci_driver, puc_devclass, 0, 0);
141 #define rdspio(indx) (bus_space_write_1(bst, bsh, efir, indx), \
142 bus_space_read_1(bst, bsh, efdr))
143 #define wrspio(indx,data) (bus_space_write_1(bst, bsh, efir, indx), \
144 bus_space_write_1(bst, bsh, efdr, data))
148 puc_print_win877(bus_space_tag_t bst, bus_space_handle_t bsh, u_int efir,
151 u_char cr00, cr01, cr04, cr09, cr0d, cr14, cr15, cr16, cr17;
152 u_char cr18, cr19, cr24, cr25, cr28, cr2c, cr31, cr32;
171 printf("877T: cr00 %x, cr01 %x, cr04 %x, cr09 %x, cr0d %x, cr14 %x, "
172 "cr15 %x, cr16 %x, cr17 %x, cr18 %x, cr19 %x, cr24 %x, cr25 %x, "
173 "cr28 %x, cr2c %x, cr31 %x, cr32 %x\n", cr00, cr01, cr04, cr09,
174 cr0d, cr14, cr15, cr16, cr17,
175 cr18, cr19, cr24, cr25, cr28, cr2c, cr31, cr32);
180 puc_config_win877(struct puc_softc *sc)
185 bus_space_handle_t bsh;
186 struct resource *res;
188 res = sc->sc_bar_mappings[0].res;
190 bst = rman_get_bustag(res);
191 bsh = rman_get_bushandle(res);
193 /* configure the first W83877TF */
194 bus_space_write_1(bst, bsh, 0x250, 0x89);
197 val = rdspio(0x09) & 0x0f;
199 printf("conf_win877: Oops not a W83877TF\n");
205 puc_print_win877(bst, bsh, efir, efdr);
214 wrspio(0x24, 0x2e8 >> 2);
215 wrspio(0x25, 0x2f8 >> 2);
221 puc_print_win877(bst, bsh, efir, efdr);
224 bus_space_write_1(bst, bsh, 0x250, 0xaa);
226 /* configure the second W83877TF */
227 bus_space_write_1(bst, bsh, 0x3f0, 0x87);
228 bus_space_write_1(bst, bsh, 0x3f0, 0x87);
231 val = rdspio(0x09) & 0x0f;
233 printf("conf_win877: Oops not a W83877TF\n");
239 puc_print_win877(bst, bsh, efir, efdr);
248 wrspio(0x24, 0x3e8 >> 2);
249 wrspio(0x25, 0x3f8 >> 2);
255 puc_print_win877(bst, bsh, efir, efdr);
258 bus_space_write_1(bst, bsh, 0x3f0, 0xaa);