1 /*- 2 * Copyright (c) 2012 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to The NetBSD Foundation 6 * by Paul Fleischer <paul (at) xpg.dk> 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 */ 29 #include <sys/cdefs.h> 30 31 #include <sys/param.h> 32 #include <sys/systm.h> 33 #include <sys/socket.h> 34 #include <sys/device.h> 35 #include <sys/time.h> 36 37 #include <net/if.h> 38 #include <net/if_ether.h> 39 #include <net/if_media.h> 40 41 #include <sys/bus.h> 42 #include <machine/intr.h> 43 44 #include <arch/arm/s3c2xx0/s3c2440reg.h> 45 #include <arch/arm/s3c2xx0/s3c2440var.h> 46 47 #include <arch/arm/s3c2xx0/s3c2440_dma.h> 48 49 #include <dev/ic/dm9000var.h> 50 #include <dev/ic/dm9000reg.h> 51 52 #include "opt_mini2440.h" 53 54 int dme_ssextio_match(device_t, cfdata_t, void *); 55 void dme_ssextio_attach(device_t, device_t, void *); 56 57 CFATTACH_DECL_NEW(dme_ssextio, sizeof(struct dme_softc), 58 dme_ssextio_match, dme_ssextio_attach, NULL, NULL); 59 60 int 61 dme_ssextio_match(device_t parent, cfdata_t cf, void *aux) 62 { 63 struct s3c2xx0_attach_args *sa = aux; 64 bus_space_tag_t iot = sa->sa_iot; 65 bus_space_handle_t ioh; 66 vaddr_t ioaddr; 67 struct dme_softc sc; /* Used to temporarily access the device for 68 probing */ 69 int have_io = 0; 70 int result = 0; 71 uint8_t vendorId[2]; 72 uint8_t productId[2]; 73 74 /* Map memory to access the device during probing */ 75 ioaddr = sa->sa_addr; 76 if (bus_space_map(iot, ioaddr, DM9000_IOSIZE, 0, &ioh)) 77 goto out; 78 have_io = 1; 79 80 /* Zero the device description */ 81 memset(&sc, 0, sizeof sc); 82 sc.sc_iot = iot; 83 sc.sc_ioh = ioh; 84 sc.dme_io = 0x0; 85 sc.dme_data = 0x4; 86 87 vendorId[0] = dme_read(&sc, DM9000_VID0); 88 vendorId[1] = dme_read(&sc, DM9000_VID1); 89 90 productId[0] = dme_read(&sc, DM9000_PID0); 91 productId[1] = dme_read(&sc, DM9000_PID1); 92 93 if (vendorId[0] == 0x46 && vendorId[1] == 0x0a && 94 productId[0] == 0x00 && productId[1] == 0x90 ) { 95 result = 1; 96 } 97 98 out: 99 if (have_io) 100 bus_space_unmap(iot, ioh, DM9000_IOSIZE); 101 102 return result; 103 } 104 105 106 void 107 dme_ssextio_attach(device_t parent, device_t self, void *aux) 108 { 109 struct dme_softc *sc = device_private(self); 110 struct s3c2xx0_attach_args *sa = aux; 111 vaddr_t ioaddr; 112 const uint8_t *enaddr; 113 prop_data_t ea; 114 115 #ifdef MINI2440_ETHER_ADDR_FIXED 116 static uint8_t enaddr_default[ETHER_ADDR_LEN] = {MINI2440_ETHER_ADDR_FIXED}; 117 #endif 118 119 sc->sc_iot = sa->sa_iot; 120 sc->sc_dev = self; 121 122 ioaddr = sa->sa_addr; 123 if (bus_space_map(sc->sc_iot, ioaddr, DM9000_IOSIZE, 0, &sc->sc_ioh)) { 124 aprint_error(": unable to map i/o space\n"); 125 return; 126 } 127 128 129 sc->sc_ih = s3c2440_extint_establish(sa->sa_intr, IPL_NET, IST_EDGE_RISING, dme_intr, sc); 130 if (sc->sc_ih == NULL) { 131 aprint_error(": unable to establish interrupt\n"); 132 return; 133 } 134 135 sc->dme_io = 0x0; 136 sc->dme_data = 0x4; 137 138 aprint_normal("\n"); 139 140 ea = prop_dictionary_get(device_properties(self), "mac-address"); 141 if( ea != NULL ) { 142 KASSERT(prop_object_type(ea) == PROP_TYPE_DATA); 143 KASSERT(prop_data_size(ea) == ETHER_ADDR_LEN); 144 enaddr = prop_data_data_nocopy(ea); 145 } else { 146 #ifdef MINI2440_ETHER_ADDR_FIXED 147 enaddr = &enaddr_default; 148 #else 149 aprint_error_dev(self, "Unable to get mac-address property\n"); 150 return; 151 #endif 152 } 153 154 dme_attach(sc, enaddr); 155 } 156