diff mbox series

[V2,46/53] net: eqos: add function to get phy node and address

Message ID 20220726084123.2508-47-peng.fan@oss.nxp.com
State Accepted
Commit a6acf95508e268d6311408d24339b42fe6e5be14
Delegated to: Stefano Babic
Headers show
Series NXP-IMX pending patches | expand

Commit Message

Peng Fan (OSS) July 26, 2022, 8:41 a.m. UTC
From: Ye Li <ye.li@nxp.com>

Since new atheros PHY driver needs to access its PHY node through
phy device, we have to assign the phy node in ethernet controller
driver. Otherwise the PHY driver will fail to get some nodes
and properties.

Signed-off-by: Ye Li <ye.li@nxp.com>
Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 drivers/net/dwc_eth_qos.c | 23 ++++++++++++++++++++---
 drivers/net/dwc_eth_qos.h |  1 +
 2 files changed, 21 insertions(+), 3 deletions(-)

Comments

Stefano Babic July 26, 2022, 1:53 p.m. UTC | #1
> From: Ye Li <ye.li@nxp.com>
> Since new atheros PHY driver needs to access its PHY node through
> phy device, we have to assign the phy node in ethernet controller
> driver. Otherwise the PHY driver will fail to get some nodes
> and properties.
> Signed-off-by: Ye Li <ye.li@nxp.com>
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
Applied to u-boot-imx, master, thanks !

Best regards,
Stefano Babic
diff mbox series

Patch

diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c
index 1f24f5cb0cf..a4380d17d9c 100644
--- a/drivers/net/dwc_eth_qos.c
+++ b/drivers/net/dwc_eth_qos.c
@@ -719,6 +719,24 @@  static int eqos_read_rom_hwaddr(struct udevice *dev)
 	return !is_valid_ethaddr(pdata->enetaddr);
 }
 
+static int eqos_get_phy_addr(struct eqos_priv *priv, struct udevice *dev)
+{
+	struct ofnode_phandle_args phandle_args;
+	int reg;
+
+	if (dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
+				       &phandle_args)) {
+		debug("Failed to find phy-handle");
+		return -ENODEV;
+	}
+
+	priv->phy_of_node = phandle_args.node;
+
+	reg = ofnode_read_u32_default(phandle_args.node, "reg", 0);
+
+	return reg;
+}
+
 static int eqos_start(struct udevice *dev)
 {
 	struct eqos_priv *eqos = dev_get_priv(dev);
@@ -767,9 +785,7 @@  static int eqos_start(struct udevice *dev)
 	 */
 	if (!eqos->phy) {
 		int addr = -1;
-#ifdef CONFIG_DM_ETH_PHY
-		addr = eth_phy_get_addr(dev);
-#endif
+		addr = eqos_get_phy_addr(eqos, dev);
 #ifdef DWC_NET_PHYADDR
 		addr = DWC_NET_PHYADDR;
 #endif
@@ -788,6 +804,7 @@  static int eqos_start(struct udevice *dev)
 			}
 		}
 
+		eqos->phy->node = eqos->phy_of_node;
 		ret = phy_config(eqos->phy);
 		if (ret < 0) {
 			pr_err("phy_config() failed: %d", ret);
diff --git a/drivers/net/dwc_eth_qos.h b/drivers/net/dwc_eth_qos.h
index ce90e1f1ce1..f470189e8d4 100644
--- a/drivers/net/dwc_eth_qos.h
+++ b/drivers/net/dwc_eth_qos.h
@@ -261,6 +261,7 @@  struct eqos_priv {
 	struct clk clk_slave_bus;
 	struct mii_dev *mii;
 	struct phy_device *phy;
+	ofnode phy_of_node;
 	u32 max_speed;
 	void *descs;
 	int tx_desc_idx, rx_desc_idx;