[PATCH v1] soc:loongson:add model and clock-frequency attribute parse.

Hongliang Wang posted 1 patch 2 years, 8 months ago
arch/loongarch/kernel/smp.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
[PATCH v1] soc:loongson:add model and clock-frequency attribute parse.
Posted by Hongliang Wang 2 years, 8 months ago
From: wanghongliang <wanghongliang@loongson.cn>

This patch add the parse of model and clock-frequency attribute,
which come from the cpus device_node in device tree and show as
Model Name and CPU MHz in /proc/cpuinfo.

device tree:

cpus {
	...
	model = "Loongson-LS2K1000";

	cpu0: cpu@0 {
		...
		clock-frequency = <1000000000>;
	};
};

/proc/cpuinfo:

Model Name              : Loongson-LS2K1000
CPU MHz                 : 1000.00

Signed-off-by: wanghongliang <wanghongliang@loongson.cn>
---
 arch/loongarch/kernel/smp.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/arch/loongarch/kernel/smp.c b/arch/loongarch/kernel/smp.c
index ed167e244cda..8644fb9119ec 100644
--- a/arch/loongarch/kernel/smp.c
+++ b/arch/loongarch/kernel/smp.c
@@ -30,6 +30,7 @@
 #include <asm/processor.h>
 #include <asm/setup.h>
 #include <asm/time.h>
+#include <asm/bootinfo.h>
 
 int __cpu_number_map[NR_CPUS];   /* Map physical to logical */
 EXPORT_SYMBOL(__cpu_number_map);
@@ -186,6 +187,14 @@ static void __init fdt_smp_setup(void)
 #ifdef CONFIG_OF
 	unsigned int cpu, cpuid;
 	struct device_node *node = NULL;
+	const void *prop = NULL;
+
+	node = of_find_node_by_path("/cpus");
+	if (node) {
+		prop = of_get_property(node, "model", NULL);
+		if (prop)
+			loongson_sysconf.cpuname = (const char *)prop;
+	}
 
 	for_each_of_cpu_node(node) {
 		if (!of_device_is_available(node))
@@ -202,6 +211,10 @@ static void __init fdt_smp_setup(void)
 			cpu = cpumask_next_zero(-1, cpu_present_mask);
 		}
 
+		prop = of_get_property(node, "clock-frequency", NULL);
+		if (prop)
+			cpu_clock_freq = be32_to_cpup(prop);
+
 		num_processors++;
 		set_cpu_possible(cpu, true);
 		set_cpu_present(cpu, true);
-- 
2.31.1