1 /* $NetBSD: spc_pcmcia.c,v 1.20 2008/04/28 20:23:56 martin Exp $ */
4 * Copyright (c) 2000, 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: spc_pcmcia.c,v 1.20 2008/04/28 20:23:56 martin Exp $");
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
43 #include <dev/scsipi/scsi_all.h>
44 #include <dev/scsipi/scsipi_all.h>
45 #include <dev/scsipi/scsiconf.h>
47 #include <dev/pcmcia/pcmciareg.h>
48 #include <dev/pcmcia/pcmciavar.h>
49 #include <dev/pcmcia/pcmciadevs.h>
51 #include <dev/ic/mb89352var.h>
53 struct spc_pcmcia_softc
{
54 struct spc_softc sc_spc
; /* glue to MI code */
56 /* PCMCIA-specific goo. */
57 struct pcmcia_function
*sc_pf
; /* our PCMCIA function */
58 void *sc_ih
; /* interrupt handler */
61 #define SPC_PCMCIA_ATTACHED 3
64 static int spc_pcmcia_match(device_t
, cfdata_t
, void *);
65 static int spc_pcmcia_validate_config(struct pcmcia_config_entry
*);
66 static void spc_pcmcia_attach(device_t
, device_t
, void *);
67 static int spc_pcmcia_detach(device_t
, int);
68 static int spc_pcmcia_enable(device_t
, int);
70 CFATTACH_DECL2_NEW(spc_pcmcia
, sizeof(struct spc_pcmcia_softc
),
71 spc_pcmcia_match
, spc_pcmcia_attach
, spc_pcmcia_detach
, NULL
, NULL
,
74 static const struct pcmcia_product spc_pcmcia_products
[] = {
75 { PCMCIA_VENDOR_FUJITSU
, PCMCIA_PRODUCT_FUJITSU_SCSI600
,
76 PCMCIA_CIS_FUJITSU_SCSI600
},
78 static const size_t spc_pcmcia_nproducts
= __arraycount(spc_pcmcia_products
);
81 spc_pcmcia_match(device_t parent
, cfdata_t cf
, void *aux
)
83 struct pcmcia_attach_args
*pa
= aux
;
85 if (pcmcia_product_lookup(pa
, spc_pcmcia_products
, spc_pcmcia_nproducts
,
86 sizeof(spc_pcmcia_products
[0]), NULL
))
92 spc_pcmcia_validate_config(struct pcmcia_config_entry
*cfe
)
95 if (cfe
->iftype
!= PCMCIA_IFTYPE_IO
||
96 cfe
->num_memspace
!= 0 ||
97 cfe
->num_iospace
!= 1)
103 spc_pcmcia_attach(device_t parent
, device_t self
, void *aux
)
105 struct spc_pcmcia_softc
*sc
= device_private(self
);
106 struct spc_softc
*spc
= &sc
->sc_spc
;
107 struct pcmcia_attach_args
*pa
= aux
;
108 struct pcmcia_config_entry
*cfe
;
109 struct pcmcia_function
*pf
= pa
->pf
;
115 error
= pcmcia_function_configure(pf
, spc_pcmcia_validate_config
);
117 aprint_error_dev(self
, "configure failed, error=%d\n", error
);
122 spc
->sc_iot
= cfe
->iospace
[0].handle
.iot
;
123 spc
->sc_ioh
= cfe
->iospace
[0].handle
.ioh
;
125 error
= spc_pcmcia_enable(self
, 1);
129 spc
->sc_initiator
= 7; /* XXX */
130 spc
->sc_adapter
.adapt_enable
= spc_pcmcia_enable
;
131 spc
->sc_adapter
.adapt_refcnt
= 1;
134 * Initialize nca board itself.
137 scsipi_adapter_delref(&spc
->sc_adapter
);
138 sc
->sc_state
= SPC_PCMCIA_ATTACHED
;
142 pcmcia_function_unconfigure(pf
);
146 spc_pcmcia_detach(device_t self
, int flags
)
148 struct spc_pcmcia_softc
*sc
= device_private(self
);
151 if (sc
->sc_state
!= SPC_PCMCIA_ATTACHED
)
154 error
= spc_detach(self
, flags
);
158 pcmcia_function_unconfigure(sc
->sc_pf
);
164 spc_pcmcia_enable(device_t self
, int onoff
)
166 struct spc_pcmcia_softc
*sc
= device_private(self
);
170 /* Establish the interrupt handler. */
171 sc
->sc_ih
= pcmcia_intr_establish(sc
->sc_pf
, IPL_BIO
,
172 spc_intr
, &sc
->sc_spc
);
176 error
= pcmcia_function_enable(sc
->sc_pf
);
178 pcmcia_intr_disestablish(sc
->sc_pf
, sc
->sc_ih
);
183 /* Initialize only chip. */
184 spc_init(&sc
->sc_spc
, 0);
186 pcmcia_function_disable(sc
->sc_pf
);
187 pcmcia_intr_disestablish(sc
->sc_pf
, sc
->sc_ih
);