* [PATCH 0/5] OF: probe clock providers from DT
@ 2013-11-09 13:24 Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 1/5] asm-generic: add macro for BAREBOX_CLK_TABLE Sebastian Hesselbarth
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: Sebastian Hesselbarth @ 2013-11-09 13:24 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This patch set brings automatic probing of DT clock providers to ARM
barebox, similar to what we have in Linux kernel.
First, a new macro BAREBOX_CLK_TABLE for generic linker scripts is added,
that will take all declared DT clock providers. That macro is then added
to the ARM linker script.
Then, barebox compatible versions of of_clk_init and CLK_OF_DECLARE are
added, that allow to parse and probe declared clock providers. The of_clk_init
call is then put right after of_platform_populate in of_probe.
Finally, clk/fixed is declared as such a clock provider and can now be probed
automatially for DT enabled ARM platforms.
Sebastian Hesselbarth (5):
asm-generic: add macro for BAREBOX_CLK_TABLE
ARM: lib: add BAREBOX_CLK_TABLE to linker script
clk: add of_clk_init and CLK_OF_DECLARE macro
OF: parse OF clock providers after populate
clk: fixed: add DT init function
arch/arm/lib/barebox.lds.S | 2 ++
drivers/clk/clk-fixed.c | 23 +++++++++++++++++++++++
drivers/clk/clk.c | 37 +++++++++++++++++++++++++++++++++++++
drivers/of/base.c | 1 +
include/asm-generic/barebox.lds.h | 9 ++++++++-
include/linux/clk.h | 14 ++++++++++++++
6 files changed, 85 insertions(+), 1 deletion(-)
---
Cc: barebox@lists.infradead.org
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/5] asm-generic: add macro for BAREBOX_CLK_TABLE
2013-11-09 13:24 [PATCH 0/5] OF: probe clock providers from DT Sebastian Hesselbarth
@ 2013-11-09 13:24 ` Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 2/5] ARM: lib: add BAREBOX_CLK_TABLE to linker script Sebastian Hesselbarth
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sebastian Hesselbarth @ 2013-11-09 13:24 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This adds a macro for linker scripts to place DT clock provider table.
While at it, also add ALIGN(8) to DTB macro and fix a whitespace issue.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
include/asm-generic/barebox.lds.h | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/include/asm-generic/barebox.lds.h b/include/asm-generic/barebox.lds.h
index 4754779..6d3a69e 100644
--- a/include/asm-generic/barebox.lds.h
+++ b/include/asm-generic/barebox.lds.h
@@ -41,9 +41,16 @@
#define BAREBOX_MAGICVARS KEEP(*(SORT_BY_NAME(.barebox_magicvar*)))
+#define BAREBOX_CLK_TABLE() \
+ . = ALIGN(8); \
+ __clk_of_table_start = .; \
+ KEEP(*(.__clk_of_table_*)); \
+ __clk_of_table_end = .;
+
#define BAREBOX_DTB() \
+ . = ALIGN(8); \
__dtb_start = .; \
- KEEP(*(.dtb.rodata.*)); \
+ KEEP(*(.dtb.rodata.*)); \
__dtb_end = .;
#if defined(CONFIG_ARCH_BAREBOX_MAX_BARE_INIT_SIZE) && \
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/5] ARM: lib: add BAREBOX_CLK_TABLE to linker script
2013-11-09 13:24 [PATCH 0/5] OF: probe clock providers from DT Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 1/5] asm-generic: add macro for BAREBOX_CLK_TABLE Sebastian Hesselbarth
@ 2013-11-09 13:24 ` Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 3/5] clk: add of_clk_init and CLK_OF_DECLARE macro Sebastian Hesselbarth
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sebastian Hesselbarth @ 2013-11-09 13:24 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This adds an .oftables section right before .dtb section with
BAREBOX_CLK_TABLE to ARM linker script.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
arch/arm/lib/barebox.lds.S | 2 ++
1 file changed, 2 insertions(+)
diff --git a/arch/arm/lib/barebox.lds.S b/arch/arm/lib/barebox.lds.S
index 10c63bf..d958873 100644
--- a/arch/arm/lib/barebox.lds.S
+++ b/arch/arm/lib/barebox.lds.S
@@ -92,6 +92,8 @@ SECTIONS
__usymtab : { BAREBOX_SYMS }
__usymtab_end = .;
+ .oftables : { BAREBOX_CLK_TABLE() }
+
.dtb : { BAREBOX_DTB() }
.rel.dyn : {
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/5] clk: add of_clk_init and CLK_OF_DECLARE macro
2013-11-09 13:24 [PATCH 0/5] OF: probe clock providers from DT Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 1/5] asm-generic: add macro for BAREBOX_CLK_TABLE Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 2/5] ARM: lib: add BAREBOX_CLK_TABLE to linker script Sebastian Hesselbarth
@ 2013-11-09 13:24 ` Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 4/5] OF: parse OF clock providers after populate Sebastian Hesselbarth
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Sebastian Hesselbarth @ 2013-11-09 13:24 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This add barebox versions of of_clk_init for parsing and registering
clock providers from DT. Also, a macro CLK_OF_DECLARE is added, that
allows to put init callbacks into its own section that can be linked
in the binary.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/clk/clk.c | 37 +++++++++++++++++++++++++++++++++++++
include/linux/clk.h | 14 ++++++++++++++
2 files changed, 51 insertions(+)
diff --git a/drivers/clk/clk.c b/drivers/clk/clk.c
index 5942e29..31d73c0 100644
--- a/drivers/clk/clk.c
+++ b/drivers/clk/clk.c
@@ -271,6 +271,10 @@ struct of_clk_provider {
void *data;
};
+extern struct of_device_id __clk_of_table_start[];
+const struct of_device_id __clk_of_table_sentinel
+ __attribute__ ((unused,section (".__clk_of_table_end")));
+
static LIST_HEAD(of_clk_providers);
struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec,
@@ -355,6 +359,39 @@ struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec)
return clk;
}
+
+/**
+ * of_clk_init() - Scan and init clock providers from the DT
+ * @root: parent of the first level to probe or NULL for the root of the tree
+ * @matches: array of compatible values and init functions for providers.
+ *
+ * This function scans the device tree for matching clock providers and
+ * calls their initialization functions
+ *
+ * Returns 0 on success, < 0 on failure.
+ */
+int of_clk_init(struct device_node *root, const struct of_device_id *matches)
+{
+ const struct of_device_id *match;
+ int rc;
+
+ if (!root)
+ root = of_find_node_by_path("/");
+ if (!root)
+ return -EINVAL;
+ if (!matches)
+ matches = __clk_of_table_start;
+
+ for_each_matching_node_and_match(root, matches, &match) {
+ of_clk_init_cb_t clk_init_cb = (of_clk_init_cb_t)match->data;
+ rc = clk_init_cb(root);
+ if (rc)
+ pr_err("%s: failed to init clock for %s: %d\n",
+ __func__, root->full_name, rc);
+ }
+
+ return 0;
+}
#endif
static void dump_one(struct clk *clk, int verbose, int indent)
diff --git a/include/linux/clk.h b/include/linux/clk.h
index 4778400..af38c72 100644
--- a/include/linux/clk.h
+++ b/include/linux/clk.h
@@ -12,6 +12,7 @@
#define __LINUX_CLK_H
#include <linux/err.h>
+#include <linux/stringify.h>
struct device_d;
@@ -278,6 +279,11 @@ void clk_dump(int verbose);
struct device_node;
struct of_phandle_args;
+#define CLK_OF_DECLARE(name, compat, fn) \
+const struct of_device_id __clk_of_table_##name \
+__attribute__ ((unused,section (".__clk_of_table_" __stringify(name)))) \
+ = { .compatible = compat, .data = (u32)fn }
+
#if defined(CONFIG_OFTREE) && defined(CONFIG_COMMON_CLK_OF_PROVIDER)
int of_clk_add_provider(struct device_node *np,
struct clk *(*clk_src_get)(struct of_phandle_args *args,
@@ -285,6 +291,8 @@ int of_clk_add_provider(struct device_node *np,
void *data);
void of_clk_del_provider(struct device_node *np);
+typedef int (*of_clk_init_cb_t)(struct device_node *);
+
struct clk_onecell_data {
struct clk **clks;
unsigned int clk_num;
@@ -295,6 +303,7 @@ struct clk *of_clk_src_simple_get(struct of_phandle_args *clkspec, void *data);
struct clk *of_clk_get(struct device_node *np, int index);
struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
+int of_clk_init(struct device_node *root, const struct of_device_id *matches);
#else
static inline struct clk *of_clk_get(struct device_node *np, int index)
{
@@ -305,6 +314,11 @@ static inline struct clk *of_clk_get_by_name(struct device_node *np,
{
return ERR_PTR(-ENOENT);
}
+static inline int of_clk_init(struct device_node *root,
+ const struct of_device_id *matches)
+{
+ return 0;
+}
#endif
#endif
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/5] OF: parse OF clock providers after populate
2013-11-09 13:24 [PATCH 0/5] OF: probe clock providers from DT Sebastian Hesselbarth
` (2 preceding siblings ...)
2013-11-09 13:24 ` [PATCH 3/5] clk: add of_clk_init and CLK_OF_DECLARE macro Sebastian Hesselbarth
@ 2013-11-09 13:24 ` Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 5/5] clk: fixed: add DT init function Sebastian Hesselbarth
2013-11-11 8:30 ` [PATCH 0/5] OF: probe clock providers from DT Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sebastian Hesselbarth @ 2013-11-09 13:24 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This adds a call to of_clk_init right after platform devices have been
populated.
Signed-off-by: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
---
Cc: barebox@lists.infradead.org
---
drivers/of/base.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/of/base.c b/drivers/of/base.c
index ba929bc..ea2d879 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1734,6 +1734,7 @@ int of_probe(void)
of_add_memory(memory, false);
of_platform_populate(root_node, of_default_bus_match_table, NULL);
+ of_clk_init(root_node, NULL);
return 0;
}
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 5/5] clk: fixed: add DT init function
2013-11-09 13:24 [PATCH 0/5] OF: probe clock providers from DT Sebastian Hesselbarth
` (3 preceding siblings ...)
2013-11-09 13:24 ` [PATCH 4/5] OF: parse OF clock providers after populate Sebastian Hesselbarth
@ 2013-11-09 13:24 ` Sebastian Hesselbarth
2013-11-11 8:30 ` [PATCH 0/5] OF: probe clock providers from DT Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sebastian Hesselbarth @ 2013-11-09 13:24 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
This adds a DT init function to clk-fixed and corresponding CLK_OF_DECLARE
to put it into the DT clock provider table.
---
Cc: barebox@lists.infradead.org
---
drivers/clk/clk-fixed.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/drivers/clk/clk-fixed.c b/drivers/clk/clk-fixed.c
index e5d36b4..3a38865 100644
--- a/drivers/clk/clk-fixed.c
+++ b/drivers/clk/clk-fixed.c
@@ -54,3 +54,26 @@ struct clk *clk_fixed(const char *name, int rate)
return &fix->clk;
}
+
+#if defined(CONFIG_OFTREE) && defined(CONFIG_COMMON_CLK_OF_PROVIDER)
+/**
+ * of_fixed_clk_setup() - Setup function for simple fixed rate clock
+ */
+static int of_fixed_clk_setup(struct device_node *node)
+{
+ struct clk *clk;
+ const char *clk_name = node->name;
+ u32 rate;
+
+ if (of_property_read_u32(node, "clock-frequency", &rate))
+ return -EINVAL;
+
+ of_property_read_string(node, "clock-output-names", &clk_name);
+
+ clk = clk_fixed(clk_name, rate);
+ if (IS_ERR(clk))
+ return IS_ERR(clk);
+ return of_clk_add_provider(node, of_clk_src_simple_get, clk);
+}
+CLK_OF_DECLARE(fixed_clk, "fixed-clock", of_fixed_clk_setup);
+#endif
--
1.8.4.rc3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 0/5] OF: probe clock providers from DT
2013-11-09 13:24 [PATCH 0/5] OF: probe clock providers from DT Sebastian Hesselbarth
` (4 preceding siblings ...)
2013-11-09 13:24 ` [PATCH 5/5] clk: fixed: add DT init function Sebastian Hesselbarth
@ 2013-11-11 8:30 ` Sascha Hauer
5 siblings, 0 replies; 7+ messages in thread
From: Sascha Hauer @ 2013-11-11 8:30 UTC (permalink / raw)
To: Sebastian Hesselbarth; +Cc: barebox
Hi Sebastian,
On Sat, Nov 09, 2013 at 02:24:16PM +0100, Sebastian Hesselbarth wrote:
> This patch set brings automatic probing of DT clock providers to ARM
> barebox, similar to what we have in Linux kernel.
>
> First, a new macro BAREBOX_CLK_TABLE for generic linker scripts is added,
> that will take all declared DT clock providers. That macro is then added
> to the ARM linker script.
>
> Then, barebox compatible versions of of_clk_init and CLK_OF_DECLARE are
> added, that allow to parse and probe declared clock providers. The of_clk_init
> call is then put right after of_platform_populate in of_probe.
>
> Finally, clk/fixed is declared as such a clock provider and can now be probed
> automatially for DT enabled ARM platforms.
>
> Sebastian Hesselbarth (5):
> asm-generic: add macro for BAREBOX_CLK_TABLE
> ARM: lib: add BAREBOX_CLK_TABLE to linker script
> clk: add of_clk_init and CLK_OF_DECLARE macro
> OF: parse OF clock providers after populate
> clk: fixed: add DT init function
I gave this a test on i.MX by adding an additional dummy clk to my dts
and it works as expected. Patches look good, so:
Applied, thanks
Sascha
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2013-11-11 8:30 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-09 13:24 [PATCH 0/5] OF: probe clock providers from DT Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 1/5] asm-generic: add macro for BAREBOX_CLK_TABLE Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 2/5] ARM: lib: add BAREBOX_CLK_TABLE to linker script Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 3/5] clk: add of_clk_init and CLK_OF_DECLARE macro Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 4/5] OF: parse OF clock providers after populate Sebastian Hesselbarth
2013-11-09 13:24 ` [PATCH 5/5] clk: fixed: add DT init function Sebastian Hesselbarth
2013-11-11 8:30 ` [PATCH 0/5] OF: probe clock providers from DT Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox