0001
0002
0003
0004
0005
0006
0007
0008
0009 #ifndef _LINUX_CLOCKCHIPS_H
0010 #define _LINUX_CLOCKCHIPS_H
0011
0012 #ifdef CONFIG_GENERIC_CLOCKEVENTS
0013
0014 # include <linux/clocksource.h>
0015 # include <linux/cpumask.h>
0016 # include <linux/ktime.h>
0017 # include <linux/notifier.h>
0018
0019 struct clock_event_device;
0020 struct module;
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 enum clock_event_state {
0036 CLOCK_EVT_STATE_DETACHED,
0037 CLOCK_EVT_STATE_SHUTDOWN,
0038 CLOCK_EVT_STATE_PERIODIC,
0039 CLOCK_EVT_STATE_ONESHOT,
0040 CLOCK_EVT_STATE_ONESHOT_STOPPED,
0041 };
0042
0043
0044
0045
0046 # define CLOCK_EVT_FEAT_PERIODIC 0x000001
0047 # define CLOCK_EVT_FEAT_ONESHOT 0x000002
0048 # define CLOCK_EVT_FEAT_KTIME 0x000004
0049
0050
0051
0052
0053
0054
0055
0056 # define CLOCK_EVT_FEAT_C3STOP 0x000008
0057 # define CLOCK_EVT_FEAT_DUMMY 0x000010
0058
0059
0060
0061
0062 # define CLOCK_EVT_FEAT_DYNIRQ 0x000020
0063 # define CLOCK_EVT_FEAT_PERCPU 0x000040
0064
0065
0066
0067
0068 # define CLOCK_EVT_FEAT_HRTIMER 0x000080
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100 struct clock_event_device {
0101 void (*event_handler)(struct clock_event_device *);
0102 int (*set_next_event)(unsigned long evt, struct clock_event_device *);
0103 int (*set_next_ktime)(ktime_t expires, struct clock_event_device *);
0104 ktime_t next_event;
0105 u64 max_delta_ns;
0106 u64 min_delta_ns;
0107 u32 mult;
0108 u32 shift;
0109 enum clock_event_state state_use_accessors;
0110 unsigned int features;
0111 unsigned long retries;
0112
0113 int (*set_state_periodic)(struct clock_event_device *);
0114 int (*set_state_oneshot)(struct clock_event_device *);
0115 int (*set_state_oneshot_stopped)(struct clock_event_device *);
0116 int (*set_state_shutdown)(struct clock_event_device *);
0117 int (*tick_resume)(struct clock_event_device *);
0118
0119 void (*broadcast)(const struct cpumask *mask);
0120 void (*suspend)(struct clock_event_device *);
0121 void (*resume)(struct clock_event_device *);
0122 unsigned long min_delta_ticks;
0123 unsigned long max_delta_ticks;
0124
0125 const char *name;
0126 int rating;
0127 int irq;
0128 int bound_on;
0129 const struct cpumask *cpumask;
0130 struct list_head list;
0131 struct module *owner;
0132 } ____cacheline_aligned;
0133
0134
0135 static inline bool clockevent_state_detached(struct clock_event_device *dev)
0136 {
0137 return dev->state_use_accessors == CLOCK_EVT_STATE_DETACHED;
0138 }
0139
0140 static inline bool clockevent_state_shutdown(struct clock_event_device *dev)
0141 {
0142 return dev->state_use_accessors == CLOCK_EVT_STATE_SHUTDOWN;
0143 }
0144
0145 static inline bool clockevent_state_periodic(struct clock_event_device *dev)
0146 {
0147 return dev->state_use_accessors == CLOCK_EVT_STATE_PERIODIC;
0148 }
0149
0150 static inline bool clockevent_state_oneshot(struct clock_event_device *dev)
0151 {
0152 return dev->state_use_accessors == CLOCK_EVT_STATE_ONESHOT;
0153 }
0154
0155 static inline bool clockevent_state_oneshot_stopped(struct clock_event_device *dev)
0156 {
0157 return dev->state_use_accessors == CLOCK_EVT_STATE_ONESHOT_STOPPED;
0158 }
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171 static inline unsigned long
0172 div_sc(unsigned long ticks, unsigned long nsec, int shift)
0173 {
0174 u64 tmp = ((u64)ticks) << shift;
0175
0176 do_div(tmp, nsec);
0177
0178 return (unsigned long) tmp;
0179 }
0180
0181
0182 extern u64 clockevent_delta2ns(unsigned long latch, struct clock_event_device *evt);
0183 extern void clockevents_register_device(struct clock_event_device *dev);
0184 extern int clockevents_unbind_device(struct clock_event_device *ced, int cpu);
0185
0186 extern void clockevents_config_and_register(struct clock_event_device *dev,
0187 u32 freq, unsigned long min_delta,
0188 unsigned long max_delta);
0189
0190 extern int clockevents_update_freq(struct clock_event_device *ce, u32 freq);
0191
0192 static inline void
0193 clockevents_calc_mult_shift(struct clock_event_device *ce, u32 freq, u32 maxsec)
0194 {
0195 return clocks_calc_mult_shift(&ce->mult, &ce->shift, NSEC_PER_SEC, freq, maxsec);
0196 }
0197
0198 extern void clockevents_suspend(void);
0199 extern void clockevents_resume(void);
0200
0201 # ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
0202 # ifdef CONFIG_ARCH_HAS_TICK_BROADCAST
0203 extern void tick_broadcast(const struct cpumask *mask);
0204 # else
0205 # define tick_broadcast NULL
0206 # endif
0207 extern int tick_receive_broadcast(void);
0208 # endif
0209
0210 # if defined(CONFIG_GENERIC_CLOCKEVENTS_BROADCAST) && defined(CONFIG_TICK_ONESHOT)
0211 extern void tick_setup_hrtimer_broadcast(void);
0212 extern int tick_check_broadcast_expired(void);
0213 # else
0214 static inline int tick_check_broadcast_expired(void) { return 0; }
0215 static inline void tick_setup_hrtimer_broadcast(void) { }
0216 # endif
0217
0218 #else
0219
0220 static inline void clockevents_suspend(void) { }
0221 static inline void clockevents_resume(void) { }
0222 static inline int tick_check_broadcast_expired(void) { return 0; }
0223 static inline void tick_setup_hrtimer_broadcast(void) { }
0224
0225 #endif
0226
0227 #endif