2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
37 * driver for AMD AM79c873 PHYs
38 * This driver also works for Davicom DM910{1,2} PHYs, which appear
39 * to be AM79c873 workalikes.
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
45 #include <sys/module.h>
46 #include <sys/socket.h>
50 #include <net/if_media.h>
52 #include <dev/mii/mii.h>
53 #include <dev/mii/miivar.h>
56 #include <dev/mii/amphyreg.h>
58 #include "miibus_if.h"
60 static int amphy_probe(device_t);
61 static int amphy_attach(device_t);
63 static device_method_t amphy_methods[] = {
64 /* device interface */
65 DEVMETHOD(device_probe, amphy_probe),
66 DEVMETHOD(device_attach, amphy_attach),
67 DEVMETHOD(device_detach, mii_phy_detach),
68 DEVMETHOD(device_shutdown, bus_generic_shutdown),
72 static devclass_t amphy_devclass;
74 static driver_t amphy_driver = {
77 sizeof(struct mii_softc)
80 DRIVER_MODULE(amphy, miibus, amphy_driver, amphy_devclass, 0, 0);
82 static int amphy_service(struct mii_softc *, struct mii_data *, int);
83 static void amphy_status(struct mii_softc *);
85 static const struct mii_phydesc amphys[] = {
86 MII_PHY_DESC(xxDAVICOM, DM9102),
87 MII_PHY_DESC(xxDAVICOM, DM9101),
88 MII_PHY_DESC(yyDAVICOM, DM9101),
92 static const struct mii_phy_funcs amphy_funcs = {
99 amphy_probe(device_t dev)
102 return (mii_phy_dev_probe(dev, amphys, BUS_PROBE_DEFAULT));
106 amphy_attach(device_t dev)
109 mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &hy_funcs, 1);
114 amphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
123 * If the interface is not up, don't do anything.
125 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
128 mii_phy_setmedia(sc);
132 if (mii_phy_tick(sc) == EJUSTRETURN)
137 /* Update the media status. */
140 /* Callback if something changed. */
141 mii_phy_update(sc, cmd);
146 amphy_status(struct mii_softc *sc)
148 struct mii_data *mii = sc->mii_pdata;
149 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
150 int bmsr, bmcr, par, anlpar;
152 mii->mii_media_status = IFM_AVALID;
153 mii->mii_media_active = IFM_ETHER;
155 bmsr = PHY_READ(sc, MII_BMSR) |
156 PHY_READ(sc, MII_BMSR);
157 if (bmsr & BMSR_LINK)
158 mii->mii_media_status |= IFM_ACTIVE;
160 bmcr = PHY_READ(sc, MII_BMCR);
161 if (bmcr & BMCR_ISO) {
162 mii->mii_media_active |= IFM_NONE;
163 mii->mii_media_status = 0;
167 if (bmcr & BMCR_LOOP)
168 mii->mii_media_active |= IFM_LOOP;
170 if (bmcr & BMCR_AUTOEN) {
172 * The PAR status bits are only valid if autonegotiation
173 * has completed (or it's disabled).
175 if ((bmsr & BMSR_ACOMP) == 0) {
176 /* Erg, still trying, I guess... */
177 mii->mii_media_active |= IFM_NONE;
181 if (PHY_READ(sc, MII_ANER) & ANER_LPAN) {
182 anlpar = PHY_READ(sc, MII_ANAR) &
183 PHY_READ(sc, MII_ANLPAR);
184 if (anlpar & ANLPAR_TX_FD)
185 mii->mii_media_active |= IFM_100_TX|IFM_FDX;
186 else if (anlpar & ANLPAR_T4)
187 mii->mii_media_active |= IFM_100_T4|IFM_HDX;
188 else if (anlpar & ANLPAR_TX)
189 mii->mii_media_active |= IFM_100_TX|IFM_HDX;
190 else if (anlpar & ANLPAR_10_FD)
191 mii->mii_media_active |= IFM_10_T|IFM_FDX;
192 else if (anlpar & ANLPAR_10)
193 mii->mii_media_active |= IFM_10_T|IFM_HDX;
195 mii->mii_media_active |= IFM_NONE;
200 * Link partner is not capable of autonegotiation.
202 par = PHY_READ(sc, MII_AMPHY_DSCSR);
203 if (par & DSCSR_100FDX)
204 mii->mii_media_active |= IFM_100_TX|IFM_FDX;
205 else if (par & DSCSR_100HDX)
206 mii->mii_media_active |= IFM_100_TX|IFM_HDX;
207 else if (par & DSCSR_10FDX)
208 mii->mii_media_active |= IFM_10_T|IFM_HDX;
209 else if (par & DSCSR_10HDX)
210 mii->mii_media_active |= IFM_10_T|IFM_HDX;
211 if ((mii->mii_media_active & IFM_FDX) != 0)
212 mii->mii_media_active |= mii_phy_flowstatus(sc);
214 mii->mii_media_active = ife->ifm_media;