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 #ifdef CONFIG_GENERIC_CLOCKEVENTS_BUILD
13 #include <linux/clocksource.h>
14 #include <linux/cpumask.h>
15 #include <linux/ktime.h>
16 #include <linux/notifier.h>
18 struct clock_event_device
;
20 /* Clock event mode commands */
21 enum 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
,
29 /* Clock event notification values */
30 enum clock_event_nofitiers
{
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
,
44 * Clock event features
46 #define CLOCK_EVT_FEAT_PERIODIC 0x000001
47 #define CLOCK_EVT_FEAT_ONESHOT 0x000002
48 #define CLOCK_EVT_FEAT_KTIME 0x000004
50 * x86(64) specific misfeatures:
52 * - Clockevent source stops in C3 State and needs broadcast support.
53 * - Local APIC timer is used as a dummy device.
55 #define CLOCK_EVT_FEAT_C3STOP 0x000008
56 #define CLOCK_EVT_FEAT_DUMMY 0x000010
59 * struct clock_event_device - clock event device descriptor
60 * @event_handler: Assigned by the framework to be called by the low
61 * level handler of the event source
62 * @set_next_event: set next event function using a clocksource delta
63 * @set_next_ktime: set next event function using a direct ktime value
64 * @next_event: local storage for the next event in oneshot mode
65 * @max_delta_ns: maximum delta value in ns
66 * @min_delta_ns: minimum delta value in ns
67 * @mult: nanosecond to cycles multiplier
68 * @shift: nanoseconds to cycles divisor (power of two)
69 * @mode: operating mode assigned by the management code
71 * @retries: number of forced programming retries
72 * @set_mode: set mode function
73 * @broadcast: function to broadcast events
74 * @min_delta_ticks: minimum delta value in ticks stored for reconfiguration
75 * @max_delta_ticks: maximum delta value in ticks stored for reconfiguration
76 * @name: ptr to clock event name
77 * @rating: variable to rate clock event devices
78 * @irq: IRQ number (only for non CPU local devices)
79 * @cpumask: cpumask to indicate for which CPUs this device works
80 * @list: list head for the management code
82 struct 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
*);
93 enum clock_event_mode mode
;
94 unsigned int features
;
95 unsigned long retries
;
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
;
106 const struct cpumask
*cpumask
;
107 struct list_head list
;
108 } ____cacheline_aligned
;
111 * Calculate a multiplication factor for scaled math, which is used to convert
112 * nanoseconds based values to clock ticks:
114 * clock_ticks = (nanoseconds * factor) >> shift.
116 * div_sc is the rearranged equation to calculate a factor from a given clock
117 * ticks / nanoseconds ratio:
119 * factor = (clock_ticks << shift) / nanoseconds
121 static inline unsigned long div_sc(unsigned long ticks
, unsigned long nsec
,
124 uint64_t tmp
= ((uint64_t)ticks
) << shift
;
127 return (unsigned long) tmp
;
130 /* Clock event layer functions */
131 extern u64
clockevent_delta2ns(unsigned long latch
,
132 struct clock_event_device
*evt
);
133 extern void clockevents_register_device(struct clock_event_device
*dev
);
135 extern void clockevents_config_and_register(struct clock_event_device
*dev
,
136 u32 freq
, unsigned long min_delta
,
137 unsigned long max_delta
);
139 extern int clockevents_update_freq(struct clock_event_device
*ce
, u32 freq
);
141 extern void clockevents_exchange_device(struct clock_event_device
*old
,
142 struct clock_event_device
*new);
143 extern void clockevents_set_mode(struct clock_event_device
*dev
,
144 enum clock_event_mode mode
);
145 extern int clockevents_register_notifier(struct notifier_block
*nb
);
146 extern int clockevents_program_event(struct clock_event_device
*dev
,
147 ktime_t expires
, bool force
);
149 extern void clockevents_handle_noop(struct clock_event_device
*dev
);
152 clockevents_calc_mult_shift(struct clock_event_device
*ce
, u32 freq
, u32 minsec
)
154 return clocks_calc_mult_shift(&ce
->mult
, &ce
->shift
, NSEC_PER_SEC
,
158 #ifdef CONFIG_GENERIC_CLOCKEVENTS
159 extern void clockevents_notify(unsigned long reason
, void *arg
);
161 # define clockevents_notify(reason, arg) do { } while (0)
164 #else /* CONFIG_GENERIC_CLOCKEVENTS_BUILD */
166 #define clockevents_notify(reason, arg) do { } while (0)