Re: [PATCH v2 1/1] net: phy: realtek: Add support for PHY LEDs on RTL8221B

From: Andrew Lunn

Date: Mon Apr 20 2026 - 09:04:34 EST


On Mon, Apr 20, 2026 at 06:08:00PM +0800, Chukun Pan wrote:
> Realtek RTL8221B Ethernet PHY supports three LED pins which are used to
> indicate link status and activity. Add netdev trigger support for them.
>
> Signed-off-by: Chukun Pan <amadeus@xxxxxxxxxx>
> ---
> Changes in v2:
> - Invert the LED polarity in led_brightness_set to achieve LED_ON.

Nice idea.

> +static int rtl822xb_led_hw_control_set(struct phy_device *phydev, u8 index,
> + unsigned long rules)
> +{
> + u16 val = 0;
> + bool act;
> + int ret;
> +
> + if (index >= RTL8211x_LED_COUNT)
> + return -EINVAL;
> +
> + if (test_bit(TRIGGER_NETDEV_LINK, &rules) ||
> + test_bit(TRIGGER_NETDEV_LINK_10, &rules))
> + val |= RTL822X_VND2_LCR_LINK_10;
> +
> + if (test_bit(TRIGGER_NETDEV_LINK, &rules) ||
> + test_bit(TRIGGER_NETDEV_LINK_100, &rules))
> + val |= RTL822X_VND2_LCR_LINK_100;
> +
> + if (test_bit(TRIGGER_NETDEV_LINK, &rules) ||
> + test_bit(TRIGGER_NETDEV_LINK_1000, &rules))
> + val |= RTL822X_VND2_LCR_LINK_1000;
> +
> + if (test_bit(TRIGGER_NETDEV_LINK, &rules) ||
> + test_bit(TRIGGER_NETDEV_LINK_2500, &rules))
> + val |= RTL822X_VND2_LCR_LINK_2500;
> +
> + ret = phy_write_mmd(phydev, MDIO_MMD_VEND2,
> + RTL822X_VND2_LED(index), val);
> + if (ret < 0)
> + return ret;
> +
> + act = test_bit(TRIGGER_NETDEV_RX, &rules) ||
> + test_bit(TRIGGER_NETDEV_TX, &rules);
> +
> + return phy_modify_mmd(phydev, MDIO_MMD_VEND2, RTL822X_VND2_LCR6,
> + RTL822X_VND2_LED_ACT(index), act ?
> + RTL822X_VND2_LED_ACT(index) : 0);

I think to be safe, you probably should set the polarity back to its
default. Or you need to add to the commit message that you have
verified that ledtrig-netdev will always turn the LED off before
offloading to hardware, so resetting the polarity.

Andrew

---
pw-bot: cr