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
22
23
24
25
26
27
28
29
30
31
32
33
34enum clock_event_state {
35 CLOCK_EVT_STATE_DETACHED,
36 CLOCK_EVT_STATE_SHUTDOWN,
37 CLOCK_EVT_STATE_PERIODIC,
38 CLOCK_EVT_STATE_ONESHOT,
39 CLOCK_EVT_STATE_ONESHOT_STOPPED,
40};
41
42
43
44
45# define CLOCK_EVT_FEAT_PERIODIC 0x000001
46# define CLOCK_EVT_FEAT_ONESHOT 0x000002
47# define CLOCK_EVT_FEAT_KTIME 0x000004
48
49
50
51
52
53
54
55# define CLOCK_EVT_FEAT_C3STOP 0x000008
56# define CLOCK_EVT_FEAT_DUMMY 0x000010
57
58
59
60
61# define CLOCK_EVT_FEAT_DYNIRQ 0x000020
62# define CLOCK_EVT_FEAT_PERCPU 0x000040
63
64
65
66
67# define CLOCK_EVT_FEAT_HRTIMER 0x000080
68
69
70
71
72
73
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
99struct clock_event_device {
100 void (*event_handler)(struct clock_event_device *);
101 int (*set_next_event)(unsigned long evt, struct clock_event_device *);
102 int (*set_next_ktime)(ktime_t expires, struct clock_event_device *);
103 ktime_t next_event;
104 u64 max_delta_ns;
105 u64 min_delta_ns;
106 u32 mult;
107 u32 shift;
108 enum clock_event_state state_use_accessors;
109 unsigned int features;
110 unsigned long retries;
111
112 int (*set_state_periodic)(struct clock_event_device *);
113 int (*set_state_oneshot)(struct clock_event_device *);
114 int (*set_state_oneshot_stopped)(struct clock_event_device *);
115 int (*set_state_shutdown)(struct clock_event_device *);
116 int (*tick_resume)(struct clock_event_device *);
117
118 void (*broadcast)(const struct cpumask *mask);
119 void (*suspend)(struct clock_event_device *);
120 void (*resume)(struct clock_event_device *);
121 unsigned long min_delta_ticks;
122 unsigned long max_delta_ticks;
123
124 const char *name;
125 int rating;
126 int irq;
127 int bound_on;
128 const struct cpumask *cpumask;
129 struct list_head list;
130 struct module *owner;
131} ____cacheline_aligned;
132
133
134static inline bool clockevent_state_detached(struct clock_event_device *dev)
135{
136 return dev->state_use_accessors == CLOCK_EVT_STATE_DETACHED;
137}
138
139static inline bool clockevent_state_shutdown(struct clock_event_device *dev)
140{
141 return dev->state_use_accessors == CLOCK_EVT_STATE_SHUTDOWN;
142}
143
144static inline bool clockevent_state_periodic(struct clock_event_device *dev)
145{
146 return dev->state_use_accessors == CLOCK_EVT_STATE_PERIODIC;
147}
148
149static inline bool clockevent_state_oneshot(struct clock_event_device *dev)
150{
151 return dev->state_use_accessors == CLOCK_EVT_STATE_ONESHOT;
152}
153
154static inline bool clockevent_state_oneshot_stopped(struct clock_event_device *dev)
155{
156 return dev->state_use_accessors == CLOCK_EVT_STATE_ONESHOT_STOPPED;
157}
158
159
160
161
162
163
164
165
166
167
168
169
170static inline unsigned long
171div_sc(unsigned long ticks, unsigned long nsec, int shift)
172{
173 u64 tmp = ((u64)ticks) << shift;
174
175 do_div(tmp, nsec);
176
177 return (unsigned long) tmp;
178}
179
180
181extern u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt);
182extern void clockevents_register_device(struct clock_event_device *dev);
183extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu);
184
185extern void clockevents_config_and_register(struct clock_event_device *dev,
186 u32 freq, unsigned long min_delta,
187 unsigned long max_delta);
188
189extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
190
191static inline void
192clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 maxsec)
193{
194 return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, freq, maxsec);
195}
196
197extern void clockevents_suspend(void);
198extern void clockevents_resume(void);
199
200# ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
201# ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
202extern void tick_broadcast(const struct cpumask *mask);
203# else
204# define tick_broadcast NULL
205# endif
206extern int tick_receive_broadcast(void);
207# endif
208
209# if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
210extern void tick_setup_hrtimer_broadcast(void);
211extern int tick_check_broadcast_expired(void);
212# else
213static inline int tick_check_broadcast_expired(void) { return 0; }
214static inline void tick_setup_hrtimer_broadcast(void) { }
215# endif
216
217#else
218
219static inline void clockevents_suspend(void) { }
220static inline void clockevents_resume(void) { }
221static inline int tick_check_broadcast_expired(void) { return 0; }
222static inline void tick_setup_hrtimer_broadcast(void) { }
223
224#endif
225
226#define CLOCKEVENT_OF_DECLARE(name, compat, fn) \
227 OF_DECLARE_1_RET(clkevt, name, compat, fn)
228
229#ifdef CONFIG_CLKEVT_PROBE
230extern int clockevent_probe(void);
231#else
232static inline int clockevent_probe(void) { return 0; }
233#endif
234
235#endif
236