]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
xtensa: xtfpga: use clock provider, don't update DT
authorMax Filippov <jcmvbkbc@gmail.com>
Mon, 25 Jul 2016 07:58:10 +0000 (10:58 +0300)
committerMax Filippov <jcmvbkbc@gmail.com>
Wed, 21 Sep 2016 01:52:51 +0000 (18:52 -0700)
Instead of querying hardcoded FPGA frequency register and then updating
clock-frequency property in specificly named DT nodes in machine setup
code register a clock provider that returns fixed-rate clock, configured
by register specified in DT. This way we have less magic/hardcoded names
and use more existing common clock framework code.

Signed-off-by: Max Filippov <jcmvbkbc@gmail.com>
Tested-by: Guenter Roeck <linux@roeck-us.net>
arch/xtensa/boot/dts/xtfpga.dtsi
arch/xtensa/platforms/xtfpga/setup.c

index cd45f9c2c4484225960dc63267230bb3c7f5a2eb..ded56984dd238e96d49b98920e7657f53461e29c 100644 (file)
        };
 
        clocks {
-               osc: main-oscillator {
-                       #clock-cells = <0>;
-                       compatible = "fixed-clock";
-               };
-
                clk54: clk54 {
                        #clock-cells = <0>;
                        compatible = "fixed-clock";
                compatible = "simple-bus";
                ranges = <0x00000000 0xf0000000 0x10000000>;
 
+               osc: main-oscillator {
+                       #clock-cells = <0>;
+                       compatible = "cdns,xtfpga-clock";
+                       reg = <0x0d020004 0x4>;
+               };
+
                serial0: serial@0d050020 {
                        device_type = "serial";
                        compatible = "ns16550a";
index f0b753f335d8c5ab12aa660edbd930a255e1073d..99a38a6febeaf43a3ae0aa242fff7488b3adb44d 100644 (file)
@@ -26,6 +26,8 @@
 #include <linux/console.h>
 #include <linux/delay.h>
 #include <linux/of.h>
+#include <linux/clk-provider.h>
+#include <linux/of_address.h>
 
 #include <asm/timex.h>
 #include <asm/processor.h>
@@ -87,6 +89,33 @@ static void __init update_clock_frequency(struct device_node *node)
        of_update_property(node, newfreq);
 }
 
+static void __init xtfpga_clk_setup(struct device_node *np)
+{
+       void __iomem *base = of_iomap(np, 0);
+       struct clk *clk;
+       u32 freq;
+
+       if (!base) {
+               pr_err("%s: invalid address\n", np->name);
+               return;
+       }
+
+       freq = __raw_readl(base);
+       iounmap(base);
+       clk = clk_register_fixed_rate(NULL, np->name, NULL, 0, freq);
+
+       if (IS_ERR(clk)) {
+               pr_err("%s: clk registration failed\n", np->name);
+               return;
+       }
+
+       if (of_clk_add_provider(np, of_clk_src_simple_get, clk)) {
+               pr_err("%s: clk provider registration failed\n", np->name);
+               return;
+       }
+}
+CLK_OF_DECLARE(xtfpga_clk, "cdns,xtfpga-clock", xtfpga_clk_setup);
+
 #define MAC_LEN 6
 static void __init update_local_mac(struct device_node *node)
 {
@@ -117,12 +146,8 @@ static void __init update_local_mac(struct device_node *node)
 
 static int __init machine_setup(void)
 {
-       struct device_node *clock;
        struct device_node *eth = NULL;
 
-       for_each_node_by_name(clock, "main-oscillator")
-               update_clock_frequency(clock);
-
        if ((eth = of_find_compatible_node(eth, NULL, "opencores,ethoc")))
                update_local_mac(eth);
        return 0;