blob: 3f94e454ef9995cd8440c4bb1ec79411bd768a08 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Marc Gonzalezccd63ce2015-10-09 16:59:18 +02002#include <linux/clocksource.h>
3#include <linux/sched_clock.h>
4#include <linux/of_address.h>
5#include <linux/printk.h>
6#include <linux/delay.h>
7#include <linux/init.h>
8#include <linux/clk.h>
9
10static void __iomem *xtal_in_cnt;
11static struct delay_timer delay_timer;
12
13static unsigned long notrace read_xtal_counter(void)
14{
15 return readl_relaxed(xtal_in_cnt);
16}
17
18static u64 notrace read_sched_clock(void)
19{
20 return read_xtal_counter();
21}
22
Daniel Lezcano0683d502016-06-06 17:59:24 +020023static int __init tango_clocksource_init(struct device_node *np)
Marc Gonzalezccd63ce2015-10-09 16:59:18 +020024{
25 struct clk *clk;
26 int xtal_freq, ret;
27
28 xtal_in_cnt = of_iomap(np, 0);
29 if (xtal_in_cnt == NULL) {
Rob Herring469869d2017-07-18 16:42:53 -050030 pr_err("%pOF: invalid address\n", np);
Daniel Lezcano0683d502016-06-06 17:59:24 +020031 return -ENXIO;
Marc Gonzalezccd63ce2015-10-09 16:59:18 +020032 }
33
34 clk = of_clk_get(np, 0);
35 if (IS_ERR(clk)) {
Rob Herring469869d2017-07-18 16:42:53 -050036 pr_err("%pOF: invalid clock\n", np);
Daniel Lezcano0683d502016-06-06 17:59:24 +020037 return PTR_ERR(clk);
Marc Gonzalezccd63ce2015-10-09 16:59:18 +020038 }
39
40 xtal_freq = clk_get_rate(clk);
41 delay_timer.freq = xtal_freq;
42 delay_timer.read_current_timer = read_xtal_counter;
43
Daniel Lezcano08818412015-11-13 10:44:38 +010044 ret = clocksource_mmio_init(xtal_in_cnt, "tango-xtal", xtal_freq, 350,
45 32, clocksource_mmio_readl_up);
Daniel Lezcano16eeed72016-04-19 15:43:02 +020046 if (ret) {
Rob Herring469869d2017-07-18 16:42:53 -050047 pr_err("%pOF: registration failed\n", np);
Daniel Lezcano0683d502016-06-06 17:59:24 +020048 return ret;
Marc Gonzalezccd63ce2015-10-09 16:59:18 +020049 }
50
51 sched_clock_register(read_sched_clock, 32, xtal_freq);
52 register_current_timer_delay(&delay_timer);
Daniel Lezcano0683d502016-06-06 17:59:24 +020053
54 return 0;
Marc Gonzalezccd63ce2015-10-09 16:59:18 +020055}
56
Daniel Lezcano17273392017-05-26 16:56:11 +020057TIMER_OF_DECLARE(tango, "sigma,tick-counter", tango_clocksource_init);