[U-Boot] [RFC 6/8] net: fec_mxc: Add clock support via CLK

Jagan Teki jagan at amarulasolutions.com
Mon Jul 9 18:30:07 UTC 2018


Now enet clock support available for imx6qdl and imx6ul,
via CLK framework, so add enable, set_rate support in
drivers.

Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
---
 drivers/net/fec_mxc.c | 58 +++++++++++++++++++++++++++++++++++++++++++
 drivers/net/fec_mxc.h |  6 +++++
 2 files changed, 64 insertions(+)

diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
index 694a0b2f7e..7998c8b8b2 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -8,6 +8,7 @@
  */
 
 #include <common.h>
+#include <clk-uclass.h>
 #include <dm.h>
 #include <environment.h>
 #include <malloc.h>
@@ -1245,6 +1246,41 @@ static int fec_phy_init(struct fec_priv *priv, struct udevice *dev)
 	return 0;
 }
 
+#if CONFIG_IS_ENABLED(CLK)
+static int fec_clk_enable(struct fec_priv *priv)
+{
+	int ret;
+
+	ret = clk_enable(&priv->clk_ahb);
+	if (ret) {
+		printf("failed to enable ahb clk\n");
+		return ret;
+	}
+
+	if (generic_clk_valid(&priv->clk_ptp)) {
+		ret = clk_set_rate(&priv->clk_ptp, ENET_50MHZ);
+		if (ret) {
+			printf("failed to set 50MHz rate to ptp clk\n");
+			goto failed_clk_ahb;
+		}
+	}
+
+	if (generic_clk_valid(&priv->clk_enet_out)) {
+		ret = clk_set_rate(&priv->clk_enet_out, ENET_50MHZ);
+		if (ret) {
+			printf("failed to set 50MHz rate to enet_out clk\n");
+			goto failed_clk_ahb;
+		}
+	}
+
+	return 0;
+
+failed_clk_ahb:
+	clk_disable(&priv->clk_ahb);
+	return ret;
+}
+#endif
+
 static int fecmxc_probe(struct udevice *dev)
 {
 	struct eth_pdata *pdata = dev_get_platdata(dev);
@@ -1253,6 +1289,12 @@ static int fecmxc_probe(struct udevice *dev)
 	uint32_t start;
 	int ret;
 
+#if CONFIG_IS_ENABLED(CLK)
+	ret = fec_clk_enable(priv);
+	if (ret)
+		return ret;
+#endif
+
 	ret = fec_alloc_descs(priv);
 	if (ret)
 		return ret;
@@ -1331,6 +1373,22 @@ static int fecmxc_ofdata_to_platdata(struct udevice *dev)
 		return -EINVAL;
 	}
 
+#if CONFIG_IS_ENABLED(CLK)
+	int ret;
+
+	ret = clk_get_by_name(dev, "ahb", &priv->clk_ahb);
+	if (ret)
+		ret = PTR_ERR(&priv->clk_ahb);
+
+	ret = clk_get_by_name(dev, "ptp", &priv->clk_ptp);
+	if (ret)
+		dev_dbg(dev, "Warning: failed to get ptp clk\n");
+
+	ret = clk_get_by_name(dev, "enet_out", &priv->clk_enet_out);
+	if (ret)
+		dev_dbg(dev, "Warning: failed to get enet_out clk\n");
+#endif
+
 	/* TODO
 	 * Need to get the reset-gpio and related properties from DT
 	 * and implemet the enet reset code on .probe call
diff --git a/drivers/net/fec_mxc.h b/drivers/net/fec_mxc.h
index 3b935afe2c..78899e7603 100644
--- a/drivers/net/fec_mxc.h
+++ b/drivers/net/fec_mxc.h
@@ -253,6 +253,12 @@ struct fec_priv {
 
 #ifdef CONFIG_DM_ETH
 	u32 interface;
+
+#if CONFIG_IS_ENABLED(CLK)
+	struct clk clk_ahb;
+	struct clk clk_ptp;
+	struct clk clk_enet_out;
+#endif
 #endif
 };
 
-- 
2.17.1



More information about the U-Boot mailing list