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