clocksource/drivers/sun5i: Add clock notifiers
[deliverable/linux.git] / include / linux / clockchips.h
CommitLineData
d316c57f
TG
1/* linux/include/linux/clockchips.h
2 *
3 * This file contains the structure definitions for clockchips.
4 *
5 * If you are not a clockchip, or the time of day code, you should
6 * not be including this file!
7 */
8#ifndef _LINUX_CLOCKCHIPS_H
9#define _LINUX_CLOCKCHIPS_H
10
4dbad816
DL
11/* Clock event notification values */
12enum clock_event_nofitiers {
13 CLOCK_EVT_NOTIFY_ADD,
14 CLOCK_EVT_NOTIFY_BROADCAST_ON,
15 CLOCK_EVT_NOTIFY_BROADCAST_OFF,
16 CLOCK_EVT_NOTIFY_BROADCAST_FORCE,
17 CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
18 CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
19 CLOCK_EVT_NOTIFY_SUSPEND,
20 CLOCK_EVT_NOTIFY_RESUME,
21 CLOCK_EVT_NOTIFY_CPU_DYING,
22 CLOCK_EVT_NOTIFY_CPU_DEAD,
23};
24
de68d9b1 25#ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
d316c57f
TG
26
27#include <linux/clocksource.h>
28#include <linux/cpumask.h>
29#include <linux/ktime.h>
30#include <linux/notifier.h>
31
32struct clock_event_device;
ccf33d68 33struct module;
d316c57f 34
77e32c89 35/* Clock event mode commands for legacy ->set_mode(): OBSOLETE */
d316c57f
TG
36enum clock_event_mode {
37 CLOCK_EVT_MODE_UNUSED = 0,
38 CLOCK_EVT_MODE_SHUTDOWN,
39 CLOCK_EVT_MODE_PERIODIC,
40 CLOCK_EVT_MODE_ONESHOT,
18de5bc4 41 CLOCK_EVT_MODE_RESUME,
77e32c89 42};
bd624d75 43
77e32c89
VK
44/*
45 * Possible states of a clock event device.
46 *
47 * DETACHED: Device is not used by clockevents core. Initial state or can be
48 * reached from SHUTDOWN.
49 * SHUTDOWN: Device is powered-off. Can be reached from PERIODIC or ONESHOT.
50 * PERIODIC: Device is programmed to generate events periodically. Can be
51 * reached from DETACHED or SHUTDOWN.
52 * ONESHOT: Device is programmed to generate event only once. Can be reached
53 * from DETACHED or SHUTDOWN.
54 */
55enum clock_event_state {
56 CLOCK_EVT_STATE_DETACHED = 0,
57 CLOCK_EVT_STATE_SHUTDOWN,
58 CLOCK_EVT_STATE_PERIODIC,
59 CLOCK_EVT_STATE_ONESHOT,
d316c57f
TG
60};
61
d316c57f
TG
62/*
63 * Clock event features
64 */
65#define CLOCK_EVT_FEAT_PERIODIC 0x000001
66#define CLOCK_EVT_FEAT_ONESHOT 0x000002
65516f8a 67#define CLOCK_EVT_FEAT_KTIME 0x000004
d316c57f
TG
68/*
69 * x86(64) specific misfeatures:
70 *
71 * - Clockevent source stops in C3 State and needs broadcast support.
72 * - Local APIC timer is used as a dummy device.
73 */
65516f8a
MS
74#define CLOCK_EVT_FEAT_C3STOP 0x000008
75#define CLOCK_EVT_FEAT_DUMMY 0x000010
d316c57f 76
d2348fb6
DL
77/*
78 * Core shall set the interrupt affinity dynamically in broadcast mode
79 */
80#define CLOCK_EVT_FEAT_DYNIRQ 0x000020
3713c0cf 81#define CLOCK_EVT_FEAT_PERCPU 0x000040
d2348fb6 82
5d1638ac
PM
83/*
84 * Clockevent device is based on a hrtimer for broadcast
85 */
86#define CLOCK_EVT_FEAT_HRTIMER 0x000080
87
d316c57f
TG
88/**
89 * struct clock_event_device - clock event device descriptor
847b2f42
TG
90 * @event_handler: Assigned by the framework to be called by the low
91 * level handler of the event source
65516f8a
MS
92 * @set_next_event: set next event function using a clocksource delta
93 * @set_next_ktime: set next event function using a direct ktime value
847b2f42 94 * @next_event: local storage for the next event in oneshot mode
d316c57f
TG
95 * @max_delta_ns: maximum delta value in ns
96 * @min_delta_ns: minimum delta value in ns
97 * @mult: nanosecond to cycles multiplier
98 * @shift: nanoseconds to cycles divisor (power of two)
77e32c89
VK
99 * @mode: operating mode, relevant only to ->set_mode(), OBSOLETE
100 * @state: current state of the device, assigned by the core code
847b2f42
TG
101 * @features: features
102 * @retries: number of forced programming retries
bd624d75 103 * @set_mode: legacy set mode function, only for modes <= CLOCK_EVT_MODE_RESUME.
77e32c89
VK
104 * @set_state_periodic: switch state to periodic, if !set_mode
105 * @set_state_oneshot: switch state to oneshot, if !set_mode
106 * @set_state_shutdown: switch state to shutdown, if !set_mode
554ef387 107 * @tick_resume: resume clkevt device, if !set_mode
847b2f42 108 * @broadcast: function to broadcast events
57f0fcbe
TG
109 * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration
110 * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration
847b2f42 111 * @name: ptr to clock event name
d316c57f 112 * @rating: variable to rate clock event devices
ce0be127 113 * @irq: IRQ number (only for non CPU local devices)
5d1638ac 114 * @bound_on: Bound on CPU
ce0be127 115 * @cpumask: cpumask to indicate for which CPUs this device works
d316c57f 116 * @list: list head for the management code
ccf33d68 117 * @owner: module reference
d316c57f
TG
118 */
119struct clock_event_device {
847b2f42
TG
120 void (*event_handler)(struct clock_event_device *);
121 int (*set_next_event)(unsigned long evt,
122 struct clock_event_device *);
65516f8a
MS
123 int (*set_next_ktime)(ktime_t expires,
124 struct clock_event_device *);
847b2f42 125 ktime_t next_event;
97813f2f
JH
126 u64 max_delta_ns;
127 u64 min_delta_ns;
23af368e
TG
128 u32 mult;
129 u32 shift;
847b2f42 130 enum clock_event_mode mode;
77e32c89 131 enum clock_event_state state;
847b2f42
TG
132 unsigned int features;
133 unsigned long retries;
134
bd624d75 135 /*
77e32c89 136 * State transition callback(s): Only one of the two groups should be
bd624d75
VK
137 * defined:
138 * - set_mode(), only for modes <= CLOCK_EVT_MODE_RESUME.
77e32c89 139 * - set_state_{shutdown|periodic|oneshot}(), tick_resume().
bd624d75 140 */
847b2f42
TG
141 void (*set_mode)(enum clock_event_mode mode,
142 struct clock_event_device *);
77e32c89
VK
143 int (*set_state_periodic)(struct clock_event_device *);
144 int (*set_state_oneshot)(struct clock_event_device *);
145 int (*set_state_shutdown)(struct clock_event_device *);
554ef387 146 int (*tick_resume)(struct clock_event_device *);
bd624d75
VK
147
148 void (*broadcast)(const struct cpumask *mask);
adc78e6b
RW
149 void (*suspend)(struct clock_event_device *);
150 void (*resume)(struct clock_event_device *);
57f0fcbe
TG
151 unsigned long min_delta_ticks;
152 unsigned long max_delta_ticks;
153
847b2f42 154 const char *name;
d316c57f
TG
155 int rating;
156 int irq;
5d1638ac 157 int bound_on;
320ab2b0 158 const struct cpumask *cpumask;
d316c57f 159 struct list_head list;
ccf33d68 160 struct module *owner;
847b2f42 161} ____cacheline_aligned;
d316c57f
TG
162
163/*
164 * Calculate a multiplication factor for scaled math, which is used to convert
165 * nanoseconds based values to clock ticks:
166 *
167 * clock_ticks = (nanoseconds * factor) >> shift.
168 *
169 * div_sc is the rearranged equation to calculate a factor from a given clock
170 * ticks / nanoseconds ratio:
171 *
172 * factor = (clock_ticks << shift) / nanoseconds
173 */
174static inline unsigned long div_sc(unsigned long ticks, unsigned long nsec,
175 int shift)
176{
177 uint64_t tmp = ((uint64_t)ticks) << shift;
178
179 do_div(tmp, nsec);
180 return (unsigned long) tmp;
181}
182
183/* Clock event layer functions */
97813f2f
JH
184extern u64 clockevent_delta2ns(unsigned long latch,
185 struct clock_event_device *evt);
d316c57f 186extern void clockevents_register_device(struct clock_event_device *dev);
03e13cf5 187extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu);
d316c57f 188
e5400321 189extern void clockevents_config(struct clock_event_device *dev, u32 freq);
57f0fcbe
TG
190extern void clockevents_config_and_register(struct clock_event_device *dev,
191 u32 freq, unsigned long min_delta,
192 unsigned long max_delta);
193
80b816b7
TG
194extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
195
d316c57f
TG
196extern void clockevents_exchange_device(struct clock_event_device *old,
197 struct clock_event_device *new);
77e32c89
VK
198extern void clockevents_set_state(struct clock_event_device *dev,
199 enum clock_event_state state);
d316c57f 200extern int clockevents_program_event(struct clock_event_device *dev,
d1748302 201 ktime_t expires, bool force);
d316c57f 202
7c1e7689
VP
203extern void clockevents_handle_noop(struct clock_event_device *dev);
204
7d2f944a
TG
205static inline void
206clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
207{
208 return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC,
209 freq, minsec);
210}
211
adc78e6b
RW
212extern void clockevents_suspend(void);
213extern void clockevents_resume(void);
214
12572dbb 215#ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
12ad1000
MR
216#ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
217extern void tick_broadcast(const struct cpumask *mask);
218#else
219#define tick_broadcast NULL
220#endif
12572dbb
MR
221extern int tick_receive_broadcast(void);
222#endif
223
eaa907c5 224#if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
5d1638ac 225extern void tick_setup_hrtimer_broadcast(void);
eaa907c5
TG
226extern int tick_check_broadcast_expired(void);
227#else
228static inline int tick_check_broadcast_expired(void) { return 0; }
f1689bb7 229static inline void tick_setup_hrtimer_broadcast(void) {};
eaa907c5
TG
230#endif
231
de68d9b1 232#ifdef CONFIG_GENERIC_CLOCKEVENTS
da7e6f45 233extern int clockevents_notify(unsigned long reason, void *arg);
d316c57f 234#else
da7e6f45 235static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
de68d9b1
TG
236#endif
237
238#else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
d316c57f 239
adc78e6b
RW
240static inline void clockevents_suspend(void) {}
241static inline void clockevents_resume(void) {}
242
da7e6f45 243static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
19919226 244static inline int tick_check_broadcast_expired(void) { return 0; }
849401b6 245static inline void tick_setup_hrtimer_broadcast(void) {};
d316c57f
TG
246
247#endif
248
249#endif
This page took 0.616501 seconds and 5 git commands to generate.