1 /* $FreeBSD: src/sys/dev/ncv/ncr53c500_pccard.c,v 1.2.2.5 2001/12/17 13:30:18 non Exp $ */
2 /* $DragonFly: src/sys/dev/disk/ncv/ncr53c500_pccard.c,v 1.9 2005/06/10 15:29:16 swildner Exp $ */
3 /* $NecBSD: ncr53c500_pisa.c,v 1.28 1998/11/26 01:59:11 honda Exp $ */
9 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe.
10 * All rights reserved.
11 * [NetBSD for NEC PC-98 series]
12 * Copyright (c) 1995, 1996, 1997, 1998
13 * NetBSD/pc98 porting staff. All rights reserved.
14 * Copyright (c) 1995, 1996, 1997, 1998
15 * Naofumi HONDA. All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. The name of the author may not be used to endorse or promote products
26 * derived from this software without specific prior written permission.
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
32 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
34 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
36 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
37 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/param.h>
42 #include <sys/systm.h>
43 #include <sys/disklabel.h>
45 #include <sys/queue.h>
46 #include <sys/malloc.h>
47 #include <sys/errno.h>
48 #include <sys/thread2.h>
52 #include <machine/bus.h>
53 #include <machine/bus_pio.h>
54 #include <machine/dvcfg.h>
56 #include <sys/device_port.h>
58 #include <bus/pccard/pccarddevs.h>
59 #include <bus/pccard/pccardvar.h>
61 #include <bus/cam/scsi/scsi_low.h>
62 #include <bus/cam/scsi/scsi_low_pisa.h>
64 #include "ncr53c500reg.h"
65 #include "ncr53c500hw.h"
66 #include "ncr53c500var.h"
68 #define KME_KXLC004_01 0x100
69 #define OFFSET_KME_KXLC004_01 0x10
71 #include <sys/kernel.h>
72 #include <sys/module.h>
73 #include <bus/pccard/cardinfo.h>
74 #include <bus/pccard/slot.h>
76 static int ncvprobe(DEVPORT_PDEVICE devi);
77 static int ncvattach(DEVPORT_PDEVICE devi);
79 static void ncv_card_unload (DEVPORT_PDEVICE);
81 static const struct ncv_product {
82 struct pccard_product prod;
85 { PCMCIA_CARD(EPSON, SC200, 0), 0},
86 { PCMCIA_CARD(PANASONIC, KXLC002, 0), 0xb4d00000 },
87 { PCMCIA_CARD(PANASONIC, KXLC004, 0), 0xb4d00100 },
88 { PCMCIA_CARD(MACNICA, MPS100, 0), 0xb6250000 },
89 { PCMCIA_CARD(MACNICA, MPS110, 0), 0 },
90 { PCMCIA_CARD(NEC, PC9801N_J03R, 0), 0 },
91 { PCMCIA_CARD(NEWMEDIA, BASICS_SCSI, 0), 0 },
92 { PCMCIA_CARD(QLOGIC, PC05, 0), 0x84d00000 },
93 #define FLAGS_REX5572 0x84d00000
94 { PCMCIA_CARD(RATOC, REX5572, 0), FLAGS_REX5572 },
95 { PCMCIA_CARD(RATOC, REX9530, 0), 0x84d00000 },
100 * Additional code for FreeBSD new-bus PCCard frontend
104 ncv_pccard_intr(void * arg)
110 ncv_release_resource(DEVPORT_PDEVICE dev)
112 struct ncv_softc *sc = device_get_softc(dev);
114 if (sc->ncv_intrhand) {
115 bus_teardown_intr(dev, sc->irq_res, sc->ncv_intrhand);
119 bus_release_resource(dev, SYS_RES_IOPORT,
120 sc->port_rid, sc->port_res);
123 if (sc->port_res_dmy) {
124 bus_release_resource(dev, SYS_RES_IOPORT,
125 sc->port_rid_dmy, sc->port_res_dmy);
129 bus_release_resource(dev, SYS_RES_IRQ,
130 sc->irq_rid, sc->irq_res);
134 bus_release_resource(dev, SYS_RES_MEMORY,
135 sc->mem_rid, sc->mem_res);
140 ncv_alloc_resource(DEVPORT_PDEVICE dev)
142 struct ncv_softc *sc = device_get_softc(dev);
143 u_int32_t flags = DEVPORT_PDEVFLAGS(dev);
144 u_long ioaddr, iosize, maddr, msize;
146 bus_addr_t offset = 0;
148 if(flags & KME_KXLC004_01)
149 offset = OFFSET_KME_KXLC004_01;
151 error = bus_get_resource(dev, SYS_RES_IOPORT, 0, &ioaddr, &iosize);
152 if (error || (iosize < (offset + NCVIOSZ))) {
157 sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid,
158 ioaddr+offset, ioaddr+iosize-offset,
159 iosize-offset, RF_ACTIVE);
160 if (sc->port_res == NULL) {
161 ncv_release_resource(dev);
166 sc->port_rid_dmy = 0;
167 sc->port_res_dmy = bus_alloc_resource(dev, SYS_RES_IOPORT,
169 ioaddr, ioaddr+offset, offset,
171 if (sc->port_res_dmy == NULL) {
172 printf("Warning: cannot allocate IOPORT partially.\n");
175 sc->port_rid_dmy = 0;
176 sc->port_res_dmy = NULL;
180 sc->irq_res = bus_alloc_resource(dev, SYS_RES_IRQ, &sc->irq_rid,
181 0, ~0, 1, RF_ACTIVE);
182 if (sc->irq_res == NULL) {
183 ncv_release_resource(dev);
187 error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize);
192 /* no need to allocate memory if not configured */
193 if (maddr == 0 || msize == 0) {
198 sc->mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mem_rid,
199 0, ~0, 1, RF_ACTIVE);
200 if (sc->mem_res == NULL) {
201 ncv_release_resource(dev);
208 static int ncv_pccard_match(device_t dev)
210 const struct ncv_product *pp;
211 const char *vendorstr;
214 if ((pp = (const struct ncv_product *) pccard_product_lookup(dev,
215 (const struct pccard_product *) ncv_products,
216 sizeof(ncv_products[0]), NULL)) != NULL) {
217 if (pp->prod.pp_name != NULL)
218 device_set_desc(dev, pp->prod.pp_name);
219 device_set_flags(dev, pp->flags);
222 vendorstr = pccard_get_vendor_str(dev);
223 prodstr = pccard_get_product_str(dev);
224 if (strcmp(vendorstr, "RATOC System Inc.") == 0 &&
225 strncmp(prodstr, "SOUND/SCSI2 CARD", 16) == 0) {
226 device_set_desc(dev, "RATOC REX-5572");
227 device_set_flags(dev, FLAGS_REX5572);
234 ncv_pccard_probe(DEVPORT_PDEVICE dev)
236 struct ncv_softc *sc = device_get_softc(dev);
239 bzero(sc, sizeof(struct ncv_softc));
241 error = ncv_alloc_resource(dev);
246 if (ncvprobe(dev) == 0) {
247 ncv_release_resource(dev);
251 ncv_release_resource(dev);
257 ncv_pccard_attach(DEVPORT_PDEVICE dev)
259 struct ncv_softc *sc = device_get_softc(dev);
262 error = ncv_alloc_resource(dev);
267 error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM,
268 ncv_pccard_intr, (void *)sc,
269 &sc->ncv_intrhand, NULL);
271 ncv_release_resource(dev);
275 if (ncvattach(dev) == 0) {
276 ncv_release_resource(dev);
284 ncv_pccard_detach(DEVPORT_PDEVICE dev)
286 ncv_card_unload(dev);
287 ncv_release_resource(dev);
290 static device_method_t ncv_pccard_methods[] = {
291 /* Device interface */
292 DEVMETHOD(device_probe, pccard_compat_probe),
293 DEVMETHOD(device_attach, pccard_compat_attach),
294 DEVMETHOD(device_detach, ncv_pccard_detach),
297 DEVMETHOD(card_compat_match, ncv_pccard_match),
298 DEVMETHOD(card_compat_probe, ncv_pccard_probe),
299 DEVMETHOD(card_compat_attach, ncv_pccard_attach),
304 static driver_t ncv_pccard_driver = {
307 sizeof(struct ncv_softc),
310 static devclass_t ncv_devclass;
312 MODULE_DEPEND(ncv, scsi_low, 1, 1, 1);
313 DRIVER_MODULE(ncv, pccard, ncv_pccard_driver, ncv_devclass, 0, 0);
316 ncv_card_unload(DEVPORT_PDEVICE devi)
318 struct ncv_softc *sc = DEVPORT_PDEVGET_SOFTC(devi);
320 printf("%s: unload\n", sc->sc_sclow.sl_xname);
322 scsi_low_deactivate((struct scsi_low_softc *)sc);
323 scsi_low_dettach(&sc->sc_sclow);
328 ncvprobe(DEVPORT_PDEVICE devi)
331 struct ncv_softc *sc = device_get_softc(devi);
332 u_int32_t flags = DEVPORT_PDEVFLAGS(devi);
334 rv = ncvprobesubr(rman_get_bustag(sc->port_res),
335 rman_get_bushandle(sc->port_res),
342 ncvattach(DEVPORT_PDEVICE devi)
344 struct ncv_softc *sc;
345 struct scsi_low_softc *slp;
346 u_int32_t flags = DEVPORT_PDEVFLAGS(devi);
347 char dvname[16]; /* SCSI_LOW_DVNAME_LEN */
349 strcpy(dvname, "ncv");
351 sc = DEVPORT_PDEVALLOC_SOFTC(devi);
358 sc->sc_iot = rman_get_bustag(sc->port_res);
359 sc->sc_ioh = rman_get_bushandle(sc->port_res);
361 slp->sl_hostid = NCV_HOSTID;
362 slp->sl_cfgflags = flags;