From: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
To: Sebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Cc: barebox@lists.infradead.org
Subject: [PATCH 3/5] clk: add of_clk_init and CLK_OF_DECLARE macro
Date: Sat, 9 Nov 2013 14:24:19 +0100 [thread overview]
Message-ID: <1384003461-21039-4-git-send-email-sebastian.hesselbarth@gmail.com> (raw)
In-Reply-To: <1384003461-21039-1-git-send-email-sebastian.hesselbarth@gmail.com>
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
next prev parent reply other threads:[~2013-11-09 13:24 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1384003461-21039-4-git-send-email-sebastian.hesselbarth@gmail.com \
--to=sebastian.hesselbarth@gmail.com \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox