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