smcphy.c (215297) | smcphy.c (221407) |
---|---|
1/*- 2 * Copyright (c) 2006 Benno Rice. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 9 unchanged lines hidden (view full) --- 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2006 Benno Rice. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. --- 9 unchanged lines hidden (view full) --- 18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 */ 24 25#include <sys/cdefs.h> |
26__FBSDID("$FreeBSD: head/sys/dev/mii/smcphy.c 215297 2010-11-14 13:26:10Z marius $"); | 26__FBSDID("$FreeBSD: head/sys/dev/mii/smcphy.c 221407 2011-05-03 19:51:29Z marius $"); |
27 28/* 29 * Driver for the internal PHY on the SMSC LAN91C111. 30 */ 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> --- 13 unchanged lines hidden (view full) --- 48#include "miidevs.h" 49 50#include "miibus_if.h" 51 52static int smcphy_probe(device_t); 53static int smcphy_attach(device_t); 54 55static int smcphy_service(struct mii_softc *, struct mii_data *, int); | 27 28/* 29 * Driver for the internal PHY on the SMSC LAN91C111. 30 */ 31 32#include <sys/param.h> 33#include <sys/systm.h> 34#include <sys/kernel.h> --- 13 unchanged lines hidden (view full) --- 48#include "miidevs.h" 49 50#include "miibus_if.h" 51 52static int smcphy_probe(device_t); 53static int smcphy_attach(device_t); 54 55static int smcphy_service(struct mii_softc *, struct mii_data *, int); |
56static int smcphy_reset(struct mii_softc *); | 56static void smcphy_reset(struct mii_softc *); |
57static void smcphy_auto(struct mii_softc *, int); 58 59static device_method_t smcphy_methods[] = { 60 /* device interface */ 61 DEVMETHOD(device_probe, smcphy_probe), 62 DEVMETHOD(device_attach, smcphy_attach), 63 DEVMETHOD(device_detach, mii_phy_detach), 64 DEVMETHOD(device_shutdown, bus_generic_shutdown), --- 7 unchanged lines hidden (view full) --- 72 "smcphy", 73 smcphy_methods, 74 sizeof(struct mii_softc) 75}; 76 77DRIVER_MODULE(smcphy, miibus, smcphy_driver, smcphy_devclass, 0, 0); 78 79static const struct mii_phydesc smcphys[] = { | 57static void smcphy_auto(struct mii_softc *, int); 58 59static device_method_t smcphy_methods[] = { 60 /* device interface */ 61 DEVMETHOD(device_probe, smcphy_probe), 62 DEVMETHOD(device_attach, smcphy_attach), 63 DEVMETHOD(device_detach, mii_phy_detach), 64 DEVMETHOD(device_shutdown, bus_generic_shutdown), --- 7 unchanged lines hidden (view full) --- 72 "smcphy", 73 smcphy_methods, 74 sizeof(struct mii_softc) 75}; 76 77DRIVER_MODULE(smcphy, miibus, smcphy_driver, smcphy_devclass, 0, 0); 78 79static const struct mii_phydesc smcphys[] = { |
80 MII_PHY_DESC(SMSC, LAN83C183), | 80 MII_PHY_DESC(SEEQ, 84220), |
81 MII_PHY_END 82}; 83 | 81 MII_PHY_END 82}; 83 |
84static const struct mii_phy_funcs smcphy_funcs = { 85 smcphy_service, 86 ukphy_status, 87 smcphy_reset 88}; 89 |
|
84static int 85smcphy_probe(device_t dev) 86{ 87 88 return (mii_phy_dev_probe(dev, smcphys, BUS_PROBE_DEFAULT)); 89} 90 91static int 92smcphy_attach(device_t dev) 93{ | 90static int 91smcphy_probe(device_t dev) 92{ 93 94 return (mii_phy_dev_probe(dev, smcphys, BUS_PROBE_DEFAULT)); 95} 96 97static int 98smcphy_attach(device_t dev) 99{ |
94 struct mii_softc *sc; 95 struct mii_attach_args *ma; 96 struct mii_data *mii; | 100 struct mii_softc *sc; |
97 98 sc = device_get_softc(dev); | 101 102 sc = device_get_softc(dev); |
99 ma = device_get_ivars(dev); 100 sc->mii_dev = device_get_parent(dev); 101 mii = ma->mii_data; 102 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); | |
103 | 103 |
104 sc->mii_flags = miibus_get_flags(dev); 105 sc->mii_inst = mii->mii_instance++; 106 sc->mii_phy = ma->mii_phyno; 107 sc->mii_service = smcphy_service; 108 sc->mii_pdata = mii; 109 110 sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP; 111 112 if (smcphy_reset(sc) != 0) { 113 device_printf(dev, "reset failed\n"); 114 } 115 116 /* Mask interrupts, we poll instead. */ 117 PHY_WRITE(sc, 0x1e, 0xffc0); 118 119 sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask; 120 device_printf(dev, " "); 121 mii_phy_add_media(sc); 122 printf("\n"); 123 124 MIIBUS_MEDIAINIT(sc->mii_dev); | 104 mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE, 105 &smcphy_funcs, 1); |
125 mii_phy_setmedia(sc); 126 127 return (0); 128} 129 130static int 131smcphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) 132{ --- 46 unchanged lines hidden (view full) --- 179 break; 180 } 181 182 if (++sc->mii_ticks <= MII_ANEGTICKS) { 183 break; 184 } 185 186 sc->mii_ticks = 0; | 106 mii_phy_setmedia(sc); 107 108 return (0); 109} 110 111static int 112smcphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) 113{ --- 46 unchanged lines hidden (view full) --- 160 break; 161 } 162 163 if (++sc->mii_ticks <= MII_ANEGTICKS) { 164 break; 165 } 166 167 sc->mii_ticks = 0; |
187 if (smcphy_reset(sc) != 0) { 188 device_printf(sc->mii_dev, "reset failed\n"); 189 } | 168 PHY_RESET(sc); |
190 smcphy_auto(sc, ife->ifm_media); 191 break; 192 } 193 194 /* Update the media status. */ | 169 smcphy_auto(sc, ife->ifm_media); 170 break; 171 } 172 173 /* Update the media status. */ |
195 ukphy_status(sc); | 174 PHY_STATUS(sc); |
196 197 /* Callback if something changed. */ 198 mii_phy_update(sc, cmd); 199 return (0); 200} 201 | 175 176 /* Callback if something changed. */ 177 mii_phy_update(sc, cmd); 178 return (0); 179} 180 |
202static int | 181static void |
203smcphy_reset(struct mii_softc *sc) 204{ 205 u_int bmcr; 206 int timeout; 207 208 PHY_WRITE(sc, MII_BMCR, BMCR_RESET); 209 210 for (timeout = 2; timeout > 0; timeout--) { 211 DELAY(50000); 212 bmcr = PHY_READ(sc, MII_BMCR); 213 if ((bmcr & BMCR_RESET) == 0) 214 break; 215 } 216 | 182smcphy_reset(struct mii_softc *sc) 183{ 184 u_int bmcr; 185 int timeout; 186 187 PHY_WRITE(sc, MII_BMCR, BMCR_RESET); 188 189 for (timeout = 2; timeout > 0; timeout--) { 190 DELAY(50000); 191 bmcr = PHY_READ(sc, MII_BMCR); 192 if ((bmcr & BMCR_RESET) == 0) 193 break; 194 } 195 |
217 if (bmcr & BMCR_RESET) { 218 return (EIO); 219 } | 196 if (bmcr & BMCR_RESET) 197 device_printf(sc->mii_dev, "reset failed\n"); |
220 221 PHY_WRITE(sc, MII_BMCR, 0x3000); | 198 199 PHY_WRITE(sc, MII_BMCR, 0x3000); |
222 return (0); | 200 201 /* Mask interrupts, we poll instead. */ 202 PHY_WRITE(sc, 0x1e, 0xffc0); |
223} 224 225static void 226smcphy_auto(struct mii_softc *sc, int media) 227{ 228 uint16_t anar; 229 230 anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | 231 ANAR_CSMA; 232 if ((media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0) 233 anar |= ANAR_FC; 234 PHY_WRITE(sc, MII_ANAR, anar); 235 /* Apparently this helps. */ 236 anar = PHY_READ(sc, MII_ANAR); 237 PHY_WRITE(sc, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG); 238} | 203} 204 205static void 206smcphy_auto(struct mii_softc *sc, int media) 207{ 208 uint16_t anar; 209 210 anar = BMSR_MEDIA_TO_ANAR(sc->mii_capabilities) | 211 ANAR_CSMA; 212 if ((media & IFM_FLOW) != 0 || (sc->mii_flags & MIIF_FORCEPAUSE) != 0) 213 anar |= ANAR_FC; 214 PHY_WRITE(sc, MII_ANAR, anar); 215 /* Apparently this helps. */ 216 anar = PHY_READ(sc, MII_ANAR); 217 PHY_WRITE(sc, MII_BMCR, BMCR_AUTOEN | BMCR_STARTNEG); 218} |