2 * Copyright (c) 1998, 1999, 2000, 2001 The NetBSD Foundation, Inc.
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.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
32 * Copyright (c) 1997 Manuel Bouyer. All rights reserved.
34 * Redistribution and use in source and binary forms, with or without
35 * modification, are permitted provided that the following conditions
37 * 1. Redistributions of source code must retain the above copyright
38 * notice, this list of conditions and the following disclaimer.
39 * 2. Redistributions in binary form must reproduce the above copyright
40 * notice, this list of conditions and the following disclaimer in the
41 * documentation and/or other materials provided with the distribution.
43 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
44 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
45 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
46 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
47 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
49 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
50 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
51 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
52 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 * from: NetBSD: bmtphy.c,v 1.8 2002/07/03 06:25:50 simonb Exp
58 #include <sys/cdefs.h>
59 __FBSDID("$FreeBSD$");
62 * Driver for the Broadcom BCM5201/BCM5202 "Mini-Theta" PHYs. This also
63 * drives the PHY on the 3Com 3c905C. The 3c905C's PHY is described in
64 * the 3c905C data sheet.
67 #include <sys/param.h>
68 #include <sys/systm.h>
69 #include <sys/kernel.h>
70 #include <sys/module.h>
71 #include <sys/socket.h>
75 #include <net/if_media.h>
77 #include <dev/mii/mii.h>
78 #include <dev/mii/miivar.h>
81 #include <dev/mii/bmtphyreg.h>
83 #include "miibus_if.h"
85 static int bmtphy_probe(device_t);
86 static int bmtphy_attach(device_t);
89 struct mii_softc mii_sc;
93 static 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),
102 static devclass_t bmtphy_devclass;
104 static driver_t bmtphy_driver = {
107 sizeof(struct bmtphy_softc)
110 DRIVER_MODULE(bmtphy, miibus, bmtphy_driver, bmtphy_devclass, 0, 0);
112 static int bmtphy_service(struct mii_softc *, struct mii_data *, int);
113 static void bmtphy_status(struct mii_softc *);
114 static void bmtphy_reset(struct mii_softc *);
116 static const struct mii_phydesc bmtphys_dp[] = {
117 MII_PHY_DESC(BROADCOM, BCM4401),
118 MII_PHY_DESC(BROADCOM, BCM5201),
119 MII_PHY_DESC(BROADCOM, BCM5214),
120 MII_PHY_DESC(BROADCOM, BCM5221),
121 MII_PHY_DESC(BROADCOM, BCM5222),
125 static const struct mii_phydesc bmtphys_lp[] = {
126 MII_PHY_DESC(BROADCOM, 3C905B),
127 MII_PHY_DESC(BROADCOM, 3C905C),
132 bmtphy_probe(device_t dev)
136 /* Let exphy(4) take precedence for these. */
137 rval = mii_phy_dev_probe(dev, bmtphys_lp, BUS_PROBE_LOW_PRIORITY);
141 return (mii_phy_dev_probe(dev, bmtphys_dp, BUS_PROBE_DEFAULT));
145 bmtphy_attach(device_t dev)
147 struct bmtphy_softc *bsc;
148 struct mii_softc *sc;
149 struct mii_attach_args *ma;
150 struct mii_data *mii;
152 bsc = device_get_softc(dev);
154 ma = device_get_ivars(dev);
155 sc->mii_dev = device_get_parent(dev);
157 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
159 sc->mii_flags = miibus_get_flags(dev);
160 sc->mii_inst = mii->mii_instance++;
161 sc->mii_phy = ma->mii_phyno;
162 sc->mii_service = bmtphy_service;
165 sc->mii_flags |= MIIF_NOMANPAUSE;
167 bsc->mii_model = MII_MODEL(ma->mii_id2);
171 sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
172 device_printf(dev, " ");
173 mii_phy_add_media(sc);
176 MIIBUS_MEDIAINIT(sc->mii_dev);
182 bmtphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
191 * If the interface is not up, don't do anything.
193 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
196 mii_phy_setmedia(sc);
200 if (mii_phy_tick(sc) == EJUSTRETURN)
205 /* Update the media status. */
208 /* Callback if something changed. */
209 mii_phy_update(sc, cmd);
214 bmtphy_status(struct mii_softc *sc)
216 struct mii_data *mii;
217 struct ifmedia_entry *ife;
218 int bmsr, bmcr, aux_csr;
221 ife = mii->mii_media.ifm_cur;
223 mii->mii_media_status = IFM_AVALID;
224 mii->mii_media_active = IFM_ETHER;
226 bmsr = PHY_READ(sc, MII_BMSR) | PHY_READ(sc, MII_BMSR);
228 if (bmsr & BMSR_LINK)
229 mii->mii_media_status |= IFM_ACTIVE;
231 bmcr = PHY_READ(sc, MII_BMCR);
232 if (bmcr & BMCR_ISO) {
233 mii->mii_media_active |= IFM_NONE;
234 mii->mii_media_status = 0;
238 if (bmcr & BMCR_LOOP)
239 mii->mii_media_active |= IFM_LOOP;
241 if (bmcr & BMCR_AUTOEN) {
243 * The media status bits are only valid if autonegotiation
244 * has completed (or it's disabled).
246 if ((bmsr & BMSR_ACOMP) == 0) {
247 /* Erg, still trying, I guess... */
248 mii->mii_media_active |= IFM_NONE;
252 aux_csr = PHY_READ(sc, MII_BMTPHY_AUX_CSR);
253 if (aux_csr & AUX_CSR_SPEED)
254 mii->mii_media_active |= IFM_100_TX;
256 mii->mii_media_active |= IFM_10_T;
257 if (aux_csr & AUX_CSR_FDX)
258 mii->mii_media_active |=
259 IFM_FDX | mii_phy_flowstatus(sc);
261 mii->mii_media_active |= IFM_HDX;
263 mii->mii_media_active = ife->ifm_media;
267 bmtphy_reset(struct mii_softc *sc)
269 struct bmtphy_softc *bsc;
272 bsc = (struct bmtphy_softc *)sc;
276 if (bsc->mii_model == MII_MODEL_BROADCOM_BCM5221) {
277 /* Enable shadow register mode. */
278 data = PHY_READ(sc, 0x1f);
279 PHY_WRITE(sc, 0x1f, data | 0x0080);
281 /* Enable APD (Auto PowerDetect). */
282 data = PHY_READ(sc, MII_BMTPHY_AUX2);
283 PHY_WRITE(sc, MII_BMTPHY_AUX2, data | 0x0020);
285 /* Enable clocks across APD for Auto-MDIX functionality. */
286 data = PHY_READ(sc, MII_BMTPHY_INTR);
287 PHY_WRITE(sc, MII_BMTPHY_INTR, data | 0x0004);
289 /* Disable shadow register mode. */
290 data = PHY_READ(sc, 0x1f);
291 PHY_WRITE(sc, 0x1f, data & ~0x0080);