i2c: mxc: add CONFIG_CLK support
authorPeng Fan <peng.fan@nxp.com>
Thu, 8 Aug 2019 01:43:30 +0000 (01:43 +0000)
committerHeiko Schocher <hs@denx.de>
Mon, 2 Sep 2019 04:35:08 +0000 (06:35 +0200)
When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Reviewed-by: Frieder Schrempf <frieder.schrempf@kontron.de>
Tested-by: Frieder Schrempf <frieder.schrempf@kontron.de>
hs: removed hunk in mxc_i2c_probe() as not longer in code

arch/arm/include/asm/mach-imx/mxc_i2c.h
drivers/i2c/mxc_i2c.c

index 8e1ea9af19db59b8536e13f26dea3b08a58a9405..81fd9814447cd9c363aabe4f2fa7fef4fbc97775 100644 (file)
@@ -6,6 +6,9 @@
 #define __ASM_ARCH_MXC_MXC_I2C_H__
 #include <asm-generic/gpio.h>
 #include <asm/mach-imx/iomux-v3.h>
+#if CONFIG_IS_ENABLED(CLK)
+#include <clk.h>
+#endif
 
 struct i2c_pin_ctrl {
        iomux_v3_cfg_t i2c_mode;
@@ -47,6 +50,9 @@ struct mxc_i2c_bus {
        ulong driver_data;
        int speed;
        struct i2c_pads_info *pads_info;
+#if CONFIG_IS_ENABLED(CLK)
+       struct clk per_clk;
+#endif
 #ifndef CONFIG_DM_I2C
        int (*idle_bus_fn)(void *p);
        void *idle_bus_data;
index 20f6dc4ecb50d80d58cf52e94f06b3c2f5146067..786b5a2226b65f3f70db6c837273ec9a55948fc5 100644 (file)
@@ -149,7 +149,12 @@ static uint8_t i2c_imx_get_clk(struct mxc_i2c_bus *i2c_bus, unsigned int rate)
 #endif
 
        /* Divider value calculation */
+#if CONFIG_IS_ENABLED(CLK)
+       i2c_clk_rate = clk_get_rate(&i2c_bus->per_clk);
+#else
        i2c_clk_rate = mxc_get_clock(MXC_I2C_CLK);
+#endif
+
        div = (i2c_clk_rate + rate - 1) / rate;
        if (div < i2c_clk_div[0][0])
                clk_div = 0;
@@ -891,9 +896,22 @@ static int mxc_i2c_probe(struct udevice *bus)
        i2c_bus->bus = bus;
 
        /* Enable clk */
+#if CONFIG_IS_ENABLED(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;
+#endif
 
        /*
         * See Documentation/devicetree/bindings/i2c/i2c-imx.txt