Home | History | Annotate | Line # | Download | only in isa
depca_isa.c revision 1.1.8.2
      1  1.1.8.2  jdolecek /*	$NetBSD: depca_isa.c,v 1.1.8.2 2002/10/10 18:39:30 jdolecek Exp $	*/
      2      1.1   thorpej 
      3      1.1   thorpej /*-
      4      1.1   thorpej  * Copyright (c) 1997, 1998, 2000 The NetBSD Foundation, Inc.
      5      1.1   thorpej  * All rights reserved.
      6      1.1   thorpej  *
      7      1.1   thorpej  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1   thorpej  * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
      9      1.1   thorpej  * Simulation Facility, NASA Ames Research Center.
     10      1.1   thorpej  *
     11      1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     12      1.1   thorpej  * modification, are permitted provided that the following conditions
     13      1.1   thorpej  * are met:
     14      1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     15      1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     16      1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     17      1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     18      1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     19      1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     20      1.1   thorpej  *    must display the following acknowledgement:
     21      1.1   thorpej  *	This product includes software developed by the NetBSD
     22      1.1   thorpej  *	Foundation, Inc. and its contributors.
     23      1.1   thorpej  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24      1.1   thorpej  *    contributors may be used to endorse or promote products derived
     25      1.1   thorpej  *    from this software without specific prior written permission.
     26      1.1   thorpej  *
     27      1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28      1.1   thorpej  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29      1.1   thorpej  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30      1.1   thorpej  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31      1.1   thorpej  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32      1.1   thorpej  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33      1.1   thorpej  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34      1.1   thorpej  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35      1.1   thorpej  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36      1.1   thorpej  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37      1.1   thorpej  * POSSIBILITY OF SUCH DAMAGE.
     38      1.1   thorpej  */
     39      1.1   thorpej 
     40      1.1   thorpej /*-
     41      1.1   thorpej  * Copyright (c) 1992, 1993
     42      1.1   thorpej  *	The Regents of the University of California.  All rights reserved.
     43      1.1   thorpej  *
     44      1.1   thorpej  * This code is derived from software contributed to Berkeley by
     45      1.1   thorpej  * Ralph Campbell and Rick Macklem.
     46      1.1   thorpej  *
     47      1.1   thorpej  * Redistribution and use in source and binary forms, with or without
     48      1.1   thorpej  * modification, are permitted provided that the following conditions
     49      1.1   thorpej  * are met:
     50      1.1   thorpej  * 1. Redistributions of source code must retain the above copyright
     51      1.1   thorpej  *    notice, this list of conditions and the following disclaimer.
     52      1.1   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     53      1.1   thorpej  *    notice, this list of conditions and the following disclaimer in the
     54      1.1   thorpej  *    documentation and/or other materials provided with the distribution.
     55      1.1   thorpej  * 3. All advertising materials mentioning features or use of this software
     56      1.1   thorpej  *    must display the following acknowledgement:
     57      1.1   thorpej  *	This product includes software developed by the University of
     58      1.1   thorpej  *	California, Berkeley and its contributors.
     59      1.1   thorpej  * 4. Neither the name of the University nor the names of its contributors
     60      1.1   thorpej  *    may be used to endorse or promote products derived from this software
     61      1.1   thorpej  *    without specific prior written permission.
     62      1.1   thorpej  *
     63      1.1   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     64      1.1   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     65      1.1   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     66      1.1   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     67      1.1   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     68      1.1   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     69      1.1   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     70      1.1   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     71      1.1   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     72      1.1   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     73      1.1   thorpej  * SUCH DAMAGE.
     74      1.1   thorpej  *
     75      1.1   thorpej  *	@(#)if_le.c	8.2 (Berkeley) 11/16/93
     76      1.1   thorpej  */
     77      1.1   thorpej 
     78  1.1.8.1   thorpej #include <sys/cdefs.h>
     79  1.1.8.2  jdolecek __KERNEL_RCSID(0, "$NetBSD: depca_isa.c,v 1.1.8.2 2002/10/10 18:39:30 jdolecek Exp $");
     80  1.1.8.1   thorpej 
     81      1.1   thorpej #include "opt_inet.h"
     82      1.1   thorpej #include "bpfilter.h"
     83      1.1   thorpej 
     84      1.1   thorpej #include <sys/param.h>
     85      1.1   thorpej #include <sys/systm.h>
     86      1.1   thorpej #include <sys/mbuf.h>
     87      1.1   thorpej #include <sys/syslog.h>
     88      1.1   thorpej #include <sys/socket.h>
     89      1.1   thorpej #include <sys/device.h>
     90      1.1   thorpej 
     91      1.1   thorpej #include <net/if.h>
     92      1.1   thorpej #include <net/if_ether.h>
     93      1.1   thorpej #include <net/if_media.h>
     94      1.1   thorpej 
     95      1.1   thorpej #ifdef INET
     96      1.1   thorpej #include <netinet/in.h>
     97      1.1   thorpej #include <netinet/if_inarp.h>
     98      1.1   thorpej #endif
     99      1.1   thorpej 
    100      1.1   thorpej #include <machine/cpu.h>
    101      1.1   thorpej #include <machine/intr.h>
    102      1.1   thorpej #include <machine/bus.h>
    103      1.1   thorpej 
    104      1.1   thorpej #include <dev/isa/isareg.h>
    105      1.1   thorpej #include <dev/isa/isavar.h>
    106      1.1   thorpej 
    107      1.1   thorpej #include <dev/ic/lancereg.h>
    108      1.1   thorpej #include <dev/ic/lancevar.h>
    109      1.1   thorpej #include <dev/ic/am7990reg.h>
    110      1.1   thorpej #include <dev/ic/am7990var.h>
    111      1.1   thorpej #include <dev/ic/depcareg.h>
    112      1.1   thorpej #include <dev/ic/depcavar.h>
    113      1.1   thorpej 
    114      1.1   thorpej int	depca_isa_probe(struct device *, struct cfdata *, void *);
    115      1.1   thorpej void	depca_isa_attach(struct device *, struct device *, void *);
    116      1.1   thorpej 
    117      1.1   thorpej struct depca_isa_softc {
    118      1.1   thorpej 	struct depca_softc sc_depca;
    119      1.1   thorpej 	isa_chipset_tag_t sc_ic;
    120      1.1   thorpej 	int sc_irq;
    121      1.1   thorpej };
    122      1.1   thorpej 
    123  1.1.8.2  jdolecek CFATTACH_DECL(depca_isa, sizeof(struct depca_isa_softc),
    124  1.1.8.2  jdolecek     depca_isa_probe, depca_isa_attach, NULL, NULL);
    125      1.1   thorpej 
    126      1.1   thorpej void	*depca_isa_intr_establish(struct depca_softc *, struct lance_softc *);
    127      1.1   thorpej 
    128      1.1   thorpej int
    129      1.1   thorpej depca_isa_probe(struct device *parent, struct cfdata *match, void *aux)
    130      1.1   thorpej {
    131      1.1   thorpej 	struct isa_attach_args *ia = aux;
    132      1.1   thorpej 	bus_space_tag_t iot = ia->ia_iot;
    133      1.1   thorpej 	bus_space_handle_t ioh;
    134      1.1   thorpej 	bus_space_handle_t memh;
    135      1.1   thorpej 	int rv = 0;
    136      1.1   thorpej 
    137  1.1.8.1   thorpej 	if (ia->ia_nio < 1)
    138  1.1.8.1   thorpej 		return (0);
    139  1.1.8.1   thorpej 	if (ia->ia_niomem < 1)
    140  1.1.8.1   thorpej 		return (0);
    141  1.1.8.1   thorpej 	if (ia->ia_nirq < 1)
    142  1.1.8.1   thorpej 		return (0);
    143  1.1.8.1   thorpej 
    144  1.1.8.1   thorpej 	if (ISA_DIRECT_CONFIG(ia))
    145  1.1.8.1   thorpej 		return (0);
    146  1.1.8.1   thorpej 
    147  1.1.8.1   thorpej 	if (ia->ia_irq[0].ir_irq == ISACF_IRQ_DEFAULT)
    148  1.1.8.1   thorpej 		return (0);
    149  1.1.8.1   thorpej 
    150      1.1   thorpej 	/* Disallow impossible i/o address. */
    151  1.1.8.1   thorpej 	if (ia->ia_io[0].ir_addr != 0x200 && ia->ia_io[0].ir_addr != 0x300)
    152      1.1   thorpej 		return (0);
    153      1.1   thorpej 
    154      1.1   thorpej 	/* Map i/o space. */
    155  1.1.8.1   thorpej 	if (bus_space_map(iot, ia->ia_io[0].ir_addr, 16, 0, &ioh))
    156      1.1   thorpej 		return 0;
    157      1.1   thorpej 
    158  1.1.8.1   thorpej 	if (ia->ia_iomem[0].ir_addr == ISACF_IOMEM_DEFAULT ||
    159  1.1.8.1   thorpej 	    (ia->ia_iomem[0].ir_size != 32*1024 &&
    160  1.1.8.1   thorpej 	     ia->ia_iomem[0].ir_size != 64*1024))
    161      1.1   thorpej 		goto bad;
    162      1.1   thorpej 
    163      1.1   thorpej 	/* Map card RAM. */
    164  1.1.8.1   thorpej 	if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr,
    165  1.1.8.1   thorpej 	    ia->ia_iomem[0].ir_size, 0, &memh))
    166      1.1   thorpej 		goto bad;
    167      1.1   thorpej 
    168      1.1   thorpej 	/* Just needed to check mapability; don't need it anymore. */
    169  1.1.8.1   thorpej 	bus_space_unmap(ia->ia_memt, memh, ia->ia_iomem[0].ir_size);
    170      1.1   thorpej 
    171      1.1   thorpej 	/* Stop the LANCE chip and put it in a known state. */
    172      1.1   thorpej 	bus_space_write_2(iot, ioh, DEPCA_RAP, LE_CSR0);
    173      1.1   thorpej 	bus_space_write_2(iot, ioh, DEPCA_RDP, LE_C0_STOP);
    174      1.1   thorpej 	delay(100);
    175      1.1   thorpej 
    176      1.1   thorpej 	bus_space_write_2(iot, ioh, DEPCA_RAP, LE_CSR0);
    177      1.1   thorpej 	if (bus_space_read_2(iot, ioh, DEPCA_RDP) != LE_C0_STOP)
    178      1.1   thorpej 		goto bad;
    179      1.1   thorpej 
    180      1.1   thorpej 	bus_space_write_2(iot, ioh, DEPCA_RAP, LE_CSR3);
    181      1.1   thorpej 	bus_space_write_2(iot, ioh, DEPCA_RDP, LE_C3_ACON);
    182      1.1   thorpej 
    183      1.1   thorpej 	bus_space_write_1(iot, ioh, DEPCA_CSR, DEPCA_CSR_DUM);
    184      1.1   thorpej 
    185      1.1   thorpej 	if (depca_readprom(iot, ioh, NULL))
    186      1.1   thorpej 		goto bad;
    187      1.1   thorpej 
    188  1.1.8.1   thorpej 	ia->ia_nio = 1;
    189  1.1.8.1   thorpej 	ia->ia_io[0].ir_size = 16;
    190  1.1.8.1   thorpej 
    191  1.1.8.1   thorpej 	ia->ia_niomem = 1;
    192  1.1.8.1   thorpej 
    193  1.1.8.1   thorpej 	ia->ia_nirq = 1;
    194  1.1.8.1   thorpej 
    195  1.1.8.1   thorpej 	ia->ia_ndrq = 0;
    196  1.1.8.1   thorpej 
    197      1.1   thorpej 	rv = 1;
    198      1.1   thorpej 
    199      1.1   thorpej  bad:
    200      1.1   thorpej 	bus_space_unmap(iot, ioh, 16);
    201      1.1   thorpej 	return (rv);
    202      1.1   thorpej }
    203      1.1   thorpej 
    204      1.1   thorpej void
    205      1.1   thorpej depca_isa_attach(struct device *parent, struct device *self, void *aux)
    206      1.1   thorpej {
    207      1.1   thorpej 	struct depca_softc *sc = (void *) self;
    208      1.1   thorpej 	struct depca_isa_softc *isc = (void *) self;
    209      1.1   thorpej 	struct isa_attach_args *ia = aux;
    210      1.1   thorpej 
    211      1.1   thorpej 	printf("\n");
    212      1.1   thorpej 
    213      1.1   thorpej 	sc->sc_iot = ia->ia_iot;
    214      1.1   thorpej 	sc->sc_memt = ia->ia_memt;
    215      1.1   thorpej 
    216  1.1.8.1   thorpej 	sc->sc_memsize = ia->ia_iomem[0].ir_size;
    217      1.1   thorpej 
    218  1.1.8.1   thorpej 	if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 16,
    219      1.1   thorpej 	    0, &sc->sc_ioh) != 0) {
    220      1.1   thorpej 		printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
    221      1.1   thorpej 		return;
    222      1.1   thorpej 	}
    223  1.1.8.1   thorpej 	if (bus_space_map(sc->sc_memt, ia->ia_iomem[0].ir_addr,
    224  1.1.8.1   thorpej 	    ia->ia_iomem[0].ir_size, 0, &sc->sc_memh) != 0) {
    225      1.1   thorpej 		printf("%s: unable to map memory space\n", sc->sc_dev.dv_xname);
    226      1.1   thorpej 		return;
    227      1.1   thorpej 	}
    228      1.1   thorpej 
    229      1.1   thorpej 	isc->sc_ic = ia->ia_ic;
    230  1.1.8.1   thorpej 	isc->sc_irq = ia->ia_irq[0].ir_irq;
    231      1.1   thorpej 	sc->sc_intr_establish = depca_isa_intr_establish;
    232      1.1   thorpej 
    233      1.1   thorpej 	depca_attach(sc);
    234      1.1   thorpej }
    235      1.1   thorpej 
    236      1.1   thorpej void *
    237      1.1   thorpej depca_isa_intr_establish(struct depca_softc *parent, struct lance_softc *child)
    238      1.1   thorpej {
    239      1.1   thorpej 	struct depca_isa_softc *isc = (void *) parent;
    240      1.1   thorpej 	void *rv;
    241      1.1   thorpej 
    242      1.1   thorpej 	rv = isa_intr_establish(isc->sc_ic, isc->sc_irq, IST_EDGE,
    243      1.1   thorpej 	    IPL_NET, depca_intredge, child);
    244      1.1   thorpej 	if (rv == NULL)
    245      1.1   thorpej 		printf("%s: unable to establish interrupt\n",
    246      1.1   thorpej 		    parent->sc_dev.dv_xname);
    247      1.1   thorpej 
    248      1.1   thorpej 	return (rv);
    249      1.1   thorpej }
    250