summaryrefslogtreecommitdiffstats
path: root/drivers/cpu/riscv_cpu.c
diff options
context:
space:
mode:
authorSean Anderson <seanga2@gmail.com>2020-06-24 06:41:21 -0400
committerAndes <uboot@andestech.com>2020-07-01 15:01:22 +0800
commitab24017a19b482d9026d21a2ec03416c5c4a388d (patch)
tree184985446d435f4d6a54275dc635b87d25d55106 /drivers/cpu/riscv_cpu.c
parent958a3f464c7f8ef7e10db9feb663e9e80445ce2f (diff)
downloadu-boot-ab24017a19b482d9026d21a2ec03416c5c4a388d.tar.gz
u-boot-ab24017a19b482d9026d21a2ec03416c5c4a388d.tar.xz
u-boot-ab24017a19b482d9026d21a2ec03416c5c4a388d.zip
riscv: Try to get cpu frequency from a "clocks" node if it exists
Instead of always using the "clock-frequency" property to determine cpu frequency, try using a clock in "clocks" if it exists. This patch also fixes a bug where there could be spurious higher frequencies if sizeof(u32) != sizeof(ulong). Signed-off-by: Sean Anderson <seanga2@gmail.com> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'drivers/cpu/riscv_cpu.c')
-rw-r--r--drivers/cpu/riscv_cpu.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/drivers/cpu/riscv_cpu.c b/drivers/cpu/riscv_cpu.c
index cb04f5638d..2d44d1c17b 100644
--- a/drivers/cpu/riscv_cpu.c
+++ b/drivers/cpu/riscv_cpu.c
@@ -3,6 +3,7 @@
* Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
*/
+#include <clk.h>
#include <common.h>
#include <cpu.h>
#include <dm.h>
@@ -11,6 +12,7 @@
#include <dm/device-internal.h>
#include <dm/lists.h>
#include <linux/bitops.h>
+#include <linux/err.h>
DECLARE_GLOBAL_DATA_PTR;
@@ -29,9 +31,24 @@ static int riscv_cpu_get_desc(struct udevice *dev, char *buf, int size)
static int riscv_cpu_get_info(struct udevice *dev, struct cpu_info *info)
{
+ int ret;
+ struct clk clk;
const char *mmu;
- dev_read_u32(dev, "clock-frequency", (u32 *)&info->cpu_freq);
+ /* Zero out the frequency, in case sizeof(ulong) != sizeof(u32) */
+ info->cpu_freq = 0;
+
+ /* First try getting the frequency from the assigned clock */
+ ret = clk_get_by_index(dev, 0, &clk);
+ if (!ret) {
+ ret = clk_get_rate(&clk);
+ if (!IS_ERR_VALUE(ret))
+ info->cpu_freq = ret;
+ clk_free(&clk);
+ }
+
+ if (!info->cpu_freq)
+ dev_read_u32(dev, "clock-frequency", (u32 *)&info->cpu_freq);
mmu = dev_read_string(dev, "mmu-type");
if (!mmu)