This source file includes following definitions.
- omap_32k_read_sched_clock
- omap_read_persistent_clock64
- omap_init_clocksource_32k
1
2
3
4
5
6
7
8
9
10
11
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14 #include <linux/clk.h>
15 #include <linux/err.h>
16 #include <linux/io.h>
17 #include <linux/clocksource.h>
18 #include <linux/sched_clock.h>
19
20 #include <asm/mach/time.h>
21
22 #include <plat/counter-32k.h>
23
24
25 #define OMAP2_32KSYNCNT_REV_OFF 0x0
26 #define OMAP2_32KSYNCNT_REV_SCHEME (0x3 << 30)
27 #define OMAP2_32KSYNCNT_CR_OFF_LOW 0x10
28 #define OMAP2_32KSYNCNT_CR_OFF_HIGH 0x30
29
30
31
32
33
34
35
36 static void __iomem *sync32k_cnt_reg;
37
38 static u64 notrace omap_32k_read_sched_clock(void)
39 {
40 return sync32k_cnt_reg ? readl_relaxed(sync32k_cnt_reg) : 0;
41 }
42
43
44
45
46
47
48
49
50 static struct timespec64 persistent_ts;
51 static cycles_t cycles;
52 static unsigned int persistent_mult, persistent_shift;
53
54 static void omap_read_persistent_clock64(struct timespec64 *ts)
55 {
56 unsigned long long nsecs;
57 cycles_t last_cycles;
58
59 last_cycles = cycles;
60 cycles = sync32k_cnt_reg ? readl_relaxed(sync32k_cnt_reg) : 0;
61
62 nsecs = clocksource_cyc2ns(cycles - last_cycles,
63 persistent_mult, persistent_shift);
64
65 timespec64_add_ns(&persistent_ts, nsecs);
66
67 *ts = persistent_ts;
68 }
69
70
71
72
73
74
75
76
77
78
79 int __init omap_init_clocksource_32k(void __iomem *vbase)
80 {
81 int ret;
82
83
84
85
86
87
88
89 if (readl_relaxed(vbase + OMAP2_32KSYNCNT_REV_OFF) &
90 OMAP2_32KSYNCNT_REV_SCHEME)
91 sync32k_cnt_reg = vbase + OMAP2_32KSYNCNT_CR_OFF_HIGH;
92 else
93 sync32k_cnt_reg = vbase + OMAP2_32KSYNCNT_CR_OFF_LOW;
94
95
96
97
98
99 clocks_calc_mult_shift(&persistent_mult, &persistent_shift,
100 32768, NSEC_PER_SEC, 120000);
101
102 ret = clocksource_mmio_init(sync32k_cnt_reg, "32k_counter", 32768,
103 250, 32, clocksource_mmio_readl_up);
104 if (ret) {
105 pr_err("32k_counter: can't register clocksource\n");
106 return ret;
107 }
108
109 sched_clock_register(omap_32k_read_sched_clock, 32, 32768);
110 register_persistent_clock(omap_read_persistent_clock64);
111 pr_info("OMAP clocksource: 32k_counter at 32768 Hz\n");
112
113 return 0;
114 }