Skip to contentSkip to conversation

leds: add Realtek RTL9300 port LEDs under software control

PATCH In review Ross Cawston 7 participants 16 messages Oct 18 – Oct 20

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover leds: add Realtek RTL9300 port LEDs under software control

The RTL9300 switch drives up to four LEDs per port over its LED interface, serial or scanned, each normally showing a hardware function chosen by the LED set of the port. Some boards wire LEDs to it that have no hardware function and that the vendor firmware switches in software, such as the PoE status LEDs of the MokerLink POE-10G07110GSM.

This series adds a binding for such LEDs as a child of the switch, like its I2C and MDIO controllers, and a driver that takes them under software control and exposes them as LED class devices. With the PSE core's LED triggers, the PoE LEDs then follow the power delivery of their ports. The registers come from the vendor SDK's register table. Tested on the MokerLink POE-10G07110GSM.

Ross Cawston (3):
dt-bindings: leds: add Realtek RTL9301 port LEDs
dt-bindings: net: realtek,rtl9301-switch: add port LED controller
leds: add Realtek RTL9300 port LED driver

 .../leds/realtek,rtl9301-port-leds.yaml       |  84 ++++++++
 .../bindings/net/realtek,rtl9301-switch.yaml  |   3 +
 MAINTAINERS                                   |   7 +
 drivers/leds/Kconfig                          |  13 ++
 drivers/leds/Makefile                         |   1 +
 drivers/leds/leds-rtl9300-port.c              | 201 ++++++++++++++++++
 6 files changed, 309 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/realtek,rtl9301-port-leds.yaml
 create mode 100644 drivers/leds/leds-rtl9300-port.c
Signature · 1 line
2.55.0.windows.5
#1 lore raw

PATCH 1/3 dt-bindings: leds: add Realtek RTL9301 port LEDs

Add a binding for RTL9300 switch port LEDs under software control. The node is a child of the switch and gives the offset of the software LED control registers; each LED child names its switch port and its place among the port's LEDs.

---
 .../leds/realtek,rtl9301-port-leds.yaml       | 84 +++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/leds/realtek,rtl9301-port-leds.yaml
Documentation/devicetree/bindings/leds/realtek,rtl9301-port-leds.yaml new file +84 -0
new file mode 100644
index 00000000000..8d6b3552526
@@ -0,0 +1,84 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/realtek,rtl9301-port-leds.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Realtek RTL9300 switch port LEDs under software control
+
+maintainers:
+  - Ross Cawston <[email protected]>
+
+description: |
+  The RTL9300 switch drives up to four LEDs per port over its LED interface,
+  serial or scanned, each normally showing a hardware function chosen by the
+  LED set of the port. The LEDs listed here are taken over by software instead
+  and switched on and off as LED class devices, for port LEDs that have no
+  hardware function such as the PoE status LED of a PoE switch. The node is a
+  child of the switch, whose registers it uses.
+
+properties:
+  compatible:
+    const: realtek,rtl9301-port-leds
+
+  reg:
+    description: The software LED control registers, from SW_LED_LOAD to the
+      end of LED_PORT_SW_CTRL, as an offset into the switch registers.
+    maxItems: 1
+
+  "#address-cells":
+    const: 2
+
+  "#size-cells":
+    const: 0
+
+patternProperties:
+  "^led@[0-9a-f]+,[0-3]$":
+    $ref: /schemas/leds/common.yaml#
+    unevaluatedProperties: false
+
+    properties:
+      reg:
+        items:
+          - items:
+              - description: Switch port
+                maximum: 27
+              - description: LED of the port, numbered as in the port's
+                  LED set
+                maximum: 3
+
+    required:
+      - reg
+
+required:
+  - compatible
+  - reg
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/leds/common.h>
+
+    led-controller@cc48 {
+        compatible = "realtek,rtl9301-port-leds";
+        reg = <0xcc48 0x84>;
+        #address-cells = <2>;
+        #size-cells = <0>;
+
+        led@0,2 {
+            reg = <0 2>;
+            color = <LED_COLOR_ID_GREEN>;
+            function = "poe";
+            function-enumerator = <1>;
+        };
+
+        led@8,2 {
+            reg = <8 2>;
+            color = <LED_COLOR_ID_GREEN>;
+            function = "poe";
+            function-enumerator = <2>;
+        };
+    };
Signature · 1 line
2.55.0.windows.5
#2 lore raw

Re: [PATCH 1/3] dt-bindings: leds: add Realtek RTL9301 port LEDs

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Low] dt-bindings: leds: rtl9301-port-leds example uses raw function string --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Low] dt-bindings: leds: rtl9301-port-leds example uses raw function string --

commit c5aa8893c90e31ee15e18fbf27c8f17550a77f2f
Author: Ross Cawston <[email protected]>

dt-bindings: leds: add Realtek RTL9301 port LEDs

This commit adds a devicetree binding schema for Realtek RTL9300 switch port LEDs controlled by software.

Quoted 6 lines
Documentation/devicetree/bindings/leds/realtek,rtl9301-port-leds.yaml new file +0 -0
new file mode 100644
index 0000000000000..8d6b35525263f
@@ -0,0 +1,84 @@

[ ... ]

Quoted 14 lines
Documentation/devicetree/bindings/leds/realtek,rtl9301-port-leds.yaml new file +14 -0
+examples:
+  - |
+    #include <dt-bindings/leds/common.h>
+
+    led-controller@cc48 {
+        compatible = "realtek,rtl9301-port-leds";
+        reg = <0xcc48 0x84>;
+        #address-cells = <2>;
+        #size-cells = <0>;
+
+        led@0,2 {
+            reg = <0 2>;
+            color = <LED_COLOR_ID_GREEN>;
+            function = "poe";

Documentation/devicetree/bindings/leds/realtek,rtl9301-port-leds.yaml line 84

Quoted 10 lines
Documentation/devicetree/bindings/leds/realtek,rtl9301-port-leds.yaml new file +10 -0
+            function-enumerator = <1>;
+        };
+
+        led@8,2 {
+            reg = <8 2>;
+            color = <LED_COLOR_ID_GREEN>;
+            function = "poe";
+            function-enumerator = <2>;
+        };
+    };

[Severity: Low]
In Documentation/devicetree/bindings/leds/realtek,rtl9301-port-leds.yaml, the ^led@[0-9a-f]+,[0-3]$ child nodes reference /schemas/leds/common.yaml#, where properties:function states:

function:
description:
LED function. Use one of the LED_FUNCTION_* prefixed definitions from the header include/dt-bindings/leds/common.h. If there is no matching LED_FUNCTION available, add a new one.

Should the example use a LED_FUNCTION_* macro from include/dt-bindings/leds/common.h (or define LED_FUNCTION_POE there) instead of the raw string literal "poe"?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH 2/3 dt-bindings: net: realtek,rtl9301-switch: add port LED controller

In reply to Ross Cawston

The switch drives the port LEDs, and some boards wire LEDs to it that have no hardware function and are switched in software, such as PoE status LEDs. Allow the software LED control block, described by realtek,rtl9301-port-leds, as a child of the switch like its I2C and MDIO controllers.

---
 .../devicetree/bindings/net/realtek,rtl9301-switch.yaml        | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/net/realtek,rtl9301-switch.yaml +3 -0
index 80eabc17066..9529327ee0c 100644
@@ -57,6 +57,9 @@ patternProperties:
   'mdio-controller@[0-9a-f]+$':
     $ref: realtek,rtl9301-mdio.yaml#
 
+  'led-controller@[0-9a-f]+$':
+    $ref: /schemas/leds/realtek,rtl9301-port-leds.yaml#
+
 required:
   - compatible
   - reg
Signature · 1 line
2.55.0.windows.5
#4 lore raw

Re: [PATCH 2/3] dt-bindings: net: realtek,rtl9301-switch: add port LED controller

Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

The switch drives the port LEDs, and some boards wire LEDs to it that have no hardware function and are switched in software, such as PoE status LEDs. Allow the software LED control block, described by realtek,rtl9301-port-leds, as a child of the switch like its I2C and MDIO controllers.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

Re: [PATCH 2/3] dt-bindings: net: realtek,rtl9301-switch: add port LED controller

In reply to Ross Cawston
Quoted 16 lines · Ross Cawston

The switch drives the port LEDs, and some boards wire LEDs to it that have no hardware function and are switched in software, such as PoE status LEDs. Allow the software LED control block, described by realtek,rtl9301-port-leds, as a child of the switch like its I2C and MDIO controllers.

---
 .../devicetree/bindings/net/realtek,rtl9301-switch.yaml        | 3 +++
 1 file changed, 3 insertions(+)
Documentation/devicetree/bindings/net/realtek,rtl9301-switch.yaml +0 -0
index 80eabc17066..9529327ee0c 100644

Documentation/devicetree/bindings/net/realtek,rtl9301-switch.yaml patternProperties: · line 61

Quoted 5 lines
Documentation/devicetree/bindings/net/realtek,rtl9301-switch.yaml +2 -0
@@ -57,6 +57,9 @@ patternProperties:
   'mdio-controller@[0-9a-f]+$':
     $ref: realtek,rtl9301-mdio.yaml#
 
+  'led-controller@[0-9a-f]+$':
+    $ref: /schemas/leds/realtek,rtl9301-port-leds.yaml#

This depends on previous patch, so cover letter should be explicit what maintainers can or cannot do with it.

Best regards,
Krzysztof

#6 lore raw

PATCH 3/3 leds: add Realtek RTL9300 port LED driver

In reply to Ross Cawston

The RTL9300 switch drives up to four LEDs per port over its LED interface, serial or scanned. Each normally shows a hardware function picked by the LED set of the port, but software can take it over: one enable bit per LED, a 3-bit mode per LED (off, on or one of six blink rates), kept separately for copper and fibre media, and a load strobe after which the LED controller applies the modes.

Add a driver for LEDs that boards wire to the switch without a hardware function, such as PoE status LEDs. It takes the LEDs listed in the device tree under software control, sets both media alike, exposes them as LED class devices and hands them back to their hardware function when it is removed. The register offsets come from the reg of its node, within the switch's syscon register block.

---
 MAINTAINERS                      |   7 ++
 drivers/leds/Kconfig             |  13 ++
 drivers/leds/Makefile            |   1 +
 drivers/leds/leds-rtl9300-port.c | 201 +++++++++++++++++++++++++++++++
 4 files changed, 222 insertions(+)
 create mode 100644 drivers/leds/leds-rtl9300-port.c
MAINTAINERS +7 -0
index a1eb0937238..1e099a4cf05 100644
@@ -23013,6 +23013,13 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/net/dsa/realtek.yaml
 F:	drivers/net/dsa/realtek/*
 
+REALTEK RTL9300 PORT LED DRIVER
+M:	Ross Cawston <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/leds/realtek,rtl9301-port-leds.yaml
+F:	drivers/leds/leds-rtl9300-port.c
+
 REALTEK SPI-NAND
 M:	Chris Packham <[email protected]>
 S:	Maintained
drivers/leds/Kconfig +13 -0
index 7ec2c8d7854..d9b2afca2a6 100644
@@ -676,6 +676,19 @@ config LEDS_REGULATOR
 	help
 	  This option enables support for regulator driven LEDs.
 
+config LEDS_RTL9300_PORT
+	tristate "LED support for Realtek RTL9300 switch port LEDs"
+	depends on LEDS_CLASS
+	depends on MACH_REALTEK_RTL || COMPILE_TEST
+	select MFD_SYSCON
+	help
+	  This option enables software control of the port LEDs of the
+	  Realtek RTL9300 switch, for port LEDs that have no hardware
+	  function, such as the PoE status LEDs of PoE switches.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called leds-rtl9300-port.
+
 config LEDS_BD2606MVV
 	tristate "LED driver for BD2606MVV"
 	depends on LEDS_CLASS
drivers/leds/Makefile +1 -0
index 4d4b089156e..e1295303738 100644
@@ -87,6 +87,7 @@ obj-$(CONFIG_LEDS_POWERNV)		+= leds-powernv.o
 obj-$(CONFIG_LEDS_PWM)			+= leds-pwm.o
 obj-$(CONFIG_LEDS_QNAP_MCU)		+= leds-qnap-mcu.o
 obj-$(CONFIG_LEDS_REGULATOR)		+= leds-regulator.o
+obj-$(CONFIG_LEDS_RTL9300_PORT)		+= leds-rtl9300-port.o
 obj-$(CONFIG_LEDS_SC27XX_BLTC)		+= leds-sc27xx-bltc.o
 obj-$(CONFIG_LEDS_ST1202)		+= leds-st1202.o
 obj-$(CONFIG_LEDS_SUN50I_A100)		+= leds-sun50i-a100.o
drivers/leds/leds-rtl9300-port.c new file +201 -0

201 lines not on this page · raw message

Signature · 1 line
2.55.0.windows.5
#7 lore raw

Re: [PATCH 3/3] leds: add Realtek RTL9300 port LED driver

Hello Ross,

drivers/leds/leds-rtl9300-port.c line 25

Quoted 3 lines · Ross Cawston
drivers/leds/leds-rtl9300-port.c new file +2 -0
+#include <linux/mod_devicetable.h>
[...]
+#include <linux/platform_device.h>

Please don't include <linux/mod_devicetable.h> which pulls in a big bunch of dependencies on subsystems not used in your driver. <linux/platform_device.h> already provides of_device_id so you can just drop the former.

Best regards
Uwe

#8 lore raw

Re: [PATCH 3/3] leds: add Realtek RTL9300 port LED driver

In reply to Ross Cawston
Sashiko has reviewed this patch and found no issues.
Quoted 7 lines

The RTL9300 switch drives up to four LEDs per port over its LED interface, serial or scanned. Each normally shows a hardware function picked by the LED set of the port, but software can take it over: one enable bit per LED, a 3-bit mode per LED (off, on or one of six blink rates), kept separately for copper and fibre media, and a load strobe after which the LED controller applies the modes.

Quoted 8 lines

Add a driver for LEDs that boards wire to the switch without a hardware function, such as PoE status LEDs. It takes the LEDs listed in the device tree under software control, sets both media alike, exposes them as LED class devices and hands them back to their hardware function when it is removed. The register offsets come from the reg of its node, within the switch's syscon register block.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#9 lore raw
In reply to Ross Cawston
Quoted 9 lines · Ross Cawston

The RTL9300 switch drives up to four LEDs per port over its LED interface, serial or scanned, each normally showing a hardware function chosen by the LED set of the port. Some boards wire LEDs to it that have no hardware function and that the vendor firmware switches in software, such as the PoE status LEDs of the MokerLink POE-10G07110GSM.

This series adds a binding for such LEDs as a child of the switch, like its I2C and MDIO controllers, and a driver that takes them under software control and exposes them as LED class devices.

This is an odd architecture when compared to other switch drivers with LEDs.

Port LEDs should be within the port node of the switch in DT. Ideally you want all LEDs for a port to start the with basics, on/off control. That gives the minimum, enough that you can make them software blink on traffic, show link speed, poe, shift lock, morse code panic dumps.

If the LED has more capabilities, you can then advertise this, and the led triggers will offload blinking to the hardware. But this is an extension, not a requirement.

So please don't make these LEDs special.

Andrew

#10 lore raw
Quoted 2 lines · Andrew Lunn

Port LEDs should be within the port node of the switch in DT. Ideally you want all LEDs for a port to start the with basics, on/off control.

[...]

Quoted 1 line

So please don't make these LEDs special.

That makes sense. The catch is that RTL9300 has no switch driver upstream yet, so there is no port node with a driver behind it to put them in: mainline only has drivers for the switch's I2C and MDIO controllers.

Unless you see a place they could go in the meantime, I'll withdraw this series until there is one.

Chris, do you know of anyone working on an RTL9300 switch driver? If so, I'd be glad to help with the port LEDs there.

Ross

#11 lore raw
Quoted 10 lines · Ross Cawston
Quoted 2 lines · Andrew Lunn

Port LEDs should be within the port node of the switch in DT. Ideally you want all LEDs for a port to start the with basics, on/off control.

[...]

Quoted 1 line

So please don't make these LEDs special.

That makes sense. The catch is that RTL9300 has no switch driver upstream yet, so there is no port node with a driver behind it to put them in: mainline only has drivers for the switch's I2C and MDIO controllers.

Markus Stockhausen <[email protected]> did a lot of work on the MDIO driver, based on what is in OpenWRT. Maybe he plans to work on the switch driver?

Andrew

#12 lore raw
Quoted 3 lines · Andrew Lunn

Markus Stockhausen <[email protected]> did a lot of work on the MDIO driver, based on what is in OpenWRT. Maybe he plans to work on the switch driver?

Thanks, adding Markus.

Markus, are you planning to take the RTL930x switch driver upstream? If so, I'd be glad to help with the port LEDs there, in the port nodes as Andrew describes earlier in this thread, and to test on an RTL9303 board:

https://lore.kernel.org/all/[email protected]/T/

In OpenWrt, openwrt/openwrt#25341 adds software control of the RTL930x LEDs to the switch driver; I tested it with this board's PoE LEDs.

Ross

#13 lore raw

Hi you two,

Quoted 4 lines

Von: Ross Cawston <[email protected]>
Gesendet: Montag, 19. Oktober 2026 07:43
An: [email protected]
Betreff: Re: [PATCH 0/3] leds: add Realtek RTL9300 port LEDs under

software control

Quoted 5 lines

...

Thanks, adding Markus.

Markus, are you planning to take the RTL930x switch driver upstream?

While this is the overall goal some day it is currently beyond the time available. I'm only two months into the nearly abandoned Otto DSA driver and just keep things rolling. As of today the operation mode is more like:

Some commited contributors are throwing AI at the hardware to fix and enhance the DSA driver. Coding, testing and PR submission is runnung full-auto-mode. So a lot gets documented during this process. With my limited time and knowledge I'm doing my best to review and organize this to some extend. If possible I ask for refactoring or add simple refactoring PRs on my own.

Markus

#14 lore raw
Quoted 1 line · Markus Stockhausen

[...] it is currently beyond the time available.

Thanks Markus, that answers it.

Then please drop this series. The PoE LEDs of this board go to OpenWrt with openwrt/openwrt#25341 for now, and I'll come back to the port LEDs, in the port nodes, once there is an RTL930x switch driver upstream.

Ross

#15 lore raw
In reply to Ross Cawston

Hi Ross,

Quoted 10 lines · Ross Cawston
Quoted 2 lines · Andrew Lunn

Port LEDs should be within the port node of the switch in DT. Ideally you want all LEDs for a port to start the with basics, on/off control.

[...]

Quoted 1 line

So please don't make these LEDs special.

That makes sense. The catch is that RTL9300 has no switch driver upstream yet, so there is no port node with a driver behind it to put them in: mainline only has drivers for the switch's I2C and MDIO controllers.

Quoted 5 lines

Unless you see a place they could go in the meantime, I'll withdraw this series until there is one.

Chris, do you know of anyone working on an RTL9300 switch driver? If so, I'd be glad to help with the port LEDs there.

I don't know of anyone actively working on it. I did have something vaguely functional as a switchdev driver, I'll see if I can dig it up and send it to you directly. I did look at the DSA driver from openwrt but I consider DSA the wrong model for the RTL9300 (mainly because the "nic" is not a true Ethernet interface it's just the DMA channel for trapped packets and FDB updates).

I'm still vaguely working on RTL stuff but we've pivoted to the ARMv8 based RTL9311B. For our commercial product we'll be starting with the Realtek SDK but personally I'd really like to see an in-kernel driver for these switches.