From patchwork Tue Dec 17 21:07:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans-Frieder Vogt via B4 Relay X-Patchwork-Id: 13912497 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2EECB1F9409 for ; Tue, 17 Dec 2024 21:07:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734469659; cv=none; b=nTtrdUsYadA8sXMsbOA7CxWuYLKr8if0SdFAymYpICQn5VIkqUj8jwvufHMH+orJuxBmkpjYVj0M6/GuZMhk/+V6Z8x+as6ProGv9/T5uOY158f/JeClwteBIqpmrlkJkVwA4DYhtEW2SAjciFtm+5+63KYV8TKPQ4haVW4yWIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734469659; c=relaxed/simple; bh=f5j//xxzj5NG7f1I5TsQwnahRvJvaAhnjd/z+1rYzzQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=P6OWC1nL0G+zIbE+NK9B1NbDawGTaWE5jwSe+qEaOIOg3m+jKWfHTmBgSw6sotOmbt2/8SDQlejZHKVPQR/Ubwu2i6/nGlscNgBKeQ8GkgwLkeat46fH21sQlbUFG4lGmY06lKIlvnwhANt/+E8gj85pBluWH6ii/jsyYml8dxg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=Wm+JV0bO; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="Wm+JV0bO" Received: by smtp.kernel.org (Postfix) with ESMTPS id C7E8EC4CEDD; Tue, 17 Dec 2024 21:07:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1734469658; bh=f5j//xxzj5NG7f1I5TsQwnahRvJvaAhnjd/z+1rYzzQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To:From; b=Wm+JV0bOrOEBxxknfltY9gUUcfQEz2/4m8OHHh2igtUAVyKms7rDzr4K1H5KcFnvO J9UeZcDeVJV0PZkPyYsCTgS00057bg4hxlZYXklYivocg/EyUJ8I+9gyE0g2tvZfoH otWSFfnZjdW+c1lhhLQAORSKBWPFEF6Ew+2QXqckzxovBzVAz2yzS4rozUd6oAUVZW mp43risqkZqSrAhL8yJB5T1OM0VTN4K3OlPG5gQEtr1IKBYDfXQsRRCAPap2M9L1Cs VZj0mIiigNTtQRTt0h+uRsqZ51wV8FKWsBvxVo3lnXhV9/ErL00Ve1c04GtzXYU2Fy /7T8W5tKWGWtA== Received: from aws-us-west-2-korg-lkml-1.web.codeaurora.org (localhost.localdomain [127.0.0.1]) by smtp.lore.kernel.org (Postfix) with ESMTP id B42C8E77187; Tue, 17 Dec 2024 21:07:38 +0000 (UTC) From: Hans-Frieder Vogt via B4 Relay Date: Tue, 17 Dec 2024 22:07:32 +0100 Subject: [PATCH net-next v3 1/7] net: phy: Add swnode support to mdiobus_scan Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20241217-tn9510-v3a-v3-1-4d5ef6f686e0@gmx.net> References: <20241217-tn9510-v3a-v3-0-4d5ef6f686e0@gmx.net> In-Reply-To: <20241217-tn9510-v3a-v3-0-4d5ef6f686e0@gmx.net> To: Andrew Lunn , Heiner Kallweit , Russell King , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , FUJITA Tomonori , Andrew Lunn Cc: netdev@vger.kernel.org, Hans-Frieder Vogt X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1734469657; l=1936; i=hfdevel@gmx.net; s=20240915; h=from:subject:message-id; bh=tjXgAqiIJ9J3+v8YrXDfNqVpQpUv8M+JKJWk7sw4eKE=; b=pUKEW6gWmJ6Jod+VW4X1UJ6wLO2Ci8B1REHU+c8axfptUcmIuoOWlmNmB8oHwzDOqePkYKFeJ DfnuyFH3QzuDRhiMt3eTOw+s80CrFFlWugkLCQ8AZIGZyJ4FwlPFsjI X-Developer-Key: i=hfdevel@gmx.net; a=ed25519; pk=s3DJ3DFe6BJDRAcnd7VGvvwPXcLgV8mrfbpt8B9coRc= X-Endpoint-Received: by B4 Relay for hfdevel@gmx.net/20240915 with auth_id=209 X-Original-From: Hans-Frieder Vogt Reply-To: hfdevel@gmx.net X-Patchwork-Delegate: kuba@kernel.org From: Hans-Frieder Vogt This patch will allow to use a swnode/fwnode defined for a phy_device. The MDIO bus (mii_bus) needs to contain nodes for the PHY devices, named "ethernet-phy@i", with i being the MDIO address (0 .. PHY_MAX_ADDR - 1). The fwnode is only attached to the phy_device if there isn't already an fwnode attached. fwnode_get_named_child_node will increase the usage counter of the fwnode. However, no new code is needed to decrease the counter again, since this is already implemented in the phy_device_release function. Signed-off-by: Hans-Frieder Vogt --- drivers/net/phy/mdio_bus.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c index 7e2f10182c0cf37bef4cea1820863f047b5cb466..ede596c1a69d1b2b986e9eef51c3beb4a5fbc805 100644 --- a/drivers/net/phy/mdio_bus.c +++ b/drivers/net/phy/mdio_bus.c @@ -551,6 +551,8 @@ static int mdiobus_create_device(struct mii_bus *bus, static struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr, bool c45) { struct phy_device *phydev = ERR_PTR(-ENODEV); + struct fwnode_handle *fwnode; + char node_name[16]; int err; phydev = get_phy_device(bus, addr, c45); @@ -562,6 +564,18 @@ static struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr, bool c45) */ of_mdiobus_link_mdiodev(bus, &phydev->mdio); + /* Search for a swnode for the phy in the swnode hierarchy of the bus. + * If there is no swnode for the phy provided, just ignore it. + */ + if (dev_fwnode(&bus->dev) && !dev_fwnode(&phydev->mdio.dev)) { + snprintf(node_name, sizeof(node_name), "ethernet-phy@%d", + addr); + fwnode = fwnode_get_named_child_node(dev_fwnode(&bus->dev), + node_name); + if (fwnode) + device_set_node(&phydev->mdio.dev, fwnode); + } + err = phy_device_register(phydev); if (err) { phy_device_free(phydev);