[U-Boot] [PATCH v4 12/13] clk: Port Linux common clock framework [CCF] for imx6q to U-boot (tag: 5.0-rc3)

2019-05-16 Thread Lukasz Majewski
This commit brings the files from Linux kernel to provide clocks support
as it is used on the Linux kernel with common clock framework [CCF] setup.

The directory structure has been preserved. The ported code only supports
reading information from PLL, MUX, Divider, etc and enabling/disabling
the clocks USDHCx/ECSPIx depending on used bus. Moreover, it is agnostic
to the alias numbering as the information about the clock is read from
device tree.

One needs to pay attention to the comments indicating necessary for U-boot's
DM changes.

If needed the code can be extended to support the "set" part of the clock
management.


Signed-off-by: Lukasz Majewski 
---

Changes in v4:
- Port some more Linux code to facilitate imx8 code porting (most notably
  flags)
- Explicitly use container_of() based macro to provide struct clk in various
  places (e.g. gate2, mux, etc)
  Following patches has been squashed:
  http://patchwork.ozlabs.org/patch/1093141/
  http://patchwork.ozlabs.org/patch/1093142/
  http://patchwork.ozlabs.org/patch/1093146/

Changes in v3: None

 drivers/clk/Kconfig|  14 
 drivers/clk/Makefile   |   2 +
 drivers/clk/clk-divider.c  | 148 ++
 drivers/clk/clk-fixed-factor.c |  87 
 drivers/clk/clk-mux.c  | 164 +
 drivers/clk/clk.c  |  56 +
 drivers/clk/imx/Kconfig|   9 +++
 drivers/clk/imx/Makefile   |   2 +
 drivers/clk/imx/clk-gate2.c| 113 ++
 drivers/clk/imx/clk-imx6q.c| 179 +
 drivers/clk/imx/clk-pfd.c  |  91 +
 drivers/clk/imx/clk-pllv3.c|  83 +++
 drivers/clk/imx/clk.h  |  75 +
 include/linux/clk-provider.h   | 115 ++
 14 files changed, 1138 insertions(+)
 create mode 100644 drivers/clk/clk-divider.c
 create mode 100644 drivers/clk/clk-fixed-factor.c
 create mode 100644 drivers/clk/clk-mux.c
 create mode 100644 drivers/clk/clk.c
 create mode 100644 drivers/clk/imx/clk-gate2.c
 create mode 100644 drivers/clk/imx/clk-imx6q.c
 create mode 100644 drivers/clk/imx/clk-pfd.c
 create mode 100644 drivers/clk/imx/clk-pllv3.c
 create mode 100644 drivers/clk/imx/clk.h
 create mode 100644 include/linux/clk-provider.h

diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig
index 96969b9e30..344cd4415c 100644
--- a/drivers/clk/Kconfig
+++ b/drivers/clk/Kconfig
@@ -46,6 +46,20 @@ config CLK_BOSTON
help
  Enable this to support the clocks
 
+config SPL_CLK_CCF
+   bool "SPL Common Clock Framework [CCF] support "
+   depends on SPL_CLK
+   help
+ Enable this option if you want to (re-)use the Linux kernel's Common
+ Clock Framework [CCF] code in U-Boot's SPL.
+
+config CLK_CCF
+   bool "Common Clock Framework [CCF] support "
+   depends on CLK
+   help
+ Enable this option if you want to (re-)use the Linux kernel's Common
+ Clock Framework [CCF] code in U-Boot's clock driver.
+
 config CLK_STM32F
bool "Enable clock driver support for STM32F family"
depends on CLK && (STM32F7 || STM32F4)
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 719b9b8e02..1a45bf3505 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -7,6 +7,8 @@
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk-uclass.o
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk_fixed_rate.o
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk_fixed_factor.o
+obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk.o clk-divider.o clk-mux.o
+obj-$(CONFIG_$(SPL_TPL_)CLK_CCF) += clk-fixed-factor.o
 
 obj-y += imx/
 obj-y += tegra/
diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
new file mode 100644
index 00..1d2c1b1ec4
--- /dev/null
+++ b/drivers/clk/clk-divider.c
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2019 DENX Software Engineering
+ * Lukasz Majewski, DENX Software Engineering, lu...@denx.de
+ *
+ * Copyright (C) 2011 Sascha Hauer, Pengutronix 
+ * Copyright (C) 2011 Richard Zhao, Linaro 
+ * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd 
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "clk.h"
+
+#define UBOOT_DM_CLK_CCF_DIVIDER "ccf_clk_divider"
+
+static unsigned int _get_table_div(const struct clk_div_table *table,
+  unsigned int val)
+{
+   const struct clk_div_table *clkt;
+
+   for (clkt = table; clkt->div; clkt++)
+   if (clkt->val == val)
+   return clkt->div;
+   return 0;
+}
+
+static unsigned int _get_div(const struct clk_div_table *table,
+unsigned int val, unsigned long flags, u8 width)
+{
+   if (flags & CLK_DIVIDER_ONE_BASED)
+   return val;
+   if (flags & CLK_DIVIDER_POWER_OF_TWO)
+  

Re: [U-Boot] [PATCH v4 12/13] clk: Port Linux common clock framework [CCF] for imx6q to U-boot (tag: 5.0-rc3)

2019-05-16 Thread Bin Meng
Hi Lukasz,

On Fri, May 17, 2019 at 6:16 AM Lukasz Majewski  wrote:
>
> This commit brings the files from Linux kernel to provide clocks support
> as it is used on the Linux kernel with common clock framework [CCF] setup.
>
> The directory structure has been preserved. The ported code only supports
> reading information from PLL, MUX, Divider, etc and enabling/disabling
> the clocks USDHCx/ECSPIx depending on used bus. Moreover, it is agnostic
> to the alias numbering as the information about the clock is read from
> device tree.
>
> One needs to pay attention to the comments indicating necessary for U-boot's

nits: it's U-Boot. Please fix this globally in the commit message, as
well as in the code comments in this commit.

> DM changes.
>
> If needed the code can be extended to support the "set" part of the clock
> management.
>
>
> Signed-off-by: Lukasz Majewski 
> ---
>
> Changes in v4:
> - Port some more Linux code to facilitate imx8 code porting (most notably
>   flags)
> - Explicitly use container_of() based macro to provide struct clk in various
>   places (e.g. gate2, mux, etc)
>   Following patches has been squashed:
>   http://patchwork.ozlabs.org/patch/1093141/
>   http://patchwork.ozlabs.org/patch/1093142/
>   http://patchwork.ozlabs.org/patch/1093146/
>
> Changes in v3: None
>
>  drivers/clk/Kconfig|  14 
>  drivers/clk/Makefile   |   2 +
>  drivers/clk/clk-divider.c  | 148 ++
>  drivers/clk/clk-fixed-factor.c |  87 
>  drivers/clk/clk-mux.c  | 164 +
>  drivers/clk/clk.c  |  56 +
>  drivers/clk/imx/Kconfig|   9 +++
>  drivers/clk/imx/Makefile   |   2 +
>  drivers/clk/imx/clk-gate2.c| 113 ++
>  drivers/clk/imx/clk-imx6q.c| 179 
> +
>  drivers/clk/imx/clk-pfd.c  |  91 +
>  drivers/clk/imx/clk-pllv3.c|  83 +++
>  drivers/clk/imx/clk.h  |  75 +
>  include/linux/clk-provider.h   | 115 ++
>  14 files changed, 1138 insertions(+)
>  create mode 100644 drivers/clk/clk-divider.c
>  create mode 100644 drivers/clk/clk-fixed-factor.c
>  create mode 100644 drivers/clk/clk-mux.c
>  create mode 100644 drivers/clk/clk.c
>  create mode 100644 drivers/clk/imx/clk-gate2.c
>  create mode 100644 drivers/clk/imx/clk-imx6q.c
>  create mode 100644 drivers/clk/imx/clk-pfd.c
>  create mode 100644 drivers/clk/imx/clk-pllv3.c
>  create mode 100644 drivers/clk/imx/clk.h
>  create mode 100644 include/linux/clk-provider.h
>

Regards,
Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 12/13] clk: Port Linux common clock framework [CCF] for imx6q to U-boot (tag: 5.0-rc3)

2019-05-17 Thread Adam Ford
On Thu, May 16, 2019 at 9:48 PM Bin Meng  wrote:
>
> Hi Lukasz,
>
> On Fri, May 17, 2019 at 6:16 AM Lukasz Majewski  wrote:
> >
> > This commit brings the files from Linux kernel to provide clocks support
> > as it is used on the Linux kernel with common clock framework [CCF] setup.
> >


Two issues / questions:

1)  I tried to test this on the imx6q_logic board, and I enabled
CLK_IMX6Q in the menu config, but when I save the defconfig, it
appears there are unmet dependencies.

WARNING: unmet direct dependencies detected for SPL_CLK_CCF
  Depends on [n]: SPL_CLK [=n]
  Selected by [y]:
  - CLK_IMX6Q [=y] && ARCH_MX6 [=y]

WARNING: unmet direct dependencies detected for SPL_CLK_CCF
  Depends on [n]: SPL_CLK [=n]
  Selected by [y]:
  - CLK_IMX6Q [=y] && ARCH_MX6 [=y]

you may want to consider implying the correct functions if ARCH_MX6 &&
CLK_IMX6Q or select the proper SPL_CLK info.  My board doesn't do DM
in SPL right now, but I assume the CLK driver you ported is using DM.

2)  I didn't attempt to load the SPL portion, but when I loaded the
u-boot-dtb.img file, it didn't appear to boot.


U-Boot SPL 2019.01 (May 13 2019 - 16:57:41 -0500)
Trying to boot from MMC1
spl_load_image_fat_os: error reading image args, err - -2


(hang)

Other than enabling CLK_IMX6Q, are there other items I need to enable?
 My board has OF_CONTROL in U-Boot with DM support working in the
U-Boot portion.

adam
> > The directory structure has been preserved. The ported code only supports
> > reading information from PLL, MUX, Divider, etc and enabling/disabling
> > the clocks USDHCx/ECSPIx depending on used bus. Moreover, it is agnostic
> > to the alias numbering as the information about the clock is read from
> > device tree.
> >
> > One needs to pay attention to the comments indicating necessary for U-boot's
>
> nits: it's U-Boot. Please fix this globally in the commit message, as
> well as in the code comments in this commit.
>
> > DM changes.
> >
> > If needed the code can be extended to support the "set" part of the clock
> > management.
> >
> >
> > Signed-off-by: Lukasz Majewski 
> > ---
> >
> > Changes in v4:
> > - Port some more Linux code to facilitate imx8 code porting (most notably
> >   flags)
> > - Explicitly use container_of() based macro to provide struct clk in various
> >   places (e.g. gate2, mux, etc)
> >   Following patches has been squashed:
> >   http://patchwork.ozlabs.org/patch/1093141/
> >   http://patchwork.ozlabs.org/patch/1093142/
> >   http://patchwork.ozlabs.org/patch/1093146/
> >
> > Changes in v3: None
> >
> >  drivers/clk/Kconfig|  14 
> >  drivers/clk/Makefile   |   2 +
> >  drivers/clk/clk-divider.c  | 148 ++
> >  drivers/clk/clk-fixed-factor.c |  87 
> >  drivers/clk/clk-mux.c  | 164 +
> >  drivers/clk/clk.c  |  56 +
> >  drivers/clk/imx/Kconfig|   9 +++
> >  drivers/clk/imx/Makefile   |   2 +
> >  drivers/clk/imx/clk-gate2.c| 113 ++
> >  drivers/clk/imx/clk-imx6q.c| 179 
> > +
> >  drivers/clk/imx/clk-pfd.c  |  91 +
> >  drivers/clk/imx/clk-pllv3.c|  83 +++
> >  drivers/clk/imx/clk.h  |  75 +
> >  include/linux/clk-provider.h   | 115 ++
> >  14 files changed, 1138 insertions(+)
> >  create mode 100644 drivers/clk/clk-divider.c
> >  create mode 100644 drivers/clk/clk-fixed-factor.c
> >  create mode 100644 drivers/clk/clk-mux.c
> >  create mode 100644 drivers/clk/clk.c
> >  create mode 100644 drivers/clk/imx/clk-gate2.c
> >  create mode 100644 drivers/clk/imx/clk-imx6q.c
> >  create mode 100644 drivers/clk/imx/clk-pfd.c
> >  create mode 100644 drivers/clk/imx/clk-pllv3.c
> >  create mode 100644 drivers/clk/imx/clk.h
> >  create mode 100644 include/linux/clk-provider.h
> >
>
> Regards,
> Bin
___
U-Boot mailing list
U-Boot@lists.denx.de
https://lists.denx.de/listinfo/u-boot


Re: [U-Boot] [PATCH v4 12/13] clk: Port Linux common clock framework [CCF] for imx6q to U-boot (tag: 5.0-rc3)

2019-05-17 Thread Lukasz Majewski
On Fri, 17 May 2019 07:31:38 -0500
Adam Ford  wrote:

> On Thu, May 16, 2019 at 9:48 PM Bin Meng  wrote:
> >
> > Hi Lukasz,
> >
> > On Fri, May 17, 2019 at 6:16 AM Lukasz Majewski 
> > wrote:  
> > >
> > > This commit brings the files from Linux kernel to provide clocks
> > > support as it is used on the Linux kernel with common clock
> > > framework [CCF] setup. 
> 
> 
> Two issues / questions:
> 
> 1)  I tried to test this on the imx6q_logic board, and I enabled
> CLK_IMX6Q in the menu config, but when I save the defconfig, it
> appears there are unmet dependencies.
> 
> WARNING: unmet direct dependencies detected for SPL_CLK_CCF
>   Depends on [n]: SPL_CLK [=n]
>   Selected by [y]:
>   - CLK_IMX6Q [=y] && ARCH_MX6 [=y]
> 
> WARNING: unmet direct dependencies detected for SPL_CLK_CCF
>   Depends on [n]: SPL_CLK [=n]
>   Selected by [y]:
>   - CLK_IMX6Q [=y] && ARCH_MX6 [=y]
> 
> you may want to consider implying the correct functions if ARCH_MX6 &&
> CLK_IMX6Q or select the proper SPL_CLK info.  My board doesn't do DM
> in SPL right now, but I assume the CLK driver you ported is using DM.

Ok. I will look into the Kconfig options.

> 
> 2)  I didn't attempt to load the SPL portion, but when I loaded the
> u-boot-dtb.img file, it didn't appear to boot.
> 
> 
> U-Boot SPL 2019.01 (May 13 2019 - 16:57:41 -0500)
> Trying to boot from MMC1
> spl_load_image_fat_os: error reading image args, err - -2
> 
> 
> (hang)
> 
> Other than enabling CLK_IMX6Q, are there other items I need to enable?
>  My board has OF_CONTROL in U-Boot with DM support working in the
> U-Boot portion.
> 

The CCF shall work also with a setup where it is enabled only in u-boot
proper (CONFIG_CLK_CCF).

Please look into following TPC DM/DTS port as a reference:
https://github.com/lmajewski/u-boot-dfu/commits/DM-SPL-TPC70

This board is fully converted and uses DM/DTS in SPL and u-boot proper
(with CCF).

> adam
> > > The directory structure has been preserved. The ported code only
> > > supports reading information from PLL, MUX, Divider, etc and
> > > enabling/disabling the clocks USDHCx/ECSPIx depending on used
> > > bus. Moreover, it is agnostic to the alias numbering as the
> > > information about the clock is read from device tree.
> > >
> > > One needs to pay attention to the comments indicating necessary
> > > for U-boot's  
> >
> > nits: it's U-Boot. Please fix this globally in the commit message,
> > as well as in the code comments in this commit.
> >  
> > > DM changes.
> > >
> > > If needed the code can be extended to support the "set" part of
> > > the clock management.
> > >
> > >
> > > Signed-off-by: Lukasz Majewski 
> > > ---
> > >
> > > Changes in v4:
> > > - Port some more Linux code to facilitate imx8 code porting (most
> > > notably flags)
> > > - Explicitly use container_of() based macro to provide struct clk
> > > in various places (e.g. gate2, mux, etc)
> > >   Following patches has been squashed:
> > >   http://patchwork.ozlabs.org/patch/1093141/
> > >   http://patchwork.ozlabs.org/patch/1093142/
> > >   http://patchwork.ozlabs.org/patch/1093146/
> > >
> > > Changes in v3: None
> > >
> > >  drivers/clk/Kconfig|  14 
> > >  drivers/clk/Makefile   |   2 +
> > >  drivers/clk/clk-divider.c  | 148
> > > ++ drivers/clk/clk-fixed-factor.c
> > > |  87  drivers/clk/clk-mux.c  | 164
> > > +
> > > drivers/clk/clk.c  |  56 +
> > > drivers/clk/imx/Kconfig|   9 +++
> > > drivers/clk/imx/Makefile   |   2 +
> > > drivers/clk/imx/clk-gate2.c| 113 ++
> > > drivers/clk/imx/clk-imx6q.c| 179
> > > +
> > > drivers/clk/imx/clk-pfd.c  |  91 +
> > > drivers/clk/imx/clk-pllv3.c|  83 +++
> > > drivers/clk/imx/clk.h  |  75 +
> > > include/linux/clk-provider.h   | 115 ++
> > > 14 files changed, 1138 insertions(+) create mode 100644
> > > drivers/clk/clk-divider.c create mode 100644
> > > drivers/clk/clk-fixed-factor.c create mode 100644
> > > drivers/clk/clk-mux.c create mode 100644 drivers/clk/clk.c create
> > > mode 100644 drivers/clk/imx/clk-gate2.c create mode 100644
> > > drivers/clk/imx/clk-imx6q.c create mode 100644
> > > drivers/clk/imx/clk-pfd.c create mode 100644
> > > drivers/clk/imx/clk-pllv3.c create mode 100644
> > > drivers/clk/imx/clk.h create mode 100644
> > > include/linux/clk-provider.h 
> >
> > Regards,
> > Bin  




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: lu...@denx.de


pgpYWX7eY6Qfo.pgp
Description: OpenPGP digital signature
___
U-Boot mailing list
U-Boot@lists.denx.de
ht