* [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set for YT8521
@ 2026-11-30 10:00 Chukun Pan
2026-11-30 10:00 ` [PATCH net-next v3 2/2] net: phy: motorcomm: add missing trigger link " Chukun Pan
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Chukun Pan @ 2026-11-30 10:00 UTC (permalink / raw)
To: Frank
Cc: Andrew Lunn, Paolo Abeni, Jakub Kicinski, Eric Dumazet,
David S . Miller, Heiner Kallweit, linux-kernel, netdev,
Chukun Pan
Add support for manual brightness setting on YT8521/YT8531 PHY.
Switching to the netdev trigger will disable led forced mode.
Testing with netdev and heartbeat on the Radxa E20C (YT8531).
Signed-off-by: Chukun Pan <amadeus@jmu.edu.cn>
---
Changes in v3:
Use GENMASK() to describe the FORCE_MODE field
Changes in v2:
Fix macro definition location
Add missing checks for using ytphy_read_ext()
Clear force led status in led_hw_control_set()
---
drivers/net/phy/motorcomm.c | 49 +++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)
diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index a87e83fdf590..e0c6477a53e4 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -271,6 +271,10 @@
*/
#define YTPHY_WCR_TYPE_PULSE BIT(0)
+#define YTPHY_LED_GENERAL_CFG_REG 0xA00B
+#define YTPHY_LED_FORCE_EN(x) BIT((x) * 3 + 2)
+#define YTPHY_LED_FORCE_MODE(x) GENMASK((x) * 3 + 1, (x) * 3)
+
#define YTPHY_PAD_DRIVE_STRENGTH_REG 0xA010
#define YT8531_RGMII_RXC_DS_MASK GENMASK(15, 13)
#define YT8531_RGMII_RXD_DS_HI_MASK BIT(12) /* Bit 2 of rxd_ds */
@@ -1775,6 +1779,44 @@ static int yt8531s_config_init(struct phy_device *phydev)
return phy_restore_page(phydev, old_page, ret);
}
+static int yt8521_hw_led_on_set(struct phy_device *phydev, u8 index,
+ bool value)
+{
+ int reg, val;
+ u16 mask;
+
+ val = ytphy_read_ext(phydev, YTPHY_LED_GENERAL_CFG_REG);
+ if (val < 0)
+ return val;
+
+ mask = YTPHY_LED_FORCE_EN(index) | YTPHY_LED_FORCE_MODE(index);
+ /* 0: force OFF, 1: force ON, same as the value */
+ reg = (val & ~mask) | (value << (index * 3));
+ if (value)
+ reg |= YTPHY_LED_FORCE_EN(index);
+
+ if (reg == val)
+ return 0;
+
+ return ytphy_write_ext(phydev, YTPHY_LED_GENERAL_CFG_REG, reg);
+}
+
+static int yt8521_led_brightness_set(struct phy_device *phydev, u8 index,
+ enum led_brightness value)
+{
+ int ret;
+
+ if (index >= YT8521_MAX_LEDS)
+ return -EINVAL;
+
+ /* clear HW LED setup */
+ ret = ytphy_write_ext(phydev, YT8521_LED0_CFG_REG + index, 0);
+ if (ret < 0)
+ return ret;
+
+ return yt8521_hw_led_on_set(phydev, index, (value != LED_OFF));
+}
+
static const unsigned long supported_trgs = (BIT(TRIGGER_NETDEV_FULL_DUPLEX) |
BIT(TRIGGER_NETDEV_HALF_DUPLEX) |
BIT(TRIGGER_NETDEV_LINK) |
@@ -1801,10 +1843,15 @@ static int yt8521_led_hw_control_set(struct phy_device *phydev, u8 index,
unsigned long rules)
{
u16 val = 0;
+ int ret;
if (index >= YT8521_MAX_LEDS)
return -EINVAL;
+ ret = yt8521_hw_led_on_set(phydev, index, false);
+ if (ret < 0)
+ return ret;
+
if (test_bit(TRIGGER_NETDEV_LINK, &rules)) {
val |= YT8521_LED_10_ON_EN;
val |= YT8521_LED_100_ON_EN;
@@ -3266,6 +3313,7 @@ static struct phy_driver motorcomm_phy_drvs[] = {
.soft_reset = yt8521_soft_reset,
.suspend = yt8521_suspend,
.resume = yt8521_resume,
+ .led_brightness_set = yt8521_led_brightness_set,
.led_hw_is_supported = yt8521_led_hw_is_supported,
.led_hw_control_set = yt8521_led_hw_control_set,
.led_hw_control_get = yt8521_led_hw_control_get,
@@ -3288,6 +3336,7 @@ static struct phy_driver motorcomm_phy_drvs[] = {
.get_wol = ytphy_get_wol,
.set_wol = yt8531_set_wol,
.link_change_notify = yt8531_link_change_notify,
+ .led_brightness_set = yt8521_led_brightness_set,
.led_hw_is_supported = yt8521_led_hw_is_supported,
.led_hw_control_set = yt8521_led_hw_control_set,
.led_hw_control_get = yt8521_led_hw_control_get,
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH net-next v3 2/2] net: phy: motorcomm: add missing trigger link for YT8521
2026-11-30 10:00 [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set for YT8521 Chukun Pan
@ 2026-11-30 10:00 ` Chukun Pan
2026-12-01 10:58 ` netdev-bot+sashiko
2026-11-30 13:17 ` [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set " Andrew Lunn
2026-12-01 10:58 ` netdev-bot+sashiko
2 siblings, 1 reply; 5+ messages in thread
From: Chukun Pan @ 2026-11-30 10:00 UTC (permalink / raw)
To: Frank
Cc: Andrew Lunn, Paolo Abeni, Jakub Kicinski, Eric Dumazet,
David S . Miller, Heiner Kallweit, linux-kernel, netdev,
Chukun Pan
TRIGGER_NETDEV_LINK is available in led_hw_control_set,
but missing in led_hw_control_get. Add it.
Signed-off-by: Chukun Pan <amadeus@jmu.edu.cn>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
Changes in v2:
Collect Reviewed-by
---
drivers/net/phy/motorcomm.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index e0c6477a53e4..27aee44a420f 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -1919,6 +1919,11 @@ static int yt8521_led_hw_control_get(struct phy_device *phydev, u8 index,
if (val & YT8521_LED_10_ON_EN)
__set_bit(TRIGGER_NETDEV_LINK_10, rules);
+ if ((val & YT8521_LED_10_ON_EN) &&
+ (val & YT8521_LED_100_ON_EN) &&
+ (val & YT8521_LED_1000_ON_EN))
+ __set_bit(TRIGGER_NETDEV_LINK, rules);
+
return 0;
}
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set for YT8521
2026-11-30 10:00 [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set for YT8521 Chukun Pan
2026-11-30 10:00 ` [PATCH net-next v3 2/2] net: phy: motorcomm: add missing trigger link " Chukun Pan
@ 2026-11-30 13:17 ` Andrew Lunn
2026-12-01 10:58 ` netdev-bot+sashiko
2 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2026-11-30 13:17 UTC (permalink / raw)
To: Chukun Pan
Cc: Frank, Paolo Abeni, Jakub Kicinski, Eric Dumazet,
David S . Miller, Heiner Kallweit, linux-kernel, netdev
On Mon, Nov 30, 2026 at 06:00:00PM +0800, Chukun Pan wrote:
> Add support for manual brightness setting on YT8521/YT8531 PHY.
> Switching to the netdev trigger will disable led forced mode.
> Testing with netdev and heartbeat on the Radxa E20C (YT8531).
>
> Signed-off-by: Chukun Pan <amadeus@jmu.edu.cn>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set for YT8521
2026-11-30 10:00 [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set for YT8521 Chukun Pan
2026-11-30 10:00 ` [PATCH net-next v3 2/2] net: phy: motorcomm: add missing trigger link " Chukun Pan
2026-11-30 13:17 ` [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set " Andrew Lunn
@ 2026-12-01 10:58 ` netdev-bot+sashiko
2 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 10:58 UTC (permalink / raw)
To: amadeus
Cc: Frank.Sae, andrew, pabeni, kuba, edumazet, davem, hkallweit1,
linux-kernel, netdev
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 (1) · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] The new LED brightness path reaches the PHY's extended registers
without holding the MDIO bus lock.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the existing
LED hw_control callbacks have the same missing MDIO bus lock.
--
net: phy: motorcomm: add led_brightness_set for YT8521
This commit adds a led_brightness_set callback for the YT8521 and YT8531
PHYs. The callback uses the force mode bits in the LED general config
register (0xA00B). It also makes led_hw_control_set() clear force mode
when switching to the netdev trigger.
> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
> index a87e83fdf590c..e0c6477a53e44 100644
> --- a/drivers/net/phy/motorcomm.c
> +++ b/drivers/net/phy/motorcomm.c
[ ... ]
> @@ -1775,6 +1779,44 @@ static int yt8531s_config_init(struct phy_device *phydev)
> return phy_restore_page(phydev, old_page, ret);
> }
>
> +static int yt8521_hw_led_on_set(struct phy_device *phydev, u8 index,
> + bool value)
> +{
> + int reg, val;
> + u16 mask;
> +
> + val = ytphy_read_ext(phydev, YTPHY_LED_GENERAL_CFG_REG);
> + if (val < 0)
> + return val;
> +
> + mask = YTPHY_LED_FORCE_EN(index) | YTPHY_LED_FORCE_MODE(index);
> + /* 0: force OFF, 1: force ON, same as the value */
> + reg = (val & ~mask) | (value << (index * 3));
> + if (value)
> + reg |= YTPHY_LED_FORCE_EN(index);
> +
> + if (reg == val)
> + return 0;
> +
> + return ytphy_write_ext(phydev, YTPHY_LED_GENERAL_CFG_REG, reg);
> +}
> +
> +static int yt8521_led_brightness_set(struct phy_device *phydev, u8 index,
> + enum led_brightness value)
> +{
> + int ret;
> +
> + if (index >= YT8521_MAX_LEDS)
> + return -EINVAL;
> +
> + /* clear HW LED setup */
> + ret = ytphy_write_ext(phydev, YT8521_LED0_CFG_REG + index, 0);
> + if (ret < 0)
> + return ret;
> +
> + return yt8521_hw_led_on_set(phydev, index, (value != LED_OFF));
> +}
[Severity: High]
Is the MDIO bus lock held on this path? ytphy_read_ext() and
ytphy_write_ext() are both documented with:
* NOTE:The caller must have taken the MDIO bus lock.
However, phy_led_set_brightness() in drivers/net/phy/phy_device.c only
takes phydev->lock before it calls the driver:
mutex_lock(&phydev->lock);
err = phydev->drv->led_brightness_set(phydev, phyled->index, value);
The call chain looks like this:
phy_led_set_brightness()
yt8521_led_brightness_set()
ytphy_write_ext(phydev, YT8521_LED0_CFG_REG + index, 0)
yt8521_hw_led_on_set()
ytphy_read_ext(phydev, YTPHY_LED_GENERAL_CFG_REG)
ytphy_write_ext(phydev, YTPHY_LED_GENERAL_CFG_REG, reg)
__phy_read() / __phy_write()
__mdiobus_read() / __mdiobus_write()
lockdep_assert_held_once(&bus->mdio_lock);
With CONFIG_LOCKDEP, wouldn't the first brightness change hit this
assertion? That change can come from sysfs or from a software trigger
such as heartbeat.
Without the bus lock, the 0x1E page select and 0x1F data pairs here are
not serialized against code that holds only the bus lock. That includes
phy_mii_ioctl(), other devices on the same MDIO bus, and the
ytphy_*_ext_with_lock() callers in suspend/resume.
Could the page select change between the select and the data access?
The write would then land in a different extended register, for example
0xA000 or the WoL config. A concurrent locked modify of 0xA00B could
also be lost between the read and the write in yt8521_hw_led_on_set().
The new yt8521_hw_led_on_set() call in yt8521_led_hw_control_set() has
the same problem, because phy_led_hw_control_set() also holds only
phydev->lock.
Would it work to take phy_lock_mdio_bus() once around the LEDx_CFG
clear and the GENERAL_CFG read-modify-write?
The later commit "net: phy: motorcomm: add missing trigger link for
YT8521" only changes yt8521_led_hw_control_get(), so it does not fix
this.
> @@ -1801,10 +1843,15 @@ static int yt8521_led_hw_control_set(struct phy_device *phydev, u8 index,
> unsigned long rules)
> {
> u16 val = 0;
> + int ret;
>
> if (index >= YT8521_MAX_LEDS)
> return -EINVAL;
>
> + ret = yt8521_hw_led_on_set(phydev, index, false);
> + if (ret < 0)
> + return ret;
> +
[Severity: High]
This is a pre-existing issue and was not introduced by this patch. The
existing LED hw_control callbacks also access the extended registers
without the MDIO bus lock.
The end of yt8521_led_hw_control_set() does:
return ytphy_write_ext(phydev, YT8521_LED0_CFG_REG + index, val);
and yt8521_led_hw_control_get() does:
val = ytphy_read_ext(phydev, YT8521_LED0_CFG_REG + index);
Both run with only phydev->lock held, taken by phy_led_hw_control_set()
and phy_led_hw_control_get(). The netdev trigger path therefore has the
same lockdep assertion and the same page select/data race. This patch
copies that unlocked pattern into the new brightness path.
If the locking gets fixed here, should the bus lock cover all of
yt8521_led_hw_control_set(), including this final write, and also
yt8521_led_hw_control_get()?
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130100001.3346131-1-amadeus%40jmu.edu.cn
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next v3 2/2] net: phy: motorcomm: add missing trigger link for YT8521
2026-11-30 10:00 ` [PATCH net-next v3 2/2] net: phy: motorcomm: add missing trigger link " Chukun Pan
@ 2026-12-01 10:58 ` netdev-bot+sashiko
0 siblings, 0 replies; 5+ messages in thread
From: netdev-bot+sashiko @ 2026-12-01 10:58 UTC (permalink / raw)
To: amadeus
Cc: Frank.Sae, andrew, pabeni, kuba, edumazet, davem, hkallweit1,
linux-kernel, netdev
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] After this patch, yt8521_led_hw_control_get()
(drivers/net/phy/motorcomm.c) still sets TRIGGER_NETDEV_LINK_10,…
- [Low] The commit says it adds a 'missing' TRIGGER_NETDEV_LINK readback
to yt8521_led_hw_control_get(), i.e. it fixes an omission.
--
net: phy: motorcomm: add missing trigger link for YT8521
This commit makes yt8521_led_hw_control_get() report TRIGGER_NETDEV_LINK
when the 10, 100 and 1000 ON_EN bits are all set in the LED config
register. This mirrors what yt8521_led_hw_control_set() does for
TRIGGER_NETDEV_LINK.
> net: phy: motorcomm: add missing trigger link for YT8521
>
> TRIGGER_NETDEV_LINK is available in led_hw_control_set,
> but missing in led_hw_control_get. Add it.
[Severity: Low]
This reads as a fix for an omission, but there is no Fixes: tag. Both
yt8521_led_hw_control_get() and the TRIGGER_NETDEV_LINK handling in
yt8521_led_hw_control_set() came from this commit:
Fixes: 355b82c54c12 ("net: phy: motorcomm: Add support for PHY LEDs on YT8521")
Should that tag be added?
The subject says "for YT8521", but the YT8531 phy_driver entry uses the
same callback:
.led_hw_control_get = yt8521_led_hw_control_get,
So YT8531 behaviour changes as well.
Adding a Fixes: tag would also mark the LINK plus LINK_xxx issue below
for stable backport. It may be worth resolving that issue first.
> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
> index e0c6477a53e44..27aee44a420fb 100644
> --- a/drivers/net/phy/motorcomm.c
> +++ b/drivers/net/phy/motorcomm.c
> @@ -1919,6 +1919,11 @@ static int yt8521_led_hw_control_get(struct phy_device *phydev, u8 index,
> if (val & YT8521_LED_10_ON_EN)
> __set_bit(TRIGGER_NETDEV_LINK_10, rules);
>
> + if ((val & YT8521_LED_10_ON_EN) &&
> + (val & YT8521_LED_100_ON_EN) &&
> + (val & YT8521_LED_1000_ON_EN))
> + __set_bit(TRIGGER_NETDEV_LINK, rules);
[Severity: Medium]
The code just above still sets TRIGGER_NETDEV_LINK_10, LINK_100 and
LINK_1000 for each enabled speed bit. When all three bits are set, the
returned rules become LINK | LINK_10 | LINK_100 | LINK_1000.
Does ledtrig-netdev accept that combination?
yt8521_led_hw_control_set() writes exactly this register state when link
is selected:
drivers/net/phy/motorcomm.c:yt8521_led_hw_control_set() {
...
if (test_bit(TRIGGER_NETDEV_LINK, &rules)) {
val |= YT8521_LED_10_ON_EN;
val |= YT8521_LED_100_ON_EN;
val |= YT8521_LED_1000_ON_EN;
}
...
}
A bootloader or hardware default with all three bits set would read
back the same way.
netdev_trig_activate() copies the hw_control_get() result straight into
trigger_data->mode:
drivers/leds/trigger/ledtrig-netdev.c:netdev_trig_activate() {
...
rc = led_cdev->hw_control_get(led_cdev, &mode);
if (!rc)
trigger_data->mode = mode;
...
}
netdev_led_attr_store() then starts from trigger_data->mode, flips one
bit, and rejects the result:
drivers/leds/trigger/ledtrig-netdev.c:netdev_led_attr_store() {
...
if (test_bit(TRIGGER_NETDEV_LINK, &mode) &&
(test_bit(TRIGGER_NETDEV_LINK_10, &mode) ||
test_bit(TRIGGER_NETDEV_LINK_100, &mode) ||
test_bit(TRIGGER_NETDEV_LINK_1000, &mode) ||
...
return -EINVAL;
...
}
Once the netdev trigger is active on such an LED, wouldn't these writes
all fail with -EINVAL?
echo 1 > tx
echo 0 > rx
echo 0 > full_duplex
echo 0 > link_100
echo 1 > link
Only "echo 0 > link" would succeed. Sysfs would also show link=1 together
with link_10, link_100 and link_1000 set to 1. The store path itself
never allows that state.
Before this patch, the same register value read back as
LINK_10 | LINK_100 | LINK_1000 without LINK. That passes the check, and
attribute writes worked. Both YT8521 and YT8531 are affected, since they
share this callback.
realtek_main.c (rtl8211f, rtl8211e, rtl822x) and air_an8801.c use the
same pattern, but this patch adds it to the motorcomm driver.
Could the code report only TRIGGER_NETDEV_LINK, and skip the
LINK_10/100/1000 bits, when all three speed bits are set? The other
option would be to make ledtrig-netdev normalise or accept this
combination.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261130100001.3346131-1-amadeus%40jmu.edu.cn
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-12-01 10:58 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 10:00 [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set for YT8521 Chukun Pan
2026-11-30 10:00 ` [PATCH net-next v3 2/2] net: phy: motorcomm: add missing trigger link " Chukun Pan
2026-12-01 10:58 ` netdev-bot+sashiko
2026-11-30 13:17 ` [PATCH net-next v3 1/2] net: phy: motorcomm: add led_brightness_set " Andrew Lunn
2026-12-01 10:58 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox