Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/mii Add a driver for the Intel IGPE1000 PHY as found...
details: https://anonhg.NetBSD.org/src/rev/442ffff09a7c
branches: trunk
changeset: 554417:442ffff09a7c
user: fvdl <fvdl%NetBSD.org@localhost>
date: Tue Oct 28 00:15:40 2003 +0000
description:
Add a driver for the Intel IGPE1000 PHY as found on 82541 and 82547 chips.
Not yet enabled anywhere.
diffstat:
sys/dev/mii/files.mii | 6 +-
sys/dev/mii/igphy.c | 403 +++++++++++++++++++++++++++++++++++++++++++++++++
sys/dev/mii/igphyreg.h | 165 ++++++++++++++++++++
3 files changed, 573 insertions(+), 1 deletions(-)
diffs (truncated from 596 to 300 lines):
diff -r 5c45b1bd532a -r 442ffff09a7c sys/dev/mii/files.mii
--- a/sys/dev/mii/files.mii Tue Oct 28 00:13:22 2003 +0000
+++ b/sys/dev/mii/files.mii Tue Oct 28 00:15:40 2003 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: files.mii,v 1.33 2002/04/17 00:35:04 thorpej Exp $
+# $NetBSD: files.mii,v 1.34 2003/10/28 00:15:40 fvdl Exp $
defflag opt_mii.h MIIVERBOSE
@@ -82,6 +82,10 @@
attach icsphy at mii
file dev/mii/icsphy.c icsphy
+device igphy: mii_phy
+attach igphy at mii
+file dev/mii/igphy.c igphy
+
device sqphy: mii_phy
attach sqphy at mii
file dev/mii/sqphy.c sqphy
diff -r 5c45b1bd532a -r 442ffff09a7c sys/dev/mii/igphy.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/mii/igphy.c Tue Oct 28 00:15:40 2003 +0000
@@ -0,0 +1,403 @@
+/* $NetBSD: igphy.c,v 1.1 2003/10/28 00:15:40 fvdl Exp $ */
+
+/*
+ * The Intel copyright applies to the analog register setup, and the
+ * (currently disabled) SmartSpeed workaround code.
+ */
+
+/*******************************************************************************
+
+ Copyright (c) 2001-2003, Intel Corporation
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ 1. Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in the
+ documentation and/or other materials provided with the distribution.
+
+ 3. Neither the name of the Intel Corporation nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+
+*******************************************************************************/
+
+
+/*-
+ * Copyright (c) 1998, 1999, 2000, 2003 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
+ * NASA Ames Research Center, and by Frank van der Linden.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: igphy.c,v 1.1 2003/10/28 00:15:40 fvdl Exp $");
+
+#include "opt_mii.h"
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/device.h>
+#include <sys/socket.h>
+#include <sys/errno.h>
+
+#include <net/if.h>
+#include <net/if_media.h>
+
+#include <dev/mii/mii.h>
+#include <dev/mii/miivar.h>
+#include <dev/mii/miidevs.h>
+
+#include <dev/mii/igphyreg.h>
+
+static void igphy_reset(struct mii_softc *);
+static void igphy_load_dspcode(struct mii_softc *);
+#if 0
+static void igphy_smartspeed_workaround(struct mii_softc *sc);
+#endif
+
+int igphymatch(struct device *, struct cfdata *, void *);
+void igphyattach(struct device *, struct device *, void *);
+
+CFATTACH_DECL(igphy, sizeof(struct mii_softc),
+ igphymatch, igphyattach, mii_phy_detach, mii_phy_activate);
+
+int igphy_service(struct mii_softc *, struct mii_data *, int);
+void igphy_status(struct mii_softc *);
+
+const struct mii_phy_funcs igphy_funcs = {
+ igphy_service, igphy_status, igphy_reset,
+};
+
+const struct mii_phydesc igphys[] = {
+ { MII_OUI_yyINTEL, MII_MODEL_yyINTEL_IGP01E1000,
+ MII_STR_yyINTEL_IGP01E1000 },
+
+ {0, 0,
+ NULL },
+};
+
+int
+igphymatch(struct device *parent, struct cfdata *match, void *aux)
+{
+ struct mii_attach_args *ma = aux;
+
+ if (mii_phy_match(ma, igphys) != NULL)
+ return 10;
+
+ return 0;
+}
+
+void
+igphyattach(struct device *parent, struct device *self, void *aux)
+{
+ struct mii_softc *sc = (struct mii_softc *)self;
+ struct mii_attach_args *ma = aux;
+ struct mii_data *mii = ma->mii_data;
+ const struct mii_phydesc *mpd;
+
+ mpd = mii_phy_match(ma, igphys);
+ aprint_naive(": Media interface\n");
+ aprint_normal(": %s, rev. %d\n", mpd->mpd_name, MII_REV(ma->mii_id2));
+
+ sc->mii_inst = mii->mii_instance;
+ sc->mii_phy = ma->mii_phyno;
+ sc->mii_funcs = &igphy_funcs;
+ sc->mii_pdata = mii;
+ sc->mii_flags = ma->mii_flags;
+ sc->mii_anegticks = 10;
+
+ PHY_RESET(sc);
+
+ sc->mii_capabilities =
+ PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+ if (sc->mii_capabilities & BMSR_EXTSTAT)
+ sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
+ aprint_normal("%s: ", sc->mii_dev.dv_xname);
+ if ((sc->mii_capabilities & BMSR_MEDIAMASK) == 0 &&
+ (sc->mii_extcapabilities & EXTSR_MEDIAMASK) == 0)
+ aprint_error("no media present");
+ else
+ mii_phy_add_media(sc);
+ aprint_normal("\n");
+}
+
+static void
+igphy_load_dspcode(struct mii_softc *sc)
+{
+ static const struct {
+ int reg;
+ uint16_t val;
+ } dspcode[] = {
+ { 0x1f95, 0x0001 },
+ { 0x1f71, 0xbd21 },
+ { 0x1f79, 0x0018 },
+ { 0x1f30, 0x1600 },
+ { 0x1f31, 0x0014 },
+ { 0x1f32, 0x161c },
+ { 0x1f94, 0x0003 },
+ { 0x1f96, 0x003f },
+ { 0x2010, 0x0008 },
+ { 0, 0 },
+ };
+ int i;
+
+ delay(10);
+
+ PHY_WRITE(sc, MII_IGPHY_PAGE_SELECT, 0x0000);
+ PHY_WRITE(sc, 0x0000, 0x0140);
+
+ delay(5);
+
+ for (i = 0; dspcode[i].reg != 0; i++)
+ IGPHY_WRITE(sc, dspcode[i].reg, dspcode[i].val);
+
+ PHY_WRITE(sc, MII_IGPHY_PAGE_SELECT,0x0000);
+ PHY_WRITE(sc, 0x0000, 0x3300);
+}
+
+static void
+igphy_reset(struct mii_softc *sc)
+{
+ uint16_t fused, fine, coarse;
+
+ mii_phy_reset(sc);
+ igphy_load_dspcode(sc);
+
+ fused = IGPHY_READ(sc, MII_IGPHY_ANALOG_SPARE_FUSE_STATUS);
+ if ((fused & ANALOG_SPARE_FUSE_ENABLED) == 0) {
+ fused = IGPHY_READ(sc, MII_IGPHY_ANALOG_FUSE_STATUS);
+
+ fine = fused & ANALOG_FUSE_FINE_MASK;
+ coarse = fused & ANALOG_FUSE_COARSE_MASK;
+
+ if (coarse > ANALOG_FUSE_COARSE_THRESH) {
+ coarse -= ANALOG_FUSE_COARSE_10;
+ fine -= ANALOG_FUSE_FINE_1;
+ } else if (coarse == ANALOG_FUSE_COARSE_THRESH)
+ fine -= ANALOG_FUSE_FINE_10;
+
+ fused = (fused & ANALOG_FUSE_POLY_MASK) |
+ (fine & ANALOG_FUSE_FINE_MASK) |
+ (coarse & ANALOG_FUSE_COARSE_MASK);
+
+ IGPHY_WRITE(sc, MII_IGPHY_ANALOG_FUSE_CONTROL, fused);
+ IGPHY_WRITE(sc, MII_IGPHY_ANALOG_FUSE_BYPASS,
+ ANALOG_FUSE_ENABLE_SW_CONTROL);
+ }
+ PHY_WRITE(sc, MII_IGPHY_PAGE_SELECT,0x0000);
+}
+
+
+int
+igphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
+{
+ struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
+ uint16_t reg;
+
+ switch (cmd) {
+ case MII_POLLSTAT:
+ /*
+ * If we're not polling our PHY instance, just return.
+ */
+ if (IFM_INST(ife->ifm_media) != sc->mii_inst)
+ return (0);
+ break;
+
+ case MII_MEDIACHG:
+ /*
+ * If the media indicates a different PHY instance,
+ * isolate ourselves.
+ */
+ if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
+ reg = PHY_READ(sc, MII_BMCR);
+ PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
+ return (0);
+ }
+
+ /*
+ * If the interface is not up, don't do anything.
+ */
+ if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
+ break;
+
+ mii_phy_setmedia(sc);
+ break;
+
+ case MII_TICK:
+ /*
+ * If we're not currently selected, just return.
Home |
Main Index |
Thread Index |
Old Index