public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Sean Anderson <seanga2@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v8 17/21] riscv: Try to get cpu frequency from a "clocks" node if it exists
Date: Fri, 10 Apr 2020 08:28:10 -0400	[thread overview]
Message-ID: <20200410122814.423237-18-seanga2@gmail.com> (raw)
In-Reply-To: <20200410122814.423237-1-seanga2@gmail.com>

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>
---
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 <bmeng.cn@gmail.com>
  */
 
+#include <clk.h>
 #include <common.h>
 #include <cpu.h>
 #include <dm.h>
 #include <errno.h>
 #include <dm/device-internal.h>
 #include <dm/lists.h>
+#include <linux/err.h>
 
 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

  parent reply	other threads:[~2020-04-10 12:28 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-10 12:27 [PATCH v8 00/21] riscv: Add Sipeed Maix support Sean Anderson
2020-04-10 12:27 ` [PATCH v8 01/21] clk: Always use the supplied struct clk Sean Anderson
2020-04-10 12:27 ` [PATCH v8 02/21] clk: Check that ops of composite clock components exist before calling Sean Anderson
2020-04-10 12:27 ` [PATCH v8 03/21] clk: Unconditionally recursively en-/dis-able clocks Sean Anderson
2020-04-10 12:27 ` [PATCH v8 04/21] clk: Fix clk_get_by_* handling of index Sean Anderson
2020-04-10 12:27 ` [PATCH v8 05/21] clk: Add K210 pll support Sean Anderson
2020-04-10 12:27 ` [PATCH v8 06/21] clk: Add a bypass clock for K210 Sean Anderson
2020-04-10 12:28 ` [PATCH v8 07/21] clk: Add K210 clock support Sean Anderson
2020-04-10 12:28 ` [PATCH v8 08/21] dm: Add support for simple-pm-bus Sean Anderson
2020-04-10 12:28 ` [PATCH v8 09/21] dm: Fix error handling for dev_read_addr_ptr Sean Anderson
2020-04-10 12:28 ` [PATCH v8 10/21] reset: Add generic reset driver Sean Anderson
2020-04-10 12:28 ` [PATCH v8 11/21] lib: Always set errno in hcreate_r Sean Anderson
2020-04-10 12:28 ` [PATCH v8 12/21] riscv: Add headers for asm/global_data.h Sean Anderson
2020-04-10 12:28 ` [PATCH v8 13/21] riscv: Clear pending interrupts before enabling IPIs Sean Anderson
2020-04-10 12:28 ` [PATCH v8 14/21] riscv: Clean up IPI initialization code Sean Anderson
2020-04-10 12:28 ` [PATCH v8 15/21] riscv: Add option to support RISC-V privileged spec 1.9 Sean Anderson
2020-04-10 12:28 ` [PATCH v8 16/21] riscv: Allow use of reset drivers Sean Anderson
2020-04-10 12:28 ` Sean Anderson [this message]
2020-04-10 12:28 ` [PATCH v8 18/21] riscv: Enable cpu clock if it is present Sean Anderson
2020-04-10 12:28 ` [PATCH v8 19/21] riscv: Add device tree for K210 and Sipeed Maix BitM Sean Anderson
2020-04-10 12:28 ` [PATCH v8 20/21] doc: riscv: Add documentation for Sipeed Maix Bit Sean Anderson
2020-04-10 12:28 ` [PATCH v8 21/21] riscv: Add Sipeed Maix support Sean Anderson
2020-04-22  5:59 ` [PATCH v8 00/21] " Rick Chen
2020-04-23  1:51   ` Rick Chen
2020-04-23  2:03     ` Sean Anderson
2020-04-23  2:10       ` Bin Meng
2020-04-23  2:12         ` Sean Anderson
2020-04-23  2:28           ` Sean Anderson
2020-04-23  2:52       ` Rick Chen
2020-04-23  8:47         ` Rick Chen
2020-04-23  2:03     ` Sean Anderson
2020-04-23 12:21       ` Tom Rini
2020-04-24  8:26         ` Rick Chen

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=20200410122814.423237-18-seanga2@gmail.com \
    --to=seanga2@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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