Module Name: src Committed By: msaitoh Date: Thu Feb 14 04:13:40 UTC 2019
Modified Files: src/sys/dev/mii: micphy.c Log Message: Add KSZ8081 support from FreeBSD. To generate a diff of this commit: cvs rdiff -u -r1.5 -r1.6 src/sys/dev/mii/micphy.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/mii/micphy.c diff -u src/sys/dev/mii/micphy.c:1.5 src/sys/dev/mii/micphy.c:1.6 --- src/sys/dev/mii/micphy.c:1.5 Tue Jan 22 17:41:06 2019 +++ src/sys/dev/mii/micphy.c Thu Feb 14 04:13:40 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: micphy.c,v 1.5 2019/01/22 17:41:06 skrll Exp $ */ +/* $NetBSD: micphy.c,v 1.6 2019/02/14 04:13:40 msaitoh Exp $ */ /*- * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc. @@ -59,7 +59,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: micphy.c,v 1.5 2019/01/22 17:41:06 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: micphy.c,v 1.6 2019/02/14 04:13:40 msaitoh Exp $"); #include "opt_mii.h" @@ -79,6 +79,8 @@ __KERNEL_RCSID(0, "$NetBSD: micphy.c,v 1 static int micphymatch(device_t, cfdata_t, void *); static void micphyattach(device_t, device_t, void *); +static void micphy_reset(struct mii_softc *); +static int micphy_service(struct mii_softc *, struct mii_data *, int); CFATTACH_DECL3_NEW(micphy, sizeof(struct mii_softc), micphymatch, micphyattach, mii_phy_detach, mii_phy_activate, NULL, NULL, @@ -88,10 +90,13 @@ static int micphy_service(struct mii_sof static void micphy_fixup(struct mii_softc *, int, int, device_t); static const struct mii_phy_funcs micphy_funcs = { - micphy_service, ukphy_status, mii_phy_reset, + micphy_service, ukphy_status, micphy_reset, }; static const struct mii_phydesc micphys[] = { + { MII_OUI_MICREL, MII_MODEL_MICREL_KSZ8081, + MII_STR_MICREL_KSZ8081 }, + { MII_OUI_MICREL, MII_MODEL_MICREL_KSZ9021RNI, MII_STR_MICREL_KSZ9021RNI }, @@ -99,6 +104,8 @@ static const struct mii_phydesc micphys[ NULL }, }; +#define MII_KSZ8081_PHYCTL2 0x1f + static int micphymatch(device_t parent, cfdata_t match, void *aux) { @@ -149,6 +156,24 @@ micphyattach(device_t parent, device_t s aprint_normal("\n"); } +static void +micphy_reset(struct mii_softc *sc) +{ + uint16_t reg; + + /* + * The 8081 has no "sticky bits" that survive a soft reset; several bits + * in the Phy Control Register 2 must be preserved across the reset. + * These bits are set up by the bootloader; they control how the phy + * interfaces to the board (such as clock frequency and LED behavior). + */ + if (sc->mii_mpd_model == MII_MODEL_MICREL_KSZ8081) + PHY_READ(sc, MII_KSZ8081_PHYCTL2, ®); + mii_phy_reset(sc); + if (sc->mii_mpd_model == MII_MODEL_MICREL_KSZ8081) + PHY_WRITE(sc, MII_KSZ8081_PHYCTL2, reg); +} + static int micphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) {