bmtphy.c (a16ce54c) | bmtphy.c (3fcb7a53) |
---|---|
1/*- 2 * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to The NetBSD Foundation 6 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 7 * NASA Ames Research Center. 8 * --- 71 unchanged lines hidden (view full) --- 80 81#include <dev/mii/bmtphyreg.h> 82 83#include "miibus_if.h" 84 85static int bmtphy_probe(device_t); 86static int bmtphy_attach(device_t); 87 | 1/*- 2 * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc. 3 * All rights reserved. 4 * 5 * This code is derived from software contributed to The NetBSD Foundation 6 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 7 * NASA Ames Research Center. 8 * --- 71 unchanged lines hidden (view full) --- 80 81#include <dev/mii/bmtphyreg.h> 82 83#include "miibus_if.h" 84 85static int bmtphy_probe(device_t); 86static int bmtphy_attach(device_t); 87 |
88struct bmtphy_softc { 89 struct mii_softc mii_sc; 90 int mii_model; 91}; 92 | |
93static device_method_t bmtphy_methods[] = { 94 /* Device interface */ 95 DEVMETHOD(device_probe, bmtphy_probe), 96 DEVMETHOD(device_attach, bmtphy_attach), 97 DEVMETHOD(device_detach, mii_phy_detach), 98 DEVMETHOD(device_shutdown, bus_generic_shutdown), 99 100 { 0, 0 } 101}; 102 103static devclass_t bmtphy_devclass; 104 105static driver_t bmtphy_driver = { 106 "bmtphy", 107 bmtphy_methods, | 88static device_method_t bmtphy_methods[] = { 89 /* Device interface */ 90 DEVMETHOD(device_probe, bmtphy_probe), 91 DEVMETHOD(device_attach, bmtphy_attach), 92 DEVMETHOD(device_detach, mii_phy_detach), 93 DEVMETHOD(device_shutdown, bus_generic_shutdown), 94 95 { 0, 0 } 96}; 97 98static devclass_t bmtphy_devclass; 99 100static driver_t bmtphy_driver = { 101 "bmtphy", 102 bmtphy_methods, |
108 sizeof(struct bmtphy_softc) | 103 sizeof(struct mii_softc) |
109}; 110 111DRIVER_MODULE(bmtphy, miibus, bmtphy_driver, bmtphy_devclass, 0, 0); 112 113static int bmtphy_service(struct mii_softc *, struct mii_data *, int); 114static void bmtphy_status(struct mii_softc *); 115static void bmtphy_reset(struct mii_softc *); 116 117static const struct mii_phydesc bmtphys_dp[] = { | 104}; 105 106DRIVER_MODULE(bmtphy, miibus, bmtphy_driver, bmtphy_devclass, 0, 0); 107 108static int bmtphy_service(struct mii_softc *, struct mii_data *, int); 109static void bmtphy_status(struct mii_softc *); 110static void bmtphy_reset(struct mii_softc *); 111 112static const struct mii_phydesc bmtphys_dp[] = { |
118 MII_PHY_DESC(BROADCOM, BCM4401), 119 MII_PHY_DESC(BROADCOM, BCM5201), 120 MII_PHY_DESC(BROADCOM, BCM5214), 121 MII_PHY_DESC(BROADCOM, BCM5221), 122 MII_PHY_DESC(BROADCOM, BCM5222), | 113 MII_PHY_DESC(xxBROADCOM, BCM4401), 114 MII_PHY_DESC(xxBROADCOM, BCM5201), 115 MII_PHY_DESC(xxBROADCOM, BCM5214), 116 MII_PHY_DESC(xxBROADCOM, BCM5221), 117 MII_PHY_DESC(xxBROADCOM, BCM5222), |
123 MII_PHY_END 124}; 125 126static const struct mii_phydesc bmtphys_lp[] = { | 118 MII_PHY_END 119}; 120 121static const struct mii_phydesc bmtphys_lp[] = { |
127 MII_PHY_DESC(BROADCOM, 3C905B), 128 MII_PHY_DESC(BROADCOM, 3C905C), | 122 MII_PHY_DESC(xxBROADCOM, 3C905B), 123 MII_PHY_DESC(xxBROADCOM, 3C905C), |
129 MII_PHY_END 130}; 131 | 124 MII_PHY_END 125}; 126 |
127static const struct mii_phy_funcs bmtphy_funcs = { 128 bmtphy_service, 129 bmtphy_status, 130 bmtphy_reset 131}; 132 |
|
132static int 133bmtphy_probe(device_t dev) 134{ 135 int rval; 136 137 /* Let exphy(4) take precedence for these. */ 138 rval = mii_phy_dev_probe(dev, bmtphys_lp, BUS_PROBE_LOW_PRIORITY); 139 if (rval <= 0) 140 return (rval); 141 142 return (mii_phy_dev_probe(dev, bmtphys_dp, BUS_PROBE_DEFAULT)); 143} 144 145static int 146bmtphy_attach(device_t dev) 147{ | 133static int 134bmtphy_probe(device_t dev) 135{ 136 int rval; 137 138 /* Let exphy(4) take precedence for these. */ 139 rval = mii_phy_dev_probe(dev, bmtphys_lp, BUS_PROBE_LOW_PRIORITY); 140 if (rval <= 0) 141 return (rval); 142 143 return (mii_phy_dev_probe(dev, bmtphys_dp, BUS_PROBE_DEFAULT)); 144} 145 146static int 147bmtphy_attach(device_t dev) 148{ |
148 struct bmtphy_softc *bsc; 149 struct mii_softc *sc; 150 struct mii_attach_args *ma; 151 struct mii_data *mii; | |
152 | 149 |
153 bsc = device_get_softc(dev); 154 sc = &bsc->mii_sc; 155 ma = device_get_ivars(dev); 156 sc->mii_dev = device_get_parent(dev); 157 mii = ma->mii_data; 158 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list); 159 160 sc->mii_flags = miibus_get_flags(dev); 161 sc->mii_inst = mii->mii_instance++; 162 sc->mii_phy = ma->mii_phyno; 163 sc->mii_service = bmtphy_service; 164 sc->mii_pdata = mii; 165 166 sc->mii_flags |= MIIF_NOMANPAUSE; 167 168 bsc->mii_model = MII_MODEL(ma->mii_id2); 169 170 bmtphy_reset(sc); 171 172 sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask; 173 device_printf(dev, " "); 174 mii_phy_add_media(sc); 175 printf("\n"); 176 177 MIIBUS_MEDIAINIT(sc->mii_dev); 178 | 150 mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &bmtphy_funcs, 1); |
179 return (0); 180} 181 182static int 183bmtphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) 184{ 185 186 switch (cmd) { --- 12 unchanged lines hidden (view full) --- 199 200 case MII_TICK: 201 if (mii_phy_tick(sc) == EJUSTRETURN) 202 return (0); 203 break; 204 } 205 206 /* Update the media status. */ | 151 return (0); 152} 153 154static int 155bmtphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) 156{ 157 158 switch (cmd) { --- 12 unchanged lines hidden (view full) --- 171 172 case MII_TICK: 173 if (mii_phy_tick(sc) == EJUSTRETURN) 174 return (0); 175 break; 176 } 177 178 /* Update the media status. */ |
207 bmtphy_status(sc); | 179 PHY_STATUS(sc); |
208 209 /* Callback if something changed. */ 210 mii_phy_update(sc, cmd); 211 return (0); 212} 213 214static void 215bmtphy_status(struct mii_softc *sc) --- 46 unchanged lines hidden (view full) --- 262 mii->mii_media_active |= IFM_HDX; 263 } else 264 mii->mii_media_active = ife->ifm_media; 265} 266 267static void 268bmtphy_reset(struct mii_softc *sc) 269{ | 180 181 /* Callback if something changed. */ 182 mii_phy_update(sc, cmd); 183 return (0); 184} 185 186static void 187bmtphy_status(struct mii_softc *sc) --- 46 unchanged lines hidden (view full) --- 234 mii->mii_media_active |= IFM_HDX; 235 } else 236 mii->mii_media_active = ife->ifm_media; 237} 238 239static void 240bmtphy_reset(struct mii_softc *sc) 241{ |
270 struct bmtphy_softc *bsc; | |
271 u_int16_t data; 272 | 242 u_int16_t data; 243 |
273 bsc = (struct bmtphy_softc *)sc; 274 | |
275 mii_phy_reset(sc); 276 | 244 mii_phy_reset(sc); 245 |
277 if (bsc->mii_model == MII_MODEL_BROADCOM_BCM5221) { | 246 if (sc->mii_mpd_model == MII_MODEL_xxBROADCOM_BCM5221) { |
278 /* Enable shadow register mode. */ 279 data = PHY_READ(sc, 0x1f); 280 PHY_WRITE(sc, 0x1f, data | 0x0080); 281 282 /* Enable APD (Auto PowerDetect). */ 283 data = PHY_READ(sc, MII_BMTPHY_AUX2); 284 PHY_WRITE(sc, MII_BMTPHY_AUX2, data | 0x0020); 285 286 /* Enable clocks across APD for Auto-MDIX functionality. */ 287 data = PHY_READ(sc, MII_BMTPHY_INTR); 288 PHY_WRITE(sc, MII_BMTPHY_INTR, data | 0x0004); 289 290 /* Disable shadow register mode. */ 291 data = PHY_READ(sc, 0x1f); 292 PHY_WRITE(sc, 0x1f, data & ~0x0080); 293 } 294} | 247 /* Enable shadow register mode. */ 248 data = PHY_READ(sc, 0x1f); 249 PHY_WRITE(sc, 0x1f, data | 0x0080); 250 251 /* Enable APD (Auto PowerDetect). */ 252 data = PHY_READ(sc, MII_BMTPHY_AUX2); 253 PHY_WRITE(sc, MII_BMTPHY_AUX2, data | 0x0020); 254 255 /* Enable clocks across APD for Auto-MDIX functionality. */ 256 data = PHY_READ(sc, MII_BMTPHY_INTR); 257 PHY_WRITE(sc, MII_BMTPHY_INTR, data | 0x0004); 258 259 /* Disable shadow register mode. */ 260 data = PHY_READ(sc, 0x1f); 261 PHY_WRITE(sc, 0x1f, data & ~0x0080); 262 } 263} |