Callers often don't just need to know the address of the phy, but also need to know its DT node so that a subsequent call of phy_config() can fetch various DT attributes specific to the given phy. Currently, phy_get_ofnode() usually incorrectly returns a pointer to the node for the ethernet controller.
This was fixed for fec_mxc in commit 89b5bd54c1a4, but I'm now hitting the exact same problem with the dwc_eth_qos driver. I have a ti,dp83867 phy which requires ti,rx-internal-delay and ti,tx-internal-delay to be specified, which I do, but the phy driver fails to fetch the values because of the wrong phy_get_ofnode() value. So generalize eth_phy_get_addr() a bit so that it also optionally returns the ofnode where it found the reg value. Follow-up patches will make use of this in dwc_eth_qos, and further generalize it even further so it can be used from fec_mxc as well (i.e., add the fixed-link support). Signed-off-by: Rasmus Villemoes <rasmus.villem...@prevas.dk> --- drivers/net/eth-phy-uclass.c | 9 ++++++++- include/eth_phy.h | 1 + 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/net/eth-phy-uclass.c b/drivers/net/eth-phy-uclass.c index 27b77444a0..05e1de8be9 100644 --- a/drivers/net/eth-phy-uclass.c +++ b/drivers/net/eth-phy-uclass.c @@ -109,7 +109,7 @@ struct mii_dev *eth_phy_get_mdio_bus(struct udevice *eth_dev) return NULL; } -int eth_phy_get_addr(struct udevice *dev) +int eth_phy_get_node_and_addr(struct udevice *dev, ofnode *phy_node) { struct ofnode_phandle_args phandle_args; int reg; @@ -121,10 +121,17 @@ int eth_phy_get_addr(struct udevice *dev) } reg = ofnode_read_u32_default(phandle_args.node, "reg", 0); + if (phy_node) + *phy_node = phandle_args.node; return reg; } +int eth_phy_get_addr(struct udevice *dev) +{ + return eth_phy_get_node_and_addr(dev, NULL); +} + /* parsing generic properties of devicetree/bindings/net/ethernet-phy.yaml */ static int eth_phy_of_to_plat(struct udevice *dev) { diff --git a/include/eth_phy.h b/include/eth_phy.h index be6c881527..caf85c84a7 100644 --- a/include/eth_phy.h +++ b/include/eth_phy.h @@ -14,5 +14,6 @@ int eth_phy_binds_nodes(struct udevice *eth_dev); int eth_phy_set_mdio_bus(struct udevice *eth_dev, struct mii_dev *mdio_bus); struct mii_dev *eth_phy_get_mdio_bus(struct udevice *eth_dev); int eth_phy_get_addr(struct udevice *dev); +int eth_phy_get_node_and_addr(struct udevice *dev, ofnode *phy_node); #endif -- 2.31.1