mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [PATCH 2/2] MIPS: csrc-r4k: get cp0 counter rate from devicetree
Date: Wed,  6 Jul 2016 23:38:26 +0300	[thread overview]
Message-ID: <1467837506-32177-3-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1467837506-32177-1-git-send-email-antonynpavlov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
---
 arch/mips/lib/csrc-r4k.c | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/arch/mips/lib/csrc-r4k.c b/arch/mips/lib/csrc-r4k.c
index 5c3f18f..6f6e18c 100644
--- a/arch/mips/lib/csrc-r4k.c
+++ b/arch/mips/lib/csrc-r4k.c
@@ -21,6 +21,8 @@
  */
 
 #include <init.h>
+#include <of.h>
+#include <linux/clk.h>
 #include <clock.h>
 #include <io.h>
 #include <asm/mipsregs.h>
@@ -37,8 +39,26 @@ static struct clocksource cs = {
 
 static int clocksource_init(void)
 {
-	cs.mult = clocksource_hz2mult(100000000, cs.shift);
+	unsigned int mips_hpt_frequency;
+	struct device_node *np;
+	struct clk *clk;
+
+	/* default rate: 100 MHz */
+	mips_hpt_frequency = 100000000;
+
+	if (IS_ENABLED(CONFIG_OFTREE)) {
+		np = of_get_cpu_node(0, NULL);
+		if (np) {
+			clk = of_clk_get(np, 0);
+			if (!IS_ERR(clk)) {
+				mips_hpt_frequency = clk_get_rate(clk) / 2;
+			}
+		}
+	}
+
+	clocks_calc_mult_shift(&cs.mult, &cs.shift,
+		mips_hpt_frequency, NSEC_PER_SEC, 10);
 
 	return init_clock(&cs);
 }
-core_initcall(clocksource_init);
+postcore_initcall(clocksource_init);
-- 
2.8.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2016-07-06 20:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-06 20:38 [PATCH 0/2] MIPS: csrc-r4k: get " Antony Pavlov
2016-07-06 20:38 ` [PATCH 1/2] of: base: import of_get_cpu_node() from linux-v4.7-rc2 Antony Pavlov
2016-07-06 20:38 ` Antony Pavlov [this message]
2016-07-07  7:30 ` [PATCH 0/2] MIPS: csrc-r4k: get counter rate from devicetree Sascha Hauer

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=1467837506-32177-3-git-send-email-antonynpavlov@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /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