PHY init code in the switch-specific hw_init functions is mainly
identical. Factor it out into a generic ar8xxx_phy_init function.

Signed-off-by: Heiner Kallweit <hkallwe...@gmail.com>
---
 .../linux/generic/files/drivers/net/phy/ar8216.c   | 66 ++++++++--------------
 1 file changed, 25 insertions(+), 41 deletions(-)

diff --git a/target/linux/generic/files/drivers/net/phy/ar8216.c 
b/target/linux/generic/files/drivers/net/phy/ar8216.c
index a0bf10a..02abfe8 100644
--- a/target/linux/generic/files/drivers/net/phy/ar8216.c
+++ b/target/linux/generic/files/drivers/net/phy/ar8216.c
@@ -340,6 +340,28 @@ ar8xxx_phy_poll_reset(struct mii_bus *bus)
         return -ETIMEDOUT;
 }
 
+static void
+ar8xxx_phy_init(struct ar8xxx_priv *priv)
+{
+       int i;
+       struct mii_bus *bus;
+
+       bus = priv->mii_bus;
+       for (i = 0; i < AR8XXX_NUM_PHYS; i++) {
+               if (priv->chip->phy_fixup)
+                       priv->chip->phy_fixup(priv, i);
+
+               /* initialize the port itself */
+               mdiobus_write(bus, i, MII_ADVERTISE,
+                       ADVERTISE_ALL | ADVERTISE_PAUSE_CAP | 
ADVERTISE_PAUSE_ASYM);
+               if (ar8xxx_has_gige(priv))
+                       mdiobus_write(bus, i, MII_CTRL1000, ADVERTISE_1000FULL);
+               mdiobus_write(bus, i, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
+       }
+
+       ar8xxx_phy_poll_reset(bus);
+}
+
 static u32
 ar8xxx_mii_read(struct ar8xxx_priv *priv, int reg)
 {
@@ -886,22 +908,10 @@ ar8236_setup_port(struct ar8xxx_priv *priv, int port, u32 
members)
 static int
 ar8236_hw_init(struct ar8xxx_priv *priv)
 {
-       int i;
-       struct mii_bus *bus;
-
        if (priv->initialized)
                return 0;
 
-       /* Initialize the PHYs */
-       bus = priv->mii_bus;
-       for (i = 0; i < AR8XXX_NUM_PHYS; i++) {
-               mdiobus_write(bus, i, MII_ADVERTISE,
-                             ADVERTISE_ALL | ADVERTISE_PAUSE_CAP |
-                             ADVERTISE_PAUSE_ASYM);
-               mdiobus_write(bus, i, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
-       }
-
-       ar8xxx_phy_poll_reset(bus);
+       ar8xxx_phy_init(priv);
 
        priv->initialized = true;
        return 0;
@@ -938,9 +948,7 @@ static const struct ar8xxx_chip ar8236_chip = {
 static int
 ar8316_hw_init(struct ar8xxx_priv *priv)
 {
-       int i;
        u32 val, newval;
-       struct mii_bus *bus;
 
        val = priv->read(priv, AR8316_REG_POSTRIP);
 
@@ -979,17 +987,7 @@ ar8316_hw_init(struct ar8xxx_priv *priv)
                msleep(1000);
        }
 
-       /* Initialize the ports */
-       bus = priv->mii_bus;
-       for (i = 0; i < AR8XXX_NUM_PHYS; i++) {
-               /* initialize the port itself */
-               mdiobus_write(bus, i, MII_ADVERTISE,
-                       ADVERTISE_ALL | ADVERTISE_PAUSE_CAP | 
ADVERTISE_PAUSE_ASYM);
-               mdiobus_write(bus, i, MII_CTRL1000, ADVERTISE_1000FULL);
-               mdiobus_write(bus, i, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
-       }
-
-       ar8xxx_phy_poll_reset(bus);
+       ar8xxx_phy_init(priv);
 
 out:
        priv->initialized = true;
@@ -1620,9 +1618,7 @@ ar8327_hw_config_of(struct ar8xxx_priv *priv, struct 
device_node *np)
 static int
 ar8327_hw_init(struct ar8xxx_priv *priv)
 {
-       struct mii_bus *bus;
        int ret;
-       int i;
 
        if (priv->phy->dev.of_node)
                ret = ar8327_hw_config_of(priv, priv->phy->dev.of_node);
@@ -1635,19 +1631,7 @@ ar8327_hw_init(struct ar8xxx_priv *priv)
 
        ar8327_leds_init(priv);
 
-       bus = priv->mii_bus;
-       for (i = 0; i < AR8XXX_NUM_PHYS; i++) {
-               priv->chip->phy_fixup(priv, i);
-
-               /* start aneg on the PHY */
-               mdiobus_write(bus, i, MII_ADVERTISE, ADVERTISE_ALL |
-                                                    ADVERTISE_PAUSE_CAP |
-                                                    ADVERTISE_PAUSE_ASYM);
-               mdiobus_write(bus, i, MII_CTRL1000, ADVERTISE_1000FULL);
-               mdiobus_write(bus, i, MII_BMCR, BMCR_RESET | BMCR_ANENABLE);
-       }
-
-       ar8xxx_phy_poll_reset(bus);
+       ar8xxx_phy_init(priv);
 
        return 0;
 }
-- 
2.1.3
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to