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