Devicetree
 help / color / mirror / Atom feed
* [PATCH net-next v9 0/2] net: phy: dap8211r: add LED control support
@ 2026-12-04  8:14 Artem Shimko
  2026-12-04  8:14 ` [PATCH net-next v9 1/2] net: phy: dap8211r: fix kernel-doc comments for extended register helpers Artem Shimko
  2026-12-04  8:14 ` [PATCH net-next v9 2/2] net: phy: dap8211r: add PHY LED control support Artem Shimko
  0 siblings, 2 replies; 7+ messages in thread
From: Artem Shimko @ 2026-12-04  8:14 UTC (permalink / raw)
  To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, robh,
	krzk+dt, conor+dt, maxime.chevallier, pavel
  Cc: Artem Shimko, linux-kernel, devicetree, linux-leds, netdev

Hello,

This series adds support for LEDs on the DAP8211R
Gigabit Ethernet PHY.

The first patch fixes mistakes in function comments about locking mdio.
The second one introduces a small helper to write extended
registers, since the LED registers are accessed indirectly via
EXT_ADD/EXT_DATA and implements the three LED callbacks
required by the PHY library.

Required:
CONFIG_NEW_LEDS=y
    CONFIG_LEDS_CLASS=y
    CONFIG_LEDS_TRIGGERS=y
        CONFIG_LEDS_TRIGGER_NETDEV=y

Testing:
$ ip link set eth1 up
$ ls /sys/class/leds/
stmmac-1:01:amber:lan  stmmac-1:01:green:lan
$ echo netdev > /sys/class/leds/stmmac-1:01:green:lan/trigger
$ echo eth1 > /sys/class/leds/stmmac-1:01:green:lan/device_name
$ echo 1 > /sys/class/leds/stmmac-1:01:green:lan/link_1000
$ cat /sys/class/leds/stmmac-1:01:green:lan/offloaded
$ ip addr add 192.168.5.100/24 dev eth1
$ ping -I eth1 192.168.5.1

$ echo netdev > /sys/class/leds/stmmac-1:01:amber:lan/trigger
$ echo eth1 > /sys/class/leds/stmmac-1:01:amber:lan/device_name
$ echo 1 > /sys/class/leds/stmmac-1:01:amber:lan/tx
$ echo 1 > /sys/class/leds/stmmac-1:01:amber:lan/rx
$ cat /sys/class/leds/stmmac-1:01:amber:lan/offloaded

$ echo none > /sys/class/leds/stmmac-1:01:amber:lan/trigger
$ echo 1 > /sys/class/leds/stmmac-1:01:amber:lan/brightness

$ echo netdev > /sys/class/leds/stmmac-1:01:amber:lan/trigger
$ echo 1 > /sys/class/leds/stmmac-1:01:amber:lan/tx
$ echo 1 > /sys/class/leds/stmmac-1:01:amber:lan/rx
$ ip addr add 192.168.5.100/24 dev eth1
$ ping -I eth1 192.168.5.1

--
Best regards,
artem

ChangeLog:
  v9:
    - Drop the dt-bindings patch, as ethernet-phy.yaml already covers it.
  v8:
    - Reference /schemas/leds/common.yaml#
    - Add unevaluatedProperties: false
    - Drop items under reg in the led@[0-2] subnode of dptel,dap8211r.yaml
    - Link: https://lore.kernel.org/all/CAOPX744wYc7JLrjcePWWpAyU_Uzbd37hsxBfjwAmUYRwu1nWow@mail.gmail.com/T/#u
  v7:
    - Add clear LED_x_CON in the dap8211r_led_brightness_set() function so
    that stale settings do not interfere with clearing the FORCE_EN bit in
    hw_control_set() when switching back to the `netdev` trigger.
    - Link: https://lore.kernel.org/all/20261127063708.3074433-1-a.shimko.dev@gmail.com/T/#t
  v6:
    - Return -EOPNOTSUPP in dap8211r_led_hw_control_get() if DAP8211R_LED_ACT_BLINK
    does not match the presence of DAP8211R_LED_RX or DAP8211R_LED_TX,
    preventing incomplete rule reporting and register clobbering.
    - Link: https://lore.kernel.org/all/CAOPX747OUSNbg2vqba3LL8r0chrTdpz6hOg1yf-n_wMX+fpQag@mail.gmail.com/T/#u
  v5:
    - Drop redundant $ref to common.yaml and inner unevaluatedProperties: false
    from the led@[0-2] subnode, as they are already inherited from
    ethernet-phy.yaml.
    - Move write of LED_x_CON first and clear FORCE_EN afterwards in
    dap8211r_led_hw_control_set().
    - Report TRIGGER_NETDEV_LINK instead of individual speed flags in
    dap8211r_led_hw_control_get() when all three link speed bits are set, as
    netdev trigger rejects reporting them together. Based on [1].
    - Add checking of DAP8211R_LED_ACT_BLINK alongside TX/RX bits in
    dap8211r_led_hw_control_get().
    - Add -EOPNOTSUPP in dap8211r_led_hw_control_get() if unsupported
    hardware bits are set in LED_x_CON.
    - Link: [1] https://lists.infradead.org/pipermail/linux-arm-kernel/2026-September/1172246.html
    - Link: https://lore.kernel.org/all/179560033613.3135.13122318439070700886@kernel.org/T/#u
  v4:
    - squash extended register write helper into the LED control patch to
    fix netdev/build_32bit, netdev/build_allmodconfig_warn, netdev/build_clang
    fails (patchwork.kernel.org)
    - add andrew+netdev@lunn.ch to Cc of dt-bindings patch to fix
    netdev/cc_maintainers warning (patchwork.kernel.org)
  v3:
    - fix kernel-doc comment for DAP8211R_LED_FORCE_MODE_ON and
    DAP8211R_LED_FORCE_MODE_MASK
    - use FIELD_PREP() for DAP8211R_LED_FORCE_MODE_ON 
    - Link: https://lore.kernel.org/all/20261120081106.2919010-1-a.shimko.dev@gmail.com/T/#t
  v2:
    - add a commit fixing kernel-doc comments for dap8211r_read_ext() and dap8211r_modify_ext()
    - move LED child node down below tx-internal-delay-ps in dptel,dap8211r.yaml
    - add blank lines in dptel,dap8211r.yaml
    - restrict LED reg index to 0..2 and fix schema properties in dptel,dap8211r.yaml
    - fix kernel-doc comment for dap8211r_write_ext()
    - add LED brightness (force mode) support to driver
    - remove rules == 0 statement
    - add TRIGGER_NETDEV_LINK to DAP8211R_LED_SUPPORTED_TRG for dap8211r_led_hw_is_supported()
    - clean up switch (index) statements
    - Link: https://lore.kernel.org/all/CAOPX74709XiLXLoioDJStTSzzhstC2sHpM4GieAO=3-37E18pw@mail.gmail.com/T/#u
  v1:
    - Link: https://lore.kernel.org/all/20261113110546.173624-1-a.shimko.dev@gmail.com/T/#t

Artem Shimko (2):
  net: phy: dap8211r: fix kernel-doc comments for extended register
    helpers
  net: phy: dap8211r: add PHY LED control support

 drivers/net/phy/dap8211r.c | 272 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 270 insertions(+), 2 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net-next v9 1/2] net: phy: dap8211r: fix kernel-doc comments for extended register helpers
  2026-12-04  8:14 [PATCH net-next v9 0/2] net: phy: dap8211r: add LED control support Artem Shimko
@ 2026-12-04  8:14 ` Artem Shimko
  2026-12-04  8:14 ` [PATCH net-next v9 2/2] net: phy: dap8211r: add PHY LED control support Artem Shimko
  1 sibling, 0 replies; 7+ messages in thread
From: Artem Shimko @ 2026-12-04  8:14 UTC (permalink / raw)
  To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, robh,
	krzk+dt, conor+dt, maxime.chevallier, pavel
  Cc: Artem Shimko, linux-kernel, devicetree, linux-leds, netdev

The kernel-doc comments for dap8211r_read_ext() and dap8211r_modify_ext()
incorrectly state that the caller must hold the MDIO bus lock.

Remove the misleading sentence from both comments since the functions
lock MDIO internally by themselves.

Fixes: d90265e75584d ("net: phy: add DAPU Telecom DAP8211R(I) Gigabit Ethernet PHY driver")
Signed-off-by: Artem Shimko <a.shimko.dev@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/phy/dap8211r.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/net/phy/dap8211r.c b/drivers/net/phy/dap8211r.c
index 0bf770f8ebbb..1fe20efd394d 100644
--- a/drivers/net/phy/dap8211r.c
+++ b/drivers/net/phy/dap8211r.c
@@ -69,7 +69,6 @@ static const int dap8211r_internal_delay[] = {0, 150, 300, 450, 600, 750, 900,
  * @reg: Extended register address
  *
  * Reads a PHY extended register using the indirect access method.
- * The caller must hold the MDIO bus lock.
  *
  * Return: Register value on success, or negative error code
  */
@@ -97,7 +96,6 @@ static int dap8211r_read_ext(struct phy_device *phydev, u16 reg)
  *
  * Modifies a PHY extended register using the indirect access method.
  * New value = (old value & ~mask) | set.
- * The caller must hold the MDIO bus lock.
  *
  * Return: 0 on success, or negative error code
  */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net-next v9 2/2] net: phy: dap8211r: add PHY LED control support
  2026-12-04  8:14 [PATCH net-next v9 0/2] net: phy: dap8211r: add LED control support Artem Shimko
  2026-12-04  8:14 ` [PATCH net-next v9 1/2] net: phy: dap8211r: fix kernel-doc comments for extended register helpers Artem Shimko
@ 2026-12-04  8:14 ` Artem Shimko
  2026-12-05  8:15   ` sashiko-bot
  2026-12-05  8:46   ` netdev-bot+sashiko
  1 sibling, 2 replies; 7+ messages in thread
From: Artem Shimko @ 2026-12-04  8:14 UTC (permalink / raw)
  To: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, robh,
	krzk+dt, conor+dt, maxime.chevallier, pavel
  Cc: Artem Shimko, linux-kernel, devicetree, linux-leds, netdev

Add support for hardware-controlled LEDs and brightness on the DAP8211R
PHY. The chip exposes three LEDs that can be programmed to react to link,
speed, duplex, and TX/RX activity or be driven via the force mode.

Add the dap8211r_write_ext() helper to access extended registers via the
PHY indirect access registers, and implement callbacks for:
led_brightness_set(), led_hw_is_supported(), led_hw_control_set(),
led_hw_control_get().

Signed-off-by: Artem Shimko <a.shimko.dev@gmail.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
---
 drivers/net/phy/dap8211r.c | 270 +++++++++++++++++++++++++++++++++++++
 1 file changed, 270 insertions(+)

diff --git a/drivers/net/phy/dap8211r.c b/drivers/net/phy/dap8211r.c
index 1fe20efd394d..c6d18312c8c3 100644
--- a/drivers/net/phy/dap8211r.c
+++ b/drivers/net/phy/dap8211r.c
@@ -12,6 +12,7 @@
  */
 
 #include <linux/bitfield.h>
+#include <linux/bitops.h>
 #include <linux/errno.h>
 #include <linux/ethtool.h>
 #include <linux/kernel.h>
@@ -57,6 +58,56 @@
  */
 #define DAP8211R_DEFAULT_DEL_SEL	0xD
 
+#define DAP8211R_LED_ID_0		0
+#define DAP8211R_LED_ID_1		1
+#define DAP8211R_LED_ID_2		2
+
+/*
+ * LED_COMCON force mode bits, per LED:
+ * bit 2 - FORCE_EN (enable force mode for this LED)
+ * bit 1:0 - FORCE_MODE: 00 = OFF, 01 = ON, 10 = blink mode1, 11 = blink mode2
+ *
+ * Only ON/OFF is supported.
+ */
+#define DAP8211R_LED_COMCON		0xA00B
+#define DAP8211R_LED_FORCE_MODE_EN	BIT(2)
+#define DAP8211R_LED_FORCE_MODE_MASK	GENMASK(1, 0)
+#define DAP8211R_LED_FORCE_MODE_ON	FIELD_PREP(DAP8211R_LED_FORCE_MODE_MASK, 1)
+
+#define DAP8211R_LED_FORCE_EN(idx)	(DAP8211R_LED_FORCE_MODE_EN << 3 * (idx))
+#define DAP8211R_LED_FORCE_ON(idx)	(DAP8211R_LED_FORCE_MODE_ON << 3 * (idx))
+#define DAP8211R_LED_FORCE_MASK(idx)	(DAP8211R_LED_FORCE_MODE_MASK << 3 * (idx))
+
+#define DAP8211R_LED_0_CON		0xA00C
+#define DAP8211R_LED_ACT_BLINK		BIT(13)
+#define DAP8211R_LED_FULL_DUPLEX	BIT(12)
+#define DAP8211R_LED_HALF_DUPLEX	BIT(11)
+#define DAP8211R_LED_TX			BIT(10)
+#define DAP8211R_LED_RX			BIT(9)
+#define DAP8211R_LED_LINK_1000		BIT(6)
+#define DAP8211R_LED_LINK_100		BIT(5)
+#define DAP8211R_LED_LINK_10		BIT(4)
+
+#define DAP8211R_LED_LINK		(DAP8211R_LED_LINK_10	| \
+					DAP8211R_LED_LINK_100	| \
+					DAP8211R_LED_LINK_1000)
+
+#define DAP8211R_LED_SUPPORTED_TRG	(BIT(TRIGGER_NETDEV_LINK)	| \
+					BIT(TRIGGER_NETDEV_LINK_10)	| \
+					BIT(TRIGGER_NETDEV_LINK_100)	| \
+					BIT(TRIGGER_NETDEV_LINK_1000)	| \
+					BIT(TRIGGER_NETDEV_TX)		| \
+					BIT(TRIGGER_NETDEV_RX)		| \
+					BIT(TRIGGER_NETDEV_HALF_DUPLEX)	| \
+					BIT(TRIGGER_NETDEV_FULL_DUPLEX))
+
+#define DAP8211R_LED_SUPPORTED_MASK	(DAP8211R_LED_ACT_BLINK		| \
+					DAP8211R_LED_FULL_DUPLEX	| \
+					DAP8211R_LED_HALF_DUPLEX	| \
+					DAP8211R_LED_TX			| \
+					DAP8211R_LED_RX			| \
+					DAP8211R_LED_LINK)
+
 static const int dap8211r_internal_delay[] = {0, 150, 300, 450, 600, 750, 900,
 					      1050, 1200, 1350, 1500, 1650, 1800,
 					      1950, 2100, 2250};
@@ -87,6 +138,31 @@ static int dap8211r_read_ext(struct phy_device *phydev, u16 reg)
 	return ret;
 }
 
+/**
+ * dap8211r_write_ext() - Write extended register
+ * @phydev: PHY device structure
+ * @reg: Extended register address
+ * @data: Data to write
+ *
+ * Writes a PHY extended register using the indirect access method.
+ *
+ * Return: 0 on success, or negative error code
+ */
+static int dap8211r_write_ext(struct phy_device *phydev, u16 reg, u16 data)
+{
+	int ret;
+
+	phy_lock_mdio_bus(phydev);
+	ret = __phy_write(phydev, DAP8211R_EXT_ADD, reg);
+	if (ret < 0)
+		goto out;
+
+	ret = __phy_write(phydev, DAP8211R_EXT_DATA, data);
+out:
+	phy_unlock_mdio_bus(phydev);
+	return ret;
+}
+
 /**
  * dap8211r_modify_ext() - Modify extended register bits
  * @phydev: PHY device structure
@@ -114,6 +190,196 @@ static int dap8211r_modify_ext(struct phy_device *phydev, u16 reg, u16 mask, u16
 	return ret;
 }
 
+/**
+ * dap8211r_led_brightness_set() - Modify the LEDs common control register
+ * @phydev: PHY device structure
+ * @index: LED index
+ * @value: ON/OFF value for force mode of the LED
+ *
+ * Clears the LED control register, enables force mode and sets the LED to
+ * ON/OFF state. Force mode will be disabled when hardware LED control is
+ * requested.
+ *
+ * Return: 0 on success, -EINVAL for an invalid LED index, or a negative error code
+ */
+static int dap8211r_led_brightness_set(struct phy_device *phydev, u8 index,
+				       enum led_brightness value)
+{
+	u16 set, mask, led_reg;
+	int ret;
+
+	switch (index) {
+	case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2:
+		mask = DAP8211R_LED_FORCE_MASK(index);
+		set = DAP8211R_LED_FORCE_EN(index);
+		led_reg = DAP8211R_LED_0_CON + index;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (value != LED_OFF)
+		set |= DAP8211R_LED_FORCE_ON(index);
+
+	ret = dap8211r_write_ext(phydev, led_reg, 0);
+	if (ret)
+		return ret;
+
+	return dap8211r_modify_ext(phydev, DAP8211R_LED_COMCON, mask, set);
+}
+
+/**
+ * dap8211r_led_hw_is_supported() - Check if the requested LED rules are supported
+ * @phydev: PHY device structure
+ * @index: LED index
+ * @rules: Bitmask of requested netdev trigger rules
+ *
+ * Validates the requested combination of rules which can be represented in the
+ * hardware register.
+ *
+ * Return: 0 on success, -EINVAL for an invalid LED index,
+ *         or -EOPNOTSUPP if any requested rule is not supported by the PHY
+ */
+static int dap8211r_led_hw_is_supported(struct phy_device *phydev, u8 index, unsigned long rules)
+{
+	switch (index) {
+	case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2:
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return (rules & ~DAP8211R_LED_SUPPORTED_TRG) ? -EOPNOTSUPP : 0;
+}
+
+/**
+ * dap8211r_led_hw_control_set() - Write the LED control register
+ * @phydev: PHY device structure
+ * @index: LED index
+ * @rules: Bitmask of requested netdev trigger rules
+ *
+ * Disables force mode and translates the requested trigger rules into
+ * the corresponding bit positions of the LED control register and writes
+ * the resulting value to the PHY.
+ *
+ * Note that the ACT_BLINK bit (13) must be set together with TX/RX rules,
+ * otherwise the LED will not blink on traffic if no other rule (such as
+ * link or duplex) is active.
+ *
+ * Return: 0 on success, -EINVAL for an invalid LED index, or a negative error code
+ */
+static int dap8211r_led_hw_control_set(struct phy_device *phydev, u8 index, unsigned long rules)
+{
+	u16 led_mode = 0, led_reg;
+	int ret;
+
+	switch (index) {
+	case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2:
+		led_reg = DAP8211R_LED_0_CON + index;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	if (test_bit(TRIGGER_NETDEV_LINK, &rules))
+		led_mode |= DAP8211R_LED_LINK;
+
+	if (test_bit(TRIGGER_NETDEV_LINK_10, &rules))
+		led_mode |= DAP8211R_LED_LINK_10;
+
+	if (test_bit(TRIGGER_NETDEV_LINK_100, &rules))
+		led_mode |= DAP8211R_LED_LINK_100;
+
+	if (test_bit(TRIGGER_NETDEV_LINK_1000, &rules))
+		led_mode |= DAP8211R_LED_LINK_1000;
+
+	if (test_bit(TRIGGER_NETDEV_RX, &rules))
+		led_mode |= DAP8211R_LED_RX | DAP8211R_LED_ACT_BLINK;
+
+	if (test_bit(TRIGGER_NETDEV_TX, &rules))
+		led_mode |= DAP8211R_LED_TX | DAP8211R_LED_ACT_BLINK;
+
+	if (test_bit(TRIGGER_NETDEV_HALF_DUPLEX, &rules))
+		led_mode |= DAP8211R_LED_HALF_DUPLEX;
+
+	if (test_bit(TRIGGER_NETDEV_FULL_DUPLEX, &rules))
+		led_mode |= DAP8211R_LED_FULL_DUPLEX;
+
+	ret = dap8211r_write_ext(phydev, led_reg, led_mode);
+	if (ret)
+		return ret;
+
+	return dap8211r_modify_ext(phydev, DAP8211R_LED_COMCON,
+				   DAP8211R_LED_FORCE_EN(index), 0);
+}
+
+/**
+ * dap8211r_led_hw_control_get() - Read the current LED configuration
+ * @phydev: PHY device structure
+ * @index: LED index
+ * @rules: Pointer to a bitmask where the current rules will be stored
+ *
+ * Reads the LED control register and translates the hardware bit
+ * positions back into the corresponding netdev trigger rules bitmask.
+ *
+ * Return: 0 on success, -EINVAL for an invalid LED index, -EOPNOTSUPP if the
+ *         current hardware configuration cannot be represented in rules, or a
+ *         negative error code
+ */
+static int dap8211r_led_hw_control_get(struct phy_device *phydev, u8 index, unsigned long *rules)
+{
+	u16 led_reg;
+	int led_mode = 0;
+
+	switch (index) {
+	case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2:
+		led_reg = DAP8211R_LED_0_CON + index;
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	led_mode = dap8211r_read_ext(phydev, led_reg);
+	if (led_mode < 0)
+		return led_mode;
+
+	if (led_mode & ~DAP8211R_LED_SUPPORTED_MASK)
+		return -EOPNOTSUPP;
+
+	if (!!(led_mode & DAP8211R_LED_ACT_BLINK) !=
+	    !!(led_mode & (DAP8211R_LED_RX | DAP8211R_LED_TX)))
+		return -EOPNOTSUPP;
+
+	if ((led_mode & DAP8211R_LED_LINK) == DAP8211R_LED_LINK) {
+		__set_bit(TRIGGER_NETDEV_LINK, rules);
+	} else {
+		if (led_mode & DAP8211R_LED_LINK_10)
+			__set_bit(TRIGGER_NETDEV_LINK_10, rules);
+
+		if (led_mode & DAP8211R_LED_LINK_100)
+			__set_bit(TRIGGER_NETDEV_LINK_100, rules);
+
+		if (led_mode & DAP8211R_LED_LINK_1000)
+			__set_bit(TRIGGER_NETDEV_LINK_1000, rules);
+	}
+
+	if ((led_mode & DAP8211R_LED_RX) &&
+	    (led_mode & DAP8211R_LED_ACT_BLINK))
+		__set_bit(TRIGGER_NETDEV_RX, rules);
+
+	if ((led_mode & DAP8211R_LED_TX) &&
+	    (led_mode & DAP8211R_LED_ACT_BLINK))
+		__set_bit(TRIGGER_NETDEV_TX, rules);
+
+	if (led_mode & DAP8211R_LED_HALF_DUPLEX)
+		__set_bit(TRIGGER_NETDEV_HALF_DUPLEX, rules);
+
+	if (led_mode & DAP8211R_LED_FULL_DUPLEX)
+		__set_bit(TRIGGER_NETDEV_FULL_DUPLEX, rules);
+
+	return 0;
+}
+
 /**
  * dap8211r_config_init() - Initialize PHY
  * @phydev: PHY device structure
@@ -202,6 +468,10 @@ static struct phy_driver dap8211r_driver[] = {
 		.config_aneg	= genphy_config_aneg,
 		.suspend	= genphy_suspend,
 		.resume		= genphy_resume,
+		.led_brightness_set	= dap8211r_led_brightness_set,
+		.led_hw_is_supported	= dap8211r_led_hw_is_supported,
+		.led_hw_control_set	= dap8211r_led_hw_control_set,
+		.led_hw_control_get	= dap8211r_led_hw_control_get,
 	},
 };
 module_phy_driver(dap8211r_driver);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v9 2/2] net: phy: dap8211r: add PHY LED control support
  2026-12-04  8:14 ` [PATCH net-next v9 2/2] net: phy: dap8211r: add PHY LED control support Artem Shimko
@ 2026-12-05  8:15   ` sashiko-bot
  2026-12-05  8:42     ` Artem Shimko
  2026-12-05  8:46   ` netdev-bot+sashiko
  1 sibling, 1 reply; 7+ messages in thread
From: sashiko-bot @ 2026-12-05  8:15 UTC (permalink / raw)
  To: Artem Shimko; +Cc: devicetree, linux-leds, robh, conor+dt, lee

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net: phy: dap8211r: dap8211r_led_hw_control_get() ignores LED
  force mode
--

commit 85921fb87a4aee5097a4e8dcd4ee62712d18ce09
Author: Artem Shimko <a.shimko.dev@gmail.com>

net: phy: dap8211r: add PHY LED control support

This commit adds brightness and hardware-controlled netdev trigger LED
support for the DAP8211R PHY, along with a dap8211r_write_ext() helper.

> diff --git a/drivers/net/phy/dap8211r.c b/drivers/net/phy/dap8211r.c
> index 1fe20efd394d7..c6d18312c8c34 100644
> --- a/drivers/net/phy/dap8211r.c
> +++ b/drivers/net/phy/dap8211r.c

[ ... ]

> +static int dap8211r_led_hw_control_get(struct phy_device *phydev, u8 index, unsigned long *rules)
> +{
> +	u16 led_reg;
> +	int led_mode = 0;
> +
> +	switch (index) {
> +	case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2:
> +		led_reg = DAP8211R_LED_0_CON + index;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	led_mode = dap8211r_read_ext(phydev, led_reg);
> +	if (led_mode < 0)
> +		return led_mode;
> +
> +	if (led_mode & ~DAP8211R_LED_SUPPORTED_MASK)
> +		return -EOPNOTSUPP;

[Severity: Medium]
Should dap8211r_led_hw_control_get() check DAP8211R_LED_FORCE_EN(index) in
DAP8211R_LED_COMCON and return -EOPNOTSUPP when force mode is active?

When force mode is enabled, the PHY drives the LED from DAP8211R_LED_COMCON
rather than led_reg.  If an LED is forced on via brightness and the netdev
trigger is then activated, netdev_trig_activate() gets 0 with empty rules
and reports hardware offload in sysfs while the LED stays forced on.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261204081448.3199171-1-a.shimko.dev@gmail.com?part=2

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v9 2/2] net: phy: dap8211r: add PHY LED control support
  2026-12-05  8:15   ` sashiko-bot
@ 2026-12-05  8:42     ` Artem Shimko
  0 siblings, 0 replies; 7+ messages in thread
From: Artem Shimko @ 2026-12-05  8:42 UTC (permalink / raw)
  To: sashiko-reviews; +Cc: devicetree, linux-leds, robh, conor+dt, lee

On Sat, Dec 5, 2026 at 11:15 AM <sashiko-bot@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] net: phy: dap8211r: dap8211r_led_hw_control_get() ignores LED
>   force mode
> --
>
> commit 85921fb87a4aee5097a4e8dcd4ee62712d18ce09
> Author: Artem Shimko <a.shimko.dev@gmail.com>
>
> net: phy: dap8211r: add PHY LED control support
>
> This commit adds brightness and hardware-controlled netdev trigger LED
> support for the DAP8211R PHY, along with a dap8211r_write_ext() helper.
>
> > diff --git a/drivers/net/phy/dap8211r.c b/drivers/net/phy/dap8211r.c
> > index 1fe20efd394d7..c6d18312c8c34 100644
> > --- a/drivers/net/phy/dap8211r.c
> > +++ b/drivers/net/phy/dap8211r.c
>
> [ ... ]
>
> > +static int dap8211r_led_hw_control_get(struct phy_device *phydev, u8 index, unsigned long *rules)
> > +{
> > +     u16 led_reg;
> > +     int led_mode = 0;
> > +
> > +     switch (index) {
> > +     case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2:
> > +             led_reg = DAP8211R_LED_0_CON + index;
> > +             break;
> > +     default:
> > +             return -EINVAL;
> > +     }
> > +
> > +     led_mode = dap8211r_read_ext(phydev, led_reg);
> > +     if (led_mode < 0)
> > +             return led_mode;
> > +
> > +     if (led_mode & ~DAP8211R_LED_SUPPORTED_MASK)
> > +             return -EOPNOTSUPP;
>
> [Severity: Medium]
> Should dap8211r_led_hw_control_get() check DAP8211R_LED_FORCE_EN(index) in
> DAP8211R_LED_COMCON and return -EOPNOTSUPP when force mode is active?
>
> When force mode is enabled, the PHY drives the LED from DAP8211R_LED_COMCON
> rather than led_reg.  If an LED is forced on via brightness and the netdev
> trigger is then activated, netdev_trig_activate() gets 0 with empty rules
> and reports hardware offload in sysfs while the LED stays forced on.

In practice, activating the `netdev` trigger is followed by configuring
at least one rule (such as `link`, `tx` or `rx`), which invokes
dap8211r_led_hw_control_set() and clears DAP8211R_LED_FORCE_EN(index).
So I would prefer to keep v9 as-is.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v9 2/2] net: phy: dap8211r: add PHY LED control support
  2026-12-04  8:14 ` [PATCH net-next v9 2/2] net: phy: dap8211r: add PHY LED control support Artem Shimko
  2026-12-05  8:15   ` sashiko-bot
@ 2026-12-05  8:46   ` netdev-bot+sashiko
  2026-12-05  8:56     ` Artem Shimko
  1 sibling, 1 reply; 7+ messages in thread
From: netdev-bot+sashiko @ 2026-12-05  8:46 UTC (permalink / raw)
  To: a.shimko.dev
  Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, robh,
	krzk+dt, conor+dt, maxime.chevallier, pavel, linux-kernel,
	devicetree, linux-leds, netdev

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · 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).

- [Medium] dap8211r_led_hw_control_get() (drivers/net/phy/dap8211r.c:343)
  can return a set of hardware-control rules that the hardware is not…

--

net: phy: dap8211r: add PHY LED control support

This adds LED support for the three LEDs on the DAP8211R PHY. It adds a
dap8211r_write_ext() helper and the led_brightness_set, led_hw_is_supported,
led_hw_control_set and led_hw_control_get callbacks. Brightness is driven
through the force mode bits in LED_COMCON, and hardware control is driven
through the per-LED LED_x_CON rule registers.

> diff --git a/drivers/net/phy/dap8211r.c b/drivers/net/phy/dap8211r.c
> index 1fe20efd394d7..c6d18312c8c34 100644
> --- a/drivers/net/phy/dap8211r.c
> +++ b/drivers/net/phy/dap8211r.c

[ ... ]

> @@ -114,6 +190,196 @@ static int dap8211r_modify_ext(struct phy_device *phydev, u16 reg, u16 mask, u16
>  	return ret;
>  }
>  

[ ... ]

> +static int dap8211r_led_hw_control_get(struct phy_device *phydev, u8 index, unsigned long *rules)
> +{
> +	u16 led_reg;
> +	int led_mode = 0;
> +
> +	switch (index) {
> +	case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2:
> +		led_reg = DAP8211R_LED_0_CON + index;
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	led_mode = dap8211r_read_ext(phydev, led_reg);
> +	if (led_mode < 0)
> +		return led_mode;

[Severity: Medium]
Can this return rules that the hardware is not actually following?

This function only reads LED_x_CON. It never checks FORCE_EN(index) in
DAP8211R_LED_COMCON. So when the LED is in force mode, it still returns 0
along with whatever LED_x_CON happens to hold.

The led_hw_control_get description in include/linux/phy.h says the callback
should "Set *@rules to how the HW is currently blinking" and return an error
"if the current blinking cannot be represented in rules". The kernel-doc
above this function also promises -EOPNOTSUPP for that case.

netdev_trig_activate() trusts a 0 return:

drivers/leds/trigger/ledtrig-netdev.c:netdev_trig_activate() {
    ...
			trigger_data->hw_control = true;
			set_device_name(trigger_data, name, strlen(name));

			rc = led_cdev->hw_control_get(led_cdev, &mode);
			if (!rc)
				trigger_data->mode = mode;
    ...
}

On this path, set_device_name() skips set_baseline_state(). That means
hw_control_set() is never called and FORCE_EN is never cleared.

This sequence looks like it would hit the problem:

  echo none > trigger
  echo 1 > brightness
    dap8211r_led_brightness_set()
      LED_x_CON = 0, FORCE_EN | FORCE_ON set
  echo netdev > trigger   (PHY attached)
    netdev_trig_activate()
      hw_control_get() reads LED_x_CON = 0, returns 0 with mode = 0

After that, the trigger reports hardware control with no rules, but the LED
stays forced on. This lasts until a later mode, device_name or netdev event
calls hw_control_set().

The same thing would happen if firmware or a bootloader leaves FORCE_EN set
with non-zero LED_x_CON rules. Those rules would be reported as active while
the LED is forced.

Would it make sense to also read DAP8211R_LED_COMCON here and return
-EOPNOTSUPP when FORCE_EN(index) is set?

A related question is what happens when only half of a two-register update
succeeds. In dap8211r_led_hw_control_set():

	ret = dap8211r_write_ext(phydev, led_reg, led_mode);
	if (ret)
		return ret;

	return dap8211r_modify_ext(phydev, DAP8211R_LED_COMCON,
				   DAP8211R_LED_FORCE_EN(index), 0);

If the COMCON modify fails, the LED stays forced, but hw_control_get()
reports the new rules. set_baseline_state() also ignores the return value
of hw_control_set().

In dap8211r_led_brightness_set(), LED_x_CON is zeroed before the COMCON
modify. If that modify fails, the LED has lost its rules and is not in
force mode either.

Should either of these restore the first register when the second access
fails?

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261204081448.3199171-1-a.shimko.dev%40gmail.com

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net-next v9 2/2] net: phy: dap8211r: add PHY LED control support
  2026-12-05  8:46   ` netdev-bot+sashiko
@ 2026-12-05  8:56     ` Artem Shimko
  0 siblings, 0 replies; 7+ messages in thread
From: Artem Shimko @ 2026-12-05  8:56 UTC (permalink / raw)
  To: netdev-bot+sashiko
  Cc: andrew, hkallweit1, linux, davem, edumazet, kuba, pabeni, robh,
	krzk+dt, conor+dt, maxime.chevallier, pavel, linux-kernel,
	devicetree, linux-leds, netdev

On Sat, Dec 5, 2026 at 11:46 AM <netdev-bot+sashiko@kernel.org> wrote:
>
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
>
> Critical: 0 · High: 0 · Medium: 1 · 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).
>
> - [Medium] dap8211r_led_hw_control_get() (drivers/net/phy/dap8211r.c:343)
>   can return a set of hardware-control rules that the hardware is not…
>
> --
>
> net: phy: dap8211r: add PHY LED control support
>
> This adds LED support for the three LEDs on the DAP8211R PHY. It adds a
> dap8211r_write_ext() helper and the led_brightness_set, led_hw_is_supported,
> led_hw_control_set and led_hw_control_get callbacks. Brightness is driven
> through the force mode bits in LED_COMCON, and hardware control is driven
> through the per-LED LED_x_CON rule registers.
>
> > diff --git a/drivers/net/phy/dap8211r.c b/drivers/net/phy/dap8211r.c
> > index 1fe20efd394d7..c6d18312c8c34 100644
> > --- a/drivers/net/phy/dap8211r.c
> > +++ b/drivers/net/phy/dap8211r.c
>
> [ ... ]
>
> > @@ -114,6 +190,196 @@ static int dap8211r_modify_ext(struct phy_device *phydev, u16 reg, u16 mask, u16
> >       return ret;
> >  }
> >
>
> [ ... ]
>
> > +static int dap8211r_led_hw_control_get(struct phy_device *phydev, u8 index, unsigned long *rules)
> > +{
> > +     u16 led_reg;
> > +     int led_mode = 0;
> > +
> > +     switch (index) {
> > +     case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2:
> > +             led_reg = DAP8211R_LED_0_CON + index;
> > +             break;
> > +     default:
> > +             return -EINVAL;
> > +     }
> > +
> > +     led_mode = dap8211r_read_ext(phydev, led_reg);
> > +     if (led_mode < 0)
> > +             return led_mode;
>
> [Severity: Medium]
> Can this return rules that the hardware is not actually following?
>
> This function only reads LED_x_CON. It never checks FORCE_EN(index) in
> DAP8211R_LED_COMCON. So when the LED is in force mode, it still returns 0
> along with whatever LED_x_CON happens to hold.
>
> The led_hw_control_get description in include/linux/phy.h says the callback
> should "Set *@rules to how the HW is currently blinking" and return an error
> "if the current blinking cannot be represented in rules". The kernel-doc
> above this function also promises -EOPNOTSUPP for that case.
>
> netdev_trig_activate() trusts a 0 return:
>
> drivers/leds/trigger/ledtrig-netdev.c:netdev_trig_activate() {
>     ...
>                         trigger_data->hw_control = true;
>                         set_device_name(trigger_data, name, strlen(name));
>
>                         rc = led_cdev->hw_control_get(led_cdev, &mode);
>                         if (!rc)
>                                 trigger_data->mode = mode;
>     ...
> }
>
> On this path, set_device_name() skips set_baseline_state(). That means
> hw_control_set() is never called and FORCE_EN is never cleared.
>
> This sequence looks like it would hit the problem:
>
>   echo none > trigger
>   echo 1 > brightness
>     dap8211r_led_brightness_set()
>       LED_x_CON = 0, FORCE_EN | FORCE_ON set
>   echo netdev > trigger   (PHY attached)
>     netdev_trig_activate()
>       hw_control_get() reads LED_x_CON = 0, returns 0 with mode = 0
>
> After that, the trigger reports hardware control with no rules, but the LED
> stays forced on. This lasts until a later mode, device_name or netdev event
> calls hw_control_set().
>
> The same thing would happen if firmware or a bootloader leaves FORCE_EN set
> with non-zero LED_x_CON rules. Those rules would be reported as active while
> the LED is forced.
>
> Would it make sense to also read DAP8211R_LED_COMCON here and return
> -EOPNOTSUPP when FORCE_EN(index) is set?
>
> A related question is what happens when only half of a two-register update
> succeeds. In dap8211r_led_hw_control_set():
>
>         ret = dap8211r_write_ext(phydev, led_reg, led_mode);
>         if (ret)
>                 return ret;
>
>         return dap8211r_modify_ext(phydev, DAP8211R_LED_COMCON,
>                                    DAP8211R_LED_FORCE_EN(index), 0);
>
> If the COMCON modify fails, the LED stays forced, but hw_control_get()
> reports the new rules. set_baseline_state() also ignores the return value
> of hw_control_set().
>
> In dap8211r_led_brightness_set(), LED_x_CON is zeroed before the COMCON
> modify. If that modify fails, the LED has lost its rules and is not in
> force mode either.
>
> Should either of these restore the first register when the second access
> fails?

ok

Checking DAP8211R_LED_FORCE_EN(index) in dap8211r_led_hw_control_get()
and retrning -EOPNOTSUPP when force mode is active makes complete
sense. I will add this check in v10.

Regarding rolling back the first MDIO write if the second access
fails: an MDIO error indicates a bus failure.

pw-bot: cr

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-12-05  8:56 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04  8:14 [PATCH net-next v9 0/2] net: phy: dap8211r: add LED control support Artem Shimko
2026-12-04  8:14 ` [PATCH net-next v9 1/2] net: phy: dap8211r: fix kernel-doc comments for extended register helpers Artem Shimko
2026-12-04  8:14 ` [PATCH net-next v9 2/2] net: phy: dap8211r: add PHY LED control support Artem Shimko
2026-12-05  8:15   ` sashiko-bot
2026-12-05  8:42     ` Artem Shimko
2026-12-05  8:46   ` netdev-bot+sashiko
2026-12-05  8:56     ` Artem Shimko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox