Home | History | Annotate | Line # | Download | only in isa
i82365_isa.c revision 1.15
      1 /*	$NetBSD: i82365_isa.c,v 1.15 2001/11/13 08:01:14 lukem 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.15 2001/11/13 08:01:14 lukem Exp $");
     34 
     35 #define	PCICISADEBUG
     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/i82365reg.h>
     55 #include <dev/ic/i82365var.h>
     56 #include <dev/isa/i82365_isavar.h>
     57 
     58 #ifdef PCICISADEBUG
     59 int	pcicisa_debug = 0;
     60 #define	DPRINTF(arg) if (pcicisa_debug) printf arg;
     61 #else
     62 #define	DPRINTF(arg)
     63 #endif
     64 
     65 int	pcic_isa_probe __P((struct device *, struct cfdata *, void *));
     66 void	pcic_isa_attach __P((struct device *, struct device *, void *));
     67 
     68 struct cfattach pcic_isa_ca = {
     69 	sizeof(struct pcic_isa_softc), pcic_isa_probe, pcic_isa_attach
     70 };
     71 
     72 static struct pcmcia_chip_functions pcic_isa_functions = {
     73 	pcic_chip_mem_alloc,
     74 	pcic_chip_mem_free,
     75 	pcic_chip_mem_map,
     76 	pcic_chip_mem_unmap,
     77 
     78 	pcic_chip_io_alloc,
     79 	pcic_chip_io_free,
     80 	pcic_chip_io_map,
     81 	pcic_chip_io_unmap,
     82 
     83 	pcic_isa_chip_intr_establish,
     84 	pcic_isa_chip_intr_disestablish,
     85 
     86 	pcic_chip_socket_enable,
     87 	pcic_chip_socket_disable,
     88 };
     89 
     90 int
     91 pcic_isa_probe(parent, match, aux)
     92 	struct device *parent;
     93 	struct cfdata *match;
     94 	void *aux;
     95 {
     96 	struct isa_attach_args *ia = aux;
     97 	bus_space_tag_t iot = ia->ia_iot;
     98 	bus_space_handle_t ioh, memh;
     99 	int val, found;
    100 
    101 	/* Disallow wildcarded i/o address. */
    102 	if (ia->ia_iobase == ISACF_PORT_DEFAULT)
    103 		return (0);
    104 
    105 	if (bus_space_map(iot, ia->ia_iobase, PCIC_IOSIZE, 0, &ioh))
    106 		return (0);
    107 
    108 	if (ia->ia_msize == -1)
    109 		ia->ia_msize = PCIC_MEMSIZE;
    110 
    111 	if (bus_space_map(ia->ia_memt, ia->ia_maddr, ia->ia_msize, 0, &memh))
    112 		return (0);
    113 
    114 	found = 0;
    115 
    116 	/*
    117 	 * this could be done with a loop, but it would violate the
    118 	 * abstraction
    119 	 */
    120 
    121 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SA + PCIC_IDENT);
    122 
    123 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    124 
    125 	if (pcic_ident_ok(val))
    126 		found++;
    127 
    128 
    129 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C0SB + PCIC_IDENT);
    130 
    131 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    132 
    133 	if (pcic_ident_ok(val))
    134 		found++;
    135 
    136 
    137 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SA + PCIC_IDENT);
    138 
    139 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    140 
    141 	if (pcic_ident_ok(val))
    142 		found++;
    143 
    144 
    145 	bus_space_write_1(iot, ioh, PCIC_REG_INDEX, C1SB + PCIC_IDENT);
    146 
    147 	val = bus_space_read_1(iot, ioh, PCIC_REG_DATA);
    148 
    149 	if (pcic_ident_ok(val))
    150 		found++;
    151 
    152 
    153 	bus_space_unmap(iot, ioh, PCIC_IOSIZE);
    154 	bus_space_unmap(ia->ia_memt, memh, ia->ia_msize);
    155 
    156 	if (!found)
    157 		return (0);
    158 
    159 	ia->ia_iosize = PCIC_IOSIZE;
    160 
    161 	return (1);
    162 }
    163 
    164 void
    165 pcic_isa_attach(parent, self, aux)
    166 	struct device *parent, *self;
    167 	void *aux;
    168 {
    169 	struct pcic_softc *sc = (void *) self;
    170 	struct pcic_isa_softc *isc = (void *) self;
    171 	struct isa_attach_args *ia = aux;
    172 	isa_chipset_tag_t ic = ia->ia_ic;
    173 	bus_space_tag_t iot = ia->ia_iot;
    174 	bus_space_tag_t memt = ia->ia_memt;
    175 	bus_space_handle_t ioh;
    176 	bus_space_handle_t memh;
    177 
    178 	/* Map i/o space. */
    179 	if (bus_space_map(iot, ia->ia_iobase, ia->ia_iosize, 0, &ioh)) {
    180 		printf(": can't map i/o space\n");
    181 		return;
    182 	}
    183 
    184 	/* Map mem space. */
    185 	if (bus_space_map(memt, ia->ia_maddr, ia->ia_msize, 0, &memh)) {
    186 		printf(": can't map mem space\n");
    187 		return;
    188 	}
    189 
    190 	sc->membase = ia->ia_maddr;
    191 	sc->subregionmask = (1 << (ia->ia_msize / PCIC_MEM_PAGESIZE)) - 1;
    192 
    193 	isc->sc_ic = ic;
    194 	sc->pct = (pcmcia_chipset_tag_t) & pcic_isa_functions;
    195 
    196 	sc->iot = iot;
    197 	sc->ioh = ioh;
    198 	sc->memt = memt;
    199 	sc->memh = memh;
    200 	sc->irq = ia->ia_irq;
    201 
    202 	printf("\n");
    203 
    204 	pcic_attach(sc);
    205 	pcic_isa_bus_width_probe(sc, iot, ioh, ia->ia_iobase, ia->ia_iosize);
    206 	pcic_attach_sockets(sc);
    207 
    208 	config_interrupts(self, pcic_isa_config_interrupts);
    209 }
    210