]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/ieee488/pcii.c
This commit was generated by cvs2svn to compensate for changes in r151497,
[FreeBSD/FreeBSD.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[2];
60         struct resource *dma;
61         void *intr_handler;
62         struct upd7210  upd7210;
63 };
64
65 static devclass_t pcii_devclass;
66
67 static int      pcii_probe(device_t dev);
68 static int      pcii_attach(device_t dev);
69
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),
75
76         { 0, 0 }
77 };
78
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},
83         { -1, 0, 0 }
84 };
85
86 static driver_t pcii_driver = {
87         "pcii",
88         pcii_methods,
89         sizeof(struct pcii_softc),
90 };
91
92 static int
93 pcii_probe(device_t dev)
94 {
95         int rid, i, j;
96         u_long start, count;
97         int error = 0;
98         struct pcii_softc *sc;
99
100         device_set_desc(dev, "PCII IEEE-4888 controller");
101         sc = device_get_softc(dev);
102
103         rid = 0;
104         if (bus_get_resource(dev, SYS_RES_IOPORT, rid, &start, &count) != 0)
105                 return ENXIO;
106         if ((start & 0x3ff) != 0x2e1)
107                 return (ENXIO);
108         count = 1;
109         if (bus_set_resource(dev, SYS_RES_IOPORT, rid, start, count) != 0)
110                 return ENXIO;
111         error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
112         if (error)
113                 return (error);
114         error = ENXIO;
115         for (i = 0; i < 8; i++) {
116                 j = bus_read_1(sc->res[2], i * 0x400);
117                 if (j != 0x00 && j != 0xff)
118                         error = 0;
119         }
120         if (!error) {
121                 bus_write_1(sc->res[2], 3 * 0x400, 0x55);
122                 if (bus_read_1(sc->res[2], 3 * 0x400) != 0x55)
123                         error = ENXIO;
124         }
125         if (!error) {
126                 bus_write_1(sc->res[2], 3 * 0x400, 0xaa);
127                 if (bus_read_1(sc->res[2], 3 * 0x400) != 0xaa)
128                         error = ENXIO;
129         }
130         bus_release_resources(dev, pcii_res_spec, sc->res);
131         return (error);
132 }
133
134 static int
135 pcii_attach(device_t dev)
136 {
137         struct pcii_softc *sc;
138         int             unit;
139         int             rid;
140         int             error = 0;
141
142         unit = device_get_unit(dev);
143         sc = device_get_softc(dev);
144         memset(sc, 0, sizeof *sc);
145
146         device_set_desc(dev, "PCII IEEE-4888 controller");
147
148         error = bus_alloc_resources(dev, pcii_res_spec, sc->res);
149         if (error)
150                 return (error);
151
152         error = bus_setup_intr(dev, sc->res[0],
153             INTR_TYPE_MISC | INTR_MPSAFE,
154             upd7210intr, &sc->upd7210, &sc->intr_handler);
155         if (error) {
156                 bus_release_resources(dev, pcii_res_spec, sc->res);
157                 return (error);
158         }
159
160         for (rid = 0; rid < 8; rid++) {
161                 sc->upd7210.reg_res[rid] = sc->res[2];
162                 sc->upd7210.reg_offset[rid] = 0x400 * rid;
163         }
164
165         if (sc->res[1] == NULL)
166                 sc->upd7210.dmachan = -1;
167         else
168                 sc->upd7210.dmachan = rman_get_start(sc->res[1]);
169
170         upd7210attach(&sc->upd7210);
171         return (error);
172 }
173
174 DRIVER_MODULE(pcii, isa, pcii_driver, pcii_devclass, 0, 0);
175 DRIVER_MODULE(pcii, acpi, pcii_driver, pcii_devclass, 0, 0);