ahc_cardbus.c revision 1.1 1 /* $NetBSD: ahc_cardbus.c,v 1.1 2000/01/26 06:37:23 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * CardBus front-end for the Adaptec AIC-7xxx family of SCSI controllers.
42 *
43 * TODO:
44 * - power management
45 */
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/malloc.h>
50 #include <sys/kernel.h>
51 #include <sys/queue.h>
52 #include <sys/device.h>
53
54 #include <machine/bus.h>
55 #include <machine/intr.h>
56
57 #include <dev/scsipi/scsi_all.h>
58 #include <dev/scsipi/scsipi_all.h>
59 #include <dev/scsipi/scsiconf.h>
60
61 #include <dev/pci/pcireg.h>
62
63 #include <dev/cardbus/cardbusvar.h>
64 #include <dev/cardbus/cardbusdevs.h>
65
66 #include <dev/ic/aic7xxxreg.h>
67 #include <dev/ic/aic7xxxvar.h>
68
69 #define AHC_CARDBUS_IOBA 0x10
70 #define AHC_CARDBUS_MMBA 0x14
71
72 struct ahc_cardbus_softc {
73 struct ahc_data sc_ahc; /* real AHC */
74
75 /* CardBus-specific goo. */
76 cardbus_devfunc_t sc_ct; /* our CardBus devfuncs */
77 int sc_intrline; /* our interrupt line */
78 cardbustag_t sc_tag;
79
80 int sc_cbenable; /* what CardBus access type to enable */
81 int sc_csr; /* CSR bits */
82 };
83
84 int ahc_cardbus_match __P((struct device *, struct cfdata *, void *));
85 void ahc_cardbus_attach __P((struct device *, struct device *, void *));
86
87 struct cfattach ahc_cardbus_ca = {
88 sizeof(struct ahc_data), ahc_cardbus_match, ahc_cardbus_attach,
89 };
90
91 int
92 ahc_cardbus_match(parent, match, aux)
93 struct device *parent;
94 struct cfdata *match;
95 void *aux;
96 {
97 struct cardbus_attach_args *ca = aux;
98
99 if (CARDBUS_VENDOR(ca->ca_id) == CARDBUS_VENDOR_ADP &&
100 CARDBUS_PRODUCT(ca->ca_id) == CARDBUS_PRODUCT_ADP_1480)
101 return (1);
102
103 return (0);
104 }
105
106 void
107 ahc_cardbus_attach(parent, self, aux)
108 struct device *parent, *self;
109 void *aux;
110 {
111 struct cardbus_attach_args *ca = aux;
112 struct ahc_cardbus_softc *csc = (void *) self;
113 struct ahc_data *ahc = &csc->sc_ahc;
114 cardbus_devfunc_t ct = ca->ca_ct;
115 cardbus_chipset_tag_t cc = ct->ct_cc;
116 cardbus_function_tag_t cf = ct->ct_cf;
117 bus_space_tag_t bst;
118 bus_space_handle_t bsh;
119 pcireg_t reg;
120 ahc_type ahc_t = AHC_NONE;
121 ahc_flag ahc_f = AHC_FNONE;
122
123 csc->sc_ct = ct;
124 csc->sc_tag = ca->ca_tag;
125 csc->sc_intrline = ca->ca_intrline;
126
127 printf(": Adaptec ADP-1480 SCSI\n");
128
129 /*
130 * Map the device.
131 */
132 csc->sc_csr = PCI_COMMAND_MASTER_ENABLE;
133 if (Cardbus_mapreg_map(csc->sc_ct, AHC_CARDBUS_MMBA,
134 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
135 &bst, &bsh, NULL, NULL) == 0) {
136 csc->sc_cbenable = CARDBUS_MEM_ENABLE;
137 csc->sc_csr |= PCI_COMMAND_MEM_ENABLE;
138 } else if (Cardbus_mapreg_map(csc->sc_ct, AHC_CARDBUS_IOBA,
139 PCI_MAPREG_TYPE_IO, 0, &bst, &bsh, NULL, NULL) == 0) {
140 csc->sc_cbenable = CARDBUS_IO_ENABLE;
141 csc->sc_csr |= PCI_COMMAND_IO_ENABLE;
142 } else {
143 printf("%s: unable to map device registers\n",
144 ahc_name(ahc));
145 return;
146 }
147
148 /* Make sure the right access type is on the CardBus bridge. */
149 (*ct->ct_cf->cardbus_ctrl)(cc, csc->sc_cbenable);
150 (*ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
151
152 /* Enable the appropriate bits in the PCI CSR. */
153 reg = cardbus_conf_read(cc, cf, ca->ca_tag, PCI_COMMAND_STATUS_REG);
154 reg &= ~(PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE);
155 reg |= csc->sc_csr;
156 cardbus_conf_write(cc, cf, ca->ca_tag, PCI_COMMAND_STATUS_REG, reg);
157
158 /*
159 * Make sure the latency timer is set to some reasonable
160 * value.
161 */
162 reg = cardbus_conf_read(cc, cf, ca->ca_tag, PCI_BHLC_REG);
163 if (PCI_LATTIMER(reg) < 0x20) {
164 reg &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
165 reg |= (0x20 << PCI_LATTIMER_SHIFT);
166 cardbus_conf_write(cc, cf, ca->ca_tag, PCI_BHLC_REG, reg);
167 }
168
169 /*
170 * ADP-1480 is always an AIC-7860.
171 */
172 ahc_t = AHC_AIC7860;
173
174 /*
175 * On all CardBus adapters, we allow SCB paging.
176 */
177 ahc_f |= AHC_PAGESCBS;
178
179 ahc_reset(ahc->sc_dev.dv_xname, bst, bsh);
180 ahc_construct(ahc, bst, bsh, ca->ca_dmat, ahc_t, ahc_f);
181
182 /*
183 * Establish the interrupt.
184 */
185 ahc->sc_ih = cardbus_intr_establish(cc, cf, ca->ca_intrline, IPL_BIO,
186 ahc_intr, ahc);
187 if (ahc->sc_ih == NULL) {
188 printf("%s: unable to establish interrupt at %d\n",
189 ahc_name(ahc), ca->ca_intrline);
190 return;
191 }
192 printf("%s: interrupting at %d\n", ahc_name(ahc), ca->ca_intrline);
193
194 /*
195 * Do chip-specific initialization.
196 */
197 {
198 u_char sblkctl;
199 const char *id_string;
200
201 switch (ahc->type) {
202 case AHC_AIC7860:
203 id_string = "aic7860 ";
204 ahc_load_seeprom(ahc);
205 break;
206
207 default:
208 printf("%s: unknown controller type\n", ahc_name(ahc));
209 ahc_free(ahc);
210 return;
211 }
212
213 /*
214 * Take the LED out of diagnostic mode.
215 */
216 sblkctl = AHC_INB(ahc, SBLKCTL);
217 AHC_OUTB(ahc, SBLKCTL, (sblkctl & ~(DIAGLEDEN|DIAGLEDON)));
218
219 /*
220 * I don't know where this is set in the SEEPROM or by the
221 * BIOS, so we default to 100%.
222 */
223 AHC_OUTB(ahc, DSPCISTATUS, DFTHRSH_100);
224
225 if (ahc->flags & AHC_USEDEFAULTS) {
226 /*
227 * We can't "use defaults", as we have no way
228 * of knowing what default settings hould be.
229 */
230 printf("%s: CardBus device requires an SEEPROM\n",
231 ahc_name(ahc));
232 return;
233 }
234
235 printf("%s: %s", ahc_name(ahc), id_string);
236 }
237
238 if (ahc_init(ahc)) {
239 ahc_free(ahc);
240 return;
241 }
242
243 ahc_attach(ahc);
244 }
245