]> git.sur5r.net Git - u-boot/commitdiff
imx: mx7ulp: Implement the clock functions for i2c driver
authorYe Li <ye.li@nxp.com>
Wed, 22 Feb 2017 08:21:44 +0000 (16:21 +0800)
committerStefano Babic <sbabic@denx.de>
Fri, 17 Mar 2017 08:27:08 +0000 (09:27 +0100)
Implement the i2c clock enable and get function for mx7ulp. These
functions are required by imx_lpi2c driver.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Ye Li <ye.li@nxp.com>
Reviewed-by: Stefano Babic <sbabic@denx.de>
arch/arm/cpu/armv7/mx7ulp/clock.c
arch/arm/include/asm/arch-mx7ulp/clock.h

index e6225bb4fba2dae53ee72389afd621de554f7e8e..1c072b8198dcf00305510057bc874248a8b5d7c3 100644 (file)
@@ -73,6 +73,46 @@ u32 get_lpuart_clk(void)
        return pcc_clock_get_rate(lpuart_pcc_clks[index - 4]);
 }
 
+#ifdef CONFIG_SYS_LPI2C_IMX
+int enable_i2c_clk(unsigned char enable, unsigned i2c_num)
+{
+       /* Set parent to FIRC DIV2 clock */
+       const enum pcc_clk lpi2c_pcc_clks[] = {
+               PER_CLK_LPI2C4,
+               PER_CLK_LPI2C5,
+               PER_CLK_LPI2C6,
+               PER_CLK_LPI2C7,
+       };
+
+       if (i2c_num < 4 || i2c_num > 7)
+               return -EINVAL;
+
+       if (enable) {
+               pcc_clock_enable(lpi2c_pcc_clks[i2c_num - 4], false);
+               pcc_clock_sel(lpi2c_pcc_clks[i2c_num - 4], SCG_FIRC_DIV2_CLK);
+               pcc_clock_enable(lpi2c_pcc_clks[i2c_num - 4], true);
+       } else {
+               pcc_clock_enable(lpi2c_pcc_clks[i2c_num - 4], false);
+       }
+       return 0;
+}
+
+u32 imx_get_i2cclk(unsigned i2c_num)
+{
+       const enum pcc_clk lpi2c_pcc_clks[] = {
+               PER_CLK_LPI2C4,
+               PER_CLK_LPI2C5,
+               PER_CLK_LPI2C6,
+               PER_CLK_LPI2C7,
+       };
+
+       if (i2c_num < 4 || i2c_num > 7)
+               return 0;
+
+       return pcc_clock_get_rate(lpi2c_pcc_clks[i2c_num - 4]);
+}
+#endif
+
 unsigned int mxc_get_clock(enum mxc_clock clk)
 {
        switch (clk) {
index f21052ef754bbffed264445c5af4d3966dd8b21c..ebf32c6c2c92919453e8f9b24b2804fd35951070 100644 (file)
@@ -27,6 +27,10 @@ enum mxc_clock {
 
 u32 mxc_get_clock(enum mxc_clock clk);
 u32 get_lpuart_clk(void);
+#ifdef CONFIG_SYS_LPI2C_IMX
+int enable_i2c_clk(unsigned char enable, unsigned i2c_num);
+u32 imx_get_i2cclk(unsigned i2c_num);
+#endif
 #ifdef CONFIG_MXC_OCOTP
 void enable_ocotp_clk(unsigned char enable);
 #endif