tcic2_isa.c revision 1.2 1 /* $NetBSD: tcic2_isa.c,v 1.2 1999/04/08 16:14:29 bad Exp $ */
2
3 #undef TCICISADEBUG
4
5 /*
6 *
7 * Copyright (c) 1998, 1999 Christoph Badura. All rights reserved.
8 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by Marc Horowitz.
21 * 4. The name of the author may not be used to endorse or promote products
22 * derived from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
25 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
28 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
36
37 #include <sys/types.h>
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41 #include <sys/extent.h>
42 #include <sys/malloc.h>
43
44 #include <vm/vm.h>
45
46 #include <machine/bus.h>
47 #include <machine/intr.h>
48
49 #include <dev/isa/isareg.h>
50 #include <dev/isa/isavar.h>
51
52 #include <dev/pcmcia/pcmciareg.h>
53 #include <dev/pcmcia/pcmciavar.h>
54 #include <dev/pcmcia/pcmciachip.h>
55
56 #include <dev/ic/tcic2reg.h>
57 #include <dev/ic/tcic2var.h>
58
59 /*****************************************************************************
60 * Configurable parameters.
61 *****************************************************************************/
62
63 #include "opt_tcic_isa_alloc_iobase.h"
64 #include "opt_tcic_isa_alloc_iosize.h"
65 #include "opt_tcic_isa_intr_alloc_mask.h"
66
67 /*
68 * Default I/O allocation range. If both are set to non-zero, these
69 * values will be used instead. Otherwise, the code attempts to probe
70 * the bus width. Systems with 10 address bits should use 0x300 and 0xff.
71 * Systems with 12 address bits (most) should use 0x400 and 0xbff.
72 */
73
74 #ifndef TCIC_ISA_ALLOC_IOBASE
75 #define TCIC_ISA_ALLOC_IOBASE 0
76 #endif
77
78 #ifndef TCIC_ISA_ALLOC_IOSIZE
79 #define TCIC_ISA_ALLOC_IOSIZE 0
80 #endif
81
82 int tcic_isa_alloc_iobase = TCIC_ISA_ALLOC_IOBASE;
83 int tcic_isa_alloc_iosize = TCIC_ISA_ALLOC_IOSIZE;
84
85 /*
86 * Default IRQ allocation bitmask. This defines the range of allowable
87 * IRQs for PCMCIA slots. Useful if order of probing would screw up other
88 * devices, or if TCIC hardware/cards have trouble with certain interrupt
89 * lines.
90 *
91 * We disable IRQ 10 by default, since some common laptops (namely, the
92 * NEC Versa series) reserve IRQ 10 for the docking station SCSI interface.
93 *
94 * XXX Do we care about this? the Versa doesn't use a tcic. -chb
95 */
96
97 #ifndef TCIC_ISA_INTR_ALLOC_MASK
98 #define TCIC_ISA_INTR_ALLOC_MASK 0xffff
99 #endif
100
101 int tcic_isa_intr_alloc_mask = TCIC_ISA_INTR_ALLOC_MASK;
102
103 /*****************************************************************************
104 * End of configurable parameters.
105 *****************************************************************************/
106
107 #ifdef TCICISADEBUG
108 int tcic_isa_debug = 1;
109 #define DPRINTF(arg) if (tcic_isa_debug) printf arg;
110 #else
111 #define DPRINTF(arg)
112 #endif
113
114 int tcic_isa_probe __P((struct device *, struct cfdata *, void *));
115 void tcic_isa_attach __P((struct device *, struct device *, void *));
116
117 void *tcic_isa_chip_intr_establish __P((pcmcia_chipset_handle_t,
118 struct pcmcia_function *, int, int (*) (void *), void *));
119 void tcic_isa_chip_intr_disestablish __P((pcmcia_chipset_handle_t, void *));
120
121 struct cfattach tcic_isa_ca = {
122 sizeof(struct tcic_softc), tcic_isa_probe, tcic_isa_attach
123 };
124
125 static struct pcmcia_chip_functions tcic_isa_functions = {
126 tcic_chip_mem_alloc,
127 tcic_chip_mem_free,
128 tcic_chip_mem_map,
129 tcic_chip_mem_unmap,
130
131 tcic_chip_io_alloc,
132 tcic_chip_io_free,
133 tcic_chip_io_map,
134 tcic_chip_io_unmap,
135
136 tcic_isa_chip_intr_establish,
137 tcic_isa_chip_intr_disestablish,
138
139 tcic_chip_socket_enable,
140 tcic_chip_socket_disable,
141 };
142
143 int
144 tcic_isa_probe(parent, match, aux)
145 struct device *parent;
146 struct cfdata *match;
147 void *aux;
148 {
149 struct isa_attach_args *ia = aux;
150 bus_space_tag_t iot = ia->ia_iot;
151 bus_space_handle_t ioh, memh;
152 int val, found;
153
154 /* Disallow wildcarded i/o address. */
155 if (ia->ia_iobase == ISACF_PORT_DEFAULT)
156 return (0);
157
158 if (bus_space_map(iot, ia->ia_iobase, TCIC_IOSIZE, 0, &ioh))
159 return (0);
160
161 if (ia->ia_msize == -1)
162 ia->ia_msize = TCIC_MEMSIZE;
163
164 if (bus_space_map(ia->ia_memt, ia->ia_maddr, ia->ia_msize, 0, &memh))
165 return (0);
166
167 DPRINTF(("tcic probing 0x%03x\n", ia->ia_iobase));
168 found = 0;
169
170 /*
171 * First, check for the reserved bits to be zero.
172 */
173 if (tcic_check_reserved_bits(iot, ioh)) {
174 DPRINTF(("tcic: reserved bits checked OK\n"));
175 /* Second, check whether the we know how to handle the chip. */
176 if ((val = tcic_chipid(iot, ioh))) {
177 DPRINTF(("tcic id: 0x%02x\n", val));
178 if (tcic_chipid_known(val))
179 found++;
180 }
181 }
182 else
183 DPRINTF(("tcic: reserved bits didn't check OK\n"));
184
185 bus_space_unmap(iot, ioh, TCIC_IOSIZE);
186 bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
187
188 if (!found)
189 return (0);
190
191 ia->ia_iosize = TCIC_IOSIZE;
192
193 return (1);
194 }
195
196 void
197 tcic_isa_attach(parent, self, aux)
198 struct device *parent, *self;
199 void *aux;
200 {
201 struct tcic_softc *sc = (void *) self;
202 struct isa_attach_args *ia = aux;
203 isa_chipset_tag_t ic = ia->ia_ic;
204 bus_space_tag_t iot = ia->ia_iot;
205 bus_space_tag_t memt = ia->ia_memt;
206 bus_space_handle_t ioh;
207 bus_space_handle_t memh;
208
209 /* Map i/o space. */
210 if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) {
211 printf(": can't map i/o space\n");
212 return;
213 }
214
215 /* Map mem space. */
216 if (bus_space_map(memt, ia->ia_maddr, ia->ia_msize, 0, &memh)) {
217 printf(": can't map mem space\n");
218 return;
219 }
220
221 sc->membase = ia->ia_maddr;
222 sc->subregionmask = (1 << (ia->ia_msize / TCIC_MEM_PAGESIZE)) - 1;
223 sc->memsize2 = tcic_log2((u_int)ia->ia_msize);
224
225 sc->intr_est = ic;
226 sc->pct = (pcmcia_chipset_tag_t) & tcic_isa_functions;
227
228 sc->iot = iot;
229 sc->ioh = ioh;
230 sc->memt = memt;
231 sc->memh = memh;
232
233 /*
234 * determine chip type and initialise some chip type dependend
235 * parameters in softc.
236 */
237 sc->chipid = tcic_chipid(iot, ioh);
238 sc->validirqs = tcic_validirqs(sc->chipid);
239
240 /*
241 * allocate an irq. interrupts are relatively
242 * scarce but for TCIC controllers very infrequent.
243 */
244
245 if ((sc->irq = ia->ia_irq) == IRQUNK) {
246 if (isa_intr_alloc(ic,
247 sc->validirqs & (tcic_isa_intr_alloc_mask & 0xff00),
248 IST_EDGE, &sc->irq)) {
249 printf("\n%s: can't allocate interrupt\n",
250 sc->dev.dv_xname);
251 return;
252 }
253 printf(": using irq %d", sc->irq);
254 }
255 printf("\n");
256
257 tcic_attach(sc);
258
259
260 /*
261 * XXX mycroft recommends I/O space range 0x400-0xfff.
262 */
263
264 /*
265 * XXX some hardware doesn't seem to grok addresses in 0x400 range--
266 * apparently missing a bit or more of address lines. (e.g.
267 * CIRRUS_PD672X with Linksys EthernetCard ne2000 clone in TI
268 * TravelMate 5000--not clear which is at fault)
269 *
270 * Add a kludge to detect 10 bit wide buses and deal with them,
271 * and also a config file option to override the probe.
272 */
273
274 #if 0
275 /*
276 * This is what we'd like to use, but...
277 */
278 sc->iobase = 0x400;
279 sc->iosize = 0xbff;
280 #else
281 /*
282 * ...the above bus width probe doesn't always work.
283 * So, experimentation has shown the following range
284 * to not lose on systems that 0x300-0x3ff loses on
285 * (e.g. the NEC Versa 6030X).
286 */
287 sc->iobase = 0x330;
288 sc->iosize = 0x0cf;
289 #endif
290
291 DPRINTF(("%s: bus_space_alloc range 0x%04lx-0x%04lx)\n",
292 sc->dev.dv_xname, (long) sc->iobase,
293 (long) sc->iobase + sc->iosize));
294
295 if (tcic_isa_alloc_iobase && tcic_isa_alloc_iosize) {
296 sc->iobase = tcic_isa_alloc_iobase;
297 sc->iosize = tcic_isa_alloc_iosize;
298
299 DPRINTF(("%s: bus_space_alloc range 0x%04lx-0x%04lx "
300 "(config override)\n", sc->dev.dv_xname, (long) sc->iobase,
301 (long) sc->iobase + sc->iosize));
302 }
303 sc->ih = isa_intr_establish(ic, sc->irq, IST_EDGE, IPL_TTY,
304 tcic_intr, sc);
305 if (sc->ih == NULL) {
306 printf("%s: can't establish interrupt\n", sc->dev.dv_xname);
307 return;
308 }
309
310 tcic_attach_sockets(sc);
311 }
312
313 void *
314 tcic_isa_chip_intr_establish(pch, pf, ipl, fct, arg)
315 pcmcia_chipset_handle_t pch;
316 struct pcmcia_function *pf;
317 int ipl;
318 int (*fct) __P((void *));
319 void *arg;
320 {
321 struct tcic_handle *h = (struct tcic_handle *) pch;
322 int irq, ist;
323 void *ih;
324
325 DPRINTF(("%s: tcic_isa_chip_intr_establish\n", h->sc->dev.dv_xname));
326
327 /* XXX should we convert level to pulse? -chb */
328 if (pf->cfe->flags & PCMCIA_CFE_IRQLEVEL)
329 ist = IST_LEVEL;
330 else if (pf->cfe->flags & PCMCIA_CFE_IRQPULSE)
331 ist = IST_PULSE;
332 else
333 ist = IST_LEVEL;
334
335 if (isa_intr_alloc(h->sc->intr_est,
336 h->sc->validirqs & tcic_isa_intr_alloc_mask, ist, &irq))
337 return (NULL);
338 if ((ih = isa_intr_establish(h->sc->intr_est, irq, ist, ipl,
339 fct, arg)) == NULL)
340 return (NULL);
341
342 DPRINTF(("%s: intr estrablished\n", h->sc->dev.dv_xname));
343
344 h->ih_irq = irq;
345
346 printf("%s: card irq %d\n", h->pcmcia->dv_xname, irq);
347
348 return (ih);
349 }
350
351 void
352 tcic_isa_chip_intr_disestablish(pch, ih)
353 pcmcia_chipset_handle_t pch;
354 void *ih;
355 {
356 struct tcic_handle *h = (struct tcic_handle *) pch;
357 int val, reg;
358
359 DPRINTF(("%s: tcic_isa_chip_intr_disestablish\n", h->sc->dev.dv_xname));
360
361 h->ih_irq = 0;
362
363 reg = TCIC_IR_SCF1_N(h->sock);
364 val = tcic_read_ind_2(h, reg);
365 val &= ~TCIC_SCF1_IRQ_MASK;
366 tcic_write_ind_2(h, reg, val);
367
368 isa_intr_disestablish(h->sc->intr_est, ih);
369 }
370