2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 1999 Luoqi Chen.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
33 #include <sys/callout.h>
34 #include <sys/kernel.h>
36 #include <sys/module.h>
37 #include <sys/mutex.h>
40 #include <machine/bus.h>
41 #include <machine/resource.h>
44 #include <dev/aic/aicvar.h>
45 #include <dev/pccard/pccardvar.h>
48 #include "pccarddevs.h"
50 struct aic_pccard_softc {
51 struct aic_softc sc_aic;
52 struct resource *sc_port;
53 struct resource *sc_irq;
57 static int aic_pccard_alloc_resources(device_t);
58 static void aic_pccard_release_resources(device_t);
59 static int aic_pccard_probe(device_t);
60 static int aic_pccard_attach(device_t);
62 static const struct pccard_product aic_pccard_products[] = {
63 PCMCIA_CARD(ADAPTEC, APA1460),
64 PCMCIA_CARD(ADAPTEC, APA1460A),
65 PCMCIA_CARD(NEWMEDIA, BUSTOASTER),
66 PCMCIA_CARD(NEWMEDIA, BUSTOASTER2),
67 PCMCIA_CARD(NEWMEDIA, BUSTOASTER3),
71 #define AIC_PCCARD_PORTSIZE 0x20
74 aic_pccard_alloc_resources(device_t dev)
76 struct aic_pccard_softc *sc = device_get_softc(dev);
79 sc->sc_port = sc->sc_irq = NULL;
82 sc->sc_port = bus_alloc_resource_anywhere(dev, SYS_RES_IOPORT, &rid,
83 AIC_PCCARD_PORTSIZE, RF_ACTIVE);
88 sc->sc_irq = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid, RF_ACTIVE);
90 aic_pccard_release_resources(dev);
95 sc->sc_aic.res = sc->sc_port;
96 mtx_init(&sc->sc_aic.lock, "aic", NULL, MTX_DEF);
101 aic_pccard_release_resources(device_t dev)
103 struct aic_pccard_softc *sc = device_get_softc(dev);
106 bus_release_resource(dev, SYS_RES_IOPORT, 0, sc->sc_port);
108 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->sc_irq);
109 sc->sc_port = sc->sc_irq = NULL;
110 mtx_destroy(&sc->sc_aic.lock);
114 aic_pccard_probe(device_t dev)
116 const struct pccard_product *pp;
118 if ((pp = pccard_product_lookup(dev, aic_pccard_products,
119 sizeof(aic_pccard_products[0]), NULL)) != NULL) {
120 if (pp->pp_name != NULL)
121 device_set_desc(dev, pp->pp_name);
124 "Adaptec 6260/6360 SCSI controller");
125 return (BUS_PROBE_DEFAULT);
131 aic_pccard_attach(device_t dev)
133 struct aic_pccard_softc *sc = device_get_softc(dev);
134 struct aic_softc *aic = &sc->sc_aic;
137 if (aic_pccard_alloc_resources(dev))
139 if (aic_probe(aic)) {
140 aic_pccard_release_resources(dev);
144 error = aic_attach(aic);
146 device_printf(dev, "attach failed\n");
147 aic_pccard_release_resources(dev);
151 error = bus_setup_intr(dev, sc->sc_irq, INTR_TYPE_CAM | INTR_ENTROPY |
152 INTR_MPSAFE, NULL, aic_intr, aic, &sc->sc_ih);
154 device_printf(dev, "failed to register interrupt handler\n");
155 aic_pccard_release_resources(dev);
162 aic_pccard_detach(device_t dev)
164 struct aic_pccard_softc *sc = device_get_softc(dev);
165 struct aic_softc *aic = &sc->sc_aic;
168 error = bus_teardown_intr(dev, sc->sc_irq, sc->sc_ih);
170 device_printf(dev, "failed to unregister interrupt handler\n");
173 error = aic_detach(aic);
175 device_printf(dev, "detach failed\n");
179 aic_pccard_release_resources(dev);
183 static device_method_t aic_pccard_methods[] = {
184 /* Device interface */
185 DEVMETHOD(device_probe, aic_pccard_probe),
186 DEVMETHOD(device_attach, aic_pccard_attach),
187 DEVMETHOD(device_detach, aic_pccard_detach),
192 static driver_t aic_pccard_driver = {
194 aic_pccard_methods, sizeof(struct aic_pccard_softc),
197 extern devclass_t aic_devclass;
199 MODULE_DEPEND(aic, cam, 1,1,1);
200 DRIVER_MODULE(aic, pccard, aic_pccard_driver, aic_devclass, 0, 0);
201 PCCARD_PNP_INFO(aic_pccard_products);