From patchwork Thu Mar 17 12:49:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Marek_Beh=C3=BAn?= X-Patchwork-Id: 1606559 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20201202 header.b=XdfW1rAH; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KK6Vw5wCcz9s5V for ; Thu, 17 Mar 2022 23:52:40 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F063383F48; Thu, 17 Mar 2022 13:52:13 +0100 (CET) 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="XdfW1rAH"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 67FCE83A29; Thu, 17 Mar 2022 13:50:25 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-3.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) (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 E1DCB83ADC for ; Thu, 17 Mar 2022 13:50:15 +0100 (CET) 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 ams.source.kernel.org (Postfix) with ESMTPS id 8D773B81EAB; Thu, 17 Mar 2022 12:50:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BCF5DC340F4; Thu, 17 Mar 2022 12:50:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647521413; bh=i//uPecMJQyjP1Cgi372H2YrzBahVqnEgVmhW377HLM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XdfW1rAHJwf9lu67bjsOiyOS7B0SfM5YOvxYIxC/6JdkR94VbOpvFqL5IbDCRG0eK mPQkGRaImpS+wzr9LEcW9yCVMnU2KH1sIzdNhe9aRFpOABkONFdjjExJ6Tu57qqQhR CkxGV3g42a2OkqiSesYlI0VsZIOr1zhWuY7JyvmMTtPGh3VUBgQyU3KSSmZAJMRtif DU7n3HP9WvMnamLWsro10vdH2Q7q+wTzsq56rCkt8dFtzXbXwGGyxjkiavX+qMI7Ot CvaHOc5FBsy8DCPHgKnun2jJF4hMD5wBIlCTUWuJ8J0W6fC7L/EXZ/6nVs3/fCbBWM rlbLt/Qt/Xe6w== From: =?utf-8?q?Marek_Beh=C3=BAn?= To: Joe Hershberger , Ramon Fried Cc: u-boot@lists.denx.de, =?utf-8?q?Marek_Beh=C3=BAn?= , Bin Meng , Chen Guanqiao , Dario Binacchi , Jagan Teki , Kishon Vijay Abraham I , Leo Yu-Chi Liang , Lokesh Vutla , Michael Walle , Miquel Raynal , Patrick Delaunay , Priyanka Jain , Simon Glass , Vladimir Oltean Subject: [PATCH u-boot-net 03/14] net: introduce helpers to get PHY ofnode from MAC Date: Thu, 17 Mar 2022 13:49:47 +0100 Message-Id: <20220317124958.27921-4-kabel@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220317124958.27921-1-kabel@kernel.org> References: <20220317124958.27921-1-kabel@kernel.org> MIME-Version: 1.0 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 helpers ofnode_get_phy_node() and dev_get_phy_node() and use it in net/mdio-uclass.c function dm_eth_connect_phy_handle(). This is useful because other part's of U-Boot may want to get PHY ofnode without connecting a PHY. Signed-off-by: Marek BehĂșn Reviewed-by: Ramon Fried Reviewed-by: Simon Glass --- drivers/core/ofnode.c | 21 +++++++++++++++++++++ drivers/core/read.c | 5 +++++ include/dm/ofnode.h | 14 ++++++++++++++ include/dm/read.h | 19 +++++++++++++++++++ net/mdio-uclass.c | 24 ++++++------------------ 5 files changed, 65 insertions(+), 18 deletions(-) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 709bea272a..eaad2c989b 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -1162,3 +1162,24 @@ const char *ofnode_conf_read_str(const char *prop_name) return ofnode_read_string(node, prop_name); } + +ofnode ofnode_get_phy_node(ofnode node) +{ + /* DT node properties that reference a PHY node */ + static const char * const phy_handle_str[] = { + "phy-handle", "phy", "phy-device", + }; + struct ofnode_phandle_args args = { + .node = ofnode_null() + }; + int i; + + assert(ofnode_valid(node)); + + for (i = 0; i < ARRAY_SIZE(phy_handle_str); i++) + if (!ofnode_parse_phandle_with_args(node, phy_handle_str[i], + NULL, 0, 0, &args)) + break; + + return args.node; +} diff --git a/drivers/core/read.c b/drivers/core/read.c index 31f9e78a06..7ff100218d 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -398,3 +398,8 @@ int dev_decode_display_timing(const struct udevice *dev, int index, { return ofnode_decode_display_timing(dev_ofnode(dev), index, config); } + +ofnode dev_get_phy_node(const struct udevice *dev) +{ + return ofnode_get_phy_node(dev_ofnode(dev)); +} diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 0cb324c8b0..8164386043 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -1204,4 +1204,18 @@ int ofnode_conf_read_int(const char *prop_name, int default_val); */ const char *ofnode_conf_read_str(const char *prop_name); +/** + * ofnode_get_phy_node() - Get PHY node for a MAC (if not fixed-link) + * + * This function parses PHY handle from the Ethernet controller's ofnode + * (trying all possible PHY handle property names), and returns the PHY ofnode. + * + * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and + * if the result to that is true, this function should not be called. + * + * @eth_node: ofnode belonging to the Ethernet controller + * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode + */ +ofnode ofnode_get_phy_node(ofnode eth_node); + #endif diff --git a/include/dm/read.h b/include/dm/read.h index 233af3c063..899eb813fd 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -743,6 +743,20 @@ int dev_read_pci_bus_range(const struct udevice *dev, struct resource *res); int dev_decode_display_timing(const struct udevice *dev, int index, struct display_timing *config); +/** + * dev_get_phy_node() - Get PHY node for a MAC (if not fixed-link) + * + * This function parses PHY handle from the Ethernet controller's ofnode + * (trying all possible PHY handle property names), and returns the PHY ofnode. + * + * Before this is used, ofnode_phy_is_fixed_link() should be checked first, and + * if the result to that is true, this function should not be called. + * + * @dev: device representing the MAC + * Return: ofnode of the PHY, if it exists, otherwise an invalid ofnode + */ +ofnode dev_get_phy_node(const struct udevice *dev); + #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ #include @@ -1092,6 +1106,11 @@ static inline int dev_decode_display_timing(const struct udevice *dev, return ofnode_decode_display_timing(dev_ofnode(dev), index, config); } +static inline ofnode dev_get_phy_node(const struct udevice *dev) +{ + return ofnode_get_phy_node(dev_ofnode(dev)); +} + #endif /* CONFIG_DM_DEV_READ_INLINE */ /** diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c index 649dc60f73..233b70171b 100644 --- a/net/mdio-uclass.c +++ b/net/mdio-uclass.c @@ -20,11 +20,6 @@ static const char * const phy_mode_str[] = { "phy-mode", "phy-connection-type" }; -/* DT node properties that reference a PHY node */ -static const char * const phy_handle_str[] = { - "phy-handle", "phy", "phy-device" -}; - void dm_mdio_probe_devices(void) { struct udevice *it; @@ -137,23 +132,16 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, u32 phy_addr; struct udevice *mdiodev; struct phy_device *phy; - struct ofnode_phandle_args phandle = {.node = ofnode_null()}; ofnode phynode; - int i; if (CONFIG_IS_ENABLED(PHY_FIXED) && ofnode_phy_is_fixed_link(dev_ofnode(ethdev), &phynode)) { phy = phy_connect(NULL, 0, ethdev, interface); - phandle.node = phynode; goto out; } - for (i = 0; i < ARRAY_SIZE(phy_handle_str); i++) - if (!dev_read_phandle_with_args(ethdev, phy_handle_str[i], NULL, - 0, 0, &phandle)) - break; - - if (!ofnode_valid(phandle.node)) { + phynode = dev_get_phy_node(ethdev); + if (!ofnode_valid(phynode)) { dev_dbg(ethdev, "can't find PHY node\n"); return NULL; } @@ -162,16 +150,16 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, * reading 'reg' directly should be fine. This is a PHY node, the * address is always size 1 and requires no translation */ - if (ofnode_read_u32(phandle.node, "reg", &phy_addr)) { + if (ofnode_read_u32(phynode, "reg", &phy_addr)) { dev_dbg(ethdev, "missing reg property in phy node\n"); return NULL; } if (uclass_get_device_by_ofnode(UCLASS_MDIO, - ofnode_get_parent(phandle.node), + ofnode_get_parent(phynode), &mdiodev)) { dev_dbg(ethdev, "can't find MDIO bus for node %s\n", - ofnode_get_name(ofnode_get_parent(phandle.node))); + ofnode_get_name(ofnode_get_parent(phynode))); return NULL; } @@ -179,7 +167,7 @@ static struct phy_device *dm_eth_connect_phy_handle(struct udevice *ethdev, out: if (phy) - phy->node = phandle.node; + phy->node = phynode; return phy; }