1 /* $NetBSD: if_tscs_isa.c,v 1.15 2012/02/02 19:43:04 tls Exp $ */ 2 3 /*- 4 * Copyright (c) 2005 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jesse Off 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: if_tscs_isa.c,v 1.15 2012/02/02 19:43:04 tls Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/socket.h> 38 #include <sys/device.h> 39 40 #include <sys/rnd.h> 41 42 #include <net/if.h> 43 #include <net/if_ether.h> 44 #include <net/if_media.h> 45 46 #include <sys/bus.h> 47 #include <sys/intr.h> 48 49 #include <dev/isa/isareg.h> 50 #include <dev/isa/isavar.h> 51 #include <dev/isa/isadmavar.h> 52 53 #include <dev/ic/cs89x0reg.h> 54 #include <dev/ic/cs89x0var.h> 55 #include <dev/isa/cs89x0isavar.h> 56 57 static int tscs_isa_probe(device_t, cfdata_t, void *); 58 static void tscs_isa_attach(device_t, device_t, void *); 59 60 CFATTACH_DECL_NEW(tscs_isa, sizeof(struct cs_softc_isa), 61 tscs_isa_probe, tscs_isa_attach, NULL, NULL); 62 63 int 64 tscs_isa_probe(device_t parent, cfdata_t cf, void *aux) 65 { 66 struct isa_attach_args *ia = aux; 67 bus_space_tag_t iot = ia->ia_iot; 68 bus_space_handle_t ioh, pldh; 69 struct cs_softc sc; 70 int rv = 0, have_io = 0, have_pld = 0, irq; 71 u_int8_t jpcfg; 72 73 if (ia->ia_nio < 1) 74 return (0); 75 if (ia->ia_nirq < 1) 76 return (0); 77 78 if (ISA_DIRECT_CONFIG(ia)) 79 return (0); 80 81 /* 82 * Disallow wildcarded I/O base. 83 */ 84 if (ia->ia_io[0].ir_addr == ISA_UNKNOWN_PORT) 85 return (0); 86 87 /* 88 * Map the I/O space. 89 */ 90 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr - 0x300, 9, 91 0, &pldh)) 92 goto out; 93 have_pld = 1; 94 95 if ((bus_space_read_1(ia->ia_iot, pldh, 0) & 0xf) == 0xa && 96 (bus_space_read_1(ia->ia_iot, pldh, 0x8) & 0xf) == 0x5 && 97 (bus_space_read_1(ia->ia_iot, pldh, 0x8) & 0xf) == 0xa) { 98 bus_space_read_1(ia->ia_iot, pldh, 0x8); /* PLD rev. */ 99 jpcfg = bus_space_read_1(ia->ia_iot, pldh, 0x8) & 0xf; 100 } else { 101 goto out; 102 } 103 104 if (bus_space_map(ia->ia_iot, ia->ia_io[0].ir_addr, CS8900_IOSIZE, 105 0, &ioh)) 106 goto out; 107 have_io = 1; 108 109 memset(&sc, 0, sizeof sc); 110 sc.sc_iot = iot; 111 sc.sc_ioh = ioh; 112 /* Verify that it's a Crystal product. */ 113 if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) != 114 EISA_NUM_CRYSTAL) 115 goto out; 116 117 /* 118 * Verify that it's a supported chip. 119 */ 120 switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) & 121 PROD_ID_MASK) { 122 case PROD_ID_CS8900: 123 break; 124 default: 125 /* invalid product ID */ 126 goto out; 127 } 128 129 /* 130 * If the IRQ wasn't specified, get it from the EEPROM. 131 */ 132 if (ia->ia_irq[0].ir_irq == ISA_UNKNOWN_IRQ) { 133 switch (jpcfg >> 1) { 134 case 0x1: 135 irq = 5; 136 break; 137 case 0x2: 138 irq = 6; 139 break; 140 case 0x4: 141 irq = 7; 142 break; 143 default: 144 goto out; 145 } 146 } else 147 irq = ia->ia_irq[0].ir_irq; 148 149 ia->ia_nio = 1; 150 ia->ia_io[0].ir_size = CS8900_IOSIZE; 151 ia->ia_niomem = 0; 152 ia->ia_nirq = 1; 153 ia->ia_ndrq = 0; 154 ia->ia_irq[0].ir_irq = irq; 155 156 rv = 1; 157 158 out: 159 if (have_io) 160 bus_space_unmap(iot, ioh, CS8900_IOSIZE); 161 if (have_pld) 162 bus_space_unmap(iot, pldh, 0x9); 163 164 return (rv); 165 } 166 167 void 168 tscs_isa_attach(device_t parent, device_t self, void *aux) 169 { 170 struct cs_softc_isa *isc = device_private(self); 171 struct cs_softc *sc = &isc->sc_cs; 172 struct isa_attach_args *ia = aux; 173 174 sc->sc_dev = self; 175 isc->sc_ic = ia->ia_ic; 176 sc->sc_iot = ia->ia_iot; 177 sc->sc_memt = ia->ia_memt; 178 179 isc->sc_drq = -1; 180 sc->sc_irq = ia->ia_irq[0].ir_irq; 181 182 printf(": Technologic Systems TS-ETH10\n"); 183 184 /* 185 * Map the device. 186 */ 187 if (bus_space_map(sc->sc_iot, ia->ia_io[0].ir_addr, CS8900_IOSIZE, 188 0, &sc->sc_ioh)) { 189 aprint_error_dev(self, "unable to map i/o space\n"); 190 return; 191 } 192 193 sc->sc_ih = isa_intr_establish(ia->ia_ic, sc->sc_irq, IST_EDGE, 194 IPL_NET, cs_intr, sc); 195 if (sc->sc_ih == NULL) { 196 aprint_error_dev(self, "unable to establish interrupt\n"); 197 return; 198 } 199 200 sc->sc_dma_chipinit = NULL; 201 sc->sc_dma_attach = NULL; 202 sc->sc_dma_process_rx = NULL; 203 204 /* all jumper routed IRQs are connected to pseudo CS8900 IRQ 5 */ 205 sc->sc_irq = 5; 206 207 cs_attach(sc, NULL, NULL, 0, 0); 208 } 209