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
29 * $FreeBSD: src/sys/dev/digi/digi_pci.c,v 1.9 2003/08/24 17:46:03 obrien Exp $
32 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
43 #include <bus/pci/pcivar.h>
45 #include <dev/serial/digi/digiio.h>
46 #include <dev/serial/digi/digireg.h>
47 #include <dev/serial/digi/digi.h>
48 #include <dev/serial/digi/digi_pci.h>
51 digi_pci_setwin(struct digi_softc *sc, unsigned int addr)
53 return (sc->vmem + addr);
57 digi_pci_hidewin(struct digi_softc *sc)
63 digi_pci_towin(struct digi_softc *sc, int win)
69 digi_pci_probe(device_t dev)
71 unsigned int device_id = pci_get_devid(dev);
73 if (device_get_unit(dev) >= 16) {
74 /* Don't overflow our control mask */
75 device_printf(dev, "At most 16 digiboards may be used\n");
79 if ((device_id & 0xffff) != PCI_VENDOR_DIGI)
82 switch (device_id >> 16) {
89 case PCI_DEVICE_920_4:
90 case PCI_DEVICE_920_8:
91 case PCI_DEVICE_920_2:
99 digi_pci_attach(device_t dev)
101 struct digi_softc *sc;
103 #ifdef DIGI_INTERRUPT
107 sc = device_get_softc(dev);
108 KASSERT(sc, ("digi%d: softc not allocated in digi_pci_attach",
109 device_get_unit(dev)));
111 bzero(sc, sizeof(*sc));
113 sc->res.unit = device_get_unit(dev);
115 device_id = pci_get_devid(dev);
116 switch (device_id >> 16) {
118 sc->name = "Digiboard PCI EPC/X ASIC";
121 sc->module = "EPCX_PCI";
124 sc->name = "Digiboard PCI PC/Xem ASIC";
130 sc->name = "Digiboard PCI PC/Xr ASIC";
136 sc->name = "Digiboard PCI C/X ASIC";
139 sc->module = "CX_PCI";
142 sc->name = "Digiboard PCI PC/Xr PLX";
147 case PCI_DEVICE_EPCJ:
148 sc->name = "Digiboard PCI EPC/X PLX";
151 sc->module = "EPCX_PCI";
153 case PCI_DEVICE_920_4: /* Digi PCI4r 920 */
154 sc->name = "Digiboard PCI4r 920";
159 case PCI_DEVICE_920_8: /* Digi PCI8r 920 */
160 sc->name = "Digiboard PCI8r 920";
165 case PCI_DEVICE_920_2: /* Digi PCI2r 920 */
166 sc->name = "Digiboard PCI2r 920";
172 device_printf(dev, "Unknown device id = %08x\n", device_id);
176 pci_write_config(dev, 0x40, 0, 4);
177 pci_write_config(dev, 0x46, 0, 4);
179 sc->res.mem = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->res.mrid,
180 0, ~0, 1, RF_ACTIVE);
182 #ifdef DIGI_INTERRUPT
184 sc->res.irq = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->res.irqrid,
185 0, ~0, 1, RF_SHAREABLE | RF_ACTIVE);
186 if (sc->res.irq == NULL) {
187 device_printf(dev, "couldn't map interrupt\n");
190 retVal = bus_setup_intr(dev, sc->res.irq, INTR_MPSAFE, digiintr, sc,
191 &sc->res.irqHandler, NULL);
193 DLOG(DIGIDB_IRQ, (sc->dev, "Interrupt support compiled out\n"));
196 sc->vmem = rman_get_virtual(sc->res.mem);
197 sc->pmem = vtophys(sc->vmem);
199 sc->win_size = 0x200000;
201 sc->csigs = &digi_normal_signals;
202 sc->status = DIGI_STATUS_NOTINIT;
203 callout_init(&sc->callout);
204 callout_init(&sc->inttest);
205 sc->setwin = digi_pci_setwin;
206 sc->hidewin = digi_pci_hidewin;
207 sc->towin = digi_pci_towin;
211 return (digi_attach(sc));
214 static device_method_t digi_pci_methods[] = {
215 /* Device interface */
216 DEVMETHOD(device_probe, digi_pci_probe),
217 DEVMETHOD(device_attach, digi_pci_attach),
218 DEVMETHOD(device_detach, digi_detach),
219 DEVMETHOD(device_shutdown, digi_shutdown),
223 static driver_t digi_pci_drv = {
226 sizeof(struct digi_softc),
228 DRIVER_MODULE(digi, pci, digi_pci_drv, digi_devclass, NULL, NULL);