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