From: Vladimir Stolyarov <[email protected]> Hi, I`ve ported Vasily`s patch to 3.8 kernel and added ralink,led-polarity directive to rt5350.dtsi. This directive allows control leds polarity without swconfig.
Tested on my DIR-320 B1 (polarity value is 0x17). Signed-off-by: Vasily E. Moskalev <[email protected]> Signed-off-by: Vladimir Stolyarov <[email protected]> --- ---a/target/linux/ramips/patches-3.8/0136-NET-MIPS-add-ralink-SoC-ethernet-driver.patch 2013-05-19 14:26:55.000000000 +0400 +++ b/target/linux/ramips/patches-3.8/0136-NET-MIPS-add-ralink-SoC-ethernet-driver.patch 2013-05-20 18:58:28.000000000 +0400 @@ -26,9 +26,11 @@ create mode 100644 drivers/net/ethernet/ramips/ramips_eth.h create mode 100644 drivers/net/ethernet/ramips/ramips_main.c ---- /dev/null -+++ b/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h -@@ -0,0 +1,27 @@ +Index: linux-3.8.12/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-3.8.12/arch/mips/include/asm/mach-ralink/rt305x_esw_platform.h 2013-05-20 18:44:40.000000000 +0400 +@@ -0,0 +1,28 @@ +/* + * Ralink RT305x SoC platform device registration + * @@ -53,12 +55,15 @@ + u8 vlan_config; + u32 reg_initval_fct2; + u32 reg_initval_fpa2; ++ u8 led_polarity; +}; + +#endif /* _RT305X_ESW_PLATFORM_H */ ---- a/arch/mips/ralink/rt305x.c -+++ b/arch/mips/ralink/rt305x.c -@@ -182,6 +182,7 @@ void __init ralink_clk_init(void) +Index: linux-3.8.12/arch/mips/ralink/rt305x.c +=================================================================== +--- linux-3.8.12.orig/arch/mips/ralink/rt305x.c 2013-05-20 18:44:39.000000000 +0400 ++++ linux-3.8.12/arch/mips/ralink/rt305x.c 2013-05-20 18:44:40.000000000 +0400 +@@ -221,6 +221,7 @@ } ralink_clk_add("cpu", cpu_rate); @@ -66,9 +71,11 @@ ralink_clk_add("10000b00.spi", sys_rate); ralink_clk_add("10000100.timer", wdt_rate); ralink_clk_add("10000120.watchdog", wdt_rate); ---- a/drivers/net/ethernet/Kconfig -+++ b/drivers/net/ethernet/Kconfig -@@ -136,6 +136,7 @@ source "drivers/net/ethernet/packetengin +Index: linux-3.8.12/drivers/net/ethernet/Kconfig +=================================================================== +--- linux-3.8.12.orig/drivers/net/ethernet/Kconfig 2013-05-08 07:33:25.000000000 +0400 ++++ linux-3.8.12/drivers/net/ethernet/Kconfig 2013-05-20 18:44:40.000000000 +0400 +@@ -136,6 +136,7 @@ source "drivers/net/ethernet/pasemi/Kconfig" source "drivers/net/ethernet/qlogic/Kconfig" source "drivers/net/ethernet/racal/Kconfig" @@ -76,9 +83,11 @@ source "drivers/net/ethernet/realtek/Kconfig" source "drivers/net/ethernet/renesas/Kconfig" source "drivers/net/ethernet/rdc/Kconfig" ---- a/drivers/net/ethernet/Makefile -+++ b/drivers/net/ethernet/Makefile -@@ -54,6 +54,7 @@ obj-$(CONFIG_NET_PACKET_ENGINE) += packe +Index: linux-3.8.12/drivers/net/ethernet/Makefile +=================================================================== +--- linux-3.8.12.orig/drivers/net/ethernet/Makefile 2013-05-08 07:33:25.000000000 +0400 ++++ linux-3.8.12/drivers/net/ethernet/Makefile 2013-05-20 18:44:40.000000000 +0400 +@@ -54,6 +54,7 @@ obj-$(CONFIG_NET_VENDOR_PASEMI) += pasemi/ obj-$(CONFIG_NET_VENDOR_QLOGIC) += qlogic/ obj-$(CONFIG_NET_VENDOR_RACAL) += racal/ @@ -86,8 +95,10 @@ obj-$(CONFIG_NET_VENDOR_REALTEK) += realtek/ obj-$(CONFIG_SH_ETH) += renesas/ obj-$(CONFIG_NET_VENDOR_RDC) += rdc/ ---- /dev/null -+++ b/drivers/net/ethernet/ramips/Kconfig +Index: linux-3.8.12/drivers/net/ethernet/ramips/Kconfig +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-3.8.12/drivers/net/ethernet/ramips/Kconfig 2013-05-20 18:44:40.000000000 +0400 @@ -0,0 +1,18 @@ +config NET_RAMIPS + tristate "Ralink RT288X/RT3X5X/RT3662/RT3883 ethernet driver" @@ -107,8 +118,10 @@ + depends on DEBUG_FS + +endif ---- /dev/null -+++ b/drivers/net/ethernet/ramips/Makefile +Index: linux-3.8.12/drivers/net/ethernet/ramips/Makefile +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-3.8.12/drivers/net/ethernet/ramips/Makefile 2013-05-20 18:44:40.000000000 +0400 @@ -0,0 +1,9 @@ +# +# Makefile for the Ramips SoCs built-in ethernet macs @@ -119,8 +132,10 @@ +ramips-$(CONFIG_NET_RAMIPS_DEBUG_FS) += ramips_debugfs.o + +obj-$(CONFIG_NET_RAMIPS) += ramips.o ---- /dev/null -+++ b/drivers/net/ethernet/ramips/ramips_debugfs.c +Index: linux-3.8.12/drivers/net/ethernet/ramips/ramips_debugfs.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-3.8.12/drivers/net/ethernet/ramips/ramips_debugfs.c 2013-05-20 18:44:40.000000000 +0400 @@ -0,0 +1,127 @@ +/* + * Ralink SoC ethernet driver debugfs code @@ -249,9 +264,11 @@ + debugfs_remove(raeth_debugfs_root); + raeth_debugfs_root = NULL; +} ---- /dev/null -+++ b/drivers/net/ethernet/ramips/ramips_esw.c -@@ -0,0 +1,1221 @@ +Index: linux-3.8.12/drivers/net/ethernet/ramips/ramips_esw.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-3.8.12/drivers/net/ethernet/ramips/ramips_esw.c 2013-05-20 18:57:32.000000000 +0400 +@@ -0,0 +1,1438 @@ +#include <linux/ioport.h> +#include <linux/switch.h> +#include <linux/mii.h> @@ -303,6 +320,15 @@ +#define RT305X_ESW_REG_P4PC 0xf8 +#define RT305X_ESW_REG_P5PC 0xfc + ++/* RT5350 only registers */ ++#define RT305X_ESW_REG_LED_POLARITY 0x168 ++#define RT305X_ESW_REG_P0TPC 0x150 ++#define RT305X_ESW_REG_P1TPC 0x154 ++#define RT305X_ESW_REG_P2TPC 0x158 ++#define RT305X_ESW_REG_P3TPC 0x15c ++#define RT305X_ESW_REG_P4TPC 0x160 ++#define RT305X_ESW_REG_P5TPC 0x164 ++ +#define RT305X_ESW_LED_LINK 0 +#define RT305X_ESW_LED_100M 1 +#define RT305X_ESW_LED_DUPLEX 2 @@ -314,6 +340,7 @@ +#define RT305X_ESW_LED_100MACT 8 +/* Additional led states not in datasheet: */ +#define RT305X_ESW_LED_BLINK 10 ++#define RT305X_ESW_LED_OFF 11 +#define RT305X_ESW_LED_ON 12 + +#define RT305X_ESW_LINK_S 25 @@ -406,6 +433,9 @@ + /* Global attributes. */ + RT305X_ESW_ATTR_ENABLE_VLAN, + RT305X_ESW_ATTR_ALT_VLAN_DISABLE, ++ RT305X_ESW_ATTR_LED_FREQ, ++ RT305X_ESW_ATTR_PKT_LENGTH, ++ RT305X_ESW_ATTR_BC_STATUS, + /* Port attributes. */ + RT305X_ESW_ATTR_PORT_DISABLE, + RT305X_ESW_ATTR_PORT_DOUBLETAG, @@ -414,6 +444,9 @@ + RT305X_ESW_ATTR_PORT_LAN, + RT305X_ESW_ATTR_PORT_RECV_BAD, + RT305X_ESW_ATTR_PORT_RECV_GOOD, ++ RT305X_ESW_ATTR_PORT_TR_BAD, ++ RT305X_ESW_ATTR_PORT_TR_GOOD, ++ RT305X_ESW_ATTR_PORT_LED_POLARITY, +}; + +struct rt305x_esw_port { @@ -447,7 +480,8 @@ + bool alt_vlan_disable; + struct rt305x_esw_vlan vlans[RT305X_ESW_NUM_VLANS]; + struct rt305x_esw_port ports[RT305X_ESW_NUM_PORTS]; -+ ++ u8 led_polarity; /* LED polarity. RT5350 only */ ++ u32 sgc; /* SGC value */ +}; + +static inline void @@ -689,6 +723,7 @@ + * ports. + */ + rt305x_esw_wr(esw, 0x0008a301, RT305X_ESW_REG_SGC); ++ esw->sgc=0x0008a301; + + /* Setup SoC Port control register */ + rt305x_esw_wr(esw, @@ -711,6 +746,9 @@ + rt305x_esw_wr(esw, 0x00000005, RT305X_ESW_REG_P3LED); + rt305x_esw_wr(esw, 0x00000005, RT305X_ESW_REG_P4LED); + ++ if (soc_is_rt5350()) ++ rt305x_esw_wr(esw,esw->led_polarity, RT305X_ESW_REG_LED_POLARITY); ++ + /* Copy disabled port configuration from bootloader setup */ + port_disable = rt305x_esw_get_port_disable(esw); + for (i = 0; i < 6; i++) @@ -809,6 +847,8 @@ + u8 en_vlan = 0; + u8 untag = 0; + ++ rt305x_esw_wr(esw, esw->sgc, RT305X_ESW_REG_SGC); ++ + for (i = 0; i < RT305X_ESW_NUM_VLANS; i++) { + u32 vid, vmsc; + if (esw->global_vlan_enable) { @@ -822,6 +862,10 @@ + rt305x_esw_set_vmsc(esw, i, vmsc); + } + ++ if (soc_is_rt5350()) { ++ rt305x_esw_wr(esw,esw->led_polarity, RT305X_ESW_REG_LED_POLARITY); ++ } ++ + for (i = 0; i < RT305X_ESW_NUM_PORTS; i++) { + u32 pvid; + disable |= esw->ports[i].disable << i; @@ -1059,6 +1103,27 @@ +} + +static int ++rt305x_esw_get_port_tr_badgood(struct switch_dev *dev, ++ const struct switch_attr *attr, ++ struct switch_val *val) ++{ ++ struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev); ++ int idx = val->port_vlan; ++ int shift = attr->id == RT305X_ESW_ATTR_PORT_TR_GOOD ? 0 : 16; ++ u32 reg; ++ ++ if (!soc_is_rt5350()) ++ return -EINVAL; ++ ++ if (idx < 0 || idx >= RT305X_ESW_NUM_LANWAN) ++ return -EINVAL; ++ ++ reg = rt305x_esw_rr(esw, RT305X_ESW_REG_P0TPC + 4*idx); ++ val->value.i = (reg >> shift) & 0xffff; ++ return 0; ++} ++ ++static int +rt305x_esw_get_port_led(struct switch_dev *dev, + const struct switch_attr *attr, + struct switch_val *val) @@ -1215,6 +1280,121 @@ + return 0; +} + ++static int ++rt305x_esw_set_port_led_polarity(struct switch_dev *dev, ++ const struct switch_attr *attr, ++ struct switch_val *val) ++{ ++ struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev); ++ int idx = val->port_vlan; ++ ++ if (idx < 0 || idx >= RT305X_ESW_NUM_LEDS) ++ return -EINVAL; ++ ++ if (!soc_is_rt5350()) ++ return -EINVAL; ++ ++ if (val->value.i==0) ++ esw->led_polarity &= ~ (1 << idx); ++ else ++ esw->led_polarity |= (1 << idx); ++ return 0; ++} ++ ++static int ++rt305x_esw_get_port_led_polarity(struct switch_dev *dev, ++ const struct switch_attr *attr, ++ struct switch_val *val) ++{ ++ struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev); ++ int idx = val->port_vlan; ++ ++ if (!soc_is_rt5350()) ++ return -EINVAL; ++ ++ ++ if (idx < 0 || idx >= RT305X_ESW_NUM_PORTS || ++ idx >= RT305X_ESW_NUM_LEDS) ++ return -EINVAL; ++ ++ val->value.i = (rt305x_esw_rr(esw, RT305X_ESW_REG_LED_POLARITY) >> idx) & 1; ++ ++ return 0; ++} ++ ++static int ++rt305x_esw_set_led_freq(struct switch_dev *dev, ++ const struct switch_attr *attr, ++ struct switch_val *val) ++{ ++ struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev); ++ ++ esw->sgc &= 0xfe7fffff; ++ esw->sgc |= ((val->value.i & 3) << 23); ++ return 0; ++} ++ ++static int ++rt305x_esw_get_led_freq(struct switch_dev *dev, ++ const struct switch_attr *attr, ++ struct switch_val *val) ++{ ++ struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev); ++ ++ val->value.i = (rt305x_esw_rr(esw,RT305X_ESW_REG_SGC) >> 23) & 3; ++ ++ return 0; ++} ++ ++static int ++rt305x_esw_set_pkt_length(struct switch_dev *dev, ++ const struct switch_attr *attr, ++ struct switch_val *val) ++{ ++ struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev); ++ ++ esw->sgc &= 0xffffff3f; ++ esw->sgc |= ((val->value.i & 3) << 6); ++ return 0; ++} ++ ++static int ++rt305x_esw_get_pkt_length(struct switch_dev *dev, ++ const struct switch_attr *attr, ++ struct switch_val *val) ++{ ++ struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev); ++ ++ val->value.i = (rt305x_esw_rr(esw, RT305X_ESW_REG_SGC) >> 6) & 3; ++ ++ return 0; ++} ++ ++ ++static int ++rt305x_esw_set_bc_status(struct switch_dev *dev, ++ const struct switch_attr *attr, ++ struct switch_val *val) ++{ ++ struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev); ++ ++ esw->sgc &= 0xffffffcf; ++ esw->sgc |= ((val->value.i & 3) << 4); ++ return 0; ++} ++ ++static int ++rt305x_esw_get_bc_status(struct switch_dev *dev, ++ const struct switch_attr *attr, ++ struct switch_val *val) ++{ ++ struct rt305x_esw *esw = container_of(dev, struct rt305x_esw, swdev); ++ ++ val->value.i = (rt305x_esw_rr(esw, RT305X_ESW_REG_SGC) >> 4) & 3; ++ ++ return 0; ++} ++ +static const struct switch_attr rt305x_esw_global[] = { + { + .type = SWITCH_TYPE_INT, @@ -1235,6 +1415,33 @@ + .get = rt305x_esw_get_alt_vlan_disable, + .set = rt305x_esw_set_alt_vlan_disable, + }, ++ { ++ .type = SWITCH_TYPE_INT, ++ .name = "led_freq", ++ .description = "LED Flash frequency (0:30mS, 1:60mS, 2:240mS, 3:480mS)", ++ .max = 3, ++ .id = RT305X_ESW_ATTR_LED_FREQ, ++ .get = rt305x_esw_get_led_freq, ++ .set = rt305x_esw_set_led_freq, ++ }, ++ { ++ .type = SWITCH_TYPE_INT, ++ .name = "pkt_maxlen", ++ .description = "Maximum packet lenghth tagged/untagged (0:1536/1536, 1:1522/1518, 2:1526/1522)", ++ .max = 2, ++ .id = RT305X_ESW_ATTR_PKT_LENGTH, ++ .get = rt305x_esw_get_pkt_length, ++ .set = rt305x_esw_set_pkt_length, ++ }, ++ { ++ .type = SWITCH_TYPE_INT, ++ .name = "bc_storm_protect", ++ .description = "Global broadcast storm protection (0:Disable, 1:64 blocks, 2:96 blocks, 3:128 blocks)", ++ .max = 2, ++ .id = RT305X_ESW_ATTR_BC_STATUS, ++ .get = rt305x_esw_get_bc_status, ++ .set = rt305x_esw_set_bc_status, ++ }, +}; + +static const struct switch_attr rt305x_esw_port[] = { @@ -1271,7 +1478,7 @@ + .name = "led", + .description = "LED mode (0:link, 1:100m, 2:duplex, 3:activity," + " 4:collision, 5:linkact, 6:duplcoll, 7:10mact," -+ " 8:100mact, 10:blink, 12:on)", ++ " 8:100mact, 10:blink, 11:off, 12:on)", + .max = 15, + .id = RT305X_ESW_ATTR_PORT_LED, + .get = rt305x_esw_get_port_led, @@ -1299,6 +1506,29 @@ + .id = RT305X_ESW_ATTR_PORT_RECV_GOOD, + .get = rt305x_esw_get_port_recv_badgood, + }, ++ { ++ .type = SWITCH_TYPE_INT, ++ .name = "led_polarity", ++ .description = "LED Polarity for each port (0:low active, 1:high active). rt5350 only", ++ .max = 1, ++ .id = RT305X_ESW_ATTR_PORT_LED_POLARITY, ++ .get = rt305x_esw_get_port_led_polarity, ++ .set = rt305x_esw_set_port_led_polarity, ++ }, ++ { ++ .type = SWITCH_TYPE_INT, ++ .name = "tr_bad", ++ .description = "Transmit bad packet counter. rt5350 only", ++ .id = RT305X_ESW_ATTR_PORT_TR_BAD, ++ .get = rt305x_esw_get_port_tr_badgood, ++ }, ++ { ++ .type = SWITCH_TYPE_INT, ++ .name = "tr_good", ++ .description = "Transmit good packet counter. rt5350 only", ++ .id = RT305X_ESW_ATTR_PORT_TR_GOOD, ++ .get = rt305x_esw_get_port_tr_badgood, ++ }, +}; + +static const struct switch_attr rt305x_esw_vlan[] = { @@ -1350,7 +1580,7 @@ +{ + struct device_node *np = pdev->dev.of_node; + const struct rt305x_esw_platform_data *pdata; -+ const __be32 *port_map, *reg_init; ++ const __be32 *port_map, *reg_init, *led_polarity; + struct rt305x_esw *esw; + struct switch_dev *swdev; + struct resource *res, *irq; @@ -1405,6 +1635,10 @@ + if (reg_init) + esw->reg_initval_fpa2 = be32_to_cpu(*reg_init); + ++ led_polarity = of_get_property(np, "ralink,led-polarity", NULL); ++ if (led_polarity && soc_is_rt5350()) ++ esw->led_polarity = be32_to_cpu(*led_polarity) & 0x1F; ++ + swdev = &esw->swdev; + swdev->of_node = pdev->dev.of_node; + swdev->name = "rt305x-esw"; @@ -1473,8 +1707,10 @@ +{ + platform_driver_unregister(&rt305x_esw_driver); +} ---- /dev/null -+++ b/drivers/net/ethernet/ramips/ramips_eth.h +Index: linux-3.8.12/drivers/net/ethernet/ramips/ramips_eth.h +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-3.8.12/drivers/net/ethernet/ramips/ramips_eth.h 2013-05-20 18:44:40.000000000 +0400 @@ -0,0 +1,375 @@ +/* + * This program is free software; you can redistribute it and/or modify @@ -1851,8 +2087,10 @@ +#endif /* CONFIG_NET_RAMIPS_DEBUG_FS */ + +#endif /* RAMIPS_ETH_H */ ---- /dev/null -+++ b/drivers/net/ethernet/ramips/ramips_main.c +Index: linux-3.8.12/drivers/net/ethernet/ramips/ramips_main.c +=================================================================== +--- /dev/null 1970-01-01 00:00:00.000000000 +0000 ++++ linux-3.8.12/drivers/net/ethernet/ramips/ramips_main.c 2013-05-20 18:44:40.000000000 +0400 @@ -0,0 +1,1285 @@ +/* + * This program is free software; you can redistribute it and/or modify --- a/target/linux/ramips/dts/rt5350.dtsi 2013-05-21 18:24:59.000000000 +0400 +++ b/target/linux/ramips/dts/rt5350.dtsi 2013-05-13 20:11:40.000000000 +0400 @@ -147,6 +147,7 @@ esw@10110000 { compatible = "ralink,rt5350-esw", "ralink,rt3050-esw"; reg = <0x10110000 8000>; + ralink,led-polarity = <0x00>; interrupt-parent = <&intc>; interrupts = <17>;
_______________________________________________ openwrt-devel mailing list [email protected] https://lists.openwrt.org/mailman/listinfo/openwrt-devel
