1 /* $NetBSD: if_cs_smdk24x0.c,v 1.7 2015/04/13 21:18:41 riastradh Exp $ */ 2 3 /* 4 * Copyright (c) 2003 Genetec corporation. All rights reserved. 5 * Written by Hiroyuki Bessho for Genetec corporation. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. The name of Genetec corporation may not be used to endorse 16 * or promote products derived from this software without specific prior 17 * written permission. 18 * 19 * THIS SOFTWARE IS PROVIDED BY GENETEC CORP. ``AS IS'' AND 20 * 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 GENETEC CORP. 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 /* derived from sys/dev/isa/if_cs_isa.c */ 33 /* 34 * Copyright 1997 35 * Digital Equipment Corporation. All rights reserved. 36 * 37 * This software is furnished under license and may be used and 38 * copied only in accordance with the following terms and conditions. 39 * Subject to these conditions, you may download, copy, install, 40 * use, modify and distribute this software in source and/or binary 41 * form. No title or ownership is transferred hereby. 42 * 43 * 1) Any source code used, modified or distributed must reproduce 44 * and retain this copyright notice and list of conditions as 45 * they appear in the source file. 46 * 47 * 2) No right is granted to use any trade name, trademark, or logo of 48 * Digital Equipment Corporation. Neither the "Digital Equipment 49 * Corporation" name nor any trademark or logo of Digital Equipment 50 * Corporation may be used to endorse or promote products derived 51 * from this software without the prior written permission of 52 * Digital Equipment Corporation. 53 * 54 * 3) This software is provided "AS-IS" and any express or implied 55 * warranties, including but not limited to, any implied warranties 56 * of merchantability, fitness for a particular purpose, or 57 * non-infringement are disclaimed. In no event shall DIGITAL be 58 * liable for any damages whatsoever, and in particular, DIGITAL 59 * shall not be liable for special, indirect, consequential, or 60 * incidental damages or damages for lost profits, loss of 61 * revenue or loss of use, whether such damages arise in contract, 62 * negligence, tort, under statute, in equity, at law or otherwise, 63 * even if advised of the possibility of such damage. 64 */ 65 66 /* 67 * driver for SMDK24[10]0's on-board CS8900A Ethernet 68 * 69 * CS8900A is located at CS3 area. 70 * A24=1: I/O access 71 * A24=0: Memory access 72 */ 73 74 #include <sys/cdefs.h> 75 __KERNEL_RCSID(0, "$NetBSD: if_cs_smdk24x0.c,v 1.7 2015/04/13 21:18:41 riastradh Exp $"); 76 77 #include <sys/param.h> 78 #include <sys/systm.h> 79 #include <sys/socket.h> 80 #include <sys/device.h> 81 82 #include <net/if.h> 83 #include <net/if_ether.h> 84 #include <net/if_media.h> 85 86 #include <sys/bus.h> 87 #include <machine/intr.h> 88 89 #include <arch/arm/s3c2xx0/s3c2410reg.h> 90 #include <arch/arm/s3c2xx0/s3c2410var.h> 91 92 #include <dev/ic/cs89x0reg.h> 93 #include <dev/ic/cs89x0var.h> 94 95 #include "locators.h" 96 #include "opt_smdk2xx0.h" /* SMDK24X0_ETHER_ADDR_FIXED */ 97 98 int cs_ssextio_probe(device_t, cfdata_t, void *); 99 void cs_ssextio_attach(device_t, device_t, void *); 100 101 /* 102 * I/O access is done when A24==1. 103 * default value for I/O base address is 0x300 104 */ 105 #define IOADDR(base) (base + (1<<24) + 0x0300) 106 107 CFATTACH_DECL_NEW(cs_ssextio, sizeof(struct cs_softc), 108 cs_ssextio_probe, cs_ssextio_attach, NULL, NULL); 109 110 int 111 cs_ssextio_probe(device_t parent, cfdata_t cf, void *aux) 112 { 113 struct s3c2xx0_attach_args *sa = aux; 114 bus_space_tag_t iot = sa->sa_iot; 115 bus_space_handle_t ioh; 116 struct cs_softc sc; 117 int rv = 0, have_io = 0; 118 vaddr_t ioaddr; 119 120 if (sa->sa_intr == SSEXTIOCF_INTR_DEFAULT) 121 sa->sa_intr = 9; 122 if (sa->sa_addr == SSEXTIOCF_ADDR_DEFAULT) 123 sa->sa_addr = S3C2410_BANK_START(3); 124 125 /* 126 * Map the I/O space. 127 */ 128 ioaddr = IOADDR(sa->sa_addr); 129 if (bus_space_map(iot, ioaddr, CS8900_IOSIZE, 0, &ioh)) 130 goto out; 131 have_io = 1; 132 133 memset(&sc, 0, sizeof sc); 134 sc.sc_iot = iot; 135 sc.sc_ioh = ioh; 136 137 if (0) { 138 int i; 139 140 for (i=0; i <=PKTPG_IND_ADDR; i += 2) { 141 if (i % 16 == 0) 142 printf( "\n%04x: ", i); 143 printf("%04x ", CS_READ_PACKET_PAGE_IO(&sc, i)); 144 } 145 146 } 147 148 /* Verify that it's a Crystal product. */ 149 if (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_EISA_NUM) != EISA_NUM_CRYSTAL) 150 goto out; 151 152 /* 153 * Verify that it's a supported chip. 154 */ 155 switch (CS_READ_PACKET_PAGE_IO(&sc, PKTPG_PRODUCT_ID) & PROD_ID_MASK) { 156 case PROD_ID_CS8900: 157 #ifdef notyet 158 case PROD_ID_CS8920: 159 case PROD_ID_CS8920M: 160 #endif 161 rv = 1; 162 } 163 164 out: 165 if (have_io) 166 bus_space_unmap(iot, ioh, CS8900_IOSIZE); 167 168 return (rv); 169 } 170 171 /* media selection: UTP only */ 172 static int cs_media[] = { 173 IFM_ETHER|IFM_10_T, 174 #if 0 175 IFM_ETHER|IFM_10_T|IFM_FDX, 176 #endif 177 }; 178 179 void 180 cs_ssextio_attach(device_t parent, device_t self, void *aux) 181 { 182 struct cs_softc *sc = device_private(self); 183 struct s3c2xx0_attach_args *sa = aux; 184 vaddr_t ioaddr; 185 #ifdef SMDK24X0_ETHER_ADDR_FIXED 186 static uint8_t enaddr[ETHER_ADDR_LEN] = {SMDK24X0_ETHER_ADDR_FIXED}; 187 #else 188 #define enaddr NULL 189 #endif 190 191 sc->sc_dev = self; 192 sc->sc_iot = sc->sc_memt = sa->sa_iot; 193 /* sc_irq is an IRQ number in ISA world. set 10 for INTRQ0 of CS8900A */ 194 sc->sc_irq = 10; 195 196 /* 197 * Map the device. 198 */ 199 ioaddr = IOADDR(sa->sa_addr); 200 if (bus_space_map(sc->sc_iot, ioaddr, CS8900_IOSIZE, 0, &sc->sc_ioh)) { 201 aprint_error(": unable to map i/o space\n"); 202 return; 203 } 204 205 if (bus_space_map(sc->sc_iot, sa->sa_addr, CS8900_MEMSIZE, 206 0, &sc->sc_memh)) 207 aprint_error(": unable to map memory space"); 208 else { 209 sc->sc_cfgflags |= CFGFLG_MEM_MODE; 210 sc->sc_pktpgaddr = sa->sa_addr; 211 } 212 213 /* CS8900A is very slow. (nOE->Data valid: 135ns max.) 214 We need to use IOCHRDY signal */ 215 sc->sc_cfgflags |= CFGFLG_IOCHRDY; 216 217 sc->sc_ih = s3c2410_extint_establish(sa->sa_intr, IPL_NET, IST_EDGE_RISING, 218 cs_intr, sc); 219 if (sc->sc_ih == NULL) { 220 aprint_error(": unable to establish interrupt\n"); 221 return; 222 } 223 224 aprint_normal("\n"); 225 226 /* SMDK24X0 doesn't have EEPRMO hooked to CS8900A */ 227 sc->sc_cfgflags |= CFGFLG_NOT_EEPROM; 228 229 cs_attach(sc, enaddr, cs_media, 230 sizeof(cs_media) / sizeof(cs_media[0]), IFM_ETHER|IFM_10_T); 231 } 232