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[3];
61 struct upd7210 upd7210;
64 static devclass_t pcii_devclass;
66 static int pcii_probe(device_t dev);
67 static int pcii_attach(device_t dev);
69 static device_method_t pcii_methods[] = {
70 DEVMETHOD(device_probe, pcii_probe),
71 DEVMETHOD(device_attach, pcii_attach),
72 DEVMETHOD(device_suspend, bus_generic_suspend),
73 DEVMETHOD(device_resume, bus_generic_resume),
78 static struct resource_spec pcii_res_spec[] = {
79 { SYS_RES_IRQ, 0, RF_ACTIVE | RF_SHAREABLE},
80 { SYS_RES_DRQ, 0, RF_ACTIVE | RF_SHAREABLE | RF_OPTIONAL},
81 { SYS_RES_IOPORT, 0, RF_ACTIVE},
85 static driver_t pcii_driver = {
88 sizeof(struct pcii_softc),
92 pcii_probe(device_t dev)
97 struct pcii_softc *sc;
99 device_set_desc(dev, "PCII IEEE-4888 controller");
100 sc = device_get_softc(dev);
103 if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
105 if ((start & 0x3ff) != 0x2e1)
108 if (bus_set_resource(dev, SYS_RES_IOPORT, rid, start, count) != 0)
110 error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
114 for (i = 0; i < 8; i++) {
115 j = bus_read_1(sc->res[2], i * 0x400);
116 if (j != 0x00 && j != 0xff)
120 bus_write_1(sc->res[2], 3 * 0x400, 0x55);
121 if (bus_read_1(sc->res[2], 3 * 0x400) != 0x55)
125 bus_write_1(sc->res[2], 3 * 0x400, 0xaa);
126 if (bus_read_1(sc->res[2], 3 * 0x400) != 0xaa)
129 bus_release_resources(dev, pcii_res_spec, sc->res);
134 pcii_attach(device_t dev)
136 struct pcii_softc *sc;
141 unit = device_get_unit(dev);
142 sc = device_get_softc(dev);
143 memset(sc, 0, sizeof *sc);
145 device_set_desc(dev, "PCII IEEE-4888 controller");
147 error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
151 error = bus_setup_intr(dev, sc->res[0],
152 INTR_TYPE_MISC | INTR_MPSAFE, NULL,
153 upd7210intr, &sc->upd7210, &sc->intr_handler);
155 bus_release_resources(dev, pcii_res_spec, sc->res);
159 for (rid = 0; rid < 8; rid++) {
160 sc->upd7210.reg_res[rid] = sc->res[2];
161 sc->upd7210.reg_offset[rid] = 0x400 * rid;
164 if (sc->res[1] == NULL)
165 sc->upd7210.dmachan = -1;
167 sc->upd7210.dmachan = rman_get_start(sc->res[1]);
169 upd7210attach(&sc->upd7210);
173 DRIVER_MODULE(pcii, isa, pcii_driver, pcii_devclass, 0, 0);
174 DRIVER_MODULE(pcii, acpi, pcii_driver, pcii_devclass, 0, 0);