1 /* $NetBSD: depca_isa.c,v 1.8 2004/09/14 20:20:46 drochner 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. Neither the name of the University nor the names of its contributors 56 * may be used to endorse or promote products derived from this software 57 * without specific prior written permission. 58 * 59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 69 * SUCH DAMAGE. 70 * 71 * @(#)if_le.c 8.2 (Berkeley) 11/16/93 72 */ 73 74 #include <sys/cdefs.h> 75 __KERNEL_RCSID(0, "$NetBSD: depca_isa.c,v 1.8 2004/09/14 20:20:46 drochner Exp $"); 76 77 #include "opt_inet.h" 78 #include "bpfilter.h" 79 80 #include <sys/param.h> 81 #include <sys/systm.h> 82 #include <sys/mbuf.h> 83 #include <sys/syslog.h> 84 #include <sys/socket.h> 85 #include <sys/device.h> 86 87 #include <net/if.h> 88 #include <net/if_ether.h> 89 #include <net/if_media.h> 90 91 #ifdef INET 92 #include <netinet/in.h> 93 #include <netinet/if_inarp.h> 94 #endif 95 96 #include <machine/cpu.h> 97 #include <machine/intr.h> 98 #include <machine/bus.h> 99 100 #include <dev/isa/isareg.h> 101 #include <dev/isa/isavar.h> 102 103 #include <dev/ic/lancereg.h> 104 #include <dev/ic/lancevar.h> 105 #include <dev/ic/am7990reg.h> 106 #include <dev/ic/am7990var.h> 107 #include <dev/ic/depcareg.h> 108 #include <dev/ic/depcavar.h> 109 110 int depca_isa_probe(struct device *, struct cfdata *, void *); 111 void depca_isa_attach(struct device *, struct device *, void *); 112 113 struct depca_isa_softc { 114 struct depca_softc sc_depca; 115 isa_chipset_tag_t sc_ic; 116 int sc_irq; 117 }; 118 119 CFATTACH_DECL(depca_isa, sizeof(struct depca_isa_softc), 120 depca_isa_probe, depca_isa_attach, NULL, NULL); 121 122 void *depca_isa_intr_establish(struct depca_softc *, struct lance_softc *); 123 124 int 125 depca_isa_probe(struct device *parent, struct cfdata *match, void *aux) 126 { 127 struct isa_attach_args *ia = aux; 128 bus_space_tag_t iot = ia->ia_iot; 129 bus_space_handle_t ioh; 130 bus_space_handle_t memh; 131 int rv = 0; 132 133 if (ia->ia_nio < 1) 134 return (0); 135 if (ia->ia_niomem < 1) 136 return (0); 137 if (ia->ia_nirq < 1) 138 return (0); 139 140 if (ISA_DIRECT_CONFIG(ia)) 141 return (0); 142 143 if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) 144 return (0); 145 146 /* Disallow impossible i/o address. */ 147 if (ia->ia_io[0].ir_addr != 0x200 && ia->ia_io[0].ir_addr != 0x300) 148 return (0); 149 150 /* Map i/o space. */ 151 if (bus_space_map(iot, ia->ia_io[0].ir_addr, 16, 0, &ioh)) 152 return 0; 153 154 if (ia->ia_iomem[0].ir_addr == ISA_UNKNOWN_IOMEM || 155 (ia->ia_iomem[0].ir_size != 32*1024 && 156 ia->ia_iomem[0].ir_size != 64*1024)) 157 goto bad; 158 159 /* Map card RAM. */ 160 if (bus_space_map(ia->ia_memt, ia->ia_iomem[0].ir_addr, 161 ia->ia_iomem[0].ir_size, 0, &memh)) 162 goto bad; 163 164 /* Just needed to check mapability; don't need it anymore. */ 165 bus_space_unmap(ia->ia_memt, memh, ia->ia_iomem[0].ir_size); 166 167 /* Stop the LANCE chip and put it in a known state. */ 168 bus_space_write_2(iot, ioh, DEPCA_RAP, LE_CSR0); 169 bus_space_write_2(iot, ioh, DEPCA_RDP, LE_C0_STOP); 170 delay(100); 171 172 bus_space_write_2(iot, ioh, DEPCA_RAP, LE_CSR0); 173 if (bus_space_read_2(iot, ioh, DEPCA_RDP) != LE_C0_STOP) 174 goto bad; 175 176 bus_space_write_2(iot, ioh, DEPCA_RAP, LE_CSR3); 177 bus_space_write_2(iot, ioh, DEPCA_RDP, LE_C3_ACON); 178 179 bus_space_write_1(iot, ioh, DEPCA_CSR, DEPCA_CSR_DUM); 180 181 if (depca_readprom(iot, ioh, NULL)) 182 goto bad; 183 184 ia->ia_nio = 1; 185 ia->ia_io[0].ir_size = 16; 186 187 ia->ia_niomem = 1; 188 189 ia->ia_nirq = 1; 190 191 ia->ia_ndrq = 0; 192 193 rv = 1; 194 195 bad: 196 bus_space_unmap(iot, ioh, 16); 197 return (rv); 198 } 199 200 void 201 depca_isa_attach(struct device *parent, struct device *self, void *aux) 202 { 203 struct depca_softc *sc = (void *) self; 204 struct depca_isa_softc *isc = (void *) self; 205 struct isa_attach_args *ia = aux; 206 207 printf("\n"); 208 209 sc->sc_iot = ia->ia_iot; 210 sc->sc_memt = ia->ia_memt; 211 212 sc->sc_memsize = ia->ia_iomem[0].ir_size; 213 214 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, 16, 215 0, &sc->sc_ioh) != 0) { 216 printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname); 217 return; 218 } 219 if (bus_space_map(sc->sc_memt, ia->ia_iomem[0].ir_addr, 220 ia->ia_iomem[0].ir_size, 0, &sc->sc_memh) != 0) { 221 printf("%s: unable to map memory space\n", sc->sc_dev.dv_xname); 222 return; 223 } 224 225 isc->sc_ic = ia->ia_ic; 226 isc->sc_irq = ia->ia_irq[0].ir_irq; 227 sc->sc_intr_establish = depca_isa_intr_establish; 228 229 depca_attach(sc); 230 } 231 232 void * 233 depca_isa_intr_establish(struct depca_softc *parent, struct lance_softc *child) 234 { 235 struct depca_isa_softc *isc = (void *) parent; 236 void *rv; 237 238 rv = isa_intr_establish(isc->sc_ic, isc->sc_irq, IST_EDGE, 239 IPL_NET, depca_intredge, child); 240 if (rv == NULL) 241 printf("%s: unable to establish interrupt\n", 242 parent->sc_dev.dv_xname); 243 244 return (rv); 245 } 246