realtek: use fixed-clock as CPU clock patch/realtek-cpu-clock-dts
authorSander Vanheule <sander@svanheule.net>
Fri, 26 Nov 2021 21:54:04 +0000 (22:54 +0100)
committerSander Vanheule <sander@svanheule.net>
Tue, 7 Jun 2022 19:03:55 +0000 (21:03 +0200)
CPU clock definition in devicetree should be specified per CPU, not in
the cpus node.

The implementation of plat_init_time() needs to be modified to look for
the clock frequency in the changed location. To achieve this, the
relevant code is copied from the generic MIPS implementation in
arch/mips/generic/init.c.

Signed-off-by: Sander Vanheule <sander@svanheule.net>
target/linux/realtek/dts-5.10/rtl838x.dtsi
target/linux/realtek/dts-5.10/rtl930x.dtsi
target/linux/realtek/dts-5.10/rtl931x.dtsi
target/linux/realtek/files-5.10/arch/mips/rtl838x/setup.c

index 11cabc3f63cb7c8c0a61fcb8b0c5587f09ae33b6..aa6c131753dbce2703bb6e09b038025e56cb6541 100644 (file)
        cpus {
                #address-cells = <1>;
                #size-cells = <0>;
-               frequency = <500000000>;
 
                cpu@0 {
                        compatible = "mips,mips4KEc";
                        reg = <0>;
+                       clocks = <&cpu_clk>;
+                       clock-names = "cpu";
                };
        };
 
                bootargs = "console=ttyS0,115200";
        };
 
+       cpu_clk: cpu_clk {
+               compatible = "fixed-clock";
+               #clock-cells = <0>;
+               clock-frequency = <500000000>;
+       };
+
        lx_clk: lx_clk {
                compatible = "fixed-clock";
                #clock-cells = <0>;
index bfde5e6ff6ae82d55f67ee82de762ed8d88eb42f..74c7181c96e20d7fc53c0d374af642e2365c6784 100644 (file)
        cpus {
                #address-cells = <1>;
                #size-cells = <0>;
-               frequency = <800000000>;
 
                cpu@0 {
                        compatible = "mips,mips34Kc";
                        reg = <0>;
+                       clocks = <&cpu_clk>;
+                       clock-names = "cpu";
                };
        };
 
                interrupt-controller;
        };
 
+       cpu_clk: cpu_clk {
+               compatible = "fixed-clock";
+               #clock-cells = <0>;
+               clock-frequency  = <800000000>;
+       };
+
        lx_clk: lx_clk {
                compatible = "fixed-clock";
                #clock-cells = <0>;
index 29aee1f7b268f156eab3a38ffa8b1fa7a77f8679..f6f39222fde88e7426faac9785ac8b788d05e183 100644 (file)
        cpus {
                #address-cells = <1>;
                #size-cells = <0>;
-               frequency = <1000000000>;
 
                cpu@0 {
                        compatible = "mti,interaptive";
                        reg = <0>;
+                       clocks = <&cpuclock>;
+                       clock-names = "cpu";
                };
 
                cpu@1 {
                        compatible = "mti,interaptive";
                        reg = <1>;
+                       clocks = <&cpuclock>;
+                       clock-names = "cpu";
                };
        };
 
index 55419c7b0b7afe89dbc3d2d039eec9def9ae86a9..86eb3c5eeaf547617fc15260073f9e4d33690021 100644 (file)
@@ -11,9 +11,9 @@
 
 #include <linux/console.h>
 #include <linux/init.h>
-#include <linux/clkdev.h>
-#include <linux/clk-provider.h>
+#include <linux/clk.h>
 #include <linux/delay.h>
+#include <linux/of_clk.h>
 #include <linux/of_fdt.h>
 #include <linux/irqchip.h>
 
@@ -91,23 +91,29 @@ void __init plat_mem_setup(void)
 void __init plat_time_init(void)
 {
        struct device_node *np;
-       u32 freq = 500000000;
+       struct clk *clk;
 
        of_clk_init(NULL);
-       timer_probe();
 
-       np = of_find_node_by_name(NULL, "cpus");
+       np = of_get_cpu_node(0, NULL);
        if (!np) {
-               pr_err("Missing 'cpus' DT node, using default frequency.");
-       } else {
-               if (of_property_read_u32(np, "frequency", &freq) < 0)
-                       pr_err("No 'frequency' property in DT, using default.");
-               else
-                       pr_info("CPU frequency from device tree: %dMHz", freq / 1000000);
-               of_node_put(np);
+               pr_err("Failed to get CPU node\n");
+               return;
+       }
+
+       clk = of_clk_get(np, 0);
+       if (IS_ERR(clk)) {
+               pr_err("Failed to get CPU clock: %ld\n", PTR_ERR(clk));
+               return;
        }
 
-       mips_hpt_frequency = freq / 2;
+       mips_hpt_frequency = clk_get_rate(clk);
+       clk_put(clk);
+
+       /* The counter runs at half the CPU clock rate */
+       mips_hpt_frequency /= 2;
+
+       timer_probe();
 }
 
 void __init arch_init_irq(void)