Skip to content

Commit 9294853

Browse files
committed
realtek: RTL930x/RTL931x led_set defines, and led-sync pin configuration
Add defines for RTL930x and RTL931x led_set 'modes' (to avoid magic numbers in dts files). Add support for led-sync pin usage on RTL930x and RTL931x devices. This allows for the HC595 shift register LED support provided by these chips. Also tidy up the handling of led_sets on rtl930x devices (so it doesn't produce errors for missing led_sets) Signed-off-by: Bevan Weiss <bevan.weiss@gmail.com>
1 parent 9736d42 commit 9294853

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

target/linux/realtek/dts/rtl930x.dtsi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,22 @@
1010
sds = <##s>; \
1111
};
1212

13+
// LED Set mode definitions
14+
#define RTL930X_LED_SET_NONE 0
15+
#define RTL930X_LED_SET_10G 1 << 0
16+
#define RTL930X_LED_SET_5G 1 << 1
17+
#define RTL930X_LED_SET_2P5G 1 << 3
18+
#define RTL930X_LED_SET_1G 1 << 5
19+
#define RTL930X_LED_SET_100M 1 << 7
20+
#define RTL930X_LED_SET_10M 1 << 8
21+
#define RTL930X_LED_SET_LINK 1 << 9
22+
#define RTL930X_LED_SET_LINK_BLINK 1 << 10
23+
#define RTL930X_LED_SET_ACT 1 << 11
24+
#define RTL930X_LED_SET_RX 1 << 12
25+
#define RTL930X_LED_SET_TX 1 << 13
26+
#define RTL930X_LED_SET_COLLISION 1 << 14
27+
#define RTL930X_LED_SET_DUPLEX 1 << 15
28+
1329
/ {
1430
#address-cells = <1>;
1531
#size-cells = <1>;

target/linux/realtek/dts/rtl931x.dtsi

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@
1212
sds = <##s>; \
1313
};
1414

15+
// LED Set mode definitions
16+
#define RTL931X_LED_SET_NONE 0
17+
#define RTL931X_LED_SET_10G 1 << 0
18+
#define RTL931X_LED_SET_5G 1 << 1
19+
#define RTL931X_LED_SET_2P5G 1 << 3
20+
#define RTL931X_LED_SET_1G 1 << 5
21+
#define RTL931X_LED_SET_100M 1 << 7
22+
#define RTL931X_LED_SET_10M 1 << 8
23+
#define RTL931X_LED_SET_LINK 1 << 9
24+
#define RTL931X_LED_SET_LINK_BLINK 1 << 10
25+
#define RTL931X_LED_SET_ACT 1 << 11
26+
#define RTL931X_LED_SET_RX 1 << 12
27+
#define RTL931X_LED_SET_TX 1 << 13
28+
#define RTL931X_LED_SET_COLLISION 1 << 14
29+
#define RTL931X_LED_SET_DUPLEX 1 << 15
30+
1531
/ {
1632
#address-cells = <1>;
1733
#size-cells = <1>;

target/linux/realtek/files-6.12/arch/mips/include/asm/mach-rtl838x/mach-rtl83xx.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@
230230
#define RTL93XX_MODEL_NAME_INFO (0x0004)
231231
#define RTL93XX_CHIP_INFO (0x0008)
232232

233+
#define RTL930X_GPIO_SEL_CTRL (0x0200)
234+
233235
#define RTL838X_LED_GLB_CTRL (0xA000)
234236
#define RTL839X_LED_GLB_CTRL (0x00E4)
235237
#define RTL9302_LED_GLB_CTRL (0xcc00)

target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl930x.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#define RTL930X_VLAN_PORT_TAG_STS_CTRL_IGR_P_OTAG_KEEP_MASK GENMASK(1,1)
2323
#define RTL930X_VLAN_PORT_TAG_STS_CTRL_IGR_P_ITAG_KEEP_MASK GENMASK(0,0)
2424

25+
#define RTL930X_GPIO_SEL_GPIO19_LEDSYNC_SEL BIT(11)
26+
2527
#define RTL930X_LED_GLB_ACTIVE_LOW BIT(22)
2628

2729
#define RTL930X_LED_SETX_0_CTRL(x) (RTL930X_LED_SET0_0_CTRL - (x * 8))
@@ -2272,11 +2274,20 @@ static void rtl930x_led_init(struct rtl838x_switch_priv *priv)
22722274
sprintf(set_name, "led_set%d", set);
22732275
leds_in_this_set = of_property_count_u32_elems(node, set_name);
22742276

2275-
if (leds_in_this_set == 0 || leds_in_this_set > sizeof(set_config)) {
2276-
pr_err("%s led_set configuration invalid skipping over this set\n", __func__);
2277+
if (leds_in_this_set == -EINVAL) {
2278+
// if this led_setX property is not present, skip it silently
22772279
continue;
22782280
}
22792281

2282+
if (leds_in_this_set <= 0 || leds_in_this_set > sizeof(set_config)) {
2283+
pr_err("%s: %s configuration invalid skipping over this set, leds_in_this_set=%d (should be >0 and <=%d\n",
2284+
__func__, set_name, leds_in_this_set, sizeof(set_config));
2285+
continue;
2286+
}
2287+
else {
2288+
pr_info("%s: %s has %d LEDs configured\n", __func__, set_name, leds_in_this_set);
2289+
}
2290+
22802291
if (of_property_read_u32_array(node, set_name, set_config, leds_in_this_set)) {
22812292
break;
22822293
}
@@ -2312,6 +2323,12 @@ static void rtl930x_led_init(struct rtl838x_switch_priv *priv)
23122323
/* Set LED mode to serial (0x1) */
23132324
sw_w32_mask(0x3, 0x1, RTL930X_LED_GLB_CTRL);
23142325

2326+
/* Enable GPIO19_LEDSYNC if utilised */
2327+
if (of_property_read_bool(node, "led-sync"))
2328+
sw_w32_mask(0,RTL930X_GPIO_SEL_GPIO19_LEDSYNC_SEL,RTL930X_GPIO_SEL_CTRL);
2329+
else
2330+
sw_w32_mask(RTL930X_GPIO_SEL_GPIO19_LEDSYNC_SEL, 0, RTL930X_GPIO_SEL_CTRL);
2331+
23152332
/* Set LED active state */
23162333
if (of_property_read_bool(node, "active-low"))
23172334
sw_w32_mask(RTL930X_LED_GLB_ACTIVE_LOW, 0, RTL930X_LED_GLB_CTRL);

target/linux/realtek/files-6.12/drivers/net/dsa/rtl83xx/rtl931x.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#define RTL931X_VLAN_PORT_TAG_ITPID_IDX_MASK GENMASK(2,1)
2626
#define RTL931X_VLAN_PORT_TAG_ITPID_KEEP_MASK GENMASK(0,0)
2727

28+
#define RTL930X_GPIO_SEL_GPIO31_LEDSYNC_SEL BIT(16)
29+
2830
extern struct mutex smi_lock;
2931
extern struct rtl83xx_soc_info soc_info;
3032

@@ -1651,6 +1653,12 @@ static void rtldsa_931x_led_init(struct rtl838x_switch_priv *priv)
16511653
/* Set LED mode to serial (0x1) */
16521654
sw_w32_mask(0x3, 0x1, RTL931X_LED_GLB_CTRL);
16531655

1656+
/* Enable GPIO31_LEDSYNC if utilised */
1657+
if (of_property_read_bool(node, "led-sync"))
1658+
sw_w32_mask(0, RTL930X_GPIO_SEL_GPIO31_LEDSYNC_SEL, RTL931X_MAC_L2_GLOBAL_CTRL2);
1659+
else
1660+
sw_w32_mask(RTL930X_GPIO_SEL_GPIO31_LEDSYNC_SEL, 0, RTL931X_MAC_L2_GLOBAL_CTRL2);
1661+
16541662
rtl839x_set_port_reg_le(pm_copper, RTL931X_LED_PORT_COPR_MASK_CTRL);
16551663
rtl839x_set_port_reg_le(pm_fiber, RTL931X_LED_PORT_FIB_MASK_CTRL);
16561664
rtl839x_set_port_reg_le(pm_copper | pm_fiber, RTL931X_LED_PORT_COMBO_MASK_CTRL);

0 commit comments

Comments
 (0)