From patchwork Fri Jan 17 19:51:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Anderson X-Patchwork-Id: 239744 List-Id: U-Boot discussion From: seanga2 at gmail.com (Sean Anderson) Date: Fri, 17 Jan 2020 14:51:51 -0500 Subject: [PATCH] riscv: Try to get cpu frequency from device tree Message-ID: Instead of always using the "clock-frequency" property to determine cpu frequency, try using a clock in "clocks" if it exists. Signed-off-by Sean Anderson Reviewed-by: Lukas Auer --- This patch depends on . drivers/cpu/riscv_cpu.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/drivers/cpu/riscv_cpu.c b/drivers/cpu/riscv_cpu.c index 1e32bb5678..280c9de376 100644 --- a/drivers/cpu/riscv_cpu.c +++ b/drivers/cpu/riscv_cpu.c @@ -3,6 +3,7 @@ * Copyright (C) 2018, Bin Meng */ +#include #include #include #include @@ -27,11 +28,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 err; + struct clk clk; const char *mmu; /* Zero out the frequency, in case sizeof(ulong) != sizeof(u32) */ info->cpu_freq = 0; - dev_read_u32(dev, "clock-frequency", (u32 *)&info->cpu_freq); + + /* First try getting the frequency from the assigned clock */ + err = clk_get_by_index(dev, 0, &clk); + if (!err) { + err = clk_get_rate(&clk); + if (!IS_ERR_VALUE(err)) + info->cpu_freq = err; + 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)