samples/bpf: add a test for bpf_override_return
[linux/fpc-iii.git] / drivers / clocksource / tango_xtal.c
blob3f94e454ef9995cd8440c4bb1ec79411bd768a08
1 // SPDX-License-Identifier: GPL-2.0
2 #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>
10 static void __iomem *xtal_in_cnt;
11 static struct delay_timer delay_timer;
13 static unsigned long notrace read_xtal_counter(void)
15 return readl_relaxed(xtal_in_cnt);
18 static u64 notrace read_sched_clock(void)
20 return read_xtal_counter();
23 static int __init tango_clocksource_init(struct device_node *np)
25 struct clk *clk;
26 int xtal_freq, ret;
28 xtal_in_cnt = of_iomap(np, 0);
29 if (xtal_in_cnt == NULL) {
30 pr_err("%pOF: invalid address\n", np);
31 return -ENXIO;
34 clk = of_clk_get(np, 0);
35 if (IS_ERR(clk)) {
36 pr_err("%pOF: invalid clock\n", np);
37 return PTR_ERR(clk);
40 xtal_freq = clk_get_rate(clk);
41 delay_timer.freq = xtal_freq;
42 delay_timer.read_current_timer = read_xtal_counter;
44 ret = clocksource_mmio_init(xtal_in_cnt, "tango-xtal", xtal_freq, 350,
45 32, clocksource_mmio_readl_up);
46 if (ret) {
47 pr_err("%pOF: registration failed\n", np);
48 return ret;
51 sched_clock_register(read_sched_clock, 32, xtal_freq);
52 register_current_timer_delay(&delay_timer);
54 return 0;
57 TIMER_OF_DECLARE(tango, "sigma,tick-counter", tango_clocksource_init);