2 * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
3 * based on work by Slawa Olhovchenkov
4 * John Prince <johnp@knight-trosoft.com>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
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 AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
37 #include <sys/module.h>
40 #include <machine/bus.h>
42 #include <machine/resource.h>
45 #include <dev/pci/pcivar.h>
47 #include <sys/digiio.h>
48 #include <dev/digi/digireg.h>
49 #include <dev/digi/digi.h>
50 #include <dev/digi/digi_pci.h>
53 digi_pci_setwin(struct digi_softc *sc, unsigned int addr)
55 return (sc->vmem + addr);
59 digi_pci_hidewin(struct digi_softc *sc)
65 digi_pci_towin(struct digi_softc *sc, int win)
71 digi_pci_probe(device_t dev)
73 unsigned int device_id = pci_get_devid(dev);
75 if (device_get_unit(dev) >= 16) {
76 /* Don't overflow our control mask */
77 device_printf(dev, "At most 16 digiboards may be used\n");
81 if ((device_id & 0xffff) != PCI_VENDOR_DIGI)
84 switch (device_id >> 16) {
91 case PCI_DEVICE_920_4:
92 case PCI_DEVICE_920_8:
93 case PCI_DEVICE_920_2:
94 return (BUS_PROBE_DEFAULT);
101 digi_pci_attach(device_t dev)
103 struct digi_softc *sc;
105 #ifdef DIGI_INTERRUPT
109 sc = device_get_softc(dev);
110 KASSERT(sc, ("digi%d: softc not allocated in digi_pci_attach\n",
111 device_get_unit(dev)));
113 bzero(sc, sizeof(*sc));
115 sc->res.unit = device_get_unit(dev);
117 device_id = pci_get_devid(dev);
118 switch (device_id >> 16) {
120 sc->name = "Digiboard PCI EPC/X ASIC";
123 sc->module = "EPCX_PCI";
126 sc->name = "Digiboard PCI PC/Xem ASIC";
132 sc->name = "Digiboard PCI PC/Xr ASIC";
138 sc->name = "Digiboard PCI C/X ASIC";
141 sc->module = "CX_PCI";
144 sc->name = "Digiboard PCI PC/Xr PLX";
149 case PCI_DEVICE_EPCJ:
150 sc->name = "Digiboard PCI EPC/X PLX";
153 sc->module = "EPCX_PCI";
155 case PCI_DEVICE_920_4: /* Digi PCI4r 920 */
156 sc->name = "Digiboard PCI4r 920";
161 case PCI_DEVICE_920_8: /* Digi PCI8r 920 */
162 sc->name = "Digiboard PCI8r 920";
167 case PCI_DEVICE_920_2: /* Digi PCI2r 920 */
168 sc->name = "Digiboard PCI2r 920";
174 device_printf(dev, "Unknown device id = %08x\n", device_id);
178 pci_write_config(dev, 0x40, 0, 4);
179 pci_write_config(dev, 0x46, 0, 4);
181 sc->res.mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->res.mrid,
184 #ifdef DIGI_INTERRUPT
186 sc->res.irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->res.irqrid,
187 RF_SHAREABLE | RF_ACTIVE);
188 if (sc->res.irq == NULL) {
189 device_printf(dev, "couldn't map interrupt\n");
192 retVal = bus_setup_intr(dev, sc->res.irq, INTR_TYPE_TTY,
193 digiintr, sc, &sc->res.irqHandler);
195 DLOG(DIGIDB_IRQ, (sc->dev, "Interrupt support compiled out\n"));
198 sc->vmem = rman_get_virtual(sc->res.mem);
199 sc->pmem = vtophys(sc->vmem);
201 sc->win_size = 0x200000;
203 sc->csigs = &digi_normal_signals;
204 sc->status = DIGI_STATUS_NOTINIT;
205 callout_handle_init(&sc->callout);
206 callout_handle_init(&sc->inttest);
207 sc->setwin = digi_pci_setwin;
208 sc->hidewin = digi_pci_hidewin;
209 sc->towin = digi_pci_towin;
213 return (digi_attach(sc));
216 static device_method_t digi_pci_methods[] = {
217 /* Device interface */
218 DEVMETHOD(device_probe, digi_pci_probe),
219 DEVMETHOD(device_attach, digi_pci_attach),
220 DEVMETHOD(device_detach, digi_detach),
221 DEVMETHOD(device_shutdown, digi_shutdown),
226 static driver_t digi_pci_drv = {
229 sizeof(struct digi_softc),
231 DRIVER_MODULE(digi, pci, digi_pci_drv, digi_devclass, 0, 0);