net: phy: Handle both led@0 and led subnode name for single-LED PHYs
Subsystems (4)
PATCH v2 1/1 net: phy: Handle both led@0 and led subnode name for single-LED PHYs
In case a PHY supports only one LED in total, like ADIN1300, and this LED is described in DT, it is currently necessary to include unit address in the LED node name and the address-cells have to be set to 1:
leds {
#address-cells = <1>;
...
led@0 {
reg = <0>;
... };
};
For a single LED PHY, this should not be necessary and plain 'led' node without unit should be acceptable as well:
leds {
...
led {
... };
};
Handle this special case. In case reg property is not present in the leds node subnode, test whether the leds node contains exactly one subnode, and if so, assume this is the one single LED with reg property set to 0.
---
Cc: "David S. Miller" <[email protected]>
Cc: Andrew Lunn <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Heiner Kallweit <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Russell King <[email protected]>
Cc: [email protected]
---
V2: Fix up variable rename
--- drivers/net/phy/phy_device.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
drivers/net/phy/phy_device.c +13 -2
@@ -3346,6 +3346,7 @@ static int of_phy_led(struct phy_device *phydev,struct led_classdev *cdev;unsigned long modes =0 ;struct phy_led *phyled; +int led_count;u32 index;int err;
@@ -3357,8 +3358,18 @@ static int of_phy_led(struct phy_device *phydev, phyled->phydev = phydev; err =of_property_read_u32 (led,"reg" , &index); -if (err) -return err; +if (err) { + led_count =of_get_available_child_count (of_get_parent (led)); + +/* +* If there is one PHY LED in total, accept 'led' subnode +* in addition to 'led@0' subnode, and assume reg = <0>; +*/ +if (led_count !=1 ) +return err; + index =0 ; + err =0 ; + }if (index >U8_MAX )return -EINVAL ;
Signature · 1 line
2.45.2
Andrew Lunn
maintainerQuoted 16 lines · Marek Vasut
In case a PHY supports only one LED in total, like ADIN1300, and this LED is described in DT, it is currently necessary to include unit address in the LED node name and the address-cells have to be set to 1:
leds {
#address-cells = <1>;
...led@0 { reg = <0>; ...};
};For a single LED PHY, this should not be necessary and plain 'led' node without unit should be acceptable as well:
Quoted 6 lines
leds {
...led { ...};
};
So how do other subsystems handle this? SPI with only a single chip select line? Standalone LED controllers with a single LED? A PWM with a single output?
Quoted 1 line
drivers/net/phy/phy_device.c | 15 +++++++++++++--
What about the device tree binding? Does it already have the reg property as optional?
Andrew
Quoted 24 lines · Andrew Lunn
Quoted 16 lines · Marek Vasut
In case a PHY supports only one LED in total, like ADIN1300, and this LED is described in DT, it is currently necessary to include unit address in the LED node name and the address-cells have to be set to 1:
leds { #address-cells = <1>; ... led@0 { reg = <0>; ... }; };For a single LED PHY, this should not be necessary and plain 'led' node without unit should be acceptable as well:
Quoted 6 lines
leds { ... led { ... }; };
Quoted 2 lines
So how do other subsystems handle this? SPI with only a single chip select line?
I believe for SPI, it is always mandatory to have 'reg' property.
Quoted 1 line
Standalone LED controllers with a single LED?
The GPIO LEDs driver does not enumerate the LEDs at all, so there is no 'reg' property needed in any case, but I don't think this is really applicable for the PHY LEDs, which depend on the ordering within each PHY.
Quoted 1 line
A PWM with a single output?
Reference the controller node itself, similar to how single output clock controller works.
Quoted 4 lines
Quoted 1 line
drivers/net/phy/phy_device.c | 15 +++++++++++++--What about the device tree binding? Does it already have the reg property as optional?
Documentation/devicetree/bindings/net/ethernet-phy.yaml does not, but that can be changed if desirable . If not desirable, then I can just discard this patch ?