From: Binbin Zhou <zhoubinbin@loongson.cn>
To: Binbin Zhou <zhoubb.aaron@gmail.com>,
Huacai Chen <chenhuacai@loongson.cn>,
Rob Herring <robh+dt@kernel.org>,
Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
Conor Dooley <conor+dt@kernel.org>,
devicetree@vger.kernel.org
Cc: Huacai Chen <chenhuacai@kernel.org>,
loongson-kernel@lists.loongnix.cn,
Xuerui Wang <kernel@xen0n.name>,
loongarch@lists.linux.dev, Jiaxun Yang <jiaxun.yang@flygoat.com>,
Hongliang Wang <wanghongliang@loongson.cn>,
Binbin Zhou <zhoubinbin@loongson.cn>
Subject: [PATCH v2 7/7] LoongArch: Parsing CPU-related information from DTS
Date: Tue, 15 Aug 2023 16:51:13 +0800 [thread overview]
Message-ID: <44e4a47851575bc9ae583cf8c6d2f63ef05b10bd.1692088166.git.zhoubinbin@loongson.cn> (raw)
In-Reply-To: <cover.1692088166.git.zhoubinbin@loongson.cn>
Generally, we can get cpu-related information, such as model name, from
/proc/cpuinfo. for DT-based systems, we need to parse the relevant
information from DTS.
Signed-off-by: Binbin Zhou <zhoubinbin@loongson.cn>
Signed-off-by: Hongliang Wang <wanghongliang@loongson.cn>
---
arch/loongarch/kernel/env.c | 33 +++++++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/arch/loongarch/kernel/env.c b/arch/loongarch/kernel/env.c
index 6b3bfb0092e6..0191fe20b535 100644
--- a/arch/loongarch/kernel/env.c
+++ b/arch/loongarch/kernel/env.c
@@ -5,13 +5,16 @@
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
*/
#include <linux/acpi.h>
+#include <linux/clk.h>
#include <linux/efi.h>
#include <linux/export.h>
#include <linux/memblock.h>
+#include <linux/of_clk.h>
#include <asm/early_ioremap.h>
#include <asm/bootinfo.h>
#include <asm/loongson.h>
#include <asm/setup.h>
+#include <asm/time.h>
u64 efi_system_table;
struct loongson_system_configuration loongson_sysconf;
@@ -34,9 +37,39 @@ void __init init_environ(void)
efi_system_table = fw_arg2;
}
+static int __init fdt_cpu_clk_init(void)
+{
+ struct clk *clk;
+ struct device_node *np;
+
+ np = of_get_cpu_node(0, NULL);
+ if (!np)
+ return -ENODEV;
+
+ clk = of_clk_get(np, 0);
+ if (IS_ERR(clk))
+ return -ENODEV;
+
+ cpu_clock_freq = clk_get_rate(clk);
+ clk_put(clk);
+
+ return 0;
+}
+late_initcall(fdt_cpu_clk_init);
+
static int __init init_cpu_fullname(void)
{
int cpu;
+ char *prop;
+ struct device_node *root;
+
+ /* Parsing cpuname from DTS model property */
+ root = of_find_node_by_path("/");
+ if (root) {
+ of_property_read_string(root, "model", (const char **)&prop);
+ if (prop)
+ loongson_sysconf.cpuname = strsep(&prop, " ");
+ }
if (loongson_sysconf.cpuname && !strncmp(loongson_sysconf.cpuname, "Loongson", 8)) {
for (cpu = 0; cpu < NR_CPUS; cpu++)
--
2.39.3
prev parent reply other threads:[~2023-08-15 8:52 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-15 8:50 [PATCH v2 0/7] LoongArch: Add built-in dtb support Binbin Zhou
2023-08-15 8:50 ` [PATCH v2 1/7] dt-bindings: loongarch: Add CPU bindings for LoongArch Binbin Zhou
2023-08-15 14:07 ` Conor Dooley
2023-08-16 6:37 ` Binbin Zhou
2023-08-16 6:50 ` Conor Dooley
2023-08-15 8:50 ` [PATCH v2 2/7] dt-bindings: loongarch: Add Loongson SoC boards compatibles Binbin Zhou
2023-08-15 14:13 ` Conor Dooley
2023-08-17 6:16 ` Binbin Zhou
2023-08-17 8:44 ` Conor Dooley
2023-08-17 8:46 ` Conor Dooley
2023-08-15 14:49 ` Krzysztof Kozlowski
2023-08-17 6:24 ` Binbin Zhou
2023-08-15 8:50 ` [PATCH v2 3/7] LoongArch: Allow device trees to be built into the kernel Binbin Zhou
2023-08-15 8:51 ` [PATCH v2 4/7] LoongArch: dts: DeviceTree for Loongson-2K0500 Binbin Zhou
2023-08-15 14:09 ` Conor Dooley
2023-08-17 3:15 ` Binbin Zhou
2023-08-15 14:48 ` Krzysztof Kozlowski
2023-08-17 5:36 ` Binbin Zhou
2023-08-15 8:51 ` [PATCH v2 5/7] LoongArch: dts: DeviceTree for Loongson-2K1000 Binbin Zhou
2023-08-15 14:56 ` Krzysztof Kozlowski
2023-08-17 6:41 ` Binbin Zhou
2023-08-15 8:51 ` [PATCH v2 6/7] LoongArch: dts: DeviceTree for Loongson-2K2000 Binbin Zhou
2023-08-15 8:51 ` Binbin Zhou [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44e4a47851575bc9ae583cf8c6d2f63ef05b10bd.1692088166.git.zhoubinbin@loongson.cn \
--to=zhoubinbin@loongson.cn \
--cc=chenhuacai@kernel.org \
--cc=chenhuacai@loongson.cn \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=jiaxun.yang@flygoat.com \
--cc=kernel@xen0n.name \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=loongarch@lists.linux.dev \
--cc=loongson-kernel@lists.loongnix.cn \
--cc=robh+dt@kernel.org \
--cc=wanghongliang@loongson.cn \
--cc=zhoubb.aaron@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).