aic_pcmcia.c revision 1.2 1 /* $NetBSD: aic_pcmcia.c,v 1.2 1997/10/16 23:27:16 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Marc Horowitz.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/select.h>
35 #include <sys/device.h>
36
37 #include <machine/cpu.h>
38 #include <machine/bus.h>
39 #include <machine/intr.h>
40
41 #include <dev/scsipi/scsipi_all.h>
42 #include <dev/scsipi/scsipiconf.h>
43 #include <dev/scsipi/scsi_all.h>
44
45 #include <dev/ic/aic6360var.h>
46
47 #include <dev/pcmcia/pcmciareg.h>
48 #include <dev/pcmcia/pcmciavar.h>
49
50 #define PCMCIA_MANUFACTURER_ADAPTEC 0x012F
51 #define PCMCIA_PRODUCT_ADAPTEC_APA1460_1 0x0001
52 #define PCMCIA_PRODUCT_ADAPTEC_APA1460_2 0x0002
53
54 #ifdef __BROKEN_INDIRECT_CONFIG
55 int aic_pcmcia_match __P((struct device *, void *, void *));
56 #else
57 int aic_pcmcia_match __P((struct device *, struct cfdata *, void *));
58 #endif
59 void aic_pcmcia_attach __P((struct device *, struct device *, void *));
60
61 struct aic_pcmcia_softc {
62 struct aic_softc sc_aic; /* real "aic" softc */
63
64 /* PCMCIA-specific goo. */
65 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */
66 int sc_io_window; /* our i/o window */
67 struct pcmcia_function *sc_pf; /* our PCMCIA function */
68 void *sc_ih; /* interrupt handler */
69 };
70
71 struct cfattach aic_pcmcia_ca = {
72 sizeof(struct aic_pcmcia_softc), aic_pcmcia_match, aic_pcmcia_attach
73 };
74
75 int
76 aic_pcmcia_match(parent, match, aux)
77 struct device *parent;
78 #ifdef __BROKEN_INDIRECT_CONFIG
79 void *match;
80 #else
81 struct cfdata *cf;
82 #endif
83 void *aux;
84 {
85 struct pcmcia_attach_args *pa = aux;
86
87 if (pa->manufacturer == PCMCIA_MANUFACTURER_ADAPTEC) {
88 switch (pa->product) {
89 case PCMCIA_PRODUCT_ADAPTEC_APA1460_1:
90 case PCMCIA_PRODUCT_ADAPTEC_APA1460_2:
91 if (pa->pf->number == 0)
92 return (1);
93 }
94 }
95
96 return (0);
97 }
98
99 void
100 aic_pcmcia_attach(parent, self, aux)
101 struct device *parent, *self;
102 void *aux;
103 {
104 struct aic_pcmcia_softc *psc = (void *)self;
105 struct aic_softc *sc = &psc->sc_aic;
106 struct pcmcia_attach_args *pa = aux;
107 struct pcmcia_config_entry *cfe;
108 struct pcmcia_function *pf = pa->pf;
109
110 psc->sc_pf = pf;
111
112 for (cfe = pf->cfe_head.sqh_first; cfe; cfe = cfe->cfe_list.sqe_next) {
113 if (cfe->num_memspace != 0 ||
114 cfe->num_iospace != 1)
115 continue;
116
117 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
118 cfe->iospace[0].length, 0, &psc->sc_pcioh) == 0)
119 break;
120 }
121
122 if (cfe == 0) {
123 printf(": can't alloc i/o space\n");
124 return;
125 }
126
127 sc->sc_iot = psc->sc_pcioh.iot;
128 sc->sc_ioh = psc->sc_pcioh.ioh;
129
130 /* Enable the card. */
131 pcmcia_function_init(pf, cfe);
132 if (pcmcia_function_enable(pf)) {
133 printf(": function enable failed\n");
134 return;
135 }
136
137 /* Map in the io space */
138 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, psc->sc_pcioh.size,
139 &psc->sc_pcioh, &psc->sc_io_window)) {
140 printf(": can't map i/o space\n");
141 return;
142 }
143
144 if (!aic_find(sc->sc_iot, sc->sc_ioh))
145 printf(": coundn't find aic\n%s", sc->sc_dev.dv_xname);
146
147 printf(": APA-1460 SCSI Host Adapter\n");
148
149 aicattach(sc);
150
151 /* Establish the interrupt handler. */
152 psc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO, aicintr, sc);
153 if (psc->sc_ih == NULL)
154 printf("%s: couldn't establish interrupt\n",
155 sc->sc_dev.dv_xname);
156 }
157