1 /* $NetBSD: icsphy.c,v 1.41 2006/11/16 21:24:07 christos Exp $ */
4 * Copyright (c) 1998, 1999, 2000 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.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
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 THE
30 * POSSIBILITY OF SUCH DAMAGE.
34 * Copyright (c) 1997 Manuel Bouyer. All rights reserved.
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
39 * 1. Redistributions of source code must retain the above copyright
40 * notice, this list of conditions and the following disclaimer.
41 * 2. Redistributions in binary form must reproduce the above copyright
42 * notice, this list of conditions and the following disclaimer in the
43 * documentation and/or other materials provided with the distribution.
45 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
46 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
47 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
48 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
49 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
50 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
51 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
52 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
53 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
54 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 #include <sys/cdefs.h>
58 __FBSDID("$FreeBSD$");
61 * driver for Integrated Circuit Systems' ICS1889-1893 ethernet 10/100 PHY
62 * datasheet from www.icst.com
65 #include <sys/param.h>
66 #include <sys/systm.h>
67 #include <sys/kernel.h>
68 #include <sys/module.h>
69 #include <sys/socket.h>
73 #include <net/if_media.h>
75 #include <dev/mii/mii.h>
76 #include <dev/mii/miivar.h>
79 #include <dev/mii/icsphyreg.h>
81 #include "miibus_if.h"
83 static int icsphy_probe(device_t dev);
84 static int icsphy_attach(device_t dev);
86 static device_method_t icsphy_methods[] = {
87 /* device interface */
88 DEVMETHOD(device_probe, icsphy_probe),
89 DEVMETHOD(device_attach, icsphy_attach),
90 DEVMETHOD(device_detach, mii_phy_detach),
91 DEVMETHOD(device_shutdown, bus_generic_shutdown),
95 static devclass_t icsphy_devclass;
97 static driver_t icsphy_driver = {
100 sizeof(struct mii_softc)
103 DRIVER_MODULE(icsphy, miibus, icsphy_driver, icsphy_devclass, 0, 0);
105 static int icsphy_service(struct mii_softc *, struct mii_data *, int);
106 static void icsphy_status(struct mii_softc *);
107 static void icsphy_reset(struct mii_softc *);
109 static const struct mii_phydesc icsphys[] = {
110 MII_PHY_DESC(ICS, 1889),
111 MII_PHY_DESC(ICS, 1890),
112 MII_PHY_DESC(ICS, 1892),
113 MII_PHY_DESC(ICS, 1893),
117 static const struct mii_phy_funcs icsphy_funcs = {
124 icsphy_probe(device_t dev)
127 return (mii_phy_dev_probe(dev, icsphys, BUS_PROBE_DEFAULT));
131 icsphy_attach(device_t dev)
134 mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
140 icsphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
149 * If the interface is not up, don't do anything.
151 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
154 mii_phy_setmedia(sc);
158 if (mii_phy_tick(sc) == EJUSTRETURN)
163 /* Update the media status. */
166 /* Callback if something changed. */
167 mii_phy_update(sc, cmd);
172 icsphy_status(struct mii_softc *sc)
174 struct mii_data *mii = sc->mii_pdata;
175 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
178 mii->mii_media_status = IFM_AVALID;
179 mii->mii_media_active = IFM_ETHER;
182 * Don't get link from the BMSR. It's available in the QPR,
183 * and we have to read it twice to unlatch it anyhow. This
184 * gives us fewer register reads.
186 qpr = PHY_READ(sc, MII_ICSPHY_QPR); /* unlatch */
187 qpr = PHY_READ(sc, MII_ICSPHY_QPR); /* real value */
190 mii->mii_media_status |= IFM_ACTIVE;
192 bmcr = PHY_READ(sc, MII_BMCR);
193 if (bmcr & BMCR_ISO) {
194 mii->mii_media_active |= IFM_NONE;
195 mii->mii_media_status = 0;
199 if (bmcr & BMCR_LOOP)
200 mii->mii_media_active |= IFM_LOOP;
202 if (bmcr & BMCR_AUTOEN) {
203 if ((qpr & QPR_ACOMP) == 0) {
204 /* Erg, still trying, I guess... */
205 mii->mii_media_active |= IFM_NONE;
209 mii->mii_media_active |= IFM_100_TX;
211 mii->mii_media_active |= IFM_10_T;
213 mii->mii_media_active |=
214 IFM_FDX | mii_phy_flowstatus(sc);
216 mii->mii_media_active |= IFM_HDX;
218 mii->mii_media_active = ife->ifm_media;
222 icsphy_reset(struct mii_softc *sc)
226 /* set powerdown feature */
227 switch (sc->mii_mpd_model) {
228 case MII_MODEL_ICS_1890:
229 case MII_MODEL_ICS_1893:
230 PHY_WRITE(sc, MII_ICSPHY_ECR2, ECR2_100AUTOPWRDN);
232 case MII_MODEL_ICS_1892:
233 PHY_WRITE(sc, MII_ICSPHY_ECR2,
234 ECR2_10AUTOPWRDN|ECR2_100AUTOPWRDN);
237 /* 1889 have no ECR2 */
241 * There is no description that the reset do auto-negotiation in the
244 PHY_WRITE(sc, MII_BMCR, BMCR_S100|BMCR_STARTNEG|BMCR_FDX);