Home | History | Annotate | Line # | Download | only in isapnp
i82365_isapnp.c revision 1.4
      1  1.4  christos /*	$NetBSD: i82365_isapnp.c,v 1.4 1998/07/23 19:30:45 christos Exp $	*/
      2  1.1  sommerfe 
      3  1.1  sommerfe /*
      4  1.1  sommerfe  * Copyright (c) 1998 Bill Sommerfeld.  All rights reserved.
      5  1.1  sommerfe  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      6  1.1  sommerfe  *
      7  1.1  sommerfe  * Redistribution and use in source and binary forms, with or without
      8  1.1  sommerfe  * modification, are permitted provided that the following conditions
      9  1.1  sommerfe  * are met:
     10  1.1  sommerfe  * 1. Redistributions of source code must retain the above copyright
     11  1.1  sommerfe  *    notice, this list of conditions and the following disclaimer.
     12  1.1  sommerfe  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1  sommerfe  *    notice, this list of conditions and the following disclaimer in the
     14  1.1  sommerfe  *    documentation and/or other materials provided with the distribution.
     15  1.1  sommerfe  * 3. All advertising materials mentioning features or use of this software
     16  1.1  sommerfe  *    must display the following acknowledgement:
     17  1.1  sommerfe  *	This product includes software developed by Marc Horowitz.
     18  1.1  sommerfe  * 4. The name of the author may not be used to endorse or promote products
     19  1.1  sommerfe  *    derived from this software without specific prior written permission.
     20  1.1  sommerfe  *
     21  1.1  sommerfe  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.1  sommerfe  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.1  sommerfe  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.1  sommerfe  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.1  sommerfe  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.1  sommerfe  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.1  sommerfe  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.1  sommerfe  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.1  sommerfe  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.1  sommerfe  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.1  sommerfe  */
     32  1.1  sommerfe 
     33  1.1  sommerfe 
     34  1.1  sommerfe #include <sys/types.h>
     35  1.1  sommerfe #include <sys/param.h>
     36  1.1  sommerfe #include <sys/systm.h>
     37  1.1  sommerfe #include <sys/device.h>
     38  1.1  sommerfe #include <sys/extent.h>
     39  1.1  sommerfe #include <sys/malloc.h>
     40  1.1  sommerfe 
     41  1.1  sommerfe #include <vm/vm.h>
     42  1.1  sommerfe 
     43  1.1  sommerfe #include <machine/bus.h>
     44  1.1  sommerfe #include <machine/intr.h>
     45  1.1  sommerfe 
     46  1.1  sommerfe #include <dev/isa/isareg.h>
     47  1.1  sommerfe #include <dev/isa/isavar.h>
     48  1.1  sommerfe 
     49  1.1  sommerfe #include <dev/isapnp/isapnpreg.h>
     50  1.1  sommerfe #include <dev/isapnp/isapnpvar.h>
     51  1.4  christos #include <dev/isapnp/isapnpdevs.h>
     52  1.1  sommerfe 
     53  1.1  sommerfe #include <dev/pcmcia/pcmciareg.h>
     54  1.1  sommerfe #include <dev/pcmcia/pcmciavar.h>
     55  1.1  sommerfe #include <dev/pcmcia/pcmciachip.h>
     56  1.1  sommerfe 
     57  1.1  sommerfe #include <dev/ic/i82365reg.h>
     58  1.1  sommerfe #include <dev/ic/i82365var.h>
     59  1.1  sommerfe #include <dev/isa/i82365_isavar.h>
     60  1.1  sommerfe 
     61  1.1  sommerfe #undef DPRINTF
     62  1.1  sommerfe #ifdef PCICISADEBUG
     63  1.1  sommerfe int	pcicisapnp_debug = 0 /* XXX */ ;
     64  1.1  sommerfe #define	DPRINTF(arg) if (pcicisapnp_debug) printf arg;
     65  1.1  sommerfe #else
     66  1.1  sommerfe #define	DPRINTF(arg)
     67  1.1  sommerfe #endif
     68  1.1  sommerfe 
     69  1.1  sommerfe int pcic_isapnp_match __P((struct device *, struct cfdata *, void *));
     70  1.1  sommerfe void	pcic_isapnp_attach __P((struct device *, struct device *, void *));
     71  1.1  sommerfe 
     72  1.1  sommerfe struct cfattach pcic_isapnp_ca = {
     73  1.1  sommerfe 	sizeof(struct pcic_softc), pcic_isapnp_match, pcic_isapnp_attach
     74  1.1  sommerfe };
     75  1.1  sommerfe 
     76  1.1  sommerfe static struct pcmcia_chip_functions pcic_isa_functions = {
     77  1.1  sommerfe 	pcic_chip_mem_alloc,
     78  1.1  sommerfe 	pcic_chip_mem_free,
     79  1.1  sommerfe 	pcic_chip_mem_map,
     80  1.1  sommerfe 	pcic_chip_mem_unmap,
     81  1.1  sommerfe 
     82  1.1  sommerfe 	pcic_chip_io_alloc,
     83  1.1  sommerfe 	pcic_chip_io_free,
     84  1.1  sommerfe 	pcic_chip_io_map,
     85  1.1  sommerfe 	pcic_chip_io_unmap,
     86  1.1  sommerfe 
     87  1.1  sommerfe 	pcic_isa_chip_intr_establish,
     88  1.1  sommerfe 	pcic_isa_chip_intr_disestablish,
     89  1.1  sommerfe 
     90  1.1  sommerfe 	pcic_chip_socket_enable,
     91  1.1  sommerfe 	pcic_chip_socket_disable,
     92  1.1  sommerfe };
     93  1.1  sommerfe 
     94  1.1  sommerfe int
     95  1.1  sommerfe pcic_isapnp_match(parent, match, aux)
     96  1.1  sommerfe 	struct device *parent;
     97  1.1  sommerfe 	struct cfdata *match;
     98  1.1  sommerfe 	void *aux;
     99  1.1  sommerfe {
    100  1.4  christos 	return isapnp_devmatch(aux, &isapnp_pcic_devinfo);
    101  1.1  sommerfe }
    102  1.1  sommerfe 
    103  1.1  sommerfe void
    104  1.1  sommerfe pcic_isapnp_attach(parent, self, aux)
    105  1.1  sommerfe 	struct device *parent, *self;
    106  1.1  sommerfe 	void *aux;
    107  1.1  sommerfe {
    108  1.1  sommerfe 	struct pcic_softc *sc = (void *) self;
    109  1.1  sommerfe 	struct isapnp_attach_args *ipa = aux;
    110  1.1  sommerfe 	isa_chipset_tag_t ic = ipa->ipa_ic;
    111  1.1  sommerfe 	bus_space_tag_t iot = ipa->ipa_iot;
    112  1.1  sommerfe 	bus_space_tag_t memt = ipa->ipa_memt;
    113  1.1  sommerfe 	bus_space_handle_t ioh;
    114  1.1  sommerfe 	bus_space_handle_t memh;
    115  1.1  sommerfe 	bus_addr_t maddr;
    116  1.1  sommerfe 	int msize;
    117  1.1  sommerfe 	int tmp1;
    118  1.1  sommerfe 
    119  1.1  sommerfe 	printf("\n");
    120  1.1  sommerfe 
    121  1.1  sommerfe 	if (isapnp_config(iot, memt, ipa)) {
    122  1.1  sommerfe 		printf("%s: error in region allocation\n", sc->dev.dv_xname);
    123  1.1  sommerfe 		return;
    124  1.1  sommerfe 	}
    125  1.1  sommerfe 
    126  1.1  sommerfe 	printf("%s: %s %s", sc->dev.dv_xname, ipa->ipa_devident,
    127  1.1  sommerfe 	    ipa->ipa_devclass);
    128  1.1  sommerfe 
    129  1.1  sommerfe 	/* sanity check that we get at least one hunk of IO space.. */
    130  1.1  sommerfe 	if (ipa->ipa_nio < 1) {
    131  1.1  sommerfe 		printf("%s: failed to get one chunk of i/o space\n",
    132  1.1  sommerfe 		       sc->dev.dv_xname);
    133  1.1  sommerfe 		return;
    134  1.1  sommerfe 	}
    135  1.1  sommerfe 
    136  1.1  sommerfe 	/* Find i/o space. */
    137  1.1  sommerfe 	ioh = ipa->ipa_io[0].h;
    138  1.1  sommerfe 
    139  1.1  sommerfe 	/* sanity check to make sure we have a real PCIC there.. */
    140  1.1  sommerfe 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SA + PCIC_IDENT);
    141  1.1  sommerfe 	tmp1 = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    142  1.1  sommerfe 	printf("(ident 0x%x", tmp1);
    143  1.1  sommerfe 	if (pcic_ident_ok(tmp1)) {
    144  1.1  sommerfe 	  	printf(" OK)");
    145  1.1  sommerfe 	} else {
    146  1.1  sommerfe 	        printf(" Not OK)\n");
    147  1.1  sommerfe 		return;
    148  1.1  sommerfe 	}
    149  1.1  sommerfe 
    150  1.1  sommerfe 	msize =  0x4000;
    151  1.1  sommerfe 	if (isa_mem_alloc (memt, msize, msize, 0, 0,
    152  1.1  sommerfe 			   &maddr, &memh)) {
    153  1.1  sommerfe 		printf(": can't alloc mem space\n");
    154  1.1  sommerfe 		return;
    155  1.1  sommerfe 	}
    156  1.3  sommerfe 	printf(": using iomem 0x%lx iosiz 0x%x", maddr, msize);
    157  1.1  sommerfe 	sc->membase = maddr;
    158  1.1  sommerfe 	sc->subregionmask = (1 << (msize / PCIC_MEM_PAGESIZE)) - 1;
    159  1.1  sommerfe 
    160  1.1  sommerfe 	sc->intr_est = ic;
    161  1.1  sommerfe 	sc->pct = (pcmcia_chipset_tag_t) & pcic_isa_functions;
    162  1.1  sommerfe 
    163  1.1  sommerfe 	sc->iot = iot;
    164  1.1  sommerfe 	sc->ioh = ioh;
    165  1.1  sommerfe 	sc->memt = memt;
    166  1.1  sommerfe 	sc->memh = memh;
    167  1.1  sommerfe 
    168  1.1  sommerfe 	/*
    169  1.1  sommerfe 	 * allocate an irq.  it will be used by both controllers.  I could
    170  1.1  sommerfe 	 * use two different interrupts, but interrupts are relatively
    171  1.1  sommerfe 	 * scarce, shareable, and for PCIC controllers, very infrequent.
    172  1.1  sommerfe 	 */
    173  1.1  sommerfe 
    174  1.1  sommerfe 	if (ipa->ipa_nirq > 0) {
    175  1.1  sommerfe 		sc->irq = ipa->ipa_irq[0].num;
    176  1.1  sommerfe 	} else {
    177  1.1  sommerfe 		if (isa_intr_alloc(ic,
    178  1.1  sommerfe 				   PCIC_CSC_INTR_IRQ_VALIDMASK & pcic_isa_intr_alloc_mask,
    179  1.1  sommerfe 				   IST_EDGE, &sc->irq)) {
    180  1.1  sommerfe 			printf("\n%s: can't allocate interrupt\n",
    181  1.1  sommerfe 			       sc->dev.dv_xname);
    182  1.1  sommerfe 			return;
    183  1.1  sommerfe 		}
    184  1.1  sommerfe 		printf(" irq %d", sc->irq);
    185  1.1  sommerfe 	}
    186  1.1  sommerfe 	printf("\n");
    187  1.1  sommerfe 
    188  1.1  sommerfe 	pcic_attach(sc);
    189  1.1  sommerfe 
    190  1.1  sommerfe 	pcic_isa_bus_width_probe(sc, iot, ioh, ipa->ipa_io[0].base, ipa->ipa_io[0].length);
    191  1.1  sommerfe 
    192  1.1  sommerfe 	sc->ih = isa_intr_establish(ic, sc->irq, IST_EDGE, IPL_TTY,
    193  1.1  sommerfe 	    pcic_intr, sc);
    194  1.1  sommerfe 	if (sc->ih == NULL) {
    195  1.1  sommerfe 		printf("%s: can't establish interrupt\n", sc->dev.dv_xname);
    196  1.1  sommerfe 		return;
    197  1.1  sommerfe 	}
    198  1.1  sommerfe 
    199  1.1  sommerfe 	pcic_attach_sockets(sc);
    200  1.1  sommerfe 
    201  1.1  sommerfe }
    202