1 /* $NecBSD: nsp_pisa.c,v 1.4 1999/04/15 01:35:54 kmatsuda Exp $ */
7 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
9 * [NetBSD for NEC PC-98 series]
11 * NetBSD/pc98 porting staff. All rights reserved.
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
28 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
32 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
40 #include <sys/param.h>
42 #include <sys/errno.h>
43 #include <sys/kernel.h>
44 #include <sys/malloc.h>
45 #include <sys/systm.h>
47 #include <machine/bus.h>
48 #include <machine/resource.h>
50 #include <compat/netbsd/dvcfg.h>
52 #include <sys/device_port.h>
54 #include <dev/pccard/pccardvar.h>
56 #include <cam/scsi/scsi_low.h>
57 #include <cam/scsi/scsi_low_pisa.h>
59 #include <dev/nsp/nspreg.h>
60 #include <dev/nsp/nspvar.h>
64 #include "pccarddevs.h"
66 #define PIO_MODE 0x100 /* pd_flags */
68 static int nspprobe(DEVPORT_PDEVICE devi);
69 static int nspattach(DEVPORT_PDEVICE devi);
71 static void nsp_card_unload (DEVPORT_PDEVICE);
73 const struct pccard_product nsp_products[] = {
74 PCMCIA_CARD(IODATA3, CBSC16),
75 PCMCIA_CARD(PANASONIC, KME),
76 PCMCIA_CARD(WORKBIT2, NINJA_SCSI3),
77 PCMCIA_CARD(WORKBIT, ULTRA_NINJA_16),
82 * Additional code for FreeBSD new-bus PCCard frontend
86 nsp_pccard_intr(void * arg)
92 nsp_release_resource(DEVPORT_PDEVICE dev)
94 struct nsp_softc *sc = device_get_softc(dev);
97 bus_teardown_intr(dev, sc->irq_res, sc->nsp_intrhand);
99 bus_release_resource(dev, SYS_RES_IOPORT,
100 sc->port_rid, sc->port_res);
102 bus_release_resource(dev, SYS_RES_IRQ,
103 sc->irq_rid, sc->irq_res);
105 bus_release_resource(dev, SYS_RES_MEMORY,
106 sc->mem_rid, sc->mem_res);
110 nsp_alloc_resource(DEVPORT_PDEVICE dev)
112 struct nsp_softc *sc = device_get_softc(dev);
113 u_long ioaddr, iosize, maddr, msize;
116 error = bus_get_resource(dev, SYS_RES_IOPORT, 0, &ioaddr, &iosize);
117 if (error || iosize < NSP_IOSIZE)
121 sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
122 0, ~0, NSP_IOSIZE, RF_ACTIVE);
123 if (sc->port_res == NULL) {
124 nsp_release_resource(dev);
129 sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid,
131 if (sc->irq_res == NULL) {
132 nsp_release_resource(dev);
136 error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
140 /* No need to allocate memory if not configured and it's in PIO mode */
141 if (maddr == 0 || msize == 0) {
142 if ((DEVPORT_PDEVFLAGS(dev) & PIO_MODE) == 0) {
143 printf("Memory window was not configured. Configure or use in PIO mode.");
144 nsp_release_resource(dev);
147 /* no need to allocate memory if PIO mode */
152 sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid,
154 if (sc->mem_res == NULL) {
155 nsp_release_resource(dev);
162 static int nsp_pccard_match(device_t dev)
164 const struct pccard_product *pp;
166 if ((pp = pccard_product_lookup(dev, nsp_products,
167 sizeof(nsp_products[0]), NULL)) != NULL) {
169 device_set_desc(dev, pp->pp_name);
176 nsp_pccard_probe(DEVPORT_PDEVICE dev)
180 error = nsp_alloc_resource(dev);
183 if (nspprobe(dev) == 0) {
184 nsp_release_resource(dev);
187 nsp_release_resource(dev);
193 nsp_pccard_attach(DEVPORT_PDEVICE dev)
195 struct nsp_softc *sc = device_get_softc(dev);
198 error = nsp_alloc_resource(dev);
201 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY,
202 nsp_pccard_intr, (void *)sc, &sc->nsp_intrhand);
204 nsp_release_resource(dev);
207 if (nspattach(dev) == 0) {
208 nsp_release_resource(dev);
216 nsp_pccard_detach(DEVPORT_PDEVICE dev)
218 nsp_card_unload(dev);
219 nsp_release_resource(dev);
222 static device_method_t nsp_pccard_methods[] = {
223 /* Device interface */
224 DEVMETHOD(device_probe, pccard_compat_probe),
225 DEVMETHOD(device_attach, pccard_compat_attach),
226 DEVMETHOD(device_detach, nsp_pccard_detach),
229 DEVMETHOD(card_compat_match, nsp_pccard_match),
230 DEVMETHOD(card_compat_probe, nsp_pccard_probe),
231 DEVMETHOD(card_compat_attach, nsp_pccard_attach),
236 static driver_t nsp_pccard_driver = {
239 sizeof(struct nsp_softc),
242 static devclass_t nsp_devclass;
244 MODULE_DEPEND(nsp, scsi_low, 1, 1, 1);
245 DRIVER_MODULE(nsp, pccard, nsp_pccard_driver, nsp_devclass, 0, 0);
248 nsp_card_unload(DEVPORT_PDEVICE devi)
250 struct nsp_softc *sc = DEVPORT_PDEVGET_SOFTC(devi);
254 scsi_low_deactivate((struct scsi_low_softc *)sc);
255 scsi_low_dettach(&sc->sc_sclow);
260 nspprobe(DEVPORT_PDEVICE devi)
263 struct nsp_softc *sc = device_get_softc(devi);
265 rv = nspprobesubr(rman_get_bustag(sc->port_res),
266 rman_get_bushandle(sc->port_res),
267 DEVPORT_PDEVFLAGS(devi));
273 nspattach(DEVPORT_PDEVICE devi)
275 struct nsp_softc *sc;
276 struct scsi_low_softc *slp;
277 u_int32_t flags = DEVPORT_PDEVFLAGS(devi);
278 u_int iobase = DEVPORT_PDEVIOBASE(devi);
282 strcpy(dvname,"nsp");
285 printf("%s: no ioaddr is given\n", dvname);
289 sc = DEVPORT_PDEVALLOC_SOFTC(devi);
295 sc->sc_iot = rman_get_bustag(sc->port_res);
296 sc->sc_ioh = rman_get_bushandle(sc->port_res);
298 if (sc->mem_res == NULL) {
299 printf("WARNING: CANNOT GET Memory RESOURCE going PIO mode");
303 if ((flags & PIO_MODE) == 0) {
304 sc->sc_memt = rman_get_bustag(sc->mem_res);
305 sc->sc_memh = rman_get_bushandle(sc->mem_res);
309 /* slp->sl_irq = devi->pd_irq; */
310 sc->sc_iclkdiv = CLKDIVR_20M;
311 sc->sc_clkdiv = CLKDIVR_40M;
313 slp->sl_hostid = NSP_HOSTID;
314 slp->sl_cfgflags = flags;