Skip to contentSkip to conversation

i2c: mxc: add CONFIG_CLK support

PATCH Superseded Peng Fan 4 participants 6 messages Aug 6, 2019 – Aug 8, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Peng Fan

author
#0 lore raw

PATCH 1/1 i2c: mxc: add CONFIG_CLK support

When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.

---
 arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
 drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)
arch/arm/include/asm/mach-imx/mxc_i2c.h +6 -0
index 8e1ea9af19..81fd981444 100644
@@ -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;
drivers/i2c/mxc_i2c.c +17 -0
index 23119cce65..2e157bca58 100644
@@ -890,9 +890,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
@@ -919,7 +932,11 @@ static int mxc_i2c_probe(struct udevice *bus)
 	ret = i2c_idle_bus(i2c_bus);
 	if (ret < 0) {
 		/* Disable clk */
+#if CONFIG_IS_ENABLED(CLK)
+		clk_disable(&i2c_bus->per_clk);
+#else
 		enable_i2c_clk(0, bus->seq);
+#endif
 		return ret;
 	}
 
Signature · 1 line
2.16.4
#1 lore raw

PATCH 1/1 i2c: mxc: add CONFIG_CLK support

Quoted 60 lines

When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.

---
 arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
 drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)
arch/arm/include/asm/mach-imx/mxc_i2c.h +6 -0
index 8e1ea9af19..81fd981444 100644
@@ -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;
drivers/i2c/mxc_i2c.c +13 -0
index 23119cce65..2e157bca58 100644
@@ -890,9 +890,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

drivers/i2c/mxc_i2c.c static int mxc_i2c_probe(struct udevice *bus) · line 941

Quoted 10 lines
drivers/i2c/mxc_i2c.c +4 -0
@@ -919,7 +932,11 @@ static int mxc_i2c_probe(struct udevice *bus)
 	ret = i2c_idle_bus(i2c_bus);
 	if (ret < 0) {
 		/* Disable clk */
+#if CONFIG_IS_ENABLED(CLK)
+		clk_disable(&i2c_bus->per_clk);
+#else
 		enable_i2c_clk(0, bus->seq);
+#endif
 		return ret;
 	}

Best regards,
Ye Li

Quoted 2 lines
#2 lore raw

PATCH 1/1 i2c: mxc: add CONFIG_CLK support

In reply to Peng Fan

Hi Peng,

drivers/i2c/mxc_i2c.c

Quoted 36 lines · Peng Fan

When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.

---
  arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
  drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
  2 files changed, 23 insertions(+)
arch/arm/include/asm/mach-imx/mxc_i2c.h +6 -0
index 8e1ea9af19..81fd981444 100644
@@ -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;
drivers/i2c/mxc_i2c.c +0 -0
index 23119cce65..2e157bca58 100644

I already commented on a previous version of this patch and the following change is still missing here:

@@ -149,7 +149,11 @@ 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;

Regards,
Frieder

Quoted 36 lines
drivers/i2c/mxc_i2c.c +17 -0
@@ -890,9 +890,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
@@ -919,7 +932,11 @@ static int mxc_i2c_probe(struct udevice *bus)
  	ret = i2c_idle_bus(i2c_bus);
  	if (ret < 0) {
  		/* Disable clk */
+#if CONFIG_IS_ENABLED(CLK)
+		clk_disable(&i2c_bus->per_clk);
+#else
  		enable_i2c_clk(0, bus->seq);
+#endif
  		return ret;
  	}
 
author
#3 lore raw

PATCH 1/1 i2c: mxc: add CONFIG_CLK support

Hi Schrempf,

Quoted 37 lines

Subject: Re: [U-Boot] [PATCH] i2c: mxc: add CONFIG_CLK support

Hi Peng,

Quoted 32 lines · Peng Fan

When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.

---
  arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
  drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
  2 files changed, 23 insertions(+)
arch/arm/include/asm/mach-imx/mxc_i2c.h +6 -0
index 8e1ea9af19..81fd981444 100644
@@ -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);
Quoted 8 lines

drivers/i2c/mxc_i2c.c

Quoted 5 lines
arch/arm/include/asm/mach-imx/mxc_i2c.h +0 -0
  	void *idle_bus_data;
drivers/i2c/mxc_i2c.c index renamed from drivers/i2c/mxc_i2c.c +0 -0

23119cce65..2e157bca58 100644

drivers/i2c/mxc_i2c.c +0 -0

I already commented on a previous version of this patch and the following change is still missing here:

Thanks, I forgot to addressed your comments. Sent out v2, please help review.

Thanks,
Peng.

Quoted 53 lines
(quoted diff) +3 -0
@@ -149,7 +149,11 @@ 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;

Regards,
Frieder

Quoted 36 lines
drivers/i2c/mxc_i2c.c +17 -0
@@ -890,9 +890,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
@@ -919,7 +932,11 @@ static int mxc_i2c_probe(struct udevice *bus)
  	ret = i2c_idle_bus(i2c_bus);
  	if (ret < 0) {
  		/* Disable clk */
+#if CONFIG_IS_ENABLED(CLK)
+		clk_disable(&i2c_bus->per_clk);
+#else
  		enable_i2c_clk(0, bus->seq);
+#endif
  		return ret;
  	}
 
#4 lore raw

PATCH 1/1 i2c: mxc: add CONFIG_CLK support

In reply to Peng Fan
Quoted 61 lines · On Tue, 6 Aug 2019 10:09:12 +0000 Peng Fan <[email protected]> wrote:

When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.

---
 arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
 drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)
(quoted diff) +0 -0

b/arch/arm/include/asm/mach-imx/mxc_i2c.h index 8e1ea9af19..81fd981444 100644 --- a/arch/arm/include/asm/mach-imx/mxc_i2c.h +++ b/arch/arm/include/asm/mach-imx/mxc_i2c.h @@ -6,6 +6,9 @@
#define __ASM_ARCH_MXC_MXC_I2C_H__
#include <asm-generic/gpio.h>
#include <asm/mach-imx/iomux-v3.h>

arch/arm/include/asm/mach-imx/mxc_i2c.h +6 -0
+#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;
drivers/i2c/mxc_i2c.c +13 -0
index 23119cce65..2e157bca58 100644
@@ -890,9 +890,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
@@ -919,7 +932,11 @@ static int mxc_i2c_probe(struct udevice *bus)
 	ret = i2c_idle_bus(i2c_bus);

drivers/i2c/mxc_i2c.c static int mxc_i2c_probe(struct udevice *bus) · line 942

Quoted 10 lines
drivers/i2c/mxc_i2c.c +4 -0
 	if (ret < 0) {
 		/* Disable clk */
+#if CONFIG_IS_ENABLED(CLK)
+		clk_disable(&i2c_bus->per_clk);
+#else
 		enable_i2c_clk(0, bus->seq);
+#endif
 		return ret;
 	}
 

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma at denx.de -------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190808/5bdffc4d/attachment.sig>

author
#5 lore raw

PATCH 1/1 i2c: mxc: add CONFIG_CLK support

Hi Lukasz,

Quoted 63 lines

Subject: Re: [PATCH] i2c: mxc: add CONFIG_CLK support

Quoted 8 lines · On Tue, 6 Aug 2019 10:09:12 +0000 Peng Fan <[email protected]> wrote:

When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.

---
 arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
 drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)
Quoted 5 lines
(quoted diff) +0 -0

b/arch/arm/include/asm/mach-imx/mxc_i2c.h index 8e1ea9af19..81fd981444 100644 --- a/arch/arm/include/asm/mach-imx/mxc_i2c.h +++ b/arch/arm/include/asm/mach-imx/mxc_i2c.h @@ -6,6 +6,9 @@

#define

Quoted 1 line

__ASM_ARCH_MXC_MXC_I2C_H__ #include <asm-generic/gpio.h>

#include

Quoted 42 lines

<asm/mach-imx/iomux-v3.h>

arch/arm/include/asm/mach-imx/mxc_i2c.h +6 -0
+#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;
drivers/i2c/mxc_i2c.c index renamed from drivers/i2c/mxc_i2c.c +0 -0

23119cce65..2e157bca58 100644

drivers/i2c/mxc_i2c.c +13 -0
@@ -890,9 +890,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
 
Quoted 16 lines
Quoted 4 lines
drivers/i2c/mxc_i2c.c +0 -0
 	/*
 	 * See Documentation/devicetree/bindings/i2c/i2c-imx.txt
@@ -919,7 +932,11 @@ static int mxc_i2c_probe(struct udevice *bus)
 	ret = i2c_idle_bus(i2c_bus);

drivers/i2c/mxc_i2c.c static int mxc_i2c_probe(struct udevice *bus) · line 942

Quoted 10 lines
drivers/i2c/mxc_i2c.c +4 -0
 	if (ret < 0) {
 		/* Disable clk */
+#if CONFIG_IS_ENABLED(CLK)
+		clk_disable(&i2c_bus->per_clk);
+#else
 		enable_i2c_clk(0, bus->seq);
+#endif
 		return ret;
 	}
 

There is a v2 patch to fix an issue. Please help review there.

Thanks,
Peng.

Quoted 12 lines

Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH, Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email:
lukma at denx.de