blob: ac6e9bc6cc5925bc6f2bb4239a4797b4b51bec36 [file] [log] [blame]
John Stultzff3ead92011-01-11 09:42:13 -08001/*
2 * Alarmtimer interface
3 *
4 * This interface provides a timer which is similarto hrtimers,
5 * but triggers a RTC alarm if the box is suspend.
6 *
7 * This interface is influenced by the Android RTC Alarm timer
8 * interface.
9 *
10 * Copyright (C) 2010 IBM Corperation
11 *
12 * Author: John Stultz <john.stultz@linaro.org>
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18#include <linux/time.h>
19#include <linux/hrtimer.h>
20#include <linux/timerqueue.h>
21#include <linux/rtc.h>
Ingo Molnar174cd4b2017-02-02 19:15:33 +010022#include <linux/sched/signal.h>
Ingo Molnarb17b0152017-02-08 18:51:35 +010023#include <linux/sched/debug.h>
John Stultzff3ead92011-01-11 09:42:13 -080024#include <linux/alarmtimer.h>
25#include <linux/mutex.h>
26#include <linux/platform_device.h>
27#include <linux/posix-timers.h>
28#include <linux/workqueue.h>
29#include <linux/freezer.h>
30
Thomas Gleixnerbab0aae92017-05-30 23:15:41 +020031#include "posix-timers.h"
32
Baolin Wang4a057542016-11-28 14:35:21 -080033#define CREATE_TRACE_POINTS
34#include <trace/events/alarmtimer.h>
35
John Stultz180bf812011-04-28 12:58:11 -070036/**
37 * struct alarm_base - Alarm timer bases
38 * @lock: Lock for syncrhonized access to the base
39 * @timerqueue: Timerqueue head managing the list of events
John Stultz180bf812011-04-28 12:58:11 -070040 * @gettime: Function to read the time correlating to the base
41 * @base_clockid: clockid for the base
John Stultz180bf812011-04-28 12:58:11 -070042 */
John Stultzff3ead92011-01-11 09:42:13 -080043static struct alarm_base {
44 spinlock_t lock;
45 struct timerqueue_head timerqueue;
John Stultzff3ead92011-01-11 09:42:13 -080046 ktime_t (*gettime)(void);
47 clockid_t base_clockid;
John Stultzff3ead92011-01-11 09:42:13 -080048} alarm_bases[ALARM_NUMTYPE];
49
Thomas Gleixnerb6b3b802017-05-27 12:23:47 +020050#if defined(CONFIG_POSIX_TIMERS) || defined(CONFIG_RTC_CLASS)
Baolin Wang4a057542016-11-28 14:35:21 -080051/* freezer information to handle clock_nanosleep triggered wakeups */
52static enum alarmtimer_type freezer_alarmtype;
53static ktime_t freezer_expires;
John Stultzc008ba582011-06-16 18:27:09 -070054static ktime_t freezer_delta;
55static DEFINE_SPINLOCK(freezer_delta_lock);
Thomas Gleixnerb6b3b802017-05-27 12:23:47 +020056#endif
John Stultzc008ba582011-06-16 18:27:09 -070057
Todd Poynor59a93c22012-08-09 00:37:27 -070058static struct wakeup_source *ws;
59
John Stultz472647d2011-04-29 15:03:10 -070060#ifdef CONFIG_RTC_CLASS
John Stultz180bf812011-04-28 12:58:11 -070061/* rtc timer and device for setting alarm wakeups at suspend */
Thomas Gleixnerc5e14e72012-03-24 12:46:23 +010062static struct rtc_timer rtctimer;
John Stultzff3ead92011-01-11 09:42:13 -080063static struct rtc_device *rtcdev;
John Stultzc008ba582011-06-16 18:27:09 -070064static DEFINE_SPINLOCK(rtcdev_lock);
John Stultzff3ead92011-01-11 09:42:13 -080065
John Stultzc008ba582011-06-16 18:27:09 -070066/**
John Stultzc008ba582011-06-16 18:27:09 -070067 * alarmtimer_get_rtcdev - Return selected rtcdevice
68 *
69 * This function returns the rtc device to use for wakealarms.
70 * If one has not already been chosen, it checks to see if a
71 * functional rtc device is available.
72 */
John Stultz57c498f2012-04-20 12:31:45 -070073struct rtc_device *alarmtimer_get_rtcdev(void)
John Stultzc008ba582011-06-16 18:27:09 -070074{
John Stultzc008ba582011-06-16 18:27:09 -070075 unsigned long flags;
76 struct rtc_device *ret;
77
78 spin_lock_irqsave(&rtcdev_lock, flags);
John Stultzc008ba582011-06-16 18:27:09 -070079 ret = rtcdev;
80 spin_unlock_irqrestore(&rtcdev_lock, flags);
81
82 return ret;
83}
Pramod Gurav71d5d2b2014-06-13 11:49:42 +053084EXPORT_SYMBOL_GPL(alarmtimer_get_rtcdev);
John Stultz8bc0daf2011-07-14 18:35:13 -070085
86static int alarmtimer_rtc_add_device(struct device *dev,
87 struct class_interface *class_intf)
88{
89 unsigned long flags;
90 struct rtc_device *rtc = to_rtc_device(dev);
91
92 if (rtcdev)
93 return -EBUSY;
94
95 if (!rtc->ops->set_alarm)
96 return -1;
97 if (!device_may_wakeup(rtc->dev.parent))
98 return -1;
99
100 spin_lock_irqsave(&rtcdev_lock, flags);
101 if (!rtcdev) {
102 rtcdev = rtc;
103 /* hold a reference so it doesn't go away */
104 get_device(dev);
105 }
106 spin_unlock_irqrestore(&rtcdev_lock, flags);
107 return 0;
108}
109
Thomas Gleixnerc5e14e72012-03-24 12:46:23 +0100110static inline void alarmtimer_rtc_timer_init(void)
111{
112 rtc_timer_init(&rtctimer, NULL, NULL);
113}
114
John Stultz8bc0daf2011-07-14 18:35:13 -0700115static struct class_interface alarmtimer_rtc_interface = {
116 .add_dev = &alarmtimer_rtc_add_device,
117};
118
Thomas Gleixner4523f6a2011-09-14 10:54:29 +0200119static int alarmtimer_rtc_interface_setup(void)
John Stultz8bc0daf2011-07-14 18:35:13 -0700120{
121 alarmtimer_rtc_interface.class = rtc_class;
Thomas Gleixner4523f6a2011-09-14 10:54:29 +0200122 return class_interface_register(&alarmtimer_rtc_interface);
123}
124static void alarmtimer_rtc_interface_remove(void)
125{
126 class_interface_unregister(&alarmtimer_rtc_interface);
John Stultz8bc0daf2011-07-14 18:35:13 -0700127}
John Stultz1c6b39a2011-06-16 18:47:37 -0700128#else
John Stultz57c498f2012-04-20 12:31:45 -0700129struct rtc_device *alarmtimer_get_rtcdev(void)
Thomas Gleixner4523f6a2011-09-14 10:54:29 +0200130{
131 return NULL;
132}
133#define rtcdev (NULL)
134static inline int alarmtimer_rtc_interface_setup(void) { return 0; }
135static inline void alarmtimer_rtc_interface_remove(void) { }
Thomas Gleixnerc5e14e72012-03-24 12:46:23 +0100136static inline void alarmtimer_rtc_timer_init(void) { }
John Stultzc008ba582011-06-16 18:27:09 -0700137#endif
John Stultzff3ead92011-01-11 09:42:13 -0800138
John Stultz180bf812011-04-28 12:58:11 -0700139/**
John Stultzff3ead92011-01-11 09:42:13 -0800140 * alarmtimer_enqueue - Adds an alarm timer to an alarm_base timerqueue
141 * @base: pointer to the base where the timer is being run
142 * @alarm: pointer to alarm being enqueued.
143 *
John Stultzdae373b2012-09-13 19:12:16 -0400144 * Adds alarm to a alarm_base timerqueue
John Stultzff3ead92011-01-11 09:42:13 -0800145 *
146 * Must hold base->lock when calling.
147 */
148static void alarmtimer_enqueue(struct alarm_base *base, struct alarm *alarm)
149{
John Stultzdae373b2012-09-13 19:12:16 -0400150 if (alarm->state & ALARMTIMER_STATE_ENQUEUED)
151 timerqueue_del(&base->timerqueue, &alarm->node);
152
John Stultzff3ead92011-01-11 09:42:13 -0800153 timerqueue_add(&base->timerqueue, &alarm->node);
John Stultza28cde82011-08-10 12:30:21 -0700154 alarm->state |= ALARMTIMER_STATE_ENQUEUED;
John Stultzff3ead92011-01-11 09:42:13 -0800155}
156
John Stultz180bf812011-04-28 12:58:11 -0700157/**
John Stultza65bcc12012-09-13 19:25:22 -0400158 * alarmtimer_dequeue - Removes an alarm timer from an alarm_base timerqueue
John Stultzff3ead92011-01-11 09:42:13 -0800159 * @base: pointer to the base where the timer is running
160 * @alarm: pointer to alarm being removed
161 *
John Stultzdae373b2012-09-13 19:12:16 -0400162 * Removes alarm to a alarm_base timerqueue
John Stultzff3ead92011-01-11 09:42:13 -0800163 *
164 * Must hold base->lock when calling.
165 */
John Stultza65bcc12012-09-13 19:25:22 -0400166static void alarmtimer_dequeue(struct alarm_base *base, struct alarm *alarm)
John Stultzff3ead92011-01-11 09:42:13 -0800167{
John Stultza28cde82011-08-10 12:30:21 -0700168 if (!(alarm->state & ALARMTIMER_STATE_ENQUEUED))
169 return;
170
John Stultzff3ead92011-01-11 09:42:13 -0800171 timerqueue_del(&base->timerqueue, &alarm->node);
John Stultza28cde82011-08-10 12:30:21 -0700172 alarm->state &= ~ALARMTIMER_STATE_ENQUEUED;
John Stultzff3ead92011-01-11 09:42:13 -0800173}
174
John Stultz7068b7a2011-04-28 13:29:18 -0700175
John Stultz180bf812011-04-28 12:58:11 -0700176/**
John Stultz7068b7a2011-04-28 13:29:18 -0700177 * alarmtimer_fired - Handles alarm hrtimer being fired.
178 * @timer: pointer to hrtimer being run
John Stultzff3ead92011-01-11 09:42:13 -0800179 *
John Stultz180bf812011-04-28 12:58:11 -0700180 * When a alarm timer fires, this runs through the timerqueue to
181 * see which alarms expired, and runs those. If there are more alarm
182 * timers queued for the future, we set the hrtimer to fire when
183 * when the next future alarm timer expires.
John Stultzff3ead92011-01-11 09:42:13 -0800184 */
John Stultz7068b7a2011-04-28 13:29:18 -0700185static enum hrtimer_restart alarmtimer_fired(struct hrtimer *timer)
John Stultzff3ead92011-01-11 09:42:13 -0800186{
John Stultzdae373b2012-09-13 19:12:16 -0400187 struct alarm *alarm = container_of(timer, struct alarm, timer);
188 struct alarm_base *base = &alarm_bases[alarm->type];
John Stultzff3ead92011-01-11 09:42:13 -0800189 unsigned long flags;
John Stultz7068b7a2011-04-28 13:29:18 -0700190 int ret = HRTIMER_NORESTART;
John Stultz54da23b2011-08-10 11:08:07 -0700191 int restart = ALARMTIMER_NORESTART;
John Stultzff3ead92011-01-11 09:42:13 -0800192
193 spin_lock_irqsave(&base->lock, flags);
John Stultza65bcc12012-09-13 19:25:22 -0400194 alarmtimer_dequeue(base, alarm);
John Stultzdae373b2012-09-13 19:12:16 -0400195 spin_unlock_irqrestore(&base->lock, flags);
John Stultzff3ead92011-01-11 09:42:13 -0800196
John Stultzdae373b2012-09-13 19:12:16 -0400197 if (alarm->function)
198 restart = alarm->function(alarm, base->gettime());
John Stultzff3ead92011-01-11 09:42:13 -0800199
John Stultzdae373b2012-09-13 19:12:16 -0400200 spin_lock_irqsave(&base->lock, flags);
201 if (restart != ALARMTIMER_NORESTART) {
202 hrtimer_set_expires(&alarm->timer, alarm->node.expires);
203 alarmtimer_enqueue(base, alarm);
John Stultz7068b7a2011-04-28 13:29:18 -0700204 ret = HRTIMER_RESTART;
John Stultzff3ead92011-01-11 09:42:13 -0800205 }
206 spin_unlock_irqrestore(&base->lock, flags);
John Stultzff3ead92011-01-11 09:42:13 -0800207
Baolin Wang4a057542016-11-28 14:35:21 -0800208 trace_alarmtimer_fired(alarm, base->gettime());
John Stultz7068b7a2011-04-28 13:29:18 -0700209 return ret;
John Stultzff3ead92011-01-11 09:42:13 -0800210
John Stultzff3ead92011-01-11 09:42:13 -0800211}
212
Todd Poynor6cffe002013-05-15 14:38:11 -0700213ktime_t alarm_expires_remaining(const struct alarm *alarm)
214{
215 struct alarm_base *base = &alarm_bases[alarm->type];
216 return ktime_sub(alarm->node.expires, base->gettime());
217}
Marcus Gelderie11682a42013-06-04 09:32:09 +0200218EXPORT_SYMBOL_GPL(alarm_expires_remaining);
Todd Poynor6cffe002013-05-15 14:38:11 -0700219
John Stultz472647d2011-04-29 15:03:10 -0700220#ifdef CONFIG_RTC_CLASS
John Stultz180bf812011-04-28 12:58:11 -0700221/**
John Stultzff3ead92011-01-11 09:42:13 -0800222 * alarmtimer_suspend - Suspend time callback
223 * @dev: unused
224 * @state: unused
225 *
226 * When we are going into suspend, we look through the bases
227 * to see which is the soonest timer to expire. We then
228 * set an rtc timer to fire that far into the future, which
229 * will wake us from suspend.
230 */
231static int alarmtimer_suspend(struct device *dev)
232{
Baolin Wang4a057542016-11-28 14:35:21 -0800233 ktime_t min, now, expires;
234 int i, ret, type;
John Stultzc008ba582011-06-16 18:27:09 -0700235 struct rtc_device *rtc;
Baolin Wang4a057542016-11-28 14:35:21 -0800236 unsigned long flags;
237 struct rtc_time tm;
John Stultzff3ead92011-01-11 09:42:13 -0800238
239 spin_lock_irqsave(&freezer_delta_lock, flags);
240 min = freezer_delta;
Baolin Wang4a057542016-11-28 14:35:21 -0800241 expires = freezer_expires;
242 type = freezer_alarmtype;
Thomas Gleixner8b0e1952016-12-25 12:30:41 +0100243 freezer_delta = 0;
John Stultzff3ead92011-01-11 09:42:13 -0800244 spin_unlock_irqrestore(&freezer_delta_lock, flags);
245
John Stultz8bc0daf2011-07-14 18:35:13 -0700246 rtc = alarmtimer_get_rtcdev();
John Stultzff3ead92011-01-11 09:42:13 -0800247 /* If we have no rtcdev, just return */
John Stultzc008ba582011-06-16 18:27:09 -0700248 if (!rtc)
John Stultzff3ead92011-01-11 09:42:13 -0800249 return 0;
250
251 /* Find the soonest timer to expire*/
252 for (i = 0; i < ALARM_NUMTYPE; i++) {
253 struct alarm_base *base = &alarm_bases[i];
254 struct timerqueue_node *next;
255 ktime_t delta;
256
257 spin_lock_irqsave(&base->lock, flags);
258 next = timerqueue_getnext(&base->timerqueue);
259 spin_unlock_irqrestore(&base->lock, flags);
260 if (!next)
261 continue;
262 delta = ktime_sub(next->expires, base->gettime());
Thomas Gleixner2456e852016-12-25 11:38:40 +0100263 if (!min || (delta < min)) {
Baolin Wang4a057542016-11-28 14:35:21 -0800264 expires = next->expires;
John Stultzff3ead92011-01-11 09:42:13 -0800265 min = delta;
Baolin Wang4a057542016-11-28 14:35:21 -0800266 type = i;
267 }
John Stultzff3ead92011-01-11 09:42:13 -0800268 }
Thomas Gleixner2456e852016-12-25 11:38:40 +0100269 if (min == 0)
John Stultzff3ead92011-01-11 09:42:13 -0800270 return 0;
271
Todd Poynor59a93c22012-08-09 00:37:27 -0700272 if (ktime_to_ns(min) < 2 * NSEC_PER_SEC) {
273 __pm_wakeup_event(ws, 2 * MSEC_PER_SEC);
274 return -EBUSY;
275 }
John Stultzff3ead92011-01-11 09:42:13 -0800276
Baolin Wang4a057542016-11-28 14:35:21 -0800277 trace_alarmtimer_suspend(expires, type);
278
John Stultzff3ead92011-01-11 09:42:13 -0800279 /* Setup an rtc timer to fire that far in the future */
John Stultzc008ba582011-06-16 18:27:09 -0700280 rtc_timer_cancel(rtc, &rtctimer);
281 rtc_read_time(rtc, &tm);
John Stultzff3ead92011-01-11 09:42:13 -0800282 now = rtc_tm_to_ktime(tm);
283 now = ktime_add(now, min);
284
Todd Poynor59a93c22012-08-09 00:37:27 -0700285 /* Set alarm, if in the past reject suspend briefly to handle */
Thomas Gleixner8b0e1952016-12-25 12:30:41 +0100286 ret = rtc_timer_start(rtc, &rtctimer, now, 0);
Todd Poynor59a93c22012-08-09 00:37:27 -0700287 if (ret < 0)
288 __pm_wakeup_event(ws, MSEC_PER_SEC);
289 return ret;
John Stultzff3ead92011-01-11 09:42:13 -0800290}
zhuo-haoa0e32132015-11-17 20:08:07 +0800291
292static int alarmtimer_resume(struct device *dev)
293{
294 struct rtc_device *rtc;
295
296 rtc = alarmtimer_get_rtcdev();
297 if (rtc)
298 rtc_timer_cancel(rtc, &rtctimer);
299 return 0;
300}
301
John Stultz472647d2011-04-29 15:03:10 -0700302#else
303static int alarmtimer_suspend(struct device *dev)
304{
305 return 0;
306}
zhuo-haoa0e32132015-11-17 20:08:07 +0800307
308static int alarmtimer_resume(struct device *dev)
309{
310 return 0;
311}
John Stultz472647d2011-04-29 15:03:10 -0700312#endif
John Stultzff3ead92011-01-11 09:42:13 -0800313
John Stultz180bf812011-04-28 12:58:11 -0700314/**
John Stultzff3ead92011-01-11 09:42:13 -0800315 * alarm_init - Initialize an alarm structure
316 * @alarm: ptr to alarm to be initialized
317 * @type: the type of the alarm
318 * @function: callback that is run when the alarm fires
John Stultzff3ead92011-01-11 09:42:13 -0800319 */
320void alarm_init(struct alarm *alarm, enum alarmtimer_type type,
John Stultz4b413082011-08-10 10:37:59 -0700321 enum alarmtimer_restart (*function)(struct alarm *, ktime_t))
John Stultzff3ead92011-01-11 09:42:13 -0800322{
323 timerqueue_init(&alarm->node);
John Stultzdae373b2012-09-13 19:12:16 -0400324 hrtimer_init(&alarm->timer, alarm_bases[type].base_clockid,
325 HRTIMER_MODE_ABS);
326 alarm->timer.function = alarmtimer_fired;
John Stultzff3ead92011-01-11 09:42:13 -0800327 alarm->function = function;
328 alarm->type = type;
John Stultza28cde82011-08-10 12:30:21 -0700329 alarm->state = ALARMTIMER_STATE_INACTIVE;
John Stultzff3ead92011-01-11 09:42:13 -0800330}
Marcus Gelderie11682a42013-06-04 09:32:09 +0200331EXPORT_SYMBOL_GPL(alarm_init);
John Stultzff3ead92011-01-11 09:42:13 -0800332
John Stultz180bf812011-04-28 12:58:11 -0700333/**
Todd Poynor6cffe002013-05-15 14:38:11 -0700334 * alarm_start - Sets an absolute alarm to fire
John Stultzff3ead92011-01-11 09:42:13 -0800335 * @alarm: ptr to alarm to set
336 * @start: time to run the alarm
John Stultzff3ead92011-01-11 09:42:13 -0800337 */
Thomas Gleixnerb1932172015-04-14 21:09:18 +0000338void alarm_start(struct alarm *alarm, ktime_t start)
John Stultzff3ead92011-01-11 09:42:13 -0800339{
340 struct alarm_base *base = &alarm_bases[alarm->type];
341 unsigned long flags;
342
343 spin_lock_irqsave(&base->lock, flags);
John Stultzff3ead92011-01-11 09:42:13 -0800344 alarm->node.expires = start;
John Stultzff3ead92011-01-11 09:42:13 -0800345 alarmtimer_enqueue(base, alarm);
Thomas Gleixnerb1932172015-04-14 21:09:18 +0000346 hrtimer_start(&alarm->timer, alarm->node.expires, HRTIMER_MODE_ABS);
John Stultzff3ead92011-01-11 09:42:13 -0800347 spin_unlock_irqrestore(&base->lock, flags);
Baolin Wang4a057542016-11-28 14:35:21 -0800348
349 trace_alarmtimer_start(alarm, base->gettime());
John Stultzff3ead92011-01-11 09:42:13 -0800350}
Marcus Gelderie11682a42013-06-04 09:32:09 +0200351EXPORT_SYMBOL_GPL(alarm_start);
John Stultzff3ead92011-01-11 09:42:13 -0800352
John Stultz180bf812011-04-28 12:58:11 -0700353/**
Todd Poynor6cffe002013-05-15 14:38:11 -0700354 * alarm_start_relative - Sets a relative alarm to fire
355 * @alarm: ptr to alarm to set
356 * @start: time relative to now to run the alarm
357 */
Thomas Gleixnerb1932172015-04-14 21:09:18 +0000358void alarm_start_relative(struct alarm *alarm, ktime_t start)
Todd Poynor6cffe002013-05-15 14:38:11 -0700359{
360 struct alarm_base *base = &alarm_bases[alarm->type];
361
Thomas Gleixnerf4781e72017-05-30 23:15:34 +0200362 start = ktime_add_safe(start, base->gettime());
Thomas Gleixnerb1932172015-04-14 21:09:18 +0000363 alarm_start(alarm, start);
Todd Poynor6cffe002013-05-15 14:38:11 -0700364}
Marcus Gelderie11682a42013-06-04 09:32:09 +0200365EXPORT_SYMBOL_GPL(alarm_start_relative);
Todd Poynor6cffe002013-05-15 14:38:11 -0700366
367void alarm_restart(struct alarm *alarm)
368{
369 struct alarm_base *base = &alarm_bases[alarm->type];
370 unsigned long flags;
371
372 spin_lock_irqsave(&base->lock, flags);
373 hrtimer_set_expires(&alarm->timer, alarm->node.expires);
374 hrtimer_restart(&alarm->timer);
375 alarmtimer_enqueue(base, alarm);
376 spin_unlock_irqrestore(&base->lock, flags);
377}
Marcus Gelderie11682a42013-06-04 09:32:09 +0200378EXPORT_SYMBOL_GPL(alarm_restart);
Todd Poynor6cffe002013-05-15 14:38:11 -0700379
380/**
John Stultz9082c462011-08-10 12:41:36 -0700381 * alarm_try_to_cancel - Tries to cancel an alarm timer
John Stultzff3ead92011-01-11 09:42:13 -0800382 * @alarm: ptr to alarm to be canceled
John Stultz9082c462011-08-10 12:41:36 -0700383 *
384 * Returns 1 if the timer was canceled, 0 if it was not running,
385 * and -1 if the callback was running
John Stultzff3ead92011-01-11 09:42:13 -0800386 */
John Stultz9082c462011-08-10 12:41:36 -0700387int alarm_try_to_cancel(struct alarm *alarm)
John Stultzff3ead92011-01-11 09:42:13 -0800388{
389 struct alarm_base *base = &alarm_bases[alarm->type];
390 unsigned long flags;
John Stultzdae373b2012-09-13 19:12:16 -0400391 int ret;
392
John Stultzff3ead92011-01-11 09:42:13 -0800393 spin_lock_irqsave(&base->lock, flags);
John Stultzdae373b2012-09-13 19:12:16 -0400394 ret = hrtimer_try_to_cancel(&alarm->timer);
395 if (ret >= 0)
John Stultza65bcc12012-09-13 19:25:22 -0400396 alarmtimer_dequeue(base, alarm);
John Stultzff3ead92011-01-11 09:42:13 -0800397 spin_unlock_irqrestore(&base->lock, flags);
Baolin Wang4a057542016-11-28 14:35:21 -0800398
399 trace_alarmtimer_cancel(alarm, base->gettime());
John Stultz9082c462011-08-10 12:41:36 -0700400 return ret;
John Stultzff3ead92011-01-11 09:42:13 -0800401}
Marcus Gelderie11682a42013-06-04 09:32:09 +0200402EXPORT_SYMBOL_GPL(alarm_try_to_cancel);
John Stultzff3ead92011-01-11 09:42:13 -0800403
404
John Stultz9082c462011-08-10 12:41:36 -0700405/**
406 * alarm_cancel - Spins trying to cancel an alarm timer until it is done
407 * @alarm: ptr to alarm to be canceled
408 *
409 * Returns 1 if the timer was canceled, 0 if it was not active.
410 */
411int alarm_cancel(struct alarm *alarm)
412{
413 for (;;) {
414 int ret = alarm_try_to_cancel(alarm);
415 if (ret >= 0)
416 return ret;
417 cpu_relax();
418 }
419}
Marcus Gelderie11682a42013-06-04 09:32:09 +0200420EXPORT_SYMBOL_GPL(alarm_cancel);
John Stultz9082c462011-08-10 12:41:36 -0700421
John Stultzdce75a82011-08-10 11:31:03 -0700422
423u64 alarm_forward(struct alarm *alarm, ktime_t now, ktime_t interval)
424{
425 u64 overrun = 1;
426 ktime_t delta;
427
428 delta = ktime_sub(now, alarm->node.expires);
429
Thomas Gleixner2456e852016-12-25 11:38:40 +0100430 if (delta < 0)
John Stultzdce75a82011-08-10 11:31:03 -0700431 return 0;
432
Thomas Gleixner2456e852016-12-25 11:38:40 +0100433 if (unlikely(delta >= interval)) {
John Stultzdce75a82011-08-10 11:31:03 -0700434 s64 incr = ktime_to_ns(interval);
435
436 overrun = ktime_divns(delta, incr);
437
438 alarm->node.expires = ktime_add_ns(alarm->node.expires,
439 incr*overrun);
440
Thomas Gleixner2456e852016-12-25 11:38:40 +0100441 if (alarm->node.expires > now)
John Stultzdce75a82011-08-10 11:31:03 -0700442 return overrun;
443 /*
444 * This (and the ktime_add() below) is the
445 * correction for exact:
446 */
447 overrun++;
448 }
449
Thomas Gleixnerf4781e72017-05-30 23:15:34 +0200450 alarm->node.expires = ktime_add_safe(alarm->node.expires, interval);
John Stultzdce75a82011-08-10 11:31:03 -0700451 return overrun;
452}
Marcus Gelderie11682a42013-06-04 09:32:09 +0200453EXPORT_SYMBOL_GPL(alarm_forward);
John Stultzdce75a82011-08-10 11:31:03 -0700454
Todd Poynor6cffe002013-05-15 14:38:11 -0700455u64 alarm_forward_now(struct alarm *alarm, ktime_t interval)
456{
457 struct alarm_base *base = &alarm_bases[alarm->type];
458
459 return alarm_forward(alarm, base->gettime(), interval);
460}
Marcus Gelderie11682a42013-06-04 09:32:09 +0200461EXPORT_SYMBOL_GPL(alarm_forward_now);
John Stultzdce75a82011-08-10 11:31:03 -0700462
Christoph Hellwigd3ba5a92017-05-26 12:03:11 +0300463#ifdef CONFIG_POSIX_TIMERS
464
465static void alarmtimer_freezerset(ktime_t absexp, enum alarmtimer_type type)
466{
467 struct alarm_base *base;
468 unsigned long flags;
469 ktime_t delta;
470
471 switch(type) {
472 case ALARM_REALTIME:
473 base = &alarm_bases[ALARM_REALTIME];
474 type = ALARM_REALTIME_FREEZER;
475 break;
476 case ALARM_BOOTTIME:
477 base = &alarm_bases[ALARM_BOOTTIME];
478 type = ALARM_BOOTTIME_FREEZER;
479 break;
480 default:
481 WARN_ONCE(1, "Invalid alarm type: %d\n", type);
482 return;
483 }
484
485 delta = ktime_sub(absexp, base->gettime());
486
487 spin_lock_irqsave(&freezer_delta_lock, flags);
488 if (!freezer_delta || (delta < freezer_delta)) {
489 freezer_delta = delta;
490 freezer_expires = absexp;
491 freezer_alarmtype = type;
492 }
493 spin_unlock_irqrestore(&freezer_delta_lock, flags);
494}
John Stultzdce75a82011-08-10 11:31:03 -0700495
John Stultz180bf812011-04-28 12:58:11 -0700496/**
John Stultz9a7adcf52011-01-11 09:54:33 -0800497 * clock2alarm - helper that converts from clockid to alarmtypes
498 * @clockid: clockid.
John Stultz9a7adcf52011-01-11 09:54:33 -0800499 */
500static enum alarmtimer_type clock2alarm(clockid_t clockid)
501{
502 if (clockid == CLOCK_REALTIME_ALARM)
503 return ALARM_REALTIME;
504 if (clockid == CLOCK_BOOTTIME_ALARM)
505 return ALARM_BOOTTIME;
506 return -1;
507}
508
John Stultz180bf812011-04-28 12:58:11 -0700509/**
John Stultz9a7adcf52011-01-11 09:54:33 -0800510 * alarm_handle_timer - Callback for posix timers
511 * @alarm: alarm that fired
512 *
513 * Posix timer callback for expired alarm timers.
514 */
John Stultz4b413082011-08-10 10:37:59 -0700515static enum alarmtimer_restart alarm_handle_timer(struct alarm *alarm,
516 ktime_t now)
John Stultz9a7adcf52011-01-11 09:54:33 -0800517{
518 struct k_itimer *ptr = container_of(alarm, struct k_itimer,
Thomas Gleixnerf2c45802017-05-30 23:15:59 +0200519 it.alarm.alarmtimer);
Richard Larocque474e941b2014-09-09 18:31:05 -0700520 enum alarmtimer_restart result = ALARMTIMER_NORESTART;
Thomas Gleixnerf2c45802017-05-30 23:15:59 +0200521 unsigned long flags;
522 int si_private = 0;
Richard Larocque474e941b2014-09-09 18:31:05 -0700523
524 spin_lock_irqsave(&ptr->it_lock, flags);
John Stultz4b413082011-08-10 10:37:59 -0700525
Thomas Gleixnerf2c45802017-05-30 23:15:59 +0200526 ptr->it_active = 0;
527 if (ptr->it_interval)
528 si_private = ++ptr->it_requeue_pending;
529
530 if (posix_timer_event(ptr, si_private) && ptr->it_interval) {
531 /*
532 * Handle ignored signals and rearm the timer. This will go
533 * away once we handle ignored signals proper.
534 */
535 ptr->it_overrun += alarm_forward_now(alarm, ptr->it_interval);
536 ++ptr->it_requeue_pending;
537 ptr->it_active = 1;
Richard Larocque474e941b2014-09-09 18:31:05 -0700538 result = ALARMTIMER_RESTART;
John Stultz54da23b2011-08-10 11:08:07 -0700539 }
Richard Larocque474e941b2014-09-09 18:31:05 -0700540 spin_unlock_irqrestore(&ptr->it_lock, flags);
541
542 return result;
John Stultz9a7adcf52011-01-11 09:54:33 -0800543}
544
John Stultz180bf812011-04-28 12:58:11 -0700545/**
Thomas Gleixnerb3db80f2017-05-30 23:15:54 +0200546 * alarm_timer_rearm - Posix timer callback for rearming timer
547 * @timr: Pointer to the posixtimer data struct
548 */
549static void alarm_timer_rearm(struct k_itimer *timr)
550{
551 struct alarm *alarm = &timr->it.alarm.alarmtimer;
552
553 timr->it_overrun += alarm_forward_now(alarm, timr->it_interval);
554 alarm_start(alarm, alarm->node.expires);
555}
556
557/**
Thomas Gleixnere7561f12017-05-30 23:15:55 +0200558 * alarm_timer_forward - Posix timer callback for forwarding timer
559 * @timr: Pointer to the posixtimer data struct
560 * @now: Current time to forward the timer against
561 */
562static int alarm_timer_forward(struct k_itimer *timr, ktime_t now)
563{
564 struct alarm *alarm = &timr->it.alarm.alarmtimer;
565
566 return (int) alarm_forward(alarm, timr->it_interval, now);
567}
568
569/**
Thomas Gleixnerd653d8452017-05-30 23:15:56 +0200570 * alarm_timer_remaining - Posix timer callback to retrieve remaining time
571 * @timr: Pointer to the posixtimer data struct
572 * @now: Current time to calculate against
573 */
574static ktime_t alarm_timer_remaining(struct k_itimer *timr, ktime_t now)
575{
576 struct alarm *alarm = &timr->it.alarm.alarmtimer;
577
578 return ktime_sub(now, alarm->node.expires);
579}
580
581/**
Thomas Gleixnere344c9e2017-05-30 23:15:57 +0200582 * alarm_timer_try_to_cancel - Posix timer callback to cancel a timer
583 * @timr: Pointer to the posixtimer data struct
584 */
585static int alarm_timer_try_to_cancel(struct k_itimer *timr)
586{
587 return alarm_try_to_cancel(&timr->it.alarm.alarmtimer);
588}
589
590/**
Thomas Gleixnerb3bf6f32017-05-30 23:15:58 +0200591 * alarm_timer_arm - Posix timer callback to arm a timer
592 * @timr: Pointer to the posixtimer data struct
593 * @expires: The new expiry time
594 * @absolute: Expiry value is absolute time
595 * @sigev_none: Posix timer does not deliver signals
596 */
597static void alarm_timer_arm(struct k_itimer *timr, ktime_t expires,
598 bool absolute, bool sigev_none)
599{
600 struct alarm *alarm = &timr->it.alarm.alarmtimer;
601 struct alarm_base *base = &alarm_bases[alarm->type];
602
603 if (!absolute)
604 expires = ktime_add_safe(expires, base->gettime());
605 if (sigev_none)
606 alarm->node.expires = expires;
607 else
608 alarm_start(&timr->it.alarm.alarmtimer, expires);
609}
610
611/**
John Stultz9a7adcf52011-01-11 09:54:33 -0800612 * alarm_clock_getres - posix getres interface
613 * @which_clock: clockid
614 * @tp: timespec to fill
615 *
616 * Returns the granularity of underlying alarm base clock
617 */
Deepa Dinamanid2e3e0c2017-03-26 12:04:15 -0700618static int alarm_clock_getres(const clockid_t which_clock, struct timespec64 *tp)
John Stultz9a7adcf52011-01-11 09:54:33 -0800619{
John Stultz1c6b39a2011-06-16 18:47:37 -0700620 if (!alarmtimer_get_rtcdev())
KOSAKI Motohiro98d6f4d2013-10-14 17:33:16 -0400621 return -EINVAL;
John Stultz1c6b39a2011-06-16 18:47:37 -0700622
Thomas Gleixner056a3ca2015-04-14 21:08:32 +0000623 tp->tv_sec = 0;
624 tp->tv_nsec = hrtimer_resolution;
625 return 0;
John Stultz9a7adcf52011-01-11 09:54:33 -0800626}
627
628/**
629 * alarm_clock_get - posix clock_get interface
630 * @which_clock: clockid
631 * @tp: timespec to fill.
632 *
633 * Provides the underlying alarm base time.
634 */
Deepa Dinamani3c9c12f2017-03-26 12:04:14 -0700635static int alarm_clock_get(clockid_t which_clock, struct timespec64 *tp)
John Stultz9a7adcf52011-01-11 09:54:33 -0800636{
637 struct alarm_base *base = &alarm_bases[clock2alarm(which_clock)];
638
John Stultz1c6b39a2011-06-16 18:47:37 -0700639 if (!alarmtimer_get_rtcdev())
KOSAKI Motohiro98d6f4d2013-10-14 17:33:16 -0400640 return -EINVAL;
John Stultz1c6b39a2011-06-16 18:47:37 -0700641
Deepa Dinamani3c9c12f2017-03-26 12:04:14 -0700642 *tp = ktime_to_timespec64(base->gettime());
John Stultz9a7adcf52011-01-11 09:54:33 -0800643 return 0;
644}
645
646/**
647 * alarm_timer_create - posix timer_create interface
648 * @new_timer: k_itimer pointer to manage
649 *
650 * Initializes the k_itimer structure.
651 */
652static int alarm_timer_create(struct k_itimer *new_timer)
653{
654 enum alarmtimer_type type;
John Stultz9a7adcf52011-01-11 09:54:33 -0800655
John Stultz1c6b39a2011-06-16 18:47:37 -0700656 if (!alarmtimer_get_rtcdev())
657 return -ENOTSUPP;
658
John Stultz9a7adcf52011-01-11 09:54:33 -0800659 if (!capable(CAP_WAKE_ALARM))
660 return -EPERM;
661
662 type = clock2alarm(new_timer->it_clock);
John Stultz9e264762011-08-10 12:09:24 -0700663 alarm_init(&new_timer->it.alarm.alarmtimer, type, alarm_handle_timer);
John Stultz9a7adcf52011-01-11 09:54:33 -0800664 return 0;
665}
666
667/**
John Stultz9a7adcf52011-01-11 09:54:33 -0800668 * alarmtimer_nsleep_wakeup - Wakeup function for alarm_timer_nsleep
669 * @alarm: ptr to alarm that fired
670 *
671 * Wakes up the task that set the alarmtimer
672 */
John Stultz4b413082011-08-10 10:37:59 -0700673static enum alarmtimer_restart alarmtimer_nsleep_wakeup(struct alarm *alarm,
674 ktime_t now)
John Stultz9a7adcf52011-01-11 09:54:33 -0800675{
676 struct task_struct *task = (struct task_struct *)alarm->data;
677
678 alarm->data = NULL;
679 if (task)
680 wake_up_process(task);
John Stultz4b413082011-08-10 10:37:59 -0700681 return ALARMTIMER_NORESTART;
John Stultz9a7adcf52011-01-11 09:54:33 -0800682}
683
684/**
685 * alarmtimer_do_nsleep - Internal alarmtimer nsleep implementation
686 * @alarm: ptr to alarmtimer
687 * @absexp: absolute expiration time
688 *
689 * Sets the alarm timer and sleeps until it is fired or interrupted.
690 */
Al Viro15f27ce2017-06-07 09:42:27 +0100691static int alarmtimer_do_nsleep(struct alarm *alarm, ktime_t absexp,
692 enum alarmtimer_type type)
John Stultz9a7adcf52011-01-11 09:54:33 -0800693{
Al Viro15f27ce2017-06-07 09:42:27 +0100694 struct timespec __user *rmtp;
John Stultz9a7adcf52011-01-11 09:54:33 -0800695 alarm->data = (void *)current;
696 do {
697 set_current_state(TASK_INTERRUPTIBLE);
John Stultz9e264762011-08-10 12:09:24 -0700698 alarm_start(alarm, absexp);
John Stultz9a7adcf52011-01-11 09:54:33 -0800699 if (likely(alarm->data))
700 schedule();
701
702 alarm_cancel(alarm);
703 } while (alarm->data && !signal_pending(current));
704
705 __set_current_state(TASK_RUNNING);
706
Al Viro15f27ce2017-06-07 09:42:27 +0100707 if (!alarm->data)
John Stultz9a7adcf52011-01-11 09:54:33 -0800708 return 0;
John Stultz9a7adcf52011-01-11 09:54:33 -0800709
Al Viro15f27ce2017-06-07 09:42:27 +0100710 if (freezing(current))
711 alarmtimer_freezerset(absexp, type);
712 rmtp = current->restart_block.nanosleep.rmtp;
713 if (rmtp) {
714 struct timespec rmt;
715 ktime_t rem;
John Stultz9a7adcf52011-01-11 09:54:33 -0800716
Al Viro15f27ce2017-06-07 09:42:27 +0100717 rem = ktime_sub(absexp, alarm_bases[type].gettime());
John Stultz9a7adcf52011-01-11 09:54:33 -0800718
Al Viro15f27ce2017-06-07 09:42:27 +0100719 if (rem <= 0)
720 return 0;
721 rmt = ktime_to_timespec(rem);
722
723 if (copy_to_user(rmtp, &rmt, sizeof(*rmtp)))
724 return -EFAULT;
725 }
726 return -ERESTART_RESTARTBLOCK;
John Stultz9a7adcf52011-01-11 09:54:33 -0800727}
728
729/**
730 * alarm_timer_nsleep_restart - restartblock alarmtimer nsleep
731 * @restart: ptr to restart block
732 *
733 * Handles restarted clock_nanosleep calls
734 */
735static long __sched alarm_timer_nsleep_restart(struct restart_block *restart)
736{
Thomas Gleixnerab8177b2011-05-20 13:05:15 +0200737 enum alarmtimer_type type = restart->nanosleep.clockid;
Al Viro15f27ce2017-06-07 09:42:27 +0100738 ktime_t exp = restart->nanosleep.expires;
John Stultz9a7adcf52011-01-11 09:54:33 -0800739 struct alarm alarm;
John Stultz9a7adcf52011-01-11 09:54:33 -0800740
John Stultz9a7adcf52011-01-11 09:54:33 -0800741 alarm_init(&alarm, type, alarmtimer_nsleep_wakeup);
742
Al Viro15f27ce2017-06-07 09:42:27 +0100743 return alarmtimer_do_nsleep(&alarm, exp, type);
John Stultz9a7adcf52011-01-11 09:54:33 -0800744}
745
746/**
747 * alarm_timer_nsleep - alarmtimer nanosleep
748 * @which_clock: clockid
749 * @flags: determins abstime or relative
750 * @tsreq: requested sleep time (abs or rel)
751 * @rmtp: remaining sleep time saved
752 *
753 * Handles clock_nanosleep calls against _ALARM clockids
754 */
755static int alarm_timer_nsleep(const clockid_t which_clock, int flags,
Deepa Dinamaniad196382017-03-26 12:04:18 -0700756 struct timespec64 *tsreq,
757 struct timespec __user *rmtp)
John Stultz9a7adcf52011-01-11 09:54:33 -0800758{
759 enum alarmtimer_type type = clock2alarm(which_clock);
Al Viro15f27ce2017-06-07 09:42:27 +0100760 struct restart_block *restart = &current->restart_block;
John Stultz9a7adcf52011-01-11 09:54:33 -0800761 struct alarm alarm;
762 ktime_t exp;
763 int ret = 0;
John Stultz9a7adcf52011-01-11 09:54:33 -0800764
Al Viro15f27ce2017-06-07 09:42:27 +0100765 if (flags & TIMER_ABSTIME)
766 rmtp = NULL;
767
768 restart->nanosleep.rmtp = rmtp;
769
John Stultz1c6b39a2011-06-16 18:47:37 -0700770 if (!alarmtimer_get_rtcdev())
771 return -ENOTSUPP;
772
John Stultz16927772014-07-07 14:06:11 -0700773 if (flags & ~TIMER_ABSTIME)
774 return -EINVAL;
775
John Stultz9a7adcf52011-01-11 09:54:33 -0800776 if (!capable(CAP_WAKE_ALARM))
777 return -EPERM;
778
779 alarm_init(&alarm, type, alarmtimer_nsleep_wakeup);
780
Deepa Dinamaniad196382017-03-26 12:04:18 -0700781 exp = timespec64_to_ktime(*tsreq);
John Stultz9a7adcf52011-01-11 09:54:33 -0800782 /* Convert (if necessary) to absolute time */
783 if (flags != TIMER_ABSTIME) {
784 ktime_t now = alarm_bases[type].gettime();
785 exp = ktime_add(now, exp);
786 }
787
Al Viro15f27ce2017-06-07 09:42:27 +0100788 ret = alarmtimer_do_nsleep(&alarm, exp, type);
789 if (ret != -ERESTART_RESTARTBLOCK)
790 return ret;
John Stultz9a7adcf52011-01-11 09:54:33 -0800791
792 /* abs timers don't set remaining time or restart */
Al Viro15f27ce2017-06-07 09:42:27 +0100793 if (flags == TIMER_ABSTIME)
794 return -ERESTARTNOHAND;
John Stultz9a7adcf52011-01-11 09:54:33 -0800795
John Stultz9a7adcf52011-01-11 09:54:33 -0800796 restart->fn = alarm_timer_nsleep_restart;
Thomas Gleixnerab8177b2011-05-20 13:05:15 +0200797 restart->nanosleep.clockid = type;
Thomas Gleixner2456e852016-12-25 11:38:40 +0100798 restart->nanosleep.expires = exp;
John Stultz9a7adcf52011-01-11 09:54:33 -0800799 return ret;
800}
John Stultzff3ead92011-01-11 09:42:13 -0800801
Christoph Hellwigd3ba5a92017-05-26 12:03:11 +0300802const struct k_clock alarm_clock = {
Thomas Gleixnerd653d8452017-05-30 23:15:56 +0200803 .clock_getres = alarm_clock_getres,
804 .clock_get = alarm_clock_get,
805 .timer_create = alarm_timer_create,
Thomas Gleixnerf2c45802017-05-30 23:15:59 +0200806 .timer_set = common_timer_set,
807 .timer_del = common_timer_del,
808 .timer_get = common_timer_get,
Thomas Gleixnerb3bf6f32017-05-30 23:15:58 +0200809 .timer_arm = alarm_timer_arm,
Thomas Gleixnerd653d8452017-05-30 23:15:56 +0200810 .timer_rearm = alarm_timer_rearm,
811 .timer_forward = alarm_timer_forward,
812 .timer_remaining = alarm_timer_remaining,
Thomas Gleixnere344c9e2017-05-30 23:15:57 +0200813 .timer_try_to_cancel = alarm_timer_try_to_cancel,
Thomas Gleixnerd653d8452017-05-30 23:15:56 +0200814 .nsleep = alarm_timer_nsleep,
Christoph Hellwigd3ba5a92017-05-26 12:03:11 +0300815};
816#endif /* CONFIG_POSIX_TIMERS */
817
John Stultzff3ead92011-01-11 09:42:13 -0800818
819/* Suspend hook structures */
820static const struct dev_pm_ops alarmtimer_pm_ops = {
821 .suspend = alarmtimer_suspend,
zhuo-haoa0e32132015-11-17 20:08:07 +0800822 .resume = alarmtimer_resume,
John Stultzff3ead92011-01-11 09:42:13 -0800823};
824
825static struct platform_driver alarmtimer_driver = {
826 .driver = {
827 .name = "alarmtimer",
828 .pm = &alarmtimer_pm_ops,
829 }
830};
831
832/**
833 * alarmtimer_init - Initialize alarm timer code
834 *
835 * This function initializes the alarm bases and registers
836 * the posix clock ids.
837 */
838static int __init alarmtimer_init(void)
839{
Thomas Gleixner4523f6a2011-09-14 10:54:29 +0200840 struct platform_device *pdev;
John Stultzff3ead92011-01-11 09:42:13 -0800841 int error = 0;
842 int i;
John Stultz9a7adcf52011-01-11 09:54:33 -0800843
Thomas Gleixnerc5e14e72012-03-24 12:46:23 +0100844 alarmtimer_rtc_timer_init();
John Stultzad30dfa2012-03-23 15:52:25 -0700845
John Stultzff3ead92011-01-11 09:42:13 -0800846 /* Initialize alarm bases */
847 alarm_bases[ALARM_REALTIME].base_clockid = CLOCK_REALTIME;
848 alarm_bases[ALARM_REALTIME].gettime = &ktime_get_real;
849 alarm_bases[ALARM_BOOTTIME].base_clockid = CLOCK_BOOTTIME;
850 alarm_bases[ALARM_BOOTTIME].gettime = &ktime_get_boottime;
851 for (i = 0; i < ALARM_NUMTYPE; i++) {
852 timerqueue_init_head(&alarm_bases[i].timerqueue);
853 spin_lock_init(&alarm_bases[i].lock);
John Stultzff3ead92011-01-11 09:42:13 -0800854 }
John Stultz8bc0daf2011-07-14 18:35:13 -0700855
Thomas Gleixner4523f6a2011-09-14 10:54:29 +0200856 error = alarmtimer_rtc_interface_setup();
857 if (error)
858 return error;
John Stultzff3ead92011-01-11 09:42:13 -0800859
Thomas Gleixner4523f6a2011-09-14 10:54:29 +0200860 error = platform_driver_register(&alarmtimer_driver);
861 if (error)
862 goto out_if;
863
864 pdev = platform_device_register_simple("alarmtimer", -1, NULL, 0);
865 if (IS_ERR(pdev)) {
866 error = PTR_ERR(pdev);
867 goto out_drv;
868 }
Todd Poynor59a93c22012-08-09 00:37:27 -0700869 ws = wakeup_source_register("alarmtimer");
Thomas Gleixner4523f6a2011-09-14 10:54:29 +0200870 return 0;
871
872out_drv:
873 platform_driver_unregister(&alarmtimer_driver);
874out_if:
875 alarmtimer_rtc_interface_remove();
John Stultzff3ead92011-01-11 09:42:13 -0800876 return error;
877}
878device_initcall(alarmtimer_init);