1 /* linux/include/linux/clockchips.h
3 * This file contains the structure definitions for clockchips.
5 * If you are not a clockchip, or the time of day code, you should
6 * not be including this file!
8 #ifndef _LINUX_CLOCKCHIPS_H
9 #define _LINUX_CLOCKCHIPS_H
11 /* Clock event notification values */
12 enum clock_event_nofitiers {
14 CLOCK_EVT_NOTIFY_BROADCAST_ENTER,
15 CLOCK_EVT_NOTIFY_BROADCAST_EXIT,
16 CLOCK_EVT_NOTIFY_CPU_DYING,
17 CLOCK_EVT_NOTIFY_CPU_DEAD,
20 #ifdef CONFIG_GENERIC_CLOCKEVENTS
22 # include <linux/clocksource.h>
23 # include <linux/cpumask.h>
24 # include <linux/ktime.h>
25 # include <linux/notifier.h>
27 struct clock_event_device;
30 /* Clock event mode commands for legacy ->set_mode(): OBSOLETE */
31 enum clock_event_mode {
32 CLOCK_EVT_MODE_UNUSED,
33 CLOCK_EVT_MODE_SHUTDOWN,
34 CLOCK_EVT_MODE_PERIODIC,
35 CLOCK_EVT_MODE_ONESHOT,
36 CLOCK_EVT_MODE_RESUME,
40 * Possible states of a clock event device.
42 * DETACHED: Device is not used by clockevents core. Initial state or can be
43 * reached from SHUTDOWN.
44 * SHUTDOWN: Device is powered-off. Can be reached from PERIODIC or ONESHOT.
45 * PERIODIC: Device is programmed to generate events periodically. Can be
46 * reached from DETACHED or SHUTDOWN.
47 * ONESHOT: Device is programmed to generate event only once. Can be reached
48 * from DETACHED or SHUTDOWN.
50 enum clock_event_state {
51 CLOCK_EVT_STATE_DETACHED,
52 CLOCK_EVT_STATE_SHUTDOWN,
53 CLOCK_EVT_STATE_PERIODIC,
54 CLOCK_EVT_STATE_ONESHOT,
58 * Clock event features
60 # define CLOCK_EVT_FEAT_PERIODIC 0x000001
61 # define CLOCK_EVT_FEAT_ONESHOT 0x000002
62 # define CLOCK_EVT_FEAT_KTIME 0x000004
65 * x86(64) specific (mis)features:
67 * - Clockevent source stops in C3 State and needs broadcast support.
68 * - Local APIC timer is used as a dummy device.
70 # define CLOCK_EVT_FEAT_C3STOP 0x000008
71 # define CLOCK_EVT_FEAT_DUMMY 0x000010
74 * Core shall set the interrupt affinity dynamically in broadcast mode
76 # define CLOCK_EVT_FEAT_DYNIRQ 0x000020
77 # define CLOCK_EVT_FEAT_PERCPU 0x000040
80 * Clockevent device is based on a hrtimer for broadcast
82 # define CLOCK_EVT_FEAT_HRTIMER 0x000080
85 * struct clock_event_device - clock event device descriptor
86 * @event_handler: Assigned by the framework to be called by the low
87 * level handler of the event source
88 * @set_next_event: set next event function using a clocksource delta
89 * @set_next_ktime: set next event function using a direct ktime value
90 * @next_event: local storage for the next event in oneshot mode
91 * @max_delta_ns: maximum delta value in ns
92 * @min_delta_ns: minimum delta value in ns
93 * @mult: nanosecond to cycles multiplier
94 * @shift: nanoseconds to cycles divisor (power of two)
95 * @mode: operating mode, relevant only to ->set_mode(), OBSOLETE
96 * @state: current state of the device, assigned by the core code
98 * @retries: number of forced programming retries
99 * @set_mode: legacy set mode function, only for modes <= CLOCK_EVT_MODE_RESUME.
100 * @set_state_periodic: switch state to periodic, if !set_mode
101 * @set_state_oneshot: switch state to oneshot, if !set_mode
102 * @set_state_shutdown: switch state to shutdown, if !set_mode
103 * @tick_resume: resume clkevt device, if !set_mode
104 * @broadcast: function to broadcast events
105 * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration
106 * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration
107 * @name: ptr to clock event name
108 * @rating: variable to rate clock event devices
109 * @irq: IRQ number (only for non CPU local devices)
110 * @bound_on: Bound on CPU
111 * @cpumask: cpumask to indicate for which CPUs this device works
112 * @list: list head for the management code
113 * @owner: module reference
115 struct clock_event_device {
116 void (*event_handler)(struct clock_event_device *);
117 int (*set_next_event)(unsigned long evt, struct clock_event_device *);
118 int (*set_next_ktime)(ktime_t expires, struct clock_event_device *);
124 enum clock_event_mode mode;
125 enum clock_event_state state;
126 unsigned int features;
127 unsigned long retries;
130 * State transition callback(s): Only one of the two groups should be
132 * - set_mode(), only for modes <= CLOCK_EVT_MODE_RESUME.
133 * - set_state_{shutdown|periodic|oneshot}(), tick_resume().
135 void (*set_mode)(enum clock_event_mode mode, struct clock_event_device *);
136 int (*set_state_periodic)(struct clock_event_device *);
137 int (*set_state_oneshot)(struct clock_event_device *);
138 int (*set_state_shutdown)(struct clock_event_device *);
139 int (*tick_resume)(struct clock_event_device *);
141 void (*broadcast)(const struct cpumask *mask);
142 void (*suspend)(struct clock_event_device *);
143 void (*resume)(struct clock_event_device *);
144 unsigned long min_delta_ticks;
145 unsigned long max_delta_ticks;
151 const struct cpumask *cpumask;
152 struct list_head list;
153 struct module *owner;
154 } ____cacheline_aligned;
157 * Calculate a multiplication factor for scaled math, which is used to convert
158 * nanoseconds based values to clock ticks:
160 * clock_ticks = (nanoseconds * factor) >> shift.
162 * div_sc is the rearranged equation to calculate a factor from a given clock
163 * ticks / nanoseconds ratio:
165 * factor = (clock_ticks << shift) / nanoseconds
167 static inline unsigned long
168 div_sc(unsigned long ticks, unsigned long nsec, int shift)
170 u64 tmp = ((u64)ticks) << shift;
174 return (unsigned long) tmp;
177 /* Clock event layer functions */
178 extern u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt);
179 extern void clockevents_register_device(struct clock_event_device *dev);
180 extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu);
182 extern void clockevents_config(struct clock_event_device *dev, u32 freq);
183 extern void clockevents_config_and_register(struct clock_event_device *dev,
184 u32 freq, unsigned long min_delta,
185 unsigned long max_delta);
187 extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
190 clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 minsec)
192 return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, freq, minsec);
195 extern void clockevents_suspend(void);
196 extern void clockevents_resume(void);
198 # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
199 # ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
200 extern void tick_broadcast(const struct cpumask *mask);
202 # define tick_broadcast NULL
204 extern int tick_receive_broadcast(void);
207 # if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
208 extern void tick_setup_hrtimer_broadcast(void);
209 extern int tick_check_broadcast_expired(void);
211 static inline int tick_check_broadcast_expired(void) { return 0; }
212 static inline void tick_setup_hrtimer_broadcast(void) { }
215 extern int clockevents_notify(unsigned long reason, void *arg);
217 #else /* !CONFIG_GENERIC_CLOCKEVENTS: */
219 static inline void clockevents_suspend(void) { }
220 static inline void clockevents_resume(void) { }
221 static inline int clockevents_notify(unsigned long reason, void *arg) { return 0; }
222 static inline int tick_check_broadcast_expired(void) { return 0; }
223 static inline void tick_setup_hrtimer_broadcast(void) { }
225 #endif /* !CONFIG_GENERIC_CLOCKEVENTS */
227 #endif /* _LINUX_CLOCKCHIPS_H */