1 /* $NetBSD: acphy.c,v 1.16 2006/03/29 07:05:24 thorpej Exp $ */
4 * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
39 * $FreeBSD: src/sys/dev/mii/acphy.c,v 1.2.2.2 2002/10/21 21:20:19 semenu Exp $
43 * Copyright (c) 1997 Manuel Bouyer. All rights reserved.
45 * Redistribution and use in source and binary forms, with or without
46 * modification, are permitted provided that the following conditions
48 * 1. Redistributions of source code must retain the above copyright
49 * notice, this list of conditions and the following disclaimer.
50 * 2. Redistributions in binary form must reproduce the above copyright
51 * notice, this list of conditions and the following disclaimer in the
52 * documentation and/or other materials provided with the distribution.
53 * 3. All advertising materials mentioning features or use of this software
54 * must display the following acknowledgement:
55 * This product includes software developed by Manuel Bouyer.
56 * 4. The name of the author may not be used to endorse or promote products
57 * derived from this software without specific prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
60 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
61 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
63 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
64 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
65 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
66 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
68 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
72 * Driver for Altima AC101 10/100 PHY
75 #include <sys/param.h>
76 #include <sys/systm.h>
77 #include <sys/kernel.h>
78 #include <sys/socket.h>
79 #include <sys/errno.h>
80 #include <sys/module.h>
84 #include <net/if_media.h>
92 #include "miibus_if.h"
94 static int acphy_probe (device_t);
95 static int acphy_attach (device_t);
97 static device_method_t acphy_methods[] = {
98 /* device interface */
99 DEVMETHOD(device_probe, acphy_probe),
100 DEVMETHOD(device_attach, acphy_attach),
101 DEVMETHOD(device_detach, ukphy_detach),
102 DEVMETHOD(device_shutdown, bus_generic_shutdown),
106 static const struct mii_phydesc acphys[] = {
107 MII_PHYDESC(xxALTIMA, AC101),
108 MII_PHYDESC(xxALTIMA, AC101L),
109 MII_PHYDESC(xxALTIMA, AC_UNKNOWN),
110 MII_PHYDESC(xxALTIMA, Am79C875),
114 static devclass_t acphy_devclass;
116 static driver_t acphy_driver = {
119 sizeof(struct mii_softc)
122 DRIVER_MODULE(acphy, miibus, acphy_driver, acphy_devclass, NULL, NULL);
124 static int acphy_service(struct mii_softc *, struct mii_data *, int);
125 static void acphy_reset(struct mii_softc *);
126 static void acphy_status(struct mii_softc *);
129 acphy_probe(device_t dev)
131 struct mii_attach_args *ma = device_get_ivars(dev);
132 const struct mii_phydesc *mpd;
134 mpd = mii_phy_match(ma, acphys);
136 device_set_desc(dev, mpd->mpd_name);
143 acphy_attach(device_t dev)
145 struct mii_softc *sc;
146 struct mii_attach_args *ma;
147 struct mii_data *mii;
149 sc = device_get_softc(dev);
150 ma = device_get_ivars(dev);
151 mii_softc_init(sc, ma);
152 sc->mii_dev = device_get_parent(dev);
153 mii = device_get_softc(sc->mii_dev);
154 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
156 sc->mii_inst = mii->mii_instance;
157 sc->mii_service = acphy_service;
158 sc->mii_reset = acphy_reset;
160 sc->mii_flags |= MIIF_NOISOLATE;
166 sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
167 device_printf(dev, " ");
168 if (sc->mii_capabilities & BMSR_MEDIAMASK)
169 mii_phy_add_media(sc);
171 kprintf("no media present");
174 MIIBUS_MEDIAINIT(sc->mii_dev);
179 acphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
181 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
185 * If we're not selected, then do nothing, just isolate and power
186 * down, if changing media.
188 if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
189 if (cmd == MII_MEDIACHG) {
190 reg = PHY_READ(sc, MII_BMCR);
191 PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO | BMCR_PDOWN);
203 * If the interface is not up, don't do anything.
205 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
208 mii_phy_set_media(sc);
213 * Is the interface even up?
215 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
219 * Only used for autonegotiation.
221 if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO)
225 * This PHY's autonegotiation doesn't need to be kicked.
230 /* Update the media status. */
233 /* Callback if something changed. */
234 mii_phy_update(sc, cmd);
239 acphy_status(struct mii_softc *sc)
241 struct mii_data *mii = sc->mii_pdata;
242 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
245 mii->mii_media_status = IFM_AVALID;
246 mii->mii_media_active = IFM_ETHER;
248 bmsr = PHY_READ(sc, MII_BMSR) |
249 PHY_READ(sc, MII_BMSR);
250 if (bmsr & BMSR_LINK)
251 mii->mii_media_status |= IFM_ACTIVE;
253 bmcr = PHY_READ(sc, MII_BMCR);
254 if (bmcr & BMCR_ISO) {
255 mii->mii_media_active |= IFM_NONE;
256 mii->mii_media_status = 0;
260 if (bmcr & BMCR_LOOP)
261 mii->mii_media_active |= IFM_LOOP;
263 if (bmcr & BMCR_AUTOEN) {
266 if ((bmsr & BMSR_ACOMP) == 0) {
267 /* Erg, still trying, I guess... */
268 mii->mii_media_active |= IFM_NONE;
272 diag = PHY_READ(sc, MII_ACPHY_DIAG);
273 if (diag & AC_DIAG_SPEED)
274 mii->mii_media_active |= IFM_100_TX;
276 mii->mii_media_active |= IFM_10_T;
278 if (diag & AC_DIAG_DUPLEX)
279 mii->mii_media_active |= IFM_FDX;
281 mii->mii_media_active = ife->ifm_media;
286 acphy_reset(struct mii_softc *sc)
289 PHY_WRITE(sc, MII_ACPHY_INT, 0);