Home | History | Annotate | Line # | Download | only in isa
i82365_isa.c revision 1.17
      1 /*	$NetBSD: i82365_isa.c,v 1.17 2002/01/07 21:47:05 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. All advertising materials mentioning features or use of this software
     15  *    must display the following acknowledgement:
     16  *	This product includes software developed by Marc Horowitz.
     17  * 4. The name of the author may not be used to endorse or promote products
     18  *    derived from this software without specific prior written permission.
     19  *
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     21  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     22  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     23  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     24  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     25  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     26  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     27  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     28  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     29  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 __KERNEL_RCSID(0, "$NetBSD: i82365_isa.c,v 1.17 2002/01/07 21:47:05 thorpej Exp $");
     34 
     35 #define	PCICISADEBUG
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 #include <sys/device.h>
     40 #include <sys/extent.h>
     41 #include <sys/malloc.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/pcmcia/pcmciareg.h>
     50 #include <dev/pcmcia/pcmciavar.h>
     51 #include <dev/pcmcia/pcmciachip.h>
     52 
     53 #include <dev/ic/i82365reg.h>
     54 #include <dev/ic/i82365var.h>
     55 #include <dev/isa/i82365_isavar.h>
     56 
     57 #ifdef PCICISADEBUG
     58 int	pcicisa_debug = 0;
     59 #define	DPRINTF(arg) if (pcicisa_debug) printf arg;
     60 #else
     61 #define	DPRINTF(arg)
     62 #endif
     63 
     64 int	pcic_isa_probe __P((struct device *, struct cfdata *, void *));
     65 void	pcic_isa_attach __P((struct device *, struct device *, void *));
     66 
     67 struct cfattach pcic_isa_ca = {
     68 	sizeof(struct pcic_isa_softc), pcic_isa_probe, pcic_isa_attach
     69 };
     70 
     71 static struct pcmcia_chip_functions pcic_isa_functions = {
     72 	pcic_chip_mem_alloc,
     73 	pcic_chip_mem_free,
     74 	pcic_chip_mem_map,
     75 	pcic_chip_mem_unmap,
     76 
     77 	pcic_chip_io_alloc,
     78 	pcic_chip_io_free,
     79 	pcic_chip_io_map,
     80 	pcic_chip_io_unmap,
     81 
     82 	pcic_isa_chip_intr_establish,
     83 	pcic_isa_chip_intr_disestablish,
     84 
     85 	pcic_chip_socket_enable,
     86 	pcic_chip_socket_disable,
     87 };
     88 
     89 int
     90 pcic_isa_probe(parent, match, aux)
     91 	struct device *parent;
     92 	struct cfdata *match;
     93 	void *aux;
     94 {
     95 	struct isa_attach_args *ia = aux;
     96 	bus_space_tag_t iot = ia->ia_iot;
     97 	bus_space_handle_t ioh, memh;
     98 	int val, found, msize;
     99 
    100 	if (ia->ia_nio < 1)
    101 		return (0);
    102 	if (ia->ia_niomem < 1)
    103 		return (0);
    104 
    105 	if (ISA_DIRECT_CONFIG(ia))
    106 		return (0);
    107 
    108 	/* Disallow wildcarded i/o address. */
    109 	if (ia->ia_io[0].ir_addr == ISACF_PORT_DEFAULT)
    110 		return (0);
    111 	if (ia->ia_iomem[0].ir_addr == ISACF_IOMEM_DEFAULT)
    112 		return (0);
    113 
    114 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, PCIC_IOSIZE, 0, &ioh))
    115 		return (0);
    116 
    117 	if (ia->ia_iomem[0].ir_size == ISACF_IOSIZ_DEFAULT)
    118 		msize = PCIC_MEMSIZE;
    119 	else
    120 		msize = ia->ia_iomem[0].ir_size;
    121 
    122 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
    123 	    msize, 0, &memh)) {
    124 		bus_space_unmap(iot, ioh, PCIC_IOSIZE);
    125 		return (0);
    126 	}
    127 
    128 	found = 0;
    129 
    130 	/*
    131 	 * this could be done with a loop, but it would violate the
    132 	 * abstraction
    133 	 */
    134 
    135 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SA + PCIC_IDENT);
    136 
    137 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    138 
    139 	if (pcic_ident_ok(val))
    140 		found++;
    141 
    142 
    143 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SB + PCIC_IDENT);
    144 
    145 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    146 
    147 	if (pcic_ident_ok(val))
    148 		found++;
    149 
    150 
    151 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SA + PCIC_IDENT);
    152 
    153 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    154 
    155 	if (pcic_ident_ok(val))
    156 		found++;
    157 
    158 
    159 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SB + PCIC_IDENT);
    160 
    161 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    162 
    163 	if (pcic_ident_ok(val))
    164 		found++;
    165 
    166 
    167 	bus_space_unmap(iot, ioh, PCIC_IOSIZE);
    168 	bus_space_unmap(ia->ia_memt, memh, msize);
    169 
    170 	if (!found)
    171 		return (0);
    172 
    173 	ia->ia_nio = 1;
    174 	ia->ia_io[0].ir_size = PCIC_IOSIZE;
    175 
    176 	ia->ia_niomem = 1;
    177 	ia->ia_iomem[0].ir_size = msize;
    178 
    179 	/* IRQ is special. */
    180 
    181 	ia->ia_ndrq = 0;
    182 
    183 	return (1);
    184 }
    185 
    186 void
    187 pcic_isa_attach(parent, self, aux)
    188 	struct device *parent, *self;
    189 	void *aux;
    190 {
    191 	struct pcic_softc *sc = (void *) self;
    192 	struct pcic_isa_softc *isc = (void *) self;
    193 	struct isa_attach_args *ia = aux;
    194 	isa_chipset_tag_t ic = ia->ia_ic;
    195 	bus_space_tag_t iot = ia->ia_iot;
    196 	bus_space_tag_t memt = ia->ia_memt;
    197 	bus_space_handle_t ioh;
    198 	bus_space_handle_t memh;
    199 
    200 	/* Map i/o space. */
    201 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, PCIC_IOSIZE, 0, &ioh)) {
    202 		printf(": can't map i/o space\n");
    203 		return;
    204 	}
    205 
    206 	/* Map mem space. */
    207 	if (bus_space_map(memt, ia->ia_iomem[0].ir_addr,
    208 	    ia->ia_iomem[0].ir_size, 0, &memh)) {
    209 		printf(": can't map mem space\n");
    210 		return;
    211 	}
    212 
    213 	sc->membase = ia->ia_iomem[0].ir_addr;
    214 	sc->subregionmask =
    215 	    (1 << (ia->ia_iomem[0].ir_size / PCIC_MEM_PAGESIZE)) - 1;
    216 
    217 	isc->sc_ic = ic;
    218 	sc->pct = (pcmcia_chipset_tag_t) & pcic_isa_functions;
    219 
    220 	sc->iot = iot;
    221 	sc->ioh = ioh;
    222 	sc->memt = memt;
    223 	sc->memh = memh;
    224 	if (ia->ia_nirq > 0)
    225 		sc->irq = ia->ia_irq[0].ir_irq;
    226 	else
    227 		sc->irq = ISACF_IRQ_DEFAULT;
    228 
    229 	printf("\n");
    230 
    231 	pcic_attach(sc);
    232 	pcic_isa_bus_width_probe(sc, iot, ioh, ia->ia_io[0].ir_addr,
    233 	    PCIC_IOSIZE);
    234 	pcic_attach_sockets(sc);
    235 
    236 	config_interrupts(self, pcic_isa_config_interrupts);
    237 }
    238