[PATCH V2 6/8] net: eqos: implement callbaks to get interface and set txclk rate

Peng Fan peng.fan at nxp.com
Sun May 3 16:41:18 CEST 2020


From: Fugang Duan <fugang.duan at nxp.com>

Implement the callbacks to get phy mode interface and txclk
rate configuration.

Reviewed-by: Ye Li <ye.li at nxp.com>
Signed-off-by: Fugang Duan <fugang.duan at nxp.com>
Signed-off-by: Peng Fan <peng.fan at nxp.com>
---

V2:
 Fix build break

 drivers/net/dwc_eth_qos.c | 55 ++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 52 insertions(+), 3 deletions(-)

diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c
index 3cdc6f1ae9..15dae20e57 100644
--- a/drivers/net/dwc_eth_qos.c
+++ b/drivers/net/dwc_eth_qos.c
@@ -42,6 +42,10 @@
 #include <asm/gpio.h>
 #include <asm/io.h>
 #include <eth_phy.h>
+#ifdef CONFIG_ARCH_IMX8M
+#include <asm/arch/clock.h>
+#include <asm/mach-imx/sys_proto.h>
+#endif
 
 /* Core registers */
 
@@ -867,11 +871,19 @@ static ulong eqos_get_tick_clk_rate_stm32(struct udevice *dev)
 #endif
 }
 
-static ulong eqos_get_tick_clk_rate_imx(struct udevice *dev)
+__weak u32 imx_get_eqos_csr_clk(void)
 {
-	/* TODO: retrieve from CSR clock */
 	return 100 * 1000000;
 }
+__weak int imx_eqos_txclk_set_rate(unsigned long rate)
+{
+	return 0;
+}
+
+static ulong eqos_get_tick_clk_rate_imx(struct udevice *dev)
+{
+	return imx_get_eqos_csr_clk();
+}
 
 static int eqos_calibrate_pads_stm32(struct udevice *dev)
 {
@@ -996,6 +1008,33 @@ static int eqos_set_tx_clk_speed_stm32(struct udevice *dev)
 
 static int eqos_set_tx_clk_speed_imx(struct udevice *dev)
 {
+	struct eqos_priv *eqos = dev_get_priv(dev);
+	ulong rate;
+	int ret;
+
+	debug("%s(dev=%p):\n", __func__, dev);
+
+	switch (eqos->phy->speed) {
+	case SPEED_1000:
+		rate = 125 * 1000 * 1000;
+		break;
+	case SPEED_100:
+		rate = 25 * 1000 * 1000;
+		break;
+	case SPEED_10:
+		rate = 2.5 * 1000 * 1000;
+		break;
+	default:
+		pr_err("invalid speed %d", eqos->phy->speed);
+		return -EINVAL;
+	}
+
+	ret = imx_eqos_txclk_set_rate(rate);
+	if (ret < 0) {
+		pr_err("imx (tx_clk, %lu) failed: %d", rate, ret);
+		return ret;
+	}
+
 	return 0;
 }
 
@@ -1865,7 +1904,17 @@ static int eqos_probe_resources_imx(struct udevice *dev)
 
 static phy_interface_t eqos_get_interface_imx(struct udevice *dev)
 {
-	return PHY_INTERFACE_MODE_RGMII;
+	const char *phy_mode;
+	phy_interface_t interface = PHY_INTERFACE_MODE_NONE;
+
+	debug("%s(dev=%p):\n", __func__, dev);
+
+	phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
+			       NULL);
+	if (phy_mode)
+		interface = phy_get_interface_by_name(phy_mode);
+
+	return interface;
 }
 
 static int eqos_remove_resources_tegra186(struct udevice *dev)
-- 
2.16.4



More information about the U-Boot mailing list