[U-Boot,V2,04/51] i2c: mxc: add CONFIG_CLK support
diff mbox series

Message ID 20190708015333.20411-5-peng.fan@nxp.com
State Rejected
Delegated to: Stefano Babic
Headers show
Series
  • Support i.MX8MM/N
Related show

Commit Message

Peng Fan July 8, 2019, 1:38 a.m. UTC
When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.

Signed-off-by: Peng Fan <peng.fan@nxp.com>
---
 arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
 drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
 2 files changed, 23 insertions(+)

Comments

Lukasz Majewski July 10, 2019, 8:03 a.m. UTC | #1
Hi Peng,

> When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>  arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
>  drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/arch/arm/include/asm/mach-imx/mxc_i2c.h
> 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>
> +#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;
> diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
> index 23119cce65..2e157bca58 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 */
> +#if CONFIG_IS_ENABLED(CLK)
> +	ret = clk_get_by_index(bus, 0, &i2c_bus->per_clk);

I'm wondering if all supported in U-Boot NXP SoCs have the per clk
defined in index 0 with their DTS ...

> +	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;
>  	}
>  




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@denx.de
Peng Fan July 10, 2019, 8:19 a.m. UTC | #2
Hi Lukasz,

> Subject: Re: [U-Boot] [PATCH V2 04/51] i2c: mxc: add CONFIG_CLK support
> 
> Hi Peng,
> 
> > When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.
> >
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > ---
> >  arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
> >  drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
> >  2 files changed, 23 insertions(+)
> >
> > diff --git a/arch/arm/include/asm/mach-imx/mxc_i2c.h
> > 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>
> > +#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;
> > diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c index
> > 23119cce65..2e157bca58 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 */
> > +#if CONFIG_IS_ENABLED(CLK)
> > +	ret = clk_get_by_index(bus, 0, &i2c_bus->per_clk);
> 
> I'm wondering if all supported in U-Boot NXP SoCs have the per clk defined in
> index 0 with their DTS ...


imx6qdl.dtsi imx6sl.dtsi imx6ul.dtsi imx7s.dtsi imx8mq.dtsi imx8mm.dtsi has
that clock.

It might not be named per clock. Just for easy to use, choose per clock name.

Regards,
Peng.

> 
> > +	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;
> >  	}
> >
> 
> 
> 
> 
> 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@denx.de
Schrempf Frieder July 10, 2019, 2:10 p.m. UTC | #3
Hi Peng,

On 08.07.19 03:38, Peng Fan wrote:
> When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.
> 
> Signed-off-by: Peng Fan <peng.fan@nxp.com>
> ---
>   arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
>   drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
>   2 files changed, 23 insertions(+)
> 
> diff --git a/arch/arm/include/asm/mach-imx/mxc_i2c.h 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>
> +#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;
> diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
> index 23119cce65..2e157bca58 100644
> --- a/drivers/i2c/mxc_i2c.c
> +++ b/drivers/i2c/mxc_i2c.c

I think this patch should also contain the following diff:

@@ -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

> @@ -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;
>   	}
>   
>
Peng Fan July 11, 2019, 6:43 a.m. UTC | #4
> Subject: Re: [U-Boot] [PATCH V2 04/51] i2c: mxc: add CONFIG_CLK support
> 
> Hi Peng,
> 
> On 08.07.19 03:38, Peng Fan wrote:
> > When CONFIG_CLK enabled, use CLK UCLASS for clk related settings.
> >
> > Signed-off-by: Peng Fan <peng.fan@nxp.com>
> > ---
> >   arch/arm/include/asm/mach-imx/mxc_i2c.h |  6 ++++++
> >   drivers/i2c/mxc_i2c.c                   | 17 +++++++++++++++++
> >   2 files changed, 23 insertions(+)
> >
> > diff --git a/arch/arm/include/asm/mach-imx/mxc_i2c.h
> > 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>
> > +#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;
> > diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c index
> > 23119cce65..2e157bca58 100644
> > --- a/drivers/i2c/mxc_i2c.c
> > +++ b/drivers/i2c/mxc_i2c.c
> 
> I think this patch should also contain the following diff:
> 
> @@ -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;

Thanks for reporting this. Yes, better to add the piece code for CLK.

Thanks,
Peng.

> 
> Regards,
> Frieder
> 
> > @@ -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;
> >   	}
> >
> >

Patch
diff mbox series

diff --git a/arch/arm/include/asm/mach-imx/mxc_i2c.h 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>
+#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;
diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
index 23119cce65..2e157bca58 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 */
+#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;
 	}