net: introduce helpers to get PHY ofnode from MAC

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(). Also add
corresponding UT test.

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 <marek.behun@nic.cz>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Marek Behún
2022-04-07 00:32:57 +02:00
committed by Ramon Fried
parent a7a96ef812
commit f3dd213e15
7 changed files with 96 additions and 18 deletions

View File

@@ -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 <asm/global_data.h>
@@ -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 */
/**