2 * Copyright (c) 2005 Poul-Henning Kamp <phk@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * Driver for GPIB cards based on NEC µPD7210 and compatibles.
28 * This driver just hooks up to the hardware and leaves all the interesting
32 * PCIIA compatible cards.
34 * Tested and known working:
35 * "B&C Microsystems PC488A-0"
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
42 #include <sys/param.h>
43 #include <sys/systm.h>
45 #include <sys/mutex.h>
46 #include <sys/kernel.h>
47 #include <sys/module.h>
49 #include <machine/bus.h>
50 #include <machine/resource.h>
52 #include <isa/isavar.h>
54 #define UPD7210_HW_DRIVER
55 #include <dev/ieee488/upd7210.h>
59 struct resource *res[2];
62 struct upd7210 upd7210;
65 static devclass_t pcii_devclass;
67 static int pcii_probe(device_t dev);
68 static int pcii_attach(device_t dev);
70 static device_method_t pcii_methods[] = {
71 DEVMETHOD(device_probe, pcii_probe),
72 DEVMETHOD(device_attach, pcii_attach),
73 DEVMETHOD(device_suspend, bus_generic_suspend),
74 DEVMETHOD(device_resume, bus_generic_resume),
79 static struct resource_spec pcii_res_spec[] = {
80 { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE},
81 { SYS_RES_DRQ, 0, RF_ACTIVE | RF_SHAREABLE | RF_OPTIONAL},
82 { SYS_RES_IOPORT, 0, RF_ACTIVE},
86 static driver_t pcii_driver = {
89 sizeof(struct pcii_softc),
93 pcii_probe(device_t dev)
98 struct pcii_softc *sc;
100 device_set_desc(dev, "PCII IEEE-4888 controller");
101 sc = device_get_softc(dev);
104 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
106 if ((start & 0x3ff) != 0x2e1)
109 if (bus_set_resource(dev, SYS_RES_IOPORT, rid, start, count) != 0)
111 error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
115 for (i = 0; i < 8; i++) {
116 j = bus_read_1(sc->res[2], i * 0x400);
117 if (j != 0x00 && j != 0xff)
121 bus_write_1(sc->res[2], 3 * 0x400, 0x55);
122 if (bus_read_1(sc->res[2], 3 * 0x400) != 0x55)
126 bus_write_1(sc->res[2], 3 * 0x400, 0xaa);
127 if (bus_read_1(sc->res[2], 3 * 0x400) != 0xaa)
130 bus_release_resources(dev, pcii_res_spec, sc->res);
135 pcii_attach(device_t dev)
137 struct pcii_softc *sc;
142 unit = device_get_unit(dev);
143 sc = device_get_softc(dev);
144 memset(sc, 0, sizeof *sc);
146 device_set_desc(dev, "PCII IEEE-4888 controller");
148 error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
152 error = bus_setup_intr(dev, sc->res[0],
153 INTR_TYPE_MISC | INTR_MPSAFE,
154 upd7210intr, &sc->upd7210, &sc->intr_handler);
156 bus_release_resources(dev, pcii_res_spec, sc->res);
160 for (rid = 0; rid < 8; rid++) {
161 sc->upd7210.reg_res[rid] = sc->res[2];
162 sc->upd7210.reg_offset[rid] = 0x400 * rid;
165 if (sc->res[1] == NULL)
166 sc->upd7210.dmachan = -1;
168 sc->upd7210.dmachan = rman_get_start(sc->res[1]);
170 upd7210attach(&sc->upd7210);
174 DRIVER_MODULE(pcii, isa, pcii_driver, pcii_devclass, 0, 0);
175 DRIVER_MODULE(pcii, acpi, pcii_driver, pcii_devclass, 0, 0);