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