From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B60FAC433EF for ; Wed, 27 Apr 2022 10:43:41 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8D4FA83E15; Wed, 27 Apr 2022 12:43:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="TJLphtsE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 86B7083EDF; Wed, 27 Apr 2022 12:42:42 +0200 (CEST) Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 5611A83ECD for ; Wed, 27 Apr 2022 12:42:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=kabel@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 0F49BCE2145; Wed, 27 Apr 2022 10:42:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B960C385A7; Wed, 27 Apr 2022 10:42:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1651056143; bh=Cn00Zh0Yz9Pqiaep+0RXXeRA3affvGNUGFl5umk66i8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TJLphtsE16VrI03uHzymCFPnilE8AdAQ4RswEIqPYmXq+YXIsRza/ZebNiNOnVYMk j66R+qUceyWdom1RRnOldSoNivfcy662EWP6IkJBN4skWCU/IoH506NtRaXAgENUDP dnVqJdqD/tm8lqtJiUL0D8R5bdhRX0/794qOOLrzcK5CrXEoxMZ+5mEqP0wG6Tmj+i KHgjf54WI+3izYpxpMK6mPxip9HcFx8o+13zT1Sb5APBAE3/bOiaNAAK4YEY/h4W5O PlbBrJ3l1DUZpxhm8QsfCPbBSp+aRg95br7oHtq/Cf21eyR+UNKJ2Vtt33s8+Z2rPQ sye/70TnlC3bw== From: =?UTF-8?q?Marek=20Beh=C3=BAn?= To: Stefan Roese Cc: Robert Marko , =?UTF-8?q?Pali=20Roh=C3=A1r?= , U-Boot-Denx , Ramon Fried , Joe Hershberger , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Heinrich Schuchardt , Vladimir Oltean , Simon Glass Subject: [PATCH u-boot-marvell 06/19] net: mdio-uclass: add dm_phy_find_by_ofnode() helper Date: Wed, 27 Apr 2022 12:41:49 +0200 Message-Id: <20220427104202.1205-7-kabel@kernel.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220427104202.1205-1-kabel@kernel.org> References: <20220427104202.1205-1-kabel@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean From: Marek BehĂșn Add helper to resolve PHY node from it's ofnode via DM MDIO subsystem. Signed-off-by: Marek BehĂșn --- include/miiphy.h | 9 +++++++++ net/mdio-uclass.c | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/include/miiphy.h b/include/miiphy.h index 110921f20d..c66a1845b5 100644 --- a/include/miiphy.h +++ b/include/miiphy.h @@ -188,6 +188,15 @@ int dm_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg, u16 va */ int dm_mdio_reset(struct udevice *mdio_dev); +/** + * dm_phy_find_by_ofnode - Find PHY device by ofnode + * + * @phynode: PHY's ofnode + * + * Return: pointer to phy_device, or NULL on error + */ +struct phy_device *dm_phy_find_by_ofnode(ofnode phynode); + /** * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO * diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 7593618d9a..4401492ca0 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -129,6 +129,28 @@ static int dm_mdio_pre_remove(struct udevice *dev) return 0; } +struct phy_device *dm_phy_find_by_ofnode(ofnode phynode) +{ + struct mdio_perdev_priv *pdata; + struct udevice *mdiodev; + u32 phy_addr; + + if (ofnode_read_u32(phynode, "reg", &phy_addr)) + return NULL; + + if (uclass_get_device_by_ofnode(UCLASS_MDIO, + ofnode_get_parent(phynode), + &mdiodev)) + return NULL; + + if (device_probe(mdiodev)) + return NULL; + + pdata = dev_get_uclass_priv(mdiodev); + + return phy_find_by_mask(pdata->mii_bus, BIT(phy_addr)); +} + struct phy_device *dm_mdio_phy_connect(struct udevice *mdiodev, int phyaddr, struct udevice *ethdev, phy_interface_t interface) -- 2.35.1