Skip to content

net: r8169: add device tree based LED configuration for r8125#496

Closed
mingzhangqun wants to merge 2 commits into
armbian:rk-6.1-rkr5.1from
mingzhangqun:seeed-r8125-led-dt
Closed

net: r8169: add device tree based LED configuration for r8125#496
mingzhangqun wants to merge 2 commits into
armbian:rk-6.1-rkr5.1from
mingzhangqun:seeed-r8125-led-dt

Conversation

@mingzhangqun
Copy link
Copy Markdown
Contributor

Summary

Read r8125 LED register/value pairs from the PCIe controller device tree realtek,led-data property, instead of hardcoding in the shared driver path.

The driver searches DT nodes for realtek,led-data and writes each reg/value pair via RTL_W16.

Tested on Seeed reComputer RK3588 DevKit

  • Both r8125 Ethernet ports: LED registers correctly written
  • No impact on other boards (property absent = default behavior)

@HeyMeco
Copy link
Copy Markdown
Collaborator

HeyMeco commented Jun 1, 2026

This is a better approach using device tree for board-specific LED config. A few suggestions to improve efficiency and safety:

1. Avoid Repeated Memory Allocation

The function allocates and parses on every call (WoL + hardware init). Cache the config once during probe instead:

// In rtl8169_private struct:
u32 *led_config;
int led_config_count;

// Parse once during probe, then reuse in rtl8125_apply_dt_led_config()

This eliminates the kmalloc_array() call from the hot path.

2. Eliminate Redundant Calls

Currently called twice during init—from both rtl_wol_enable_rx() and rtl_hw_start_8125_common(). Call it once from a single location like rtl_hw_start_8125().

3. Improve Type Safety (Minor)

for (i = 0; i < count; i += 2)
    RTL_W16(tp, (unsigned int)led_data[i], (u16)led_data[i + 1]);

Use unsigned int for register addresses instead of int cast.


Read r8125 LED register/value pairs from the PCIe controller DT
"realtek,led-data" property, instead of hardcoding in the shared
driver path.

Walk up the device parent chain to find the PCIe platform device's
of_node, since PCI devices on Rockchip platforms do not have their
of_node set directly.

Parse the DT property once during probe and cache it in the driver
private struct. Apply the cached config from rtl_hw_start_8125_common
only, eliminating redundant calls and repeated memory allocation.
@mingzhangqun
Copy link
Copy Markdown
Contributor Author

@HeyMeco Thanks for the review! All three suggestions applied in the latest push:

  1. Cache config at probestruct rtl8169_private now holds led_data / led_data_count. DT parsing (rtl8125_parse_dt_led_config()) runs once from rtl_init_one(), and rtl_remove_one() frees the buffer. The hot-path rtl8125_apply_dt_led_config() only iterates the cached array — no more kmalloc_array() per call.

  2. Single call site — removed the call from rtl_wol_enable_rx(). LED config is now applied only from rtl_hw_start_8125_common().

  3. Type safety — dropped the (int) cast; register addresses flow as u32 straight into RTL_W16().

Patch updated to v2 (21bb15e). The diff vs the previous revision is essentially the parse/apply split + the struct fields + the probe/remove wiring.

@mingzhangqun
Copy link
Copy Markdown
Contributor Author

Superseded by #497 (branch recreated due to CI runner failure). All discussion migrated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants