[PATCH v1] realtek: use fixed-clock as CPU clock
Sander Vanheule
sander at svanheule.net
Tue Jun 7 00:57:56 PDT 2022
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 at svanheule.net>
---
target/linux/realtek/dts-5.10/rtl838x.dtsi | 9 +++++-
target/linux/realtek/dts-5.10/rtl930x.dtsi | 9 +++++-
target/linux/realtek/dts-5.10/rtl931x.dtsi | 5 ++-
.../files-5.10/arch/mips/rtl838x/setup.c | 32 +++++++++++--------
4 files changed, 39 insertions(+), 16 deletions(-)
diff --git a/target/linux/realtek/dts-5.10/rtl838x.dtsi b/target/linux/realtek/dts-5.10/rtl838x.dtsi
index 11cabc3f63cb..aa6c131753db 100644
--- a/target/linux/realtek/dts-5.10/rtl838x.dtsi
+++ b/target/linux/realtek/dts-5.10/rtl838x.dtsi
@@ -56,11 +56,12 @@
cpus {
#address-cells = <1>;
#size-cells = <0>;
- frequency = <500000000>;
cpu at 0 {
compatible = "mips,mips4KEc";
reg = <0>;
+ clocks = <&cpu_clk>;
+ clock-names = "cpu";
};
};
@@ -68,6 +69,12 @@
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>;
diff --git a/target/linux/realtek/dts-5.10/rtl930x.dtsi b/target/linux/realtek/dts-5.10/rtl930x.dtsi
index bfde5e6ff6ae..74c7181c96e2 100644
--- a/target/linux/realtek/dts-5.10/rtl930x.dtsi
+++ b/target/linux/realtek/dts-5.10/rtl930x.dtsi
@@ -11,11 +11,12 @@
cpus {
#address-cells = <1>;
#size-cells = <0>;
- frequency = <800000000>;
cpu at 0 {
compatible = "mips,mips34Kc";
reg = <0>;
+ clocks = <&cpu_clk>;
+ clock-names = "cpu";
};
};
@@ -35,6 +36,12 @@
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>;
diff --git a/target/linux/realtek/dts-5.10/rtl931x.dtsi b/target/linux/realtek/dts-5.10/rtl931x.dtsi
index 29aee1f7b268..f6f39222fde8 100644
--- a/target/linux/realtek/dts-5.10/rtl931x.dtsi
+++ b/target/linux/realtek/dts-5.10/rtl931x.dtsi
@@ -11,16 +11,19 @@
cpus {
#address-cells = <1>;
#size-cells = <0>;
- frequency = <1000000000>;
cpu at 0 {
compatible = "mti,interaptive";
reg = <0>;
+ clocks = <&cpuclock>;
+ clock-names = "cpu";
};
cpu at 1 {
compatible = "mti,interaptive";
reg = <1>;
+ clocks = <&cpuclock>;
+ clock-names = "cpu";
};
};
diff --git a/target/linux/realtek/files-5.10/arch/mips/rtl838x/setup.c b/target/linux/realtek/files-5.10/arch/mips/rtl838x/setup.c
index 55419c7b0b7a..86eb3c5eeaf5 100644
--- a/target/linux/realtek/files-5.10/arch/mips/rtl838x/setup.c
+++ b/target/linux/realtek/files-5.10/arch/mips/rtl838x/setup.c
@@ -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)
--
2.36.1
More information about the openwrt-devel
mailing list