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

Message ID 1507890129-1543-16-git-send-email-yamada.masahiro@socionext.com
State New
Headers show
Series
  • ARM: uniphier: various refactoring for v2017.11-rc2
Related show

Commit Message

Masahiro Yamada Oct. 13, 2017, 10:22 a.m.
Get clock rate from the clock driver instead of hard-coding it.

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

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

Comments

Heiko Schocher Oct. 16, 2017, 6:25 a.m. | #1
Hello Masahiro,

Am 13.10.2017 um 12:22 schrieb Masahiro Yamada:
> Get clock rate from the clock driver instead of hard-coding it.
> 
> Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
> ---
> 
>   drivers/i2c/i2c-uniphier-f.c | 19 ++++++++++++++++---
>   1 file changed, 16 insertions(+), 3 deletions(-)

Reviewed-by: Heiko Schocher <hs@denx.de>

bye,
Heiko

Patch

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;