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