generic: ar8216: move port initialization into a separate function
authorGabor Juhos <juhosg@openwrt.org>
Wed, 7 Mar 2012 16:32:46 +0000 (16:32 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Wed, 7 Mar 2012 16:32:46 +0000 (16:32 +0000)
SVN-Revision: 30848

target/linux/generic/files/drivers/net/phy/ar8216.c

index 26a79be7ef523949841588f9695acd1d34a51d01..3b7937d72b58b6cb499c2590d1222d8ca5737269 100644 (file)
@@ -718,6 +718,32 @@ out:
        return 0;
 }
 
+static void
+ar8216_init_port(struct ar8216_priv *priv, int port)
+{
+       /* Enable port learning and tx */
+       priv->write(priv, AR8216_REG_PORT_CTRL(port),
+               AR8216_PORT_CTRL_LEARN |
+               (4 << AR8216_PORT_CTRL_STATE_S));
+
+       priv->write(priv, AR8216_REG_PORT_VLAN(port), 0);
+
+       if (port == AR8216_PORT_CPU) {
+               priv->write(priv, AR8216_REG_PORT_STATUS(port),
+                       AR8216_PORT_STATUS_LINK_UP |
+                       ((priv->chip == AR8316) ?
+                               AR8216_PORT_SPEED_1000M : AR8216_PORT_SPEED_100M) |
+                       AR8216_PORT_STATUS_TXMAC |
+                       AR8216_PORT_STATUS_RXMAC |
+                       ((priv->chip == AR8316) ? AR8216_PORT_STATUS_RXFLOW : 0) |
+                       ((priv->chip == AR8316) ? AR8216_PORT_STATUS_TXFLOW : 0) |
+                       AR8216_PORT_STATUS_DUPLEX);
+       } else {
+               priv->write(priv, AR8216_REG_PORT_STATUS(port),
+                       AR8216_PORT_STATUS_LINK_AUTO);
+       }
+}
+
 static int
 ar8216_reset_switch(struct switch_dev *dev)
 {
@@ -730,30 +756,11 @@ ar8216_reset_switch(struct switch_dev *dev)
        for (i = 0; i < AR8X16_MAX_VLANS; i++) {
                priv->vlan_id[i] = i;
        }
-       for (i = 0; i < AR8216_NUM_PORTS; i++) {
-               /* Enable port learning and tx */
-               priv->write(priv, AR8216_REG_PORT_CTRL(i),
-                       AR8216_PORT_CTRL_LEARN |
-                       (4 << AR8216_PORT_CTRL_STATE_S));
-
-               priv->write(priv, AR8216_REG_PORT_VLAN(i), 0);
-
-               /* Configure all PHYs */
-               if (i == AR8216_PORT_CPU) {
-                       priv->write(priv, AR8216_REG_PORT_STATUS(i),
-                               AR8216_PORT_STATUS_LINK_UP |
-                               ((priv->chip == AR8316) ?
-                                       AR8216_PORT_SPEED_1000M : AR8216_PORT_SPEED_100M) |
-                               AR8216_PORT_STATUS_TXMAC |
-                               AR8216_PORT_STATUS_RXMAC |
-                               ((priv->chip == AR8316) ? AR8216_PORT_STATUS_RXFLOW : 0) |
-                               ((priv->chip == AR8316) ? AR8216_PORT_STATUS_TXFLOW : 0) |
-                               AR8216_PORT_STATUS_DUPLEX);
-               } else {
-                       priv->write(priv, AR8216_REG_PORT_STATUS(i),
-                               AR8216_PORT_STATUS_LINK_AUTO);
-               }
-       }
+
+       /* Configure all ports */
+       for (i = 0; i < AR8216_NUM_PORTS; i++)
+               ar8216_init_port(priv, i);
+
        /* XXX: undocumented magic from atheros, required! */
        priv->write(priv, 0x38, 0xc000050e);