[U-Boot] [PATCH 15/20] i2c: uniphier-f: use clk for enable and get_rate

Masahiro Yamada yamada.masahiro at socionext.com
Fri Oct 13 10:22:04 UTC 2017


Get clock rate from the clock driver instead of hard-coding it.

Signed-off-by: Masahiro Yamada <yamada.masahiro at socionext.com>
---

 drivers/i2c/i2c-uniphier-f.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/i2c/i2c-uniphier-f.c b/drivers/i2c/i2c-uniphier-f.c
index eb6c9f3..6f45cc5 100644
--- a/drivers/i2c/i2c-uniphier-f.c
+++ b/drivers/i2c/i2c-uniphier-f.c
@@ -11,6 +11,7 @@
 #include <linux/iopoll.h>
 #include <linux/sizes.h>
 #include <linux/types.h>
+#include <clk.h>
 #include <dm.h>
 #include <i2c.h>
 #include <fdtdec.h>
@@ -61,8 +62,6 @@ struct uniphier_fi2c_regs {
 #define I2C_BRST_RSCLO	(1 << 0)	/* release SCL low fixing */
 };
 
-#define FIOCLK	50000000
-
 struct uniphier_fi2c_priv {
 	struct udevice *dev;
 	struct uniphier_fi2c_regs __iomem *regs;	/* register base */
@@ -93,6 +92,8 @@ static int uniphier_fi2c_probe(struct udevice *dev)
 {
 	fdt_addr_t addr;
 	struct uniphier_fi2c_priv *priv = dev_get_priv(dev);
+	struct clk clk;
+	int ret;
 
 	addr = devfdt_get_addr(dev);
 	if (addr == FDT_ADDR_T_NONE)
@@ -102,7 +103,19 @@ static int uniphier_fi2c_probe(struct udevice *dev)
 	if (!priv->regs)
 		return -ENOMEM;
 
-	priv->fioclk = FIOCLK;
+	ret = clk_get_by_index(dev, 0, &clk);
+	if (ret < 0) {
+		dev_err(dev, "failed to get clock\n");
+		return ret;
+	}
+
+	ret = clk_enable(&clk);
+	if (ret) {
+		dev_err(dev, "failed to enable clock\n");
+		return ret;
+	}
+
+	priv->fioclk = clk_get_rate(&clk);
 
 	priv->dev = dev;
 
-- 
2.7.4



More information about the U-Boot mailing list