diff mbox series

[v2] net: phy: Handle both led@0 and led subnode name for single-LED PHYs

Message ID 20250120090256.54382-1-marex@denx.de (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [v2] net: phy: Handle both led@0 and led subnode name for single-LED PHYs | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 1 this patch: 1
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 27 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 39 this patch: 39
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2025-01-20--15-00 (tests: 886)

Commit Message

Marek Vasut Jan. 20, 2025, 9:02 a.m. UTC
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.

Signed-off-by: Marek Vasut <marex@denx.de>
---
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Andrew Lunn <andrew@lunn.ch>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Heiner Kallweit <hkallweit1@gmail.com>
Cc: Jakub Kicinski <kuba@kernel.org>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: netdev@vger.kernel.org
---
V2: Fix up variable rename
---
 drivers/net/phy/phy_device.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

Comments

Andrew Lunn Jan. 20, 2025, 4:35 p.m. UTC | #1
On Mon, Jan 20, 2025 at 10:02:46AM +0100, Marek Vasut wrote:
> 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 {
>     ...
>   };
> };

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?

>  drivers/net/phy/phy_device.c | 15 +++++++++++++--

What about the device tree binding? Does it already have the reg
property as optional?

	Andrew
Marek Vasut Jan. 21, 2025, 11:53 a.m. UTC | #2
On 1/20/25 5:35 PM, Andrew Lunn wrote:
> On Mon, Jan 20, 2025 at 10:02:46AM +0100, Marek Vasut wrote:
>> 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 {
>>      ...
>>    };
>> };
> 
> 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.

> 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.

> A PWM with a single output?

Reference the controller node itself, similar to how single output clock 
controller works.

>>   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 ?
diff mbox series

Patch

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 5b34d39d1d52a..e36e65e672e79 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -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;