netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Vasut <marex@denx.de>
To: linux-leds@vger.kernel.org
Cc: Marek Vasut <marex@denx.de>,
	"David S. Miller" <davem@davemloft.net>,
	Andrew Lunn <andrew@lunn.ch>, Eric Dumazet <edumazet@google.com>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Russell King <linux@armlinux.org.uk>,
	netdev@vger.kernel.org
Subject: [PATCH] net: phy: Handle both led@0 and led subnode name for single-LED PHYs
Date: Mon, 20 Jan 2025 09:25:58 +0100	[thread overview]
Message-ID: <20250120082609.50445-1-marex@denx.de> (raw)

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
---
 drivers/net/phy/phy_device.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 5b34d39d1d52a..fa91d03d9e920 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 (total_led_count != 1)
+			return err;
+		index = 0;
+		err = 0;
+	}
 	if (index > U8_MAX)
 		return -EINVAL;
 
-- 
2.45.2


             reply	other threads:[~2025-01-20  8:26 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-20  8:25 Marek Vasut [this message]
2025-01-20  9:02 ` [PATCH] net: phy: Handle both led@0 and led subnode name for single-LED PHYs Marek Vasut
2025-01-20 17:34   ` Jakub Kicinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250120082609.50445-1-marex@denx.de \
    --to=marex@denx.de \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-leds@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).