ramips: allow to specify port layout for the switch of the RT305x/RT3350
authorGabor Juhos <juhosg@openwrt.org>
Mon, 15 Aug 2011 14:11:43 +0000 (14:11 +0000)
committerGabor Juhos <juhosg@openwrt.org>
Mon, 15 Aug 2011 14:11:43 +0000 (14:11 +0000)
Based on a patch by Roman Yeryomin <roman@advem.lv>

SVN-Revision: 27990

13 files changed:
target/linux/ramips/files/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-dir-300-revb.c
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-f5d8235-v2.c
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-fonera20n.c
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-hw550-3g.c
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-mofi3500-3gn.c
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-nw718.c
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-pwh2004.c
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-rt-g32-revb.c
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-v22rw-2x2.c
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-wcr150gn.c
target/linux/ramips/files/arch/mips/ralink/rt305x/mach-whr-g300n.c
target/linux/ramips/files/drivers/net/ramips_esw.c

index fd1f6eb19a04ab958f17535916a0840c92ecc427..97ee375eb771253122aa2232499be745955a4a1c 100644 (file)
 #ifndef _RT305X_ESW_PLATFORM_H
 #define _RT305X_ESW_PLATFORM_H
 
+enum {
+       RT305X_ESW_VLAN_CONFIG_NONE = 0,
+       RT305X_ESW_VLAN_CONFIG_LLLLW,
+       RT305X_ESW_VLAN_CONFIG_WLLLL,
+};
+
 struct rt305x_esw_platform_data
 {
+       u8 vlan_config;
 };
 
 #endif /* _RT305X_ESW_PLATFORM_H */
index 71b9c51fa412fff84e34b77eaa8f7d4441728692..622803672a2dd6a9068012e01751b2452cbc0076 100644 (file)
@@ -110,6 +110,7 @@ static void __init dir_300b_init(void)
        rt305x_gpio_init(RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT);
 
        rt305x_register_flash(0, &dir_300b_flash_data);
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
        rt305x_register_ethernet();
        ramips_register_gpio_leds(-1, ARRAY_SIZE(dir_300b_leds_gpio),
                                  dir_300b_leds_gpio);
index b4062818ee2e0cb05a68117d4bfd16f2077b3837..7e218f7bd6e9e8acc931e80ac5698a3c05e15c0f 100644 (file)
@@ -132,6 +132,7 @@ static void __init f5d8235v2_init(void)
        rt305x_register_flash(0, &f5d8235v2_flash_data);
        ramips_register_gpio_leds(-1, ARRAY_SIZE(f5d8235v2_leds_gpio),
                                                f5d8235v2_leds_gpio);
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_NONE;
        rt305x_register_ethernet();
        platform_device_register(&f5d8235v2_switch);
        rt305x_register_wifi();
index bbf152fa86256f3aab9cb7cd78e3d6c6bd33f884..544279509a49bea6191ac7ce83e18e04bbb3cdf4 100644 (file)
@@ -118,6 +118,7 @@ static void __init fonera20n_init(void)
                                     ARRAY_SIZE(fonera20n_gpio_buttons),
                                     fonera20n_gpio_buttons);
 
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
        rt305x_register_ethernet();
        rt305x_register_wifi();
        rt305x_register_wdt();
index c1023e0010ed50ba88444542bf15e6a7aac492cf..77e068233af7d63bbdcd81e4369dbff8291fe743 100644 (file)
@@ -127,6 +127,7 @@ static void __init hw550_3g_init(void)
        rt305x_gpio_init(HW550_3G_GPIO_MODE);
 
        rt305x_register_flash(0, &hw550_3g_flash_data);
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
        rt305x_register_ethernet();
        ramips_register_gpio_leds(-1, ARRAY_SIZE(hw550_3g_leds_gpio),
                                  hw550_3g_leds_gpio);
index 8e34ad0bc3b6d60bb83994bad5d53384883e6b93..16b109fd1b02b0b967c0a591e4f361baa535f9c1 100644 (file)
@@ -127,6 +127,7 @@ static void __init mofi3500_3gn_init(void)
        rt305x_gpio_init(MOFI3500_3GN_GPIO_MODE);
 
        rt305x_register_flash(0, &mofi3500_3gn_flash_data);
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
        rt305x_register_ethernet();
        ramips_register_gpio_leds(-1, ARRAY_SIZE(mofi3500_3gn_leds_gpio),
                                  mofi3500_3gn_leds_gpio);
index 09f6dc485914b6c73b214824b03be4311c687ab8..7107a8c50adfa970e14d8cf0cfdf27d4a5b4dbf5 100644 (file)
@@ -129,6 +129,7 @@ static void __init nw718_init(void)
        rt305x_gpio_init(RT305X_GPIO_MODE_I2C |
                         RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT);
 
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
        rt305x_register_ethernet();
        ramips_register_gpio_leds(-1, ARRAY_SIZE(nw718_leds_gpio),
                                  nw718_leds_gpio);
index 03dc19221d90e5a58d8f76864989237898f6d671..c321e1108865cf8f818ddf9b712b97e6d34a4e32 100644 (file)
@@ -95,6 +95,7 @@ static void __init pwh2004_init(void)
        ramips_register_gpio_buttons(-1, PWH2004_BUTTONS_POLL_INTERVAL,
                                     ARRAY_SIZE(pwh2004_gpio_buttons),
                                     pwh2004_gpio_buttons);
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
        rt305x_register_ethernet();
        rt305x_register_wifi();
        rt305x_register_wdt();
index 8273c5ae3b629f32812e65361fedba3e78170adc..274466c2105cf8ee4c5c2ae16278b6bed0296e49 100644 (file)
@@ -103,6 +103,7 @@ static void __init rt_g32b_init(void)
        rt305x_register_spi(rt_g32b_spi_slave_info,
                            ARRAY_SIZE(rt_g32b_spi_slave_info));
 
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
        rt305x_register_ethernet();
        ramips_register_gpio_buttons(-1, RT_G32B_BUTTONS_POLL_INTERVAL,
                                     ARRAY_SIZE(rt_g32b_gpio_buttons),
index 382da755f97cbdc262ac426d362ed28d78bbb248..b5883bb99734841d45fc1dd19710a963deb1268a 100644 (file)
@@ -104,6 +104,7 @@ static void __init v22rw_2x2_init(void)
        rt305x_gpio_init(RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT);
 
        rt305x_register_flash(0, &v22rw_2x2_flash_data);
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
        rt305x_register_ethernet();
        ramips_register_gpio_leds(-1, ARRAY_SIZE(v22rw_2x2_leds_gpio),
                                  v22rw_2x2_leds_gpio);
index babaa710a55e85ff5885460541231349212fb8fb..984bab7b851e68d79c069ad02b5be4fa6b8f357b 100644 (file)
@@ -60,6 +60,7 @@ static void __init wcr150gn_init(void)
 {
        rt305x_gpio_init(RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT);
        rt305x_register_flash(0, &wcr150gn_flash_data);
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
        rt305x_register_ethernet();
        rt305x_register_wifi();
        rt305x_register_wdt();
index 63131358858a6cc10bcc28e5766d620026f11b19..49ab0fd00978e180576a7566bd475ddca01aae40 100644 (file)
@@ -130,6 +130,7 @@ static void __init whr_g300n_init(void)
        rt305x_gpio_init(RT305X_GPIO_MODE_GPIO << RT305X_GPIO_MODE_UART0_SHIFT);
 
        rt305x_register_flash(0, &whr_g300n_flash_data);
+       rt305x_esw_data.vlan_config = RT305X_ESW_VLAN_CONFIG_LLLLW;
        rt305x_register_ethernet();
        ramips_register_gpio_leds(-1, ARRAY_SIZE(whr_g300n_leds_gpio),
                                  whr_g300n_leds_gpio);
index c6b5db76dc09412b045aea42bcdcf7bbcf0b646c..c681eed830e904238defe7224dda3b2d48ff1dc5 100644 (file)
@@ -72,6 +72,9 @@
 #define RT305X_ESW_PORTS_ALL   \
                (RT305X_ESW_PORTS_NOCPU | RT305X_ESW_PORTS_CPU)
 
+#define RT305X_ESW_NUM_VLANS   16
+#define RT305X_ESW_NUM_PORTS   7
+
 struct rt305x_esw {
        void __iomem *base;
        struct rt305x_esw_platform_data *pdata;
@@ -221,8 +224,6 @@ rt305x_esw_hw_init(struct rt305x_esw *esw)
                       (RT305X_ESW_PORTS_CPU << RT305X_ESW_SOCPC_DISBC2CPU_S)),
                      RT305X_ESW_REG_SOCPC);
 
-       rt305x_esw_set_pvid(esw, RT305X_ESW_PORT4, 2);
-       rt305x_esw_set_pvid(esw, RT305X_ESW_PORT5, 1);
        rt305x_esw_wr(esw, 0x3f502b28, RT305X_ESW_REG_FPA2);
        rt305x_esw_wr(esw, 0x00000000, RT305X_ESW_REG_FPA);
 
@@ -252,17 +253,47 @@ rt305x_esw_hw_init(struct rt305x_esw *esw)
        /* select local register */
        rt305x_mii_write(esw, 0, 31, 0x8000);
 
-       /* set default vlan */
-       rt305x_esw_set_vlan_id(esw, 0, 1);
-       rt305x_esw_set_vlan_id(esw, 1, 2);
-       rt305x_esw_set_vmsc(esw, 0,
-                           (BIT(RT305X_ESW_PORT0) | BIT(RT305X_ESW_PORT1) |
-                            BIT(RT305X_ESW_PORT2) | BIT(RT305X_ESW_PORT3) |
-                            BIT(RT305X_ESW_PORT6)));
-       rt305x_esw_set_vmsc(esw, 1,
-                           (BIT(RT305X_ESW_PORT4) | BIT(RT305X_ESW_PORT6)));
-       rt305x_esw_set_vmsc(esw, 2, 0);
-       rt305x_esw_set_vmsc(esw, 3, 0);
+       for (i = 0; i < RT305X_ESW_NUM_VLANS; i++) {
+               rt305x_esw_set_vlan_id(esw, i, 0);
+               rt305x_esw_set_vmsc(esw, i, 0);
+       }
+
+       for (i = 0; i < RT305X_ESW_NUM_PORTS; i++)
+               rt305x_esw_set_pvid(esw, i, 1);
+
+       switch (esw->pdata->vlan_config) {
+       case RT305X_ESW_VLAN_CONFIG_NONE:
+               break;
+
+       case RT305X_ESW_VLAN_CONFIG_LLLLW:
+               rt305x_esw_set_vlan_id(esw, 0, 1);
+               rt305x_esw_set_vlan_id(esw, 1, 2);
+               rt305x_esw_set_pvid(esw, RT305X_ESW_PORT4, 2);
+
+               rt305x_esw_set_vmsc(esw, 0,
+                               BIT(RT305X_ESW_PORT0) | BIT(RT305X_ESW_PORT1) |
+                               BIT(RT305X_ESW_PORT2) | BIT(RT305X_ESW_PORT3) |
+                               BIT(RT305X_ESW_PORT6));
+               rt305x_esw_set_vmsc(esw, 1,
+                               BIT(RT305X_ESW_PORT4) | BIT(RT305X_ESW_PORT6));
+               break;
+
+       case RT305X_ESW_VLAN_CONFIG_WLLLL:
+               rt305x_esw_set_vlan_id(esw, 0, 1);
+               rt305x_esw_set_vlan_id(esw, 1, 2);
+               rt305x_esw_set_pvid(esw, RT305X_ESW_PORT0, 2);
+
+               rt305x_esw_set_vmsc(esw, 0,
+                               BIT(RT305X_ESW_PORT1) | BIT(RT305X_ESW_PORT2) |
+                               BIT(RT305X_ESW_PORT3) | BIT(RT305X_ESW_PORT4) |
+                               BIT(RT305X_ESW_PORT6));
+               rt305x_esw_set_vmsc(esw, 1,
+                               BIT(RT305X_ESW_PORT0) | BIT(RT305X_ESW_PORT6));
+               break;
+
+       default:
+               BUG();
+       }
 }
 
 static int