Merge branch 'fixes' of git://git.linaro.org/people/rmk/linux-arm
[firefly-linux-kernel-4.4.55.git] / arch / metag / kernel / clock.c
index defc84056f185e0deaef01dbdec1e8cecc599417..6339c9c6d0abebbd9ef355740bad27cd233512ee 100644 (file)
@@ -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,63 @@ 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();
+
+       pr_info("Core clock frequency: %lu Hz\n", get_coreclock());
+}
+
 /**
- * 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.