kernel: ar8216: move port vlan setup into a separate function
authorGabor Juhos <juhosg@openwrt.org>
Sat, 12 Nov 2011 14:09:50 +0000 (14:09 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Sat, 12 Nov 2011 14:09:50 +0000 (14:09 +0000)
SVN-Revision: 28992

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

index 62da3c0b645037854dfd86be62e3ab4d077eb39b..cdbf1668b65cfca02822858c495ed7c90bc5506f 100644 (file)
@@ -486,6 +486,33 @@ ar8216_vtu_op(struct ar8216_priv *priv, u32 op, u32 val)
        priv->write(priv, AR8216_REG_VTU, op);
 }
 
+static void
+ar8216_setup_port(struct ar8216_priv *priv, int port, u32 egress, u32 ingress,
+                 u32 members, u32 pvid)
+{
+       u32 header;
+
+       if (priv->vlan && port == AR8216_PORT_CPU && priv->chip == AR8216)
+               header = AR8216_PORT_CTRL_HEADER;
+       else
+               header = 0;
+
+       ar8216_rmw(priv, AR8216_REG_PORT_CTRL(port),
+                  AR8216_PORT_CTRL_LEARN | AR8216_PORT_CTRL_VLAN_MODE |
+                  AR8216_PORT_CTRL_SINGLE_VLAN | AR8216_PORT_CTRL_STATE |
+                  AR8216_PORT_CTRL_HEADER | AR8216_PORT_CTRL_LEARN_LOCK,
+                  AR8216_PORT_CTRL_LEARN | header |
+                  (egress << AR8216_PORT_CTRL_VLAN_MODE_S) |
+                  (AR8216_PORT_STATE_FORWARD << AR8216_PORT_CTRL_STATE_S));
+
+       ar8216_rmw(priv, AR8216_REG_PORT_VLAN(port),
+                  AR8216_PORT_VLAN_DEST_PORTS | AR8216_PORT_VLAN_MODE |
+                  AR8216_PORT_VLAN_DEFAULT_ID,
+                  (members << AR8216_PORT_VLAN_DEST_PORTS_S) |
+                  (ingress << AR8216_PORT_VLAN_MODE_S) |
+                  (pvid << AR8216_PORT_VLAN_DEFAULT_ID_S));
+}
+
 static int
 ar8216_hw_apply(struct switch_dev *dev)
 {
@@ -552,22 +579,7 @@ ar8216_hw_apply(struct switch_dev *dev)
                        ingress = AR8216_IN_PORT_ONLY;
                }
 
-               ar8216_rmw(priv, AR8216_REG_PORT_CTRL(i),
-                       AR8216_PORT_CTRL_LEARN | AR8216_PORT_CTRL_VLAN_MODE |
-                       AR8216_PORT_CTRL_SINGLE_VLAN | AR8216_PORT_CTRL_STATE |
-                       AR8216_PORT_CTRL_HEADER | AR8216_PORT_CTRL_LEARN_LOCK,
-                       AR8216_PORT_CTRL_LEARN |
-                         (priv->vlan && i == AR8216_PORT_CPU && (priv->chip == AR8216) ?
-                          AR8216_PORT_CTRL_HEADER : 0) |
-                         (egress << AR8216_PORT_CTRL_VLAN_MODE_S) |
-                         (AR8216_PORT_STATE_FORWARD << AR8216_PORT_CTRL_STATE_S));
-
-               ar8216_rmw(priv, AR8216_REG_PORT_VLAN(i),
-                       AR8216_PORT_VLAN_DEST_PORTS | AR8216_PORT_VLAN_MODE |
-                         AR8216_PORT_VLAN_DEFAULT_ID,
-                       (portmask[i] << AR8216_PORT_VLAN_DEST_PORTS_S) |
-                         (ingress << AR8216_PORT_VLAN_MODE_S) |
-                         (pvid << AR8216_PORT_VLAN_DEFAULT_ID_S));
+               ar8216_setup_port(priv, i, egress, ingress, portmask[i], pvid);
        }
        mutex_unlock(&priv->reg_mutex);
        return 0;