Author: nbd
Date: 2014-11-19 21:17:52 +0100 (Wed, 19 Nov 2014)
New Revision: 43331

Modified:
   trunk/target/linux/generic/files/drivers/net/phy/ar8216.c
Log:
ar8216: factor out PHY init code into a generic function

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 <[email protected]>
Signed-off-by: Felix Fietkau <[email protected]>

Modified: trunk/target/linux/generic/files/drivers/net/phy/ar8216.c
===================================================================
--- trunk/target/linux/generic/files/drivers/net/phy/ar8216.c   2014-11-19 
20:17:43 UTC (rev 43330)
+++ trunk/target/linux/generic/files/drivers/net/phy/ar8216.c   2014-11-19 
20:17:52 UTC (rev 43331)
@@ -342,6 +342,28 @@
         return -ETIMEDOUT;
 }
 
+static void
+ar8xxx_phy_init(struct ar8xxx_priv *priv, bool support_1000)
+{
+       int i;
+       struct mii_bus *bus;
+
+       if (priv->chip->fixup_phys)
+               priv->chip->fixup_phys(priv);
+
+       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);
+               if (support_1000)
+                       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)
 {
@@ -888,23 +910,11 @@
 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_init(priv, false);
 
-       ar8xxx_phy_poll_reset(bus);
-
        priv->initialized = true;
        return 0;
 }
@@ -940,9 +950,7 @@
 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);
 
@@ -981,18 +989,8 @@
                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_init(priv, true);
 
-       ar8xxx_phy_poll_reset(bus);
-
 out:
        priv->initialized = true;
        return 0;
@@ -1622,9 +1620,7 @@
 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);
@@ -1637,20 +1633,8 @@
 
        ar8327_leds_init(priv);
 
-       priv->chip->fixup_phys(priv);
+       ar8xxx_phy_init(priv, true);
 
-       bus = priv->mii_bus;
-       for (i = 0; i < AR8XXX_NUM_PHYS; 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);
-
        return 0;
 }
 
_______________________________________________
openwrt-commits mailing list
[email protected]
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-commits

Reply via email to