Skip to content

Instantly share code, notes, and snippets.

@pepe2k
Created January 9, 2014 00:05
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepe2k/8327121 to your computer and use it in GitHub Desktop.
Save pepe2k/8327121 to your computer and use it in GitHub Desktop.
This patch adds an option in swconfig which allows to disable all leds in AR8327N switch (e.g. on TL-WDR3600/4300, TL-WR1043ND v2, etc.). For example, on TL-WR1043ND v2: "swconfig dev switch0 set disable_all_leds 1" will turn off all switch LEDs (WAN and 4x LAN) and "swconfig dev switch0 set disable_all_leds 0" will turn them on again. OpenWrt t…
Index: target/linux/generic/files/drivers/net/phy/ar8216.c
===================================================================
--- target/linux/generic/files/drivers/net/phy/ar8216.c (wersja 39210)
+++ target/linux/generic/files/drivers/net/phy/ar8216.c (kopia robocza)
@@ -1903,6 +1903,57 @@
return ret;
}
+static int
+ar8xxx_sw_set_disable_all_leds(struct switch_dev *dev,
+ const struct switch_attr *attr,
+ struct switch_val *val)
+{
+ struct ar8xxx_priv *priv = swdev_to_ar8xxx(dev);
+ u32 mask;
+
+ if(val->value.i){
+ /* Set PATTERN_EN = 00 (LED always off) for
+ * both LED_CTRL_RULE in single 32-bit register */
+ u32 mask = ~(BIT(31) | BIT(30) | BIT(14) | BIT(15));
+
+ priv->write(priv, AR8327_REG_LED_CTRL0,
+ priv->read(priv, AR8327_REG_LED_CTRL0) & mask);
+
+ priv->write(priv, AR8327_REG_LED_CTRL1,
+ priv->read(priv, AR8327_REG_LED_CTRL1) & mask);
+
+ priv->write(priv, AR8327_REG_LED_CTRL2,
+ priv->read(priv, AR8327_REG_LED_CTRL2) & mask);
+
+ /* Set LED_PATTERN_EN_XY = 00 (pattern enable for portX LEDY) for
+ * all ports (1~3) */
+ mask = ~(BITS(8, 25));
+
+ priv->write(priv, AR8327_REG_LED_CTRL3,
+ priv->read(priv, AR8327_REG_LED_CTRL3) & mask);
+ } else {
+ /* Set PATTERN_EN = 11 (LED controlled by LED_RULE registers) */
+ u32 mask = BIT(31) | BIT(30) | BIT(14) | BIT(15);
+
+ priv->write(priv, AR8327_REG_LED_CTRL0,
+ priv->read(priv, AR8327_REG_LED_CTRL0) | mask);
+
+ priv->write(priv, AR8327_REG_LED_CTRL1,
+ priv->read(priv, AR8327_REG_LED_CTRL1) | mask);
+
+ priv->write(priv, AR8327_REG_LED_CTRL2,
+ priv->read(priv, AR8327_REG_LED_CTRL2) | mask);
+
+ /* Set LED_PATTERN_EN_XY = 11 */
+ mask = BITS(8, 25);
+
+ priv->write(priv, AR8327_REG_LED_CTRL3,
+ priv->read(priv, AR8327_REG_LED_CTRL3) | mask);
+ }
+
+ return 0;
+}
+
static struct switch_attr ar8xxx_sw_attr_globals[] = {
{
.type = SWITCH_TYPE_INT,
@@ -1999,6 +2050,13 @@
.get = ar8xxx_sw_get_mirror_source_port,
.max = AR8327_NUM_PORTS - 1
},
+ {
+ .type = SWITCH_TYPE_INT,
+ .name = "disable_all_leds",
+ .description = "Disable all switch LEDs",
+ .set = ar8xxx_sw_set_disable_all_leds,
+ .max = 1
+ },
};
static struct switch_attr ar8xxx_sw_attr_port[] = {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment