Skip to content

Commit 5edc658

Browse files
luizlucadavem330
authored andcommitted
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: Luiz Angelo Daros de Luca <[email protected]> Reviewed-by: Linus Walleij <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent e8dfd42 commit 5edc658

File tree

1 file changed

+20
-67
lines changed

1 file changed

+20
-67
lines changed

drivers/net/dsa/realtek/rtl8366rb.c

Lines changed: 20 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,12 @@
185185
#define RTL8366RB_LED_BLINKRATE_222MS 0x0004
186186
#define RTL8366RB_LED_BLINKRATE_446MS 0x0005
187187

188+
/* LED trigger event for each group */
188189
#define RTL8366RB_LED_CTRL_REG 0x0431
190+
#define RTL8366RB_LED_CTRL_OFFSET(led_group) \
191+
(4 * (led_group))
192+
#define RTL8366RB_LED_CTRL_MASK(led_group) \
193+
(0xf << RTL8366RB_LED_CTRL_OFFSET(led_group))
189194
#define RTL8366RB_LED_OFF 0x0
190195
#define RTL8366RB_LED_DUP_COL 0x1
191196
#define RTL8366RB_LED_LINK_ACT 0x2
@@ -202,6 +207,11 @@
202207
#define RTL8366RB_LED_LINK_TX 0xd
203208
#define RTL8366RB_LED_MASTER 0xe
204209
#define RTL8366RB_LED_FORCE 0xf
210+
211+
/* The RTL8366RB_LED_X_X registers are used to manually set the LED state only
212+
* when the corresponding LED group in RTL8366RB_LED_CTRL_REG is
213+
* RTL8366RB_LED_FORCE. Otherwise, it is ignored.
214+
*/
205215
#define RTL8366RB_LED_0_1_CTRL_REG 0x0432
206216
#define RTL8366RB_LED_1_OFFSET 6
207217
#define RTL8366RB_LED_2_3_CTRL_REG 0x0433
@@ -1001,28 +1011,20 @@ static int rtl8366rb_setup(struct dsa_switch *ds)
10011011
*/
10021012
if (priv->leds_disabled) {
10031013
/* Turn everything off */
1004-
regmap_update_bits(priv->map,
1005-
RTL8366RB_LED_0_1_CTRL_REG,
1006-
0x0FFF, 0);
1007-
regmap_update_bits(priv->map,
1008-
RTL8366RB_LED_2_3_CTRL_REG,
1009-
0x0FFF, 0);
10101014
regmap_update_bits(priv->map,
10111015
RTL8366RB_INTERRUPT_CONTROL_REG,
10121016
RTL8366RB_P4_RGMII_LED,
10131017
0);
1014-
val = RTL8366RB_LED_OFF;
1015-
} else {
1016-
/* TODO: make this configurable per LED */
1017-
val = RTL8366RB_LED_FORCE;
1018-
}
1019-
for (i = 0; i < 4; i++) {
1020-
ret = regmap_update_bits(priv->map,
1021-
RTL8366RB_LED_CTRL_REG,
1022-
0xf << (i * 4),
1023-
val << (i * 4));
1024-
if (ret)
1025-
return ret;
1018+
1019+
for (i = 0; i < RTL8366RB_NUM_LEDGROUPS; i++) {
1020+
val = RTL8366RB_LED_OFF << RTL8366RB_LED_CTRL_OFFSET(i);
1021+
ret = regmap_update_bits(priv->map,
1022+
RTL8366RB_LED_CTRL_REG,
1023+
RTL8366RB_LED_CTRL_MASK(i),
1024+
val);
1025+
if (ret)
1026+
return ret;
1027+
}
10261028
}
10271029

10281030
ret = rtl8366_reset_vlan(priv);
@@ -1167,52 +1169,6 @@ rtl8366rb_mac_link_down(struct dsa_switch *ds, int port, unsigned int mode,
11671169
}
11681170
}
11691171

1170-
static void rb8366rb_set_port_led(struct realtek_priv *priv,
1171-
int port, bool enable)
1172-
{
1173-
u16 val = enable ? 0x3f : 0;
1174-
int ret;
1175-
1176-
if (priv->leds_disabled)
1177-
return;
1178-
1179-
switch (port) {
1180-
case 0:
1181-
ret = regmap_update_bits(priv->map,
1182-
RTL8366RB_LED_0_1_CTRL_REG,
1183-
0x3F, val);
1184-
break;
1185-
case 1:
1186-
ret = regmap_update_bits(priv->map,
1187-
RTL8366RB_LED_0_1_CTRL_REG,
1188-
0x3F << RTL8366RB_LED_1_OFFSET,
1189-
val << RTL8366RB_LED_1_OFFSET);
1190-
break;
1191-
case 2:
1192-
ret = regmap_update_bits(priv->map,
1193-
RTL8366RB_LED_2_3_CTRL_REG,
1194-
0x3F, val);
1195-
break;
1196-
case 3:
1197-
ret = regmap_update_bits(priv->map,
1198-
RTL8366RB_LED_2_3_CTRL_REG,
1199-
0x3F << RTL8366RB_LED_3_OFFSET,
1200-
val << RTL8366RB_LED_3_OFFSET);
1201-
break;
1202-
case 4:
1203-
ret = regmap_update_bits(priv->map,
1204-
RTL8366RB_INTERRUPT_CONTROL_REG,
1205-
RTL8366RB_P4_RGMII_LED,
1206-
enable ? RTL8366RB_P4_RGMII_LED : 0);
1207-
break;
1208-
default:
1209-
dev_err(priv->dev, "no LED for port %d\n", port);
1210-
return;
1211-
}
1212-
if (ret)
1213-
dev_err(priv->dev, "error updating LED on port %d\n", port);
1214-
}
1215-
12161172
static int
12171173
rtl8366rb_port_enable(struct dsa_switch *ds, int port,
12181174
struct phy_device *phy)
@@ -1226,7 +1182,6 @@ rtl8366rb_port_enable(struct dsa_switch *ds, int port,
12261182
if (ret)
12271183
return ret;
12281184

1229-
rb8366rb_set_port_led(priv, port, true);
12301185
return 0;
12311186
}
12321187

@@ -1241,8 +1196,6 @@ rtl8366rb_port_disable(struct dsa_switch *ds, int port)
12411196
BIT(port));
12421197
if (ret)
12431198
return;
1244-
1245-
rb8366rb_set_port_led(priv, port, false);
12461199
}
12471200

12481201
static int

0 commit comments

Comments
 (0)