net: phy: dap8211r: add LED control support
Subsystems (5)
v4 cover net: phy: dap8211r: add LED control support
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 patch documents the optional "leds" node in the Device Tree binding.
The third patch 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.
$ make dt_binding_check DT_SCHEMA_FILES=Documentation/devicetree/bindings/net/dptel,dap8211r.yaml
SCHEMA Documentation/devicetree/bindings/processed-schema.json
CHKDT ./Documentation/devicetree/bindings
LINT ./Documentation/devicetree/bindings
STYLE ./Documentation/devicetree/bindings
DTEX Documentation/devicetree/bindings/net/dptel,dap8211r.example.dts
DTC [C] Documentation/devicetree/bindings/net/dptel,dap8211r.example.dtb
$ yamllint Documentation/devicetree/bindings/net/dptel,dap8211r.yaml
$ grep -i "dap8211r" Documentation/devicetree/bindings/processed-schema.json
"http://devicetree.org/schemas/net/dptel,dap8211r.yaml": {
"$filename": "/home/a-shimko/patchwork/linux/Documentation/devicetree/bindings/net/dptel,dap8211r.yaml",
"$id": "http://devicetree.org/schemas/net/dptel,dap8211r.yaml#",
"title": "DAPU Telecom DAP8211R(I) Gigabit Ethernet PHY",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:
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 [email protected] 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/[email protected]/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/[email protected]/T/#t
Artem Shimko (3):
net: phy: dap8211r: fix kernel-doc comments for extended register
helpers
dt-bindings: net: dptel,dap8211r: add LED nodes
net: phy: dap8211r: add PHY LED control support
.../bindings/net/dptel,dap8211r.yaml | 50 ++++ drivers/net/phy/dap8211r.c | 242 +++++++++++++++++- 2 files changed, 290 insertions(+), 2 deletions(-)
Signature · 1 line
2.43.0
PATCH v4 1/3 net: phy: dap8211r: fix kernel-doc comments for extended register helpers
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.
--- drivers/net/phy/dap8211r.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/phy/dap8211r.c +0 -2
@@ -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 */
Signature · 1 line
2.43.0
PATCH v4 2/3 dt-bindings: net: dptel,dap8211r: add LED nodes
In reply to Artem ShimkoDocument the optional "leds" node supported by the DAP8211R PHY.
The PHY exposes three configurable LED outputs, each of which can be assigned a color, a function and a default trigger.
--- .../bindings/net/dptel,dap8211r.yaml | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+)
Documentation/devicetree/bindings/net/dptel,dap8211r.yaml +50 -0
@@ -20,6 +20,7 @@ description: | - IEEE 802.3az-2010 Energy Efficient Ethernet - IEEE 1588 SyncE support - Internal packet generator and checker for link diagnostics + - Three configurable LEDs (link, speed, duplex, TX/RX activity) allOf: - $ref: ethernet-phy.yaml#
@@ -45,10 +46,40 @@ properties: maximum: 2250 default: 1950 + leds: + type: object + + description: + Optional node describing the three configurable LEDs of the PHY. + Each LED can be assigned a color, function and default trigger + (e.g. "netdev" for link/activity indication). + + properties: + '#address-cells': + const: 1 + '#size-cells': + const: 0 + + patternProperties: + '^led@[0-2]$': + type: object + + $ref: /schemas/leds/common.yaml# + unevaluatedProperties: false + + properties: + reg: + items: + maximum: 2 + + additionalProperties: false + unevaluatedProperties: false examples: - | + #include <dt-bindings/leds/common.h> + mdio { #address-cells = <1>; #size-cells = <0>;
@@ -58,5 +89,24 @@ examples: reg = <1>; rx-internal-delay-ps = <1950>; tx-internal-delay-ps = <1950>; + + leds { + #address-cells = <1>; + #size-cells = <0>; + + led@0 { + reg = <0>; + color = <LED_COLOR_ID_GREEN>; + function = LED_FUNCTION_LAN; + linux,default-trigger = "netdev"; + }; + + led@1 { + reg = <1>; + color = <LED_COLOR_ID_AMBER>; + function = LED_FUNCTION_LAN; + linux,default-trigger = "netdev"; + }; + }; }; };
Signature · 1 line
2.43.0
PATCH v4 3/3 net: phy: dap8211r: add PHY LED control support
In reply to Artem ShimkoAdd 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().
--- drivers/net/phy/dap8211r.c | 240 +++++++++++++++++++++++++++++++++++++ 1 file changed, 240 insertions(+)
drivers/net/phy/dap8211r.c +240 -0
@@ -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,49 @@*/ #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)) +static const int dap8211r_internal_delay[] = {0 ,150 ,300 ,450 ,600 ,750 ,900 ,1050 ,1200 ,1350 ,1500 ,1650 ,1800 ,1950 ,2100 ,2250 };
@@ -87,6 +131,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 +183,173 @@ static int dap8211r_modify_ext(struct phy_device *phydev, u16 reg, u16 mask, u16return 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 +* +* Enables force mode and sets the LED to ON/OFF state. +* It 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; + +switch (index) { + case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2: + mask =DAP8211R_LED_FORCE_MASK (index); + set =DAP8211R_LED_FORCE_EN (index); +break ; +default : +return -EINVAL ; + } + +if (value !=LED_OFF ) + set |=DAP8211R_LED_FORCE_ON (index); + +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 ; + } + + ret =dap8211r_modify_ext (phydev,DAP8211R_LED_COMCON ,DAP8211R_LED_FORCE_EN (index),0 ); +if (ret) +return ret; + +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 ; + +return dap8211r_write_ext (phydev, led_reg, led_mode); +} + +/** +* 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, 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_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 ) +__set_bit (TRIGGER_NETDEV_RX , rules); + +if (led_mode &DAP8211R_LED_TX ) +__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 +438,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);
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this 3-patch series and found no issues.
Sashiko has reviewed this 3-patch series and found no issues.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]
Re: [PATCH net-next v4 3/3] net: phy: dap8211r: add PHY LED control support
In reply to Artem ShimkoQuoted 10 lines · Artem Shimko
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 <[email protected]>
Andrew
[email protected]
AI reviewRe: [PATCH net-next v4 2/3] dt-bindings: net: dptel,dap8211r: add LED nodes
In reply to Artem ShimkoThank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The new leds block in Documentation/devicetree/bindings/net/dptel,dap8211r.yaml mostly…
--
dt-bindings: net: dptel,dap8211r: add LED nodes
This commit documents an optional leds node in the DAP8211R PHY binding. The PHY has three LED outputs, and each can be given a color, a function and a default trigger. The commit also adds an example with two LED nodes.
Quoted 4 lines
Documentation/devicetree/bindings/net/dptel,dap8211r.yaml +0
-0
[ ... ]
Quoted 22 lines
Documentation/devicetree/bindings/net/dptel,dap8211r.yaml +18
-0@@ -45,10 +46,40 @@ properties: maximum: 2250 default: 1950 + leds: + type: object + + description: + Optional node describing the three configurable LEDs of the PHY. + Each LED can be assigned a color, function and default trigger + (e.g. "netdev" for link/activity indication). + + properties: + '#address-cells': + const: 1 + '#size-cells': + const: 0 + + patternProperties: + '^led@[0-2]$': + type: object +
Documentation/devicetree/bindings/net/dptel,dap8211r.yaml properties: · line 76
Quoted 10 lines
Documentation/devicetree/bindings/net/dptel,dap8211r.yaml +10
-0+ $ref: /schemas/leds/common.yaml# + unevaluatedProperties: false + + properties: + reg: + items: + maximum: 2 + + additionalProperties: false +
[Severity: Low]
This isn't a bug, but does most of this block need to be here? The binding already gets a leds definition from allOf: - $ref: ethernet-phy.yaml#:
Documentation/devicetree/bindings/net/ethernet-phy.yaml:
leds:
type: object
properties:
'#address-cells':
const: 1
'#size-cells':
const: 0
patternProperties:
'^led@[a-f0-9]+$':
$ref: /schemas/leds/common.yaml#
...
required:
- reg
unevaluatedProperties: false
additionalProperties: falseMost of the new block repeats ethernet-phy.yaml: the type: object keys, the cell constraints, the common.yaml $ref and unevaluatedProperties: false.
Only two constraints are new. The '^led@[0-2]$' node name pattern, combined with the local additionalProperties: false, rejects led@3 and above. The reg items maximum of 2 limits the LED index.
Could the block be cut down to just the constraints that limit the PHY to three LEDs?
The commit message also says:
Document the optional "leds" node supported by the DAP8211R PHY.
Before this patch, a leds node with LED children already passed validation for this PHY through ethernet-phy.yaml. Would it be clearer for the message to say that the change limits the LED nodes to indices 0-2?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122131900.2951586-1-a.shimko.dev%40gmail.com
[email protected]
AI reviewRe: [PATCH net-next v4 3/3] net: phy: dap8211r: add PHY LED control support
In reply to Artem ShimkoThank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.
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] In drivers/net/phy/dap8211r.c, dap8211r_led_hw_control_get() (lines 312-351) does not undo what dap8211r_led_hw_control_set()…
- [Low] dap8211r_led_hw_control_set() in drivers/net/phy/dap8211r.c first clears FORCE_EN(index) in LED_COMCON (0xA00B) with…
--
net: phy: dap8211r: add PHY LED control support
This adds PHY LED support for the three LEDs on the DAP8211R. It adds a dap8211r_write_ext() helper for indirect extended register writes. It also implements the led_brightness_set, led_hw_is_supported, led_hw_control_set and led_hw_control_get callbacks, using force mode for brightness and the LED_x_CON registers for hardware triggers.
Quoted 4 lines
drivers/net/phy/dap8211r.c +0
-0
[ ... ]
Quoted 6 lines
drivers/net/phy/dap8211r.c +6
-0+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) {
drivers/net/phy/dap8211r.c static int dap8211r_modify_ext(struct phy_device *phydev, u16 reg, u16 mask, u16 · line 272
Quoted 10 lines
drivers/net/phy/dap8211r.c +10
-0+ case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2: + led_reg =DAP8211R_LED_0_CON + index; +break ; +default : +return -EINVAL ; + } + + ret =dap8211r_modify_ext (phydev,DAP8211R_LED_COMCON ,DAP8211R_LED_FORCE_EN (index),0 ); +if (ret) +return ret;
[Severity: Low]
Force mode is cleared in LED_COMCON here, but the new rules are only written to LED_x_CON later by a separate dap8211r_write_ext() call. Each helper takes and drops the MDIO bus lock on its own. In between, won't the LED follow whatever LED_x_CON held before (power-on, bootloader, or previous trigger rules)?
If the final dap8211r_write_ext() fails, the function returns an error but leaves force mode off and the stale rules active. set_baseline_state() in drivers/leds/trigger/ledtrig-netdev.c ignores the return value:
led_cdev->hw_control_set(led_cdev, trigger_data->mode);
so the trigger would assume the new mode is in effect.
Would it work to write LED_x_CON first and clear FORCE_EN afterwards? The rule register has no visible effect while force mode is on.
Quoted 4 lines
drivers/net/phy/dap8211r.c +4
-0+ +if (test_bit (TRIGGER_NETDEV_LINK , &rules)) + led_mode |=DAP8211R_LED_LINK ; +
[ ... ]
Quoted 6 lines
drivers/net/phy/dap8211r.c +6
-0+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 ; +
[ ... ]
Quoted 2 lines
drivers/net/phy/dap8211r.c +2
-0+return dap8211r_write_ext (phydev, led_reg, led_mode); +}
[ ... ]
Quoted 2 lines
drivers/net/phy/dap8211r.c +2
-0+static int dap8211r_led_hw_control_get (struct phy_device *phydev,u8 index,unsigned long *rules) +{
[ ... ]
Quoted 17 lines
drivers/net/phy/dap8211r.c +17
-0+ led_mode =dap8211r_read_ext (phydev, led_reg); +if (led_mode <0 ) +return led_mode; + +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 ) +__set_bit (TRIGGER_NETDEV_RX , rules); + +if (led_mode &DAP8211R_LED_TX )
drivers/net/phy/dap8211r.c static int dap8211r_modify_ext(struct phy_device *phydev, u16 reg, u16 mask, u16 · line 351
Quoted 10 lines
drivers/net/phy/dap8211r.c +10
-0+__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 ; +}
[Severity: Medium]
Does dap8211r_led_hw_control_get() return the same rules that dap8211r_led_hw_control_set() writes? I see three mismatches.
First, hw_control_set() turns TRIGGER_NETDEV_LINK into LINK_10 | LINK_100 | LINK_1000. This function only reports the three speed bits and never reports TRIGGER_NETDEV_LINK.
Second, hw_control_set() always sets DAP8211R_LED_ACT_BLINK along with TX/RX, but bit 13 is never checked here. The kernel-doc on hw_control_set() says the LED does not blink on traffic without ACT_BLINK unless another rule is active. A register with TX/RX set, ACT_BLINK clear and no link/duplex bit would still be reported as tx/rx offload.
Third, any other LED_x_CON bits are silently ignored, and 0 is returned anyway.
The led_hw_control_get kernel-doc in include/linux/phy.h says:
Set *@rules to how the HW is currently blinking. Returns 0 on success, or a error code if the current blinking cannot be represented in rules, or some other error happens.
Should this return an error when the register holds bits that cannot be expressed as rules?
This matters because the netdev trigger reads the rules and then writes them back:
netdev_trig_activate()
led_cdev->hw_control_get(led_cdev, &mode)
trigger_data->mode = mode
register_netdevice_notifier()
netdev_trig_notify(NETDEV_REGISTER)
set_baseline_state()
led_cdev->hw_control_set(led_cdev, trigger_data->mode)hw_control_set() rebuilds led_mode from 0 and writes the whole register with dap8211r_write_ext(), not a masked modify. Any hardware setting that hw_control_get() could not express would then be lost just by activating the trigger, for example via linux,default-trigger = "netdev".
In the ACT_BLINK case, the LED could start blinking on traffic when it did not before. Whether this happens in practice depends on the power-on or strap values of LED_x_CON.
In the LINK case, after the trigger is re-activated, sysfs would show link=0 and link_10=link_100=link_1000=1. Writing link=1 is then rejected with -EINVAL by this check in 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) ||until the speed bits are cleared by hand.
rtl8211f_led_hw_control_get() in the realtek driver reports TRIGGER_NETDEV_LINK when all three speed bits are set. Could the same approach be used here?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261122131900.2951586-1-a.shimko.dev%40gmail.com
Re: [PATCH net-next v4 2/3] dt-bindings: net: dptel,dap8211r: add LED nodes
In reply to [email protected]Quoted 87 lines · On Mon, Nov 23, 2026 at 4:19 PM <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The new
ledsblock inDocumentation/devicetree/bindings/net/dptel,dap8211r.yamlmostly…--
dt-bindings: net: dptel,dap8211r: add LED nodes
This commit documents an optional leds node in the DAP8211R PHY binding. The PHY has three LED outputs, and each can be given a color, a function and a default trigger. The commit also adds an example with two LED nodes.
Quoted 4 lines
Documentation/devicetree/bindings/net/dptel,dap8211r.yaml +0
-0[ ... ]
Quoted 22 lines
Documentation/devicetree/bindings/net/dptel,dap8211r.yaml +18
-0@@ -45,10 +46,40 @@ properties: maximum: 2250 default: 1950 + leds: + type: object + + description: + Optional node describing the three configurable LEDs of the PHY. + Each LED can be assigned a color, function and default trigger + (e.g. "netdev" for link/activity indication). + + properties: + '#address-cells': + const: 1 + '#size-cells': + const: 0 + + patternProperties: + '^led@[0-2]$': + type: object +Documentation/devicetree/bindings/net/dptel,dap8211r.yaml properties: · line 76
Quoted 10 lines
Documentation/devicetree/bindings/net/dptel,dap8211r.yaml +10
-0+ $ref: /schemas/leds/common.yaml# + unevaluatedProperties: false + + properties: + reg: + items: + maximum: 2 + + additionalProperties: false +[Severity: Low]
This isn't a bug, but does most of this block need to be here? The binding already gets a leds definition from allOf: - $ref: ethernet-phy.yaml#:
Documentation/devicetree/bindings/net/ethernet-phy.yaml:
leds:type: object properties: '#address-cells': const: 1 '#size-cells': const: 0 patternProperties: '^led@[a-f0-9]+$': $ref: /schemas/leds/common.yaml# ... required: - reg unevaluatedProperties: false additionalProperties: falseMost of the new block repeats
ethernet-phy.yaml: the type: object keys, the cell constraints, thecommon.yaml$ref and unevaluatedProperties: false.
Quoted 6 lines
Only two constraints are new. The '^led@[0-2]$' node name pattern, combined with the local additionalProperties: false, rejects led@3 and above. The reg items maximum of 2 limits the LED index.
Could the block be cut down to just the constraints that limit the PHY to three LEDs?
ok, i'll fix it.
Quoted 7 lines
The commit message also says:
Document the optional "leds" node supported by the DAP8211R PHY.
Before this patch, a leds node with LED children already passed validation for this PHY through
ethernet-phy.yaml. Would it be clearer for the message to say that the change limits the LED nodes to indices 0-2?
I'll keep the current wording for now, since
the message describes what the patch does (adds LED nodes and an example) and the restriction to 0..2 is visible in the diff itself. If the maintainers prefer a different wording, i'll adjust in a follow-up.
--
Best regards,
artem
Re: [PATCH net-next v4 3/3] net: phy: dap8211r: add PHY LED control support
In reply to [email protected]Quoted 63 lines · On Mon, Nov 23, 2026 at 4:19 PM <[email protected]> wrote:
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] In
drivers/net/phy/dap8211r.c,dap8211r_led_hw_control_get()(lines 312-351) does not undo what dap8211r_led_hw_control_set()…
- [Low]dap8211r_led_hw_control_set()indrivers/net/phy/dap8211r.cfirst clearsFORCE_EN(index)inLED_COMCON(0xA00B) with…--
net: phy: dap8211r: add PHY LED control support
This adds PHY LED support for the three LEDs on the DAP8211R. It adds a
dap8211r_write_ext()helper for indirect extended register writes. It also implements theled_brightness_set,led_hw_is_supported,led_hw_control_setandled_hw_control_getcallbacks, using force mode for brightness and theLED_x_CONregisters for hardware triggers.Quoted 4 lines
drivers/net/phy/dap8211r.c +0
-0[ ... ]
Quoted 6 lines
drivers/net/phy/dap8211r.c +6
-0+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) {drivers/net/phy/dap8211r.c static int dap8211r_modify_ext(struct phy_device *phydev, u16 reg, u16 mask, u16 · line 272
Quoted 10 lines
drivers/net/phy/dap8211r.c +10
-0+ case DAP8211R_LED_ID_0 ... DAP8211R_LED_ID_2: + led_reg =DAP8211R_LED_0_CON + index; +break ; +default : +return -EINVAL ; + } + + ret =dap8211r_modify_ext (phydev,DAP8211R_LED_COMCON ,DAP8211R_LED_FORCE_EN (index),0 ); +if (ret) +return ret;[Severity: Low]
Force mode is cleared in
LED_COMCONhere, but the new rules are only written toLED_x_CONlater by a separatedap8211r_write_ext()call. Each helper takes and drops the MDIO bus lock on its own. In between, won't the LED follow whateverLED_x_CONheld before (power-on, bootloader, or previous trigger rules)?If the final
dap8211r_write_ext()fails, the function returns an error but leaves force mode off and the stale rules active.set_baseline_state()indrivers/leds/trigger/ledtrig-netdev.cignores the return value:
Quoted 6 lines
led_cdev->hw_control_set(led_cdev, trigger_data->mode);so the trigger would assume the new mode is in effect.
Would it work to write
LED_x_CONfirst and clearFORCE_ENafterwards? The rule register has no visible effect while force mode is on.
Agreed. mxl86110_led_hw_control_set() does exactly this. I'll reorder the calls in dap8211r_led_hw_control_set() the same way in v5,
Quoted 8 lines
[Severity: Medium]
Does
dap8211r_led_hw_control_get()return the same rules thatdap8211r_led_hw_control_set()writes? I see three mismatches.First,
hw_control_set()turnsTRIGGER_NETDEV_LINKintoLINK_10|LINK_100|LINK_1000. This function only reports the three speed bits and never reportsTRIGGER_NETDEV_LINK.
i'll add it, thanks
Quoted 5 lines
Second,
hw_control_set()always setsDAP8211R_LED_ACT_BLINKalong with TX/RX, but bit 13 is never checked here. The kernel-doc onhw_control_set()says the LED does not blink on traffic withoutACT_BLINKunless another rule is active. A register with TX/RX set,ACT_BLINKclear and no link/duplex bit would still be reported as tx/rx offload.
i.e., if ACT_BLINK == 0 but txrx are active (by some reason), then -EOPNOTSUPP should be
returned, because the register state does not correspond to an operational state. Oh, that's
important i think. Yes, it should be fixed.
Quoted 3 lines
Third, any other
LED_x_CONbits are silently ignored, and 0 is returned anyway.
ok
Quoted 3 lines
rtl8211f_led_hw_control_get()in the realtek driver reportsTRIGGER_NETDEV_LINKwhen all three speed bits are set. Could the same approach be used here?
Yes, i think so
--
Best regards,
artem
pw-bot: cr