Commit 5edc6585 authored by Luiz Angelo Daros de Luca's avatar Luiz Angelo Daros de Luca Committed by David S. Miller

net: dsa: realtek: keep default LED state in rtl8366rb

This switch family supports four LEDs for each of its six ports. Each
LED group is composed of one of these four LEDs from all six ports. LED
groups can be configured to display hardware information, such as link
activity, or manually controlled through a bitmap in registers
RTL8366RB_LED_0_1_CTRL_REG and RTL8366RB_LED_2_3_CTRL_REG.

After a reset, the default LED group configuration for groups 0 to 3
indicates, respectively, link activity, link at 1000M, 100M, and 10M, or
RTL8366RB_LED_CTRL_REG as 0x5432. These configurations are commonly used
for LED indications. However, the driver was replacing that
configuration to use manually controlled LEDs (RTL8366RB_LED_FORCE)
without providing a way for the OS to control them. The default
configuration is deemed more useful than fixed, uncontrollable turned-on
LEDs.

The driver was enabling/disabling LEDs during port_enable/disable.
However, these events occur when the port is administratively controlled
(up or down) and are not related to link presence. Additionally, when a
port N was disabled, the driver was turning off all LEDs for group N,
not only the corresponding LED for port N in any of those 4 groups. In
such cases, if port 0 was brought down, the LEDs for all ports in LED
group 0 would be turned off. As another side effect, the driver was
wrongly warning that port 5 didn't have an LED ("no LED for port 5").
Since showing the administrative state of ports is not an orthodox way
to use LEDs, it was not worth it to fix it and all this code was
dropped.

The code to disable LEDs was simplified only changing each LED group to
the RTL8366RB_LED_OFF state. Registers RTL8366RB_LED_0_1_CTRL_REG and
RTL8366RB_LED_2_3_CTRL_REG are only used when the corresponding LED
group is configured with RTL8366RB_LED_FORCE and they don't need to be
cleaned. The code still references an LED controlled by
RTL8366RB_INTERRUPT_CONTROL_REG, but as of now, no test device has
actually used it. Also, some magic numbers were replaced by macros.
Signed-off-by: default avatarLuiz Angelo Daros de Luca <luizluca@gmail.com>
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent e8dfd42c
...@@ -185,7 +185,12 @@ ...@@ -185,7 +185,12 @@
#define RTL8366RB_LED_BLINKRATE_222MS 0x0004 #define RTL8366RB_LED_BLINKRATE_222MS 0x0004
#define RTL8366RB_LED_BLINKRATE_446MS 0x0005 #define RTL8366RB_LED_BLINKRATE_446MS 0x0005
/* LED trigger event for each group */
#define RTL8366RB_LED_CTRL_REG 0x0431 #define RTL8366RB_LED_CTRL_REG 0x0431
#define RTL8366RB_LED_CTRL_OFFSET(led_group) \
(4 * (led_group))
#define RTL8366RB_LED_CTRL_MASK(led_group) \
(0xf << RTL8366RB_LED_CTRL_OFFSET(led_group))
#define RTL8366RB_LED_OFF 0x0 #define RTL8366RB_LED_OFF 0x0
#define RTL8366RB_LED_DUP_COL 0x1 #define RTL8366RB_LED_DUP_COL 0x1
#define RTL8366RB_LED_LINK_ACT 0x2 #define RTL8366RB_LED_LINK_ACT 0x2
...@@ -202,6 +207,11 @@ ...@@ -202,6 +207,11 @@
#define RTL8366RB_LED_LINK_TX 0xd #define RTL8366RB_LED_LINK_TX 0xd
#define RTL8366RB_LED_MASTER 0xe #define RTL8366RB_LED_MASTER 0xe
#define RTL8366RB_LED_FORCE 0xf #define RTL8366RB_LED_FORCE 0xf
/* The RTL8366RB_LED_X_X registers are used to manually set the LED state only
* when the corresponding LED group in RTL8366RB_LED_CTRL_REG is
* RTL8366RB_LED_FORCE. Otherwise, it is ignored.
*/
#define RTL8366RB_LED_0_1_CTRL_REG 0x0432 #define RTL8366RB_LED_0_1_CTRL_REG 0x0432
#define RTL8366RB_LED_1_OFFSET 6 #define RTL8366RB_LED_1_OFFSET 6
#define RTL8366RB_LED_2_3_CTRL_REG 0x0433 #define RTL8366RB_LED_2_3_CTRL_REG 0x0433
...@@ -1001,29 +1011,21 @@ static int rtl8366rb_setup(struct dsa_switch *ds) ...@@ -1001,29 +1011,21 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
*/ */
if (priv->leds_disabled) { if (priv->leds_disabled) {
/* Turn everything off */ /* Turn everything off */
regmap_update_bits(priv->map,
RTL8366RB_LED_0_1_CTRL_REG,
0x0FFF, 0);
regmap_update_bits(priv->map,
RTL8366RB_LED_2_3_CTRL_REG,
0x0FFF, 0);
regmap_update_bits(priv->map, regmap_update_bits(priv->map,
RTL8366RB_INTERRUPT_CONTROL_REG, RTL8366RB_INTERRUPT_CONTROL_REG,
RTL8366RB_P4_RGMII_LED, RTL8366RB_P4_RGMII_LED,
0); 0);
val = RTL8366RB_LED_OFF;
} else { for (i = 0; i < RTL8366RB_NUM_LEDGROUPS; i++) {
/* TODO: make this configurable per LED */ val = RTL8366RB_LED_OFF << RTL8366RB_LED_CTRL_OFFSET(i);
val = RTL8366RB_LED_FORCE;
}
for (i = 0; i < 4; i++) {
ret = regmap_update_bits(priv->map, ret = regmap_update_bits(priv->map,
RTL8366RB_LED_CTRL_REG, RTL8366RB_LED_CTRL_REG,
0xf << (i * 4), RTL8366RB_LED_CTRL_MASK(i),
val << (i * 4)); val);
if (ret) if (ret)
return ret; return ret;
} }
}
ret = rtl8366_reset_vlan(priv); ret = rtl8366_reset_vlan(priv);
if (ret) if (ret)
...@@ -1167,52 +1169,6 @@ rtl8366rb_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode, ...@@ -1167,52 +1169,6 @@ rtl8366rb_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
} }
} }
static void rb8366rb_set_port_led(struct realtek_priv *priv,
int port, bool enable)
{
u16 val = enable ? 0x3f : 0;
int ret;
if (priv->leds_disabled)
return;
switch (port) {
case 0:
ret = regmap_update_bits(priv->map,
RTL8366RB_LED_0_1_CTRL_REG,
0x3F, val);
break;
case 1:
ret = regmap_update_bits(priv->map,
RTL8366RB_LED_0_1_CTRL_REG,
0x3F << RTL8366RB_LED_1_OFFSET,
val << RTL8366RB_LED_1_OFFSET);
break;
case 2:
ret = regmap_update_bits(priv->map,
RTL8366RB_LED_2_3_CTRL_REG,
0x3F, val);
break;
case 3:
ret = regmap_update_bits(priv->map,
RTL8366RB_LED_2_3_CTRL_REG,
0x3F << RTL8366RB_LED_3_OFFSET,
val << RTL8366RB_LED_3_OFFSET);
break;
case 4:
ret = regmap_update_bits(priv->map,
RTL8366RB_INTERRUPT_CONTROL_REG,
RTL8366RB_P4_RGMII_LED,
enable ? RTL8366RB_P4_RGMII_LED : 0);
break;
default:
dev_err(priv->dev, "no LED for port %d\n", port);
return;
}
if (ret)
dev_err(priv->dev, "error updating LED on port %d\n", port);
}
static int static int
rtl8366rb_port_enable(struct dsa_switch *ds, int port, rtl8366rb_port_enable(struct dsa_switch *ds, int port,
struct phy_device *phy) struct phy_device *phy)
...@@ -1226,7 +1182,6 @@ rtl8366rb_port_enable(struct dsa_switch *ds, int port, ...@@ -1226,7 +1182,6 @@ rtl8366rb_port_enable(struct dsa_switch *ds, int port,
if (ret) if (ret)
return ret; return ret;
rb8366rb_set_port_led(priv, port, true);
return 0; return 0;
} }
...@@ -1241,8 +1196,6 @@ rtl8366rb_port_disable(struct dsa_switch *ds, int port) ...@@ -1241,8 +1196,6 @@ rtl8366rb_port_disable(struct dsa_switch *ds, int port)
BIT(port)); BIT(port));
if (ret) if (ret)
return; return;
rb8366rb_set_port_led(priv, port, false);
} }
static int static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment