1
2
3
4
5
6
7
8#ifndef _LINUX_CLOCKCHIPS_H
9#define _LINUX_CLOCKCHIPS_H
10
11#ifdef CONFIG_GENERIC_CLOCKEVENTS
12
13# include <linux/clocksource.h>
14# include <linux/cpumask.h>
15# include <linux/ktime.h>
16# include <linux/notifier.h>
17
18struct clock_event_device;
19struct module;
20
21
22enum clock_event_mode {
23 CLOCK_EVT_MODE_UNUSED,
24 CLOCK_EVT_MODE_SHUTDOWN,
25 CLOCK_EVT_MODE_PERIODIC,
26 CLOCK_EVT_MODE_ONESHOT,
27 CLOCK_EVT_MODE_RESUME,
28};
29
30
31
32
33
34
35
36
37
38
39
40
41enum clock_event_state {
42 CLOCK_EVT_STATE_DETACHED,
43 CLOCK_EVT_STATE_SHUTDOWN,
44 CLOCK_EVT_STATE_PERIODIC,
45 CLOCK_EVT_STATE_ONESHOT,
46};
47
48
49
50
51# define CLOCK_EVT_FEAT_PERIODIC 0x000001
52# define CLOCK_EVT_FEAT_ONESHOT 0x000002
53# define CLOCK_EVT_FEAT_KTIME 0x000004
54
55
56
57
58
59
60
61# define CLOCK_EVT_FEAT_C3STOP 0x000008
62# define CLOCK_EVT_FEAT_DUMMY 0x000010
63
64
65
66
67# define CLOCK_EVT_FEAT_DYNIRQ 0x000020
68# define CLOCK_EVT_FEAT_PERCPU 0x000040
69
70
71
72
73# define CLOCK_EVT_FEAT_HRTIMER 0x000080
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106struct clock_event_device {
107 void (*event_handler)(struct clock_event_device *);
108 int (*set_next_event)(unsigned long evt, struct clock_event_device *);
109 int (*set_next_ktime)(ktime_t expires, struct clock_event_device *);
110 ktime_t next_event;
111 u64 max_delta_ns;
112 u64 min_delta_ns;
113 u32 mult;
114 u32 shift;
115 enum clock_event_mode mode;
116 enum clock_event_state state;
117 unsigned int features;
118 unsigned long retries;
119
120
121
122
123
124
125
126 void (*set_mode)(enum clock_event_mode mode, struct clock_event_device *);
127 int (*set_state_periodic)(struct clock_event_device *);
128 int (*set_state_oneshot)(struct clock_event_device *);
129 int (*set_state_shutdown)(struct clock_event_device *);
130 int (*tick_resume)(struct clock_event_device *);
131
132 void (*broadcast)(const struct cpumask *mask);
133 void (*suspend)(struct clock_event_device *);
134 void (*resume)(struct clock_event_device *);
135 unsigned long min_delta_ticks;
136 unsigned long max_delta_ticks;
137
138 const char *name;
139 int rating;
140 int irq;
141 int bound_on;
142 const struct cpumask *cpumask;
143 struct list_head list;
144 struct module *owner;
145} ____cacheline_aligned;
146
147
148
149
150
151
152
153
154
155
156
157
158static inline unsigned long
159div_sc(unsigned long ticks, unsigned long nsec, int shift)
160{
161 u64 tmp = ((u64)ticks) << shift;
162
163 do_div(tmp, nsec);
164
165 return (unsigned long) tmp;
166}
167
168
169extern u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt);
170extern void clockevents_register_device(struct clock_event_device *dev);
171extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu);
172
173extern void clockevents_config(struct clock_event_device *dev, u32 freq);
174extern void clockevents_config_and_register(struct clock_event_device *dev,
175 u32 freq, unsigned long min_delta,
176 unsigned long max_delta);
177
178extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
179
180static inline void
181clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
182{
183 return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, freq, minsec);
184}
185
186extern void clockevents_suspend(void);
187extern void clockevents_resume(void);
188
189# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
190# ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
191extern void tick_broadcast(const struct cpumask *mask);
192# else
193# define tick_broadcast NULL
194# endif
195extern int tick_receive_broadcast(void);
196# endif
197
198# if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
199extern void tick_setup_hrtimer_broadcast(void);
200extern int tick_check_broadcast_expired(void);
201# else
202static inline int tick_check_broadcast_expired(void) { return 0; }
203static inline void tick_setup_hrtimer_broadcast(void) { }
204# endif
205
206extern int clockevents_notify(unsigned long reason, void *arg);
207
208#else
209
210static inline void clockevents_suspend(void) { }
211static inline void clockevents_resume(void) { }
212static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
213static inline int tick_check_broadcast_expired(void) { return 0; }
214static inline void tick_setup_hrtimer_broadcast(void) { }
215
216#endif
217
218#endif
219