diff options
author | Antony Pavlov <antonynpavlov@gmail.com> | 2016-07-06 23:38:26 +0300 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2016-07-07 09:29:54 +0200 |
commit | ad30a80ddb1bc2e7090768e575bb97f9f7be1255 (patch) | |
tree | a52920cf353cf4177f3b7a05ca13e234f0195719 /arch | |
parent | adce981d2449004dfcea432d48a1a57556f0c994 (diff) | |
download | barebox-ad30a80ddb1bc2e7090768e575bb97f9f7be1255.tar.gz barebox-ad30a80ddb1bc2e7090768e575bb97f9f7be1255.tar.xz |
MIPS: csrc-r4k: get cp0 counter rate from devicetree
Signed-off-by: Antony Pavlov <antonynpavlov@gmail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch')
-rw-r--r-- | arch/mips/lib/csrc-r4k.c | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/arch/mips/lib/csrc-r4k.c b/arch/mips/lib/csrc-r4k.c index 5c3f18ff24..6f6e18c8e8 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); |