1 /* $OpenBSD: ax88190.c,v 1.2 2003/06/25 17:35:36 miod Exp $ */ 2 /* $NetBSD$ */ 3 4 /*- 5 * Copyright (c) 2001 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Enami Tsugutomo. 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 #include <sys/param.h> 41 #include <sys/systm.h> 42 #include <sys/device.h> 43 #include <sys/socket.h> 44 45 #include <net/if.h> 46 #include <net/if_dl.h> 47 #include <net/if_types.h> 48 #include <net/if_media.h> 49 50 #ifdef INET 51 #include <netinet/in.h> 52 #include <netinet/in_systm.h> 53 #include <netinet/in_var.h> 54 #include <netinet/ip.h> 55 #include <netinet/if_ether.h> 56 #endif 57 58 #include <machine/bus.h> 59 60 #include <dev/mii/miivar.h> 61 #include <dev/mii/mii.h> 62 #include <dev/mii/mii_bitbang.h> 63 64 #include <dev/ic/dp8390reg.h> 65 #include <dev/ic/dp8390var.h> 66 67 #include <dev/ic/ne2000reg.h> 68 #include <dev/ic/ne2000var.h> 69 70 #include <dev/ic/ax88190reg.h> 71 #include <dev/ic/ax88190var.h> 72 73 int ax88190_mii_readreg(struct device *, int, int); 74 void ax88190_mii_writereg(struct device *, int, int, int); 75 void ax88190_mii_statchg(struct device *); 76 77 /* 78 * MII bit-bang glue. 79 */ 80 u_int32_t ax88190_mii_bitbang_read(struct device *); 81 void ax88190_mii_bitbang_write(struct device *, u_int32_t); 82 83 const struct mii_bitbang_ops ax88190_mii_bitbang_ops = { 84 ax88190_mii_bitbang_read, 85 ax88190_mii_bitbang_write, 86 { 87 AX88190_MEMR_MDO, /* MII_BIT_MDO */ 88 AX88190_MEMR_MDI, /* MII_BIT_MDI */ 89 AX88190_MEMR_MDC, /* MII_BIT_MDC */ 90 0, /* MII_BIT_DIR_HOST_PHY */ 91 AX88190_MEMR_MDIR, /* MII_BIT_DIR_PHY_HOST */ 92 } 93 }; 94 95 void 96 ax88190_media_init(struct dp8390_softc *sc) 97 { 98 struct ifnet *ifp = &sc->sc_arpcom.ac_if; 99 100 sc->sc_mii.mii_ifp = ifp; 101 sc->sc_mii.mii_readreg = ax88190_mii_readreg; 102 sc->sc_mii.mii_writereg = ax88190_mii_writereg; 103 sc->sc_mii.mii_statchg = ax88190_mii_statchg; 104 ifmedia_init(&sc->sc_mii.mii_media, 0, dp8390_mediachange, 105 dp8390_mediastatus); 106 107 mii_attach(&sc->sc_dev, &sc->sc_mii, 0xffffffff, MII_PHY_ANY, 108 MII_OFFSET_ANY, 0); 109 110 if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) { 111 ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE, 0, 112 NULL); 113 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_NONE); 114 } else 115 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO); 116 } 117 118 void 119 ax88190_media_fini(struct dp8390_softc *sc) 120 { 121 mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY); 122 } 123 124 int 125 ax88190_mediachange(struct dp8390_softc *sc) 126 { 127 mii_mediachg(&sc->sc_mii); 128 return (0); 129 } 130 131 void 132 ax88190_mediastatus(struct dp8390_softc *sc, struct ifmediareq *ifmr) 133 { 134 mii_pollstat(&sc->sc_mii); 135 ifmr->ifm_status = sc->sc_mii.mii_media_status; 136 ifmr->ifm_active = sc->sc_mii.mii_media_active; 137 } 138 139 void 140 ax88190_init_card(struct dp8390_softc *sc) 141 { 142 mii_mediachg(&sc->sc_mii); 143 } 144 145 void 146 ax88190_stop_card(struct dp8390_softc *sc) 147 { 148 mii_down(&sc->sc_mii); 149 } 150 151 u_int32_t 152 ax88190_mii_bitbang_read(self) 153 struct device *self; 154 { 155 struct ne2000_softc *sc = (void *)self; 156 157 return (bus_space_read_1(sc->sc_asict, sc->sc_asich, AX88190_MEMR)); 158 } 159 160 void 161 ax88190_mii_bitbang_write(self, val) 162 struct device *self; 163 u_int32_t val; 164 { 165 struct ne2000_softc *sc = (void *)self; 166 167 bus_space_write_1(sc->sc_asict, sc->sc_asich, AX88190_MEMR, val); 168 } 169 170 int 171 ax88190_mii_readreg(self, phy, reg) 172 struct device *self; 173 int phy, reg; 174 { 175 return (mii_bitbang_readreg(self, &ax88190_mii_bitbang_ops, phy, reg)); 176 } 177 178 void 179 ax88190_mii_writereg(self, phy, reg, val) 180 struct device *self; 181 int phy, reg, val; 182 { 183 mii_bitbang_writereg(self, &ax88190_mii_bitbang_ops, phy, reg, val); 184 } 185 186 void 187 ax88190_mii_statchg(self) 188 struct device *self; 189 { 190 /* XXX */ 191 } 192