4 * This interface provides a timer which is similarto hrtimers,
5 * but triggers a RTC alarm if the box is suspend.
7 * This interface is influenced by the Android RTC Alarm timer
10 * Copyright (C) 2010 IBM Corperation
12 * Author: John Stultz <john.stultz@linaro.org>
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.
18 #include <linux/time.h>
19 #include <linux/hrtimer.h>
20 #include <linux/timerqueue.h>
21 #include <linux/rtc.h>
22 #include <linux/alarmtimer.h>
23 #include <linux/mutex.h>
24 #include <linux/platform_device.h>
25 #include <linux/posix-timers.h>
26 #include <linux/workqueue.h>
27 #include <linux/freezer.h>
30 * struct alarm_base - Alarm timer bases
31 * @lock: Lock for syncrhonized access to the base
32 * @timerqueue: Timerqueue head managing the list of events
33 * @gettime: Function to read the time correlating to the base
34 * @base_clockid: clockid for the base
36 static struct alarm_base
{
38 struct timerqueue_head timerqueue
;
39 ktime_t (*gettime
)(void);
40 clockid_t base_clockid
;
41 } alarm_bases
[ALARM_NUMTYPE
];
43 /* freezer delta & lock used to handle clock_nanosleep triggered wakeups */
44 static ktime_t freezer_delta
;
45 static DEFINE_SPINLOCK(freezer_delta_lock
);
47 static struct wakeup_source
*ws
;
49 #ifdef CONFIG_RTC_CLASS
50 /* rtc timer and device for setting alarm wakeups at suspend */
51 static struct rtc_timer rtctimer
;
52 static struct rtc_device
*rtcdev
;
53 static DEFINE_SPINLOCK(rtcdev_lock
);
56 * alarmtimer_get_rtcdev - Return selected rtcdevice
58 * This function returns the rtc device to use for wakealarms.
59 * If one has not already been chosen, it checks to see if a
60 * functional rtc device is available.
62 struct rtc_device
*alarmtimer_get_rtcdev(void)
65 struct rtc_device
*ret
;
67 spin_lock_irqsave(&rtcdev_lock
, flags
);
69 spin_unlock_irqrestore(&rtcdev_lock
, flags
);
73 EXPORT_SYMBOL_GPL(alarmtimer_get_rtcdev
);
75 static int alarmtimer_rtc_add_device(struct device
*dev
,
76 struct class_interface
*class_intf
)
79 struct rtc_device
*rtc
= to_rtc_device(dev
);
84 if (!rtc
->ops
->set_alarm
)
86 if (!device_may_wakeup(rtc
->dev
.parent
))
89 spin_lock_irqsave(&rtcdev_lock
, flags
);
92 /* hold a reference so it doesn't go away */
95 spin_unlock_irqrestore(&rtcdev_lock
, flags
);
99 static inline void alarmtimer_rtc_timer_init(void)
101 rtc_timer_init(&rtctimer
, NULL
, NULL
);
104 static struct class_interface alarmtimer_rtc_interface
= {
105 .add_dev
= &alarmtimer_rtc_add_device
,
108 static int alarmtimer_rtc_interface_setup(void)
110 alarmtimer_rtc_interface
.class = rtc_class
;
111 return class_interface_register(&alarmtimer_rtc_interface
);
113 static void alarmtimer_rtc_interface_remove(void)
115 class_interface_unregister(&alarmtimer_rtc_interface
);
118 struct rtc_device
*alarmtimer_get_rtcdev(void)
122 #define rtcdev (NULL)
123 static inline int alarmtimer_rtc_interface_setup(void) { return 0; }
124 static inline void alarmtimer_rtc_interface_remove(void) { }
125 static inline void alarmtimer_rtc_timer_init(void) { }
129 * alarmtimer_enqueue - Adds an alarm timer to an alarm_base timerqueue
130 * @base: pointer to the base where the timer is being run
131 * @alarm: pointer to alarm being enqueued.
133 * Adds alarm to a alarm_base timerqueue
135 * Must hold base->lock when calling.
137 static void alarmtimer_enqueue(struct alarm_base
*base
, struct alarm
*alarm
)
139 if (alarm
->state
& ALARMTIMER_STATE_ENQUEUED
)
140 timerqueue_del(&base
->timerqueue
, &alarm
->node
);
142 timerqueue_add(&base
->timerqueue
, &alarm
->node
);
143 alarm
->state
|= ALARMTIMER_STATE_ENQUEUED
;
147 * alarmtimer_dequeue - Removes an alarm timer from an alarm_base timerqueue
148 * @base: pointer to the base where the timer is running
149 * @alarm: pointer to alarm being removed
151 * Removes alarm to a alarm_base timerqueue
153 * Must hold base->lock when calling.
155 static void alarmtimer_dequeue(struct alarm_base
*base
, struct alarm
*alarm
)
157 if (!(alarm
->state
& ALARMTIMER_STATE_ENQUEUED
))
160 timerqueue_del(&base
->timerqueue
, &alarm
->node
);
161 alarm
->state
&= ~ALARMTIMER_STATE_ENQUEUED
;
166 * alarmtimer_fired - Handles alarm hrtimer being fired.
167 * @timer: pointer to hrtimer being run
169 * When a alarm timer fires, this runs through the timerqueue to
170 * see which alarms expired, and runs those. If there are more alarm
171 * timers queued for the future, we set the hrtimer to fire when
172 * when the next future alarm timer expires.
174 static enum hrtimer_restart
alarmtimer_fired(struct hrtimer
*timer
)
176 struct alarm
*alarm
= container_of(timer
, struct alarm
, timer
);
177 struct alarm_base
*base
= &alarm_bases
[alarm
->type
];
179 int ret
= HRTIMER_NORESTART
;
180 int restart
= ALARMTIMER_NORESTART
;
182 spin_lock_irqsave(&base
->lock
, flags
);
183 alarmtimer_dequeue(base
, alarm
);
184 spin_unlock_irqrestore(&base
->lock
, flags
);
187 restart
= alarm
->function(alarm
, base
->gettime());
189 spin_lock_irqsave(&base
->lock
, flags
);
190 if (restart
!= ALARMTIMER_NORESTART
) {
191 hrtimer_set_expires(&alarm
->timer
, alarm
->node
.expires
);
192 alarmtimer_enqueue(base
, alarm
);
193 ret
= HRTIMER_RESTART
;
195 spin_unlock_irqrestore(&base
->lock
, flags
);
201 ktime_t
alarm_expires_remaining(const struct alarm
*alarm
)
203 struct alarm_base
*base
= &alarm_bases
[alarm
->type
];
204 return ktime_sub(alarm
->node
.expires
, base
->gettime());
206 EXPORT_SYMBOL_GPL(alarm_expires_remaining
);
208 #ifdef CONFIG_RTC_CLASS
210 * alarmtimer_suspend - Suspend time callback
214 * When we are going into suspend, we look through the bases
215 * to see which is the soonest timer to expire. We then
216 * set an rtc timer to fire that far into the future, which
217 * will wake us from suspend.
219 static int alarmtimer_suspend(struct device
*dev
)
224 struct rtc_device
*rtc
;
228 spin_lock_irqsave(&freezer_delta_lock
, flags
);
230 freezer_delta
= ktime_set(0, 0);
231 spin_unlock_irqrestore(&freezer_delta_lock
, flags
);
233 rtc
= alarmtimer_get_rtcdev();
234 /* If we have no rtcdev, just return */
238 /* Find the soonest timer to expire*/
239 for (i
= 0; i
< ALARM_NUMTYPE
; i
++) {
240 struct alarm_base
*base
= &alarm_bases
[i
];
241 struct timerqueue_node
*next
;
244 spin_lock_irqsave(&base
->lock
, flags
);
245 next
= timerqueue_getnext(&base
->timerqueue
);
246 spin_unlock_irqrestore(&base
->lock
, flags
);
249 delta
= ktime_sub(next
->expires
, base
->gettime());
250 if (!min
.tv64
|| (delta
.tv64
< min
.tv64
))
256 if (ktime_to_ns(min
) < 2 * NSEC_PER_SEC
) {
257 __pm_wakeup_event(ws
, 2 * MSEC_PER_SEC
);
261 /* Setup an rtc timer to fire that far in the future */
262 rtc_timer_cancel(rtc
, &rtctimer
);
263 rtc_read_time(rtc
, &tm
);
264 now
= rtc_tm_to_ktime(tm
);
265 now
= ktime_add(now
, min
);
267 /* Set alarm, if in the past reject suspend briefly to handle */
268 ret
= rtc_timer_start(rtc
, &rtctimer
, now
, ktime_set(0, 0));
270 __pm_wakeup_event(ws
, MSEC_PER_SEC
);
274 static int alarmtimer_resume(struct device
*dev
)
276 struct rtc_device
*rtc
;
278 rtc
= alarmtimer_get_rtcdev();
280 rtc_timer_cancel(rtc
, &rtctimer
);
285 static int alarmtimer_suspend(struct device
*dev
)
290 static int alarmtimer_resume(struct device
*dev
)
296 static void alarmtimer_freezerset(ktime_t absexp
, enum alarmtimer_type type
)
300 struct alarm_base
*base
= &alarm_bases
[type
];
302 delta
= ktime_sub(absexp
, base
->gettime());
304 spin_lock_irqsave(&freezer_delta_lock
, flags
);
305 if (!freezer_delta
.tv64
|| (delta
.tv64
< freezer_delta
.tv64
))
306 freezer_delta
= delta
;
307 spin_unlock_irqrestore(&freezer_delta_lock
, flags
);
312 * alarm_init - Initialize an alarm structure
313 * @alarm: ptr to alarm to be initialized
314 * @type: the type of the alarm
315 * @function: callback that is run when the alarm fires
317 void alarm_init(struct alarm
*alarm
, enum alarmtimer_type type
,
318 enum alarmtimer_restart (*function
)(struct alarm
*, ktime_t
))
320 timerqueue_init(&alarm
->node
);
321 hrtimer_init(&alarm
->timer
, alarm_bases
[type
].base_clockid
,
323 alarm
->timer
.function
= alarmtimer_fired
;
324 alarm
->function
= function
;
326 alarm
->state
= ALARMTIMER_STATE_INACTIVE
;
328 EXPORT_SYMBOL_GPL(alarm_init
);
331 * alarm_start - Sets an absolute alarm to fire
332 * @alarm: ptr to alarm to set
333 * @start: time to run the alarm
335 void alarm_start(struct alarm
*alarm
, ktime_t start
)
337 struct alarm_base
*base
= &alarm_bases
[alarm
->type
];
340 spin_lock_irqsave(&base
->lock
, flags
);
341 alarm
->node
.expires
= start
;
342 alarmtimer_enqueue(base
, alarm
);
343 hrtimer_start(&alarm
->timer
, alarm
->node
.expires
, HRTIMER_MODE_ABS
);
344 spin_unlock_irqrestore(&base
->lock
, flags
);
346 EXPORT_SYMBOL_GPL(alarm_start
);
349 * alarm_start_relative - Sets a relative alarm to fire
350 * @alarm: ptr to alarm to set
351 * @start: time relative to now to run the alarm
353 void alarm_start_relative(struct alarm
*alarm
, ktime_t start
)
355 struct alarm_base
*base
= &alarm_bases
[alarm
->type
];
357 start
= ktime_add(start
, base
->gettime());
358 alarm_start(alarm
, start
);
360 EXPORT_SYMBOL_GPL(alarm_start_relative
);
362 void alarm_restart(struct alarm
*alarm
)
364 struct alarm_base
*base
= &alarm_bases
[alarm
->type
];
367 spin_lock_irqsave(&base
->lock
, flags
);
368 hrtimer_set_expires(&alarm
->timer
, alarm
->node
.expires
);
369 hrtimer_restart(&alarm
->timer
);
370 alarmtimer_enqueue(base
, alarm
);
371 spin_unlock_irqrestore(&base
->lock
, flags
);
373 EXPORT_SYMBOL_GPL(alarm_restart
);
376 * alarm_try_to_cancel - Tries to cancel an alarm timer
377 * @alarm: ptr to alarm to be canceled
379 * Returns 1 if the timer was canceled, 0 if it was not running,
380 * and -1 if the callback was running
382 int alarm_try_to_cancel(struct alarm
*alarm
)
384 struct alarm_base
*base
= &alarm_bases
[alarm
->type
];
388 spin_lock_irqsave(&base
->lock
, flags
);
389 ret
= hrtimer_try_to_cancel(&alarm
->timer
);
391 alarmtimer_dequeue(base
, alarm
);
392 spin_unlock_irqrestore(&base
->lock
, flags
);
395 EXPORT_SYMBOL_GPL(alarm_try_to_cancel
);
399 * alarm_cancel - Spins trying to cancel an alarm timer until it is done
400 * @alarm: ptr to alarm to be canceled
402 * Returns 1 if the timer was canceled, 0 if it was not active.
404 int alarm_cancel(struct alarm
*alarm
)
407 int ret
= alarm_try_to_cancel(alarm
);
413 EXPORT_SYMBOL_GPL(alarm_cancel
);
416 u64
alarm_forward(struct alarm
*alarm
, ktime_t now
, ktime_t interval
)
421 delta
= ktime_sub(now
, alarm
->node
.expires
);
426 if (unlikely(delta
.tv64
>= interval
.tv64
)) {
427 s64 incr
= ktime_to_ns(interval
);
429 overrun
= ktime_divns(delta
, incr
);
431 alarm
->node
.expires
= ktime_add_ns(alarm
->node
.expires
,
434 if (alarm
->node
.expires
.tv64
> now
.tv64
)
437 * This (and the ktime_add() below) is the
438 * correction for exact:
443 alarm
->node
.expires
= ktime_add(alarm
->node
.expires
, interval
);
446 EXPORT_SYMBOL_GPL(alarm_forward
);
448 u64
alarm_forward_now(struct alarm
*alarm
, ktime_t interval
)
450 struct alarm_base
*base
= &alarm_bases
[alarm
->type
];
452 return alarm_forward(alarm
, base
->gettime(), interval
);
454 EXPORT_SYMBOL_GPL(alarm_forward_now
);
458 * clock2alarm - helper that converts from clockid to alarmtypes
461 static enum alarmtimer_type
clock2alarm(clockid_t clockid
)
463 if (clockid
== CLOCK_REALTIME_ALARM
)
464 return ALARM_REALTIME
;
465 if (clockid
== CLOCK_BOOTTIME_ALARM
)
466 return ALARM_BOOTTIME
;
471 * alarm_handle_timer - Callback for posix timers
472 * @alarm: alarm that fired
474 * Posix timer callback for expired alarm timers.
476 static enum alarmtimer_restart
alarm_handle_timer(struct alarm
*alarm
,
480 struct k_itimer
*ptr
= container_of(alarm
, struct k_itimer
,
481 it
.alarm
.alarmtimer
);
482 enum alarmtimer_restart result
= ALARMTIMER_NORESTART
;
484 spin_lock_irqsave(&ptr
->it_lock
, flags
);
485 if ((ptr
->it_sigev_notify
& ~SIGEV_THREAD_ID
) != SIGEV_NONE
) {
486 if (posix_timer_event(ptr
, 0) != 0)
490 /* Re-add periodic timers */
491 if (ptr
->it
.alarm
.interval
.tv64
) {
492 ptr
->it_overrun
+= alarm_forward(alarm
, now
,
493 ptr
->it
.alarm
.interval
);
494 result
= ALARMTIMER_RESTART
;
496 spin_unlock_irqrestore(&ptr
->it_lock
, flags
);
502 * alarm_clock_getres - posix getres interface
503 * @which_clock: clockid
504 * @tp: timespec to fill
506 * Returns the granularity of underlying alarm base clock
508 static int alarm_clock_getres(const clockid_t which_clock
, struct timespec
*tp
)
510 if (!alarmtimer_get_rtcdev())
514 tp
->tv_nsec
= hrtimer_resolution
;
519 * alarm_clock_get - posix clock_get interface
520 * @which_clock: clockid
521 * @tp: timespec to fill.
523 * Provides the underlying alarm base time.
525 static int alarm_clock_get(clockid_t which_clock
, struct timespec
*tp
)
527 struct alarm_base
*base
= &alarm_bases
[clock2alarm(which_clock
)];
529 if (!alarmtimer_get_rtcdev())
532 *tp
= ktime_to_timespec(base
->gettime());
537 * alarm_timer_create - posix timer_create interface
538 * @new_timer: k_itimer pointer to manage
540 * Initializes the k_itimer structure.
542 static int alarm_timer_create(struct k_itimer
*new_timer
)
544 enum alarmtimer_type type
;
546 if (!alarmtimer_get_rtcdev())
549 if (!capable(CAP_WAKE_ALARM
))
552 type
= clock2alarm(new_timer
->it_clock
);
553 alarm_init(&new_timer
->it
.alarm
.alarmtimer
, type
, alarm_handle_timer
);
558 * alarm_timer_get - posix timer_get interface
559 * @new_timer: k_itimer pointer
560 * @cur_setting: itimerspec data to fill
562 * Copies out the current itimerspec data
564 static void alarm_timer_get(struct k_itimer
*timr
,
565 struct itimerspec
*cur_setting
)
567 ktime_t relative_expiry_time
=
568 alarm_expires_remaining(&(timr
->it
.alarm
.alarmtimer
));
570 if (ktime_to_ns(relative_expiry_time
) > 0) {
571 cur_setting
->it_value
= ktime_to_timespec(relative_expiry_time
);
573 cur_setting
->it_value
.tv_sec
= 0;
574 cur_setting
->it_value
.tv_nsec
= 0;
577 cur_setting
->it_interval
= ktime_to_timespec(timr
->it
.alarm
.interval
);
581 * alarm_timer_del - posix timer_del interface
582 * @timr: k_itimer pointer to be deleted
584 * Cancels any programmed alarms for the given timer.
586 static int alarm_timer_del(struct k_itimer
*timr
)
591 if (alarm_try_to_cancel(&timr
->it
.alarm
.alarmtimer
) < 0)
598 * alarm_timer_set - posix timer_set interface
599 * @timr: k_itimer pointer to be deleted
600 * @flags: timer flags
601 * @new_setting: itimerspec to be used
602 * @old_setting: itimerspec being replaced
604 * Sets the timer to new_setting, and starts the timer.
606 static int alarm_timer_set(struct k_itimer
*timr
, int flags
,
607 struct itimerspec
*new_setting
,
608 struct itimerspec
*old_setting
)
615 if (flags
& ~TIMER_ABSTIME
)
619 alarm_timer_get(timr
, old_setting
);
621 /* If the timer was already set, cancel it */
622 if (alarm_try_to_cancel(&timr
->it
.alarm
.alarmtimer
) < 0)
625 /* start the timer */
626 timr
->it
.alarm
.interval
= timespec_to_ktime(new_setting
->it_interval
);
627 exp
= timespec_to_ktime(new_setting
->it_value
);
628 /* Convert (if necessary) to absolute time */
629 if (flags
!= TIMER_ABSTIME
) {
632 now
= alarm_bases
[timr
->it
.alarm
.alarmtimer
.type
].gettime();
633 exp
= ktime_add(now
, exp
);
636 alarm_start(&timr
->it
.alarm
.alarmtimer
, exp
);
641 * alarmtimer_nsleep_wakeup - Wakeup function for alarm_timer_nsleep
642 * @alarm: ptr to alarm that fired
644 * Wakes up the task that set the alarmtimer
646 static enum alarmtimer_restart
alarmtimer_nsleep_wakeup(struct alarm
*alarm
,
649 struct task_struct
*task
= (struct task_struct
*)alarm
->data
;
653 wake_up_process(task
);
654 return ALARMTIMER_NORESTART
;
658 * alarmtimer_do_nsleep - Internal alarmtimer nsleep implementation
659 * @alarm: ptr to alarmtimer
660 * @absexp: absolute expiration time
662 * Sets the alarm timer and sleeps until it is fired or interrupted.
664 static int alarmtimer_do_nsleep(struct alarm
*alarm
, ktime_t absexp
)
666 alarm
->data
= (void *)current
;
668 set_current_state(TASK_INTERRUPTIBLE
);
669 alarm_start(alarm
, absexp
);
670 if (likely(alarm
->data
))
674 } while (alarm
->data
&& !signal_pending(current
));
676 __set_current_state(TASK_RUNNING
);
678 return (alarm
->data
== NULL
);
683 * update_rmtp - Update remaining timespec value
684 * @exp: expiration time
686 * @rmtp: user pointer to remaining timepsec value
688 * Helper function that fills in rmtp value with time between
689 * now and the exp value
691 static int update_rmtp(ktime_t exp
, enum alarmtimer_type type
,
692 struct timespec __user
*rmtp
)
697 rem
= ktime_sub(exp
, alarm_bases
[type
].gettime());
701 rmt
= ktime_to_timespec(rem
);
703 if (copy_to_user(rmtp
, &rmt
, sizeof(*rmtp
)))
711 * alarm_timer_nsleep_restart - restartblock alarmtimer nsleep
712 * @restart: ptr to restart block
714 * Handles restarted clock_nanosleep calls
716 static long __sched
alarm_timer_nsleep_restart(struct restart_block
*restart
)
718 enum alarmtimer_type type
= restart
->nanosleep
.clockid
;
720 struct timespec __user
*rmtp
;
724 exp
.tv64
= restart
->nanosleep
.expires
;
725 alarm_init(&alarm
, type
, alarmtimer_nsleep_wakeup
);
727 if (alarmtimer_do_nsleep(&alarm
, exp
))
730 if (freezing(current
))
731 alarmtimer_freezerset(exp
, type
);
733 rmtp
= restart
->nanosleep
.rmtp
;
735 ret
= update_rmtp(exp
, type
, rmtp
);
741 /* The other values in restart are already filled in */
742 ret
= -ERESTART_RESTARTBLOCK
;
748 * alarm_timer_nsleep - alarmtimer nanosleep
749 * @which_clock: clockid
750 * @flags: determins abstime or relative
751 * @tsreq: requested sleep time (abs or rel)
752 * @rmtp: remaining sleep time saved
754 * Handles clock_nanosleep calls against _ALARM clockids
756 static int alarm_timer_nsleep(const clockid_t which_clock
, int flags
,
757 struct timespec
*tsreq
, struct timespec __user
*rmtp
)
759 enum alarmtimer_type type
= clock2alarm(which_clock
);
763 struct restart_block
*restart
;
765 if (!alarmtimer_get_rtcdev())
768 if (flags
& ~TIMER_ABSTIME
)
771 if (!capable(CAP_WAKE_ALARM
))
774 alarm_init(&alarm
, type
, alarmtimer_nsleep_wakeup
);
776 exp
= timespec_to_ktime(*tsreq
);
777 /* Convert (if necessary) to absolute time */
778 if (flags
!= TIMER_ABSTIME
) {
779 ktime_t now
= alarm_bases
[type
].gettime();
780 exp
= ktime_add(now
, exp
);
783 if (alarmtimer_do_nsleep(&alarm
, exp
))
786 if (freezing(current
))
787 alarmtimer_freezerset(exp
, type
);
789 /* abs timers don't set remaining time or restart */
790 if (flags
== TIMER_ABSTIME
) {
791 ret
= -ERESTARTNOHAND
;
796 ret
= update_rmtp(exp
, type
, rmtp
);
801 restart
= ¤t
->restart_block
;
802 restart
->fn
= alarm_timer_nsleep_restart
;
803 restart
->nanosleep
.clockid
= type
;
804 restart
->nanosleep
.expires
= exp
.tv64
;
805 restart
->nanosleep
.rmtp
= rmtp
;
806 ret
= -ERESTART_RESTARTBLOCK
;
813 /* Suspend hook structures */
814 static const struct dev_pm_ops alarmtimer_pm_ops
= {
815 .suspend
= alarmtimer_suspend
,
816 .resume
= alarmtimer_resume
,
819 static struct platform_driver alarmtimer_driver
= {
821 .name
= "alarmtimer",
822 .pm
= &alarmtimer_pm_ops
,
827 * alarmtimer_init - Initialize alarm timer code
829 * This function initializes the alarm bases and registers
830 * the posix clock ids.
832 static int __init
alarmtimer_init(void)
834 struct platform_device
*pdev
;
837 struct k_clock alarm_clock
= {
838 .clock_getres
= alarm_clock_getres
,
839 .clock_get
= alarm_clock_get
,
840 .timer_create
= alarm_timer_create
,
841 .timer_set
= alarm_timer_set
,
842 .timer_del
= alarm_timer_del
,
843 .timer_get
= alarm_timer_get
,
844 .nsleep
= alarm_timer_nsleep
,
847 alarmtimer_rtc_timer_init();
849 posix_timers_register_clock(CLOCK_REALTIME_ALARM
, &alarm_clock
);
850 posix_timers_register_clock(CLOCK_BOOTTIME_ALARM
, &alarm_clock
);
852 /* Initialize alarm bases */
853 alarm_bases
[ALARM_REALTIME
].base_clockid
= CLOCK_REALTIME
;
854 alarm_bases
[ALARM_REALTIME
].gettime
= &ktime_get_real
;
855 alarm_bases
[ALARM_BOOTTIME
].base_clockid
= CLOCK_BOOTTIME
;
856 alarm_bases
[ALARM_BOOTTIME
].gettime
= &ktime_get_boottime
;
857 for (i
= 0; i
< ALARM_NUMTYPE
; i
++) {
858 timerqueue_init_head(&alarm_bases
[i
].timerqueue
);
859 spin_lock_init(&alarm_bases
[i
].lock
);
862 error
= alarmtimer_rtc_interface_setup();
866 error
= platform_driver_register(&alarmtimer_driver
);
870 pdev
= platform_device_register_simple("alarmtimer", -1, NULL
, 0);
872 error
= PTR_ERR(pdev
);
875 ws
= wakeup_source_register("alarmtimer");
879 platform_driver_unregister(&alarmtimer_driver
);
881 alarmtimer_rtc_interface_remove();
884 device_initcall(alarmtimer_init
);