summaryrefslogtreecommitdiffstats
path: root/arch/metag/kernel/clock.c
diff options
context:
space:
mode:
authorJames Hogan <james.hogan@imgtec.com>2013-01-15 15:27:45 +0000
committerJames Hogan <james.hogan@imgtec.com>2013-06-13 12:54:41 +0100
commitcaa279dda4d9a442d824cd333e8b72078b83e855 (patch)
tree609d39ecdf728bc759ab4a3e8775475b1e4636b7 /arch/metag/kernel/clock.c
parentc24d2976c7834aa948f9d8a48ad4285cfbaf1c3a (diff)
downloadop-kernel-dev-caa279dda4d9a442d824cd333e8b72078b83e855.zip
op-kernel-dev-caa279dda4d9a442d824cd333e8b72078b83e855.tar.gz
metag: init common clk and use "core" clk
If the common clock framework is enabled, call of_clk_init(NULL) in time_init() to register device tree clocks with the clock framework. After this time_init() calls a new function init_metag_clocks(), which looks for a clock named "core" in the node compatible with "img,meta" (usually the root node). If found the get_core_freq machine callback is overridden to obtain the core clock frequency using that clock. Signed-off-by: James Hogan <james.hogan@imgtec.com> Cc: Mike Turquette <mturquette@linaro.org> Cc: Grant Likely <grant.likely@linaro.org> Cc: Rob Herring <rob.herring@calxeda.com> Cc: devicetree-discuss@lists.ozlabs.org
Diffstat (limited to 'arch/metag/kernel/clock.c')
-rw-r--r--arch/metag/kernel/clock.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/arch/metag/kernel/clock.c b/arch/metag/kernel/clock.c
index defc840..8bfd6a5 100644
--- a/arch/metag/kernel/clock.c
+++ b/arch/metag/kernel/clock.c
@@ -8,8 +8,10 @@
* published by the Free Software Foundation.
*/
+#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/io.h>
+#include <linux/of.h>
#include <asm/param.h>
#include <asm/clock.h>
@@ -34,8 +36,61 @@ static unsigned long get_core_freq_default(void)
#endif
}
+static struct clk *clk_core;
+
+/* Clk based get_core_freq callback. */
+static unsigned long get_core_freq_clk(void)
+{
+ return clk_get_rate(clk_core);
+}
+
+/**
+ * init_metag_core_clock() - Set up core clock from devicetree.
+ *
+ * Checks to see if a "core" clock is provided in the device tree, and overrides
+ * the get_core_freq callback to use it.
+ */
+static void __init init_metag_core_clock(void)
+{
+ /*
+ * See if a core clock is provided by the devicetree (and
+ * registered by the init callback above).
+ */
+ struct device_node *node;
+ node = of_find_compatible_node(NULL, NULL, "img,meta");
+ if (!node) {
+ pr_warn("%s: no compatible img,meta DT node found\n",
+ __func__);
+ return;
+ }
+
+ clk_core = of_clk_get_by_name(node, "core");
+ if (IS_ERR(clk_core)) {
+ pr_warn("%s: no core clock found in DT\n",
+ __func__);
+ return;
+ }
+
+ /*
+ * Override the core frequency callback to use
+ * this clk.
+ */
+ _meta_clock.get_core_freq = get_core_freq_clk;
+}
+
+/**
+ * init_metag_clocks() - Set up clocks from devicetree.
+ *
+ * Set up important clocks from device tree. In particular any needed for clock
+ * sources.
+ */
+void __init init_metag_clocks(void)
+{
+ init_metag_core_clock();
+}
+
/**
- * setup_meta_clocks() - Set up the Meta clock.
+ * setup_meta_clocks() - Early set up of the Meta clock.
* @desc: Clock descriptor usually provided by machine description
*
* Ensures all callbacks are valid.
OpenPOWER on IntegriCloud