diff options
Diffstat (limited to 'kernel/time/clockevents.c')
-rw-r--r-- | kernel/time/clockevents.c | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/kernel/time/clockevents.c b/kernel/time/clockevents.c index 0d74b9ba90c8..22a9da9a9c96 100644 --- a/kernel/time/clockevents.c +++ b/kernel/time/clockevents.c | |||
@@ -194,6 +194,70 @@ void clockevents_register_device(struct clock_event_device *dev) | |||
194 | } | 194 | } |
195 | EXPORT_SYMBOL_GPL(clockevents_register_device); | 195 | EXPORT_SYMBOL_GPL(clockevents_register_device); |
196 | 196 | ||
197 | static void clockevents_config(struct clock_event_device *dev, | ||
198 | u32 freq) | ||
199 | { | ||
200 | unsigned long sec; | ||
201 | |||
202 | if (!(dev->features & CLOCK_EVT_FEAT_ONESHOT)) | ||
203 | return; | ||
204 | |||
205 | /* | ||
206 | * Calculate the maximum number of seconds we can sleep. Limit | ||
207 | * to 10 minutes for hardware which can program more than | ||
208 | * 32bit ticks so we still get reasonable conversion values. | ||
209 | */ | ||
210 | sec = dev->max_delta_ticks; | ||
211 | do_div(sec, freq); | ||
212 | if (!sec) | ||
213 | sec = 1; | ||
214 | else if (sec > 600 && dev->max_delta_ticks > UINT_MAX) | ||
215 | sec = 600; | ||
216 | |||
217 | clockevents_calc_mult_shift(dev, freq, sec); | ||
218 | dev->min_delta_ns = clockevent_delta2ns(dev->min_delta_ticks, dev); | ||
219 | dev->max_delta_ns = clockevent_delta2ns(dev->max_delta_ticks, dev); | ||
220 | } | ||
221 | |||
222 | /** | ||
223 | * clockevents_config_and_register - Configure and register a clock event device | ||
224 | * @dev: device to register | ||
225 | * @freq: The clock frequency | ||
226 | * @min_delta: The minimum clock ticks to program in oneshot mode | ||
227 | * @max_delta: The maximum clock ticks to program in oneshot mode | ||
228 | * | ||
229 | * min/max_delta can be 0 for devices which do not support oneshot mode. | ||
230 | */ | ||
231 | void clockevents_config_and_register(struct clock_event_device *dev, | ||
232 | u32 freq, unsigned long min_delta, | ||
233 | unsigned long max_delta) | ||
234 | { | ||
235 | dev->min_delta_ticks = min_delta; | ||
236 | dev->max_delta_ticks = max_delta; | ||
237 | clockevents_config(dev, freq); | ||
238 | clockevents_register_device(dev); | ||
239 | } | ||
240 | |||
241 | /** | ||
242 | * clockevents_update_freq - Update frequency and reprogram a clock event device. | ||
243 | * @dev: device to modify | ||
244 | * @freq: new device frequency | ||
245 | * | ||
246 | * Reconfigure and reprogram a clock event device in oneshot | ||
247 | * mode. Must be called on the cpu for which the device delivers per | ||
248 | * cpu timer events with interrupts disabled! Returns 0 on success, | ||
249 | * -ETIME when the event is in the past. | ||
250 | */ | ||
251 | int clockevents_update_freq(struct clock_event_device *dev, u32 freq) | ||
252 | { | ||
253 | clockevents_config(dev, freq); | ||
254 | |||
255 | if (dev->mode != CLOCK_EVT_MODE_ONESHOT) | ||
256 | return 0; | ||
257 | |||
258 | return clockevents_program_event(dev, dev->next_event, ktime_get()); | ||
259 | } | ||
260 | |||
197 | /* | 261 | /* |
198 | * Noop handler when we shut down an event device | 262 | * Noop handler when we shut down an event device |
199 | */ | 263 | */ |