1
2
3
4
5
6
7
8#ifndef _LINUX_CLOCKCHIPS_H
9#define _LINUX_CLOCKCHIPS_H
10
11#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
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;
19
20
21enum clock_event_mode {
22 CLOCK_EVT_MODE_UNUSED = 0,
23 CLOCK_EVT_MODE_SHUTDOWN,
24 CLOCK_EVT_MODE_PERIODIC,
25 CLOCK_EVT_MODE_ONESHOT,
26 CLOCK_EVT_MODE_RESUME,
27};
28
29
30enum clock_event_nofitiers {
31 CLOCK_EVT_NOTIFY_ADD,
32 CLOCK_EVT_NOTIFY_BROADCAST_ON,
33 CLOCK_EVT_NOTIFY_BROADCAST_OFF,
34 CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
35 CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
36 CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
37 CLOCK_EVT_NOTIFY_SUSPEND,
38 CLOCK_EVT_NOTIFY_RESUME,
39 CLOCK_EVT_NOTIFY_CPU_DYING,
40 CLOCK_EVT_NOTIFY_CPU_DEAD,
41};
42
43
44
45
46#define CLOCK_EVT_FEAT_PERIODIC 0x000001
47#define CLOCK_EVT_FEAT_ONESHOT 0x000002
48#define CLOCK_EVT_FEAT_KTIME 0x000004
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82struct clock_event_device {
83 void (*event_handler)(struct clock_event_device *);
84 int (*set_next_event)(unsigned long evt,
85 struct clock_event_device *);
86 int (*set_next_ktime)(ktime_t expires,
87 struct clock_event_device *);
88 ktime_t next_event;
89 u64 max_delta_ns;
90 u64 min_delta_ns;
91 u32 mult;
92 u32 shift;
93 enum clock_event_mode mode;
94 unsigned int features;
95 unsigned long retries;
96
97 void (*broadcast)(const struct cpumask *mask);
98 void (*set_mode)(enum clock_event_mode mode,
99 struct clock_event_device *);
100 unsigned long min_delta_ticks;
101 unsigned long max_delta_ticks;
102
103 const char *name;
104 int rating;
105 int irq;
106 const struct cpumask *cpumask;
107 struct list_head list;
108} ____cacheline_aligned;
109
110
111
112
113
114
115
116
117
118
119
120
121static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
122 int shift)
123{
124 uint64_t tmp = ((uint64_t)ticks) << shift;
125
126 do_div(tmp, nsec);
127 return (unsigned long) tmp;
128}
129
130
131extern u64 clockevent_delta2ns(unsigned long latch,
132 struct clock_event_device *evt);
133extern void clockevents_register_device(struct clock_event_device *dev);
134
135extern void clockevents_config_and_register(struct clock_event_device *dev,
136 u32 freq, unsigned long min_delta,
137 unsigned long max_delta);
138
139extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
140
141extern void clockevents_exchange_device(struct clock_event_device *old,
142 struct clock_event_device *new);
143extern void clockevents_set_mode(struct clock_event_device *dev,
144 enum clock_event_mode mode);
145extern int clockevents_register_notifier(struct notifier_block *nb);
146extern int clockevents_program_event(struct clock_event_device *dev,
147 ktime_t expires, bool force);
148
149extern void clockevents_handle_noop(struct clock_event_device *dev);
150
151static inline void
152clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
153{
154 return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC,
155 freq, minsec);
156}
157
158#ifdef CONFIG_GENERIC_CLOCKEVENTS
159extern void clockevents_notify(unsigned long reason, void *arg);
160#else
161# define clockevents_notify(reason, arg) do { } while (0)
162#endif
163
164#else
165
166#define clockevents_notify(reason, arg) do { } while (0)
167
168#endif
169
170#endif
171