[U-Boot] [PATCH 04/52] i2c: mxc: add CONFIG_CLK support
peng.fan at nxp.com
peng.fan at nxp.com
Tue Jul 2 02:31:18 UTC 2019
From: Peng Fan <peng.fan at nxp.com>
When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.
Signed-off-by: Peng Fan <peng.fan at nxp.com>
---
arch/arm/include/asm/mach-imx/mxc_i2c.h | 2 ++
drivers/i2c/mxc_i2c.c | 24 ++++++++++++++++++++----
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/arch/arm/include/asm/mach-imx/mxc_i2c.h b/arch/arm/include/asm/mach-imx/mxc_i2c.h
index 8e1ea9af19..c2f9419530 100644
--- a/arch/arm/include/asm/mach-imx/mxc_i2c.h
+++ b/arch/arm/include/asm/mach-imx/mxc_i2c.h
@@ -6,6 +6,7 @@
#define __ASM_ARCH_MXC_MXC_I2C_H__
#include <asm-generic/gpio.h>
#include <asm/mach-imx/iomux-v3.h>
+#include <clk.h>
struct i2c_pin_ctrl {
iomux_v3_cfg_t i2c_mode;
@@ -47,6 +48,7 @@ struct mxc_i2c_bus {
ulong driver_data;
int speed;
struct i2c_pads_info *pads_info;
+ struct clk per_clk;
#ifndef CONFIG_DM_I2C
int (*idle_bus_fn)(void *p);
void *idle_bus_data;
diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
index 23119cce65..6565379253 100644
--- a/drivers/i2c/mxc_i2c.c
+++ b/drivers/i2c/mxc_i2c.c
@@ -890,9 +890,22 @@ static int mxc_i2c_probe(struct udevice *bus)
i2c_bus->bus = bus;
/* Enable clk */
- ret = enable_i2c_clk(1, bus->seq);
- if (ret < 0)
- return ret;
+ if (IS_ENABLED(CONFIG_CLK)) {
+ ret = clk_get_by_index(bus, 0, &i2c_bus->per_clk);
+ if (ret) {
+ printf("Failed to get i2c clk\n");
+ return ret;
+ }
+ ret = clk_enable(&i2c_bus->per_clk);
+ if (ret) {
+ printf("Failed to enable i2c clk\n");
+ return ret;
+ }
+ } else {
+ ret = enable_i2c_clk(1, bus->seq);
+ if (ret < 0)
+ return ret;
+ }
/*
* See Documentation/devicetree/bindings/i2c/i2c-imx.txt
@@ -919,7 +932,10 @@ static int mxc_i2c_probe(struct udevice *bus)
ret = i2c_idle_bus(i2c_bus);
if (ret < 0) {
/* Disable clk */
- enable_i2c_clk(0, bus->seq);
+ if (IS_ENABLED(CONFIG_CLK))
+ clk_disable(&i2c_bus->per_clk);
+ else
+ enable_i2c_clk(0, bus->seq);
return ret;
}
--
2.16.4
More information about the U-Boot
mailing list