]> CyberLeo.Net >> Repos - FreeBSD/releng/7.2.git/blob - sys/dev/ieee488/pcii.c
Create releng/7.2 from stable/7 in preparation for 7.2-RELEASE.
[FreeBSD/releng/7.2.git] / sys / dev / ieee488 / pcii.c
1 /*-
2  * Copyright (c) 2005 Poul-Henning Kamp <phk@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
13  *
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
24  * SUCH DAMAGE.
25  *
26  * Driver for GPIB cards based on NEC µPD7210 and compatibles.
27  *
28  * This driver just hooks up to the hardware and leaves all the interesting
29  * stuff to upd7210.c.
30  *
31  * Supported hardware:
32  *    PCIIA compatible cards.
33  *
34  *    Tested and known working:
35  *      "B&C Microsystems PC488A-0"
36  *
37  */
38
39 #include <sys/cdefs.h>
40 __FBSDID("$FreeBSD$");
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/lock.h>
45 #include <sys/mutex.h>
46 #include <sys/kernel.h>
47 #include <sys/module.h>
48 #include <sys/bus.h>
49 #include <machine/bus.h>
50 #include <machine/resource.h>
51 #include <sys/rman.h>
52 #include <isa/isavar.h>
53
54 #define UPD7210_HW_DRIVER
55 #include <dev/ieee488/upd7210.h>
56
57 struct pcii_softc {
58         int foo;
59         struct resource *res[3];
60         void *intr_handler;
61         struct upd7210  upd7210;
62 };
63
64 static devclass_t pcii_devclass;
65
66 static int      pcii_probe(device_t dev);
67 static int      pcii_attach(device_t dev);
68
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),
74
75         { 0, 0 }
76 };
77
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},
82         { -1, 0, 0 }
83 };
84
85 static driver_t pcii_driver = {
86         "pcii",
87         pcii_methods,
88         sizeof(struct pcii_softc),
89 };
90
91 static int
92 pcii_probe(device_t dev)
93 {
94         int rid, i, j;
95         u_long start, count;
96         int error = 0;
97         struct pcii_softc *sc;
98
99         device_set_desc(dev, "PCII IEEE-4888 controller");
100         sc = device_get_softc(dev);
101
102         rid = 0;
103         if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
104                 return ENXIO;
105         if ((start & 0x3ff) != 0x2e1)
106                 return (ENXIO);
107         count = 1;
108         if (bus_set_resource(dev, SYS_RES_IOPORT, rid, start, count) != 0)
109                 return ENXIO;
110         error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
111         if (error)
112                 return (error);
113         error = ENXIO;
114         for (i = 0; i < 8; i++) {
115                 j = bus_read_1(sc->res[2], i * 0x400);
116                 if (j != 0x00 && j != 0xff)
117                         error = 0;
118         }
119         if (!error) {
120                 bus_write_1(sc->res[2], 3 * 0x400, 0x55);
121                 if (bus_read_1(sc->res[2], 3 * 0x400) != 0x55)
122                         error = ENXIO;
123         }
124         if (!error) {
125                 bus_write_1(sc->res[2], 3 * 0x400, 0xaa);
126                 if (bus_read_1(sc->res[2], 3 * 0x400) != 0xaa)
127                         error = ENXIO;
128         }
129         bus_release_resources(dev, pcii_res_spec, sc->res);
130         return (error);
131 }
132
133 static int
134 pcii_attach(device_t dev)
135 {
136         struct pcii_softc *sc;
137         int             unit;
138         int             rid;
139         int             error = 0;
140
141         unit = device_get_unit(dev);
142         sc = device_get_softc(dev);
143         memset(sc, 0, sizeof *sc);
144
145         device_set_desc(dev, "PCII IEEE-4888 controller");
146
147         error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
148         if (error)
149                 return (error);
150
151         error = bus_setup_intr(dev, sc->res[0],
152             INTR_TYPE_MISC | INTR_MPSAFE, NULL,
153             upd7210intr, &sc->upd7210, &sc->intr_handler);
154         if (error) {
155                 bus_release_resources(dev, pcii_res_spec, sc->res);
156                 return (error);
157         }
158
159         for (rid = 0; rid < 8; rid++) {
160                 sc->upd7210.reg_res[rid] = sc->res[2];
161                 sc->upd7210.reg_offset[rid] = 0x400 * rid;
162         }
163
164         if (sc->res[1] == NULL)
165                 sc->upd7210.dmachan = -1;
166         else
167                 sc->upd7210.dmachan = rman_get_start(sc->res[1]);
168
169         upd7210attach(&sc->upd7210);
170         return (error);
171 }
172
173 DRIVER_MODULE(pcii, isa, pcii_driver, pcii_devclass, 0, 0);
174 DRIVER_MODULE(pcii, acpi, pcii_driver, pcii_devclass, 0, 0);