1 #include <linux/clocksource.h>
2 #include <linux/sched_clock.h>
3 #include <linux/of_address.h>
4 #include <linux/printk.h>
5 #include <linux/delay.h>
6 #include <linux/init.h>
9 static void __iomem
*xtal_in_cnt
;
10 static struct delay_timer delay_timer
;
12 static unsigned long notrace
read_xtal_counter(void)
14 return readl_relaxed(xtal_in_cnt
);
17 static u64 notrace
read_sched_clock(void)
19 return read_xtal_counter();
22 static cycle_t
read_clocksource(struct clocksource
*cs
)
24 return read_xtal_counter();
27 static struct clocksource tango_xtal
= {
30 .read
= read_clocksource
,
31 .mask
= CLOCKSOURCE_MASK(32),
32 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
35 static void __init
tango_clocksource_init(struct device_node
*np
)
40 xtal_in_cnt
= of_iomap(np
, 0);
41 if (xtal_in_cnt
== NULL
) {
42 pr_err("%s: invalid address\n", np
->full_name
);
46 clk
= of_clk_get(np
, 0);
48 pr_err("%s: invalid clock\n", np
->full_name
);
52 xtal_freq
= clk_get_rate(clk
);
53 delay_timer
.freq
= xtal_freq
;
54 delay_timer
.read_current_timer
= read_xtal_counter
;
56 ret
= clocksource_register_hz(&tango_xtal
, xtal_freq
);
58 pr_err("%s: registration failed\n", np
->full_name
);
62 sched_clock_register(read_sched_clock
, 32, xtal_freq
);
63 register_current_timer_delay(&delay_timer
);
66 CLOCKSOURCE_OF_DECLARE(tango
, "sigma,tick-counter", tango_clocksource_init
);