From mboxrd@z Thu Jan 1 00:00:00 1970 From: Sean Anderson Date: Wed, 22 Apr 2020 22:33:16 -0400 Subject: [PATCH v9 17/21] riscv: Try to get cpu frequency from a "clocks" node if it exists In-Reply-To: <20200423023320.1380090-1-seanga2@gmail.com> References: <20200423023320.1380090-1-seanga2@gmail.com> Message-ID: <20200423023320.1380090-18-seanga2@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 Reviewed-by: Bin Meng --- This patch was previously sumbitted on its own as https://patchwork.ozlabs.org/patch/1232420/ This patch is the combination of the patches https://patchwork.ozlabs.org/patch/1223933/ https://patchwork.ozlabs.org/patch/1224957/ "riscv: Fix incorrect cpu frequency on RV64" "riscv: Try to get cpu frequency from device tree" Changes in v5: - Include linux/err.h explicitly - Reword commit message Changes in v4: - New drivers/cpu/riscv_cpu.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/cpu/riscv_cpu.c b/drivers/cpu/riscv_cpu.c index 28ad0aa30f..c6ed060abc 100644 --- a/drivers/cpu/riscv_cpu.c +++ b/drivers/cpu/riscv_cpu.c @@ -3,12 +3,14 @@ * Copyright (C) 2018, Bin Meng */ +#include #include #include #include #include #include #include +#include DECLARE_GLOBAL_DATA_PTR; @@ -27,9 +29,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) -- 2.25.1